Skip to content

[OpenApi] Ignore unknown HTTP methods #63034

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 2 commits into from
Aug 1, 2025

Conversation

martincostello
Copy link
Member

@martincostello martincostello commented Aug 1, 2025

Ignore unknown HTTP methods

  • Ignore unknown HTTP methods from OpenAPI documents.
  • Generate OpenAPI operations for HTTP QUERY.

Description

Exclude unsupported HTTP methods from the OpenAPI document, rather than throwing an exception.

Fixes #60914.

Exclude unsupported HTTP methods from the OpenAPI document, rather than throwing an exception.

Resolves dotnet#60914.
@Copilot Copilot AI review requested due to automatic review settings August 1, 2025 11:41
@martincostello martincostello requested review from captainsafia and a team as code owners August 1, 2025 11:41
@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 Aug 1, 2025
Copy link
Contributor

@Copilot 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

This PR modifies the OpenAPI document generation to gracefully handle unknown HTTP methods by ignoring them instead of throwing exceptions. The changes allow the system to continue processing supported HTTP methods while silently skipping unsupported ones.

  • Modified GetHttpMethod() to return HttpMethod? instead of throwing for unknown methods
  • Updated OpenAPI document service to skip operations with unsupported HTTP methods
  • Removed test that verified exception throwing for unknown methods
  • Added sample controller methods with unsupported HTTP methods for testing

Reviewed Changes

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

File Description
ApiDescriptionExtensions.cs Changed GetHttpMethod() to return nullable and return null for unknown methods
OpenApiDocumentService.cs Added null checks to skip operations with unsupported HTTP methods
ApiDescriptionExtensionsTests.cs Removed test verifying exception for unknown HTTP methods
TestController.cs Added sample methods with unsupported HTTP methods for testing
Comments suppressed due to low confidence (1)

src/OpenApi/src/Services/OpenApiDocumentService.cs:260

  • [nitpick] Remove the unnecessary blank line. According to the coding guidelines, ensure proper formatting by avoiding extra blank lines.
        return paths;

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Aug 1, 2025
@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 Aug 1, 2025
Support generating OpenAPI documentation for HTTP QUERY endpoints.

Contributes to dotnet#61089.
Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

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

LGTM!

@captainsafia captainsafia enabled auto-merge (squash) August 1, 2025 18:13
@captainsafia captainsafia merged commit f8c007b into dotnet:main Aug 1, 2025
30 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-rc1 milestone Aug 1, 2025
@martincostello martincostello deleted the gh-60914 branch August 1, 2025 19:33
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.

InvalidOperationException thrown if attempting to document a controller endpoint without an explicit HTTP method
2 participants