Browse Source

Support uploading files for IRemoteStreamContent type in swagger

Resolve #8637
pull/8650/head
maliming 6 years ago
parent
commit
cc0fa33eed
  1. 61
      framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenServiceCollectionExtensions.cs

61
framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenServiceCollectionExtensions.cs

@ -3,52 +3,59 @@ using System.Collections.Generic;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
using Volo.Abp.Content;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
{ {
public static class AbpSwaggerGenServiceCollectionExtensions public static class AbpSwaggerGenServiceCollectionExtensions
{ {
public static IServiceCollection AddAbpSwaggerGenWithOAuth( public static IServiceCollection AddAbpSwaggerGen(
this IServiceCollection services, this IServiceCollection services,
[NotNull] string authority,
[NotNull] Dictionary<string, string> scopes,
Action<SwaggerGenOptions> setupAction = null) Action<SwaggerGenOptions> setupAction = null)
{ {
return services.AddSwaggerGen( return services.AddSwaggerGen(
options => options =>
{ {
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme Func<OpenApiSchema> remoteStreamContentSchemaFactory = () => new OpenApiSchema()
{ {
Type = SecuritySchemeType.OAuth2, Type = "string",
Flows = new OpenApiOAuthFlows Format = "binary"
{ };
AuthorizationCode = new OpenApiOAuthFlow
{ options.MapType<RemoteStreamContent>(remoteStreamContentSchemaFactory);
AuthorizationUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/authorize"), options.MapType<IRemoteStreamContent>(remoteStreamContentSchemaFactory);
Scopes = scopes,
TokenUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/token") setupAction?.Invoke(options);
} });
} }
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement public static IServiceCollection AddAbpSwaggerGenWithOAuth(
this IServiceCollection services,
[NotNull] string authority,
[NotNull] Dictionary<string, string> scopes,
Action<SwaggerGenOptions> 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, AuthorizationUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/authorize"),
Id = "oauth2" Scopes = scopes,
TokenUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/token")
} }
}, }
Array.Empty<string>() });
}
});
setupAction?.Invoke(options); setupAction?.Invoke(options);
}); });
} }
} }
} }

Loading…
Cancel
Save