Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions exclusion.dic
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ serializer
startup
swashbuckle
swagger-ui
unprocessable
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ private void SortSchemas(OpenApiDocument document)
{
if (!_options.SwaggerDocs.TryGetValue(documentName, out OpenApiInfo info))
{
throw new UnknownSwaggerDocument(documentName, _options.SwaggerDocs.Select(d => d.Key));
throw new UnknownSwaggerDocument(documentName, _options.SwaggerDocs.Select((p) => p.Key));
}

var applicableApiDescriptions = _apiDescriptionsProvider.ApiDescriptionGroups.Items
.SelectMany(group => group.Items)
.Where(apiDesc =>
.SelectMany((p) => p.Items)
.Where((p) =>
{
var attributes = apiDesc.CustomAttributes().ToList();
var attributes = p.CustomAttributes().ToList();
return !(_options.IgnoreObsoleteActions && attributes.OfType<ObsoleteAttribute>().Any()) &&
!attributes.OfType<SwaggerIgnoreAttribute>().Any() &&
_options.DocInclusionPredicate(documentName, apiDesc);
_options.DocInclusionPredicate(documentName, p);
});

var schemaRepository = new SchemaRepository(documentName);
Expand Down Expand Up @@ -171,10 +171,10 @@ private async Task<IDictionary<string, OpenApiSecurityScheme>> GetSecurityScheme

// Default implementation, currently only supports JWT Bearer scheme
return authenticationSchemes
.Where(authScheme => authScheme.Name == "Bearer")
.Where((scheme) => scheme.Name == "Bearer")
.ToDictionary(
(authScheme) => authScheme.Name,
(authScheme) => new OpenApiSecurityScheme
(scheme) => scheme.Name,
(scheme) => new OpenApiSecurityScheme
{
Type = SecuritySchemeType.Http,
Scheme = "bearer", // "bearer" refers to the header name here
Expand Down Expand Up @@ -248,7 +248,7 @@ private async Task<OpenApiPaths> GeneratePathsAsync(
{
return apiDescriptions
.OrderBy(_options.SortKeySelector)
.GroupBy(apiDesc => apiDesc.HttpMethod)
.GroupBy((p) => p.HttpMethod)
.Select(PrepareGenerateOperation);
}

Expand Down Expand Up @@ -300,7 +300,7 @@ private async Task<Dictionary<OperationType, OpenApiOperation>> GenerateOperatio
"Actions require a unique method/path combination for Swagger/OpenAPI 2.0 and 3.0. Use ConflictingActionsResolver as a workaround or provide your own implementation of PathGroupSelector.",
httpMethod,
group.First().RelativePath,
string.Join(", ", group.Select(apiDesc => apiDesc.ActionDescriptor.DisplayName))));
string.Join(", ", group.Select((p) => p.ActionDescriptor.DisplayName))));
}

