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

remove stringify from constructor properties #5333

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed a bug where function descriptions in plugin manifest defaults to path summary instead of description. [#5301](https://github.com/microsoft/kiota/issues/5301)
- Fixed a bug where TypeScript would not properly build URIs with uppercase first characters query parameter names.[#5382](https://github.com/microsoft/kiota/issues/5382)
- Fixed a bug where the description special characters are encoded. [5286](https://github.com/microsoft/kiota/issues/5286)
- Fixed a bug where python constructor parameters are being cast to strings leading to bugs as the types is unknown on graph call. [microsoftgraph/msgraph-sdk-python#165](https://github.com/microsoftgraph/msgraph-sdk-python/issues/165)

## [1.18.0] - 2024-09-05

Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
var requestParams = new RequestParams(requestBodyParam, requestConfigParam, requestContentType);
if (!codeElement.IsOfKind(CodeMethodKind.Setter) &&
!(codeElement.IsOfKind(CodeMethodKind.Constructor) && parentClass.IsOfKind(CodeClassKind.RequestBuilder)))
foreach (var parameter in codeElement.Parameters.Where(static x => !x.Optional).OrderBy(static x => x.Name))

Check warning on line 43 in src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Loop should be simplified by calling Select(parameter => parameter.Name)) (https://rules.sonarsource.com/csharp/RSPEC-3267)
{
var parameterName = parameter.Name;
writer.StartBlock($"if {parameterName} is None:");
Expand Down Expand Up @@ -112,7 +112,7 @@
break;
}
}
private void WriteRawUrlBuilderBody(CodeClass parentClass, CodeMethod codeElement, LanguageWriter writer)

Check warning on line 115 in src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Make 'WriteRawUrlBuilderBody' a static method. (https://rules.sonarsource.com/csharp/RSPEC-2325)
{
var rawUrlParameter = codeElement.Parameters.OfKind(CodeParameterKind.RawUrl) ?? throw new InvalidOperationException("RawUrlBuilder method should have a RawUrl parameter");
var requestAdapterProperty = parentClass.GetPropertyOfKind(CodePropertyKind.RequestAdapter) ?? throw new InvalidOperationException("RawUrlBuilder method should have a RequestAdapter property");
Expand All @@ -135,7 +135,7 @@
writer.WriteLine($"return {parentClass.Name}()");
}
private const string ResultVarName = "result";
private void WriteFactoryMethodBodyForUnionModel(CodeMethod codeElement, CodeClass parentClass, CodeParameter parseNodeParameter, LanguageWriter writer)

Check warning on line 138 in src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
writer.WriteLine($"{ResultVarName} = {parentClass.Name}()");
var includeElse = false;
Expand Down Expand Up @@ -164,7 +164,7 @@
}
writer.WriteLine($"return {ResultVarName}");
}
private void WriteFactoryMethodBodyForIntersectionModel(CodeMethod codeElement, CodeClass parentClass, CodeParameter parseNodeParameter, LanguageWriter writer)

Check warning on line 167 in src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
writer.WriteLine($"{ResultVarName} = {parentClass.Name}()");
var includeElse = false;
Expand Down Expand Up @@ -324,7 +324,7 @@
return _SetterAccessProperties;
}
}
private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMethod, LanguageWriter writer, bool inherits)

Check warning on line 327 in src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 28 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (inherits && !parentClass.IsOfKind(CodeClassKind.Model))
{
Expand All @@ -344,7 +344,7 @@
foreach (var parameter in pathParameters)
{
var (name, identName) = parameter;
writer.WriteLine($"{pathParametersParameter.Name}['{name}'] = str({identName})");
writer.WriteLine($"{pathParametersParameter.Name}['{name}'] = {identName}");
}
writer.DecreaseIndent();
}
Expand Down Expand Up @@ -373,7 +373,7 @@
writer.IncreaseIndent();
}
}
private void WriteDirectAccessProperties(CodeClass parentClass, LanguageWriter writer)

Check warning on line 376 in src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
foreach (var propWithDefault in parentClass.GetPropertiesOfKind(DirectAccessProperties)
.Where(static x => !string.IsNullOrEmpty(x.DefaultValue) && !NoneKeyword.Equals(x.DefaultValue, StringComparison.Ordinal))
Expand All @@ -390,7 +390,7 @@
conventions.WriteInLineDescription(propWithDefault, writer);
if (parentClass.IsOfKind(CodeClassKind.Model))
{
writer.WriteLine($"{propWithDefault.Name}: {(propWithDefault.Type.IsNullable ? "Optional[" : string.Empty)}{returnType}{(propWithDefault.Type.IsNullable ? "]" : string.Empty)} = {defaultValue}");

Check warning on line 393 in src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'Optional[' 7 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
writer.WriteLine();
}
else
Expand Down Expand Up @@ -427,7 +427,7 @@
}
}
private const string NoneKeyword = "None";
private void WriteSetterAccessPropertiesWithoutDefaults(CodeClass parentClass, LanguageWriter writer)

Check warning on line 430 in src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
foreach (var propWithoutDefault in parentClass.GetPropertiesOfKind(SetterAccessProperties)
.Where(static x => string.IsNullOrEmpty(x.DefaultValue) || NoneKeyword.Equals(x.DefaultValue, StringComparison.Ordinal))
Expand Down Expand Up @@ -499,7 +499,7 @@
else
WriteDeserializerBodyForInheritedModel(inherits, codeElement, parentClass, writer);
}
private void WriteDeserializerBodyForUnionModel(CodeMethod method, CodeClass parentClass, LanguageWriter writer)

Check warning on line 502 in src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Make 'WriteDeserializerBodyForUnionModel' a static method. (https://rules.sonarsource.com/csharp/RSPEC-2325)
{
foreach (var otherPropName in parentClass
.GetPropertiesOfKind(CodePropertyKind.Custom)
Expand All @@ -515,7 +515,7 @@
}
writer.WriteLine($"return {DefaultDeserializerValue}");
}
private void WriteDeserializerBodyForIntersectionModel(CodeClass parentClass, LanguageWriter writer)

Check warning on line 518 in src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Make 'WriteDeserializerBodyForIntersectionModel' a static method. (https://rules.sonarsource.com/csharp/RSPEC-2325)
{
var complexProperties = parentClass.GetPropertiesOfKind(CodePropertyKind.Custom)
.Where(static x => x.Type is CodeType propType && propType.TypeDefinition is CodeClass && !x.Type.IsCollection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ public void WritesConstructorForRequestBuilderWithRequestAdapterAndPathParameter
Assert.Contains("def __init__(self,request_adapter: RequestAdapter, path_parameters: Union[Dict[str, Any], str],", result);
Assert.Contains("username: Optional[str] = None", result);
Assert.Contains("if isinstance(path_parameters, dict):", result);
Assert.Contains("path_parameters['username'] = str(username)", result);
Assert.Contains("path_parameters['username'] = username", result);
Assert.DoesNotContain("This property has a description", result);
Assert.DoesNotContain($"self.{propName}: Optional[str] = {defaultValue}", result);
Assert.DoesNotContain("get_path_parameters(", result);
Expand Down
Loading