Samuel Kahn e3eb3c2f7d
UE4 client generator fixes (#6438)
* Added the possibility for a codegen to set the location of the generated model files, similarly to API files.

* Removed std::shared_ptr from the generated types. Types in UE4Codegen are handled as POD structs, not shared pointers.

* Fixed handling of body parameters as per the specification, the single body object is written directly as the payload.

* Fixed handling of files and binaries, if a field is both isFile and isBinary, file will take precedence.

* Updated cpp-ue4 client samples

* Fixed handling of enums in models

Co-authored-by: William Cheng <wing328hk@gmail.com>
2020-06-01 00:13:12 +08:00

107 lines
2.9 KiB
C++

/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* https://github.com/OpenAPITools/openapi-generator
* Do not edit the class manually.
*/
#include "OpenAPIPet.h"
#include "OpenAPIModule.h"
#include "OpenAPIHelpers.h"
#include "Templates/SharedPointer.h"
namespace OpenAPI
{
inline FString ToString(const OpenAPIPet::StatusEnum& Value)
{
switch (Value)
{
case OpenAPIPet::StatusEnum::Available:
return TEXT("available");
case OpenAPIPet::StatusEnum::Pending:
return TEXT("pending");
case OpenAPIPet::StatusEnum::Sold:
return TEXT("sold");
}
UE_LOG(LogOpenAPI, Error, TEXT("Invalid OpenAPIPet::StatusEnum Value (%d)"), (int)Value);
return TEXT("");
}
inline FStringFormatArg ToStringFormatArg(const OpenAPIPet::StatusEnum& Value)
{
return FStringFormatArg(ToString(Value));
}
inline void WriteJsonValue(JsonWriter& Writer, const OpenAPIPet::StatusEnum& Value)
{
WriteJsonValue(Writer, ToString(Value));
}
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, OpenAPIPet::StatusEnum& Value)
{
FString TmpValue;
if (JsonValue->TryGetString(TmpValue))
{
static TMap<FString, OpenAPIPet::StatusEnum> StringToEnum = {
{ TEXT("available"), OpenAPIPet::StatusEnum::Available },
{ TEXT("pending"), OpenAPIPet::StatusEnum::Pending },
{ TEXT("sold"), OpenAPIPet::StatusEnum::Sold }, };
const auto Found = StringToEnum.Find(TmpValue);
if(Found)
{
Value = *Found;
return true;
}
}
return false;
}
void OpenAPIPet::WriteJson(JsonWriter& Writer) const
{
Writer->WriteObjectStart();
if (Id.IsSet())
{
Writer->WriteIdentifierPrefix(TEXT("id")); WriteJsonValue(Writer, Id.GetValue());
}
if (Category.IsSet())
{
Writer->WriteIdentifierPrefix(TEXT("category")); WriteJsonValue(Writer, Category.GetValue());
}
Writer->WriteIdentifierPrefix(TEXT("name")); WriteJsonValue(Writer, Name);
Writer->WriteIdentifierPrefix(TEXT("photoUrls")); WriteJsonValue(Writer, PhotoUrls);
if (Tags.IsSet())
{
Writer->WriteIdentifierPrefix(TEXT("tags")); WriteJsonValue(Writer, Tags.GetValue());
}
if (Status.IsSet())
{
Writer->WriteIdentifierPrefix(TEXT("status")); WriteJsonValue(Writer, Status.GetValue());
}
Writer->WriteObjectEnd();
}
bool OpenAPIPet::FromJson(const TSharedPtr<FJsonObject>& JsonObject)
{
bool ParseSuccess = true;
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("id"), Id);
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("category"), Category);
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("name"), Name);
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("photoUrls"), PhotoUrls);
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("tags"), Tags);
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("status"), Status);
return ParseSuccess;
}
}