Skip to content

Commit

Permalink
fix: Only display API version if present (#773)
Browse files Browse the repository at this point in the history
* Only display API version if present
* Warn if `info.version` is omitted, error if `info` is missing.
  • Loading branch information
TheMarex authored and RomanHotsiy committed Jan 17, 2019
1 parent c343db6 commit fb3cb36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/ApiInfo/ApiInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
)) ||
null;

const version =
(info.version && (
<span>({info.version})</span>
)) ||
null;

return (
<Section>
<Row>
<MiddlePanel className="api-info">
<ApiHeader>
{info.title} <span>({info.version})</span>
{info.title} {version}
</ApiHeader>
{!hideDownloadButton && (
<p>
Expand Down
6 changes: 6 additions & 0 deletions src/services/OpenAPIParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export class OpenAPIParser {
if (spec.openapi === undefined) {
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) {
Expand Down

0 comments on commit fb3cb36

Please sign in to comment.