-
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
Minimal API Group with OpenAPI and Return Type of Result<TResult> creates incorrect OpenAPI document. #57876
Comments
Which preview of .NET 9 are you using? If not release candidate 1, try upgrading to that - there's a bunch of bug fixes since preview 7. |
@martincostello thanks for the quick response. I updated to 9.0.100-rc.1.24452.12 and it does indeed fix the documentation Do however still see an exception, although slightly different to the original one.
|
@MarkTallentire Thanks for filling this issue! I'm glad @martincostello's guidance about updating to RC1 solved your first issue. As for the second one, does the issue only happen when you access the Scalar UI? Does something similar happen when you directly navigate to the |
@captainsafia I can confirm this only happens when I access the scalar UI, possibly a bug on their side instead of in .net? |
It might be that your second issue was fixed by #57852. |
I don't think anything in that PR would've resolved this particularly issue but I suppose it is worth a try. You can try it out by using package version |
Hey @MarkTallentire, |
@xC0dex Thanks for checking. @captainsafia @martincostello I updated to latest version starting with 9 available in the nightly nuget provided above but unfortunately still see the error I've created a repo that reproduces this issue in the hope it helps diagnose. I get the error 8/10 times when running directly from a terminal using The only changes made from the default Thanks again |
Hey @MarkTallentire, Thanks for sharing the link to the repo. Edit: app.Start();
var factory = app.Services.GetRequiredService<IHttpClientFactory>();
var httpClient = factory.CreateClient();
var tasks = new List<Task<HttpResponseMessage>>
{
httpClient.GetAsync("https://localhost:7216/openapi/v1.json"),
httpClient.GetAsync("https://localhost:7216/openapi/v1.json"),
httpClient.GetAsync("https://localhost:7216/openapi/v1.json")
};
await Task.WhenAll(tasks);
app.WaitForShutdown(); |
I think a regression was introduced here when we switched from @xC0dex Any interest in opening a PR for this? |
@captainsafia, sure! I just have to read through the |
Is there an existing issue for this?
Describe the bug
I have a simple API that uses the new OpenAPI document generation and Minimal APIs that utilize groups functionality.
When using the following code, i expect OpenAPI to generate a document with the available return types of Created and BadRequest.
However I get Ok, Created and BadRequest and it also produces some weird return model types
I also see the following exception in my console.
System.ArgumentException: An item with the same key has already been added. Key: OpenApiSchemaKey { Type = Microsoft.AspNetCore.Http.HttpResults.Results
2[Microsoft.AspNetCore.Http.HttpResults.Created1[Api.Features.Accounts.DTOs.CreateAccountResponse],Microsoft.AspNetCore.Http.HttpResults.BadRequest
1[FluentValidation.Results.ValidationResult]], ParameterInfo = }`
Produces:
Expected Behavior
To show only Created(201) and BadRequest(400) as available return types and only ValidationResult and CreateAccountResponse as return models.
Steps To Reproduce
Use code above in a new .net9 project and run
Exceptions (if any)
System.ArgumentException: An item with the same key has already been added. Key: OpenApiSchemaKey { Type = Microsoft.AspNetCore.Http.HttpResults.Results
2[Microsoft.AspNetCore.Http.HttpResults.Created1[Api.Features.Accounts.DTOs.CreateAccountResponse],Microsoft.AspNetCore.Http.HttpResults.BadRequest
1[FluentValidation.Results.ValidationResult]], ParameterInfo = }`
.NET Version
9.0 preview
Anything else?
I have also attempted to use .Produces() to explicitly define the return types but have the same issue
The text was updated successfully, but these errors were encountered: