Search code examples
c#swaggerswagger-uifast-endpoints

Fastendpoints swagger summary not displaying


Extract of my program.cs :

...
 .AddSwaggerGen(opt =>
 {
     opt.SwaggerDoc("v1", new OpenApiInfo { Title = "thing.Forum.Api", Version = "v1" });
     opt.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
     {
         In = ParameterLocation.Header,
         Description = "Please enter token",
         Name = "Authorization",
         Type = SecuritySchemeType.Http,
         BearerFormat = "JWT",
         Scheme = "bearer"
     });

     opt.AddSecurityRequirement(new OpenApiSecurityRequirement
     {
         {
             new OpenApiSecurityScheme
             {
                 Reference = new OpenApiReference
                 {
                     Type=ReferenceType.SecurityScheme,
                     Id="Bearer"
                 }
             },
             Array.Empty<string>()
         }
     });
 })
...
app.UseSwagger();
...

My endpoint :

using FastEndpoints;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Thing.Forum.Api.EndPoints.POC
{
    public class POCAction : BaseAction<POCRequest, POCResponse>
    {
        public override void Configure()
        {
            Post("/api/POC/create");
            Roles("Moderator");
            Summary(s => {
                s.Summary = "short summary goes here";
                s.Description = "long description goes here";
                s.ExampleRequest = new POCRequest { Id = 123 };
                s.ResponseExamples[200] = new POCResponse {  };
                s.Responses[200] = "ok response description goes here";
                s.Responses[403] = "forbidden response description goes here";
            });
        }
    
        public override async Task HandleAsyncImpl(POCRequest req, CancellationToken ct)
        {
            await SendAsync(new()
            {
            }, cancellation: ct);
        }
    }
}

Even though the endpoint works, and I do see the endpoint in my swagger, the summary is not there : swagger

What am I missing?


Solution

  • your middleware setup is incorrect. the following is the correct way to do it in fastendpoints (copied straight from the docs):

    using FastEndpoints.Swagger; //add this
    
    var bld = WebApplication.CreateBuilder();
    bld.Services
       .AddFastEndpoints()
       .SwaggerDocument(); //define a swagger document
    
    var app = bld.Build();
    app.UseFastEndpoints()
       .UseSwaggerGen(); //add this
    app.Run();
    

    btw, swagger jwt auth is included by default, so you don't need to define that.