Skip to content

Commit

Permalink
write all properties including ones in the base class
Browse files Browse the repository at this point in the history
  • Loading branch information
koros committed Nov 14, 2024
1 parent 80d771c commit bac834f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,27 @@ private static void WriteRequestBody(CodeMethod method, LanguageWriter writer)
{
writer.WriteLine("{");
writer.IncreaseIndent();
foreach (var prop in requestBodyClass.Properties.Where(prop => prop.IsOfKind(CodePropertyKind.Custom)))
{
writer.WriteLine($"{prop.Name}: {GetDefaultValueForProperty(prop)}");
}
WriteProperties(requestBodyClass, writer);
writer.DecreaseIndent();
writer.WriteLine("}");
}
}

private static void WriteProperties(CodeClass codeClass, LanguageWriter writer)
{
// Write properties of the current class
foreach (var prop in codeClass.Properties.Where(prop => prop.IsOfKind(CodePropertyKind.Custom)))
{
writer.WriteLine($"{prop.Name}: {GetDefaultValueForProperty(prop)}");
}

// If the class extends another class, write properties of the base class
if (codeClass.StartBlock.Inherits?.TypeDefinition is CodeClass baseClass)
{
WriteProperties(baseClass, writer);
}
}

private static string GetDefaultValueForProperty(CodeProperty prop)
{
return prop.Type.Name switch
Expand Down

0 comments on commit bac834f

Please sign in to comment.