Browse Source

Support uploading files for IRemoteStreamContent type in swagger

Resolve #8637
pull/8650/head
maliming 5 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 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<string, string> scopes,
Action<SwaggerGenOptions> setupAction = null)
{
return services.AddSwaggerGen(
options =>
{
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
Func<OpenApiSchema> 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<RemoteStreamContent>(remoteStreamContentSchemaFactory);
options.MapType<IRemoteStreamContent>(remoteStreamContentSchemaFactory);
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,
Id = "oauth2"
AuthorizationUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/authorize"),
Scopes = scopes,
TokenUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/token")
}
},
Array.Empty<string>()
}
});
}
});
setupAction?.Invoke(options);
});
setupAction?.Invoke(options);
});
}
}
}

Loading…
Cancel
Save