[cpp-ue4] Series of fixes for cpp-ue4 (#15068)

* [cpp-ue4] Removed warning related to wrong casing of HTTP module

* [cpp-ue4] Fixed compilation error when using file parameters in json body generation

* [cpp-ue4] Do not write the form param json body generation unless there actually are form params

* [cpp-ue4] Added support for enum values in path params
This commit is contained in:
Samuel Kahn 2023-04-01 13:01:45 +02:00 committed by GitHub
parent 938c72cec0
commit 033b946856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -11,7 +11,7 @@ public class {{unrealModuleName}} : ModuleRules
new string[]
{
"Core",
"Http",
"HTTP",
"Json",
}
);

View File

@ -172,11 +172,16 @@ void {{classname}}::{{operationIdCamelCase}}Request::SetupHttpRequest(const FHtt
HttpRequest->SetContentAsString(JsonBody);
{{/bodyParams.0}}
{{^bodyParams.0}}
// Form parameters
{{#formParams.0}}
// Form parameters added to try to generate a json body when no body parameters are specified.
FString JsonBody;
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
Writer->WriteObjectStart();
{{#formParams}}
{{#isFile}}
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Form parameter ({{baseName}}) was ignored, Files are not supported in json body"));
{{/isFile}}
{{^isFile}}
{{#required}}
Writer->WriteIdentifierPrefix(TEXT("{{baseName}}"));
WriteJsonValue(Writer, {{paramName}});
@ -187,11 +192,13 @@ void {{classname}}::{{operationIdCamelCase}}Request::SetupHttpRequest(const FHtt
WriteJsonValue(Writer, {{paramName}}.GetValue());
}
{{/required}}
{{/isFile}}
{{/formParams}}
Writer->WriteObjectEnd();
Writer->Close();
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
HttpRequest->SetContentAsString(JsonBody);
{{/formParams.0}}
{{/bodyParams.0}}
}
else if (Consumes.Contains(TEXT("multipart/form-data")))

View File

@ -94,12 +94,18 @@ FString Base64UrlEncode(const T& Value)
return Base64String;
}
template<typename T>
template<typename T, typename std::enable_if<!std::is_base_of<Model, T>::value, int>::type = 0>
inline FStringFormatArg ToStringFormatArg(const T& Value)
{
return FStringFormatArg(Value);
}
template<typename T, typename std::enable_if<std::is_base_of<Model, T>::value, int>::type = 0>
inline FStringFormatArg ToStringFormatArg(const T& EnumModelValue)
{
return FStringFormatArg(T::EnumToString(EnumModelValue.Value));
}
inline FStringFormatArg ToStringFormatArg(const FDateTime& Value)
{
return FStringFormatArg(Value.ToIso8601());