Skip to content

Commit

Permalink
Add ref support inside fromProperty (OpenAPITools#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
etherealjoy authored Oct 20, 2018
1 parent 343e120 commit aad23e6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -276,6 +278,24 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
}
}

// override with any special post-processing
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
List<CodegenOperation> operationList = (List<CodegenOperation>) 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

{{#imports}}{{{import}}}
{{/imports}}
{{^hasModelImport}}#include "../ModelBase.h"{{/hasModelImport}}

#include <boost/optional.hpp>

Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/cpp-restsdk/api/PetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "Pet.h"
#include <cpprest/details/basic_types.h>


#include <boost/optional.hpp>

namespace org {
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/cpp-restsdk/api/StoreApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <map>
#include <cpprest/details/basic_types.h>


#include <boost/optional.hpp>

namespace org {
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/cpp-restsdk/api/UserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>
#include <cpprest/details/basic_types.h>


#include <boost/optional.hpp>

namespace org {
Expand Down

0 comments on commit aad23e6

Please sign in to comment.