@@ -58,24 +58,46 @@ SwaggerParser.prototype.parse = function (path, api, options, callback) {
5858
5959 return $RefParser . prototype . parse . call ( this , args . path , args . schema , args . options )
6060 . then ( function ( schema ) {
61- var supportedSwaggerVersions = [ '2.0' ] ;
61+ if ( schema . swagger ) {
62+ var supportedVersions = [ '2.0' ] ;
6263
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 ( '%s is not a valid Swagger API definition' , args . path || args . schema ) ;
66- }
67- else if ( typeof schema . swagger === 'number' ) {
68- // This is a very common mistake, so give a helpful error message
69- throw ono . syntax ( 'Swagger version number must be a string (e.g. "2.0") not a number.' ) ;
70- }
71- else if ( typeof schema . info . version === 'number' ) {
72- // This is a very common mistake, so give a helpful error message
73- throw ono . syntax ( 'API version number must be a string (e.g. "1.0.0") not a number.' ) ;
74- }
75- else if ( supportedSwaggerVersions . indexOf ( schema . swagger ) === - 1 ) {
76- throw ono . syntax (
77- 'Unsupported Swagger version: %d. Swagger Parser only supports version %s' ,
78- schema . swagger , supportedSwaggerVersions . join ( ', ' ) ) ;
64+ // Verify that the parsed object is a Swagger API
65+ if ( schema . swagger === undefined || schema . info === undefined || schema . paths === undefined ) {
66+ throw ono . syntax ( '%s is not a valid Swagger API definition' , args . path || args . schema ) ;
67+ }
68+ else if ( typeof schema . swagger === 'number' ) {
69+ // This is a very common mistake, so give a helpful error message
70+ throw ono . syntax ( 'Swagger version number must be a string (e.g. "2.0") not a number.' ) ;
71+ }
72+ else if ( typeof schema . info . version === 'number' ) {
73+ // This is a very common mistake, so give a helpful error message
74+ throw ono . syntax ( 'API version number must be a string (e.g. "1.0.0") not a number.' ) ;
75+ }
76+ else if ( supportedVersions . indexOf ( schema . swagger ) === - 1 ) {
77+ throw ono . syntax (
78+ 'Unsupported Swagger version: %d. Swagger Parser only supports version %s' ,
79+ schema . swagger , supportedVersions . join ( ', ' ) ) ;
80+ }
81+ } else {
82+ var supportedVersions = [ '3.0.0' , '3.0.1' ] ;
83+
84+ // Verify that the parsed object is a Openapi API
85+ if ( schema . openapi === undefined || schema . info === undefined || schema . paths === undefined ) {
86+ throw ono . syntax ( '%s is not a valid Openapi API definition' , args . path || args . schema ) ;
87+ }
88+ else if ( typeof schema . openapi === 'number' ) {
89+ // This is a very common mistake, so give a helpful error message
90+ throw ono . syntax ( 'Openapi version number must be a string (e.g. "3.0.0") not a number.' ) ;
91+ }
92+ else if ( typeof schema . info . version === 'number' ) {
93+ // This is a very common mistake, so give a helpful error message
94+ throw ono . syntax ( 'API version number must be a string (e.g. "1.0.0") not a number.' ) ;
95+ }
96+ else if ( supportedVersions . indexOf ( schema . openapi ) === - 1 ) {
97+ throw ono . syntax (
98+ 'Unsupported Openapi version: %d. Openapi Parser only supports version %s' ,
99+ schema . openapi , supportedVersions . join ( ', ' ) ) ;
100+ }
79101 }
80102
81103 // Looks good!
0 commit comments