Skip to content
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

OpenAPI document names are case-sensitive in urls #59175

Closed
1 task done
kpko opened this issue Nov 26, 2024 · 1 comment · Fixed by #59199 · May be fixed by #59568
Closed
1 task done

OpenAPI document names are case-sensitive in urls #59175

kpko opened this issue Nov 26, 2024 · 1 comment · Fixed by #59199 · May be fixed by #59568
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-openapi

Comments

@kpko
Copy link

kpko commented Nov 26, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I included several different openapi documents via .AddOpenApi("myDoc"). The document name contains upper- and lowercase letters. Later on I want to retrieve my document via /openapi/mydoc.json but I get a 404. After looking into it I found out that this should come from the fact that we're using keyed services:

        return endpoints.MapGet(pattern, async (HttpContext context, string documentName = OpenApiConstants.DefaultDocumentName) =>
            {
                // It would be ideal to use the `HttpResponseStreamWriter` to
                // asynchronously write to the response stream here but Microsoft.OpenApi
                // does not yet support async APIs on their writers.
                // See https://github.com/microsoft/OpenAPI.NET/issues/421 for more info.
                var documentService = context.RequestServices.GetKeyedService<OpenApiDocumentService>(documentName);
                if (documentService is null)
                {
                    context.Response.StatusCode = StatusCodes.Status404NotFound;
                    context.Response.ContentType = "text/plain;charset=utf-8";
                    await context.Response.WriteAsync($"No OpenAPI document with the name '{documentName}' was found.");
                }

Keyed services seem to be case sensitive. I can resolve this issue by lowercasing everything but this is counter-intuitive for me because the rest of aspnetcore does not use case sensitive routing AFAIK.

Expected Behavior

I expect the url for the openapi documents to be case insensitive, so I can receive my document regardless of the casing I use.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

9.0.100

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Nov 26, 2024
@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 Nov 26, 2024
@sander1095
Copy link
Contributor

I'm looking into this!

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 feature-openapi
Projects
None yet
3 participants