Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed Nov 21, 2024
1 parent a60d3be commit 43f01c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
30 changes: 12 additions & 18 deletions src/Kiota.Builder/Refiners/TypeScriptRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CodeClass>(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
},
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/TypeScript/CodeConstantWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}";
Expand Down

0 comments on commit 43f01c6

Please sign in to comment.