/// <summary>Adds the Swagger generator and Swagger UI to the pipeline.</summary> /// <param name="app">The app.</param> /// <param name="controllerTypes">The Web API controller types.</param> /// <param name="configure">Configure the Swagger settings.</param> /// <param name="schemaGenerator">The schema generator.</param> /// <returns>The app builder.</returns> public static IApplicationBuilder UseSwaggerUi3( this IApplicationBuilder app, IEnumerable <Type> controllerTypes, Action <SwaggerUi3Settings <WebApiToSwaggerGeneratorSettings> > configure = null, SwaggerJsonSchemaGenerator schemaGenerator = null) { var settings = new SwaggerUi3Settings <WebApiToSwaggerGeneratorSettings>(); configure?.Invoke(settings); if (controllerTypes != null) { app.UseMiddleware <WebApiToSwaggerMiddleware>(settings.ActualSwaggerRoute, controllerTypes, settings, schemaGenerator ?? new SwaggerJsonSchemaGenerator(settings.GeneratorSettings)); } app.UseMiddleware <RedirectMiddleware>(settings.ActualSwaggerUiRoute, settings.ActualSwaggerRoute); app.UseMiddleware <SwaggerUiIndexMiddleware <WebApiToSwaggerGeneratorSettings> >(settings.ActualSwaggerUiRoute + "/index.html", settings, "NSwag.AspNetCore.SwaggerUi3.index.html"); app.UseFileServer(new FileServerOptions { RequestPath = new PathString(settings.ActualSwaggerUiRoute), FileProvider = new EmbeddedFileProvider(typeof(SwaggerExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.SwaggerUi3") }); return(app); }
/// <summary>Adds the Swagger generator and Swagger UI to the OWIN pipeline.</summary> /// <param name="app">The app.</param> /// <param name="webApiAssembly">The Web API assembly to search for controller types.</param> /// <param name="settings">The Swagger UI and generator settings.</param> /// <returns>The app builder.</returns> public static IApplicationBuilder UseSwaggerUi3( this IApplicationBuilder app, Assembly webApiAssembly, SwaggerUi3Settings settings) { return(app.UseSwaggerUi3(new[] { webApiAssembly }, settings)); }
/// <summary>Adds the Swagger generator and Swagger UI to the OWIN pipeline.</summary> /// <param name="app">The app.</param> /// <param name="webApiAssemblies">The Web API assemblies to search for controller types.</param> /// <param name="settings">The Swagger UI and generator settings.</param> /// <returns>The app builder.</returns> public static IApplicationBuilder UseSwaggerUi3( this IApplicationBuilder app, IEnumerable <Assembly> webApiAssemblies, SwaggerUi3Settings settings) { var controllerTypes = webApiAssemblies.SelectMany(WebApiToSwaggerGenerator.GetControllerClasses); return(app.UseSwaggerUi3(controllerTypes, settings, new SwaggerJsonSchemaGenerator(settings))); }
public static void HandlePathBase(this SwaggerUi3Settings <WebApiToSwaggerGeneratorSettings> settings, IConfiguration configuration) { string basePath = configuration.GetValue <string>("basePath"); if (!String.IsNullOrWhiteSpace(basePath)) { settings.DocumentPath = $"{basePath}/swagger/{{documentName}}/swagger.json"; } }
/// <summary>Adds the Swagger generator and Swagger UI to the OWIN pipeline.</summary> /// <param name="app">The app.</param> /// <param name="controllerTypes">The Web API controller types.</param> /// <param name="configure">Configure the Swagger generator and UI settings.</param> public static IApplicationBuilder UseSwaggerUi3( this IApplicationBuilder app, IEnumerable <Type> controllerTypes, Action <SwaggerUi3Settings> configure = null) { var settings = new SwaggerUi3Settings(); configure?.Invoke(settings); return(app.UseSwaggerUi3(controllerTypes, settings, new SwaggerJsonSchemaGenerator(settings))); }
/// <summary>Adds the Swagger UI (only) to the OWIN pipeline.</summary> /// <param name="app">The app.</param> /// <param name="settings">The Swagger UI settings.</param> /// <returns>The app builder.</returns> public static IApplicationBuilder UseSwaggerUi3( this IApplicationBuilder app, SwaggerUi3Settings settings) { return(app.UseSwaggerUi3(null, settings, null)); }