-
Notifications
You must be signed in to change notification settings - Fork 218
feat: add rule to validate query and querystring parameters usage #2551
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d19469a
feat: add rule to validate query and querystring parameter usage in O…
n0rahh c29879a
Merge branch 'main' into feat/add-support-for-querystring
n0rahh 6a6d15f
Merge branch 'main' into feat/add-support-for-querystring
n0rahh 7fc64f9
fix: cr fixes
n0rahh d2a3d37
Merge branch 'main' into feat/add-support-for-querystring
n0rahh c4b3781
fix: enhance querystring parameter validation
n0rahh d8d5c70
Merge branch 'main' into feat/add-support-for-querystring
n0rahh 65d7edf
fix: simplify querystring parameter error messages and improve valida…
n0rahh 0470969
Merge branch 'main' into feat/add-support-for-querystring
n0rahh 0431ac1
Apply suggestion from @JLekawa
JLekawa 1835524
docs: update docs
n0rahh 7e4e1f7
fix: keep 'spec-querystring-parameters' rule within 3.2
n0rahh 23942d3
docs: correct formatting in 'spec-querystring-parameters' documentation
n0rahh b61bf55
Merge branch 'main' into feat/add-support-for-querystring
n0rahh 5d7330b
Apply suggestions from code review
JLekawa d98c58b
fix: docs refactor
n0rahh ba04384
Merge branch 'main' into feat/add-support-for-querystring
n0rahh 462abf1
Apply suggestion from @JLekawa
JLekawa c311a23
Merge branch 'main' into feat/add-support-for-querystring
n0rahh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@redocly/openapi-core": minor | ||
| "@redocly/cli": minor | ||
| --- | ||
|
|
||
| Added the `spec-querystring-parameters` rule (OpenAPI 3.2). | ||
| This rule enforces that `query` and `querystring` are not mixed in the same operation/path parameter set, and that at most one `querystring` parameter is declared per operation or path. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| --- | ||
| slug: /docs/cli/rules/oas/spec-querystring-parameters | ||
| --- | ||
|
|
||
| # spec-querystring-parameters | ||
|
|
||
| Enforces valid use of `querystring` parameters. | ||
|
|
||
| | OAS | Compatibility | | ||
| | --- | ------------- | | ||
| | 2.0 | ❌ | | ||
| | 3.0 | ❌ | | ||
| | 3.1 | ❌ | | ||
| | 3.2 | ✅ | | ||
|
|
||
| ## API design principles | ||
|
|
||
| OpenAPI 3.2 introduces the `querystring` parameter location for representing the full query string as a single schema (e.g. `application/x-www-form-urlencoded`). | ||
|
|
||
| This rule ensures that: | ||
|
|
||
| - There is at most one `querystring` parameter. | ||
| Parameters with `in: querystring` may be defined only once per path/operation parameter set. | ||
| - No mixing `querystring` with `query`. | ||
| Parameters with `in: query` cannot be used together with `in: querystring` in the same operation/path parameter set. | ||
|
|
||
| ## Configuration | ||
|
|
||
| | Option | Type | Description | | ||
| | -------- | ------ | ------------------------------------------------------------------------------------------ | | ||
| | severity | string | Possible values: `off`, `warn`, `error`. Default `error` (in `recommended` configuration). | | ||
|
|
||
| An example configuration: | ||
|
|
||
| ```yaml | ||
| rules: | ||
| spec-querystring-parameters: error | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| Given this configuration: | ||
|
|
||
| ```yaml | ||
| rules: | ||
| spec-querystring-parameters: error | ||
| ``` | ||
|
|
||
| Example of **incorrect** use (mixing `query` and `querystring`): | ||
|
|
||
| ```yaml | ||
| paths: | ||
| /events: | ||
| get: | ||
| summary: List events | ||
| parameters: | ||
| - name: timezone | ||
| in: query | ||
| schema: | ||
| type: string | ||
| default: UTC | ||
| - name: criteria | ||
| in: querystring | ||
| content: | ||
| application/x-www-form-urlencoded: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| startDate: { type: string, format: date } | ||
| endDate: { type: string, format: date } | ||
| status: { type: string, enum: [scheduled, cancelled, completed] } | ||
| ``` | ||
|
|
||
| Example of **incorrect** use (multiple `querystring` parameters): | ||
|
|
||
| ```yaml | ||
| paths: | ||
| /events: | ||
| get: | ||
| summary: List events | ||
| parameters: | ||
| - name: filters | ||
| in: querystring | ||
| content: | ||
| application/x-www-form-urlencoded: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| startDate: { type: string, format: date } | ||
| status: { type: string } | ||
| - name: pagination | ||
| in: querystring | ||
| content: | ||
| application/x-www-form-urlencoded: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| limit: { type: integer } | ||
| offset: { type: integer } | ||
| ``` | ||
|
|
||
| Example of **correct** use (single `querystring` parameter, no `query`): | ||
|
|
||
| ```yaml | ||
| paths: | ||
| /events: | ||
| get: | ||
| summary: List events | ||
| parameters: | ||
| - name: params | ||
| in: querystring | ||
| content: | ||
| application/x-www-form-urlencoded: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| startDate: { type: string, format: date } | ||
| endDate: { type: string, format: date } | ||
| status: { type: string, enum: [scheduled, cancelled, completed] } | ||
| limit: { type: integer, default: 20 } | ||
| offset: { type: integer, default: 0 } | ||
| ``` | ||
|
|
||
| ## Related rules | ||
|
|
||
| - [operation-parameters-unique](./operation-parameters-unique.md) | ||
|
|
||
| ## Resources | ||
|
|
||
| - [Rule source](https://github.com/Redocly/redocly-cli/blob/main/packages/core/src/rules/oas3/spec-querystring-parameters.ts) | ||
| - [OpenAPI 3.2 Parameter object](https://spec.openapis.org/oas/3.2.0#parameter-object) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.