From 056d172fc13182750b7b86b838ffc977ecae937f Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Mon, 30 Oct 2023 19:52:54 +0300 Subject: [PATCH 1/3] Fix instances properties being camel case --- src/Kiota.Builder/Refiners/PythonRefiner.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Refiners/PythonRefiner.cs b/src/Kiota.Builder/Refiners/PythonRefiner.cs index 1cb92885d9..4f07068020 100644 --- a/src/Kiota.Builder/Refiners/PythonRefiner.cs +++ b/src/Kiota.Builder/Refiners/PythonRefiner.cs @@ -182,6 +182,11 @@ private static void CorrectCommonNames(CodeElement currentElement) { param.Name = param.Name.ToFirstCharacterLowerCase().ToSnakeCase(); } + if (parentClassM.IsOfKind(CodeClassKind.Model)) + foreach (var prop in parentClassM.Properties) + { + prop.Name = prop.Name.ToFirstCharacterLowerCase().ToSnakeCase(); + } } else if (currentElement is CodeClass c) { @@ -191,7 +196,6 @@ private static void CorrectCommonNames(CodeElement currentElement) (p.IsOfKind(CodePropertyKind.RequestAdapter) || p.IsOfKind(CodePropertyKind.PathParameters) || p.IsOfKind(CodePropertyKind.QueryParameters) || - p.IsOfKind(CodePropertyKind.Custom) || p.IsOfKind(CodePropertyKind.UrlTemplate)) && currentElement.Parent is CodeClass parentClassP) { From 99e213d2a00667e951a94f04252175d097129729 Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Mon, 30 Oct 2023 19:53:04 +0300 Subject: [PATCH 2/3] Update tests --- .../Kiota.Builder.Tests/Refiners/PythonLanguageRefinerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Kiota.Builder.Tests/Refiners/PythonLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/PythonLanguageRefinerTests.cs index 564d38b72e..ce50b0d849 100644 --- a/tests/Kiota.Builder.Tests/Refiners/PythonLanguageRefinerTests.cs +++ b/tests/Kiota.Builder.Tests/Refiners/PythonLanguageRefinerTests.cs @@ -278,7 +278,7 @@ public async Task CorrectsCoreType() var model = root.AddClass(new CodeClass { Name = "model", - Kind = CodeClassKind.Model + Kind = CodeClassKind.RequestBuilder }).First(); model.AddProperty(new CodeProperty { From 3f8dd16d9f0d2918558816ddfe8a54941cefd0c3 Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Mon, 30 Oct 2023 20:15:08 +0300 Subject: [PATCH 3/3] Refactor changes --- src/Kiota.Builder/Refiners/PythonRefiner.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Refiners/PythonRefiner.cs b/src/Kiota.Builder/Refiners/PythonRefiner.cs index 4f07068020..639e3403da 100644 --- a/src/Kiota.Builder/Refiners/PythonRefiner.cs +++ b/src/Kiota.Builder/Refiners/PythonRefiner.cs @@ -183,10 +183,17 @@ private static void CorrectCommonNames(CodeElement currentElement) param.Name = param.Name.ToFirstCharacterLowerCase().ToSnakeCase(); } if (parentClassM.IsOfKind(CodeClassKind.Model)) + { foreach (var prop in parentClassM.Properties) { - prop.Name = prop.Name.ToFirstCharacterLowerCase().ToSnakeCase(); + if (string.IsNullOrEmpty(prop.SerializationName)) + { + prop.SerializationName = prop.Name; + } + + parentClassM.RenameChildElement(prop.Name, prop.Name.ToFirstCharacterLowerCase().ToSnakeCase()); } + } } else if (currentElement is CodeClass c) {