Skip to content

[OpenApi] Ignore unknown HTTP methods - #63034

Merged
captainsafia merged 2 commits into
dotnet:mainfrom
martincostello:gh-60914
Aug 1, 2025
Merged

captainsafia merged 2 commits into
dotnet:mainfrom
martincostello:gh-60914

Conversation

@martincostello

@martincostello martincostello commented Aug 1, 2025 •

Copy link
Copy Markdown
Member

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 AI review requested due to automatic review settings August 1, 2025 11:41
@martincostello
martincostello requested review from a team and captainsafia 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@captainsafia captainsafia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

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

3 participants