How to set base path property in swagger for .Net Core Web API

后端 未结 3 568
离开以前
离开以前 2021-01-02 00:47

i\'ve built a Web API in ASP.Net Core (version 1.1.2) and i use the Swashbuckle.AspNetCore for generating the swagger definition.

below is a part of the automaticall

3条回答
  •  鱼传尺愫
    2021-01-02 01:23

    BasePath was used in Swagger v2.0 It has been replaced by the servers array in OpenApi v3.0

    In v5 you have to do this for using OpenApi v3.0:

    var basePath = "/v1";
    app.UseSwagger(c =>
        {
            c.RouteTemplate = "swagger/{documentName}/swagger.json";
            c.PreSerializeFilters.Add((swaggerDoc, httpReq) =>
            {
                swaggerDoc.Servers = new List { new OpenApiServer { Url = $"{httpReq.Scheme}://{httpReq.Host.Value}{basePath}" } };
            });
        });
    

提交回复
热议问题