diff --git a/.travis.yml b/.travis.yml
index ec63cde0374e..d65971a5867d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -30,12 +30,18 @@ cache:
- $HOME/perl5
- $HOME/.cargo
- $HOME/.stack
+ - $HOME/samples/server/petstore/cpp-pistache/pistache
services:
- docker
# comment out the host table change to use the public petstore server
addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ packages:
+ - g++-5
chrome: stable
hosts:
- petstore.swagger.io
@@ -86,10 +92,13 @@ before_install:
install:
# Add Godeps dependencies to GOPATH and PATH
- - eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=1.4 bash)"
- - export GOPATH="${TRAVIS_BUILD_DIR}/Godeps/_workspace"
+ #- eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=1.4 bash)"
+ #- export GOPATH="${TRAVIS_BUILD_DIR}/Godeps/_workspace"
- export PATH="${TRAVIS_BUILD_DIR}/Godeps/_workspace/bin:$HOME/.cargo/bin:$PATH"
- - go version
+ #- go version
+ - gcc -v
+ - echo $CC
+ - echo $CXX
script:
# fail fast
@@ -130,4 +139,4 @@ after_success:
- if [ $DOCKER_HUB_USERNAME ]; then echo "$DOCKER_HUB_PASSWORD" | docker login --username=$DOCKER_HUB_USERNAME --password-stdin && docker build -t $DOCKER_CODEGEN_CLI_IMAGE_NAME ./modules/openapi-generator-cli && if [ ! -z "$TRAVIS_TAG" ]; then docker tag $DOCKER_CODEGEN_CLI_IMAGE_NAME:latest $DOCKER_CODEGEN_CLI_IMAGE_NAME:$TRAVIS_TAG; fi && if [ ! -z "$TRAVIS_TAG" ] || [ "$TRAVIS_BRANCH" = "master" ]; then docker push $DOCKER_CODEGEN_CLI_IMAGE_NAME && echo "Pushed to $DOCKER_CODEGEN_CLI_IMAGE_NAME"; fi; fi
env:
- - DOCKER_GENERATOR_IMAGE_NAME=openapitools/openapi-generator-online DOCKER_CODEGEN_CLI_IMAGE_NAME=openapitools/openapi-generator-cli NODE_ENV=test
+ - DOCKER_GENERATOR_IMAGE_NAME=openapitools/openapi-generator-online DOCKER_CODEGEN_CLI_IMAGE_NAME=openapitools/openapi-generator-cli NODE_ENV=test CC=gcc-5 CXX=g++-5
diff --git a/CI/circle_parallel.sh b/CI/circle_parallel.sh
new file mode 100755
index 000000000000..3487a09bf6ef
--- /dev/null
+++ b/CI/circle_parallel.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+NODE_INDEX=${CIRCLE_NODE_INDEX:-0}
+
+
+if [ "$NODE_INDEX" = "1" ]; then
+ echo "Running node $NODE_INDEX to test CI/pom.xml.circleci ..."
+ cp CI/pom.xml.circleci pom.xml
+ java -version
+ mvn --quiet verify -Psamples
+else
+ echo "Running node $NODE_INDEX to test CI/pom.xml.circleci.java7 ..."
+ sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
+ java -version
+ cp CI/pom.xml.circleci.java7 pom.xml
+ mvn --quiet verify -Psamples
+fi
+
+
diff --git a/CI/pom.xml.circleci b/CI/pom.xml.circleci
index b352263ff60d..20a1e5c6a7fc 100644
--- a/CI/pom.xml.circleci
+++ b/CI/pom.xml.circleci
@@ -844,10 +844,12 @@
samples/client/petstore/java/feignsamples/client/petstore/java/jersey1samples/client/petstore/java/jersey2
+ samples/client/petstore/java/jersey2-java8samples/client/petstore/java/okhttp-gsonsamples/client/petstore/java/retrofitsamples/client/petstore/java/retrofit2samples/client/petstore/java/retrofit2rx
+ samples/client/petstore/java/retrofit2-play25samples/client/petstore/jaxrs-cxf-clientsamples/client/petstore/java/resttemplatesamples/client/petstore/java/resttemplate-withXml
diff --git a/CI/pom.xml.circleci.java7 b/CI/pom.xml.circleci.java7
index 4062ca0a4a77..d7b6e7122bda 100644
--- a/CI/pom.xml.circleci.java7
+++ b/CI/pom.xml.circleci.java7
@@ -852,9 +852,6 @@
samples/client/petstore/java/resteasysamples/client/petstore/java/google-api-clientsamples/client/petstore/kotlin/
-
-
- samples/client/petstore/typescript-angular-v6-provided-in-rootsamples/server/petstore/java-vertx/rxsamples/server/petstore/java-vertx/async
diff --git a/README.md b/README.md
index 000066043b1c..6ad8180bc080 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,8 @@
[](https://gitter.im/OpenAPITools/openapi-generator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+[](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.openapitools%22%20AND%20a%3A%22openapi-generator%22)
+[](https://twitter.com/oas_generator)
@@ -430,6 +432,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
- 2018/06/08 - [Swagger Codegen is now OpenAPI Generator](https://angular.schule/blog/2018-06-swagger-codegen-is-now-openapi-generator) by [JohannesHoppe](https://github.com/JohannesHoppe)
- 2018/06/21 - [Connect your JHipster apps to the world of APIs with OpenAPI and gRPC](https://fr.slideshare.net/chbornet/jhipster-conf-2018-connect-your-jhipster-apps-to-the-world-of-apis-with-openapi-and-grpc) by [Christophe Bornet](https://github.com/cbornet) at [JHipster Conf 2018](https://jhipster-conf.github.io/)
- 2018/06/27 - [Lessons Learned from Leading an Open-Source Project Supporting 30+ Programming Languages](https://speakerdeck.com/wing328/lessons-learned-from-leading-an-open-source-project-supporting-30-plus-programming-languages) - [William Cheng](https://github.com/wing328) at [LinuxCon + ContainerCon + CloudOpen China 2018](https://www.lfasiallc.com/events/lc3-2018/)
+- 2018/07/19 - [OpenAPI Generator Contribution Quickstart - RingCentral Go SDK](https://medium.com/ringcentral-developers/openapi-generator-for-go-contribution-quickstart-8cc72bf37b53) by [John Wang](https://github.com/grokify)
## [6 - About Us](#table-of-contents)
diff --git a/bin/cpp-pistache-server-petstore.sh b/bin/cpp-pistache-server-petstore.sh
index c205a732358a..0aa9488b35b4 100755
--- a/bin/cpp-pistache-server-petstore.sh
+++ b/bin/cpp-pistache-server-petstore.sh
@@ -27,6 +27,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
-ags="generate -g cpp-pistache-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/cpp-pistache $@"
+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 --additional-properties addExternalLibs=true -o samples/server/petstore/cpp-pistache $@"
java $JAVA_OPTS -jar $executable $ags
diff --git a/bin/openapi3/cpp-pistache-server-petstore.sh b/bin/openapi3/cpp-pistache-server-petstore.sh
index 5f7dd337691f..e2240ea20473 100755
--- a/bin/openapi3/cpp-pistache-server-petstore.sh
+++ b/bin/openapi3/cpp-pistache-server-petstore.sh
@@ -27,6 +27,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
-ags="generate -g cpp-pistache-server -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o samples/server/petstore/cpp-pistache $@"
+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 $@"
java $JAVA_OPTS -jar $executable $ags
diff --git a/circle.yml b/circle.yml
index 844fa6a27107..bfbe40bceddb 100644
--- a/circle.yml
+++ b/circle.yml
@@ -1,10 +1,16 @@
version: 2
jobs:
build:
+ # docker:
+ # #- image: openapitools/openapi-generator
+ # - image: swaggerapi/petstore
+ # environment:
+ # SWAGGER_HOST=http://petstore.swagger.io
+ # SWAGGER_BASE_PATH=/v2
machine:
docker_layer_caching: true
working_directory: ~/OpenAPITools/openapi-generator
- parallelism: 1
+ parallelism: 2
shell: /bin/bash --login
environment:
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
@@ -37,12 +43,6 @@ jobs:
printf '127.0.0.1 petstore.swagger.io
' | sudo tee -a /etc/hosts
# Dependencies
- # This would typically go in either a build or a build-and-test job when using workflows
- # This is based on your 1.0 configuration file or project settings
- - run: sudo add-apt-repository ppa:duggan/bats --yes
- - run: sudo apt-get update -qq
- - run: sudo apt-get install -qq bats
- - run: sudo apt-get install -qq curl
# Install latest stable node for angular 6
- run:
name: Install node@stable (for angular 6)
@@ -65,21 +65,9 @@ jobs:
- run: docker ps -a
- run: sleep 30
- run: cat /etc/hosts
- # This is based on your 1.0 configuration file or project settings
- - run: cp CI/pom.xml.circleci pom.xml
# Test
- # This would typically be a build job when using workflows, possibly combined with build
- # This is based on your 1.0 configuration file or project settings
- #- run: java -version
- run: mvn --quiet clean install
- - run: mvn --quiet verify -Psamples
- - run: if [ $? -ne 0 ]; then exit 1; fi
- - run: sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
- - run: java -version
- - run: cp CI/pom.xml.circleci.java7 pom.xml
- - run: mvn --quiet clean install
- - run: mvn --quiet verify -Psamples
- - run: if [ $? -ne 0 ]; then exit 1; fi
+ - run: ./CI/circle_parallel.sh
# Save dependency cache
- save_cache:
key: source-v1-{{ .Branch }}-{{ .Revision }}
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 bd3f11c0eaf1..e91d00d4ce33 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
@@ -230,6 +230,10 @@ public interface CodegenConfig {
String getHttpUserAgent();
+ void setDocExtension(String docExtension);
+
+ String getDocExtension();
+
String getCommonTemplateDir();
void setIgnoreFilePathOverride(String ignoreFileOverride);
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java
index 34676479f3da..4be60e75a51a 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java
@@ -254,4 +254,7 @@ public class CodegenConstants {
public static final String STRIP_PACKAGE_NAME = "stripPackageName";
public static final String STRIP_PACKAGE_NAME_DESC = "Whether to strip leading dot-separated packages from generated model classes";
+
+ public static final String DOCEXTENSION = "docExtension";
+ public static final String DOCEXTENSION_DESC = "The extension of the generated documentation files, defaults to markdown, .md";
}
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 08ae8593db8b..5806a0fd6c63 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
@@ -121,6 +121,8 @@ public class DefaultCodegen implements CodegenConfig {
// When a model is an alias for a simple type
protected Map typeAliases = null;
protected Boolean prependFormOrBodyParameters = false;
+ // The extension of the generated documentation files (defaults to markdown .md)
+ protected String docExtension;
protected String ignoreFilePathOverride;
@@ -179,6 +181,11 @@ public class DefaultCodegen implements CodegenConfig {
this.setRemoveOperationIdPrefix(Boolean.valueOf(additionalProperties
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
}
+
+ if (additionalProperties.containsKey(CodegenConstants.DOCEXTENSION)){
+ this.setDocExtension(String.valueOf(additionalProperties
+ .get(CodegenConstants.DOCEXTENSION).toString()));
+ }
}
// override with any special post-processing for all models
@@ -3454,7 +3461,8 @@ public class DefaultCodegen implements CodegenConfig {
* @return the API documentation file name with full path
*/
public String apiDocFilename(String templateName, String tag) {
- String suffix = apiDocTemplateFiles().get(templateName);
+ String docExtension = getDocExtension();
+ String suffix = docExtension != null ? docExtension: apiDocTemplateFiles().get(templateName);
return apiDocFileFolder() + File.separator + toApiDocFilename(tag) + suffix;
}
@@ -3591,6 +3599,25 @@ public class DefaultCodegen implements CodegenConfig {
return releaseNote;
}
+ /**
+ * Documentation files extension
+ *
+ * @return Documentation files extension
+ */
+ public String getDocExtension() {
+ return docExtension;
+ }
+
+ /**
+ * Set Documentation files extension
+ *
+ * @param userDocExtension documentation files extension
+ */
+ public void setDocExtension(String userDocExtension) {
+ this.docExtension = userDocExtension;
+ }
+
+
/**
* Set HTTP user agent.
*
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 4ddf0d866495..056f56307bf3 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
@@ -278,7 +278,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
private void generateModelDocumentation(List files, Map models, String modelName) throws IOException {
for (String templateName : config.modelDocTemplateFiles().keySet()) {
- String suffix = config.modelDocTemplateFiles().get(templateName);
+ String docExtension = config.getDocExtension();
+ String suffix = docExtension!=null ? docExtension : config.modelDocTemplateFiles().get(templateName);
String filename = config.modelDocFileFolder() + File.separator + config.toModelDocFilename(modelName) + suffix;
if (!config.shouldOverwrite(filename)) {
LOGGER.info("Skipped overwriting " + filename);
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java
index 30472ba30bb9..8bce5a3cd1eb 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java
@@ -191,7 +191,13 @@ public class ExampleGenerator {
Schema innerType = ((ArraySchema) property).getItems();
if (innerType != null) {
int arrayLength = null == ((ArraySchema) property).getMaxItems() ? 2 : ((ArraySchema) property).getMaxItems();
- if (arrayLength > 1024) {
+ if (arrayLength == Integer.MAX_VALUE) {
+ // swagger-jersey2-jaxrs generated spec may contain maxItem = 2147483647
+ // semantically this means there is no upper limit
+ // treating this as if the property was not present at all
+ LOGGER.warn("The max items allowed in property {} of {} equals Integer.MAX_VALUE. Treating this as if no max items has been specified.", property, arrayLength);
+ arrayLength = 2;
+ } else if (arrayLength > 1024) {
LOGGER.warn("The max items allowed in property {} is too large ({} items), restricting it to 1024 items", property, arrayLength);
arrayLength = 1024;
}
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java
index a782f23f42da..83afd83730cb 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java
@@ -228,10 +228,10 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
// make api and model src path available in mustache template
- additionalProperties.put("apiSrcPath", "." + File.separator + toSrcPath(apiPackage, srcBasePath));
- additionalProperties.put("modelSrcPath", "." + File.separator + toSrcPath(modelPackage, srcBasePath));
- additionalProperties.put("apiTestPath", "." + File.separator + testBasePath + File.separator + apiDirName);
- additionalProperties.put("modelTestPath", "." + File.separator + testBasePath + File.separator + modelDirName);
+ additionalProperties.put("apiSrcPath", "./" + toSrcPath(apiPackage, srcBasePath));
+ additionalProperties.put("modelSrcPath", "./" + toSrcPath(modelPackage, srcBasePath));
+ additionalProperties.put("apiTestPath", "./" + testBasePath + "/" + apiDirName);
+ additionalProperties.put("modelTestPath", "./" + testBasePath + "/" + modelDirName);
// make api and model doc path available in mustache template
additionalProperties.put("apiDocPath", apiDocPath);
@@ -255,7 +255,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
public String toSrcPath(String packageName, String basePath) {
packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
if (basePath != null && basePath.length() > 0) {
- basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
+ basePath = basePath.replaceAll("[\\\\/]?$", "") + '/'; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
}
String regFirstPathSeparator;
@@ -274,7 +274,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
return (basePath
// Replace period, backslash, forward slash with file separator in package name
- + packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
+ + packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement("/"))
// Trim prefix file separators from package path
.replaceAll(regFirstPathSeparator, ""))
// Trim trailing file separators from the overall path
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java
index be50b3356a7a..69832171cb20 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java
@@ -43,7 +43,9 @@ import java.util.Set;
public class CppPistacheServerCodegen extends AbstractCppCodegen {
protected String implFolder = "impl";
-
+ protected boolean isAddExternalLibs = false;
+ public static final String OPTIONAL_EXTERNAL_LIB = "addExternalLibs";
+ public static final String OPTIONAL_EXTERNAL_LIB_DESC = "Add the Possibility to fetch and compile external Libraries needed by this Framework.";
@Override
public CodegenType getTag() {
return CodegenType.SERVER;
@@ -77,6 +79,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
embeddedTemplateDir = templateDir = "cpp-pistache-server";
cliOptions.clear();
+ addSwitch(OPTIONAL_EXTERNAL_LIB, OPTIONAL_EXTERNAL_LIB_DESC, this.isAddExternalLibs);
reservedWords = new HashSet<>();
@@ -102,6 +105,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
typeMapping.put("binary", "std::string");
typeMapping.put("number", "double");
typeMapping.put("UUID", "std::string");
+ typeMapping.put("ByteArray", "std::string");
super.importMapping = new HashMap();
importMapping.put("std::vector", "#include ");
@@ -117,7 +121,12 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
additionalProperties.put("modelNamespaceDeclarations", modelPackage.split("\\."));
additionalProperties.put("modelNamespace", modelPackage.replaceAll("\\.", "::"));
additionalProperties.put("apiNamespaceDeclarations", apiPackage.split("\\."));
- additionalProperties.put("apiNamespace", apiPackage.replaceAll("\\.", "::"));
+ additionalProperties.put("apiNamespace", apiPackage.replaceAll("\\.", "::"));
+ if (additionalProperties.containsKey(OPTIONAL_EXTERNAL_LIB)) {
+ setAddExternalLibs(convertPropertyToBooleanAndWriteBack(OPTIONAL_EXTERNAL_LIB));
+ } else {
+ additionalProperties.put(OPTIONAL_EXTERNAL_LIB, isAddExternalLibs);
+ }
}
/**
@@ -292,6 +301,9 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
Schema inner = (Schema) p.getAdditionalProperties();
return getSchemaType(p) + "";
}
+ else if (ModelUtils.isByteArraySchema(p)) {
+ return "std::string";
+ }
if (ModelUtils.isStringSchema(p)
|| ModelUtils.isDateSchema(p)
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
@@ -320,6 +332,9 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
return "0L";
}
return "0";
+ }
+ else if (ModelUtils.isByteArraySchema(p)) {
+ return "";
} else if (ModelUtils.isMapSchema(p)) {
String inner = getSchemaType((Schema) p.getAdditionalProperties());
return "std::map()";
@@ -403,4 +418,17 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
public String escapeUnsafeCharacters(String input) {
return input.replace("*/", "*_/").replace("/*", "/_*");
}
+
+ @Override
+ public String getTypeDeclaration(String str) {
+ return toModelName(str);
+ }
+
+ /**
+ * Specify whether external libraries will be added during the generation
+ * @param value the value to be set
+ */
+ public void setAddExternalLibs(boolean value){
+ isAddExternalLibs = value;
+ }
}
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 4212923bc4d2..0f6872b162eb 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
@@ -153,6 +153,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
typeMapping.put("binary", "std::string");
typeMapping.put("number", "double");
typeMapping.put("UUID", "utility::string_t");
+ typeMapping.put("ByteArray", "utility::string_t");
super.importMapping = new HashMap();
importMapping.put("std::vector", "#include ");
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java
index 7c21c824df61..a39033a4501b 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java
@@ -164,8 +164,8 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("date", "chrono::DateTime");
typeMapping.put("DateTime", "chrono::DateTime");
typeMapping.put("password", "String");
- typeMapping.put("File", "Box, Error=Error> + Send>");
- typeMapping.put("file", "Box, Error=Error> + Send>");
+ typeMapping.put("File", "swagger::ByteArray");
+ typeMapping.put("file", "swagger::ByteArray");
typeMapping.put("array", "Vec");
typeMapping.put("map", "HashMap");
@@ -710,8 +710,6 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
}
header.nameInCamelCase = toModelName(header.baseName);
}
-
- additionalProperties.put("apiHasFile", true);
}
return objs;
@@ -1069,22 +1067,11 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
private void processParam(CodegenParameter param, CodegenOperation op) {
String example = null;
- if (param.isFile) {
- param.vendorExtensions.put("formatString", "{:?}");
- op.vendorExtensions.put("hasFile", true);
- additionalProperties.put("apiHasFile", true);
- example = "Box::new(stream::once(Ok(b\"hello\".to_vec()))) as Box + Send>";
- } else if (param.isString) {
- if (param.dataFormat != null && param.dataFormat.equals("byte")) {
- param.vendorExtensions.put("formatString", "\\\"{:?}\\\"");
- example = "swagger::ByteArray(\"" + ((param.example != null) ? param.example : "") + "\".to_string().into_bytes())";
- } else {
- param.vendorExtensions.put("formatString", "\\\"{}\\\"");
- example = "\"" + ((param.example != null) ? param.example : "") + "\".to_string()";
- }
+ if (param.isString) {
+ param.vendorExtensions.put("formatString", "\\\"{}\\\"");
+ example = "\"" + ((param.example != null) ? param.example : "") + "\".to_string()";
} else if (param.isPrimitiveType) {
- if ((param.isByteArray) ||
- (param.isBinary)) {
+ if ((param.isByteArray) || (param.isBinary)) {
// Binary primitive types don't implement `Display`.
param.vendorExtensions.put("formatString", "{:?}");
example = "swagger::ByteArray(Vec::from(\"" + ((param.example != null) ? param.example : "") + "\"))";
@@ -1119,12 +1106,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
} else {
// Not required, so override the format string and example
param.vendorExtensions.put("formatString", "{:?}");
- if (param.isFile) {
- // Optional file types are wrapped in a future
- param.vendorExtensions.put("example", (example != null) ? "Box::new(future::ok(Some(" + example + "))) as Box + Send>" : "None");
- } else {
- param.vendorExtensions.put("example", (example != null) ? "Some(" + example + ")" : "None");
- }
+ param.vendorExtensions.put("example", (example != null) ? "Some(" + example + ")" : "None");
}
}
}
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java
index 4fa6ffd9c6ad..91aba80d82c9 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java
@@ -19,6 +19,8 @@ package org.openapitools.codegen.utils;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.servers.Server;
+import io.swagger.v3.oas.models.servers.ServerVariable;
+import io.swagger.v3.oas.models.servers.ServerVariables;
import org.openapitools.codegen.CodegenConfig;
import org.slf4j.Logger;
@@ -26,12 +28,17 @@ import org.slf4j.LoggerFactory;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class URLPathUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(URLPathUtils.class);
public static final String LOCAL_HOST = "http://localhost";
+ public static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{([^\\}]+)\\}");
public static URL getServerURL(OpenAPI openAPI) {
final List servers = openAPI.getServers();
@@ -40,8 +47,40 @@ public class URLPathUtils {
return getDefaultUrl();
}
// TODO need a way to obtain all server URLs
- final Server server = servers.get(0);
- String url = sanitizeUrl(server.getUrl());
+ return getServerURL(servers.get(0));
+ }
+
+ static URL getServerURL(final Server server) {
+ String url = server.getUrl();
+ ServerVariables variables = server.getVariables();
+ if(variables == null) {
+ variables = new ServerVariables();
+ }
+ Set replacedVariables = new HashSet<>();
+ Matcher matcher = VARIABLE_PATTERN.matcher(url);
+ while(matcher.find()) {
+ if(!replacedVariables.contains(matcher.group())) {
+ ServerVariable variable = variables.get(matcher.group(1));
+ String replacement;
+ if(variable != null) {
+ if(variable.getDefault() != null) {
+ replacement = variable.getDefault();
+ } else if(variable.getEnum() != null && !variable.getEnum().isEmpty()) {
+ replacement = variable.getEnum().get(0);
+ } else {
+ LOGGER.warn("No value found for variable '{}' in server definition '{}', default to empty string.", matcher.group(1), server.getUrl());
+ replacement = "";
+ }
+ } else {
+ LOGGER.warn("No variable '{}' found in server definition '{}', default to empty string.", matcher.group(1), server.getUrl());
+ replacement = "";
+ }
+ url = url.replace(matcher.group(), replacement);
+ replacedVariables.add(matcher.group());
+ matcher = VARIABLE_PATTERN.matcher(url);
+ }
+ }
+ url = sanitizeUrl(url);
try {
return new URL(url);
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/api.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/api.mustache
index a906a80e7a83..f48180f4381e 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/api.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/api.mustache
@@ -61,7 +61,7 @@ public class {{classname}} {
{{/externalDocs}}
*/
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws RestClientException {
- Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}new Object(){{/bodyParam}};
+ Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) {
diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache
index d815ce10ab7d..b9e97395e41a 100644
--- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache
+++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache
@@ -52,8 +52,8 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
{{/hasPathParams}}{{#hasBodyParam}}
// Getting the body param
{{#bodyParam}}
- {{^isPrimitiveType}}
- {{baseType}} {{paramName}};{{/isPrimitiveType}}
+ {{^isPrimitiveType}}{{^isContainer}}
+ {{baseType}} {{paramName}};{{/isContainer}}{{#isListContainer}}std::vector<{{items.baseType}}> {{paramName}};{{/isListContainer}}{{#isMapContainer}}std::map {{paramName}};{{/isMapContainer}}{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{dataType}} {{paramName}};
{{/isPrimitiveType}}
@@ -74,9 +74,9 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
{{#hasBodyParam}}
{{#bodyParam}}
nlohmann::json request_body = nlohmann::json::parse(request.body());
- {{^isPrimitiveType}}
+ {{^isPrimitiveType}}{{^isContainer}}
{{paramName}}.fromJson(request_body);
- {{/isPrimitiveType}}
+ {{/isContainer}}{{/isPrimitiveType}}{{#isContainer}} {{paramName}} = {{#isListContainer}} ModelArrayHelper{{/isListContainer}}{{#isMapContainer}} ModelMapHelper{{/isMapContainer}}::fromJson<{{items.baseType}}>(request_body);{{/isContainer}}
{{#isPrimitiveType}}
// The conversion is done automatically by the json library
{{paramName}} = request_body;
diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/cmake.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/cmake.mustache
index 12b066f22b71..bec552992418 100644
--- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/cmake.mustache
+++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/cmake.mustache
@@ -2,7 +2,27 @@ cmake_minimum_required (VERSION 3.2)
project(server)
-set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++11)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pg -g3" )
+
+{{#addExternalLibs}}
+include(ExternalProject)
+
+set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
+
+ExternalProject_Add(PISTACHE
+ GIT_REPOSITORY https://github.com/oktal/pistache.git
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
+)
+
+ExternalProject_Add(NLOHMANN
+ GIT_REPOSITORY https://github.com/nlohmann/json.git
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
+
+)
+include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
+include_directories(${EXTERNAL_INSTALL_LOCATION}/include/nlohmann)
+link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
+{{/addExternalLibs}}
link_directories(/usr/local/lib/)
diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache
index b2434df4670c..7a36c378903a 100644
--- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache
+++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache
@@ -79,11 +79,11 @@ void {{classname}}::fromJson(nlohmann::json& val)
{{/items.isDateTime}}{{^items.isDateTime}}
if(item.is_null())
{
- m_{{name}}.push_back( {{{items.datatype}}}(nullptr) );
+ m_{{name}}.push_back( {{{items.datatype}}}() );
}
else
{
- {{{items.datatype}}} newItem({{{items.defaultValue}}});
+ {{{items.datatype}}} newItem;
newItem.fromJson(item);
m_{{name}}.push_back( newItem );
}
@@ -95,15 +95,15 @@ void {{classname}}::fromJson(nlohmann::json& val)
}
{{/isListContainer}}{{^isListContainer}}{{^isPrimitiveType}}{{^required}}if(val.find("{{baseName}}") != val.end())
{
- {{#isString}}{{setter}}(val.at("{{baseName}}"));
- {{/isString}}{{^isString}}{{#isDateTime}}{{setter}}(val.at("{{baseName}}"));
- {{/isDateTime}}{{^isDateTime}}if(!val["{{baseName}}"].is_null())
+ {{#isString}}{{setter}}(val.at("{{baseName}}"));{{/isString}}{{#isByteArray}}{{setter}}(val.at("{{baseName}}"));
+ {{/isByteArray}}{{^isString}}{{#isDateTime}}{{setter}}(val.at("{{baseName}}"));
+ {{/isDateTime}}{{^isDateTime}}{{^isByteArray}}if(!val["{{baseName}}"].is_null())
{
- {{{dataType}}} newItem({{{defaultValue}}});
+ {{{dataType}}} newItem;
newItem.fromJson(val["{{baseName}}"]);
{{setter}}( newItem );
}
- {{/isDateTime}}{{/isString}}
+ {{/isByteArray}}{{/isDateTime}}{{/isString}}
}
{{/required}}{{#required}}{{#isString}}{{setter}}(val.at("{{baseName}}"));
{{/isString}}{{^isString}}{{#isDateTime}}{{setter}}(val.at("{{baseName}}"));
diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/modelbase-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/modelbase-header.mustache
index 2e43bb7b8534..1cb28f0d988f 100644
--- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/modelbase-header.mustache
+++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/modelbase-header.mustache
@@ -12,6 +12,8 @@
#include "json.hpp"
#include
#include
+#include
+#include