-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Misleading error message claiming allowed values in "in" of a parameter only "query, header, cookie" without "path" #1853
Comments
Hi @bingtimren, thanks for the report 😄 This is, indeed, an error quality issue. Behind the scenes, the validation engine is trying to match your parameter against an internally-defined schema for a Path Parameter Object, but doesn't match because |
Like @bingtimren, I am learning the OpenAPI specification and got the same misleading error by forgetting the This is the file I'm working on, as an example, and the corresponding errors below: openapi: '3.0.1'
info:
title: My API
version: 0.1.0
paths:
'/':
get:
responses:
'200':
description: OK
'/audits':
get:
responses:
'501':
description: Not Implemented
tags:
- audits
'/audits/{auditId}':
parameters:
- in: path
name: auditId
# required: true
schema:
type: integer
format: int64
get:
responses:
'501':
description: Not Implemented
tags:
- audits
I am aware that the |
Is a fix for the validator in the works, or still an open issue? |
@ChristianDavis no one is working on it currently, it’s a pretty general issue with the JavaScript JSONSchema validation libraries. Big thing that we want to tackle, but of course there are smaller, more pressing things. If you feel up to the task, let me know here, and I’ll share some more context. |
Still no news ? We also have this issue. |
Same here |
I just ran into the same issue, if I remove
If I add
|
The schema and required fields are not even required based on 3.0.0 openapi spec. Why it needs them to be required ?! |
This error happens not only on the editor (http://editor.swagger.io), but also on Swagger UI itself (when hosted). Adding schema to the parameters solves the issue (no idea why is required, though): parameters:
- name: contactId
in: path
description: ID of contact to return
required: true
schema:
type: integer
format: int64 |
Adding the schema does nothing for me. I copied the first example from this page: https://swagger.io/docs/specification/describing-parameters/ paths:
/users/{userId}:
get:
summary: Get a user by ID
parameters:
- in: path
name: userId
schema:
type: integer
required: true
description: Numeric ID of the user to get and I still get errors:
|
@sirolf2009 have you tried specifying the format for that integer field? paths:
/users/{userId}:
get:
summary: Get a user by ID
parameters:
- in: path
name: userId
schema:
type: integer
format: int64
required: true
description: Numeric ID of the user to get |
@eneko just tried it, still got errors |
oh, sorry, I see, path parameters must be true... |
@kurt-o-sys correct, @sirolf2009, seems like you are missing the The following spec contains both of your examples, and properly validates at https://editor.swagger.com openapi: '3.0.1'
info:
title: My API
version: 0.1.0
paths:
'/':
get:
responses:
'200':
description: OK
'/audits':
get:
responses:
'501':
description: Not Implemented
tags:
- audits
'/audits/{auditId}':
parameters:
- in: path
name: auditId
required: true
schema:
type: integer
format: int64
get:
responses:
'501':
description: Not Implemented
tags:
- audits
/users/{userId}:
get:
summary: Get a user by ID
parameters:
- in: path
name: userId
schema:
type: integer
format: int64
required: true
description: Numeric ID of the user to get
responses:
'200':
description: OK
/api/rss/{periodicity}:
get:
summary: rss feed
operationId: getRss
parameters:
- name: periodicity
in: path
description: periodicity of the rss feed
required: true
schema:
type: string
responses:
'200':
description: OK |
@eneko I did have a responses part, but on closer inspection, I had swagger: '2.0' instead of openapi: '3.0.1' Updating that fixed it |
I've opened a pull request (#1985) that will close this issue. Here's what Swagger Editor reports with my changes:
|
For me it shows that
Seems to fix itself after a hard refresh of the webpage on editor.swagger.io |
* adopt @webron's OpenAPI 3.0 schema from OAI/OpenAPI-Specification#1270 permalink: https://github.com/OAI/OpenAPI-Specification/blob/92e15eba1d4591ebfe8c11898c48241e72854381/schemas/v3.0/schema.yaml * add ajv-errors * address error messages for #1808's Swagger 2.0 example clarifies the schema and adds custom error messages for unclear error conditions * address error messages for #1808's OpenAPI 3.0 example * restrict underlying JSON Schema `type` field to simple types only (for #1832) * fix limitation in JSON Pointer conversion helper * add clear `not` error message (for #1489) * add additionalProperties message (for #1394) * add ajv-keywords * use `switch` to intelligently identify inline vs referenced content (for #1853) * use `switch` to XOR `schema` and `content` (for #1853) * use `switch` to pivot security scheme based on type (for #1672) * use switch to fall-through to inline security scheme validation (for #1672) * rewrite more Reference oneOfs (for #1519) * add custom message for `Schema.required` type error (for #1519) * rewrite Response/Reference oneOf (for #1489) * use switch in ParameterLocation validation (for #1797) * define pivot key switches for SecurityDefinitions (for #1711) * give helpful `format: uri` messages for SecurityDefinitions (for #1711) * eliminate NonBodyParameter; pivot on `Parameter.in` with a switch (for #1511) * oneOf -> switch for Parameters.items reference * (for #1711) * remove redundant semantic validator (for #1511) * adjust wording of custom error message (for #1853) * add regression tests for all related issues * revert to expect@^1.20.2 * linter fixes * fix messaging flaw for #1832 * improve messaging for #1394 * use literal key for `$ref` in Reference Object * remove commented legacy data from OAS3 schema * remove superfluous quotation marks * normalize test case paths to `/` * normalize openapi fields to 3.0.0 * drop unused `paths` information * ensure clear errors for 3.0 Parameter style/content exclusivity * add `required` assertions to switch statements that pivot on a key's value this prevents false positives when the pivot key is missing entirely * remove stray space
…i#1985) * adopt @webron's OpenAPI 3.0 schema from OAI/OpenAPI-Specification#1270 permalink: https://github.com/OAI/OpenAPI-Specification/blob/92e15eba1d4591ebfe8c11898c48241e72854381/schemas/v3.0/schema.yaml * add ajv-errors * address error messages for swagger-api#1808's Swagger 2.0 example clarifies the schema and adds custom error messages for unclear error conditions * address error messages for swagger-api#1808's OpenAPI 3.0 example * restrict underlying JSON Schema `type` field to simple types only (for swagger-api#1832) * fix limitation in JSON Pointer conversion helper * add clear `not` error message (for swagger-api#1489) * add additionalProperties message (for swagger-api#1394) * add ajv-keywords * use `switch` to intelligently identify inline vs referenced content (for swagger-api#1853) * use `switch` to XOR `schema` and `content` (for swagger-api#1853) * use `switch` to pivot security scheme based on type (for swagger-api#1672) * use switch to fall-through to inline security scheme validation (for swagger-api#1672) * rewrite more Reference oneOfs (for swagger-api#1519) * add custom message for `Schema.required` type error (for swagger-api#1519) * rewrite Response/Reference oneOf (for swagger-api#1489) * use switch in ParameterLocation validation (for swagger-api#1797) * define pivot key switches for SecurityDefinitions (for swagger-api#1711) * give helpful `format: uri` messages for SecurityDefinitions (for swagger-api#1711) * eliminate NonBodyParameter; pivot on `Parameter.in` with a switch (for swagger-api#1511) * oneOf -> switch for Parameters.items reference * (for swagger-api#1711) * remove redundant semantic validator (for swagger-api#1511) * adjust wording of custom error message (for swagger-api#1853) * add regression tests for all related issues * revert to expect@^1.20.2 * linter fixes * fix messaging flaw for swagger-api#1832 * improve messaging for swagger-api#1394 * use literal key for `$ref` in Reference Object * remove commented legacy data from OAS3 schema * remove superfluous quotation marks * normalize test case paths to `/` * normalize openapi fields to 3.0.0 * drop unused `paths` information * ensure clear errors for 3.0 Parameter style/content exclusivity * add `required` assertions to switch statements that pivot on a key's value this prevents false positives when the pivot key is missing entirely * remove stray space
Q&A (please complete the following information)
Content & configuration
Example Swagger/OpenAPI definition:
Swagger-Editor configuration options:
Describe the bug you're encountering
This is a file I'm working on. When I still have not defined the schema for a path parameter, editor reports an error at the "in" property, claiming the allowed values are only "query, header, cookie". This is very confusing and in fact wrong. If I just complete the parameter definition by providing it's schema, this error is not reported, although the value for "in" is still "path".
As a learner myself to the OpenAPI specification I was quite confused by the misleading error, and spent much time consulting with documents and examples, then finally concluded that it's a false alarm.
To reproduce...
Steps to reproduce the behavior:
Load the sample definition
Expected behavior
The error should not be reported in the first place. Or, if that's not possible or difficult, at least make the message not so misleading.
Screenshots
See above
Additional context or thoughts
The text was updated successfully, but these errors were encountered: