예제 #1
0
 /// <summary>Addes 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 IAppBuilder UseSwaggerUi(
     this IAppBuilder app,
     Assembly webApiAssembly,
     SwaggerUiOwinSettings settings)
 {
     return(app.UseSwaggerUi(new[] { webApiAssembly }, settings));
 }
예제 #2
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 IAppBuilder UseSwaggerUi(
            this IAppBuilder app,
            IEnumerable <Assembly> webApiAssemblies,
            SwaggerUiOwinSettings settings)
        {
            var controllerTypes = webApiAssemblies.SelectMany(WebApiToSwaggerGenerator.GetControllerClasses);

            return(app.UseSwaggerUi(controllerTypes, settings, new SwaggerJsonSchemaGenerator(settings)));
        }
예제 #3
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 IAppBuilder UseSwaggerUi(
            this IAppBuilder app,
            IEnumerable <Type> controllerTypes,
            Action <SwaggerUiOwinSettings> configure = null)
        {
            var settings = new SwaggerUiOwinSettings();

            configure?.Invoke(settings);
            return(app.UseSwaggerUi(controllerTypes, settings, new SwaggerJsonSchemaGenerator(settings)));
        }
예제 #4
0
 /// <summary>Addes 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 generator settings.</param>
 /// <returns>The app builder.</returns>
 public static IAppBuilder UseSwaggerUi(
     this IAppBuilder app,
     IEnumerable <Type> controllerTypes,
     SwaggerUiOwinSettings settings)
 {
     app.Use <RedirectMiddleware>(settings.SwaggerUiRoute, settings.SwaggerUiRoute + "/index.html?url=" + Uri.EscapeDataString(settings.SwaggerRoute));
     app.Use <SwaggerMiddleware>(settings.SwaggerRoute, controllerTypes, settings);
     app.UseFileServer(new FileServerOptions
     {
         RequestPath = new PathString(settings.SwaggerUiRoute),
         FileSystem  = new EmbeddedResourceFileSystem(typeof(SwaggerUiExtensions).Assembly, "NSwag.AspNet.Owin.SwaggerUi")
     });
     app.UseStageMarker(PipelineStage.MapHandler);
     return(app);
 }
예제 #5
0
        /// <summary>Addes 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 IAppBuilder UseSwaggerUi(
            this IAppBuilder app,
            IEnumerable <Type> controllerTypes,
            SwaggerUiOwinSettings settings,
            SwaggerJsonSchemaGenerator schemaGenerator)
        {
            if (controllerTypes != null)
            {
                app.Use <SwaggerMiddleware>(settings.ActualSwaggerRoute, controllerTypes, settings, schemaGenerator);
            }

            app.Use <RedirectMiddleware>(settings.ActualSwaggerUiRoute, settings.ActualSwaggerRoute);
            app.Use <SwaggerUiIndexMiddleware>(settings.ActualSwaggerUiRoute + "/index.html", settings);
            app.UseFileServer(new FileServerOptions
            {
                RequestPath = new PathString(settings.ActualSwaggerUiRoute),
                FileSystem  = new EmbeddedResourceFileSystem(typeof(SwaggerExtensions).Assembly, "NSwag.AspNet.Owin.SwaggerUi")
            });
            app.UseStageMarker(PipelineStage.MapHandler);
            return(app);
        }
예제 #6
0
 /// <summary>Addes 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 IAppBuilder UseSwaggerUi(
     this IAppBuilder app,
     SwaggerUiOwinSettings settings)
 {
     return(app.UseSwaggerUi(null, settings, null));
 }
예제 #7
0
 public SwaggerUiIndexMiddleware(OwinMiddleware next, string indexPath, SwaggerUiOwinSettings settings)
     : base(next)
 {
     _indexPath = indexPath;
     _settings  = settings;
 }