Skip to content

Conversation

@sander1095
Copy link
Contributor

@sander1095 sander1095 commented Nov 27, 2024

Change OpenAPI document name resolution to be case-insensitive

  • 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.

Case-sensitive urls are now supported when retrieving OpenAPI documents.

Description

There was a routing issue when using case-sensitive document names in Microsoft.AspNetCore.OpenApi's AddOpenApi() and MapOpenApi() methods. If you registered a document in a case-sensitive manner (MyDocument) and tried to retrieve it at /openapi/mydocument.json, it would result in a 404.

This is odd, as ASP.NET Core's routing has always been case-insensitive by default.

The reason for this bug is that keyed services are used to register relevant services. The key is the document name, and keyed services are case-sensitive.

This PR changes this inconsistent behaviour by allowing case-insensitive document resolution by invariantly lowercasing both the registered document name and the document name that's being retrieved.

Fixes #59175

@sander1095 sander1095 requested review from a team and captainsafia as code owners November 27, 2024 14:57
@ghost ghost added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Nov 27, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 27, 2024
@martincostello martincostello added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc labels Nov 27, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Dec 5, 2024
@mkArtakMSFT mkArtakMSFT removed the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Dec 13, 2024
@captainsafia captainsafia enabled auto-merge (squash) December 16, 2024 22:28
@captainsafia captainsafia merged commit 09d7789 into dotnet:main Dec 16, 2024
27 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview1 milestone Dec 16, 2024
captainsafia pushed a commit that referenced this pull request Feb 11, 2025
* Fix analyser error

* Wrote unit test to verify when bug is fixed

* Register document names in a case-insensitive manner

* Change OpenAPI document name resolution to be case-insensitive

* Restore AddOpenApiCore to its own method

* Fix typo in extension method
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 pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI document names are case-sensitive in urls

4 participants