Skip to content

Commit 45fdd70

Browse files
authored
Fix error message (#267)
1 parent 9e2d461 commit 45fdd70

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/index.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,11 @@ class SwaggerParser extends $RefParser {
4343
let schema = await super.parse(args.path, args.schema, args.options);
4444

4545
if (schema.swagger) {
46-
// Verify that the parsed object is a Swagger API
47-
if (schema.swagger === undefined || schema.info === undefined || schema.paths === undefined) {
48-
throw ono.syntax(`${args.path || args.schema} is not a valid Swagger API definition`);
49-
}
50-
else if (typeof schema.swagger === "number") {
46+
if (typeof schema.swagger === "number") {
5147
// This is a very common mistake, so give a helpful error message
5248
throw ono.syntax('Swagger version number must be a string (e.g. "2.0") not a number.');
5349
}
54-
else if (typeof schema.info.version === "number") {
50+
else if (schema.info && typeof schema.info.version === "number") {
5551
// This is a very common mistake, so give a helpful error message
5652
throw ono.syntax('API version number must be a string (e.g. "1.0.0") not a number.');
5753
}
@@ -60,11 +56,7 @@ class SwaggerParser extends $RefParser {
6056
}
6157
}
6258
else {
63-
// Verify that the parsed object is a Openapi API
64-
if (schema.openapi === undefined || schema.info === undefined) {
65-
throw ono.syntax(`${args.path || args.schema} is not a valid Openapi API definition`);
66-
}
67-
else if (schema.paths === undefined) {
59+
if (schema.paths === undefined) {
6860
if (supported31Versions.indexOf(schema.openapi) !== -1) {
6961
if (schema.webhooks === undefined) {
7062
throw ono.syntax(`${args.path || args.schema} is not a valid Openapi API definition`);
@@ -78,7 +70,7 @@ class SwaggerParser extends $RefParser {
7870
// This is a very common mistake, so give a helpful error message
7971
throw ono.syntax('Openapi version number must be a string (e.g. "3.0.0") not a number.');
8072
}
81-
else if (typeof schema.info.version === "number") {
73+
else if (schema.info && typeof schema.info.version === "number") {
8274
// This is a very common mistake, so give a helpful error message
8375
throw ono.syntax('API version number must be a string (e.g. "1.0.0") not a number.');
8476
}

0 commit comments

Comments
 (0)