Skip to content

The documentation says the attribute [Description] don't work to add a OAS parameter description in Minimal API, but it worksΒ #36254

@vernou

Description

@vernou

Description

In the documentation :

The [Description] attribute works in an MVC app but doesn't work in a Minimal API app at this time. For more information, see Description parameter of ProducesResponseTypeAttribute does not work in minimal API app (dotnet/aspnetcore #60518).

But the ticket dotnet/aspnetcore#60518 seems about response description, not parameter description. Moreover [DescriptionAttribute] works as expected on lambda parameter or method parameter.

With this code :

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthorization();
builder.Services.AddOpenApi();

var app = builder.Build();
if (app.Environment.IsDevelopment())
{
    app.MapOpenApi();
}
app.MapGet("/test", ([System.ComponentModel.Description("The parameter one")] string param1) => { });
app.Run();

The generated OpenAPI specification is :

{
...
"parameters": [
  {
    "name": "param1",
    "in": "query",
    "description": "The parameter one",
    "required": true,
    "schema": {
      "type": "string"
    }
  }
],
...
}

So the below citation in the documentation seems to be incorrect.

If you want, I can do a PR to fix it.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/include-metadata?view=aspnetcore-9.0&tabs=minimal-apis

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/openapi/include-metadata.md

Document ID

cbc730ec-642f-480d-4a41-044c6c6ef7d3

Platform Id

4bbf4c77-ca40-25d5-0673-fab1102c2291

Article author

@captainsafia

Metadata

  • ID: cbc730ec-642f-480d-4a41-044c6c6ef7d3
  • PlatformId: 4bbf4c77-ca40-25d5-0673-fab1102c2291
  • Service: aspnet-core
  • Sub-service: fundamentals

Related Issues


Associated WorkItem - 503030

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions