Skip to content

AddEndpointsApiExplorer: Service parameters end up being part of the model using swagger #33685

@davidfowl

Description

@davidfowl

Describe the bug

Services injected into Map overloads get detected as models in the open api description.

To Reproduce

using Microsoft.OpenApi.Models;

var builder = WebApplication.CreateBuilder(args);

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

var app = builder.Build();

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

app.MapGet("/todos", (MyService service) =>
{
});

app.Run();

class MyService
{

}

The above URL shows up like this in the swagger UI:

image

Further technical details

  • Microsoft.NETCore.App 6.0.0-preview.6.21317.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

cc @halter73

Metadata

Metadata

Assignees

Labels

area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.feature-minimal-actionsController-like actions for endpoint routing

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions