Skip to content

Commit

Permalink
fix(oas): improve invalid paramaters detection (#1430)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Mar 8, 2021
1 parent 1691892 commit fa93c64
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"test": "jest --silent"
},
"dependencies": {
"@stoplight/better-ajv-errors": "0.0.3",
"@stoplight/better-ajv-errors": "0.0.4",
"@stoplight/json": "3.10.2",
"@stoplight/json-ref-readers": "1.2.1",
"@stoplight/json-ref-resolver": "3.1.1",
Expand Down
16 changes: 16 additions & 0 deletions src/cli/services/__tests__/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,22 @@ describe('Linter service', () => {
},
source: expect.stringContaining('__tests__/__fixtures__/refs/contact.json'),
}),
expect.objectContaining({
code: 'oas2-schema',
message: '`description` property type should be string.', // this is covered by 'info-description' as well
path: ['description'],
range: {
end: {
character: 18,
line: 2,
},
start: {
character: 17,
line: 2,
},
},
source: expect.stringContaining('__tests__/__fixtures__/refs/contact.json'),
}),
expect.objectContaining({
code: 'oas2-schema',
message: 'Property `response` is not expected to be here.',
Expand Down
16 changes: 11 additions & 5 deletions test-harness/scenarios/oas3-schema.scenario
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ paths:
required: true
schema:
type: [string, number]
- name: alias
in: path
type: string
required: true
example: Joe
responses:
"200":
description: An Example
Expand Down Expand Up @@ -55,9 +60,10 @@ OpenAPI 3.x detected
5:11 error oas3-schema Property `foo` is not expected to be here. info.contact
12:11 error oas3-schema Property `type` is not expected to be here. paths./user.get.parameters[0]
23:18 error oas3-schema `type` property type should be string. paths./user.get.parameters[1].schema.type
32:28 error oas3-schema `user_id` property type should be object. paths./user.get.responses[200].content.application/json.schema.properties.user_id
36:28 error oas3-schema `properties` property type should be object. paths./user.get.responses[200].content.application/yaml.schema.properties
38:23 error oas3-schema `description` property type should be string. paths./user.get.responses[400].description
41:17 error oas3-schema `responses` property should not have fewer than 1 properties. paths./address.get.responses
24:11 error oas3-schema Property `type` is not expected to be here. paths./user.get.parameters[2]
37:28 error oas3-schema `user_id` property type should be object. paths./user.get.responses[200].content.application/json.schema.properties.user_id
41:28 error oas3-schema `properties` property type should be object. paths./user.get.responses[200].content.application/yaml.schema.properties
43:23 error oas3-schema `description` property type should be string. paths./user.get.responses[400].description
46:17 error oas3-schema `responses` property should not have fewer than 1 properties. paths./address.get.responses

7 problems (7 errors, 0 warnings, 0 infos, 0 hints)
8 problems (8 errors, 0 warnings, 0 infos, 0 hints)
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,10 @@
dependencies:
type-detect "4.0.8"

"@stoplight/better-ajv-errors@0.0.3":
version "0.0.3"
resolved "https://registry.yarnpkg.com/@stoplight/better-ajv-errors/-/better-ajv-errors-0.0.3.tgz#8d47a511aca89e0027cf748785910fbb25d7c54f"
integrity sha512-q3PoPiYZdzfJjQ+q6ifuLVFx3dBKRxW1OBGxnLAoDlamYb+GJUNiaSLB32L6OB4fi6h/TsY21lZB7y7aYFM7tQ==
"@stoplight/better-ajv-errors@0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@stoplight/better-ajv-errors/-/better-ajv-errors-0.0.4.tgz#2147e0e4e9918519e885e74b15aa458a89eb2337"
integrity sha512-HFXOerq/6/6YisiTJwCOScwfNaXyGmX7ROAEUoKOrckK9+hJ/QLFm5EofQYEgX4aXkvHokLEbWBs4NMwZ6hQUw==
dependencies:
jsonpointer "^4.0.1"
leven "^3.1.0"
Expand Down

0 comments on commit fa93c64

Please sign in to comment.