From 07dbc9bd56e0e99a98474856eb47e6292591cf85 Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Thu, 19 Oct 2023 13:27:05 +0300 Subject: [PATCH 1/4] Backing store and odata type properties snake case --- src/Kiota.Builder/Refiners/PythonRefiner.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Kiota.Builder/Refiners/PythonRefiner.cs b/src/Kiota.Builder/Refiners/PythonRefiner.cs index d1d401e877..1cb92885d9 100644 --- a/src/Kiota.Builder/Refiners/PythonRefiner.cs +++ b/src/Kiota.Builder/Refiners/PythonRefiner.cs @@ -74,6 +74,7 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance CodePropertyKind.Custom, CodePropertyKind.QueryParameter, CodePropertyKind.RequestBuilder, + CodePropertyKind.BackingStore }, static s => s.ToFirstCharacterLowerCase().ToSnakeCase()); AddParentClassToErrorClasses( @@ -190,6 +191,7 @@ 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 7c10303ee91e795abd830e6909c06c10d8833d7e Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Thu, 19 Oct 2023 13:58:16 +0300 Subject: [PATCH 2/4] Align with abstraction changes on header management --- src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs index 9a400cd7df..63ca6626e6 100644 --- a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs @@ -617,7 +617,7 @@ private void WriteRequestGeneratorBody(CodeMethod codeElement, RequestParams req $"{RequestInfoVarName}.path_parameters = {GetPropertyCall(urlTemplateParamsProperty, "''")}"); writer.WriteLine($"{RequestInfoVarName}.http_method = Method.{codeElement.HttpMethod.Value.ToString().ToUpperInvariant()}"); if (codeElement.AcceptedResponseTypes.Any()) - writer.WriteLine($"{RequestInfoVarName}.try_add_request_header(\"Accept\", \"{string.Join(", ", codeElement.AcceptedResponseTypes)}\")"); + writer.WriteLine($"{RequestInfoVarName}.headers.try_add(\"Accept\", \"{string.Join(", ", codeElement.AcceptedResponseTypes)}\")"); if (currentClass.GetPropertyOfKind(CodePropertyKind.RequestAdapter) is CodeProperty requestAdapterProperty) UpdateRequestInformationFromRequestBody(codeElement, requestParams, requestAdapterProperty, writer); writer.WriteLine($"return {RequestInfoVarName}"); @@ -823,7 +823,7 @@ private static void UpdateRequestInformationFromRequestConfiguration(RequestPara { writer.StartBlock($"if {requestParams.requestConfiguration.Name}:"); var headers = requestParams.Headers?.Name ?? "headers"; - writer.WriteLine($"{RequestInfoVarName}.add_request_headers({requestParams.requestConfiguration.Name}.{headers})"); + writer.WriteLine($"{RequestInfoVarName}.headers.add({requestParams.requestConfiguration.Name}.{headers})"); var queryString = requestParams.QueryParameters; if (queryString != null) writer.WriteLines($"{RequestInfoVarName}.set_query_string_parameters_from_raw_object({requestParams.requestConfiguration.Name}.{queryString.Name})"); From a33686e7754fa7ab0d1c18dc9533146d975a8155 Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Thu, 19 Oct 2023 13:59:16 +0300 Subject: [PATCH 3/4] Update tests --- .../Writers/Python/CodeMethodWriterTests.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs index a17efa9aab..c2af143038 100644 --- a/tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs @@ -673,9 +673,8 @@ public void WritesRequestGeneratorBodyForScalar() Assert.Contains("request_info.http_method = Method", result); Assert.Contains("request_info.url_template = ", result); Assert.Contains("request_info.path_parameters = ", result); - Assert.Contains("request_info.try_add_request_header(\"Accept\", \"application/json, text/plain\")", result); + Assert.Contains("request_info.headers.try_add(\"Accept\", \"application/json, text/plain\")", result); Assert.Contains("if c:", result); - Assert.Contains("request_info.add_request_headers", result); Assert.Contains("request_info.add_request_options", result); Assert.Contains("request_info.set_query_string_parameters_from_raw_object", result); Assert.Contains("set_content_from_scalar", result); @@ -698,9 +697,8 @@ public void WritesRequestGeneratorBodyForParsable() Assert.Contains("request_info.http_method = Method", result); Assert.Contains("request_info.url_template = ", result); Assert.Contains("request_info.path_parameters = ", result); - Assert.Contains("request_info.try_add_request_header(\"Accept\", \"application/json, text/plain\")", result); + Assert.Contains("request_info.headers.try_add(\"Accept\", \"application/json, text/plain\")", result); Assert.Contains("if c:", result); - Assert.Contains("request_info.add_request_headers", result); Assert.Contains("request_info.add_request_options", result); Assert.Contains("request_info.set_query_string_parameters_from_raw_object", result); Assert.Contains("set_content_from_parsable", result); From 4ed69cdfbddd6fb6acda7963ae9f6e9afcc655c6 Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Thu, 19 Oct 2023 14:14:31 +0300 Subject: [PATCH 4/4] Add CHANGELOG entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0ea774996..b84db06044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Aligns header management in Python with other languages. [#3430](https://github.com/microsoft/kiota/issues/3430) +- Fixed parameters that are in camelcase to snakecase in Python. [#3525](https://github.com/microsoft/kiota/issues/3525 - Fixed missing imports for method parameters that are query parameters. - Fixed query parameters type mapping for arrays. [#3354](https://github.com/microsoft/kiota/issues/3354) - Fixed bug where base64url and decimal types would not be generated properly in Java.