Skip to content

Commit

Permalink
fix: surface all validation errors (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored Oct 17, 2022
1 parent 89d1914 commit 39b2c61
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 45 deletions.
61 changes: 61 additions & 0 deletions __tests__/__fixtures__/very-invalid-oas.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
24 changes: 24 additions & 0 deletions __tests__/cmds/openapi/__snapshots__/validate.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions __tests__/cmds/openapi/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
84 changes: 41 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 39b2c61

Please sign in to comment.