fix: Only display API version if present (#773)

* Only display API version if present
* Warn if `info.version` is omitted, error if `info` is missing.
This commit is contained in:
Patrick Niklaus 2019-01-17 16:24:05 +01:00 committed by Roman Hotsiy
parent c343db694e
commit fb3cb3627b
2 changed files with 13 additions and 1 deletions

View File

@ -70,12 +70,18 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
)) || )) ||
null; null;
const version =
(info.version && (
<span>({info.version})</span>
)) ||
null;
return ( return (
<Section> <Section>
<Row> <Row>
<MiddlePanel className="api-info"> <MiddlePanel className="api-info">
<ApiHeader> <ApiHeader>
{info.title} <span>({info.version})</span> {info.title} {version}
</ApiHeader> </ApiHeader>
{!hideDownloadButton && ( {!hideDownloadButton && (
<p> <p>

View File

@ -63,6 +63,12 @@ export class OpenAPIParser {
if (spec.openapi === undefined) { if (spec.openapi === undefined) {
throw new Error('Document must be valid OpenAPI 3.0.0 definition'); throw new Error('Document must be valid OpenAPI 3.0.0 definition');
} }
if (spec.info === undefined) {
throw new Error('OpenAPI 3.0.0 requires an `info` section');
}
if (spec.info.version === undefined) {
console.warn('OpenAPI 3.0.0 requires setting a `info.version` field, ignoring.')
}
} }
preprocess(spec: OpenAPISpec) { preprocess(spec: OpenAPISpec) {