diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs index 730f01ecbb..f5207082eb 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs @@ -408,7 +408,7 @@ private async Task GenerateOpenApiOperationFromMetadataAsync(A { var (parameterAndContext, filterContext) = GenerateParameterAndContext(apiParameter, schemaRepository); parameter.Schema = parameterAndContext.Schema; - parameter.Description = parameterAndContext.Description; + parameter.Description ??= parameterAndContext.Description; foreach (var filter in _options.ParameterAsyncFilters) { diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_For_WebApi_swaggerRequestUri=v1.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_For_WebApi_swaggerRequestUri=v1.verified.txt index a024a3215d..84cdebb45c 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_For_WebApi_swaggerRequestUri=v1.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_For_WebApi_swaggerRequestUri=v1.verified.txt @@ -246,6 +246,17 @@ "tags": [ "WithOpenApi" ], + "parameters": [ + { + "name": "queryParameter", + "in": "query", + "description": "queryParameter Description", + "required": true, + "schema": { + "type": "string" + } + } + ], "requestBody": { "content": { "multipart/form-data": { diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.TypesAreRenderedCorrectly.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.TypesAreRenderedCorrectly.verified.txt index a024a3215d..84cdebb45c 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.TypesAreRenderedCorrectly.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.TypesAreRenderedCorrectly.verified.txt @@ -246,6 +246,17 @@ "tags": [ "WithOpenApi" ], + "parameters": [ + { + "name": "queryParameter", + "in": "query", + "description": "queryParameter Description", + "required": true, + "schema": { + "type": "string" + } + } + ], "requestBody": { "content": { "multipart/form-data": { diff --git a/test/WebSites/Basic/Controllers/FilesController.cs b/test/WebSites/Basic/Controllers/FilesController.cs index 0d09ffbdf4..0ca4714b48 100644 --- a/test/WebSites/Basic/Controllers/FilesController.cs +++ b/test/WebSites/Basic/Controllers/FilesController.cs @@ -21,7 +21,7 @@ public IActionResult PostFiles(IFormFileCollection files) } [HttpPost("form-with-file")] - public IActionResult PostFormWithFile([FromForm]FormWithFile formWithFile) + public IActionResult PostFormWithFile([FromForm] FormWithFile formWithFile) { throw new NotImplementedException(); } @@ -41,7 +41,7 @@ public FileResult GetFile(string name) writer.Flush(); stream.Position = 0; - var contentType = name.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase) ? "application/zip" : "text/plain"; + var contentType = name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) ? "application/zip" : "text/plain"; return File(stream, contentType, name); } diff --git a/test/WebSites/WebApi/EndPoints/OpenApiEndpoints.cs b/test/WebSites/WebApi/EndPoints/OpenApiEndpoints.cs index f8c22e9244..f59eb08e1c 100644 --- a/test/WebSites/WebApi/EndPoints/OpenApiEndpoints.cs +++ b/test/WebSites/WebApi/EndPoints/OpenApiEndpoints.cs @@ -42,10 +42,18 @@ public static IEndpointRouteBuilder MapWithOpenApiEndpoints(this IEndpointRouteB }) .WithOpenApi(); - group.MapPost("/IFromFile", (IFormFile file) => + group.MapPost("/IFromFile", (IFormFile file, string queryParameter) => { - return file.FileName; - }).WithOpenApi(); + return $"{file.FileName}{queryParameter}"; + }).WithOpenApi(o => + { + var parameter = o.Parameters.FirstOrDefault(p => p.Name.Equals("queryParameter", StringComparison.OrdinalIgnoreCase)); + if (parameter is not null) + { + parameter.Description = $"{parameter.Name} Description"; + } + return o; + }); group.MapPost("/IFromFileCollection", (IFormFileCollection collection) => {