Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support uploading files for IRemoteStreamContent type in swagger #8650

Merged
merged 2 commits into from
Apr 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,74 @@
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.AddSecurityRequirement(new OpenApiSecurityRequirement
options.MapType<RemoteStreamContent>(remoteStreamContentSchemaFactory);
options.MapType<IRemoteStreamContent>(remoteStreamContentSchemaFactory);

setupAction?.Invoke(options);
});
}

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>()
}
});
}
});

options.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "oauth2"
}
},
Array.Empty<string>()
}
});

setupAction?.Invoke(options);
});
setupAction?.Invoke(options);
});
}
}
}