Skip to content

Commit

Permalink
fixes parameter types for send methods of type primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
andrueastman committed Nov 7, 2024
1 parent 61826d0 commit 81a22a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,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, isEnum, returnTypeWithoutCollectionSymbol);
var newFactoryParameter = GetTypeFactory(isVoid, isStream, isEnum, returnTypeWithoutCollectionSymbol, codeElement.ReturnType.IsCollection);
var errorMappingVarName = NoneKeyword;
if (codeElement.ErrorMappings.Any())
{
Expand Down Expand Up @@ -819,11 +819,11 @@ private string GetSerializationMethodName(CodeTypeBase propType)
_ => "write_object_value",
};
}
internal string GetTypeFactory(bool isVoid, bool isStream, bool isEnum, string returnType)
internal string GetTypeFactory(bool isVoid, bool isStream, bool isEnum, string returnType, bool isCollection)
{
if (isVoid) return string.Empty;
if (isStream || isEnum) return $" \"{returnType}\",";
if (conventions.IsPrimitiveType(returnType)) return $" {returnType},";
if (conventions.IsPrimitiveType(returnType)) return isCollection ? $" {returnType}," : $" \"{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
Expand Up @@ -130,7 +130,7 @@ public bool IsPrimitiveType(string typeName)
{
return typeName switch
{
"int" or "float" or "str" or "bool" or "None" => true,
"int" or "float" or "str" or "bool" or "None" or "datetime.datetime" or "datetime.timedelta" or "datetime.date" or "datetime.time" => true,
_ => false,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,12 +820,13 @@ public void WritesUnionDeSerializerBody()
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)
[InlineData(true, false, false, false, "string", "")]
[InlineData(false, true, false, false, "Stream", " \"Stream\",")]
[InlineData(false, false, true, false, "SomeEnum", " \"SomeEnum\",")]
[InlineData(false, false, false, true, "int", " int,")]
[InlineData(false, false, false, false, "int", " \"int\",")]
[InlineData(false, false, false, false, "CustomType", " CustomType,")]
public void GetTypeFactory_ReturnsCorrectString(bool isVoid, bool isStream, bool isEnum, bool isCollection, string returnType, string expected)
{
var mockConventionService = new Mock<PythonConventionService>();

Expand All @@ -835,9 +836,7 @@ public void GetTypeFactory_ReturnsCorrectString(bool isVoid, bool isStream, bool
false // usesBackingStore
);

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


var result = codeMethodWriter.GetTypeFactory(isVoid, isStream, isEnum, returnType, isCollection);
Assert.Equal(expected, result);
}
[Fact]
Expand Down

0 comments on commit 81a22a9

Please sign in to comment.