diff --git a/lib/index.js b/lib/index.js index 69841fc3..9ee69d87 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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.'); } @@ -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`); @@ -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.'); }