-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error on unsupported OpenAPI versions
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
import OpenAPIParser from '@readme/openapi-parser'; | ||
|
||
export const validateSpec = async options => { | ||
return await OpenAPIParser.validate(options.spec); | ||
const spec = await OpenAPIParser.validate(options.spec); | ||
|
||
if (spec.swagger) { | ||
throw new TypeError(`Unsupported OpenAPI version: ${spec.swagger}`); | ||
} | ||
|
||
const majorVersion = Number(spec.openapi?.split('.')[0] ?? '0'); | ||
|
||
if (majorVersion < 3 || majorVersion >= 4) { | ||
throw new TypeError(`Unsupported OpenAPI version: ${spec.openapi ?? 'n/a'}`); | ||
} | ||
|
||
return spec; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters