Exemplo n.º 1
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<SwaggerUiSettings> configure = null)
 {
     var settings = new SwaggerUiSettings();
     configure?.Invoke(settings);
     return app.UseSwaggerUi(controllerTypes, settings, new SwaggerJsonSchemaGenerator(settings));
 }
Exemplo n.º 2
0
        public static IApplicationBuilder UseSwaggerUi(
            this IApplicationBuilder app,
            Action <SwaggerUiSettings> configure = null)
        {
            var settings = new SwaggerUiSettings();

            settings.DocumentPath = "/swagger/v1/swagger.json";
            configure?.Invoke(settings);

            app.UseMiddleware <RedirectToIndexMiddleware>(settings.ActualSwaggerUiPath, settings.ActualSwaggerDocumentPath, settings.TransformToExternalPath);
            app.UseMiddleware <SwaggerUiIndexMiddleware>(settings.ActualSwaggerUiPath + "/index.html", settings, "NSwag.AspNetCore.SwaggerUi.index.html");
            app.UseFileServer(new FileServerOptions
            {
                RequestPath  = new PathString(settings.ActualSwaggerUiPath),
                FileProvider = new EmbeddedFileProvider(typeof(NSwagApplicationBuilderExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.SwaggerUi")
            });

            return(app);
        }
Exemplo n.º 3
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,
            SwaggerUiSettings 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.SwaggerUi.index.html");
            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;
        }
        public static void ConfigureSwagger(this IApplicationBuilder app, Assembly assembly)
        {
            var swaggerUiOwinSettings = new SwaggerUiSettings
            {
                DefaultPropertyNameHandling = PropertyNameHandling.CamelCase,
                Title          = "ArchitectNow.ApiStarter",
                SwaggerRoute   = "/api/docs/v1/swagger.json",
                SwaggerUiRoute = "/api/docs",
                UseJsonEditor  = true, //Set to false if you want to manually type in the Json
                FlattenInheritanceHierarchy = true,
                IsAspNetCore = true
            };

            swaggerUiOwinSettings.DocumentProcessors.Add(new SecurityDefinitionAppender("Authorization",
                                                                                        new SwaggerSecurityScheme
            {
                Type = SwaggerSecuritySchemeType.ApiKey,
                Name = "Authorization",
                In   = SwaggerSecurityApiKeyLocation.Header
            })
                                                         );

            app.UseSwaggerUi(assembly, swaggerUiOwinSettings);
        }
Exemplo n.º 5
0
        public static IAppBuilder UseSwaggerUi(
            this IAppBuilder app,
            IEnumerable <Type> controllerTypes,
            Action <SwaggerUiSettings <WebApiOpenApiDocumentGeneratorSettings> > configure = null)
        {
            var settings = new SwaggerUiSettings <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.SwaggerUi.index.html");
            app.UseFileServer(new FileServerOptions
            {
                RequestPath = new PathString(settings.ActualSwaggerUiPath),
                FileSystem  = new EmbeddedResourceFileSystem(typeof(SwaggerExtensions).Assembly, "NSwag.AspNet.Owin.SwaggerUi")
            });
            app.UseStageMarker(PipelineStage.MapHandler);
            return(app);
        }
 static IApplicationBuilder UseDefaultSwaggerBuilderLocal(IApplicationBuilder app, SwaggerSettings swaggerSettings, SwaggerUiSettings swaggerUiSettings) =>
 app
 .UseSwagger(option => {
 public static IApplicationBuilder UseDefaultSwaggerBuilder(this IApplicationBuilder app, SwaggerSettings swaggerSettings, SwaggerUiSettings swaggerUiSettings, string environmentName)
 {
Exemplo n.º 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 UseSwaggerUi(
     this IAppBuilder app,
     SwaggerUiSettings settings)
 {
     return(app.UseSwaggerUi(null, settings, null));
 }
Exemplo n.º 9
0
 protected virtual void SwaggerUiSetting(SwaggerUiSettings setting)
 {
 }
Exemplo n.º 10
0
 public CustomSwaggerGenOptions(IOptionsSnapshot <SwaggerUiSettings> swaggerUiConfig)
 {
     _swaggerUiSettings = swaggerUiConfig.Value;
 }
Exemplo n.º 11
0
 public SwaggerUiIndexMiddleware(OwinMiddleware next, string indexPath, SwaggerUiSettings settings)
     : base(next)
 {
     _indexPath = indexPath;
     _settings  = settings;
 }