Swagger UI在RequestToken请求URL中不包含主机

问题描述

我将api从.netcore2.2升级到.netcore3.1 Swagger.json似乎正确生成

但是,当我尝试使用Swagger UI生成承载令牌时,我发现请求URL不包含主机

应该像https://example.com/v1/api/RequestToken一样像https://example.com/myapiname/api/RequestToken

类似的卷曲

我拥有的内部配置

        app.UseSwagger(c =>
        {
            c.SerializeAsV2 = true;
            c.RouteTemplate =
                "api-docs/{documentName}/swagger.json";
         
            var basePath = "/v1";
            c.PreSerializefilters.Add((swaggerDoc,httpReq) =>
            {
                swaggerDoc.Servers = new List<OpenApiServer>
                    {new OpenApiServer {Url = $"{httpReq.Scheme}://{httpReq.Host.Value}{basePath}"}};
            });
        });
        Environment.SetEnvironmentvariable("GRPC_DNS_RESOLVER","native");
        app.UseSwaggerUI(c =>
        {
            //Include virtual directory if site is configured so
            c.RoutePrefix = "api-docs";
         
            c.SwaggerEndpoint("./v1/swagger.json","Api v1");
        });

[更新]

我可以通过将基本路径从“ / v1”更改为“ myapiname”来解决此问题,但是我只需要在升级到netcore3.1之前执行此操作

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)