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] 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;