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

fix: Guid is an alias to primitive type string #5740

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
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
Loading