예제 #1
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="configure">Configure the Swagger settings.</param>
        /// <param name="schemaGenerator">The schema generator.</param>
        /// <returns>The app builder.</returns>
        public static IAppBuilder UseSwaggerReDoc(
            this IAppBuilder app,
            IEnumerable <Type> controllerTypes,
            Action <SwaggerReDocSettings <WebApiToSwaggerGeneratorSettings> > configure = null,
            SwaggerJsonSchemaGenerator schemaGenerator = null)
        {
            var settings = new SwaggerReDocSettings <WebApiToSwaggerGeneratorSettings>();

            configure?.Invoke(settings);

            if (controllerTypes != null)
            {
                app.Use <SwaggerMiddleware>(settings.ActualSwaggerRoute, controllerTypes, settings, schemaGenerator ?? new SwaggerJsonSchemaGenerator(settings.GeneratorSettings));
            }

            app.Use <RedirectMiddleware>(settings.ActualSwaggerUiRoute, settings.ActualSwaggerRoute);
            app.Use <SwaggerUiIndexMiddleware <WebApiToSwaggerGeneratorSettings> >(settings.ActualSwaggerUiRoute + "/index.html", settings, "NSwag.AspNet.Owin.ReDoc.index.html");
            app.UseFileServer(new FileServerOptions
            {
                RequestPath = new PathString(settings.ActualSwaggerUiRoute),
                FileSystem  = new EmbeddedResourceFileSystem(typeof(SwaggerExtensions).Assembly, "NSwag.AspNet.Owin.ReDoc")
            });
            app.UseStageMarker(PipelineStage.MapHandler);
            return(app);
        }
예제 #2
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 UseSwaggerReDoc(
     this IAppBuilder app,
     Assembly webApiAssembly,
     SwaggerReDocSettings settings)
 {
     return app.UseSwaggerReDoc(new[] { webApiAssembly }, settings);
 }
예제 #3
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 UseSwaggerReDoc(
     this IAppBuilder app,
     IEnumerable<Assembly> webApiAssemblies,
     SwaggerReDocSettings settings)
 {
     var controllerTypes = webApiAssemblies.SelectMany(WebApiToSwaggerGenerator.GetControllerClasses);
     return app.UseSwaggerReDoc(controllerTypes, settings, new SwaggerJsonSchemaGenerator(settings));
 }
예제 #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="configure">Configure the Swagger generator and UI settings.</param>
 public static IAppBuilder UseSwaggerReDoc(
     this IAppBuilder app,
     IEnumerable<Type> controllerTypes,
     Action<SwaggerReDocSettings> configure = null)
 {
     var settings = new SwaggerReDocSettings();
     configure?.Invoke(settings);
     return app.UseSwaggerReDoc(controllerTypes, settings, new SwaggerJsonSchemaGenerator(settings));
 }
예제 #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 UseSwaggerReDoc(
            this IAppBuilder app,
            IEnumerable<Type> controllerTypes,
            SwaggerReDocSettings 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, "NSwag.AspNet.Owin.ReDoc.index.html");
            app.UseFileServer(new FileServerOptions
            {
                RequestPath = new PathString(settings.ActualSwaggerUiRoute),
                FileSystem = new EmbeddedResourceFileSystem(typeof(SwaggerExtensions).Assembly, "NSwag.AspNet.Owin.ReDoc")
            });
            app.UseStageMarker(PipelineStage.MapHandler);
            return app;
        }
        /// <summary>Adds the ReDoc UI (only) to the pipeline.</summary>
        /// <remarks>The settings.GeneratorSettings property does not have any effect.</remarks>
        /// <param name="app">The app.</param>
        /// <param name="configure">Configure the Swagger settings.</param>
        /// <returns>The app builder.</returns>
        public static IApplicationBuilder UseReDoc(
            this IApplicationBuilder app,
            Action <SwaggerReDocSettings <WebApiToSwaggerGeneratorSettings> > configure = null)
        {
            var settings = new SwaggerReDocSettings <WebApiToSwaggerGeneratorSettings>();

            configure?.Invoke(settings);

            UseSwaggerUiWithDocumentNamePlaceholderExpanding(app, settings, (swaggerRoute, swaggerUiRoute) =>
            {
                app.UseMiddleware <RedirectToIndexMiddleware>(swaggerUiRoute, swaggerRoute, settings.TransformToExternalPath);
                app.UseMiddleware <SwaggerUiIndexMiddleware <WebApiToSwaggerGeneratorSettings> >(swaggerUiRoute + "/index.html", settings, "NSwag.AspNetCore.ReDoc.index.html");
                app.UseFileServer(new FileServerOptions
                {
                    RequestPath  = new PathString(swaggerUiRoute),
                    FileProvider = new EmbeddedFileProvider(typeof(SwaggerExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.ReDoc")
                });
            }, (documents) => false);

            return(app);
        }
        /// <summary>Adds the ReDoc UI (only) to the pipeline.</summary>
        /// <remarks>The settings.GeneratorSettings property does not have any effect.</remarks>
        /// <param name="app">The app.</param>
        /// <param name="configure">Configure the Swagger settings.</param>
        /// <returns>The app builder.</returns>
        public static IApplicationBuilder UseReDoc(
            this IApplicationBuilder app,
            Action <SwaggerReDocSettings <WebApiToSwaggerGeneratorSettings> > configure = null)
        {
            var settings = new SwaggerReDocSettings <WebApiToSwaggerGeneratorSettings>();

            configure?.Invoke(settings);

            UseSwaggerUiWithDocumentNamePlaceholderExpanding(app, settings, (swaggerRoute, swaggerUiRoute) =>
            {
                app.UseMiddleware <RedirectToIndexMiddleware>(swaggerUiRoute, swaggerRoute, settings.TransformToExternalPath);
                app.UseMiddleware <SwaggerUiIndexMiddleware <WebApiToSwaggerGeneratorSettings> >(swaggerUiRoute + "/index.html", settings, "NSwag.AspNetCore.ReDoc.index.html");
                app.UseFileServer(new FileServerOptions
                {
                    RequestPath  = new PathString(swaggerUiRoute),
                    FileProvider = new EmbeddedFileProvider(typeof(SwaggerExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.ReDoc")
                });
            }, (documents) => throw new NotSupportedException("ReDoc does not support multiple documents per UI: " +
                                                              "Do not use '{documentName}' placeholder only in SwaggerRoute but also in SwaggerUiRoute to register multiple UIs."));

            return(app);
        }
예제 #8
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 UseSwaggerReDoc(
     this IAppBuilder app,
     SwaggerReDocSettings settings)
 {
     return app.UseSwaggerReDoc(null, settings, null);
 }