Exemplo n.º 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>
        /// <returns>The app builder.</returns>
        public static IAppBuilder UseSwaggerReDoc(
            this IAppBuilder app,
            IEnumerable <Type> controllerTypes,
            Action <ReDocSettings <WebApiOpenApiDocumentGeneratorSettings> > configure = null)
        {
            var settings = new ReDocSettings <WebApiOpenApiDocumentGeneratorSettings>();

            configure?.Invoke(settings);

            if (controllerTypes != null)
            {
                app.Use <OpenApiDocumentMiddleware>(settings.ActualSwaggerDocumentPath, controllerTypes, settings);
            }

            app.Use <RedirectToIndexMiddleware>(settings.ActualSwaggerUiPath, settings.ActualSwaggerDocumentPath, settings.TransformToExternalPath);
            app.Use <SwaggerUiIndexMiddleware <WebApiOpenApiDocumentGeneratorSettings> >(settings.ActualSwaggerUiPath + "/index.html", settings, "NSwag.AspNet.Owin.ReDoc.index.html");
            app.UseFileServer(new FileServerOptions
            {
                RequestPath = new PathString(settings.ActualSwaggerUiPath),
                FileSystem  = new EmbeddedResourceFileSystem(typeof(SwaggerExtensions).Assembly, "NSwag.AspNet.Owin.ReDoc")
            });
            app.UseStageMarker(PipelineStage.MapHandler);
            return(app);
        }
Exemplo n.º 2
0
 protected virtual void ReDocUiSetting(ReDocSettings setting)
 {
 }