forked from loafle/openapi-generator-original
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>
This commit is contained in:
@@ -192,6 +192,8 @@ public interface CodegenConfig {
|
||||
|
||||
void postProcessParameter(CodegenParameter parameter);
|
||||
|
||||
String modelFilename(String templateName, String modelName);
|
||||
|
||||
String apiFilename(String templateName, String tag);
|
||||
|
||||
String apiTestFilename(String templateName, String tag);
|
||||
|
||||
@@ -4828,6 +4828,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return apiFileFolder() + File.separator + toApiFilename(tag) + suffix;
|
||||
}
|
||||
|
||||
public String modelFilename(String templateName, String modelName) {
|
||||
String suffix = modelTemplateFiles().get(templateName);
|
||||
return modelFileFolder() + File.separator + toModelFilename(modelName) + suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the full path and API documentation file
|
||||
*
|
||||
|
||||
@@ -363,14 +363,9 @@ public class DefaultGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
|
||||
private String getModelFilenameByTemplate(String modelName, String templateName){
|
||||
String suffix = config.modelTemplateFiles().get(templateName);
|
||||
return config.modelFileFolder() + File.separator + config.toModelFilename(modelName) + suffix;
|
||||
}
|
||||
|
||||
private void generateModel(List<File> files, Map<String, Object> models, String modelName) throws IOException {
|
||||
for (String templateName : config.modelTemplateFiles().keySet()) {
|
||||
String filename = getModelFilenameByTemplate(modelName, templateName);
|
||||
String filename = config.modelFilename(templateName, modelName);
|
||||
File written = processTemplateToFile(models, templateName, filename, generateModels, CodegenConstants.MODELS);
|
||||
if (written != null) {
|
||||
files.add(written);
|
||||
@@ -429,7 +424,7 @@ public class DefaultGenerator implements Generator {
|
||||
|
||||
for (String templateName : config.modelTemplateFiles().keySet()) {
|
||||
// HACK: Because this returns early, could lead to some invalid model reporting.
|
||||
String filename = getModelFilenameByTemplate(name, templateName);
|
||||
String filename = config.modelFilename(templateName, name);
|
||||
Path path = java.nio.file.Paths.get(filename);
|
||||
this.templateProcessor.skip(path,"Skipped prior to model processing due to import mapping conflict (either by user or by generator)." );
|
||||
}
|
||||
|
||||
@@ -331,18 +331,16 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
||||
return outputFolder + File.separator + apiPackage().replace("::", File.separator);
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public String modelFilename(String templateName, String tag) {
|
||||
public String modelFilename(String templateName, String modelName) {
|
||||
String suffix = modelTemplateFiles().get(templateName);
|
||||
String folder = privateFolder;
|
||||
if (suffix == ".h") {
|
||||
folder = publicFolder;
|
||||
}
|
||||
|
||||
return modelFileFolder() + File.separator + folder + File.separator + toModelFilename(tag) + suffix;
|
||||
return modelFileFolder() + File.separator + folder + File.separator + toModelFilename(modelName) + suffix;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
@@ -399,6 +397,10 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
|
||||
@@ -139,19 +139,17 @@ void {{classname}}::{{operationIdCamelCase}}Request::SetupHttpRequest(const TSha
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
{{#bodyParams}}
|
||||
{{#required}}
|
||||
Writer->WriteIdentifierPrefix(TEXT("{{baseName}}")); WriteJsonValue(Writer, {{paramName}});
|
||||
WriteJsonValue(Writer, {{paramName}});
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
if ({{paramName}}.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("{{baseName}}")); WriteJsonValue(Writer, {{paramName}}.GetValue());
|
||||
WriteJsonValue(Writer, {{paramName}}.GetValue());
|
||||
}
|
||||
{{/required}}
|
||||
{{/bodyParams}}
|
||||
Writer->WriteObjectEnd();
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
@@ -176,14 +174,14 @@ void {{classname}}::{{operationIdCamelCase}}Request::SetupHttpRequest(const TSha
|
||||
{{#isFile}}
|
||||
FormData.AddFilePart(TEXT("{{baseName}}"), {{paramName}});
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
{{#isBinary}}
|
||||
FormData.AddBinaryPart(TEXT("{{baseName}}"), {{paramName}});
|
||||
{{/isBinary}}
|
||||
{{#isBinary}}
|
||||
{{^isFile}}
|
||||
{{^isBinary}}
|
||||
FormData.AddStringPart(TEXT("{{baseName}}"), *ToUrlString({{paramName}}));
|
||||
{{/isFile}}
|
||||
{{/isBinary}}
|
||||
{{/isFile}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
if({{paramName}}.IsSet())
|
||||
@@ -191,14 +189,14 @@ void {{classname}}::{{operationIdCamelCase}}Request::SetupHttpRequest(const TSha
|
||||
{{#isFile}}
|
||||
FormData.AddFilePart(TEXT("{{baseName}}"), {{paramName}}.GetValue());
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
{{#isBinary}}
|
||||
FormData.AddBinaryPart(TEXT("{{baseName}}"), {{paramName}}.GetValue());
|
||||
{{/isBinary}}
|
||||
{{^isBinary}}
|
||||
{{^isFile}}
|
||||
FormData.AddStringPart(TEXT("{{baseName}}"), *ToUrlString({{paramName}}.GetValue()));
|
||||
{{/isFile}}
|
||||
{{/isBinary}}
|
||||
{{/isFile}}
|
||||
}
|
||||
{{/required}}
|
||||
{{/isContainer}}
|
||||
|
||||
@@ -42,6 +42,7 @@ inline void WriteJsonValue(JsonWriter& Writer, const {{classname}}::{{{enumName}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, {{classname}}::{{{enumName}}}& Value)
|
||||
{
|
||||
{{#allowableValues}}
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
{
|
||||
@@ -55,6 +56,7 @@ inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, {{classname
|
||||
return true;
|
||||
}
|
||||
}
|
||||
{{/allowableValues}}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
31
samples/client/petstore/cpp-ue4/.openapi-generator/FILES
Normal file
31
samples/client/petstore/cpp-ue4/.openapi-generator/FILES
Normal file
@@ -0,0 +1,31 @@
|
||||
OpenAPI.Build.cs
|
||||
Private\OpenAPIApiResponse.cpp
|
||||
Private\OpenAPIBaseModel.cpp
|
||||
Private\OpenAPICategory.cpp
|
||||
Private\OpenAPIHelpers.cpp
|
||||
Private\OpenAPIModule.cpp
|
||||
Private\OpenAPIModule.h
|
||||
Private\OpenAPIOrder.cpp
|
||||
Private\OpenAPIPet.cpp
|
||||
Private\OpenAPIPetApi.cpp
|
||||
Private\OpenAPIPetApiOperations.cpp
|
||||
Private\OpenAPIStoreApi.cpp
|
||||
Private\OpenAPIStoreApiOperations.cpp
|
||||
Private\OpenAPITag.cpp
|
||||
Private\OpenAPIUser.cpp
|
||||
Private\OpenAPIUserApi.cpp
|
||||
Private\OpenAPIUserApiOperations.cpp
|
||||
Public\OpenAPIApiResponse.h
|
||||
Public\OpenAPIBaseModel.h
|
||||
Public\OpenAPICategory.h
|
||||
Public\OpenAPIHelpers.h
|
||||
Public\OpenAPIOrder.h
|
||||
Public\OpenAPIPet.h
|
||||
Public\OpenAPIPetApi.h
|
||||
Public\OpenAPIPetApiOperations.h
|
||||
Public\OpenAPIStoreApi.h
|
||||
Public\OpenAPIStoreApiOperations.h
|
||||
Public\OpenAPITag.h
|
||||
Public\OpenAPIUser.h
|
||||
Public\OpenAPIUserApi.h
|
||||
Public\OpenAPIUserApiOperations.h
|
||||
@@ -51,7 +51,10 @@ inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, OpenAPIOrde
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
{
|
||||
static TMap<FString, OpenAPIOrder::StatusEnum> StringToEnum = { };
|
||||
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)
|
||||
@@ -51,7 +51,10 @@ inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, OpenAPIPet:
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
{
|
||||
static TMap<FString, OpenAPIPet::StatusEnum> StringToEnum = { };
|
||||
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)
|
||||
@@ -43,9 +43,7 @@ void OpenAPIPetApi::AddPetRequest::SetupHttpRequest(const TSharedRef<IHttpReques
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
WriteJsonValue(Writer, Body);
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
@@ -366,9 +364,7 @@ void OpenAPIPetApi::UpdatePetRequest::SetupHttpRequest(const TSharedRef<IHttpReq
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
WriteJsonValue(Writer, Body);
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
@@ -517,7 +513,6 @@ void OpenAPIPetApi::UploadFileRequest::SetupHttpRequest(const TSharedRef<IHttpRe
|
||||
if(File.IsSet())
|
||||
{
|
||||
FormData.AddFilePart(TEXT("file"), File.GetValue());
|
||||
FormData.AddBinaryPart(TEXT("file"), File.GetValue());
|
||||
}
|
||||
|
||||
FormData.SetupHttpRequest(HttpRequest);
|
||||
|
||||
@@ -197,9 +197,7 @@ void OpenAPIStoreApi::PlaceOrderRequest::SetupHttpRequest(const TSharedRef<IHttp
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
WriteJsonValue(Writer, Body);
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
|
||||
@@ -43,9 +43,7 @@ void OpenAPIUserApi::CreateUserRequest::SetupHttpRequest(const TSharedRef<IHttpR
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
WriteJsonValue(Writer, Body);
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
@@ -102,9 +100,7 @@ void OpenAPIUserApi::CreateUsersWithArrayInputRequest::SetupHttpRequest(const TS
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
WriteJsonValue(Writer, Body);
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
@@ -161,9 +157,7 @@ void OpenAPIUserApi::CreateUsersWithListInputRequest::SetupHttpRequest(const TSh
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
WriteJsonValue(Writer, Body);
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
@@ -433,9 +427,7 @@ void OpenAPIUserApi::UpdateUserRequest::SetupHttpRequest(const TSharedRef<IHttpR
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
WriteJsonValue(Writer, Body);
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
|
||||
@@ -34,8 +34,8 @@ public:
|
||||
TOptional<int64> Id;
|
||||
TOptional<OpenAPICategory> Category;
|
||||
FString Name;
|
||||
TArray<std::shared_ptr<FString>> PhotoUrls;
|
||||
TOptional<TArray<std::shared_ptr<OpenAPIOpenAPITag>>> Tags;
|
||||
TArray<FString> PhotoUrls;
|
||||
TOptional<TArray<OpenAPITag>> Tags;
|
||||
enum class StatusEnum
|
||||
{
|
||||
Available,
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
FString ComputePath() const final;
|
||||
|
||||
/* Pet object that needs to be added to the store */
|
||||
std::shared_ptr<OpenAPIOpenAPIPet> Body;
|
||||
OpenAPIPet Body;
|
||||
};
|
||||
|
||||
class OPENAPI_API OpenAPIPetApi::AddPetResponse : public Response
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
Sold,
|
||||
};
|
||||
/* Status values that need to be considered for filter */
|
||||
TArray<std::shared_ptr<StatusEnum>> Status;
|
||||
TArray<StatusEnum> Status;
|
||||
};
|
||||
|
||||
class OPENAPI_API OpenAPIPetApi::FindPetsByStatusResponse : public Response
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
void SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode) final;
|
||||
bool FromJson(const TSharedPtr<FJsonValue>& JsonObject) final;
|
||||
|
||||
TArray<std::shared_ptr<OpenAPIOpenAPIPet>> Content;
|
||||
TArray<OpenAPIPet> Content;
|
||||
};
|
||||
|
||||
/* Finds Pets by tags
|
||||
@@ -114,7 +114,7 @@ public:
|
||||
FString ComputePath() const final;
|
||||
|
||||
/* Tags to filter by */
|
||||
TArray<std::shared_ptr<FString>> Tags;
|
||||
TArray<FString> Tags;
|
||||
};
|
||||
|
||||
class OPENAPI_API OpenAPIPetApi::FindPetsByTagsResponse : public Response
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
void SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode) final;
|
||||
bool FromJson(const TSharedPtr<FJsonValue>& JsonObject) final;
|
||||
|
||||
TArray<std::shared_ptr<OpenAPIOpenAPIPet>> Content;
|
||||
TArray<OpenAPIPet> Content;
|
||||
};
|
||||
|
||||
/* Find pet by ID
|
||||
@@ -163,7 +163,7 @@ public:
|
||||
FString ComputePath() const final;
|
||||
|
||||
/* Pet object that needs to be added to the store */
|
||||
std::shared_ptr<OpenAPIOpenAPIPet> Body;
|
||||
OpenAPIPet Body;
|
||||
};
|
||||
|
||||
class OPENAPI_API OpenAPIPetApi::UpdatePetResponse : public Response
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
void SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode) final;
|
||||
bool FromJson(const TSharedPtr<FJsonValue>& JsonObject) final;
|
||||
|
||||
TMap<FString, std::shared_ptr<int32>> Content;
|
||||
TMap<FString, int32> Content;
|
||||
};
|
||||
|
||||
/* Find purchase order by ID
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
FString ComputePath() const final;
|
||||
|
||||
/* order placed for purchasing the pet */
|
||||
std::shared_ptr<OpenAPIOpenAPIOrder> Body;
|
||||
OpenAPIOrder Body;
|
||||
};
|
||||
|
||||
class OPENAPI_API OpenAPIStoreApi::PlaceOrderResponse : public Response
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
FString ComputePath() const final;
|
||||
|
||||
/* Created user object */
|
||||
std::shared_ptr<OpenAPIOpenAPIUser> Body;
|
||||
OpenAPIUser Body;
|
||||
};
|
||||
|
||||
class OPENAPI_API OpenAPIUserApi::CreateUserResponse : public Response
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
FString ComputePath() const final;
|
||||
|
||||
/* List of user object */
|
||||
TArray<std::shared_ptr<OpenAPIOpenAPIUser>> Body;
|
||||
TArray<OpenAPIUser> Body;
|
||||
};
|
||||
|
||||
class OPENAPI_API OpenAPIUserApi::CreateUsersWithArrayInputResponse : public Response
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
FString ComputePath() const final;
|
||||
|
||||
/* List of user object */
|
||||
TArray<std::shared_ptr<OpenAPIOpenAPIUser>> Body;
|
||||
TArray<OpenAPIUser> Body;
|
||||
};
|
||||
|
||||
class OPENAPI_API OpenAPIUserApi::CreateUsersWithListInputResponse : public Response
|
||||
@@ -204,7 +204,7 @@ public:
|
||||
/* name that need to be deleted */
|
||||
FString Username;
|
||||
/* Updated user object */
|
||||
std::shared_ptr<OpenAPIOpenAPIUser> Body;
|
||||
OpenAPIUser Body;
|
||||
};
|
||||
|
||||
class OPENAPI_API OpenAPIUserApi::UpdateUserResponse : public Response
|
||||
|
||||
Reference in New Issue
Block a user