public static async Task <IActionResult> RenderSwaggerUI( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "swagger/ui")] HttpRequest req, ILogger log) { var ui = new SwaggerUI(); var metaData = new OpenApiInfo { Version = "1.0.0", Title = "Azure Functions Hello World", License = new OpenApiLicense { Name = "None" }, Contact = new OpenApiContact { Email = "*****@*****.**", Url = new Uri("https://github.com/NtFreX/HelloAzureFunctions") } }; var result = await ui .AddServer(req, ApiPrefix) .AddMetadata(metaData) .BuildAsync() .RenderAsync("swagger.json") .ConfigureAwait(false); var response = new ContentResult() { Content = result, ContentType = "text/html", StatusCode = (int)HttpStatusCode.OK }; return(response); }
public void Given_NullOptions_When_AddServer_Invoked_Then_It_Should_Return_BaseUrl(string scheme, string host, string routePrefix, string expected) { var req = new Mock <IHttpRequestDataObject>(); req.SetupGet(p => p.Scheme).Returns(scheme); var hostString = new HostString(host); req.SetupGet(p => p.Host).Returns(hostString); var ui = new SwaggerUI(); ui.AddServer(req.Object, routePrefix, null); var fi = ui.GetType().GetField("_baseUrl", BindingFlags.Instance | BindingFlags.NonPublic); (fi.GetValue(ui) as string).Should().Be(expected); }
public void Given_NullOptions_When_AddServer_Invoked_Then_It_Should_Return_SwaggerUIApiPrefix(string scheme, string host, string routePrefix, bool optionsSet, string expected) { var req = new Mock <IHttpRequestDataObject>(); req.SetupGet(p => p.Scheme).Returns(scheme); var hostString = new HostString(host); req.SetupGet(p => p.Host).Returns(hostString); var ui = new SwaggerUI(); var options = new Mock <IOpenApiConfigurationOptions>(); options.SetupGet(p => p.Servers).Returns(new List <OpenApiServer>()); ui.AddServer(req.Object, routePrefix, optionsSet ? options.Object: null); var fi = ui.GetType().GetField("_swaggerUiApiPrefix", BindingFlags.Instance | BindingFlags.NonPublic); (fi.GetValue(ui) as string).Should().Be(expected); }