@@ -60,15 +60,11 @@ SwaggerParser.prototype.parse = async function (path, api, options, callback) {
6060 let schema = await $RefParser . prototype . parse . call ( this , args . path , args . schema , args . options ) ;
6161
6262 if ( schema . swagger ) {
63- // Verify that the parsed object is a Swagger API
64- if ( schema . swagger === undefined || schema . info === undefined || schema . paths === undefined ) {
65- throw ono . syntax ( `${ args . path || args . schema } is not a valid Swagger API definition` ) ;
66- }
67- else if ( typeof schema . swagger === "number" ) {
63+ if ( typeof schema . swagger === "number" ) {
6864 // This is a very common mistake, so give a helpful error message
6965 throw ono . syntax ( 'Swagger version number must be a string (e.g. "2.0") not a number.' ) ;
7066 }
71- else if ( typeof schema . info . version === "number" ) {
67+ else if ( schema . info && typeof schema . info . version === "number" ) {
7268 // This is a very common mistake, so give a helpful error message
7369 throw ono . syntax ( 'API version number must be a string (e.g. "1.0.0") not a number.' ) ;
7470 }
@@ -79,15 +75,11 @@ SwaggerParser.prototype.parse = async function (path, api, options, callback) {
7975 else {
8076 let supportedVersions = [ "3.0.0" , "3.0.1" , "3.0.2" , "3.0.3" ] ;
8177
82- // Verify that the parsed object is a Openapi API
83- if ( schema . openapi === undefined || schema . info === undefined || schema . paths === undefined ) {
84- throw ono . syntax ( `${ args . path || args . schema } is not a valid Openapi API definition` ) ;
85- }
86- else if ( typeof schema . openapi === "number" ) {
78+ if ( typeof schema . openapi === "number" ) {
8779 // This is a very common mistake, so give a helpful error message
8880 throw ono . syntax ( 'Openapi version number must be a string (e.g. "3.0.0") not a number.' ) ;
8981 }
90- else if ( typeof schema . info . version === "number" ) {
82+ else if ( schema . info && typeof schema . info . version === "number" ) {
9183 // This is a very common mistake, so give a helpful error message
9284 throw ono . syntax ( 'API version number must be a string (e.g. "1.0.0") not a number.' ) ;
9385 }
0 commit comments