From 9075bed49c6821f55a4247bbf4327e0175f3e068 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Thu, 13 Jun 2024 16:29:47 +0300 Subject: [PATCH] Ensure description is not empty --- CHANGELOG.md | 1 + src/Kiota.Builder/Plugins/PluginsGenerationService.cs | 3 +++ .../Plugins/PluginsGenerationServiceTests.cs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30ce596928..e4966f58d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs index 2acad9f0de..b13d40d731 100644 --- a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs +++ b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs @@ -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 { { diff --git a/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs b/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs index e67253a8c4..509004f814 100644 --- a/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs +++ b/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs @@ -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 } }