Skip to content

Commit

Permalink
handle None in serializer method
Browse files Browse the repository at this point in the history
  • Loading branch information
shemogumbe committed Nov 7, 2024
1 parent 6faea06 commit a0a3b84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,20 @@ private void WriteSerializerBodyForInheritedModel(bool inherits, CodeClass paren
if (inherits)
writer.WriteLine("super().serialize(writer)");
foreach (var otherProp in parentClass
.GetPropertiesOfKind(CodePropertyKind.Custom)
.Where(static x => !x.ExistsInBaseType && !x.ReadOnly)
.OrderBy(static x => x.Name))
.GetPropertiesOfKind(CodePropertyKind.Custom)
.Where(static x => !x.ExistsInBaseType && !x.ReadOnly)
.OrderBy(static x => x.Name))
{
var serializationMethodName = GetSerializationMethodName(otherProp.Type);
writer.WriteLine($"writer.{serializationMethodName}(\"{otherProp.WireName}\", self.{otherProp.Name})");
var propertyName = otherProp.Name;
writer.WriteLine($"if self.{propertyName} is not None:");
writer.IncreaseIndent();
writer.WriteLine($"writer.{serializationMethodName}(\"{otherProp.WireName}\", self.{propertyName})");
writer.DecreaseIndent();
writer.WriteLine("else:");
writer.IncreaseIndent();
writer.WriteLine($"writer.{serializationMethodName}(\"{otherProp.WireName}\", None)");
writer.DecreaseIndent();
}
}
private void WriteSerializerBodyForUnionModel(CodeClass parentClass, LanguageWriter writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public bool IsPrimitiveType(string typeName)
{
return typeName switch
{
"int" or "float" or "str" or "bool" => true,
"int" or "float" or "str" or "bool" or "None" => true,
_ => false,
};
}
Expand Down

0 comments on commit a0a3b84

Please sign in to comment.