Skip to content

Commit

Permalink
Merge pull request #4829 from microsoft/andrueastman/fixEmptyDescript…
Browse files Browse the repository at this point in the history
…ions

Ensure response description is not empty in response for openApi file generated during plugin generation
  • Loading branch information
andrueastman authored Jun 13, 2024
2 parents d3bb9c3 + 9075bed commit 9c8d937
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- TypeScript imports are now using ES6 imports with the .js extension.
- Remove LINQ usage in generated code.
- Ensures descriptions are not empty in sliced OpenApi file when generating a plugin.

## [1.15.0] - 2024-06-06

Expand Down
3 changes: 3 additions & 0 deletions src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ private OpenApiDocument GetDocumentWithTrimmedComponentsAndResponses(OpenApiDocu
//empty out all the responses with a single empty 2XX
foreach (var operation in doc.Paths.SelectMany(static item => item.Value.Operations.Values))
{
var responseDescription = operation.Responses.Values.Select(static response => response.Description)
.FirstOrDefault(static desc => !string.IsNullOrEmpty(desc)) ?? "Api Response";
operation.Responses = new OpenApiResponses()
{
{
"2XX",new OpenApiResponse
{
Description = responseDescription,
Content = new Dictionary<string, OpenApiMediaType>
{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public async Task GeneratesManifestAndCleansUpInputDescription()
Assert.Empty(resultDocument.Extensions); // no extension at root (unsupported extension is removed)
Assert.Equal(2, resultDocument.Paths.Count); // document has only two paths
Assert.Single(resultDocument.Paths["/test"].Operations[OperationType.Get].Responses); // other responses are removed from the document
Assert.NotEmpty(resultDocument.Paths["/test"].Operations[OperationType.Get].Responses["2XX"].Description); // response description string is not empty
Assert.Single(resultDocument.Paths["/test/{id}"].Operations[OperationType.Get].Responses); // 2 responses originally
Assert.NotEmpty(resultDocument.Paths["/test/{id}"].Operations[OperationType.Get].Responses["2XX"].Description);// response description string is not empty
}
}

0 comments on commit 9c8d937

Please sign in to comment.