Skip to content

Commit

Permalink
Fix descriptions when using WithOpenApi (#3085)
Browse files Browse the repository at this point in the history
Fixing breaking change when applying filters for WithOpenApi extension.
  • Loading branch information
jgarciadelanoceda authored Sep 30, 2024
1 parent 17981d9 commit e9bdab9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private async Task<OpenApiOperation> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@
"tags": [
"WithOpenApi"
],
"parameters": [
{
"name": "queryParameter",
"in": "query",
"description": "queryParameter Description",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"multipart/form-data": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@
"tags": [
"WithOpenApi"
],
"parameters": [
{
"name": "queryParameter",
"in": "query",
"description": "queryParameter Description",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"multipart/form-data": {
Expand Down
4 changes: 2 additions & 2 deletions test/WebSites/Basic/Controllers/FilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
}
Expand Down
14 changes: 11 additions & 3 deletions test/WebSites/WebApi/EndPoints/OpenApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand Down

0 comments on commit e9bdab9

Please sign in to comment.