var apiDescription =
Expand Down Expand Up @@ -422,7 +422,7 @@ private async Task<OpenApiOperation> GenerateOpenApiOperationFromMetadataAsync(A
// Schemas will be generated via Swashbuckle by default.
foreach (var parameter in operation.Parameters)
{
var apiParameter = apiDescription.ParameterDescriptions.SingleOrDefault(desc => desc.Name == parameter.Name && !desc.IsFromBody() && !desc.IsFromForm() && !desc.IsIllegalHeaderParameter());
var apiParameter = apiDescription.ParameterDescriptions.SingleOrDefault((p) => p.Name == parameter.Name && !p.IsFromBody() && !p.IsFromForm() && !p.IsIllegalHeaderParameter());
if (apiParameter is not null)
{
var (parameterAndContext, filterContext) = GenerateParameterAndContext(apiParameter, schemaRepository);
Expand All @@ -448,7 +448,7 @@ private async Task<OpenApiOperation> GenerateOpenApiOperationFromMetadataAsync(A
foreach (var contentType in requestContentTypes)
{
var contentTypeValue = operation.RequestBody.Content[contentType];
var fromFormParameters = apiDescription.ParameterDescriptions.Where(desc => desc.IsFromForm()).ToList();
var fromFormParameters = apiDescription.ParameterDescriptions.Where((p) => p.IsFromForm()).ToList();
ApiParameterDescription bodyParameterDescription = null;
if (fromFormParameters.Count > 0)
{
Expand All @@ -463,7 +463,7 @@ private async Task<OpenApiOperation> GenerateOpenApiOperationFromMetadataAsync(A
}
else
{
bodyParameterDescription = apiDescription.ParameterDescriptions.SingleOrDefault(desc => desc.IsFromBody());
bodyParameterDescription = apiDescription.ParameterDescriptions.SingleOrDefault((p) => p.IsFromBody());
if (bodyParameterDescription is not null)
{
contentTypeValue.Schema = GenerateSchema(
Expand Down Expand Up @@ -498,7 +498,7 @@ private async Task<OpenApiOperation> GenerateOpenApiOperationFromMetadataAsync(A
foreach (var kvp in operation.Responses)
{
var response = kvp.Value;
var responseModel = apiDescription.SupportedResponseTypes.SingleOrDefault(desc => desc.StatusCode.ToString() == kvp.Key);
var responseModel = apiDescription.SupportedResponseTypes.SingleOrDefault((p) => p.StatusCode.ToString() == kvp.Key);
if (responseModel is not null)
{
var responseContentTypes = response?.Content?.Values;
Expand All @@ -521,14 +521,14 @@ private List<OpenApiTag> GenerateOperationTags(OpenApiDocument document, ApiDesc

private static async Task<List<OpenApiParameter>> GenerateParametersAsync(
ApiDescription apiDescription,
SchemaRepository schemaRespository,
SchemaRepository schemaRepository,
Func<ApiParameterDescription, SchemaRepository, Task<OpenApiParameter>> parameterGenerator)
{
if (apiDescription.ParameterDescriptions.Any(IsFromFormAttributeUsedWithIFormFile))
{
throw new SwaggerGeneratorException(string.Format(
"Error reading parameter(s) for action {0} as [FromForm] attribute used with IFormFile. " +
"Please refer to https://github.com/domaindrivendev/Swashbuckle.AspNetCore#handle-forms-and-file-uploads for more information",
"Please refer to https://github.com/domaindrivendev/Swashbuckle.AspNetCore/tree/master/docs/configure-and-customize-swaggergen.md#handle-forms-and-file-uploads for more information",
apiDescription.ActionDescriptor.DisplayName));
}

Expand All @@ -546,27 +546,27 @@ private static async Task<List<OpenApiParameter>> GenerateParametersAsync(

foreach (var parameter in applicableApiParameters)
{
parameters.Add(await parameterGenerator(parameter, schemaRespository));
parameters.Add(await parameterGenerator(parameter, schemaRepository));
}

return parameters;
}

private List<OpenApiParameter> GenerateParameters(ApiDescription apiDescription, SchemaRepository schemaRespository)
private List<OpenApiParameter> GenerateParameters(ApiDescription apiDescription, SchemaRepository schemaRepository)
{
return GenerateParametersAsync(
apiDescription,
schemaRespository,
(parameter, schemaRespository) => Task.FromResult(GenerateParameter(parameter, schemaRespository))).Result;
schemaRepository,
(parameter, schemaRepository) => Task.FromResult(GenerateParameter(parameter, schemaRepository))).Result;
}

private async Task<List<OpenApiParameter>> GenerateParametersAsync(
ApiDescription apiDescription,
SchemaRepository schemaRespository)
SchemaRepository schemaRepository)
{
return await GenerateParametersAsync(
apiDescription,
schemaRespository,
schemaRepository,
GenerateParameterAsync);
}

Expand Down Expand Up @@ -710,10 +710,10 @@ private OpenApiSchema GenerateSchema(
RequestBodyFilterContext filterContext = null;

var bodyParameter = apiDescription.ParameterDescriptions
.FirstOrDefault(paramDesc => paramDesc.IsFromBody());
.FirstOrDefault((p) => p.IsFromBody());

var formParameters = apiDescription.ParameterDescriptions
.Where(paramDesc => paramDesc.IsFromForm())
.Where((p) => p.IsFromForm())
.ToList();

if (bodyParameter != null)
Expand Down Expand Up @@ -798,8 +798,8 @@ private OpenApiRequestBody GenerateRequestBodyFromBodyParameter(
{
Required = isRequired,
Content = contentTypes.ToDictionary(
contentType => contentType,
contentType => new OpenApiMediaType
(contentType) => contentType,
(contentType) => new OpenApiMediaType
{
Schema = schema
}),
Expand All @@ -812,7 +812,7 @@ private static IEnumerable<string> InferRequestContentTypes(ApiDescription apiDe
var explicitContentTypes = apiDescription
.CustomAttributes()
.OfType<ConsumesAttribute>()
.SelectMany(attr => attr.ContentTypes)
.SelectMany((p) => p.ContentTypes)
.Distinct();

if (explicitContentTypes.Any())
Expand All @@ -822,8 +822,8 @@ private static IEnumerable<string> InferRequestContentTypes(ApiDescription apiDe

// If there's content types surfaced by ApiExplorer, use them
return apiDescription.SupportedRequestFormats
.Select(format => format.MediaType)
.Where(x => x != null)
.Select((format) => format.MediaType)
.Where((p) => p != null)
.Distinct();
}

Expand All @@ -842,19 +842,19 @@ private OpenApiRequestBody GenerateRequestBodyFromFormParameters(
var schema = GenerateSchemaFromFormParameters(formParameters, schemaRepository);

var totalProperties = schema.AllOf
?.FirstOrDefault(s => s.Properties?.Count > 0)
?.FirstOrDefault((p) => p.Properties?.Count > 0)
?.Properties ?? schema.Properties;

return new OpenApiRequestBody
{
Content = contentTypes.ToDictionary(
contentType => contentType,
contentType => new OpenApiMediaType
(contentType) => contentType,
(contentType) => new OpenApiMediaType
{
Schema = schema,
Encoding = totalProperties?.ToDictionary(
entry => entry.Key,
entry => new OpenApiEncoding { Style = ParameterStyle.Form }
(entry) => entry.Key,
(entry) => new OpenApiEncoding { Style = ParameterStyle.Form }
) ?? []
})
};
Expand Down Expand Up @@ -970,8 +970,8 @@ private OpenApiResponse GenerateResponse(
{
Description = description,
Content = responseContentTypes.ToDictionary(
contentType => contentType,
contentType => CreateResponseMediaType(apiResponseType.ModelMetadata?.ModelType ?? apiResponseType.Type, schemaRepository)
(contentType) => contentType,
(contentType) => CreateResponseMediaType(apiResponseType.ModelMetadata?.ModelType ?? apiResponseType.Type, schemaRepository)
)
};
}
Expand All @@ -987,7 +987,7 @@ private static IEnumerable<string> InferResponseContentTypes(ApiDescription apiD

// If there's content types explicitly specified via ProducesAttribute, use them
var explicitContentTypes = apiDescription.CustomAttributes().OfType<ProducesAttribute>()
.SelectMany(attr => attr.ContentTypes)
.SelectMany((p) => p.ContentTypes)
.Distinct();

if (explicitContentTypes.Any())
Expand All @@ -997,15 +997,15 @@ private static IEnumerable<string> InferResponseContentTypes(ApiDescription apiD

// If there's content types surfaced by ApiExplorer, use them
return [.. apiResponseType.ApiResponseFormats
.Select(responseFormat => responseFormat.MediaType)
.Select((responseFormat) => responseFormat.MediaType)
.Distinct()];
}

private OpenApiMediaType CreateResponseMediaType(Type modelType, SchemaRepository schemaRespository)
private OpenApiMediaType CreateResponseMediaType(Type modelType, SchemaRepository schemaRepository)
{
return new OpenApiMediaType
{
Schema = GenerateSchema(modelType, schemaRespository)
Schema = GenerateSchema(modelType, schemaRepository)
};
}

Expand Down Expand Up @@ -1122,13 +1122,13 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription
private static string GenerateSummary(ApiDescription apiDescription) =>
apiDescription.ActionDescriptor?.EndpointMetadata
?.OfType<IEndpointSummaryMetadata>()
.Select(s => s.Summary)
.Select((p) => p.Summary)
.LastOrDefault();

private static string GenerateDescription(ApiDescription apiDescription) =>
apiDescription.ActionDescriptor?.EndpointMetadata
?.OfType<IEndpointDescriptionMetadata>()
.Select(s => s.Description)
.Select((p) => p.Description)
.LastOrDefault();
#endif

Expand Down