AspNetCore.Docs
AspNetCore.Docs copied to clipboard
sample code: Provide endpoint descriptions and summaries for minimal APIs
See Provide endpoint descriptions and summaries for minimal APIs
and write sample code in https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/endpoint-description-summary/7.0-samples
then delete https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/minimal-apis/endpoint-description-summary/7.0-samples/ReadMe.md
cc @fiyazbinhasan
on it! :)
@Rick-Anderson There seems to be an issue with OpenAPI support. I can't see any summary or description,

ok I can see there is an opened issue for this https://github.com/dotnet/aspnetcore/issues/40753
We'll have to wait.
using Microsoft.AspNetCore.OpenApi;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
app.MapGet("/", [EndpointSummary("Sends a Hello request to the backend")] // <----
[EndpointDescription("Description: Sends hello request")] () => "Hello World!"); // <----
app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateTime.Now.AddDays(index),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithDescription("Description:Sends the weather forcast.") // <----
.WithSummary("Summary: Sends the weather forcast.") // <----
.WithName("GetWeatherForecast")
.WithOpenApi();
app.Run();
internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}