Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Following up on issue (#920) there is still an issue present with the new WithOpenApi method.
I tried to clone https://github.com/joaofbantunes/AspNetApiVersioningWithOpenApiRepro from previous issue and cut it down to a bare minimum API.
var ordersV1 = orders.MapGroup( "/api/orders" )
.HasApiVersion( 1.0 );
ordersV1.MapGet( "/{id:int}", ( int id ) => new OrderV1() { Id = id, Customer = "John Doe" } )
.WithOpenApi()
.Produces<OrderV1>();
ordersV1.MapPost( "/", ( HttpRequest request, OrderV1 order ) =>
{
order.Id = 42;
var scheme = request.Scheme;
var host = request.Host;
var location = new Uri( $"{scheme}{Uri.SchemeDelimiter}{host}/api/orders/{order.Id}" );
return Results.Created( location, order );
} )
.Accepts<OrderV1>( "application/json" )
.Produces<OrderV1>( 201 )
.Produces( 400 )
.MapToApiVersion( 1.0 );
ordersV1.MapPatch( "/{id:int}", ( int id, OrderV1 order ) => Results.NoContent() )
.Accepts<OrderV1>( "application/json" )
.Produces( 204 )
.Produces( 400 )
.Produces( 404 )
.MapToApiVersion( 1.0 );
When adding the WithOpenApi method to the ordersV1.MapGet endpoint, the api-version query parameter disappears from swagger. On the MapPatch endpoint, where WithOpenApi is not added, the api-version query parameter still is present.
The primary reason for me to utilize .WithOpenApi method atm, is to properly add a Summary to my endpoints, seeing as .WithSummary method does not work properly with Swagger.
Expected Behavior
ASP.NET API Versioning features working the same, regardless of WithOpenApi usage.
Steps To Reproduce
Clone the repo from previous issue: https://github.com/joaofbantunes/AspNetApiVersioningWithOpenApiRepro
Cut the sample down to a minimum:
var ordersV1 = orders.MapGroup( "/api/orders" )
.HasApiVersion( 1.0 );
ordersV1.MapGet( "/{id:int}", ( int id ) => new OrderV1() { Id = id, Customer = "John Doe" } )
.WithOpenApi()
.Produces<OrderV1>();
ordersV1.MapPost( "/", ( HttpRequest request, OrderV1 order ) =>
{
order.Id = 42;
var scheme = request.Scheme;
var host = request.Host;
var location = new Uri( $"{scheme}{Uri.SchemeDelimiter}{host}/api/orders/{order.Id}" );
return Results.Created( location, order );
} )
.Accepts<OrderV1>( "application/json" )
.Produces<OrderV1>( 201 )
.Produces( 400 )
.MapToApiVersion( 1.0 );
ordersV1.MapPatch( "/{id:int}", ( int id, OrderV1 order ) => Results.NoContent() )
.Accepts<OrderV1>( "application/json" )
.Produces( 204 )
.Produces( 400 )
.Produces( 404 )
.MapToApiVersion( 1.0 );
Try to incomment/outcomment the WithOpenApi method on the ordersV1.MapGet and observe differences in Swagger Page.
Exceptions (if any)
No response
.NET Version
7.0.102
Anything else?
Microsoft.AspNetCore.OpenApi v 7.0.2 being used in the example - updated from v. 7.0.0