Skip to content

Commit 1dee3e2

Browse files
etherealjoywing328
authored andcommitted
[cpp-pistache] add the option to fetch dependencies (#495)
* Add the Possibility to fetch dependencies needed by the generated code * Fix typo * Make External Libraries default to false * Add parameter string to the javadoc comment
1 parent 0da5508 commit 1dee3e2

5 files changed

Lines changed: 42 additions & 5 deletions

File tree

bin/cpp-pistache-server-petstore.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ fi
2727

2828
# if you've executed sbt assembly previously it will use that instead.
2929
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
30-
ags="generate -g cpp-pistache-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/cpp-pistache $@"
30+
ags="generate -g cpp-pistache-server -t modules/openapi-generator/src/main/resources/cpp-pistache-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/cpp-pistache $@"
3131

3232
java $JAVA_OPTS -jar $executable $ags

bin/openapi3/cpp-pistache-server-petstore.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ fi
2727

2828
# if you've executed sbt assembly previously it will use that instead.
2929
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
30-
ags="generate -g cpp-pistache-server -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o samples/server/petstore/cpp-pistache $@"
30+
ags="generate -g cpp-pistache-server -t modules/openapi-generator/src/main/resources/cpp-pistache-server -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o samples/server/petstore/cpp-pistache $@"
3131

3232
java $JAVA_OPTS -jar $executable $ags

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343

4444
public class CppPistacheServerCodegen extends AbstractCppCodegen {
4545
protected String implFolder = "impl";
46-
46+
protected boolean isAddExternalLibs = false;
47+
public static final String OPTIONAL_EXTERNAL_LIB = "addExternalLibs";
48+
public static final String OPTIONAL_EXTERNAL_LIB_DESC = "Add the Possibility to fetch and compile external Libraries needed by this Framework.";
4749
@Override
4850
public CodegenType getTag() {
4951
return CodegenType.SERVER;
@@ -77,6 +79,7 @@ public CppPistacheServerCodegen() {
7779
embeddedTemplateDir = templateDir = "cpp-pistache-server";
7880

7981
cliOptions.clear();
82+
addSwitch(OPTIONAL_EXTERNAL_LIB, OPTIONAL_EXTERNAL_LIB_DESC, this.isAddExternalLibs);
8083

8184
reservedWords = new HashSet<>();
8285

@@ -118,7 +121,12 @@ public void processOpts() {
118121
additionalProperties.put("modelNamespaceDeclarations", modelPackage.split("\\."));
119122
additionalProperties.put("modelNamespace", modelPackage.replaceAll("\\.", "::"));
120123
additionalProperties.put("apiNamespaceDeclarations", apiPackage.split("\\."));
121-
additionalProperties.put("apiNamespace", apiPackage.replaceAll("\\.", "::"));
124+
additionalProperties.put("apiNamespace", apiPackage.replaceAll("\\.", "::"));
125+
if (additionalProperties.containsKey(OPTIONAL_EXTERNAL_LIB)) {
126+
setAddExternalLibs(convertPropertyToBooleanAndWriteBack(OPTIONAL_EXTERNAL_LIB));
127+
} else {
128+
additionalProperties.put(OPTIONAL_EXTERNAL_LIB, isAddExternalLibs);
129+
}
122130
}
123131

124132
/**
@@ -410,9 +418,17 @@ public String escapeQuotationMark(String input) {
410418
public String escapeUnsafeCharacters(String input) {
411419
return input.replace("*/", "*_/").replace("/*", "/_*");
412420
}
413-
421+
414422
@Override
415423
public String getTypeDeclaration(String str) {
416424
return toModelName(str);
417425
}
426+
427+
/**
428+
* Specify whether external libraries will be added during the generation
429+
* @param value the value to be set
430+
*/
431+
public void setAddExternalLibs(boolean value){
432+
isAddExternalLibs = value;
433+
}
418434
}

modules/openapi-generator/src/main/resources/cpp-pistache-server/cmake.mustache

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ project(server)
44

55
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pg -g3" )
66

7+
{{#addExternalLibs}}
8+
include(ExternalProject)
9+
10+
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
11+
12+
ExternalProject_Add(PISTACHE
13+
GIT_REPOSITORY https://github.com/oktal/pistache.git
14+
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
15+
)
16+
17+
ExternalProject_Add(NLOHMANN
18+
GIT_REPOSITORY https://github.com/nlohmann/json.git
19+
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
20+
21+
)
22+
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
23+
include_directories(${EXTERNAL_INSTALL_LOCATION}/include/nlohmann)
24+
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
25+
{{/addExternalLibs}}
26+
727
link_directories(/usr/local/lib/)
828

929
aux_source_directory(model MODEL_SOURCES)

samples/server/petstore/cpp-pistache/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ project(server)
44

55
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pg -g3" )
66

7+
78
link_directories(/usr/local/lib/)
89

910
aux_source_directory(model MODEL_SOURCES)

0 commit comments

Comments
 (0)