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

sample code: Provide endpoint descriptions and summaries for minimal APIs #26291

Closed
Tracked by #26326
Rick-Anderson opened this issue Jul 1, 2022 · 4 comments · Fixed by #26792
Closed
Tracked by #26326

sample code: Provide endpoint descriptions and summaries for minimal APIs #26291

Rick-Anderson opened this issue Jul 1, 2022 · 4 comments · Fixed by #26792
Assignees
Projects

Comments

@Rick-Anderson Rick-Anderson added Help wanted Up for grabs. We would accept a PR to help resolve this issue and removed ⌚ Not Triaged labels Jul 1, 2022
@Rick-Anderson Rick-Anderson changed the title Provide endpoint descriptions and summaries for minimal APIs sample code: Provide endpoint descriptions and summaries for minimal APIs Jul 3, 2022
@fiyazbinhasan
Copy link
Contributor

on it! :)

@fiyazbinhasan
Copy link
Contributor

@Rick-Anderson There seems to be an issue with OpenAPI support. I can't see any summary or description,

image

@fiyazbinhasan
Copy link
Contributor

ok I can see there is an opened issue for this dotnet/aspnetcore#40753

@Rick-Anderson
Copy link
Contributor Author

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

@Rick-Anderson Rick-Anderson added code help wanted Sample code help wanted. and removed Help wanted Up for grabs. We would accept a PR to help resolve this issue labels Jul 7, 2022
@tdykstra tdykstra assigned tdykstra and unassigned tdykstra Aug 10, 2022
@tdykstra tdykstra self-assigned this Aug 19, 2022
@tdykstra tdykstra added this to To DO in .NET 7 Aug 19, 2022
@tdykstra tdykstra removed the code help wanted Sample code help wanted. label Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
.NET 7
To DO
Development

Successfully merging a pull request may close this issue.

5 participants