-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
More thorough support for retrieving OpenAPI routes in a case-sensitive manner #59568
base: main
Are you sure you want to change the base?
More thorough support for retrieving OpenAPI routes in a case-sensitive manner #59568
Conversation
…ument name for OpenAPI version retrieval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this and following up with a PR!
This has got me thinking that we should audit other places where we pass in documentName in the same way. As a result, it looks like we'll also want to make a change in OpenApiDocumentProvider
. The same test around the API version should work here.
@captainsafia I've implemented your requested changes, added extra comments, improved existing ones and updated the title and description of PR to better reflect the changes. Let me know if you want me to do anything else! :) |
@@ -106,6 +105,9 @@ public static IServiceCollection AddOpenApi(this IServiceCollection services, Ac | |||
public static IServiceCollection AddOpenApi(this IServiceCollection services) | |||
=> services.AddOpenApi(OpenApiConstants.DefaultDocumentName); | |||
|
|||
/// <param name="services">The <see cref="IServiceCollection"/> to register services onto.</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove the docstrings on private methods.
@@ -25,10 +25,17 @@ internal sealed class OpenApiDocumentProvider(IServiceProvider serviceProvider) | |||
/// <param name="writer">A text writer associated with the document to write to.</param> | |||
public async Task GenerateAsync(string documentName, TextWriter writer) | |||
{ | |||
// We need to retrieve the document name in a case-insensitive manner to support case-insensitive document name resolution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just reference the comment in the IServiceCollection
extensions file instead of duplicating the content here.
// It's registered as "casesensitive" but we're passing in "CaseSensitive", which doesn't exist. | ||
// Therefore, if the test doesn't throw, we know it has passed correctly. | ||
// We still do a small check to validate the document, just in case. But the main test is that it doesn't throw. | ||
ValidateOpenApiDocument(stringWriter, _ => { }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Add an assertion here to validate the OpenAPI version as above?
Thanks for the review! I'll implement requested changes after my holiday (in ~2 weeks) |
More thorough support for retrieving OpenAPI routes in a case-sensitive manner
This PR fixes some oversights from #59199 around retrieving OpenAPI documents case-insensitively.
Description
This PR modifies missed files from #59199 that use the registered document name as a key for retrieving services or options. This needs to be done case-insensitively to:
OpenApiOptions
is returned, which might contain different settings than what the user had configured.This PR also adds some more comments and improves existing ones based on the previous PR around case-insensitive OpenAPI document names.
Fixes #59175