Ejemplo n.º 1
0
        public static IApplicationBuilder UseSwagger(this IApplicationBuilder app, IConfiguration Configuration)
        {
            var options = new SwaggerOptions();

            Configuration.GetSection(nameof(SwaggerOptions)).Bind(options);

            if (string.IsNullOrWhiteSpace(options.Title))
            {
                options.Title = AppDomain.CurrentDomain.FriendlyName.Trim().Trim('_');
            }

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint($"/swagger/{options.VersionName}/swagger.json", options.Title);
            });

            return(app);
        }
Ejemplo n.º 2
0
        public static IServiceCollection AddSwagger(this IServiceCollection services, IConfiguration Configuration)
        {
            var options = new SwaggerOptions();

            Configuration.GetSection(nameof(SwaggerOptions)).Bind(options);
            services.Configure <SwaggerOptions>(Configuration.GetSection(nameof(SwaggerOptions)));

            if (string.IsNullOrWhiteSpace(options.Title))
            {
                options.Title = AppDomain.CurrentDomain.FriendlyName.Trim().Trim('_');
            }

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc(options.VersionName, options);
                c.CustomSchemaIds(x => x.FullName);
            });

            return(services);
        }