diff --git a/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenServiceCollectionExtensions.cs b/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenServiceCollectionExtensions.cs index 1da6958830..d669fcd9b9 100644 --- a/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenServiceCollectionExtensions.cs +++ b/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenServiceCollectionExtensions.cs @@ -3,52 +3,59 @@ using System.Collections.Generic; using JetBrains.Annotations; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; +using Volo.Abp.Content; namespace Microsoft.Extensions.DependencyInjection { public static class AbpSwaggerGenServiceCollectionExtensions { - public static IServiceCollection AddAbpSwaggerGenWithOAuth( + public static IServiceCollection AddAbpSwaggerGen( this IServiceCollection services, - [NotNull] string authority, - [NotNull] Dictionary scopes, Action setupAction = null) { return services.AddSwaggerGen( options => { - options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme + Func remoteStreamContentSchemaFactory = () => new OpenApiSchema() { - Type = SecuritySchemeType.OAuth2, - Flows = new OpenApiOAuthFlows - { - AuthorizationCode = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/authorize"), - Scopes = scopes, - TokenUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/token") - } - } - }); + Type = "string", + Format = "binary" + }; + + options.MapType(remoteStreamContentSchemaFactory); + options.MapType(remoteStreamContentSchemaFactory); + + setupAction?.Invoke(options); + }); + } - options.AddSecurityRequirement(new OpenApiSecurityRequirement + public static IServiceCollection AddAbpSwaggerGenWithOAuth( + this IServiceCollection services, + [NotNull] string authority, + [NotNull] Dictionary scopes, + Action setupAction = null) + { + return services + .AddAbpSwaggerGen() + .AddSwaggerGen( + options => { + options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme { - new OpenApiSecurityScheme + Type = SecuritySchemeType.OAuth2, + Flows = new OpenApiOAuthFlows { - Reference = new OpenApiReference + AuthorizationCode = new OpenApiOAuthFlow { - Type = ReferenceType.SecurityScheme, - Id = "oauth2" + AuthorizationUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/authorize"), + Scopes = scopes, + TokenUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/token") } - }, - Array.Empty() - } - }); - + } + }); - setupAction?.Invoke(options); - }); + setupAction?.Invoke(options); + }); } } }