From 43f01c67b84d307ec1a368eff3123a729f9b7fc4 Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:15:20 +0300 Subject: [PATCH] Fix --- .../Refiners/TypeScriptRefiner.cs | 30 ++++++++----------- .../Writers/TypeScript/CodeConstantWriter.cs | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs b/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs index 6e9288a894..85f22e79e0 100644 --- a/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs +++ b/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs @@ -1493,28 +1493,22 @@ private static void AddDeserializerUsingToDiscriminatorFactory(CodeElement codeE foreach (var mappedType in parsableFactoryFunction.OriginalMethodParentClass.DiscriminatorInformation.DiscriminatorMappings) { - if (mappedType.Value is CodeType type && type.TypeDefinition is CodeClass mappedClass) + // check if the model was trimmed + if (mappedType.Value is CodeType type && type.TypeDefinition is CodeClass mappedClass && mappedClass.Parent is CodeNamespace codeNamespace && codeNamespace.FindChildByName(mappedClass.Name) != null) { - try - { - var deserializer = GetSerializationFunctionsForNamespace(mappedClass).Item2; + var deserializer = GetSerializationFunctionsForNamespace(mappedClass).Item2; - if (deserializer.Parent is not null) + if (deserializer.Parent is not null) + { + parsableFactoryFunction.AddUsing(new CodeUsing { - parsableFactoryFunction.AddUsing(new CodeUsing + Name = deserializer.Parent.Name, + Declaration = new CodeType { - Name = deserializer.Parent.Name, - Declaration = new CodeType - { - Name = deserializer.Name, - TypeDefinition = deserializer - }, - }); - } - } - catch (InvalidOperationException) - { - // The deserializer function for the mapped class does not exist. + Name = deserializer.Name, + TypeDefinition = deserializer + }, + }); } } } diff --git a/src/Kiota.Builder/Writers/TypeScript/CodeConstantWriter.cs b/src/Kiota.Builder/Writers/TypeScript/CodeConstantWriter.cs index 0abb0fda27..f9f41d41a8 100644 --- a/src/Kiota.Builder/Writers/TypeScript/CodeConstantWriter.cs +++ b/src/Kiota.Builder/Writers/TypeScript/CodeConstantWriter.cs @@ -169,7 +169,7 @@ private string GetTypeFactory(bool isVoid, bool isStream, CodeMethod codeElement { if (isVoid) return string.Empty; var typeName = conventions.TranslateType(codeElement.ReturnType); - if (isStream || IsPrimitiveType(typeName)) return $" \"{typeName}\""; + if (isStream || IsPrimitiveType(typeName) || IsKiotaPrimitive(typeName)) return $" \"{typeName}\""; if (GetPrimitiveAlias(typeName) is { } alias && !string.IsNullOrEmpty(alias)) return $" \"{alias}\""; return $" {GetFactoryMethodName(codeElement.ReturnType, codeElement, writer)}";