Skip to content

Commit

Permalink
Remove stringify from primitive types (#5616)
Browse files Browse the repository at this point in the history
* Remove stringify from primitive types

* clean up code

* revert changes in launch.json file

* Updated changelog"

* move changelog to unrealeased

* update method writer tests

* update code format

* update code format

* remove unused parameter

* update unit tests

* updete tests

* fix unit test

* update unit tests

* fix integration tests

* update get factory for enums

* update uni test for enums

* update uni test for enums

* Update CHANGELOG.md

Co-authored-by: Andrew Omondi <[email protected]>

* update method to internal

* Update tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs

Co-authored-by: Andrew Omondi <[email protected]>

* Update CHANGELOG.md

Co-authored-by: Andrew Omondi <[email protected]>

* remove uused vars

* docs: removes duplicated changelog entry

---------

Co-authored-by: Andrew Omondi <[email protected]>
Co-authored-by: Vincent Biret <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2024
1 parent 2d13e44 commit 3fdc657
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 12 deletions.
40 changes: 32 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["search", "microsoft"],
"args": [
"search",
"microsoft"
],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
Expand All @@ -207,7 +210,10 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["search", "test"],
"args": [
"search",
"test"
],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
Expand Down Expand Up @@ -249,7 +255,11 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["info", "-l", "CSharp"],
"args": [
"info",
"-l",
"CSharp"
],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
Expand All @@ -260,7 +270,11 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["update", "-o", "${workspaceFolder}/samples"],
"args": [
"update",
"-o",
"${workspaceFolder}/samples"
],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
Expand All @@ -271,7 +285,10 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["workspace", "migrate"],
"args": [
"workspace",
"migrate"
],
"cwd": "${workspaceFolder}/samples/msgraph-mail/dotnet",
"console": "internalConsole",
"stopAtEntry": false,
Expand All @@ -285,7 +302,10 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["client", "generate"],
"args": [
"client",
"generate"
],
"cwd": "${workspaceFolder}/samples/msgraph-mail/dotnet",
"console": "internalConsole",
"stopAtEntry": false,
Expand Down Expand Up @@ -349,7 +369,11 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["login", "github", "device"],
"args": [
"login",
"github",
"device"
],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
Expand All @@ -361,4 +385,4 @@
"processId": "${command:pickProcess}"
}
]
}
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
- Fixed python generation client serailization failure str being quoted as "str"
- Fixed Issue with primitive values being stringified in python python. [#5417](https://github.com/microsoft/kiota/issues/5417)

- Fixed an issue where multipart request content would be ignored if other unstructured content was present in the description. [#5638](https://github.com/microsoft/kiota/issues/5638)
- Fixed an issue where when generating Go code the deserializer for unions was using `CodeClass` as a filter and not `CodeInterface`. [#4844](https://github.com/microsoft/kiota/issues/4844)
Expand All @@ -32,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed cyclic dependencies in generated Go code. [#2834](https://github.com/microsoft/kiota/issues/2834)
- Fixed a bug where default output folder is created on plugin edit and generate commands. [#5510](https://github.com/microsoft/kiota/issues/5429)
- Changed GeneratedCode attribute applied when generating CSharp to only include the major version of Kiota. [#5489](https://github.com/microsoft/kiota/issues/5489)

- Fixed generating CSharp client displays clean hint regardless of whether --clean-output is already passed [#5576](https://github.com/microsoft/kiota/issues/5576)

## [1.19.0] - 2024-10-03
Expand Down
7 changes: 4 additions & 3 deletions src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ
var isStream = conventions.StreamTypeName.Equals(returnType, StringComparison.OrdinalIgnoreCase);
var returnTypeWithoutCollectionSymbol = GetReturnTypeWithoutCollectionSymbol(codeElement, returnType);
var genericTypeForSendMethod = GetSendRequestMethodName(isVoid, isStream, codeElement.ReturnType.IsCollection, returnTypeWithoutCollectionSymbol, isEnum);
var newFactoryParameter = GetTypeFactory(isVoid, isStream, returnTypeWithoutCollectionSymbol, isEnum);
var newFactoryParameter = GetTypeFactory(isVoid, isStream, isEnum, returnTypeWithoutCollectionSymbol);
var errorMappingVarName = NoneKeyword;
if (codeElement.ErrorMappings.Any())
{
Expand Down Expand Up @@ -809,10 +809,11 @@ private string GetSerializationMethodName(CodeTypeBase propType)
_ => "write_object_value",
};
}
private string GetTypeFactory(bool isVoid, bool isStream, string returnType, bool isEnum)
internal string GetTypeFactory(bool isVoid, bool isStream, bool isEnum, string returnType)
{
if (isVoid) return string.Empty;
if (isStream || conventions.IsPrimitiveType(returnType) || isEnum) return $" \"{returnType}\",";
if (isStream || isEnum) return $" \"{returnType}\",";
if (conventions.IsPrimitiveType(returnType)) return $" {returnType},";
return $" {returnType},";
}
private string GetSendRequestMethodName(bool isVoid, bool isStream, bool isCollection, string returnType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.IO;
using System.Linq;

using Kiota.Builder.CodeDOM;
using Kiota.Builder.Extensions;
using Kiota.Builder.Writers;
using Kiota.Builder.Writers.Python;
using Moq;
using Xunit;

namespace Kiota.Builder.Tests.Writers.Python;
Expand All @@ -25,12 +25,15 @@ public sealed class CodeMethodWriterTests : IDisposable
private const string MethodDescription = "some description";
private const string ParamDescription = "some parameter description";
private const string ParamName = "param_name";


public CodeMethodWriterTests()
{
writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.Python, DefaultPath, DefaultName);
tw = new StringWriter();
writer.SetTextWriter(tw);
root = CodeNamespace.InitRootNamespace();

}
private void setup(bool withInheritance = false)
{
Expand Down Expand Up @@ -791,6 +794,7 @@ public void WritesInheritedDeSerializerBody()
Assert.Contains("return fields", result);
Assert.DoesNotContain("defined_in_parent", result, StringComparison.OrdinalIgnoreCase);
}

[Fact]
public void WritesUnionDeSerializerBody()
{
Expand All @@ -815,6 +819,27 @@ public void WritesUnionDeSerializerBody()
Assert.Contains("return self.complex_type1_value.get_field_deserializers()", result);
Assert.Contains("return {}", result);
}
[Theory]
[InlineData(true, false, false, "string", "")]
[InlineData(false, true, false, "Stream", " \"Stream\",")]
[InlineData(false, false, true, "SomeEnum", " \"SomeEnum\",")]
[InlineData(false, false, false, "int", " int,")]
[InlineData(false, false, false, "CustomType", " CustomType,")]
public void GetTypeFactory_ReturnsCorrectString(bool isVoid, bool isStream, bool isEnum, string returnType, string expected)
{
var mockConventionService = new Mock<PythonConventionService>();

var codeMethodWriter = new CodeMethodWriter(
mockConventionService.Object,
"TestNamespace",
false // usesBackingStore
);

var result = codeMethodWriter.GetTypeFactory(isVoid, isStream, isEnum, returnType);


Assert.Equal(expected, result);
}
[Fact]
public void WritesIntersectionDeSerializerBody()
{
Expand Down

0 comments on commit 3fdc657

Please sign in to comment.