Пример #1
0
        /// <summary>Addes 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 UseSwaggerUi(
            this IApplicationBuilder app,
            IEnumerable <Assembly> webApiAssemblies,
            SwaggerUiSettings settings)
        {
            var controllerTypes = webApiAssemblies.SelectMany(WebApiToSwaggerGenerator.GetControllerClasses);

            return(app.UseSwaggerUi(controllerTypes, settings, new SwaggerJsonSchemaGenerator(settings)));
        }
Пример #2
0
        /// <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 UseSwaggerUi(
            this IApplicationBuilder app,
            IEnumerable <Type> controllerTypes,
            Action <SwaggerUiSettings> configure = null)
        {
            var settings = new SwaggerUiSettings();

            configure?.Invoke(settings);
            return(app.UseSwaggerUi(controllerTypes, settings, new SwaggerJsonSchemaGenerator(settings)));
        }
Пример #3
0
        /// <summary>Adds the Swagger generator and Swagger UI to the pipeline.</summary>
        /// <param name="app">The app.</param>
        /// <param name="configure">Configure the Swagger settings.</param>
        /// <param name="schemaGenerator">The schema generator.</param>
        /// <returns>The app builder.</returns>
        public static IApplicationBuilder UseSwaggerReDocWithApiExplorer(
            this IApplicationBuilder app,
            Action <SwaggerUiSettings <AspNetCoreToSwaggerGeneratorSettings> > configure = null,
            SwaggerJsonSchemaGenerator schemaGenerator = null)
        {
            var settings = new SwaggerUiSettings <AspNetCoreToSwaggerGeneratorSettings>();

            configure?.Invoke(settings);

            app.UseMiddleware <AspNetCoreToSwaggerMiddleware>(settings, schemaGenerator ?? new SwaggerJsonSchemaGenerator(settings.GeneratorSettings));
            app.UseMiddleware <RedirectMiddleware>(settings.ActualSwaggerUiRoute, settings.ActualSwaggerRoute);
            app.UseMiddleware <SwaggerUiIndexMiddleware <AspNetCoreToSwaggerGeneratorSettings> >(settings.ActualSwaggerUiRoute + "/index.html", settings, "NSwag.AspNetCore.ReDoc.index.html");
            app.UseFileServer(new FileServerOptions
            {
                RequestPath  = new PathString(settings.ActualSwaggerUiRoute),
                FileProvider = new EmbeddedFileProvider(typeof(SwaggerExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.ReDoc")
            });

            return(app);
        }
Пример #4
0
        /// <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="settings">The Swagger UI and generator settings.</param>
        /// <param name="schemaGenerator">The schema generator.</param>
        /// <returns>The app builder.</returns>
        public static IApplicationBuilder UseSwaggerUi(
            this IApplicationBuilder app,
            IEnumerable <Type> controllerTypes,
            SwaggerUiSettings settings,
            SwaggerJsonSchemaGenerator schemaGenerator)
        {
            if (controllerTypes != null)
            {
                app.UseMiddleware <SwaggerMiddleware>(settings.ActualSwaggerRoute, controllerTypes, settings, schemaGenerator);
            }

            app.UseMiddleware <RedirectMiddleware>(settings.ActualSwaggerUiRoute, settings.ActualSwaggerRoute);
            app.UseMiddleware <SwaggerUiIndexMiddleware>(settings.ActualSwaggerUiRoute + "/index.html", settings, "NSwag.AspNetCore.SwaggerUi.index.html");
            app.UseFileServer(new FileServerOptions
            {
                RequestPath  = new PathString(settings.ActualSwaggerUiRoute),
                FileProvider = new EmbeddedFileProvider(typeof(SwaggerExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.SwaggerUi")
            });

            return(app);
        }
Пример #5
0
 /// <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 UseSwaggerUi(
     this IApplicationBuilder app,
     SwaggerUiSettings settings)
 {
     return(app.UseSwaggerUi(null, settings, null));
 }
 public SwaggerUiIndexMiddleware(RequestDelegate nextDelegate, string indexPath, SwaggerUiSettings settings)
 {
     _nextDelegate = nextDelegate;
     _indexPath    = indexPath;
     _settings     = settings;
 }