我已使用 Microsoft.Azure.Functions.Worker.Extensions.OpenApi 将 OpenAPI 文档添加到我的 Function 应用程序项目中,但是当响应太大(大约 2mb)时,swagger/ui 会冻结。我能做点什么吗?
我的函数返回大响应:
[Function("GetBookableResources")]
[OpenApiOperation(operationId: "GetBookableResources", tags: new[] { "Bookable Resource" }, Summary = "Get Bookable Resources", Description = "", Visibility = OpenApiVisibilityType.Important)]
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)]
[OpenApiRequestBody("application/json", typeof(BookableResourcesRequestBody),Description = "JSON request body", Required = true)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(List<BookableResourcesResponse>), Summary = "The response", Description = "This returns the response")]
public IActionResult GetBookableResources([HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req, [FromBody] BookableResourcesRequestBody reqBody)
{
try
{
var bookableResources = _bookableResourceService.GetBookableResources(reqBody);
return new OkObjectResult(bookableResources);
}
catch (Exception ex)
{
_logger.LogError($"Get Bookable resources error: {ex.Message}");
return new BadRequestObjectResult(ex.Message);
}
}
程序.cs:
services.AddSingleton<IOpenApiConfigurationOptions>(_ =>
{
var options = new OpenApiConfigurationOptions()
{
Info = new OpenApiInfo()
{
Version = "1.0.0",
Title = "API",
Description = "This is API."
},
Servers = DefaultOpenApiConfigurationOptions.GetHostNames(),
OpenApiVersion = OpenApiVersionType.V3,
IncludeRequestingHostName = true,
ForceHttps = false,
ForceHttp = false
};
return options;
});