Fastendpoints swagger 摘要未显示

问题描述 投票:0回答:1

我的程序.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();
...

我的终点:

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

尽管端点有效,并且我确实在我的大摇大摆中看到了端点,但摘要并不存在: swagger

我错过了什么?

c# swagger swagger-ui fast-endpoints
1个回答
0
投票

您的中间件设置不正确。 以下是在 fastendpoints 中执行此操作的正确方法(直接从 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();

顺便说一句,swagger jwt auth 默认包含,所以你不需要定义它。

© www.soinside.com 2019 - 2024. All rights reserved.