From 0fbb488a77c9562c5f010d5e7c13670bc06dec6d Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Thu, 28 Nov 2024 00:33:47 +0300 Subject: [PATCH 01/26] Updated discriminator method to ensure that primitive types don't default to collection of objects --- it/config.json | 4 ---- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/it/config.json b/it/config.json index 777f0a36fd..78cab6a5fe 100644 --- a/it/config.json +++ b/it/config.json @@ -32,10 +32,6 @@ { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/1816" - }, - { - "Language": "php", - "Rationale": "https://github.com/microsoft/kiota/issues/5779" } ], "ExcludePatterns": [ diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index a8601c382a..165a81ba33 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -486,6 +486,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me parseNodeMethod = currentType.TypeDefinition switch { CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", + CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", _ => $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" }; else if (currentType.TypeDefinition is CodeEnum) From d9caaa91a68e577b494819b1ce316cb049e0ac5f Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Thu, 28 Nov 2024 00:54:54 +0300 Subject: [PATCH 02/26] Checked for null type definition --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 165a81ba33..c5052c3237 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -485,6 +485,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me if (isCollection) parseNodeMethod = currentType.TypeDefinition switch { + CodeType codeType when codeType.TypeDefinition == null => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", _ => $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" From b553e9e1e484f153366b5a095b4c7a2c0d8e1e21 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Thu, 28 Nov 2024 01:06:28 +0300 Subject: [PATCH 03/26] Default to collection of primitive types for testing --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index c5052c3237..210871533a 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -485,10 +485,10 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me if (isCollection) parseNodeMethod = currentType.TypeDefinition switch { - CodeType codeType when codeType.TypeDefinition == null => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", + //CodeType codeType when codeType.TypeDefinition == null => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", - CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", - _ => $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" + //CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", + _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" }; else if (currentType.TypeDefinition is CodeEnum) parseNodeMethod = $"getEnumValue({propertyType.ToFirstCharacterUpperCase()}::class)"; From 4dd6a01e2b693c6ce32086c6955338590d80e771 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Thu, 28 Nov 2024 01:24:11 +0300 Subject: [PATCH 04/26] More updates on code method writer --- .../Writers/Php/CodeMethodWriter.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 210871533a..c9cbaf7910 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -483,13 +483,25 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me if (propType is CodeType currentType) { if (isCollection) - parseNodeMethod = currentType.TypeDefinition switch + // parseNodeMethod = currentType.TypeDefinition switch + // { + // //CodeType codeType when codeType.TypeDefinition == null => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", + // CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", + // //CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", + // _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" + // }; + if (currentType.TypeDefinition == null) { - //CodeType codeType when codeType.TypeDefinition == null => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", - CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", - //CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", - _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" - }; + parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; + } + else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) + { + parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; + } + else + { + parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; + } else if (currentType.TypeDefinition is CodeEnum) parseNodeMethod = $"getEnumValue({propertyType.ToFirstCharacterUpperCase()}::class)"; } @@ -503,6 +515,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me "decimal" or "double" => "getFloatValue()", "streaminterface" => "getBinaryContent()", "byte" => "getByteValue()", + "string" => "getStringValue()", _ when conventions.PrimitiveTypes.Contains(lowerCaseType) => $"get{propertyType.ToFirstCharacterUpperCase()}Value()", _ => $"getObjectValue([{propertyType.ToFirstCharacterUpperCase()}::class, '{CreateDiscriminatorMethodName}'])", } : parseNodeMethod; From 88c7ad21d258d1818403b58e4283156260068e0f Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Thu, 28 Nov 2024 01:29:27 +0300 Subject: [PATCH 05/26] Rolled back the default to object values --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index c9cbaf7910..579882a14a 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -500,7 +500,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me } else { - parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; + parseNodeMethod = $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; } else if (currentType.TypeDefinition is CodeEnum) parseNodeMethod = $"getEnumValue({propertyType.ToFirstCharacterUpperCase()}::class)"; From de7c9247ebc2140d0cc86095cd5ff7fd98fda9b7 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Thu, 28 Nov 2024 01:39:12 +0300 Subject: [PATCH 06/26] Added back enum check --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 579882a14a..9f8073a234 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -498,6 +498,10 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me { parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; } + else if (currentType.TypeDefinition is CodeEnum) + { + parseNodeMethod = $"getCollectionOfEnumValues({currentType.TypeDefinition.Name.ToFirstCharacterUpperCase()}::class)"; + } else { parseNodeMethod = $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; From 35551a10035a5cc7770aecfeaba0b7d15ed7361c Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Thu, 28 Nov 2024 01:52:43 +0300 Subject: [PATCH 07/26] Defaulted any null type definitions to collection of object values --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 9f8073a234..f1777e38ba 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -490,11 +490,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me // //CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", // _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" // }; - if (currentType.TypeDefinition == null) - { - parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; - } - else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) + if (currentType.TypeDefinition != null && conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) { parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; } From 803e3778c5f5e9f2a137afd2f22d5b73c0bffb11 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Thu, 28 Nov 2024 02:02:09 +0300 Subject: [PATCH 08/26] Rolled back --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index f1777e38ba..9f8073a234 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -490,7 +490,11 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me // //CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", // _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" // }; - if (currentType.TypeDefinition != null && conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) + if (currentType.TypeDefinition == null) + { + parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; + } + else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) { parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; } From 0f05da28f7ff6749393766901341eefffb1c3c69 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 00:15:56 +0300 Subject: [PATCH 09/26] Ensured that parameter passed to getCollectionOfPrimitiveValues is a string --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 9f8073a234..dd7c972470 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -492,11 +492,11 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me // }; if (currentType.TypeDefinition == null) { - parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; + parseNodeMethod = $"getCollectionOfPrimitiveValues('{CreateDiscriminatorMethodName}')"; } else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) { - parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; + parseNodeMethod = $"getCollectionOfPrimitiveValues('{CreateDiscriminatorMethodName}')"; } else if (currentType.TypeDefinition is CodeEnum) { From a5fa77432700b55153d7f526a912bf93aa3fc8e1 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 12:27:04 +0300 Subject: [PATCH 10/26] Updted method write --- .../Writers/Php/CodeMethodWriter.cs | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index dd7c972470..546cbcf95c 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -482,30 +482,31 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me var parseNodeMethod = string.Empty; if (propType is CodeType currentType) { + var collectionMethod = propType.IsArray ? "Array" : "Collection"; if (isCollection) - // parseNodeMethod = currentType.TypeDefinition switch - // { - // //CodeType codeType when codeType.TypeDefinition == null => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", - // CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", - // //CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", - // _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" - // }; - if (currentType.TypeDefinition == null) + parseNodeMethod = currentType.TypeDefinition switch { - parseNodeMethod = $"getCollectionOfPrimitiveValues('{CreateDiscriminatorMethodName}')"; - } - else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) - { - parseNodeMethod = $"getCollectionOfPrimitiveValues('{CreateDiscriminatorMethodName}')"; - } - else if (currentType.TypeDefinition is CodeEnum) - { - parseNodeMethod = $"getCollectionOfEnumValues({currentType.TypeDefinition.Name.ToFirstCharacterUpperCase()}::class)"; - } - else - { - parseNodeMethod = $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; - } + CodeType codeType when codeType.TypeDefinition == null => $"getCollectionOfPrimitiveValues()", + CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", + // CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues('{currentType.TypeDefinition.Name}')", + _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" + }; + // if (currentType.TypeDefinition == null) + // { + // parseNodeMethod = $"getCollectionOfPrimitiveValues()"; + // } + // else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) + // { + // parseNodeMethod = $"getCollectionOfPrimitiveValues('{currentType.TypeDefinition.Name}')"; + // } + // else if (currentType.TypeDefinition is CodeEnum) + // { + // parseNodeMethod = $"getCollectionOfEnumValues({currentType.TypeDefinition.Name.ToFirstCharacterUpperCase()}::class)"; + // } + // else + // { + // parseNodeMethod = $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; + // } else if (currentType.TypeDefinition is CodeEnum) parseNodeMethod = $"getEnumValue({propertyType.ToFirstCharacterUpperCase()}::class)"; } @@ -948,6 +949,7 @@ private void WriteFactoryMethodBodyForIntersectionModel(CodeMethod codeElement, writer.CloseBlock(decreaseIndent: false); } + private void WriteFactoryMethodBodyForUnionModelForDiscriminatedTypes(CodeMethod codeElement, CodeClass parentClass, LanguageWriter writer) { var includeElse = false; From 17a56af45af97ae8f7f30369f5d0a6687025ebf5 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 14:11:34 +0300 Subject: [PATCH 11/26] Updated code method writer for php --- .../Writers/Php/CodeMethodWriter.cs | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 546cbcf95c..969bdccd0b 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -484,29 +484,25 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me { var collectionMethod = propType.IsArray ? "Array" : "Collection"; if (isCollection) - parseNodeMethod = currentType.TypeDefinition switch + // parseNodeMethod = currentType.TypeDefinition switch + // { + // //CodeType codeType when codeType.TypeDefinition == null => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", + // CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", + // //CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", + // _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" + // }; + if (currentType.TypeDefinition != null && conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) { - CodeType codeType when codeType.TypeDefinition == null => $"getCollectionOfPrimitiveValues()", - CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", - // CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues('{currentType.TypeDefinition.Name}')", - _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" - }; - // if (currentType.TypeDefinition == null) - // { - // parseNodeMethod = $"getCollectionOfPrimitiveValues()"; - // } - // else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) - // { - // parseNodeMethod = $"getCollectionOfPrimitiveValues('{currentType.TypeDefinition.Name}')"; - // } - // else if (currentType.TypeDefinition is CodeEnum) - // { - // parseNodeMethod = $"getCollectionOfEnumValues({currentType.TypeDefinition.Name.ToFirstCharacterUpperCase()}::class)"; - // } - // else - // { - // parseNodeMethod = $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; - // } + parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); + } + else if (currentType.TypeDefinition is CodeEnum) + { + parseNodeMethod = $"getCollectionOfEnumValues({currentType.TypeDefinition.Name.ToFirstCharacterUpperCase()}::class)"; + } + else + { + parseNodeMethod = $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; + } else if (currentType.TypeDefinition is CodeEnum) parseNodeMethod = $"getEnumValue({propertyType.ToFirstCharacterUpperCase()}::class)"; } From 122a646d1d5cda0ddd7f980ad29897e1605f521a Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 14:29:09 +0300 Subject: [PATCH 12/26] More experimental updates --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 969bdccd0b..81598a7508 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -491,7 +491,15 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me // //CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", // _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" // }; - if (currentType.TypeDefinition != null && conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) + if (currentType.TypeDefinition is null) + { + parseNodeMethod = "object"; + } + else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) + { + parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); + } + else if (conventions.CustomTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) { parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); } From 55047bafac00738fbedbf46478204b329ba94aa4 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 14:50:26 +0300 Subject: [PATCH 13/26] Updated parseNodeMethod to be a collection of primitive values if type definition is null --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 81598a7508..d8ac6dbc6c 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -493,15 +493,15 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me // }; if (currentType.TypeDefinition is null) { - parseNodeMethod = "object"; + parseNodeMethod = $"getCollectionOfPrimitiveValues()"; } else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) { parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); } - else if (conventions.CustomTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) + else if (conventions.CustomTypes.Contains(currentType.TypeDefinition.Name.ToFirstCharacterUpperCase())) { - parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); + parseNodeMethod = currentType.TypeDefinition.Name.ToFirstCharacterUpperCase(); } else if (currentType.TypeDefinition is CodeEnum) { From d892c51b5cab65b6ec4e905e03ff7bcefdd9a33a Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 15:02:17 +0300 Subject: [PATCH 14/26] Defaulted parseNode method to a string incase type definition is null --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index d8ac6dbc6c..6f569913fe 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -493,7 +493,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me // }; if (currentType.TypeDefinition is null) { - parseNodeMethod = $"getCollectionOfPrimitiveValues()"; + parseNodeMethod = "string"; } else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) { @@ -501,7 +501,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me } else if (conventions.CustomTypes.Contains(currentType.TypeDefinition.Name.ToFirstCharacterUpperCase())) { - parseNodeMethod = currentType.TypeDefinition.Name.ToFirstCharacterUpperCase(); + parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); } else if (currentType.TypeDefinition is CodeEnum) { @@ -525,6 +525,8 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me "streaminterface" => "getBinaryContent()", "byte" => "getByteValue()", "string" => "getStringValue()", + "date" => "getDateValue()", + "datetime" => "getDateTimeValue()", _ when conventions.PrimitiveTypes.Contains(lowerCaseType) => $"get{propertyType.ToFirstCharacterUpperCase()}Value()", _ => $"getObjectValue([{propertyType.ToFirstCharacterUpperCase()}::class, '{CreateDiscriminatorMethodName}'])", } : parseNodeMethod; From f7b207082b561ef363aed83ea060362d258a71ad Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 15:40:29 +0300 Subject: [PATCH 15/26] Fixed undefined property error --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 6f569913fe..76eadad315 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -493,7 +493,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me // }; if (currentType.TypeDefinition is null) { - parseNodeMethod = "string"; + parseNodeMethod = "getStringValue()"; } else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) { From e38b2b00b8f1102baaa721361aa04b652ac0c418 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 15:55:15 +0300 Subject: [PATCH 16/26] Updated method writer during null checks in typedefinition --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 76eadad315..17a0287044 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -493,7 +493,8 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me // }; if (currentType.TypeDefinition is null) { - parseNodeMethod = "getStringValue()"; + //Set the parseNodeMethod to the appropriate method for the collection of primitive values + parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; } else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) { From 32c2757feb4abef399d21abc7acef35145a27904 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 17:06:01 +0300 Subject: [PATCH 17/26] Updated code writer --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 17a0287044..bc50823b39 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -494,7 +494,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me if (currentType.TypeDefinition is null) { //Set the parseNodeMethod to the appropriate method for the collection of primitive values - parseNodeMethod = $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; + parseNodeMethod = $"getCollectionOfPrimitiveValues()"; } else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) { @@ -932,7 +932,15 @@ private void WriteFactoryMethodBodyForIntersectionModel(CodeMethod codeElement, { var deserializationMethodName = $"{ParseNodeVarName}->{GetDeserializationMethodName(propertyType, codeElement)}"; writer.StartBlock($"{(includeElse ? "} else " : string.Empty)}if ({deserializationMethodName} !== null) {{"); - writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({deserializationMethodName});"); + if(deserializationMethodName.Contains("getCollectionOfPrimitiveValues", StringComparison.Ordinal)) + { + writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}(getStringValue());"); + } + else + { + writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({deserializationMethodName});"); + } + writer.DecreaseIndent(); } if (!includeElse) From ea585a4be1712defaa0f1537cdc71e21cff09c20 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 17:15:49 +0300 Subject: [PATCH 18/26] Updates --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index bc50823b39..8b16dca3b1 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -932,12 +932,12 @@ private void WriteFactoryMethodBodyForIntersectionModel(CodeMethod codeElement, { var deserializationMethodName = $"{ParseNodeVarName}->{GetDeserializationMethodName(propertyType, codeElement)}"; writer.StartBlock($"{(includeElse ? "} else " : string.Empty)}if ({deserializationMethodName} !== null) {{"); - if(deserializationMethodName.Contains("getCollectionOfPrimitiveValues", StringComparison.Ordinal)) + if (deserializationMethodName.Contains("getCollectionOfPrimitiveValues", StringComparison.Ordinal)) { writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}(getStringValue());"); } else - { + { writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({deserializationMethodName});"); } @@ -1011,7 +1011,14 @@ private void WriteFactoryMethodBodyForUnionModelForUnDiscriminatedTypes(CodeMeth { var serializationMethodName = $"{ParseNodeVarName}->{GetDeserializationMethodName(property.Type, currentElement)}"; writer.StartBlock($"{(includeElse ? "} else " : string.Empty)}if ({serializationMethodName} !== null) {{"); - writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({serializationMethodName});"); + if (serializationMethodName.Contains("getCollectionOfPrimitiveValues", StringComparison.Ordinal)) + { + writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}(getStringValue());"); + } + else + { + writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({serializationMethodName});"); + } writer.DecreaseIndent(); if (!includeElse) includeElse = true; From a7cab3643726912ff8c4532e5c4387dbd5af0769 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 17:25:22 +0300 Subject: [PATCH 19/26] Rectified typo --- src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 8b16dca3b1..dec6709e00 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -934,7 +934,7 @@ private void WriteFactoryMethodBodyForIntersectionModel(CodeMethod codeElement, writer.StartBlock($"{(includeElse ? "} else " : string.Empty)}if ({deserializationMethodName} !== null) {{"); if (deserializationMethodName.Contains("getCollectionOfPrimitiveValues", StringComparison.Ordinal)) { - writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}(getStringValue());"); + writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({ParseNodeVarName}->getStringValue());"); } else { @@ -1013,7 +1013,7 @@ private void WriteFactoryMethodBodyForUnionModelForUnDiscriminatedTypes(CodeMeth writer.StartBlock($"{(includeElse ? "} else " : string.Empty)}if ({serializationMethodName} !== null) {{"); if (serializationMethodName.Contains("getCollectionOfPrimitiveValues", StringComparison.Ordinal)) { - writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}(getStringValue());"); + writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({ParseNodeVarName}->getStringValue());"); } else { From 3af85e61d15735faee0a6a5445c7f5a26a08345c Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Fri, 29 Nov 2024 17:34:26 +0300 Subject: [PATCH 20/26] More tests --- .../Writers/Php/CodeMethodWriter.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index dec6709e00..22438c7cf0 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -496,14 +496,14 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me //Set the parseNodeMethod to the appropriate method for the collection of primitive values parseNodeMethod = $"getCollectionOfPrimitiveValues()"; } - else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) - { - parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); - } - else if (conventions.CustomTypes.Contains(currentType.TypeDefinition.Name.ToFirstCharacterUpperCase())) - { - parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); - } + // else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) + // { + // parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); + // } + // else if (conventions.CustomTypes.Contains(currentType.TypeDefinition.Name.ToFirstCharacterUpperCase())) + // { + // parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); + // } else if (currentType.TypeDefinition is CodeEnum) { parseNodeMethod = $"getCollectionOfEnumValues({currentType.TypeDefinition.Name.ToFirstCharacterUpperCase()}::class)"; @@ -525,9 +525,9 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me "decimal" or "double" => "getFloatValue()", "streaminterface" => "getBinaryContent()", "byte" => "getByteValue()", - "string" => "getStringValue()", - "date" => "getDateValue()", - "datetime" => "getDateTimeValue()", + // "string" => "getStringValue()", + // "date" => "getDateValue()", + // "datetime" => "getDateTimeValue()", _ when conventions.PrimitiveTypes.Contains(lowerCaseType) => $"get{propertyType.ToFirstCharacterUpperCase()}Value()", _ => $"getObjectValue([{propertyType.ToFirstCharacterUpperCase()}::class, '{CreateDiscriminatorMethodName}'])", } : parseNodeMethod; From a11a427056b66757b83d3802f03e2bb58c15ff0a Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Mon, 2 Dec 2024 12:49:27 +0300 Subject: [PATCH 21/26] Default to get String values --- .../Writers/Php/CodeMethodWriter.cs | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 22438c7cf0..5d228ee5db 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -494,7 +494,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me if (currentType.TypeDefinition is null) { //Set the parseNodeMethod to the appropriate method for the collection of primitive values - parseNodeMethod = $"getCollectionOfPrimitiveValues()"; + parseNodeMethod = $"getStringValue()"; } // else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) // { @@ -932,15 +932,7 @@ private void WriteFactoryMethodBodyForIntersectionModel(CodeMethod codeElement, { var deserializationMethodName = $"{ParseNodeVarName}->{GetDeserializationMethodName(propertyType, codeElement)}"; writer.StartBlock($"{(includeElse ? "} else " : string.Empty)}if ({deserializationMethodName} !== null) {{"); - if (deserializationMethodName.Contains("getCollectionOfPrimitiveValues", StringComparison.Ordinal)) - { - writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({ParseNodeVarName}->getStringValue());"); - } - else - { - writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({deserializationMethodName});"); - } - + writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({deserializationMethodName});"); writer.DecreaseIndent(); } if (!includeElse) @@ -1011,14 +1003,7 @@ private void WriteFactoryMethodBodyForUnionModelForUnDiscriminatedTypes(CodeMeth { var serializationMethodName = $"{ParseNodeVarName}->{GetDeserializationMethodName(property.Type, currentElement)}"; writer.StartBlock($"{(includeElse ? "} else " : string.Empty)}if ({serializationMethodName} !== null) {{"); - if (serializationMethodName.Contains("getCollectionOfPrimitiveValues", StringComparison.Ordinal)) - { - writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({ParseNodeVarName}->getStringValue());"); - } - else - { - writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({serializationMethodName});"); - } + writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({serializationMethodName});"); writer.DecreaseIndent(); if (!includeElse) includeElse = true; From 994b96cfdd55f2ae3c00ae1885f5714e8951cae5 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Tue, 3 Dec 2024 11:00:53 +0300 Subject: [PATCH 22/26] Revert changes --- .../Writers/Php/CodeMethodWriter.cs | 36 +++---------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 5d228ee5db..a8601c382a 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -482,36 +482,12 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me var parseNodeMethod = string.Empty; if (propType is CodeType currentType) { - var collectionMethod = propType.IsArray ? "Array" : "Collection"; if (isCollection) - // parseNodeMethod = currentType.TypeDefinition switch - // { - // //CodeType codeType when codeType.TypeDefinition == null => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", - // CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", - // //CodeType codeType when conventions.PrimitiveTypes.Contains(codeType.Name.ToLowerInvariant()) => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])", - // _ => $"getCollectionOfPrimitiveValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" - // }; - if (currentType.TypeDefinition is null) - { - //Set the parseNodeMethod to the appropriate method for the collection of primitive values - parseNodeMethod = $"getStringValue()"; - } - // else if (conventions.PrimitiveTypes.Contains(currentType.TypeDefinition.Name.ToLowerInvariant())) - // { - // parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); - // } - // else if (conventions.CustomTypes.Contains(currentType.TypeDefinition.Name.ToFirstCharacterUpperCase())) - // { - // parseNodeMethod = currentType.TypeDefinition.Name.ToLowerInvariant(); - // } - else if (currentType.TypeDefinition is CodeEnum) + parseNodeMethod = currentType.TypeDefinition switch { - parseNodeMethod = $"getCollectionOfEnumValues({currentType.TypeDefinition.Name.ToFirstCharacterUpperCase()}::class)"; - } - else - { - parseNodeMethod = $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"; - } + CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", + _ => $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" + }; else if (currentType.TypeDefinition is CodeEnum) parseNodeMethod = $"getEnumValue({propertyType.ToFirstCharacterUpperCase()}::class)"; } @@ -525,9 +501,6 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me "decimal" or "double" => "getFloatValue()", "streaminterface" => "getBinaryContent()", "byte" => "getByteValue()", - // "string" => "getStringValue()", - // "date" => "getDateValue()", - // "datetime" => "getDateTimeValue()", _ when conventions.PrimitiveTypes.Contains(lowerCaseType) => $"get{propertyType.ToFirstCharacterUpperCase()}Value()", _ => $"getObjectValue([{propertyType.ToFirstCharacterUpperCase()}::class, '{CreateDiscriminatorMethodName}'])", } : parseNodeMethod; @@ -956,7 +929,6 @@ private void WriteFactoryMethodBodyForIntersectionModel(CodeMethod codeElement, writer.CloseBlock(decreaseIndent: false); } - private void WriteFactoryMethodBodyForUnionModelForDiscriminatedTypes(CodeMethod codeElement, CodeClass parentClass, LanguageWriter writer) { var includeElse = false; From 6e0bcc6fac92bef97d329d0bed6db4bbefe056ed Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Wed, 4 Dec 2024 12:56:23 +0300 Subject: [PATCH 23/26] Added expected data type for setString method which takes a primitive function that returns an array of mixed types --- .../Writers/Php/CodeMethodWriter.cs | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index a8601c382a..c1b25d996f 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -475,35 +475,42 @@ _ when conventions.PrimitiveTypes.Contains(lowerCaseProp) => $"write{lowerCasePr } private const string ParseNodeVarName = "$parseNode"; - private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod method) + private (string, string) GetDeserializationMethodName(CodeTypeBase propType, CodeMethod method) { var isCollection = propType.CollectionKind != CodeTypeBase.CodeTypeCollectionKind.None; var propertyType = conventions.GetTypeString(propType, method, false); - var parseNodeMethod = string.Empty; + var parseNodeMethod = (string.Empty, string.Empty); if (propType is CodeType currentType) { if (isCollection) parseNodeMethod = currentType.TypeDefinition switch { - CodeEnum enumType => $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)", - _ => $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])" + CodeEnum enumType => (string.Empty, $"getCollectionOfEnumValues({enumType.Name.ToFirstCharacterUpperCase()}::class)"), + CodeClass => (string.Empty, $"getCollectionOfObjectValues([{conventions.TranslateType(propType)}::class, '{CreateDiscriminatorMethodName}'])"), + _ => (conventions.TranslateType(propType), $"getCollectionOfPrimitiveValues('{conventions.TranslateType(propType)}')") }; else if (currentType.TypeDefinition is CodeEnum) - parseNodeMethod = $"getEnumValue({propertyType.ToFirstCharacterUpperCase()}::class)"; + parseNodeMethod = (string.Empty, $"getEnumValue({propertyType.ToFirstCharacterUpperCase()}::class)"); } var lowerCaseType = propertyType.ToLowerInvariant(); - return string.IsNullOrEmpty(parseNodeMethod) ? lowerCaseType switch - { - "int" => "getIntegerValue()", - "bool" => "getBooleanValue()", - "number" => "getIntegerValue()", - "decimal" or "double" => "getFloatValue()", - "streaminterface" => "getBinaryContent()", - "byte" => "getByteValue()", - _ when conventions.PrimitiveTypes.Contains(lowerCaseType) => $"get{propertyType.ToFirstCharacterUpperCase()}Value()", - _ => $"getObjectValue([{propertyType.ToFirstCharacterUpperCase()}::class, '{CreateDiscriminatorMethodName}'])", - } : parseNodeMethod; + var res = parseNodeMethod; + if (string.IsNullOrEmpty(parseNodeMethod.Item2)) + res = (string.Empty, lowerCaseType switch + { + "int" => "getIntegerValue()", + "bool" => "getBooleanValue()", + "number" => "getIntegerValue()", + "decimal" or "double" => "getFloatValue()", + "streaminterface" => "getBinaryContent()", + "byte" => "getByteValue()", + _ when conventions.PrimitiveTypes.Contains(lowerCaseType) => + $"get{propertyType.ToFirstCharacterUpperCase()}Value()", + _ => + $"getObjectValue([{propertyType.ToFirstCharacterUpperCase()}::class, '{CreateDiscriminatorMethodName}'])", + }); + + return res; } private void WriteSetterBody(LanguageWriter writer, CodeMethod codeElement, CodeClass parentClass) @@ -672,7 +679,7 @@ private void WriteDeserializerPropertyCallback(CodeProperty property, CodeMethod writer.WriteLine("},"); return; } - writer.WriteLine($"'{property.WireName}' => fn(ParseNode $n) => $o->{property.Setter!.Name.ToFirstCharacterLowerCase()}($n->{GetDeserializationMethodName(property.Type, method)}),"); + writer.WriteLine($"'{property.WireName}' => fn(ParseNode $n) => $o->{property.Setter!.Name.ToFirstCharacterLowerCase()}($n->{GetDeserializationMethodName(property.Type, method).Item2}),"); } private static void WriteDeserializerBodyForIntersectionModel(CodeClass parentClass, LanguageWriter writer) @@ -903,7 +910,8 @@ private void WriteFactoryMethodBodyForIntersectionModel(CodeMethod codeElement, { if (property.Type is CodeType propertyType) { - var deserializationMethodName = $"{ParseNodeVarName}->{GetDeserializationMethodName(propertyType, codeElement)}"; + var methodName = GetDeserializationMethodName(propertyType, codeElement); + var deserializationMethodName = $"{ParseNodeVarName}->{methodName.Item2}"; writer.StartBlock($"{(includeElse ? "} else " : string.Empty)}if ({deserializationMethodName} !== null) {{"); writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({deserializationMethodName});"); writer.DecreaseIndent(); @@ -973,9 +981,16 @@ private void WriteFactoryMethodBodyForUnionModelForUnDiscriminatedTypes(CodeMeth .ToArray(); foreach (var property in otherProps) { - var serializationMethodName = $"{ParseNodeVarName}->{GetDeserializationMethodName(property.Type, currentElement)}"; + var methodName = GetDeserializationMethodName(property.Type, currentElement); + var serializationMethodName = $"{ParseNodeVarName}->{methodName.Item2}"; + const string finalValueName = "$finalValue"; writer.StartBlock($"{(includeElse ? "} else " : string.Empty)}if ({serializationMethodName} !== null) {{"); - writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({serializationMethodName});"); + if (!string.IsNullOrEmpty(methodName.Item1)) + { + writer.WriteLine($"/** @var array<{methodName.Item1}> {finalValueName} */"); + } + writer.WriteLine($"{finalValueName} = {serializationMethodName};"); + writer.WriteLine($"{ResultVarName}->{property.Setter!.Name.ToFirstCharacterLowerCase()}({finalValueName});"); writer.DecreaseIndent(); if (!includeElse) includeElse = true; From 07b21e03ea311c640657f8d7c02fe200842c3133 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Wed, 4 Dec 2024 14:11:05 +0300 Subject: [PATCH 24/26] Updated regex in phpstan.neon --- it/php/phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/it/php/phpstan.neon b/it/php/phpstan.neon index 11ffe2a09e..8af9a44026 100644 --- a/it/php/phpstan.neon +++ b/it/php/phpstan.neon @@ -7,4 +7,4 @@ parameters: - src ignoreErrors: - '#Parameter [\w\W]+ \$errorMappings of method [\w\\]+RequestAdapter::send[\w]+\(\) expects [\w\W\s]+ given\.#' - - '#getFieldDeserializers\(\) should return array\ but returns array\{[\d]+\: Closure\(Microsoft\\Kiota\\Abstractions\\Serialization\\ParseNode\)\: void.+#' + - '#getFieldDeserializers\(\) should return array\ but returns array\{.+\: Closure\(Microsoft\\Kiota\\Abstractions\\Serialization\\ParseNode\)\: void.+#' From 8c6e84f8ae4548a5c895b010ce8bac144fac3121 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Wed, 4 Dec 2024 15:04:02 +0300 Subject: [PATCH 25/26] Updated CodeMethodWriter test file for php --- .../Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs index fe01e34e07..1dd307da19 100644 --- a/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs @@ -1474,9 +1474,9 @@ public void WritesModelFactoryBodyForUnionModels() Assert.Contains("if ('#kiota.complexType1' === $mappingValue) {", result); Assert.Contains("$result->setComplexType1Value(new ComplexType1())", result); Assert.Contains("if ($parseNode->getStringValue() !== null) {", result); - Assert.Contains("$result->setStringValue($parseNode->getStringValue())", result); + Assert.Contains("$result->setStringValue($finalValue)", result); Assert.Contains("else if ($parseNode->getCollectionOfObjectValues([ComplexType2::class, 'createFromDiscriminatorValue']) !== null) {", result); - Assert.Contains("$result->setComplexType2Value($parseNode->getCollectionOfObjectValues([ComplexType2::class, 'createFromDiscriminatorValue']))", result); + Assert.Contains("$result->setComplexType2Value($finalValue)", result); Assert.Contains("return $result", result); Assert.DoesNotContain("return new UnionTypeWrapper()", result); AssertExtensions.Before("$parseNode->getStringValue()", "getCollectionOfObjectValues([ComplexType2::class, 'createFromDiscriminatorValue'])", result); From 8886b19a635fb937d47f95db71a18c159044ec7e Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Thu, 5 Dec 2024 10:26:18 +0300 Subject: [PATCH 26/26] $finalValue validation --- tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs index 1dd307da19..ad5c54b056 100644 --- a/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs @@ -1474,8 +1474,10 @@ public void WritesModelFactoryBodyForUnionModels() Assert.Contains("if ('#kiota.complexType1' === $mappingValue) {", result); Assert.Contains("$result->setComplexType1Value(new ComplexType1())", result); Assert.Contains("if ($parseNode->getStringValue() !== null) {", result); + Assert.Contains("$finalValue = $parseNode->getStringValue()", result); Assert.Contains("$result->setStringValue($finalValue)", result); Assert.Contains("else if ($parseNode->getCollectionOfObjectValues([ComplexType2::class, 'createFromDiscriminatorValue']) !== null) {", result); + Assert.Contains("$finalValue = $parseNode->getCollectionOfObjectValues([ComplexType2::class, 'createFromDiscriminatorValue'])", result); Assert.Contains("$result->setComplexType2Value($finalValue)", result); Assert.Contains("return $result", result); Assert.DoesNotContain("return new UnionTypeWrapper()", result);