Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More error details fixes #116 #267

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
* @param {string} [path] - The file path or URL of the JSON schema
* @param {object} [api] - The Swagger API object. This object will be used instead of reading from `path`.
* @param {ParserOptions} [options] - Options that determine how the API is parsed

Check warning on line 34 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node 20 on ubuntu-latest

The type 'ParserOptions' is undefined

Check warning on line 34 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node 20 on macos-latest

The type 'ParserOptions' is undefined

Check warning on line 34 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node 20 on windows-latest

The type 'ParserOptions' is undefined
* @param {Function} [callback] - An error-first callback. The second parameter is the parsed API object.
* @returns {Promise} - The returned promise resolves with the parsed API object.
*/
Expand All @@ -43,15 +43,11 @@
let schema = await super.parse(args.path, args.schema, args.options);

if (schema.swagger) {
// Verify that the parsed object is a Swagger API
if (schema.swagger === undefined || schema.info === undefined || schema.paths === undefined) {
throw ono.syntax(`${args.path || args.schema} is not a valid Swagger API definition`);
}
else if (typeof schema.swagger === "number") {
if (typeof schema.swagger === "number") {
// This is a very common mistake, so give a helpful error message
throw ono.syntax('Swagger version number must be a string (e.g. "2.0") not a number.');
}
else if (typeof schema.info.version === "number") {
else if (schema.info && typeof schema.info.version === "number") {
// This is a very common mistake, so give a helpful error message
throw ono.syntax('API version number must be a string (e.g. "1.0.0") not a number.');
}
Expand All @@ -60,11 +56,7 @@
}
}
else {
// Verify that the parsed object is a Openapi API
if (schema.openapi === undefined || schema.info === undefined) {
throw ono.syntax(`${args.path || args.schema} is not a valid Openapi API definition`);
}
else if (schema.paths === undefined) {
if (schema.paths === undefined) {
if (supported31Versions.indexOf(schema.openapi) !== -1) {
if (schema.webhooks === undefined) {
throw ono.syntax(`${args.path || args.schema} is not a valid Openapi API definition`);
Expand All @@ -78,7 +70,7 @@
// This is a very common mistake, so give a helpful error message
throw ono.syntax('Openapi version number must be a string (e.g. "3.0.0") not a number.');
}
else if (typeof schema.info.version === "number") {
else if (schema.info && typeof schema.info.version === "number") {
// This is a very common mistake, so give a helpful error message
throw ono.syntax('API version number must be a string (e.g. "1.0.0") not a number.');
}
Expand Down Expand Up @@ -108,7 +100,7 @@
*
* @param {string} [path] - The file path or URL of the JSON schema
* @param {object} [api] - The Swagger API object. This object will be used instead of reading from `path`.
* @param {ParserOptions} [options] - Options that determine how the API is parsed, dereferenced, and validated

Check warning on line 103 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node 20 on ubuntu-latest

The type 'ParserOptions' is undefined

Check warning on line 103 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node 20 on macos-latest

The type 'ParserOptions' is undefined

Check warning on line 103 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node 20 on windows-latest

The type 'ParserOptions' is undefined
* @param {Function} [callback] - An error-first callback. The second parameter is the parsed API object.
* @returns {Promise} - The returned promise resolves with the parsed API object.
*/
Expand Down
Loading