From e63b09cdd25508c26a10d9172fc48d67029da7f8 Mon Sep 17 00:00:00 2001 From: Samuel Kahn Date: Tue, 26 May 2020 18:26:02 +0200 Subject: [PATCH 1/6] Added the possibility for a codegen to set the location of the generated model files, similarly to API files. --- .../java/org/openapitools/codegen/CodegenConfig.java | 2 ++ .../java/org/openapitools/codegen/DefaultCodegen.java | 5 +++++ .../java/org/openapitools/codegen/DefaultGenerator.java | 9 ++------- .../codegen/languages/CppUE4ClientCodegen.java | 6 ++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java index 06fd6a30d627..9e8d49ab4b41 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java @@ -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); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 08894cd58a43..37c0669f9542 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -4743,6 +4743,11 @@ public String apiFilename(String templateName, String tag) { 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 * diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index c9e449c6e01e..9e0c8d5f00b7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -366,14 +366,9 @@ private void generateModelDocumentation(List files, Map mo } } - 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 files, Map models, String modelName) throws IOException { for (String templateName : config.modelTemplateFiles().keySet()) { - String filename = getModelFilenameByTemplate(modelName, templateName); + String filename = config.modelFilename(templateName, modelName); if (!config.shouldOverwrite(filename)) { LOGGER.info("Skipped overwriting {}", filename); if (dryRun) { @@ -444,7 +439,7 @@ void generateModels(List files, List allModels, List unuse if (dryRun) { // HACK: Because this returns early, could lead to some invalid model reporting. for (String templateName : config.modelTemplateFiles().keySet()) { - String filename = getModelFilenameByTemplate(name, templateName); + String filename = config.modelFilename(templateName, name); dryRunStatusMap.put(filename, new DryRunStatus( java.nio.file.Paths.get(filename), DryRunStatus.State.Skipped, diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppUE4ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppUE4ClientCodegen.java index 88d9c309ecd1..1df43f495935 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppUE4ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppUE4ClientCodegen.java @@ -331,18 +331,16 @@ public String apiFileFolder() { 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) { From 4c8ffe451762abc8afd6e17d48b7e0824c8384b2 Mon Sep 17 00:00:00 2001 From: Samuel Kahn Date: Tue, 26 May 2020 18:35:46 +0200 Subject: [PATCH 2/6] Removed std::shared_ptr from the generated types. Types in UE4Codegen are handled as POD structs, not shared pointers. --- .../openapitools/codegen/languages/CppUE4ClientCodegen.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppUE4ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppUE4ClientCodegen.java index 1df43f495935..4b990fafd49d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppUE4ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppUE4ClientCodegen.java @@ -397,6 +397,10 @@ public String getTypeDeclaration(Schema p) { } } + @Override + public String getTypeDeclaration(String name) { + return name; + } @Override public String toDefaultValue(Schema p) { From fd0bc2a5fc6ef58e13b751b02cde14ebfa7406f2 Mon Sep 17 00:00:00 2001 From: Samuel Kahn Date: Tue, 26 May 2020 19:08:59 +0200 Subject: [PATCH 3/6] Fixed handling of body parameters as per the specification, the single body object is written directly as the payload. --- .../main/resources/cpp-ue4/api-operations-source.mustache | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-ue4/api-operations-source.mustache b/modules/openapi-generator/src/main/resources/cpp-ue4/api-operations-source.mustache index 894e76bc7b7b..e59c122c17b3 100644 --- a/modules/openapi-generator/src/main/resources/cpp-ue4/api-operations-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-ue4/api-operations-source.mustache @@ -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")); From ae8e3a937907f965c317b4ac39bb66a3413acdd8 Mon Sep 17 00:00:00 2001 From: Samuel Kahn Date: Tue, 26 May 2020 20:25:09 +0200 Subject: [PATCH 4/6] Fixed handling of files and binaries, if a field is both isFile and isBinary, file will take precedence. --- .../resources/cpp-ue4/api-operations-source.mustache | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-ue4/api-operations-source.mustache b/modules/openapi-generator/src/main/resources/cpp-ue4/api-operations-source.mustache index e59c122c17b3..8ab14a704cf1 100644 --- a/modules/openapi-generator/src/main/resources/cpp-ue4/api-operations-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-ue4/api-operations-source.mustache @@ -174,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()) @@ -189,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}} From 52a99f75c962290088ee4fb9a9d3b8769ce4ad3b Mon Sep 17 00:00:00 2001 From: Samuel Kahn Date: Tue, 26 May 2020 20:27:43 +0200 Subject: [PATCH 5/6] Updated cpp-ue4 client samples --- .../petstore/cpp-ue4/.openapi-generator/FILES | 32 +++++++++++++++++++ .../{ => Private}/OpenAPIApiResponse.cpp | 0 .../cpp-ue4/{ => Private}/OpenAPICategory.cpp | 0 .../cpp-ue4/{ => Private}/OpenAPIOrder.cpp | 0 .../cpp-ue4/{ => Private}/OpenAPIPet.cpp | 0 .../Private/OpenAPIPetApiOperations.cpp | 9 ++---- .../Private/OpenAPIStoreApiOperations.cpp | 4 +-- .../cpp-ue4/{ => Private}/OpenAPITag.cpp | 0 .../cpp-ue4/{ => Private}/OpenAPIUser.cpp | 0 .../Private/OpenAPIUserApiOperations.cpp | 16 +++------- .../cpp-ue4/{ => Public}/OpenAPIApiResponse.h | 0 .../cpp-ue4/{ => Public}/OpenAPICategory.h | 0 .../cpp-ue4/{ => Public}/OpenAPIOrder.h | 0 .../cpp-ue4/{ => Public}/OpenAPIPet.h | 4 +-- .../cpp-ue4/Public/OpenAPIPetApiOperations.h | 12 +++---- .../Public/OpenAPIStoreApiOperations.h | 4 +-- .../cpp-ue4/{ => Public}/OpenAPITag.h | 0 .../cpp-ue4/{ => Public}/OpenAPIUser.h | 0 .../cpp-ue4/Public/OpenAPIUserApiOperations.h | 8 ++--- 19 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 samples/client/petstore/cpp-ue4/.openapi-generator/FILES rename samples/client/petstore/cpp-ue4/{ => Private}/OpenAPIApiResponse.cpp (100%) rename samples/client/petstore/cpp-ue4/{ => Private}/OpenAPICategory.cpp (100%) rename samples/client/petstore/cpp-ue4/{ => Private}/OpenAPIOrder.cpp (100%) rename samples/client/petstore/cpp-ue4/{ => Private}/OpenAPIPet.cpp (100%) rename samples/client/petstore/cpp-ue4/{ => Private}/OpenAPITag.cpp (100%) rename samples/client/petstore/cpp-ue4/{ => Private}/OpenAPIUser.cpp (100%) rename samples/client/petstore/cpp-ue4/{ => Public}/OpenAPIApiResponse.h (100%) rename samples/client/petstore/cpp-ue4/{ => Public}/OpenAPICategory.h (100%) rename samples/client/petstore/cpp-ue4/{ => Public}/OpenAPIOrder.h (100%) rename samples/client/petstore/cpp-ue4/{ => Public}/OpenAPIPet.h (89%) rename samples/client/petstore/cpp-ue4/{ => Public}/OpenAPITag.h (100%) rename samples/client/petstore/cpp-ue4/{ => Public}/OpenAPIUser.h (100%) diff --git a/samples/client/petstore/cpp-ue4/.openapi-generator/FILES b/samples/client/petstore/cpp-ue4/.openapi-generator/FILES new file mode 100644 index 000000000000..58fce1c2a072 --- /dev/null +++ b/samples/client/petstore/cpp-ue4/.openapi-generator/FILES @@ -0,0 +1,32 @@ +.openapi-generator-ignore +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 diff --git a/samples/client/petstore/cpp-ue4/OpenAPIApiResponse.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIApiResponse.cpp similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPIApiResponse.cpp rename to samples/client/petstore/cpp-ue4/Private/OpenAPIApiResponse.cpp diff --git a/samples/client/petstore/cpp-ue4/OpenAPICategory.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPICategory.cpp similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPICategory.cpp rename to samples/client/petstore/cpp-ue4/Private/OpenAPICategory.cpp diff --git a/samples/client/petstore/cpp-ue4/OpenAPIOrder.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIOrder.cpp similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPIOrder.cpp rename to samples/client/petstore/cpp-ue4/Private/OpenAPIOrder.cpp diff --git a/samples/client/petstore/cpp-ue4/OpenAPIPet.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIPet.cpp similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPIPet.cpp rename to samples/client/petstore/cpp-ue4/Private/OpenAPIPet.cpp diff --git a/samples/client/petstore/cpp-ue4/Private/OpenAPIPetApiOperations.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIPetApiOperations.cpp index 8ca1ec220fd5..4df6f9160880 100644 --- a/samples/client/petstore/cpp-ue4/Private/OpenAPIPetApiOperations.cpp +++ b/samples/client/petstore/cpp-ue4/Private/OpenAPIPetApiOperations.cpp @@ -43,9 +43,7 @@ void OpenAPIPetApi::AddPetRequest::SetupHttpRequest(const TSharedRef::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::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::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")); diff --git a/samples/client/petstore/cpp-ue4/OpenAPITag.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPITag.cpp similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPITag.cpp rename to samples/client/petstore/cpp-ue4/Private/OpenAPITag.cpp diff --git a/samples/client/petstore/cpp-ue4/OpenAPIUser.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIUser.cpp similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPIUser.cpp rename to samples/client/petstore/cpp-ue4/Private/OpenAPIUser.cpp diff --git a/samples/client/petstore/cpp-ue4/Private/OpenAPIUserApiOperations.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIUserApiOperations.cpp index c31afe5ba13e..97562911f703 100644 --- a/samples/client/petstore/cpp-ue4/Private/OpenAPIUserApiOperations.cpp +++ b/samples/client/petstore/cpp-ue4/Private/OpenAPIUserApiOperations.cpp @@ -43,9 +43,7 @@ void OpenAPIUserApi::CreateUserRequest::SetupHttpRequest(const TSharedRef::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::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")); diff --git a/samples/client/petstore/cpp-ue4/OpenAPIApiResponse.h b/samples/client/petstore/cpp-ue4/Public/OpenAPIApiResponse.h similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPIApiResponse.h rename to samples/client/petstore/cpp-ue4/Public/OpenAPIApiResponse.h diff --git a/samples/client/petstore/cpp-ue4/OpenAPICategory.h b/samples/client/petstore/cpp-ue4/Public/OpenAPICategory.h similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPICategory.h rename to samples/client/petstore/cpp-ue4/Public/OpenAPICategory.h diff --git a/samples/client/petstore/cpp-ue4/OpenAPIOrder.h b/samples/client/petstore/cpp-ue4/Public/OpenAPIOrder.h similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPIOrder.h rename to samples/client/petstore/cpp-ue4/Public/OpenAPIOrder.h diff --git a/samples/client/petstore/cpp-ue4/OpenAPIPet.h b/samples/client/petstore/cpp-ue4/Public/OpenAPIPet.h similarity index 89% rename from samples/client/petstore/cpp-ue4/OpenAPIPet.h rename to samples/client/petstore/cpp-ue4/Public/OpenAPIPet.h index 3a90d2b0c6b1..0e81e5fe0f9c 100644 --- a/samples/client/petstore/cpp-ue4/OpenAPIPet.h +++ b/samples/client/petstore/cpp-ue4/Public/OpenAPIPet.h @@ -34,8 +34,8 @@ class OPENAPI_API OpenAPIPet : public Model TOptional Id; TOptional Category; FString Name; - TArray> PhotoUrls; - TOptional>> Tags; + TArray PhotoUrls; + TOptional> Tags; enum class StatusEnum { Available, diff --git a/samples/client/petstore/cpp-ue4/Public/OpenAPIPetApiOperations.h b/samples/client/petstore/cpp-ue4/Public/OpenAPIPetApiOperations.h index 2667a08066b7..a93365d9546a 100644 --- a/samples/client/petstore/cpp-ue4/Public/OpenAPIPetApiOperations.h +++ b/samples/client/petstore/cpp-ue4/Public/OpenAPIPetApiOperations.h @@ -33,7 +33,7 @@ class OPENAPI_API OpenAPIPetApi::AddPetRequest : public Request FString ComputePath() const final; /* Pet object that needs to be added to the store */ - std::shared_ptr Body; + OpenAPIPet Body; }; class OPENAPI_API OpenAPIPetApi::AddPetResponse : public Response @@ -89,7 +89,7 @@ class OPENAPI_API OpenAPIPetApi::FindPetsByStatusRequest : public Request Sold, }; /* Status values that need to be considered for filter */ - TArray> Status; + TArray Status; }; class OPENAPI_API OpenAPIPetApi::FindPetsByStatusResponse : public Response @@ -99,7 +99,7 @@ class OPENAPI_API OpenAPIPetApi::FindPetsByStatusResponse : public Response void SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode) final; bool FromJson(const TSharedPtr& JsonObject) final; - TArray> Content; + TArray Content; }; /* Finds Pets by tags @@ -114,7 +114,7 @@ class OPENAPI_API OpenAPIPetApi::FindPetsByTagsRequest : public Request FString ComputePath() const final; /* Tags to filter by */ - TArray> Tags; + TArray Tags; }; class OPENAPI_API OpenAPIPetApi::FindPetsByTagsResponse : public Response @@ -124,7 +124,7 @@ class OPENAPI_API OpenAPIPetApi::FindPetsByTagsResponse : public Response void SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode) final; bool FromJson(const TSharedPtr& JsonObject) final; - TArray> Content; + TArray Content; }; /* Find pet by ID @@ -163,7 +163,7 @@ class OPENAPI_API OpenAPIPetApi::UpdatePetRequest : public Request FString ComputePath() const final; /* Pet object that needs to be added to the store */ - std::shared_ptr Body; + OpenAPIPet Body; }; class OPENAPI_API OpenAPIPetApi::UpdatePetResponse : public Response diff --git a/samples/client/petstore/cpp-ue4/Public/OpenAPIStoreApiOperations.h b/samples/client/petstore/cpp-ue4/Public/OpenAPIStoreApiOperations.h index 924bb148dd46..06e6809c1850 100644 --- a/samples/client/petstore/cpp-ue4/Public/OpenAPIStoreApiOperations.h +++ b/samples/client/petstore/cpp-ue4/Public/OpenAPIStoreApiOperations.h @@ -65,7 +65,7 @@ class OPENAPI_API OpenAPIStoreApi::GetInventoryResponse : public Response void SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode) final; bool FromJson(const TSharedPtr& JsonObject) final; - TMap> Content; + TMap Content; }; /* Find purchase order by ID @@ -104,7 +104,7 @@ class OPENAPI_API OpenAPIStoreApi::PlaceOrderRequest : public Request FString ComputePath() const final; /* order placed for purchasing the pet */ - std::shared_ptr Body; + OpenAPIOrder Body; }; class OPENAPI_API OpenAPIStoreApi::PlaceOrderResponse : public Response diff --git a/samples/client/petstore/cpp-ue4/OpenAPITag.h b/samples/client/petstore/cpp-ue4/Public/OpenAPITag.h similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPITag.h rename to samples/client/petstore/cpp-ue4/Public/OpenAPITag.h diff --git a/samples/client/petstore/cpp-ue4/OpenAPIUser.h b/samples/client/petstore/cpp-ue4/Public/OpenAPIUser.h similarity index 100% rename from samples/client/petstore/cpp-ue4/OpenAPIUser.h rename to samples/client/petstore/cpp-ue4/Public/OpenAPIUser.h diff --git a/samples/client/petstore/cpp-ue4/Public/OpenAPIUserApiOperations.h b/samples/client/petstore/cpp-ue4/Public/OpenAPIUserApiOperations.h index 2b0ab2e5385e..3e050a41ef08 100644 --- a/samples/client/petstore/cpp-ue4/Public/OpenAPIUserApiOperations.h +++ b/samples/client/petstore/cpp-ue4/Public/OpenAPIUserApiOperations.h @@ -32,7 +32,7 @@ class OPENAPI_API OpenAPIUserApi::CreateUserRequest : public Request FString ComputePath() const final; /* Created user object */ - std::shared_ptr Body; + OpenAPIUser Body; }; class OPENAPI_API OpenAPIUserApi::CreateUserResponse : public Response @@ -56,7 +56,7 @@ class OPENAPI_API OpenAPIUserApi::CreateUsersWithArrayInputRequest : public Requ FString ComputePath() const final; /* List of user object */ - TArray> Body; + TArray Body; }; class OPENAPI_API OpenAPIUserApi::CreateUsersWithArrayInputResponse : public Response @@ -80,7 +80,7 @@ class OPENAPI_API OpenAPIUserApi::CreateUsersWithListInputRequest : public Reque FString ComputePath() const final; /* List of user object */ - TArray> Body; + TArray Body; }; class OPENAPI_API OpenAPIUserApi::CreateUsersWithListInputResponse : public Response @@ -204,7 +204,7 @@ class OPENAPI_API OpenAPIUserApi::UpdateUserRequest : public Request /* name that need to be deleted */ FString Username; /* Updated user object */ - std::shared_ptr Body; + OpenAPIUser Body; }; class OPENAPI_API OpenAPIUserApi::UpdateUserResponse : public Response From 17837e64f6b53ecd5679a371867a7e77327cb6b5 Mon Sep 17 00:00:00 2001 From: Samuel Kahn Date: Wed, 27 May 2020 19:41:31 +0200 Subject: [PATCH 6/6] Fixed handling of enums in models --- .../src/main/resources/cpp-ue4/model-source.mustache | 2 ++ samples/client/petstore/cpp-ue4/.openapi-generator/FILES | 1 - samples/client/petstore/cpp-ue4/Private/OpenAPIOrder.cpp | 5 ++++- samples/client/petstore/cpp-ue4/Private/OpenAPIPet.cpp | 5 ++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-ue4/model-source.mustache b/modules/openapi-generator/src/main/resources/cpp-ue4/model-source.mustache index 4850fb9859ce..3e9b14788a67 100644 --- a/modules/openapi-generator/src/main/resources/cpp-ue4/model-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-ue4/model-source.mustache @@ -42,6 +42,7 @@ inline void WriteJsonValue(JsonWriter& Writer, const {{classname}}::{{{enumName} inline bool TryGetJsonValue(const TSharedPtr& JsonValue, {{classname}}::{{{enumName}}}& Value) { + {{#allowableValues}} FString TmpValue; if (JsonValue->TryGetString(TmpValue)) { @@ -55,6 +56,7 @@ inline bool TryGetJsonValue(const TSharedPtr& JsonValue, {{classname return true; } } + {{/allowableValues}} return false; } diff --git a/samples/client/petstore/cpp-ue4/.openapi-generator/FILES b/samples/client/petstore/cpp-ue4/.openapi-generator/FILES index 58fce1c2a072..23079276740b 100644 --- a/samples/client/petstore/cpp-ue4/.openapi-generator/FILES +++ b/samples/client/petstore/cpp-ue4/.openapi-generator/FILES @@ -1,4 +1,3 @@ -.openapi-generator-ignore OpenAPI.Build.cs Private\OpenAPIApiResponse.cpp Private\OpenAPIBaseModel.cpp diff --git a/samples/client/petstore/cpp-ue4/Private/OpenAPIOrder.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIOrder.cpp index cd8e524b0496..f125c7ae40b1 100644 --- a/samples/client/petstore/cpp-ue4/Private/OpenAPIOrder.cpp +++ b/samples/client/petstore/cpp-ue4/Private/OpenAPIOrder.cpp @@ -51,7 +51,10 @@ inline bool TryGetJsonValue(const TSharedPtr& JsonValue, OpenAPIOrde FString TmpValue; if (JsonValue->TryGetString(TmpValue)) { - static TMap StringToEnum = { }; + static TMap StringToEnum = { + { TEXT("placed"), OpenAPIOrder::StatusEnum::Placed }, + { TEXT("approved"), OpenAPIOrder::StatusEnum::Approved }, + { TEXT("delivered"), OpenAPIOrder::StatusEnum::Delivered }, }; const auto Found = StringToEnum.Find(TmpValue); if(Found) diff --git a/samples/client/petstore/cpp-ue4/Private/OpenAPIPet.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIPet.cpp index d1d1a690d6c5..b36df84ae6b7 100644 --- a/samples/client/petstore/cpp-ue4/Private/OpenAPIPet.cpp +++ b/samples/client/petstore/cpp-ue4/Private/OpenAPIPet.cpp @@ -51,7 +51,10 @@ inline bool TryGetJsonValue(const TSharedPtr& JsonValue, OpenAPIPet: FString TmpValue; if (JsonValue->TryGetString(TmpValue)) { - static TMap StringToEnum = { }; + static TMap StringToEnum = { + { TEXT("available"), OpenAPIPet::StatusEnum::Available }, + { TEXT("pending"), OpenAPIPet::StatusEnum::Pending }, + { TEXT("sold"), OpenAPIPet::StatusEnum::Sold }, }; const auto Found = StringToEnum.Find(TmpValue); if(Found)