From aad23e603ff65ed582a6628cf43a5d2c4f7f1248 Mon Sep 17 00:00:00 2001 From: sunn <33183834+etherealjoy@users.noreply.github.com> Date: Sat, 20 Oct 2018 13:52:46 +0200 Subject: [PATCH] Add ref support inside fromProperty (#1235) --- .../languages/CppRestSdkClientCodegen.java | 22 ++++++++++++++++++- .../cpp-rest-sdk-client/api-header.mustache | 1 + .../client/petstore/cpp-restsdk/api/PetApi.h | 1 + .../petstore/cpp-restsdk/api/StoreApi.h | 1 + .../client/petstore/cpp-restsdk/api/UserApi.h | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java index 841e1c2dd09f..5a8424838bad 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java @@ -38,6 +38,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -154,7 +155,7 @@ public CppRestSdkClientCodegen() { typeMapping.put("map", "std::map"); typeMapping.put("file", "HttpContent"); typeMapping.put("object", "Object"); - typeMapping.put("binary", "std::string"); + typeMapping.put("binary", "utility::string_t"); typeMapping.put("number", "double"); typeMapping.put("UUID", "utility::string_t"); typeMapping.put("ByteArray", "utility::string_t"); @@ -249,6 +250,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation if (methodResponse != null) { Schema response = ModelUtils.getSchemaFromResponse(methodResponse); + response = ModelUtils.unaliasSchema(openAPI.getComponents().getSchemas(), response); if (response != null) { CodegenProperty cm = fromProperty("response", response); op.vendorExtensions.put("x-codegen-response", cm); @@ -276,6 +278,24 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert } } + // override with any special post-processing + @SuppressWarnings("unchecked") + @Override + public Map postProcessOperationsWithModels(Map objs, List allModels) { + Map operations = (Map) objs.get("operations"); + List operationList = (List) operations.get("operation"); + for (CodegenOperation op : operationList) { + for(String hdr : op.imports) { + if(importMapping.containsKey(hdr)) { + continue; + } + operations.put("hasModelImport", true); + break; + } + } + return objs; + } + protected boolean isFileSchema(CodegenProperty property) { return property.baseType.equals("HttpContent"); } diff --git a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-header.mustache index fbf515deb156..1df116498b23 100644 --- a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-header.mustache @@ -13,6 +13,7 @@ {{#imports}}{{{import}}} {{/imports}} +{{^hasModelImport}}#include "../ModelBase.h"{{/hasModelImport}} #include diff --git a/samples/client/petstore/cpp-restsdk/api/PetApi.h b/samples/client/petstore/cpp-restsdk/api/PetApi.h index 0313da30395e..a4b37987816e 100644 --- a/samples/client/petstore/cpp-restsdk/api/PetApi.h +++ b/samples/client/petstore/cpp-restsdk/api/PetApi.h @@ -26,6 +26,7 @@ #include "Pet.h" #include + #include namespace org { diff --git a/samples/client/petstore/cpp-restsdk/api/StoreApi.h b/samples/client/petstore/cpp-restsdk/api/StoreApi.h index 507756dee1d9..3a2a1ac3b324 100644 --- a/samples/client/petstore/cpp-restsdk/api/StoreApi.h +++ b/samples/client/petstore/cpp-restsdk/api/StoreApi.h @@ -25,6 +25,7 @@ #include #include + #include namespace org { diff --git a/samples/client/petstore/cpp-restsdk/api/UserApi.h b/samples/client/petstore/cpp-restsdk/api/UserApi.h index ea184c0cf76c..c0ea7d3b1f23 100644 --- a/samples/client/petstore/cpp-restsdk/api/UserApi.h +++ b/samples/client/petstore/cpp-restsdk/api/UserApi.h @@ -25,6 +25,7 @@ #include #include + #include namespace org {