in src/Microsoft.Azure.WebJobs.Extensions.OpenApi/OpenApiTriggerFunctions.cs [184:243]
public static async Task<IActionResult> RenderSwaggerUI(
[OpenApiHttpTriggerContext] OpenApiHttpTriggerContext openApiContext,
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 openApiContext.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 openApiContext.SwaggerUI
.AddMetadata(openApiContext.OpenApiConfigurationOptions.Info)
.AddServer(new HttpRequestObject(req), openApiContext.HttpSettings.RoutePrefix, openApiContext.OpenApiConfigurationOptions)
.BuildAsync(openApiContext.PackageAssembly, openApiContext.OpenApiCustomUIOptions)
.RenderAsync("swagger.json", openApiContext.GetDocumentAuthLevel(), openApiContext.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 (openApiContext.IsDevelopment)
{
result += "\r\n\r\n";
result += ex.StackTrace;
}
content = new ContentResult()
{
Content = result,
ContentType = ContentTypeText,
StatusCode = (int)HttpStatusCode.InternalServerError,
};
}
return content;
}