Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers alignment/ snake case properties #3524

Merged
merged 7 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/Kiota.Builder/Refiners/PythonRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down Expand Up @@ -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})");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down