diff --git a/CHANGELOG.md b/CHANGELOG.md
index a732d9914d..e17050735e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed an issue where multipart request content would be ignored if other unstructured content was present in the description. [#5638](https://github.com/microsoft/kiota/issues/5638)
- 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/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)
## [1.19.1] - 2024-10-11
diff --git a/it/config.json b/it/config.json
index f6e1a2ae70..1e7120f803 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": [
@@ -79,8 +21,34 @@
"MockServerITFolder": "gh",
"Suppressions": [
{
- "Language": "all",
- "Rationale": "https://github.com/microsoft/kiota/issues/4241"
+ "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": [
+ {
+ "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 +119,6 @@
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/2484"
- },
- {
- "Language": "python",
- "Rationale": "https://github.com/microsoft/kiota/issues/2957"
}
],
"IdempotencySuppressions": []
@@ -229,10 +193,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"
@@ -248,6 +208,10 @@
{
"Language": "php",
"Rationale": "https://github.com/microsoft/kiota/issues/5354"
+ },
+ {
+ "Language": "typescript",
+ "Rationale": "https://github.com/microsoft/kiota/issues/5353"
}
],
"IdempotencySuppressions": [
@@ -281,7 +245,7 @@
},
{
"Language": "python",
- "Rationale": "https://github.com/microsoft/kiota/issues/3030"
+ "Rationale": "https://github.com/microsoft/kiota/issues/5637"
}
]
},
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 })
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/gh/src/test/java/GHAPITest.java b/it/java/gh/src/test/java/GHAPITest.java
index cc9f50ec48..1a0409497e 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 {
@@ -17,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(null);
+ 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);
}
}
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
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/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();
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/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/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/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)
diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
index aaf4e8d449..b1c6dcc045 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,62 @@ 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 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()
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/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]
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()