-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Unintuitive/incorrect behaviour from use of WithOpenApi() #41623
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
Comments
Also in the case where the user wants to adjust the operation (rather than replace it), maybe an overload that takes an public static partial class OpenApiRouteHandlerBuilderExtensions
{
+ public static RouteHandlerBuilder WithOpenApi(this RouteHandlerBuilder builder, Action<OpenApiOperation> configureOperation);
} Doing something like the below to tweak a single field is a bit cumbersome, in my opinion: .WithOpenApi(operation =>
{
operation.Summary = "whatever";
return operation;
}); Where it could alternatively be: .WithOpenApi(operation => operation.Summary = "whatever"); |
Yep, this is the goal. However, there are some challenges here particularly when it comes to schema generation for complex models like
As you mentioned, this is an artifact of this bug #40753 and not the new
Yep, this is an artifact of the schema generation issue above. So, yes, this issue is particularly annoying and getting the schema generation working right and at the right point in the stack will be challenging. For the moment, users have the workaround of setting the object themselves via the I've also been noodling about making the work I did in domaindrivendev/Swashbuckle.AspNetCore#2404 to support "merging" with the schema produced in Swashbuckle instead of overriding it which should alleviate the issue.
I actually started out with this API in the first draft of the PR but we moved to the override model to:
So in the future, you'd be able to do .WithOpenApi(operation => new(operation) {
Summary = "whatever";
}); Which lends itself very nicely to the object initialization pattern used extensively in the |
Thanks for the links to the other repos' issues Safia, I'll keep an eye on those 👀 Your comment here microsoft/OpenAPI.NET#836 (comment) also touches on something else I'd noticed while playing with this that I didn't mention, which was getting access to things from the Otherwise that all makes sense, it was just a bit of a challenge to try out at this current stage in its development - I appreciate it's a complex area 😄 |
Triage: Marking as a dupe of #41246 |
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes. See our Issue Management Policies for more information. |
Is there an existing issue for this?
Describe the bug
Using the new
WithOpenApi()
method with Minimal APIs in .NET 7 preview 4 in conjunction with Swashbuckle.AspNetCore produces unintuitive results in the generatedswagger.json
file.If either
WithOpenApi()
overload is used, the metadata that would be present without it is lost, some information is incorrectly added, and information that doesn't work at all without it (see #40753) does render.Below is the
swagger.json
generated by Swashbuckle.AspNetCore using the repro application included later in this issue.For resource
/a
:MyModel
and has a descriptionFor resources
/b
and/c
:Neither resource is 100% correct in its description.
swagger.json
Expected Behavior
WithOpenApi()
provides the ability for the user to extend the operations generated by default (or allows them to be completely replaced) without losing any of those conventions.I would expect that the object passed to
WithOpenApi()
would contain the same detail as if it had not been used on the endpoint at all.In the example given, this would mean that:
MyModel
with a descriptionSteps To Reproduce
Program.cs
Project.csproj
Exceptions (if any)
No response
.NET Version
7.0.100-preview.4.22252.9
Anything else?
No response
The text was updated successfully, but these errors were encountered: