public static IApplicationBuilder UseCustomSwagger(this IApplicationBuilder app, CustsomSwaggerOptions options)
        {
            app.UseSwagger(opt =>
            {
                if (options.UseSwaggerAction == null)
                {
                    return;
                }
                options.UseSwaggerAction(opt);
            });
            app.UseSwaggerUI(c =>
            {
                if (options.ApiVersions == null)
                {
                    return;
                }
                c.RoutePrefix   = options.RoutePrefix;
                c.DocumentTitle = options.ProjectName;
                if (options.UseCustomIndex)
                {
                    c.UseCustomSwaggerIndex();
                }
                foreach (var item in options.ApiVersions)
                {
                    c.SwaggerEndpoint($"/swagger/{item}/swagger.json", $"{item}");
                }
                options.UseSwaggerUIAction?.Invoke(c);
            });

            return(app);
        }
Exemplo n.º 2
0
 public static IServiceCollection AddCustomSwagger(this IServiceCollection services, CustsomSwaggerOptions options)
 {
     services.AddSwaggerGen(c =>
     {
         if (options.ApiVersions == null)
         {
             return;
         }
         foreach (var version in options.ApiVersions)
         {
             c.SwaggerDoc(version, new OpenApiInfo {
                 Title = options.ProjectName, Version = version
             });
         }
         c.OperationFilter <SwaggerDefaultValueFilter>();
         options.AddSwaggerGenAction?.Invoke(c);
     });
     return(services);
 }