Я обновляю свой API с .netcore2.1 до 3.1
API использует SwagerUI и Autorest для генерации клиента.
С этот вопрос об Autorest I обнаружил, что мне нужно использовать
app.UseSwagger(c =>
{
c.SerializeAsV2 = true;
});
Однако пользовательский интерфейс дает
Fetch error
Internal Server Error v1/swagger.json
json
{
"StatusCode": 500,
"ErrorMessage": "Internal server error: Invalid URI: The format of the URI could not be determined. nStack:
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at Microsoft.OpenApi.Models.OpenApiDocument.WriteHostInfoV2(IOpenApiWriter writer, IList`1 servers)
at Microsoft.OpenApi.Models.OpenApiDocument.SerializeAsV2(IOpenApiWriter writer)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.RespondWithSwaggerJson(HttpResponse response, OpenApiDocument swagger)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)",
"SystemMessage": "Invalid URI: The format of the URI could not be determined."
}
[Обновление]
Я нашел упоминание об этом здесь
c.PreSerializeFilters.Add((swaggerDoc, httpReq) =>
{
swaggerDoc.Servers = new List<OpenApiServer> { new OpenApiServer { Url = $"{httpReq.Scheme}://{httpReq.Host.Value}{pathPrefix}" } };
});
Теперь json показывает
{
"StatusCode": 500,
"ErrorMessage": "Internal server error: Invalid URI: Invalid port specified.
Stack: at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at Microsoft.OpenApi.Models.OpenApiDocument.WriteHostInfoV2(IOpenApiWriter writer, IList`1 servers)
at Microsoft.OpenApi.Models.OpenApiDocument.SerializeAsV2(IOpenApiWriter writer)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.RespondWithSwaggerJson(HttpResponse response, OpenApiDocument swagger)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)",
"SystemMessage": "Invalid URI: Invalid port specified."
}