diff --git a/__tests__/__fixtures__/very-invalid-oas.json b/__tests__/__fixtures__/very-invalid-oas.json new file mode 100644 index 000000000..f91548ea4 --- /dev/null +++ b/__tests__/__fixtures__/very-invalid-oas.json @@ -0,0 +1,61 @@ +{ + "openapi": "3.0.0", + "info": { + "description": "This OpenAPI definition has a typod `servers.url` and `paths.**.tags` properties.", + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "servers": [ + { + "urll": "http://petstore.swagger.io/v2" + } + ], + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + } + ], + "paths": { + "/pet/findByStatus": { + "get": { + "tagss": [ + "pet" + ], + "summary": "Finds Pets by status", + "description": "Multiple status values can be provided with comma separated strings", + "operationId": "findPetsByStatus", + "parameters": [ + { + "name": "status", + "in": "query", + "description": "Status values that need to be considered for filter", + "required": true, + "explode": true, + "schema": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "available", + "pending", + "sold" + ], + "default": "available" + } + } + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + } + } +} diff --git a/__tests__/cmds/openapi/__snapshots__/validate.test.ts.snap b/__tests__/cmds/openapi/__snapshots__/validate.test.ts.snap index 51c0ffc8b..cf0fc91a3 100644 --- a/__tests__/cmds/openapi/__snapshots__/validate.test.ts.snap +++ b/__tests__/cmds/openapi/__snapshots__/validate.test.ts.snap @@ -148,6 +148,30 @@ jobs: " `; +exports[`rdme openapi:validate error handling should throw an error if an invalid API definition has many errors 1`] = ` +[SyntaxError: OpenAPI schema validation failed. + +REQUIRED must have required property 'url' + + 7 | }, + 8 | "servers": [ +> 9 | { + | ^ ☹️ url is missing here! + 10 | "urll": "http://petstore.swagger.io/v2" + 11 | } + 12 | ], + +ADDITIONAL PROPERTY must NOT have additional properties + + 24 | "/pet/findByStatus": { + 25 | "get": { +> 26 | "tagss": [ + | ^^^^^^^ 😲 tagss is not expected to be here! + 27 | "pet" + 28 | ], + 29 | "summary": "Finds Pets by status",] +`; + exports[`rdme openapi:validate error handling should throw an error if an invalid OpenAPI 3.1 definition is supplied 1`] = ` [SyntaxError: OpenAPI schema validation failed. diff --git a/__tests__/cmds/openapi/validate.test.ts b/__tests__/cmds/openapi/validate.test.ts index 84fd17fa9..dfa768296 100644 --- a/__tests__/cmds/openapi/validate.test.ts +++ b/__tests__/cmds/openapi/validate.test.ts @@ -107,6 +107,10 @@ describe('rdme openapi:validate', () => { it('should throw an error if an invalid Swagger definition is supplied', () => { return expect(validate.run({ spec: './__tests__/__fixtures__/invalid-swagger.json' })).rejects.toMatchSnapshot(); }); + + it('should throw an error if an invalid API definition has many errors', () => { + return expect(validate.run({ spec: './__tests__/__fixtures__/very-invalid-oas.json' })).rejects.toMatchSnapshot(); + }); }); describe('CI tests', () => { diff --git a/package-lock.json b/package-lock.json index 84f70617d..b62c99d02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,8 +25,8 @@ "jsonpath": "^1.1.1", "mime-types": "^2.1.35", "node-fetch": "^2.6.1", - "oas": "^18.4.4", - "oas-normalize": "^7.0.0", + "oas": "^19.0.1", + "oas-normalize": "^7.1.0", "open": "^8.2.1", "ora": "^5.4.1", "parse-link-header": "^2.0.0", @@ -1514,9 +1514,9 @@ "dev": true }, "node_modules/@readme/openapi-parser": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@readme/openapi-parser/-/openapi-parser-2.2.0.tgz", - "integrity": "sha512-t5E+cCln50GSsOx0GuT+GLnkG6Ux7I6V1vWJ48jvW7Rxs6jMkJrVYMu5MIhJ3ihylrFspxJ6aSACzj7yVr6Dow==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@readme/openapi-parser/-/openapi-parser-2.3.0.tgz", + "integrity": "sha512-/aR/sE8qAzIB50zK22MZPau5wXg2/Gu2sgfcbIa4DLaEMX2JR4f4Rh1RBnHfqbWuS7OxTKqdyOM5Ajp/mIy52Q==", "dependencies": { "@apidevtools/openapi-schemas": "^2.1.0", "@apidevtools/swagger-methods": "^3.0.2", @@ -1534,19 +1534,6 @@ "openapi-types": ">=7" } }, - "node_modules/@readme/openapi-parser/node_modules/ajv-draft-04": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/ajv-draft-04/-/ajv-draft-04-1.0.0.tgz", - "integrity": "sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw==", - "peerDependencies": { - "ajv": "^8.5.0" - }, - "peerDependenciesMeta": { - "ajv": { - "optional": true - } - } - }, "node_modules/@sinclair/typebox": { "version": "0.24.22", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.24.22.tgz", @@ -2185,6 +2172,19 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/ajv-draft-04": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ajv-draft-04/-/ajv-draft-04-1.0.0.tgz", + "integrity": "sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw==", + "peerDependencies": { + "ajv": "^8.5.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, "node_modules/ansi-align": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz", @@ -7895,9 +7895,9 @@ } }, "node_modules/oas": { - "version": "18.4.4", - "resolved": "https://registry.npmjs.org/oas/-/oas-18.4.4.tgz", - "integrity": "sha512-m1r6vPRnNbPVfhXWiuFuK3JlneI0717iMHqsj9MaCF/lCQ7nAdX2sklqgQmKnnG8Jg6INHgP3oaHcHSuBfZooQ==", + "version": "19.0.1", + "resolved": "https://registry.npmjs.org/oas/-/oas-19.0.1.tgz", + "integrity": "sha512-DSEtgLnpoQEamgfJKVC8Hs0BlNIYW5+eb4bfB8Rpuej4glYm0CT0yElcW3v8L+hB5HZCdlfwukPsyNYRSbyQ9Q==", "dependencies": { "@readme/json-schema-ref-parser": "^1.1.0", "@types/json-schema": "^7.0.11", @@ -7945,11 +7945,11 @@ } }, "node_modules/oas-normalize": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/oas-normalize/-/oas-normalize-7.0.0.tgz", - "integrity": "sha512-K/ChGYwdXPR1Vl0fnIdeAmEeQIw/MV90QmRL3DLsRGIS27/VaDn+ChMZ0GvTrE2lxjlDiGkm8cgKqS95F2jQNQ==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/oas-normalize/-/oas-normalize-7.1.0.tgz", + "integrity": "sha512-a3rWTwmePXGFq8lutfCR3cFC5DerKXZW+Rd1U9t1TJUsedVng40DxG8P+rYBaoe/MWQKfy5reid8gWD7QSzaHg==", "dependencies": { - "@readme/openapi-parser": "^2.2.0", + "@readme/openapi-parser": "^2.3.0", "js-yaml": "^4.1.0", "node-fetch": "^2.6.1", "openapi-types": "^12.0.0", @@ -11623,9 +11623,9 @@ "dev": true }, "@readme/openapi-parser": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@readme/openapi-parser/-/openapi-parser-2.2.0.tgz", - "integrity": "sha512-t5E+cCln50GSsOx0GuT+GLnkG6Ux7I6V1vWJ48jvW7Rxs6jMkJrVYMu5MIhJ3ihylrFspxJ6aSACzj7yVr6Dow==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@readme/openapi-parser/-/openapi-parser-2.3.0.tgz", + "integrity": "sha512-/aR/sE8qAzIB50zK22MZPau5wXg2/Gu2sgfcbIa4DLaEMX2JR4f4Rh1RBnHfqbWuS7OxTKqdyOM5Ajp/mIy52Q==", "requires": { "@apidevtools/openapi-schemas": "^2.1.0", "@apidevtools/swagger-methods": "^3.0.2", @@ -11635,14 +11635,6 @@ "ajv": "^8.11.0", "ajv-draft-04": "^1.0.0", "call-me-maybe": "^1.0.1" - }, - "dependencies": { - "ajv-draft-04": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/ajv-draft-04/-/ajv-draft-04-1.0.0.tgz", - "integrity": "sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw==", - "requires": {} - } } }, "@sinclair/typebox": { @@ -12167,6 +12159,12 @@ "uri-js": "^4.2.2" } }, + "ajv-draft-04": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ajv-draft-04/-/ajv-draft-04-1.0.0.tgz", + "integrity": "sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw==", + "requires": {} + }, "ansi-align": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz", @@ -16359,9 +16357,9 @@ } }, "oas": { - "version": "18.4.4", - "resolved": "https://registry.npmjs.org/oas/-/oas-18.4.4.tgz", - "integrity": "sha512-m1r6vPRnNbPVfhXWiuFuK3JlneI0717iMHqsj9MaCF/lCQ7nAdX2sklqgQmKnnG8Jg6INHgP3oaHcHSuBfZooQ==", + "version": "19.0.1", + "resolved": "https://registry.npmjs.org/oas/-/oas-19.0.1.tgz", + "integrity": "sha512-DSEtgLnpoQEamgfJKVC8Hs0BlNIYW5+eb4bfB8Rpuej4glYm0CT0yElcW3v8L+hB5HZCdlfwukPsyNYRSbyQ9Q==", "requires": { "@readme/json-schema-ref-parser": "^1.1.0", "@types/json-schema": "^7.0.11", @@ -16430,11 +16428,11 @@ } }, "oas-normalize": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/oas-normalize/-/oas-normalize-7.0.0.tgz", - "integrity": "sha512-K/ChGYwdXPR1Vl0fnIdeAmEeQIw/MV90QmRL3DLsRGIS27/VaDn+ChMZ0GvTrE2lxjlDiGkm8cgKqS95F2jQNQ==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/oas-normalize/-/oas-normalize-7.1.0.tgz", + "integrity": "sha512-a3rWTwmePXGFq8lutfCR3cFC5DerKXZW+Rd1U9t1TJUsedVng40DxG8P+rYBaoe/MWQKfy5reid8gWD7QSzaHg==", "requires": { - "@readme/openapi-parser": "^2.2.0", + "@readme/openapi-parser": "^2.3.0", "js-yaml": "^4.1.0", "node-fetch": "^2.6.1", "openapi-types": "^12.0.0", diff --git a/package.json b/package.json index aa45eba90..be327e62b 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,8 @@ "jsonpath": "^1.1.1", "mime-types": "^2.1.35", "node-fetch": "^2.6.1", - "oas": "^18.4.4", - "oas-normalize": "^7.0.0", + "oas": "^19.0.1", + "oas-normalize": "^7.1.0", "open": "^8.2.1", "ora": "^5.4.1", "parse-link-header": "^2.0.0",