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

.NET 7: Document endpoint descriptions and summaries for minimal APIs #26340

Closed
Rick-Anderson opened this issue Jul 7, 2022 · 2 comments
Closed
Assignees
Labels
doc-idea Source - Docs.ms Docs Customer feedback via GitHub Issue

Comments

@Rick-Anderson
Copy link
Contributor

endpoint descriptions and summaries for minimal APIs

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);
}

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@dotnet-bot dotnet-bot added ⌚ Not Triaged Source - Docs.ms Docs Customer feedback via GitHub Issue labels Jul 7, 2022
@Rick-Anderson
Copy link
Contributor Author

@martincostello should this be postponed until dotnet/aspnetcore#40753 is closed?

@hwoodiwiss writes

Due to the changes to CI that will be required, it may have to wait until a bit closer to .NET 7's Release before it gets merged.

@Rick-Anderson Rick-Anderson self-assigned this Jul 7, 2022
@martincostello
Copy link
Member

I guess so if it still doesn't work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-idea Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

3 participants