Skip to content

feat: add rule to validate query and querystring parameters usage#2551

Open
n0rahh wants to merge 15 commits intomainfrom
feat/add-support-for-querystring
Open

feat: add rule to validate query and querystring parameters usage#2551
n0rahh wants to merge 15 commits intomainfrom
feat/add-support-for-querystring

Conversation

@n0rahh
Copy link
Contributor

@n0rahh n0rahh commented Feb 10, 2026

What/Why/How?

A new rule has been added because if any parameters are in in: query, you cannot use in: querystring, and vice versa.

Reference

https://github.com/Redocly/redocly/issues/15509

Testing

Screenshots (optional)

Check yourself

  • Code changed? - Tested with Redoc/Realm/Reunite (internal)
  • All new/updated code is covered by tests
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2026

🦋 Changeset detected

Latest commit: 5d7330b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/openapi-core Minor
@redocly/cli Minor
@redocly/respect-core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@n0rahh n0rahh added the snapshot Create experimental release PR label Feb 10, 2026
@github-actions
Copy link
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1770712109 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1770712109
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1770712109
# or
npm install @redocly/respect-core@0.0.0-snapshot.1770712109

⚠️ Note: This is a development build and may contain unstable features.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 79.49% (🎯 78%) 6348 / 7985
🔵 Statements 78.92% (🎯 78%) 6557 / 8308
🔵 Functions 83.42% (🎯 82%) 1304 / 1563
🔵 Branches 71.01% (🎯 70%) 4313 / 6073
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/config/all.ts 100% 100% 100% 100%
packages/core/src/config/minimal.ts 100% 100% 100% 100%
packages/core/src/config/recommended-strict.ts 100% 100% 100% 100%
packages/core/src/config/recommended.ts 100% 100% 100% 100%
packages/core/src/config/spec.ts 100% 100% 100% 100%
packages/core/src/rules/oas3/index.ts 100% 100% 100% 100%
packages/core/src/rules/oas3/spec-querystring-parameters.ts 100% 83.33% 100% 100%
packages/core/src/types/redocly-yaml.ts 92.3% 82.85% 100% 91.93% 366-373, 375, 520-525, 528-533, 536-541
Generated in workflow #8629 for commit 5d7330b by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

CLI Version Mean Time ± Std Dev (s) Relative Performance (Lower is Faster)
cli-latest 3.561s ± 0.059s ▓ 1.00x
cli-next 3.545s ± 0.027s ▓ 1.00x (Fastest)

@n0rahh n0rahh marked this pull request as ready for review February 10, 2026 09:20
@n0rahh n0rahh requested review from a team as code owners February 10, 2026 09:20
"@redocly/cli": minor
---

Added `spec-no-mixed-query-and-querystring-parameters` rule to validate `query` and `querystring` parameter usage in OpenAPI 3.2.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's also worth checking that it's the only one querystring declared on the Operation/PathItem to follow the other part of the spec restriction (https://spec.openapis.org/oas/v3.2.0.html#parameter-locations)? I'd suggest renaming the rule to something more general then, i.e. to spec-querystring-parameters.

@n0rahh n0rahh requested a review from tatomyr February 12, 2026 10:59
},

Parameter(parameter: Oas3Parameter, ctx: UserContext) {
const location = ctx.parentLocations.PathItem.child(['parameters', ctx.key]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit too complicated. Cannot we simply use the ctx.location or something similar instead?

return parameters.filter((p) => !('$ref' in p) && p.in === 'querystring').length;
}

const QUERYSTRING_ONCE_MESSAGE =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't make sense to declare a const. Simply use it in place.

}

const QUERYSTRING_ONCE_MESSAGE =
'Parameters with `in: querystring` should be defined only once per path/operation parameter set (OpenAPI 3.2).';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Parameters with `in: querystring` should be defined only once per path/operation parameter set (OpenAPI 3.2).';
'Parameters with `in: querystring` should be defined only once per path/operation parameter set.';

I don't think it's needed.

@n0rahh n0rahh requested a review from tatomyr February 13, 2026 09:10
@JLekawa
Copy link
Contributor

JLekawa commented Feb 13, 2026

@tatomyr: should this rule be documented in Built-in rules?

@tatomyr
Copy link
Collaborator

tatomyr commented Feb 13, 2026

@JLekawa certainly. And not only there but in some other places perhaps too (sidebars, rulesets, the rule's documentation page itself, etc.). @n0rahh please add the corresponding docs as well and mark the corresponding point:

image

import { BaseResolver } from '../../../resolve.js';
import { createConfig } from '../../../config/index.js';

describe('OAS3 spec-querystring-parameters (OAS 3.2)', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although querystring was introduced in 3.2, this rule also included into other that 3.2 specs, do we need to mention (OAS 3.2) in describe?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it won't appear on other spec flavours.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you mean in the describe's message? Let it remain there for the sake of clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now it makes sense to keep it, I did the changes that @tatomyr suggested below

@tatomyr
Copy link
Collaborator

tatomyr commented Feb 13, 2026

Please disregard the failing smokes. They are related to a separate issue.

@n0rahh n0rahh requested a review from JLekawa February 13, 2026 11:00

# spec-querystring-parameters

Enforce valid use of parameters with `in: querystring` (OpenAPI 3.2).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Enforce valid use of parameters with `in: querystring` (OpenAPI 3.2).
Enforces valid use of querystring parameters.

Please follow the style of other documents.


| Option | Type | Description |
| -------- | ------ | ------------------------------------------------------------------------------------------------- |
| severity | string | Possible values: `off`, `warn`, `error`. Default `off` (3.0/3.1), `error` in `recommended` (3.2). |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| severity | string | Possible values: `off`, `warn`, `error`. Default `off` (3.0/3.1), `error` in `recommended` (3.2). |
| severity | string | Possible values: `off`, `warn`, `error`. Default `error` (in `recommended` configuration). |

/search:
get:
parameters:
- name: qs1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coudl you come up with something meaningful? This is the documentation that our users will face, and as a user I'd love to see a well-thought example.

Comment on lines +105 to +107
- [path-not-include-query](./path-not-include-query.md)
- [operation-parameters-unique](./operation-parameters-unique.md)
- [configurable rules](../configurable-rules.md)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- [path-not-include-query](./path-not-include-query.md)
- [operation-parameters-unique](./operation-parameters-unique.md)
- [configurable rules](../configurable-rules.md)
- [path-not-include-query](./path-not-include-query.md) # -- not sure about this one
- [operation-parameters-unique](./operation-parameters-unique.md)

- [security-defined](./oas/security-defined.md): Security rules must be defined, either globally or per-operation
- [struct](./common/struct.md): Conform to the declared OpenAPI specification version
- [spec-components-invalid-map-name](./oas/spec-components-invalid-map-name.md): Use only alphanumeric and basic punctuation as key names in the components section
- [spec-querystring-parameters](./oas/spec-querystring-parameters.md): Enforce valid use of `in: querystring` (OpenAPI 3.2): at most one per path/operation, and not mixed with `in: query`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also check if we need to add the rule reference to a sidebar.

@tatomyr
Copy link
Collaborator

tatomyr commented Feb 13, 2026

Left comments mostly related to the docs.
cc @JLekawa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snapshot Create experimental release PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants