public static async Task <IActionResult> RenderSwaggerUI(HttpRequest req, ExecutionContext ctx, ILogger log) { log.LogInformation("SwaggerUI page was requested."); var request = new HttpRequestObject(req); var result = default(string); var content = default(ContentResult); try { var auth = await context.SetApplicationAssemblyAsync(ctx.FunctionAppDirectory) .AuthorizeAsync(request) .ConfigureAwait(false); if (!auth.IsNullOrDefault()) { content = new ContentResult() { Content = auth.Payload, ContentType = auth.ContentType, StatusCode = (int)auth.StatusCode, }; return(content); } result = await context.SwaggerUI .AddMetadata(context.OpenApiConfigurationOptions.Info) .AddServer(new HttpRequestObject(req), context.HttpSettings.RoutePrefix, context.OpenApiConfigurationOptions) .BuildAsync(context.PackageAssembly, context.OpenApiCustomUIOptions) .RenderAsync("swagger.json", context.GetDocumentAuthLevel(), context.GetSwaggerAuthKey()) .ConfigureAwait(false); content = new ContentResult() { Content = result, ContentType = ContentTypeHtml, StatusCode = (int)HttpStatusCode.OK, }; } catch (Exception ex) { log.LogError(ex.Message); result = ex.Message; if (context.IsDevelopment) { result += "\r\n\r\n"; result += ex.StackTrace; } content = new ContentResult() { Content = result, ContentType = ContentTypeText, StatusCode = (int)HttpStatusCode.InternalServerError, }; } return(content); }