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

Minimal API endpoints do not appear in OpenAPI if WithGroupName() is used #36414

Closed
martincostello opened this issue Sep 11, 2021 · 3 comments
Closed
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-minimal-actions Controller-like actions for endpoint routing

Comments

@martincostello
Copy link
Member

Describe the bug

If WithGroupName(string) is used with a Minimal APIs endpoint, it disappears from being displayed in OpenAPI.

Using WithGroupName()

image

No WithGroupName()

image

To Reproduce

Create an empty ASP.NET Core 6 project with a reference to Swashbuckle.AspNetCore with the below code as Program.cs.

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
    options.SwaggerDoc("v1", new() { Title = builder.Environment.ApplicationName, Version = "v1" });
});

var app = builder.Build();

app.MapGet("/greeting", () => "Hello, world")
   .WithGroupName("Greetings");

app.UseSwagger();
app.UseSwaggerUI(options =>
{
    options.EnableTryItOutByDefault();
    options.SwaggerEndpoint("/swagger/v1/swagger.json", $"{builder.Environment.ApplicationName} v1");
});

app.Run();

Further technical details

.NET SDK version 6.0.100-rc.1.21460.8

@davidfowl davidfowl added area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-minimal-actions Controller-like actions for endpoint routing labels Sep 11, 2021
@captainsafia
Copy link
Member

captainsafia commented Sep 13, 2021

Thanks for testing these scenarios, @martincostello!

So, the GroupName metadata is designed to be used when generating multiple Swagger documents. So the following:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
    options.SwaggerDoc("v1", new() { Title = $"{builder.Environment.ApplicationName} v1", Version = "v1" });
    options.SwaggerDoc("v2", new() { Title = $"{builder.Environment.ApplicationName} v2", Version = "v2" });
});

var app = builder.Build();

app.MapGet("/greeting", () => "Hello, world")
   .WithGroupName("v1");

app.MapGet("/farewell", () => "Bye, world")
   .WithGroupName("v2");

app.UseSwagger();
app.UseSwaggerUI(options =>
{
    options.EnableTryItOutByDefault();
    options.SwaggerEndpoint("/swagger/v1/swagger.json", $"{builder.Environment.ApplicationName} v1");
    options.SwaggerEndpoint("/swagger/v2/swagger.json", $"{builder.Environment.ApplicationName} v2");
});

app.Run();

Should work to display the /greeting API under the v1 subsection and the /farewell API under the v2 subsection.

image

image

WithTags should work for grouping endpoints within a document.

@martincostello
Copy link
Member Author

Ah, fair enough, my mistake!

I guess the nomenclature in this case is slightly confusing, but I'd probably have ended up doing the right thing via trial-and-error if the version I was using had WithTags() 👍

@captainsafia
Copy link
Member

@martincostello No worries! BTW, I misspoke. The WithTags stuff doesn't totally work yet. You'll need to use the changes in domaindrivendev/Swashbuckle.AspNetCore#2210 to get it working in the E2E.

Closing this one for now.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-minimal-actions Controller-like actions for endpoint routing
Projects
None yet
Development

No branches or pull requests

4 participants