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

113 lines
3.0 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 "OpenAPIOrder.h"
#include "OpenAPIModule.h"
#include "OpenAPIHelpers.h"
#include "Templates/SharedPointer.h"
namespace OpenAPI
{
inline FString ToString(const OpenAPIOrder::StatusEnum& Value)
{
switch (Value)
{
case OpenAPIOrder::StatusEnum::Placed:
return TEXT("placed");
case OpenAPIOrder::StatusEnum::Approved:
return TEXT("approved");
case OpenAPIOrder::StatusEnum::Delivered:
return TEXT("delivered");
}
UE_LOG(LogOpenAPI, Error, TEXT("Invalid OpenAPIOrder::StatusEnum Value (%d)"), (int)Value);
return TEXT("");
}
inline FStringFormatArg ToStringFormatArg(const OpenAPIOrder::StatusEnum& Value)
{
return FStringFormatArg(ToString(Value));
}
inline void WriteJsonValue(JsonWriter& Writer, const OpenAPIOrder::StatusEnum& Value)
{
WriteJsonValue(Writer, ToString(Value));
}
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, OpenAPIOrder::StatusEnum& Value)
{
FString TmpValue;
if (JsonValue->TryGetString(TmpValue))
{
static TMap<FString, OpenAPIOrder::StatusEnum> StringToEnum = {
{ TEXT("placed"), OpenAPIOrder::StatusEnum::Placed },
{ TEXT("approved"), OpenAPIOrder::StatusEnum::Approved },
{ TEXT("delivered"), OpenAPIOrder::StatusEnum::Delivered }, };
const auto Found = StringToEnum.Find(TmpValue);
if(Found)
{
Value = *Found;
return true;
}
}
return false;
}
void OpenAPIOrder::WriteJson(JsonWriter& Writer) const
{
Writer->WriteObjectStart();
if (Id.IsSet())
{
Writer->WriteIdentifierPrefix(TEXT("id")); WriteJsonValue(Writer, Id.GetValue());
}
if (PetId.IsSet())
{
Writer->WriteIdentifierPrefix(TEXT("petId")); WriteJsonValue(Writer, PetId.GetValue());
}
if (Quantity.IsSet())
{
Writer->WriteIdentifierPrefix(TEXT("quantity")); WriteJsonValue(Writer, Quantity.GetValue());
}
if (ShipDate.IsSet())
{
Writer->WriteIdentifierPrefix(TEXT("shipDate")); WriteJsonValue(Writer, ShipDate.GetValue());
}
if (Status.IsSet())
{
Writer->WriteIdentifierPrefix(TEXT("status")); WriteJsonValue(Writer, Status.GetValue());
}
if (Complete.IsSet())
{
Writer->WriteIdentifierPrefix(TEXT("complete")); WriteJsonValue(Writer, Complete.GetValue());
}
Writer->WriteObjectEnd();
}
bool OpenAPIOrder::FromJson(const TSharedPtr<FJsonObject>& JsonObject)
{
bool ParseSuccess = true;
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("id"), Id);
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("petId"), PetId);
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("quantity"), Quantity);
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("shipDate"), ShipDate);
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("status"), Status);
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("complete"), Complete);
return ParseSuccess;
}
}