diff --git a/exclusion.dic b/exclusion.dic index 486974911d..16ee57eac3 100644 --- a/exclusion.dic +++ b/exclusion.dic @@ -11,3 +11,4 @@ serializer startup swashbuckle swagger-ui +unprocessable diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs index 033c572f73..1dd32881f6 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs @@ -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().Any()) && !attributes.OfType().Any() && - _options.DocInclusionPredicate(documentName, apiDesc); + _options.DocInclusionPredicate(documentName, p); }); var schemaRepository = new SchemaRepository(documentName); @@ -171,10 +171,10 @@ private async Task> 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 @@ -248,7 +248,7 @@ private async Task GeneratePathsAsync( { return apiDescriptions .OrderBy(_options.SortKeySelector) - .GroupBy(apiDesc => apiDesc.HttpMethod) + .GroupBy((p) => p.HttpMethod) .Select(PrepareGenerateOperation); } @@ -300,7 +300,7 @@ private async Task> 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 = @@ -422,7 +422,7 @@ private async Task 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); @@ -448,7 +448,7 @@ private async Task 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) { @@ -463,7 +463,7 @@ private async Task 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( @@ -498,7 +498,7 @@ private async Task 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; @@ -521,14 +521,14 @@ private List GenerateOperationTags(OpenApiDocument document, ApiDesc private static async Task> GenerateParametersAsync( ApiDescription apiDescription, - SchemaRepository schemaRespository, + SchemaRepository schemaRepository, Func> 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)); } @@ -546,27 +546,27 @@ private static async Task> GenerateParametersAsync( foreach (var parameter in applicableApiParameters) { - parameters.Add(await parameterGenerator(parameter, schemaRespository)); + parameters.Add(await parameterGenerator(parameter, schemaRepository)); } return parameters; } - private List GenerateParameters(ApiDescription apiDescription, SchemaRepository schemaRespository) + private List 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> GenerateParametersAsync( ApiDescription apiDescription, - SchemaRepository schemaRespository) + SchemaRepository schemaRepository) { return await GenerateParametersAsync( apiDescription, - schemaRespository, + schemaRepository, GenerateParameterAsync); } @@ -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) @@ -798,8 +798,8 @@ private OpenApiRequestBody GenerateRequestBodyFromBodyParameter( { Required = isRequired, Content = contentTypes.ToDictionary( - contentType => contentType, - contentType => new OpenApiMediaType + (contentType) => contentType, + (contentType) => new OpenApiMediaType { Schema = schema }), @@ -812,7 +812,7 @@ private static IEnumerable InferRequestContentTypes(ApiDescription apiDe var explicitContentTypes = apiDescription .CustomAttributes() .OfType() - .SelectMany(attr => attr.ContentTypes) + .SelectMany((p) => p.ContentTypes) .Distinct(); if (explicitContentTypes.Any()) @@ -822,8 +822,8 @@ private static IEnumerable 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(); } @@ -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 } ) ?? [] }) }; @@ -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) ) }; } @@ -987,7 +987,7 @@ private static IEnumerable InferResponseContentTypes(ApiDescription apiD // If there's content types explicitly specified via ProducesAttribute, use them var explicitContentTypes = apiDescription.CustomAttributes().OfType() - .SelectMany(attr => attr.ContentTypes) + .SelectMany((p) => p.ContentTypes) .Distinct(); if (explicitContentTypes.Any()) @@ -997,15 +997,15 @@ private static IEnumerable 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) }; } @@ -1122,13 +1122,13 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription private static string GenerateSummary(ApiDescription apiDescription) => apiDescription.ActionDescriptor?.EndpointMetadata ?.OfType() - .Select(s => s.Summary) + .Select((p) => p.Summary) .LastOrDefault(); private static string GenerateDescription(ApiDescription apiDescription) => apiDescription.ActionDescriptor?.EndpointMetadata ?.OfType() - .Select(s => s.Description) + .Select((p) => p.Description) .LastOrDefault(); #endif