public static IServiceCollection AddApskOpenApiDocument(this IServiceCollection services, IConfiguration configuration) { var apiSetting = new OpenApiSetting(); configuration.GetSection(nameof(OpenApiSetting)).Bind(apiSetting); if (apiSetting is null) { throw new System.ArgumentNullException(nameof(apiSetting)); } if (string.IsNullOrWhiteSpace(apiSetting.Title)) { apiSetting.Title = Assembly.GetEntryAssembly().GetName().Name; } services.AddOpenApiDocument(opt => { opt.DocumentName = $"{apiSetting.Title}:{apiSetting.Version}"; opt.Title = apiSetting.Title; opt.Version = apiSetting.Version; opt.Description = apiSetting.Description; }); return(services); }
public static void UseApskOpenApiDocument(this IApplicationBuilder app, IConfiguration config) { var apiSetting = new OpenApiSetting(); config.GetSection(nameof(OpenApiSetting)).Bind(apiSetting); if (apiSetting is null) { throw new System.ArgumentNullException(nameof(apiSetting)); } if (string.IsNullOrWhiteSpace(apiSetting.Title)) { apiSetting.Title = Assembly.GetEntryAssembly().GetName().Name; } app.UseOpenApi(setting => { setting.DocumentName = $"{apiSetting.Title}:{apiSetting.Version}"; }); app.UseSwaggerUi3(); app.UseReDoc(); }