|
| 1 | +--- |
| 2 | +slug: /docs/cli/rules/oas/spec-querystring-parameters |
| 3 | +--- |
| 4 | + |
| 5 | +# spec-querystring-parameters |
| 6 | + |
| 7 | +Enforces valid use of `querystring` parameters. |
| 8 | + |
| 9 | +| OAS | Compatibility | |
| 10 | +| --- | ------------- | |
| 11 | +| 2.0 | ❌ | |
| 12 | +| 3.0 | ❌ | |
| 13 | +| 3.1 | ❌ | |
| 14 | +| 3.2 | ✅ | |
| 15 | + |
| 16 | +## API design principles |
| 17 | + |
| 18 | +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`). |
| 19 | + |
| 20 | +This rule ensures that: |
| 21 | + |
| 22 | +- There is at most one `querystring` parameter. |
| 23 | + Parameters with `in: querystring` may be defined only once per path/operation parameter set. |
| 24 | +- No mixing `querystring` with `query`. |
| 25 | + Parameters with `in: query` cannot be used together with `in: querystring` in the same operation/path parameter set. |
| 26 | + |
| 27 | +## Configuration |
| 28 | + |
| 29 | +| Option | Type | Description | |
| 30 | +| -------- | ------ | ------------------------------------------------------------------------------------------ | |
| 31 | +| severity | string | Possible values: `off`, `warn`, `error`. Default `error` (in `recommended` configuration). | |
| 32 | + |
| 33 | +An example configuration: |
| 34 | + |
| 35 | +```yaml |
| 36 | +rules: |
| 37 | + spec-querystring-parameters: error |
| 38 | +``` |
| 39 | +
|
| 40 | +## Examples |
| 41 | +
|
| 42 | +Given this configuration: |
| 43 | +
|
| 44 | +```yaml |
| 45 | +rules: |
| 46 | + spec-querystring-parameters: error |
| 47 | +``` |
| 48 | +
|
| 49 | +Example of **incorrect** use (mixing `query` and `querystring`): |
| 50 | + |
| 51 | +```yaml |
| 52 | +paths: |
| 53 | + /events: |
| 54 | + get: |
| 55 | + summary: List events |
| 56 | + parameters: |
| 57 | + - name: timezone |
| 58 | + in: query |
| 59 | + schema: |
| 60 | + type: string |
| 61 | + default: UTC |
| 62 | + - name: criteria |
| 63 | + in: querystring |
| 64 | + content: |
| 65 | + application/x-www-form-urlencoded: |
| 66 | + schema: |
| 67 | + type: object |
| 68 | + properties: |
| 69 | + startDate: { type: string, format: date } |
| 70 | + endDate: { type: string, format: date } |
| 71 | + status: { type: string, enum: [scheduled, cancelled, completed] } |
| 72 | +``` |
| 73 | + |
| 74 | +Example of **incorrect** use (multiple `querystring` parameters): |
| 75 | + |
| 76 | +```yaml |
| 77 | +paths: |
| 78 | + /events: |
| 79 | + get: |
| 80 | + summary: List events |
| 81 | + parameters: |
| 82 | + - name: filters |
| 83 | + in: querystring |
| 84 | + content: |
| 85 | + application/x-www-form-urlencoded: |
| 86 | + schema: |
| 87 | + type: object |
| 88 | + properties: |
| 89 | + startDate: { type: string, format: date } |
| 90 | + status: { type: string } |
| 91 | + - name: pagination |
| 92 | + in: querystring |
| 93 | + content: |
| 94 | + application/x-www-form-urlencoded: |
| 95 | + schema: |
| 96 | + type: object |
| 97 | + properties: |
| 98 | + limit: { type: integer } |
| 99 | + offset: { type: integer } |
| 100 | +``` |
| 101 | + |
| 102 | +Example of **correct** use (single `querystring` parameter, no `query`): |
| 103 | + |
| 104 | +```yaml |
| 105 | +paths: |
| 106 | + /events: |
| 107 | + get: |
| 108 | + summary: List events |
| 109 | + parameters: |
| 110 | + - name: params |
| 111 | + in: querystring |
| 112 | + content: |
| 113 | + application/x-www-form-urlencoded: |
| 114 | + schema: |
| 115 | + type: object |
| 116 | + properties: |
| 117 | + startDate: { type: string, format: date } |
| 118 | + endDate: { type: string, format: date } |
| 119 | + status: { type: string, enum: [scheduled, cancelled, completed] } |
| 120 | + limit: { type: integer, default: 20 } |
| 121 | + offset: { type: integer, default: 0 } |
| 122 | +``` |
| 123 | + |
| 124 | +## Related rules |
| 125 | + |
| 126 | +- [operation-parameters-unique](./operation-parameters-unique.md) |
| 127 | + |
| 128 | +## Resources |
| 129 | + |
| 130 | +- [Rule source](https://github.com/Redocly/redocly-cli/blob/main/packages/core/src/rules/oas3/spec-querystring-parameters.ts) |
| 131 | +- [OpenAPI 3.2 Parameter object](https://spec.openapis.org/oas/3.2.0#parameter-object) |
0 commit comments