Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(oas): improve invalid paramaters detection #1430

Merged
merged 1 commit into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"test": "jest --silent"
},
"dependencies": {
"@stoplight/better-ajv-errors": "0.0.3",
"@stoplight/better-ajv-errors": "0.0.4",
"@stoplight/json": "3.9.0",
"@stoplight/json-ref-readers": "1.2.1",
"@stoplight/json-ref-resolver": "3.1.0",
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 @@ -667,6 +667,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 @@ -1162,10 +1162,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