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(); }
internal static Lazy <IReadOnlyList <ApiVersionDescription> > Create(CustomApiVersionDescriptionProvider apiVersionDescriptionProvider, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider) { var descriptions = new LazyApiVersionDescriptions(apiVersionDescriptionProvider, actionDescriptorCollectionProvider); return(new Lazy <IReadOnlyList <ApiVersionDescription> >(descriptions.EnumerateApiVersions)); }
LazyApiVersionDescriptions(CustomApiVersionDescriptionProvider apiVersionDescriptionProvider, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider) { _apiVersionDescriptionProvider = apiVersionDescriptionProvider; _actionDescriptorCollectionProvider = actionDescriptorCollectionProvider; }