From c51e6740f1f34b066cdd7a3028255a5f1cead1d1 Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Fri, 18 Oct 2024 10:43:01 +0100 Subject: [PATCH 01/15] Initial fixes to restore Java IT --- it/get-additional-arguments.ps1 | 2 +- it/java/basic/pom.xml | 2 +- it/java/gh/pom.xml | 2 +- it/java/gh/src/test/java/GHAPITest.java | 8 ++------ 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/it/get-additional-arguments.ps1 b/it/get-additional-arguments.ps1 index 6f68879e2d..aa1e6db286 100755 --- a/it/get-additional-arguments.ps1 +++ b/it/get-additional-arguments.ps1 @@ -21,7 +21,7 @@ if ($language -eq "csharp") { $command = " --output `"./it/$language/client`" --namespace-name `"app.client`"" } elseif ($language -eq "java") { - $command = " --output `"./it/$language/src`"" + $command = " --output `"./it/$language/src/apisdk`"" } elseif ($language -eq "go") { $command = " --output `"./it/$language/client`" --namespace-name `"integrationtest/client`"" diff --git a/it/java/basic/pom.xml b/it/java/basic/pom.xml index 6f1bad14e6..ae528722a1 100644 --- a/it/java/basic/pom.xml +++ b/it/java/basic/pom.xml @@ -15,7 +15,7 @@ UTF-8 UTF-8 - 1.1.1 + 1.7.0 diff --git a/it/java/gh/pom.xml b/it/java/gh/pom.xml index 4dae43e904..5087ebf3fe 100644 --- a/it/java/gh/pom.xml +++ b/it/java/gh/pom.xml @@ -15,7 +15,7 @@ UTF-8 UTF-8 - 1.1.1 + 1.7.0 diff --git a/it/java/gh/src/test/java/GHAPITest.java b/it/java/gh/src/test/java/GHAPITest.java index cc9f50ec48..c148c5a8ad 100644 --- a/it/java/gh/src/test/java/GHAPITest.java +++ b/it/java/gh/src/test/java/GHAPITest.java @@ -1,14 +1,10 @@ import apisdk.ApiClient; -import com.microsoft.kiota.ApiException; +import apisdk.repos.item.item.generate.GeneratePostRequestBody; import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider; import com.microsoft.kiota.http.OkHttpRequestAdapter; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.util.concurrent.TimeUnit; - -public class BasicAPITest { +public class GHAPITest { @Test void basicTest() throws Exception { From e06af9f7040850c3310b0e290a410b79e5a2d946 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 10:14:47 -0400 Subject: [PATCH 02/15] chore: linting Signed-off-by: Vincent Biret --- tests/Kiota.Builder.Tests/KiotaBuilderTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index 32123dcde3..ae63b3d12e 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -7328,7 +7328,7 @@ public async Task MergesIntersectionTypesAsync() var codeModel = builder.CreateSourceModel(node); var resultClass = codeModel.FindChildByName("DirectoryObjectGetResponse"); Assert.NotNull(resultClass); - Assert.Equal(4, resultClass.Properties.Where(static x => x.IsOfKind(CodePropertyKind.Custom)).Count()); + Assert.Equal(4, resultClass.Properties.Count(static x => x.IsOfKind(CodePropertyKind.Custom))); } [Fact] public async Task SkipsInvalidItemsPropertiesAsync() @@ -7373,7 +7373,7 @@ public async Task SkipsInvalidItemsPropertiesAsync() Assert.NotNull(propertiesToValidate); Assert.NotEmpty(propertiesToValidate); Assert.Equal(keysToCheck.Count, propertiesToValidate.Length);// all the properties are present - Assert.Single(resultClass.Properties, x => x.IsOfKind(CodePropertyKind.Custom) && x.Name.Equals("id", StringComparison.OrdinalIgnoreCase)); + Assert.Single(resultClass.Properties, static x => x.IsOfKind(CodePropertyKind.Custom) && x.Name.Equals("id", StringComparison.OrdinalIgnoreCase)); } [Fact] public async Task DescriptionTakenFromAllOfAsync() From 89019a12488f382f9c2d3d5b515f1b7c963568d8 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 10:32:08 -0400 Subject: [PATCH 03/15] fix: naming issue for inherited inline models --- CHANGELOG.md | 3 +- src/Kiota.Builder/KiotaBuilder.cs | 5 +- .../Kiota.Builder.Tests/KiotaBuilderTests.cs | 55 +++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d02c06c805..f740aa3aa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an issue where when generating Go code the deserializer for unions was using `CodeClass` as a filter and not `CodeInterface`. [#4844](https://github.com/microsoft/kiota/issues/4844) - Fixes mapping of `int16` format to the `integer` type rather than `double` when the type is `integer` or `number` [#5611](https://github.com/microsoft/kiota/issues/5611) +- Fixed a bug where the type name for inherited inline models would be incorrect. [#5610](https://github.com/microsoft/kiota/issues/5610) ## [1.19.1] - 2024-10-11 @@ -1484,5 +1485,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial GitHub release - - diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index 4325507151..193f336e99 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -1667,7 +1667,10 @@ private CodeClass CreateInheritedModelDeclaration(OpenApiUrlTreeNode currentNode var inlineSchemas = Array.FindAll(flattenedAllOfs, static x => !x.IsReferencedSchema()); var referencedSchemas = Array.FindAll(flattenedAllOfs, static x => x.IsReferencedSchema()); var rootSchemaHasProperties = schema.HasAnyProperty(); - var className = (schema.GetSchemaName(schema.IsSemanticallyMeaningful()) is string cName && !string.IsNullOrEmpty(cName) ? + // if the schema is meaningful, we only want to consider the root schema for naming to avoid "grabbing" the name of the parent + // if the schema has no reference id we're either at the beginning of an inline schema, or expanding the inheritance tree + var shouldNameLookupConsiderSubSchemas = schema.IsSemanticallyMeaningful() || string.IsNullOrEmpty(referenceId); + var className = (schema.GetSchemaName(shouldNameLookupConsiderSubSchemas) is string cName && !string.IsNullOrEmpty(cName) ? cName : (!string.IsNullOrEmpty(typeNameForInlineSchema) ? typeNameForInlineSchema : diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index ae63b3d12e..d979fb6049 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -7376,6 +7376,61 @@ public async Task SkipsInvalidItemsPropertiesAsync() Assert.Single(resultClass.Properties, static x => x.IsOfKind(CodePropertyKind.Custom) && x.Name.Equals("id", StringComparison.OrdinalIgnoreCase)); } [Fact] + public async Task GetsCorrectInheritedInlineSchemaNameAsync() + { + var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); + await using var fs = await GetDocumentStreamAsync(@"openapi: 3.0.3 +servers: +- url: https://api.github.com +info: + title: GitHub API + version: 1.0.0 +paths: + '/app-manifests/{code}/conversions': + post: + operationId: apps/create-from-manifest + parameters: + - in: path + name: code + required: true + schema: + type: string + responses: + '201': + content: + application/json: + schema: + allOf: + - '$ref': '#/components/schemas/integration' + - additionalProperties: true + properties: + client_id: + type: string + client_secret: + type: string + pem: + type: string + webhook_secret: + nullable: true + type: string + type: object + description: Response +components: + schemas: + integration: + properties: + client_id: + type: string + title: GitHub app + type: object"); + var mockLogger = new Mock>(); + var builder = new KiotaBuilder(mockLogger.Object, new GenerationConfiguration { ClientClassName = "Graph", OpenAPIFilePath = tempFilePath }, _httpClient); + var document = await builder.CreateOpenApiDocumentAsync(fs); + var node = builder.CreateUriSpace(document); + var codeModel = builder.CreateSourceModel(node); + Assert.NotNull(codeModel.FindChildByName("ConversionsPostResponse")); + } + [Fact] public async Task DescriptionTakenFromAllOfAsync() { var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); From 18b4d6b553d58f42a66a5cdf7819b94b233d4003 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 11:06:38 -0400 Subject: [PATCH 04/15] fix: default bool quotes values java Signed-off-by: Vincent Biret --- CHANGELOG.md | 1 + .../Writers/CSharp/CodeMethodWriter.cs | 9 ++++++--- src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs | 9 ++++++--- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 11 +++++++---- .../Writers/CSharp/CodeMethodWriterTests.cs | 14 ++++++++++++++ .../Writers/Java/CodeMethodWriterTests.cs | 14 ++++++++++++++ .../Writers/Php/CodeMethodWriterTests.cs | 14 ++++++++++++++ 7 files changed, 62 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f740aa3aa5..ed84ce167c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an issue where when generating Go code the deserializer for unions was using `CodeClass` as a filter and not `CodeInterface`. [#4844](https://github.com/microsoft/kiota/issues/4844) - Fixes mapping of `int16` format to the `integer` type rather than `double` when the type is `integer` or `number` [#5611](https://github.com/microsoft/kiota/issues/5611) +- Fixed a bug where default boolean values with quotes would fail in Java/PHP/CSharp. - Fixed a bug where the type name for inherited inline models would be incorrect. [#5610](https://github.com/microsoft/kiota/issues/5610) ## [1.19.1] - 2024-10-11 diff --git a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs index 2645ea5550..2bee2503fb 100644 --- a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs @@ -250,12 +250,15 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho { defaultValue = $"{conventions.GetTypeString(propWithDefault.Type, currentMethod).TrimEnd('?')}.{defaultValue.Trim('"').CleanupSymbolName().ToFirstCharacterUpperCase()}"; } - // avoid setting null as a string. - if (propWithDefault.Type.IsNullable && + else if (propWithDefault.Type.IsNullable && defaultValue.TrimQuotes().Equals(NullValueString, StringComparison.OrdinalIgnoreCase)) - { + { // avoid setting null as a string. defaultValue = NullValueString; } + else if (propWithDefault.Type is CodeType propType && propType.Name.Equals("boolean", StringComparison.OrdinalIgnoreCase)) + { + defaultValue = defaultValue.TrimQuotes(); + } writer.WriteLine($"{propWithDefault.Name.ToFirstCharacterUpperCase()} = {defaultValue};"); } if (parentClass.IsOfKind(CodeClassKind.RequestBuilder) && diff --git a/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs index a3113f3df9..67e8dbdab6 100644 --- a/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs @@ -358,12 +358,15 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho { defaultValue = $"{enumDefinition.Name}.forValue({defaultValue})"; } - // avoid setting null as a string. - if (propWithDefault.Type.IsNullable && + else if (propWithDefault.Type.IsNullable && defaultValue.TrimQuotes().Equals(NullValueString, StringComparison.OrdinalIgnoreCase)) - { + {// avoid setting null as a string. defaultValue = NullValueString; } + else if (propWithDefault.Type is CodeType propType && propType.Name.Equals("boolean", StringComparison.OrdinalIgnoreCase)) + { + defaultValue = defaultValue.TrimQuotes(); + } writer.WriteLine($"this.{setterName}({defaultValue});"); } if (parentClass.IsOfKind(CodeClassKind.RequestBuilder) && diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 8b8c870165..a8601c382a 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -150,12 +150,15 @@ private void WriteModelConstructorBody(CodeClass parentClass, LanguageWriter wri { defaultValue = $"new {enumDefinition.Name.ToFirstCharacterUpperCase()}({defaultValue})"; } - // avoid setting null as a string. - if (propWithDefault.Type.IsNullable && + else if (propWithDefault.Type.IsNullable && defaultValue.TrimQuotes().Equals(NullValueString, StringComparison.OrdinalIgnoreCase)) - { + { // avoid setting null as a string. defaultValue = NullValueString; } + else if (propWithDefault.Type is CodeType propType && propType.Name.Equals("boolean", StringComparison.OrdinalIgnoreCase)) + { + defaultValue = defaultValue.TrimQuotes(); + } writer.WriteLine($"$this->{setterName}({defaultValue});"); } } @@ -241,7 +244,7 @@ private void WritePathParametersOptions(CodeMethod currentMethod, CodeClass pare currentMethod.Parameters.Where(static parameter => parameter.IsOfKind(CodeParameterKind.Path)).ToList() .ForEach(parameter => { - var key = String.IsNullOrEmpty(parameter.SerializationName) + var key = string.IsNullOrEmpty(parameter.SerializationName) ? parameter.Name : parameter.SerializationName; writer.WriteLine($"{UrlTemplateTempVarName}['{key}'] = ${parameter.Name.ToFirstCharacterLowerCase()};"); diff --git a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs index 9b2dc48247..0bb3f9441d 100644 --- a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs @@ -1502,6 +1502,19 @@ public void WritesConstructor() IsNullable = true } }); + var defaultValueBool = "\"true\""; + var boolPropName = "propWithDefaultBoolValue"; + parentClass.AddProperty(new CodeProperty + { + Name = boolPropName, + DefaultValue = defaultValueBool, + Kind = CodePropertyKind.Custom, + Type = new CodeType + { + Name = "boolean", + IsNullable = true + } + }); writer.Write(method); var result = tw.ToString(); Assert.Contains("", result); @@ -1509,6 +1522,7 @@ public void WritesConstructor() Assert.Contains(parentClass.Name.ToFirstCharacterUpperCase(), result); Assert.Contains($"{propName.ToFirstCharacterUpperCase()} = {defaultValue}", result); Assert.Contains($"{nullPropName.ToFirstCharacterUpperCase()} = {defaultValueNull.TrimQuotes()}", result); + Assert.Contains($"{boolPropName.ToFirstCharacterUpperCase()} = {defaultValueBool.TrimQuotes()}", result); } [Fact] public void WritesWithUrl() diff --git a/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs index c1defb8fb6..1c0701650c 100644 --- a/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs @@ -1800,6 +1800,19 @@ public void WritesConstructor() IsNullable = true } }); + var defaultValueBool = "\"true\""; + var boolPropName = "propWithDefaultBoolValue"; + parentClass.AddProperty(new CodeProperty + { + Name = boolPropName, + DefaultValue = defaultValueBool, + Kind = CodePropertyKind.Custom, + Type = new CodeType + { + Name = "boolean", + IsNullable = true + } + }); AddRequestProperties(); method.AddParameter(new CodeParameter { @@ -1815,6 +1828,7 @@ public void WritesConstructor() Assert.Contains(parentClass.Name, result); Assert.Contains($"this.set{propName.ToFirstCharacterUpperCase()}({defaultValue})", result); Assert.Contains($"this.set{nullPropName.ToFirstCharacterUpperCase()}({defaultValueNull.TrimQuotes()})", result); + Assert.Contains($"this.set{boolPropName.ToFirstCharacterUpperCase()}({defaultValueBool.TrimQuotes()})", result); Assert.Contains("super", result); } [Fact] diff --git a/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs index 4afb2e42f3..fe01e34e07 100644 --- a/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs @@ -1138,6 +1138,19 @@ public async Task WriteConstructorBodyAsync() IsNullable = true } }); + var defaultValueBool = "\"true\""; + var boolPropName = "propWithDefaultBoolValue"; + parentClass.AddProperty(new CodeProperty + { + Name = boolPropName, + DefaultValue = defaultValueBool, + Kind = CodePropertyKind.Custom, + Type = new CodeType + { + Name = "boolean", + IsNullable = true + } + }); await ILanguageRefiner.RefineAsync(new GenerationConfiguration { Language = GenerationLanguage.PHP }, root); _codeMethodWriter.WriteCodeElement(constructor, languageWriter); var result = stringWriter.ToString(); @@ -1146,6 +1159,7 @@ public async Task WriteConstructorBodyAsync() Assert.Contains("$this->setType('#microsoft.graph.entity')", result); Assert.Contains("$this->setCountryCode(new CountryCode('+254'));", result); Assert.Contains("$this->setPropWithDefaultNullValue(null)", result); + Assert.Contains("$this->setPropWithDefaultBoolValue(true)", result); } [Fact] public void DoesNotWriteConstructorWithDefaultFromComposedType() From 1a42b639ec9e2a4f5614a1966faa2119477c3d69 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 11:19:31 -0400 Subject: [PATCH 05/15] ci: removes fixed suppressions Signed-off-by: Vincent Biret --- it/config.json | 88 +++++++++++--------------------------------------- 1 file changed, 18 insertions(+), 70 deletions(-) diff --git a/it/config.json b/it/config.json index f6e1a2ae70..cfc4e7aab8 100644 --- a/it/config.json +++ b/it/config.json @@ -1,54 +1,4 @@ { - "oas::petstore": { - "ExcludePatterns": [ - { - "Pattern": "/gists", - "Rationale": "https://github.com/github/rest-api-description/issues/214" - }, - { - "Pattern": "/gists/**", - "Rationale": "https://github.com/github/rest-api-description/issues/214" - }, - { - "Pattern": "/users/*/gists", - "Rationale": "https://github.com/github/rest-api-description/issues/214" - }, - { - "Pattern": "/orgs/*/migrations", - "Rationale": "https://github.com/github/rest-api-description/issues/2246" - }, - { - "Pattern": "/orgs/*/migrations/**", - "Rationale": "https://github.com/github/rest-api-description/issues/2246" - }, - { - "Pattern": "/user/migrations", - "Rationale": "https://github.com/github/rest-api-description/issues/2246" - }, - { - "Pattern": "/user/migrations/**", - "Rationale": "https://github.com/github/rest-api-description/issues/2246" - }, - { - "Pattern": "/users/*/gpg_keys", - "Rationale": "https://github.com/github/rest-api-description/issues/2247" - }, - { - "Pattern": "/user/gpg_keys", - "Rationale": "https://github.com/github/rest-api-description/issues/2247" - }, - { - "Pattern": "/user/gpg_keys/**", - "Rationale": "https://github.com/github/rest-api-description/issues/2247" - } - ], - "Suppressions": [ - { - "Language": "ruby", - "Rationale": "https://github.com/microsoft/kiota/issues/1816" - } - ] - }, "./tests/Kiota.Builder.IntegrationTests/InheritingErrors.yaml": { "MockServerITFolder": "basic", "Suppressions": [ @@ -58,14 +8,6 @@ } ] }, - "./tests/Kiota.Builder.IntegrationTests/NoUnderscoresInModel.yaml": { - "Suppressions": [ - { - "Language": "ruby", - "Rationale": "https://github.com/microsoft/kiota/issues/2374" - } - ] - }, "./tests/Kiota.Builder.IntegrationTests/GeneratesUritemplateHints.yaml": { "MockServerITFolder": "query-params", "Suppressions": [ @@ -81,6 +23,24 @@ { "Language": "all", "Rationale": "https://github.com/microsoft/kiota/issues/4241" + }, + { + "Language": "ruby", + "Rationale": "https://github.com/microsoft/kiota/issues/1816" + } + ], + "ExcludePatterns": [ + { + "Pattern": "/users/*/gpg_keys", + "Rationale": "https://github.com/github/rest-api-description/issues/2247" + }, + { + "Pattern": "/user/gpg_keys", + "Rationale": "https://github.com/github/rest-api-description/issues/2247" + }, + { + "Pattern": "/user/gpg_keys/**", + "Rationale": "https://github.com/github/rest-api-description/issues/2247" } ] }, @@ -151,10 +111,6 @@ { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/2484" - }, - { - "Language": "python", - "Rationale": "https://github.com/microsoft/kiota/issues/2957" } ], "IdempotencySuppressions": [] @@ -229,10 +185,6 @@ }, "apisguru::stripe.com": { "Suppressions": [ - { - "Language": "typescript", - "Rationale": "https://github.com/microsoft/kiota/issues/5256" - }, { "Language": "java", "Rationale": "https://github.com/microsoft/kiota/issues/2842" @@ -278,10 +230,6 @@ { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/2484" - }, - { - "Language": "python", - "Rationale": "https://github.com/microsoft/kiota/issues/3030" } ] }, From 8be57154446324e2d2530f5af0346ad0a09d6c86 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 11:23:04 -0400 Subject: [PATCH 06/15] fix: missing body parameter for gh integration test Signed-off-by: Vincent Biret --- it/java/gh/src/test/java/GHAPITest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/it/java/gh/src/test/java/GHAPITest.java b/it/java/gh/src/test/java/GHAPITest.java index c148c5a8ad..18a1fb4f6f 100644 --- a/it/java/gh/src/test/java/GHAPITest.java +++ b/it/java/gh/src/test/java/GHAPITest.java @@ -13,7 +13,7 @@ void basicTest() throws Exception { var client = new ApiClient(adapter); client.repos().byOrgId("my-owner").byRepoId("my-repo").get(); - client.repos().byOrgId("my-owner").byRepoId("my-repo").generate().post(null); + client.repos().byOrgId("my-owner").byRepoId("my-repo").generate().post(new GeneratePostRequestBody()); } } From 75934f10429b6008b86e9f5967625ad709b1e251 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 12:15:29 -0400 Subject: [PATCH 07/15] ci: fixes the mock server script to ensure it also works on windows Signed-off-by: Vincent Biret --- it/exec-cmd.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/it/exec-cmd.ps1 b/it/exec-cmd.ps1 index af5993caa3..ee6faf9440 100755 --- a/it/exec-cmd.ps1 +++ b/it/exec-cmd.ps1 @@ -78,7 +78,7 @@ if ($mockServerTest) { Pop-Location # Provision Mock server with the right spec - $openapiUrl = Join-Path -Path $PSScriptRoot -ChildPath "openapi.yaml" + $openapiUrl = (Join-Path -Path $PSScriptRoot -ChildPath "openapi.yaml") -replace '\\', '/' # provision MockServer to mock the specific openapi description https://www.mock-server.com/mock_server/using_openapi.html#button_open_api_filepath Retry({ Invoke-WebRequest -Method PUT -Body "{ `"specUrlOrPayload`": `"$openapiUrl`" }" -Uri http://localhost:1080/mockserver/openapi -ContentType application/json }) From 379ea7cf83feac3ec436ef2cc53f442e00663b14 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 12:27:30 -0400 Subject: [PATCH 08/15] chore: updates mock server version Signed-off-by: Vincent Biret --- it/mockserver/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/it/mockserver/pom.xml b/it/mockserver/pom.xml index 220e6f2416..05f13ed6f6 100644 --- a/it/mockserver/pom.xml +++ b/it/mockserver/pom.xml @@ -9,7 +9,7 @@ 0.0.1-SNAPSHOT - 5.14.0 + 5.15.0 From cc06e93f193efadce5fdd61eaf093dd782238220 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 12:32:46 -0400 Subject: [PATCH 09/15] fix: adds missing required properties to payload Signed-off-by: Vincent Biret --- it/java/gh/src/test/java/GHAPITest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/it/java/gh/src/test/java/GHAPITest.java b/it/java/gh/src/test/java/GHAPITest.java index 18a1fb4f6f..1a0409497e 100644 --- a/it/java/gh/src/test/java/GHAPITest.java +++ b/it/java/gh/src/test/java/GHAPITest.java @@ -13,7 +13,13 @@ void basicTest() throws Exception { var client = new ApiClient(adapter); client.repos().byOrgId("my-owner").byRepoId("my-repo").get(); - client.repos().byOrgId("my-owner").byRepoId("my-repo").generate().post(new GeneratePostRequestBody()); + final GeneratePostRequestBody body = new GeneratePostRequestBody(); + body.setDescription("my description"); + body.setIncludeAllBranches(true); + body.setName("my-repo2"); + body.setOwner("my-owner2"); + body.setPrivate(false); + client.repos().byOrgId("my-owner").byRepoId("my-repo").generate().post(body); } } From 139c9589cc8a4a995700cdbab7330ea736c4e2bf Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 12:44:07 -0400 Subject: [PATCH 10/15] fix: missing internal imports for python serialization Signed-off-by: Vincent Biret --- src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs index f9d19b388c..4cf7b7fc80 100644 --- a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs @@ -646,6 +646,7 @@ private void WriteSerializerBodyForInheritedModel(bool inherits, CodeClass paren { if (inherits) writer.WriteLine("super().serialize(writer)"); + _codeUsingWriter.WriteInternalImports(parentClass, writer); foreach (var otherProp in parentClass .GetPropertiesOfKind(CodePropertyKind.Custom) .Where(static x => !x.ExistsInBaseType && !x.ReadOnly) From 7009fe6165a7cd2405be15dc352c55695141c9d7 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 12:44:46 -0400 Subject: [PATCH 11/15] ci: adds missing suppression for typescript composed types Signed-off-by: Vincent Biret --- it/config.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/it/config.json b/it/config.json index cfc4e7aab8..49992beecf 100644 --- a/it/config.json +++ b/it/config.json @@ -200,6 +200,10 @@ { "Language": "php", "Rationale": "https://github.com/microsoft/kiota/issues/5354" + }, + { + "Language": "typescript", + "Rationale": "https://github.com/microsoft/kiota/issues/5353" } ], "IdempotencySuppressions": [ From dbeba87ca1617ce84c7c680e7abb7e6032b2f524 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 12:45:39 -0400 Subject: [PATCH 12/15] ci: removes blanket suppression for github integration tests Signed-off-by: Vincent Biret --- it/config.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/it/config.json b/it/config.json index 49992beecf..b84859ae1b 100644 --- a/it/config.json +++ b/it/config.json @@ -20,10 +20,6 @@ "apisguru::github.com:api.github.com": { "MockServerITFolder": "gh", "Suppressions": [ - { - "Language": "all", - "Rationale": "https://github.com/microsoft/kiota/issues/4241" - }, { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/1816" From 939137b7d23402276678300a3598db3518a808dc Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 13:06:58 -0400 Subject: [PATCH 13/15] fix: wrong import for composed type wrapper in CSharp Signed-off-by: Vincent Biret --- CHANGELOG.md | 1 + src/Kiota.Builder/Refiners/CSharpRefiner.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa92e408a3..29ec810e7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an issue where when generating Go code the deserializer for unions was using `CodeClass` as a filter and not `CodeInterface`. [#4844](https://github.com/microsoft/kiota/issues/4844) - Fixes mapping of `int16` format to the `integer` type rather than `double` when the type is `integer` or `number` [#5611](https://github.com/microsoft/kiota/issues/5611) - Fixed a bug where default boolean values with quotes would fail in Java/PHP/CSharp. +- Fixed a bug where composed types wrappers would not build in CSharp. - Fixed a bug where the type name for inherited inline models would be incorrect. [#5610](https://github.com/microsoft/kiota/issues/5610) - Fixes typing inconsistencies in generated code and libraries in Python [kiota-python#333](https://github.com/microsoft/kiota-python/issues/333) diff --git a/src/Kiota.Builder/Refiners/CSharpRefiner.cs b/src/Kiota.Builder/Refiners/CSharpRefiner.cs index c432dee00e..6a59fb3bd5 100644 --- a/src/Kiota.Builder/Refiners/CSharpRefiner.cs +++ b/src/Kiota.Builder/Refiners/CSharpRefiner.cs @@ -56,7 +56,7 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken _configuration.UsesBackingStore, static s => s, true, - AbstractionsNamespaceName, + SerializationNamespaceName, "IComposedTypeWrapper" ); cancellationToken.ThrowIfCancellationRequested(); From eaa8e956751882b0219f44f80125cdfed97d933a Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 13:20:31 -0400 Subject: [PATCH 14/15] fix: default quoted bool or null in go Signed-off-by: Vincent Biret --- CHANGELOG.md | 2 +- .../Writers/Go/CodeMethodWriter.cs | 11 ++++++- .../Writers/Go/CodeMethodWriterTests.cs | 29 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29ec810e7c..ace7a437e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an issue where when generating Go code the deserializer for unions was using `CodeClass` as a filter and not `CodeInterface`. [#4844](https://github.com/microsoft/kiota/issues/4844) - Fixes mapping of `int16` format to the `integer` type rather than `double` when the type is `integer` or `number` [#5611](https://github.com/microsoft/kiota/issues/5611) -- Fixed a bug where default boolean values with quotes would fail in Java/PHP/CSharp. +- Fixed a bug where default boolean values with quotes would fail in Java/PHP/CSharp/Go. - Fixed a bug where composed types wrappers would not build in CSharp. - Fixed a bug where the type name for inherited inline models would be incorrect. [#5610](https://github.com/microsoft/kiota/issues/5610) - Fixes typing inconsistencies in generated code and libraries in Python [kiota-python#333](https://github.com/microsoft/kiota-python/issues/333) diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index 59a288062b..542be4f681 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -569,7 +569,12 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho .OrderBy(static x => x.Name)) { var defaultValueReference = propWithDefault.DefaultValue; - if (defaultValueReference.StartsWith('"')) + if (propWithDefault.Type.IsNullable && + defaultValueReference.TrimQuotes().Equals("null", StringComparison.OrdinalIgnoreCase)) + {// avoid setting null as a string. + defaultValueReference = "nil"; + } + else if (defaultValueReference.StartsWith('"')) { defaultValueReference = $"{propWithDefault.Name.ToFirstCharacterLowerCase()}Value"; var defaultValue = propWithDefault.DefaultValue; @@ -580,6 +585,10 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho enumDefinition.Options.FirstOrDefault(x => x.SerializationName.Equals(defaultValue, StringComparison.OrdinalIgnoreCase))?.Name ?? defaultValue; defaultValue = $"{defaultValue.ToUpperInvariant()}_{enumDefinition.Name.ToUpperInvariant()}"; } + else if (propWithDefault.Type is CodeType propType && propType.Name.Equals("boolean", StringComparison.OrdinalIgnoreCase)) + { + defaultValue = defaultValue.TrimQuotes(); + } writer.WriteLine($"{defaultValueReference} := {defaultValue}"); defaultValueReference = $"&{defaultValueReference}"; } diff --git a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs index 885af77aae..e9b5f586fa 100644 --- a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs @@ -1871,6 +1871,32 @@ public void WritesConstructor() Name = "string", } }); + var defaultValueNull = "\"null\""; + var nullPropName = "propWithDefaultNullValue"; + parentClass.AddProperty(new CodeProperty + { + Name = nullPropName, + DefaultValue = defaultValueNull, + Kind = CodePropertyKind.Custom, + Type = new CodeType + { + Name = "int", + IsNullable = true + } + }); + var defaultValueBool = "\"true\""; + var boolPropName = "propWithDefaultBoolValue"; + parentClass.AddProperty(new CodeProperty + { + Name = boolPropName, + DefaultValue = defaultValueBool, + Kind = CodePropertyKind.Custom, + Type = new CodeType + { + Name = "boolean", + IsNullable = true + } + }); AddRequestProperties(); method.AddParameter(new CodeParameter { @@ -1885,6 +1911,9 @@ public void WritesConstructor() var result = tw.ToString(); Assert.Contains(parentClass.Name.ToFirstCharacterUpperCase(), result); Assert.Contains($"m.Set{propName.ToFirstCharacterUpperCase()}({defaultValue})", result); + Assert.Contains($"m.SetPropWithDefaultNullValue(nil)", result); + Assert.Contains($"propWithDefaultBoolValueValue := true", result); + Assert.Contains($"m.SetPropWithDefaultBoolValue(&propWithDefaultBoolValueValue)", result); Assert.Contains("NewBaseRequestBuilder", result); } [Fact] From 7dacd03e460f0886f6f2286ef91adc5323027cc4 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 13:40:08 -0400 Subject: [PATCH 15/15] ci: adds missing suppressions for failing integration tests Signed-off-by: Vincent Biret --- it/config.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/it/config.json b/it/config.json index b84859ae1b..1e7120f803 100644 --- a/it/config.json +++ b/it/config.json @@ -20,9 +20,21 @@ "apisguru::github.com:api.github.com": { "MockServerITFolder": "gh", "Suppressions": [ + { + "Language": "typescript", + "Rationale": "https://github.com/microsoft/kiota/issues/5634" + }, + { + "Language": "php", + "Rationale": "https://github.com/microsoft/kiota/issues/5635" + }, { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/1816" + }, + { + "Language": "python", + "Rationale": "https://github.com/microsoft/kiota/issues/5636" } ], "ExcludePatterns": [ @@ -230,6 +242,10 @@ { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/2484" + }, + { + "Language": "python", + "Rationale": "https://github.com/microsoft/kiota/issues/5637" } ] },