Skip to content

feat: support the HTTP QUERY method (RFC 10008) - #4007

Open
gentritabazi wants to merge 4 commits into
nestjs:masterfrom
gentritabazi:feat/http-query-method
Open

gentritabazi wants to merge 4 commits into
nestjs:masterfrom
gentritabazi:feat/http-query-method

Conversation

@gentritabazi

@gentritabazi gentritabazi commented Jul 14, 2026

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

PathItemObject has no query operation field, so routes declared with the new HTTP QUERY method (RFC 10008, added to RequestMethod in nestjs/nest#17162) cannot be represented in the generated OpenAPI document.

Issue Number: N/A

What is the new behavior?

PathItemObject accepts an optional query operation, so controllers using RequestMethod.QUERY are exposed under the query method in the generated document — including their requestBody (QUERY is defined as a safe method that carries a body). @All() handlers now expand to query as well, since Nest maps RequestMethod.QUERY -> 'query' and routes it through the adapter's .all() handler.

Because the query Path Item field only exists from OpenAPI 3.2 onwards, it is gated on the document version: SwaggerModule.createDocument strips every query operation (and prunes any path item left empty) whenever the openapi version is below 3.2.0, keeping 3.0/3.1 documents on-spec. To emit the operation, set the version via DocumentBuilder#setOpenAPIVersion('3.2.0').

Tests cover a @RequestMapping({ method: RequestMethod.QUERY }) route end to end through SwaggerExplorer (method, path, request body schema, response), the @All() expansion, the isOas32OrLater util, and the 3.0/3.1/3.2 stripping behaviour end to end.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

  • Depends on feat(core,common,platform-fastify): add query http method support nest#17162 (RequestMethod.QUERY), which has since shipped in @nestjs/common; the QUERY-specific tests are guarded with describe.runIf('QUERY' in RequestMethod) so they run once a compatible @nestjs/common is installed and skip cleanly otherwise.
  • Rebased on latest master (ESM migration + createDocument refactor); the stripping is folded into the current finalDocument flow and uses native destructuring (no new runtime dependency).
  • User-facing documentation lives in the separate docs.nestjs.com repo; happy to open a follow-up PR there documenting the setOpenAPIVersion('3.2.0') requirement once this lands.

@official-burak official-burak left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

query is an OpenAPI 3.2 Path Item field. This package still defaults the document to 3.0.0, so the emitted operation is off-spec.

head?: OperationObject;
patch?: OperationObject;
trace?: OperationObject;
query?: OperationObject;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OAS 3.0 and 3.1 Path Item objects have no query field. That lands in 3.2. SwaggerModule still defaults openapi to '3.0.0', so a document with paths['/foos/filtered'].query fails spec validation and Swagger UI drops the operation.

RequestMethod.ALL still expands to get/post/put/delete/patch/options/head/search and never query.

Gate this on OAS 3.2 (or put it under additionalOperations) and include query in the ALL list if Nest actually routes it.

@gentritabazi gentritabazi Sep 20, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Both points addressed:

  1. Gating on 3.2 the query operation is now stripped from the generated document for any openapi version below 3.2.0 (new isOas32OrLater util + stripQueryOperations in SwaggerModule.createDocument, which also prunes a path item that becomes empty). So 3.0/3.1 documents stay on-spec and Swagger UI keeps every sibling operation.

  2. RequestMethod.ALL Nest maps RequestMethod.QUERY -> 'query' in its router method map and @All() binds the adapter's .all() handler, which routes QUERY, so I added 'query' to the list the explorer expands for @All() controllers. It is still stripped for pre-3.2 documents by the gate above.

@gentritabazi
gentritabazi force-pushed the feat/http-query-method branch from b3ad3a2 to 571b766 Compare August 20, 2026 22:59
@official-burak

Copy link
Copy Markdown

Thanks. Gating query behind OpenAPI 3.2 keeps 3.0 documents on-spec.

@nmhernandez10

Copy link
Copy Markdown

This is urgently needed now that NestJS supports query methods with the merge of nestjs/nest#17162.

gentritabazi and others added 3 commits September 20, 2026 13:13
The `query` operation is an OpenAPI 3.2 Path Item field, but documents
default to 3.0.0, so a `RequestMethod.QUERY` route would emit an
off-spec operation.

Drop `query` operations when the configured version is below 3.2,
mirroring how `webhooks` is gated on 3.1. Sibling operations on the
same path are preserved, and the path entry is removed when `query`
was its only operation. The strip is applied to the webhook path
fold-back too, since that merges after the initial pass.
RequestMethod.ALL maps to the adapter's .all() handler, which routes the HTTP QUERY method (RequestMethod.QUERY -> 'query' in Nest's router method map). Include 'query' in the operations expanded for @ALL() controllers so those routes are represented in the generated document. The operation is still stripped for OpenAPI documents older than 3.2.
@gentritabazi

Copy link
Copy Markdown
Author

@kamilmysliwiec this is ready for review whenever you have a chance.

Would love your feedback on whether this is good to merge.

@nrutman

nrutman commented Sep 21, 2026

Copy link
Copy Markdown

Is there any chance we can get this merged / released ASAP? This seems like a huge add for the NestJS community, and I'd love to start taking advantage of it like 2 months ago. 😁

If there's anything that more supporters can do to help speed this along, let me know. I'll happily devote some cycles!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants