Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into andrueastman/pythonFix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrueastman committed Nov 8, 2024
2 parents c8ce364 + 2b04b18 commit 5be6680
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Kiota.Builder/Writers/TypeScript/CodeConstantWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private void WriteRequestsMetadataConstant(CodeConstant codeElement, LanguageWri
var isEnum = executorMethod.ReturnType is CodeType codeType && codeType.TypeDefinition is CodeEnum;
var returnTypeWithoutCollectionSymbol = GetReturnTypeWithoutCollectionSymbol(executorMethod, returnType);
var isPrimitive = IsPrimitiveType(returnTypeWithoutCollectionSymbol);
var isPrimitiveAlias = GetPrimitiveAlias(returnTypeWithoutCollectionSymbol) is not null;
writer.StartBlock($"{executorMethod.Name.ToFirstCharacterLowerCase()}: {{");
var urlTemplateValue = executorMethod.HasUrlTemplateOverride ? $"\"{executorMethod.UrlTemplateOverride}\"" : uriTemplateConstant.Name.ToFirstCharacterUpperCase();
writer.WriteLine($"uriTemplate: {urlTemplateValue},");
Expand All @@ -118,7 +119,7 @@ private void WriteRequestsMetadataConstant(CodeConstant codeElement, LanguageWri
}
writer.CloseBlock("},");
}
writer.WriteLine($"adapterMethodName: \"{GetSendRequestMethodName(isVoid, isStream, executorMethod.ReturnType.IsCollection, isPrimitive, isEnum)}\",");
writer.WriteLine($"adapterMethodName: \"{GetSendRequestMethodName(isVoid, isStream, executorMethod.ReturnType.IsCollection, isPrimitive || isPrimitiveAlias, isEnum)}\",");
if (isEnum)
{
string enumObjectName = string.Empty;
Expand Down Expand Up @@ -169,6 +170,8 @@ private string GetTypeFactory(bool isVoid, bool isStream, CodeMethod codeElement
if (isVoid) return string.Empty;
var typeName = conventions.TranslateType(codeElement.ReturnType);
if (isStream || IsPrimitiveType(typeName)) return $" \"{typeName}\"";
if (GetPrimitiveAlias(typeName) is { } alias && !string.IsNullOrEmpty(alias))
return $" \"{alias}\"";
return $" {GetFactoryMethodName(codeElement.ReturnType, codeElement, writer)}";
}
private string GetReturnTypeWithoutCollectionSymbol(CodeMethod codeElement, string fullTypeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ public static string TranslateTypescriptType(CodeTypeBase type)
{
TYPE_INTEGER or TYPE_INT or TYPE_INT64 or TYPE_FLOAT or TYPE_DOUBLE or TYPE_BYTE or TYPE_SBYTE or TYPE_DECIMAL => TYPE_NUMBER,
TYPE_BINARY or TYPE_BASE64 or TYPE_BASE64URL => TYPE_STRING,
TYPE_GUID => TYPE_GUID,
TYPE_STRING or TYPE_OBJECT or TYPE_BOOLEAN or TYPE_VOID or TYPE_LOWERCASE_STRING or TYPE_LOWERCASE_OBJECT or TYPE_LOWERCASE_BOOLEAN or TYPE_LOWERCASE_VOID => type.Name.ToFirstCharacterLowerCase(),
null => TYPE_OBJECT,
_ when type is CodeComposedTypeBase composedType => composedType.Name.ToFirstCharacterUpperCase(),
Expand Down Expand Up @@ -225,6 +224,15 @@ TYPE_LOWERCASE_BOOLEAN or
};
}

public static string? GetPrimitiveAlias(string typeName)
{
return typeName switch
{
TYPE_GUID => TYPE_LOWERCASE_STRING,
_ => null
};
}

public static bool IsPrimitiveType(CodeType codeType, CodeComposedTypeBase codeComposedTypeBase) => IsPrimitiveType(codeType, codeComposedTypeBase, true);

public static bool IsPrimitiveType(CodeType codeType, CodeComposedTypeBase codeComposedTypeBase, bool includeCollectionInformation) => IsPrimitiveType(GetTypescriptTypeString(codeType, codeComposedTypeBase, includeCollectionInformation));
Expand Down

0 comments on commit 5be6680

Please sign in to comment.