diff --git a/.vscode/launch.json b/.vscode/launch.json
index e35088074b..b780e8e5c7 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -412,14 +412,17 @@
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": [
- "generate",
- "--openapi", "C:\\Users\\evansaboge\\Documents\\RestClient\\openapi.yaml",
- "--language", "http",
- "--output", "C:\\Users\\evansaboge\\Documents\\RestClient\\HTTP1"
+ "generate",
+ "--openapi",
+ "https://raw.githubusercontent.com/microsoftgraph/msgraph-sdk-powershell/dev/openApiDocs/v1.0/Mail.yml",
+ "--language",
+ "http",
+ "--output",
+ "${workspaceFolder}/samples/msgraph-mail/http",
],
"cwd": "${workspaceFolder}/src/kiota",
"stopAtEntry": false,
"console": "internalConsole"
}
]
-}
\ No newline at end of file
+}
diff --git a/src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs b/src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs
index 2be8d10a8f..279a02e295 100644
--- a/src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs
+++ b/src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs
@@ -287,19 +287,34 @@ private static void WriteRequestBody(CodeMethod method, LanguageWriter writer)
///
/// The request body class containing the properties.
/// The language writer to write the properties to.
- private static void WriteProperties(CodeClass requestBodyClass, LanguageWriter writer)
+ private static void WriteProperties(CodeClass requestBodyClass, LanguageWriter writer, HashSet? processedClasses = null, int depth = 0)
{
+
+ if (processedClasses == null)
+ {
+ processedClasses = new HashSet();
+ }
+
+ // Add the current class to the set of processed classes
+ if (!processedClasses.Add(requestBodyClass))
+ {
+ // If the class is already processed, write its properties again up to a certain depth
+ if (depth >= 3)
+ {
+ return;
+ }
+ }
+
var properties = requestBodyClass.Properties
.Where(static prop => prop.IsOfKind(CodePropertyKind.Custom))
.ToArray();
var propertyCount = properties.Length;
- var currentIndex = 0;
foreach (var prop in properties)
{
// Add a trailing comma if there are more properties to be written
- var separator = currentIndex < propertyCount - 1 ? "," : string.Empty;
+ var separator = ",";
var propName = $"\"{prop.Name}\"";
writer.Write($"{propName}: ");
@@ -308,7 +323,7 @@ private static void WriteProperties(CodeClass requestBodyClass, LanguageWriter w
// If the property is an object, write a JSON representation recursively
writer.WriteLine("{", includeIndent: false);
writer.IncreaseIndent();
- WriteProperties(propClass, writer);
+ WriteProperties(propClass, writer, processedClasses, depth + 1);
writer.CloseBlock($"}}{separator}");
}
else
@@ -317,10 +332,13 @@ private static void WriteProperties(CodeClass requestBodyClass, LanguageWriter w
}
}
+ // Remove the current class from the set of processed classes after processing
+ processedClasses.Remove(requestBodyClass);
+
// If the class extends another class, write properties of the base class
if (requestBodyClass.StartBlock.Inherits?.TypeDefinition is CodeClass baseClass)
{
- WriteProperties(baseClass, writer);
+ WriteProperties(baseClass, writer, processedClasses, depth + 1);
}
}