예제 #1
0
        public static void AddSwaggerForApiDocs(this IServiceCollection services, string groupNameFormat, Action <SwaggerGenOptions> additionalOptions)
        {
            CustomApiVersionDescriptionProvider.AddApiExplorerServices(
                services,
                options =>
            {
                options.GroupNameFormat           = groupNameFormat;
                options.SubstituteApiVersionInUrl = true;
            });

            services.AddTransient <IConfigureOptions <SwaggerGenOptions>, ConfigureSwaggerOptions>(
                s =>
                new ConfigureSwaggerOptions(s.GetRequiredService <IApiVersionDescriptionProvider>(), s.GetRequiredService <ApplicationPartManager>(), additionalOptions))
            .AddSwaggerGen()
            .AddSwaggerGenNewtonsoftSupport();

            services.AddApiVersioning(o =>
            {
                o.AssumeDefaultVersionWhenUnspecified = true;
                o.DefaultApiVersion = new ApiVersion(1, 0);
            });

            services.AddRouting(options => options.LowercaseUrls = true);

            services.Configure <MvcOptions>(options => { });

            services.AddControllers()
            .AddNewtonsoftJson();
        }
예제 #2
0
            internal static Lazy <IReadOnlyList <ApiVersionDescription> > Create(CustomApiVersionDescriptionProvider apiVersionDescriptionProvider, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
            {
                var descriptions = new LazyApiVersionDescriptions(apiVersionDescriptionProvider, actionDescriptorCollectionProvider);

                return(new Lazy <IReadOnlyList <ApiVersionDescription> >(descriptions.EnumerateApiVersions));
            }
예제 #3
0
 LazyApiVersionDescriptions(CustomApiVersionDescriptionProvider apiVersionDescriptionProvider, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
 {
     _apiVersionDescriptionProvider      = apiVersionDescriptionProvider;
     _actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
 }