Skip to content

Support HTTP QUERY#65714

Merged
halter73 merged 16 commits intodotnet:mainfrom
kilifu:gh-65489-add-query-operation
Apr 1, 2026
Merged

Support HTTP QUERY#65714
halter73 merged 16 commits intodotnet:mainfrom
kilifu:gh-65489-add-query-operation

Conversation

@kilifu
Copy link
Copy Markdown
Contributor

@kilifu kilifu commented Mar 9, 2026

[OpenAPI] Support HTTP QUERY

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Description

add support for query operations

Fixes #65489

Copilot AI review requested due to automatic review settings March 9, 2026 19:19
@kilifu kilifu requested a review from a team as a code owner March 9, 2026 19:19
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Mar 9, 2026
@kilifu
Copy link
Copy Markdown
Contributor Author

kilifu commented Mar 9, 2026

@dotnet-policy-service agree

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 9, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds OpenAPI generation support for the HTTP QUERY operation (introduced as a first-class PathItem operation in OpenAPI 3.2), and updates integration snapshots/tests to validate correct serialization across OpenAPI versions.

Changes:

  • Map ApiDescription.HttpMethod == "QUERY" to an OpenAPI operation and ensure it’s treated like other body-less methods for inferred body behavior.
  • Include QUERY in the set of supported OpenAPI HTTP methods for path generation.
  • Update OpenAPI 3.0/3.1/3.2 snapshot baselines to reflect QUERY serialization (native query in 3.2; extension-based in earlier versions).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/OpenApi/src/Extensions/ApiDescriptionExtensions.cs Adds QUERY to the ApiDescription→HttpMethod mapping and updates the spec reference link.
src/OpenApi/src/Services/OpenApiConstants.cs Adds HttpMethod.Query to the preallocated HTTP method list used during path generation.
src/OpenApi/src/Services/OpenApiGenerator.cs Treats QUERY as a method that normally does not infer a request body.
src/OpenApi/src/Services/OpenApiDocumentService.cs Contains unrelated formatting-only changes in several edited lines.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Extensions/ApiDescriptionExtensionsTests.cs Extends method mapping test data to include QUERY and adds an unsupported-method test.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApiDocumentLocalizationTests.VerifyOpenApiDocumentIsInvariant.verified.txt Snapshot updated to include /query output using additional-operations extension format.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_2/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=controllers.verified.txt Snapshot updated to serialize /query using the OpenAPI 3.2 query operation field.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_1/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=controllers.verified.txt Snapshot updated to serialize /query via x-oai-additionalOperations.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=controllers.verified.txt Snapshot updated to serialize /query via x-oai-additionalOperations.

@martincostello martincostello added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Mar 10, 2026
@martincostello
Copy link
Copy Markdown
Member

There's lots of whitespace changes in this PR that shouldn't be here, it also incorrectly emits QUERY operations in OpenAPI documents that aren't targeting version 3.2 of the specification (see #64368 (comment))).

@baywet
Copy link
Copy Markdown
Contributor

baywet commented Mar 10, 2026

There's lots of whitespace changes in this PR that shouldn't be here, it also incorrectly emits QUERY operations in OpenAPI documents that aren't targeting version 3.2 of the specification (see #64368 (comment))).

Why is this an issue? it's being emitted as an extension when looking at the unit tests. Which means the document in earlier versions is valid (albeit not very useful).

@martincostello
Copy link
Copy Markdown
Member

Why is this an issue?

IIRC, they caused the documents to fail schema validation: #63092.

Does the Microsoft.OpenApi schema validation now allow QUERY for all document versions?

@baywet
Copy link
Copy Markdown
Contributor

baywet commented Mar 10, 2026

@martincostello I'm not sure what you mean by "schema"?

If you're referring to the OpenAPI schemas that can be found here since query was added for 3.2.0 only, it's valid only for that version. Earlier versions need to use an extension instead.

If you're referring to the Microsoft.OpenApi object model, yes, that property (and serialization/deserialization for it) was added in v3 of the library, which brings supports for OpenAPI 3.2.0, and which we have upgraded for asp.net 11 preview2.

@martincostello
Copy link
Copy Markdown
Member

By schema I meant the schema documents that say what a valid OpenAPI document looks like (the schema for the schemas).

If the library has evolved since the version where I made the test changes then it's not a concern as the tests won't break, but at the time adding QUERY to a 3.0 and 3.1 document would have caused the tests to fail when Microsoft.OpenApi was used to validate the object model, as it would contain a validation diagnostic in the result here:

[Theory]
[MemberData(nameof(OpenApiDocuments))]
public async Task OpenApiDocumentIsValid(string documentName, OpenApiSpecVersion version)
{
var json = await GetOpenApiDocument(documentName, version);
var actual = OpenApiDocument.Parse(json, format: "json");
Assert.NotNull(actual);
Assert.NotNull(actual.Document);
Assert.NotNull(actual.Diagnostic);
Assert.NotNull(actual.Diagnostic.Errors);
Assert.Empty(actual.Diagnostic.Errors);
var ruleSet = ValidationRuleSet.GetDefaultRuleSet();
var errors = actual.Document.Validate(ruleSet);
Assert.Empty(errors);
}

@baywet
Copy link
Copy Markdown
Contributor

baywet commented Mar 10, 2026

@martincostello thanks for sharing this. Since that validation is implemented in Microsoft.OpenAPI, if that's still a challenge (it should not), I can always put a bugfix together there. Bottom line being:

  • Query should be serialized as "query" for OAI 3.2.0+
  • Should be serialized as an extension for < 3.2.0

In both cases, it should not lead to any validation issue from Microsoft.OpenApi (v3)

Copy link
Copy Markdown
Contributor

@mikekistler mikekistler left a comment

Choose a reason for hiding this comment

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

QUERY operations must be able to accept a body, and we should have tests that verify this.

Copy link
Copy Markdown
Contributor

@mikekistler mikekistler left a comment

Choose a reason for hiding this comment

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

Switching my review to approve as the team has decided to defer support for MapQuery.

This was referenced Mar 25, 2026
@halter73 halter73 removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Mar 26, 2026
@halter73 halter73 enabled auto-merge (squash) March 26, 2026 02:48
Copy link
Copy Markdown
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

Thanks! ❤️

@halter73 halter73 merged commit 56f5912 into dotnet:main Apr 1, 2026
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview3 milestone Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc community-contribution Indicates that the PR has been added by a community member feature-openapi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI 3.2.0 - aspnet11 - add support for query operations

6 participants