Skip to content

Commit

Permalink
Fix error message
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHolly committed Jan 26, 2025
1 parent 9e2d461 commit eba31c0
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ class SwaggerParser extends $RefParser {
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 @@ class SwaggerParser extends $RefParser {
}
}
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 @@ class SwaggerParser extends $RefParser {
// 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

0 comments on commit eba31c0

Please sign in to comment.