forked from loafle/openapi-generator-original
Compare commits
101 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f329872ce7 | ||
|
|
05db32fea2 | ||
|
|
c116c8fb9b | ||
|
|
1ab4fe43b5 | ||
|
|
f6c21057e1 | ||
|
|
c9085b4f2b | ||
|
|
f6146b212f | ||
|
|
2b429ee43b | ||
|
|
a258cf3fc6 | ||
|
|
07a5715b9f | ||
|
|
f32398a708 | ||
|
|
f0425d77ef | ||
|
|
e0020b41da | ||
|
|
375c26ccb3 | ||
|
|
40024ac72a | ||
|
|
ab08dd1d26 | ||
|
|
21141f682f | ||
|
|
d8ea28e147 | ||
|
|
82156b6639 | ||
|
|
3085bf1df5 | ||
|
|
58e0946b1e | ||
|
|
f793ac25c7 | ||
|
|
d1fc923b66 | ||
|
|
f1897c4462 | ||
|
|
d8ec6b2003 | ||
|
|
824654964b | ||
|
|
0c52fcd5ff | ||
|
|
926b971497 | ||
|
|
1e95d36809 | ||
|
|
a3e5185e39 | ||
|
|
1cbfca4887 | ||
|
|
b0909ade6f | ||
|
|
036fa6918c | ||
|
|
b587052de4 | ||
|
|
cb9a734ebb | ||
|
|
01dbb8b693 | ||
|
|
68d80ab67d | ||
|
|
14ab3d763e | ||
|
|
3c3ac0a071 | ||
|
|
0b88889cdf | ||
|
|
b33f1f945b | ||
|
|
c7953ac137 | ||
|
|
534b6b5978 | ||
|
|
b6fc29050d | ||
|
|
7e494e52ab | ||
|
|
7624a1ff85 | ||
|
|
1d72edddf6 | ||
|
|
c9b934147a | ||
|
|
65bad61abb | ||
|
|
77df3d6770 | ||
|
|
a8e8acead7 | ||
|
|
44d419c1a1 | ||
|
|
60c81eae0a | ||
|
|
00246f3ea0 | ||
|
|
6f19fa7e91 | ||
|
|
70cdd27e75 | ||
|
|
c6004a8f89 | ||
|
|
85f0909c7f | ||
|
|
37be47fc56 | ||
|
|
86d7009f4c | ||
|
|
530065137d | ||
|
|
59d38d7dd2 | ||
|
|
59bd3b6dcb | ||
|
|
27a356dacf | ||
|
|
2e1add83e7 | ||
|
|
2e6bec7345 | ||
|
|
667e3130fe | ||
|
|
a9961a062a | ||
|
|
af3ca293e4 | ||
|
|
d42ff75ceb | ||
|
|
4156bb9f01 | ||
|
|
5328f103da | ||
|
|
1dee3e227c | ||
|
|
0da55081c9 | ||
|
|
af9d57e4b9 | ||
|
|
8867d2b34c | ||
|
|
eeda132e73 | ||
|
|
97d6b71460 | ||
|
|
1b2d12286f | ||
|
|
c70ed678f6 | ||
|
|
ab9be95442 | ||
|
|
71ef6a0a2b | ||
|
|
888da52181 | ||
|
|
bd33a333af | ||
|
|
f7617bc628 | ||
|
|
c5e170961f | ||
|
|
e02e875978 | ||
|
|
52cd17ecc7 | ||
|
|
76160b53c7 | ||
|
|
80cf1324c5 | ||
|
|
0f0d8a01cb | ||
|
|
995edc0b75 | ||
|
|
5344a02bbc | ||
|
|
45ed374b62 | ||
|
|
1e596496a5 | ||
|
|
baaa335664 | ||
|
|
0a52f56ba4 | ||
|
|
478d6ced4e | ||
|
|
0cc60d39d2 | ||
|
|
8f6bb8d9ec | ||
|
|
23c04e2e66 |
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -2,7 +2,7 @@
|
||||
|
||||
- [ ] Read the [contribution guidelines](https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md).
|
||||
- [ ] Ran the shell script under `./bin/` to update Petstore sample so that CIs can verify the change. (For instance, only need to run `./bin/{LANG}-petstore.sh` and `./bin/security/{LANG}-petstore.sh` if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in `.\bin\windows\`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`, `3.1.x`, `4.0.x`. Default: `master`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`, `4.0.x`. Default: `master`.
|
||||
- [ ] Copied the [technical committee](https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee) to review the pull request if your PR is targeting a particular programming language.
|
||||
|
||||
### Description of the PR
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -99,6 +99,8 @@ samples/client/petstore/silex/SwaggerServer/venodr/
|
||||
samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/cache/
|
||||
samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/logs/
|
||||
|
||||
#PHP-laravel
|
||||
samples/server/petstore/php-laravel/node_modules
|
||||
|
||||
# Perl
|
||||
samples/client/petstore/perl/deep_module_test/
|
||||
|
||||
19
.travis.yml
19
.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
|
||||
@@ -114,7 +123,7 @@ after_success:
|
||||
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" uploadArchives --no-daemon;
|
||||
echo "Finished ./gradlew uploadArchives";
|
||||
popd;
|
||||
elif ([ "$TRAVIS_BRANCH" == "3.1.x" ] || [ "$TRAVIS_BRANCH" == "4.0.x" ]) ; then
|
||||
elif ([ "$TRAVIS_BRANCH" == "4.0.x" ]) ; then
|
||||
mvn clean deploy --settings CI/settings.xml;
|
||||
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
|
||||
pushd .;
|
||||
@@ -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
|
||||
|
||||
19
CI/circle_parallel.sh
Executable file
19
CI/circle_parallel.sh
Executable file
@@ -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
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.1.1</version>
|
||||
<version>3.2.0</version>
|
||||
<url>https://github.com/openapi-tools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapi-tools/openapi-generator.git</connection>
|
||||
@@ -920,7 +920,7 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-parser-version>2.0.1</swagger-parser-version>
|
||||
<swagger-parser-version>2.0.2-OpenAPITools.org-1</swagger-parser-version>
|
||||
<swagger-core-version>2.0.1</swagger-core-version>
|
||||
<scala-version>2.11.1</scala-version>
|
||||
<felix-version>3.3.0</felix-version>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.1.1</version>
|
||||
<version>3.2.0</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -844,10 +844,12 @@
|
||||
<module>samples/client/petstore/java/feign</module>
|
||||
<module>samples/client/petstore/java/jersey1</module>
|
||||
<module>samples/client/petstore/java/jersey2</module>
|
||||
<module>samples/client/petstore/java/jersey2-java8</module>
|
||||
<module>samples/client/petstore/java/okhttp-gson</module>
|
||||
<module>samples/client/petstore/java/retrofit</module>
|
||||
<module>samples/client/petstore/java/retrofit2</module>
|
||||
<module>samples/client/petstore/java/retrofit2rx</module>
|
||||
<module>samples/client/petstore/java/retrofit2-play25</module>
|
||||
<module>samples/client/petstore/jaxrs-cxf-client</module>
|
||||
<module>samples/client/petstore/java/resttemplate</module>
|
||||
<module>samples/client/petstore/java/resttemplate-withXml</module>
|
||||
@@ -974,7 +976,7 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-parser-version>2.0.1</swagger-parser-version>
|
||||
<swagger-parser-version>2.0.2-OpenAPITools.org-1</swagger-parser-version>
|
||||
<swagger-core-version>2.0.1</swagger-core-version>
|
||||
<scala-version>2.11.1</scala-version>
|
||||
<felix-version>3.3.0</felix-version>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.1.1</version>
|
||||
<version>3.2.0</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -852,9 +852,6 @@
|
||||
<module>samples/client/petstore/java/resteasy</module>
|
||||
<module>samples/client/petstore/java/google-api-client</module>
|
||||
<module>samples/client/petstore/kotlin/</module>
|
||||
<!-- test non-java projects -->
|
||||
<!--<module>samples/client/petstore/go</module>-->
|
||||
<module>samples/client/petstore/typescript-angular-v6-provided-in-root</module>
|
||||
<!-- servers -->
|
||||
<module>samples/server/petstore/java-vertx/rx</module>
|
||||
<module>samples/server/petstore/java-vertx/async</module>
|
||||
@@ -951,7 +948,7 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-parser-version>2.0.1</swagger-parser-version>
|
||||
<swagger-parser-version>2.0.2-OpenAPITools.org-1</swagger-parser-version>
|
||||
<swagger-core-version>2.0.1</swagger-core-version>
|
||||
<scala-version>2.11.1</scala-version>
|
||||
<felix-version>3.3.0</felix-version>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.1.1</version>
|
||||
<version>3.2.0</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -928,7 +928,7 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-parser-version>2.0.1</swagger-parser-version>
|
||||
<swagger-parser-version>2.0.2-OpenAPITools.org-1</swagger-parser-version>
|
||||
<swagger-core-version>2.0.1</swagger-core-version>
|
||||
<scala-version>2.11.1</scala-version>
|
||||
<felix-version>3.3.0</felix-version>
|
||||
|
||||
@@ -14,8 +14,9 @@ COPY ./LICENSE ${GEN_DIR}
|
||||
COPY ./google_checkstyle.xml ${GEN_DIR}
|
||||
|
||||
# Modules are copied individually here to allow for caching of docker layers between major.minor versions
|
||||
# NOTE: openapi-generator-online is not included here
|
||||
COPY ./modules/openapi-generator-gradle-plugin ${GEN_DIR}/modules/openapi-generator-gradle-plugin
|
||||
COPY ./modules/openapi-generator-maven-plugin ${GEN_DIR}/modules/openapi-generator-maven-plugin
|
||||
COPY ./modules/openapi-generator-online ${GEN_DIR}/modules/openapi-generator-online
|
||||
COPY ./modules/openapi-generator-cli ${GEN_DIR}/modules/openapi-generator-cli
|
||||
COPY ./modules/openapi-generator ${GEN_DIR}/modules/openapi-generator
|
||||
COPY ./pom.xml ${GEN_DIR}
|
||||
|
||||
81
README.md
81
README.md
@@ -2,16 +2,11 @@
|
||||
|
||||
<div align="center">
|
||||
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`3.1.1`): [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`3.2.1`): [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
|
||||
|
||||
[`3.2.x`](https://github.com/OpenAPITools/openapi-generator/tree/3.2.x) branch: [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
|
||||
|
||||
[`4.0.x`](https://github.com/OpenAPITools/openapi-generator/tree/4.0.x) branch: [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
@@ -21,6 +16,8 @@
|
||||
<div align="center">
|
||||
|
||||
[](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)
|
||||
|
||||
</div>
|
||||
|
||||
@@ -86,8 +83,8 @@ The OpenAPI Specification has undergone 3 revisions since initial creation in 20
|
||||
OpenAPI Generator Version | Release Date | OpenAPI Spec compatibility | Notes
|
||||
---------------------------- | ------------ | -------------------------- | -----
|
||||
4.0.0 (upcoming major release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Major release with breaking changes (no fallback)
|
||||
3.2.0 (upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.2.0-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release with breaking changes (with fallbacks)
|
||||
3.1.2-SNAPSHOT (current master, upcoming patch release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.1.2-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
|
||||
3.2.1 (current master, upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.2.1-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release with breaking changes (with fallbacks)
|
||||
[3.1.2](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.1.2) | 25.07.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
|
||||
[3.1.1](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.1.1) | 18.07.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
|
||||
[3.1.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.1.0) | 06.07.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release with breaking changes (with fallbacks)
|
||||
[3.0.3](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.3) | 27.06.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
|
||||
@@ -145,16 +142,16 @@ See the different versions of the [openapi-generator-cli](https://mvnrepository.
|
||||
|
||||
If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum):
|
||||
|
||||
JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.1/openapi-generator-cli-3.1.1.jar`
|
||||
JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.2/openapi-generator-cli-3.1.2.jar`
|
||||
|
||||
For **Mac/Linux** users:
|
||||
```sh
|
||||
wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.1/openapi-generator-cli-3.1.1.jar -O openapi-generator-cli.jar
|
||||
wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.2/openapi-generator-cli-3.1.2.jar -O openapi-generator-cli.jar
|
||||
```
|
||||
|
||||
For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.
|
||||
```
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.1/openapi-generator-cli-3.1.1.jar
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.2/openapi-generator-cli-3.1.2.jar
|
||||
```
|
||||
|
||||
After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage.
|
||||
@@ -165,6 +162,49 @@ export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
|
||||
export PATH=${JAVA_HOME}/bin:$PATH
|
||||
```
|
||||
|
||||
### Launcher Script
|
||||
|
||||
One downside to manual jar downloads is that you don't keep up-to-date with the latest released version. We have a Bash launcher script at [bin/utils/openapi-generator.cli.sh](./bin/utils/openapi-generator.cli.sh) which resolves this issue.
|
||||
|
||||
To install the launcher script, copy the contents of the script to a location on your path and make the script executable.
|
||||
|
||||
An example of setting this up (NOTE: Always evaluate scripts curled from external systems before executing them).
|
||||
|
||||
```
|
||||
mkdir -p ~/bin/openapitools
|
||||
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator.cli.sh > ~/bin/openapitools/openapi-generator-cli
|
||||
chmod u+x ~/bin/openapitools/openapi-generator-cli
|
||||
export PATH=$PATH:~/bin/openapitools/
|
||||
```
|
||||
|
||||
Now, `openapi-generator-cli` is "installed". On invocation, it will query the GitHub repository for the most recently released version. If this matches the last downloaded jar,
|
||||
it will execute as normal. If a newer version is found, the script will download the latest release and execute it.
|
||||
|
||||
If you need to invoke an older version of the generator, you can define the variable `OPENAPI_GENERATOR_VERSION` either ad hoc or globally. You can export this variable if you'd like to persist a specific release version.
|
||||
|
||||
Examples:
|
||||
|
||||
```
|
||||
# Execute latest released openapi-generator-cli
|
||||
openapi-generator-cli version
|
||||
|
||||
# Execute version 3.1.0 for the current invocation, regardless of the latest released version
|
||||
OPENAPI_GENERATOR_VERSION=3.1.0 openapi-generator-cli version
|
||||
|
||||
# Execute version 3.1.0-SNAPSHOT for the current invocation
|
||||
OPENAPI_GENERATOR_VERSION=3.1.0-SNAPSHOT openapi-generator-cli version
|
||||
|
||||
# Execute version 3.0.2 for every invocation in the current shell session
|
||||
export OPENAPI_GENERATOR_VERSION=3.0.2
|
||||
openapi-generator-cli version # is 3.0.2
|
||||
openapi-generator-cli version # is also 3.0.2
|
||||
|
||||
# To "install" a specific version, set the variable in .bashrc/.bash_profile
|
||||
echo "export OPENAPI_GENERATOR_VERSION=3.0.2" >> ~/.bashrc
|
||||
source ~/.bashrc
|
||||
openapi-generator-cli version # is always 3.0.2, unless any of the above overrides are done ad hoc
|
||||
```
|
||||
|
||||
### [1.4 - Build Projects](#table-of-contents)
|
||||
|
||||
To build from source, you need the following installed and available in your `$PATH:`
|
||||
@@ -277,6 +317,20 @@ Once built, `run-in-docker.sh` will act as an executable for openapi-generator-c
|
||||
-g go -o /gen/out/go-petstore -DpackageName=petstore # generates go client, outputs locally to ./out/go-petstore
|
||||
```
|
||||
|
||||
##### Troubleshooting
|
||||
|
||||
If an error like this occurs, just execute the **mvn clean install -U** command:
|
||||
|
||||
> org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project openapi-generator: A type incompatibility occurred while executing org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test: java.lang.ExceptionInInitializerError cannot be cast to java.io.IOException
|
||||
|
||||
```sh
|
||||
./run-in-docker.sh mvn clean install -U
|
||||
```
|
||||
|
||||
> Failed to execute goal org.fortasoft:gradle-maven-plugin:1.0.8:invoke (default) on project openapi-generator-gradle-plugin-mvn-wrapper: org.gradle.tooling.BuildException: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.7-bin.zip'
|
||||
|
||||
Right now: no solution for this one :|
|
||||
|
||||
#### Run Docker in Vagrant
|
||||
Prerequisite: install [Vagrant](https://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads).
|
||||
```sh
|
||||
@@ -417,11 +471,11 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- [Bithost GmbH](https://www.bithost.ch)
|
||||
- [GMO Pepabo](https://pepabo.com/en/)
|
||||
- [Raiffeisen Schweiz Genossenschaft](https://www.raiffeisen.ch)
|
||||
- [RepreZen API Studio](https://www.reprezen.com/swagger-openapi-code-generation-api-first-microservices-enterprise-development)
|
||||
- [REST United](https://restunited.com)
|
||||
- [Telstra](https://dev.telstra.com)
|
||||
- [unblu inc.](https://www.unblu.com/)
|
||||
|
||||
|
||||
## [5 - Presentations/Videos/Tutorials/Books](#table-of-contents)
|
||||
|
||||
- 2018/05/12 - [OpenAPI Generator - community drivenで成長するコードジェネレータ](https://ackintosh.github.io/blog/2018/05/12/openapi-generator/) by [中野暁人](https://github.com/ackintosh)
|
||||
@@ -430,6 +484,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)
|
||||
|
||||
@@ -504,6 +559,7 @@ Here is a list of template creators:
|
||||
* Ada: @stcarrez
|
||||
* C# ASP.NET5: @jimschubert
|
||||
* C# NancyFX: @mstefaniuk
|
||||
* C++ (Qt5 QHttpEngine): @etherealjoy
|
||||
* C++ Pistache: @sebymiano
|
||||
* C++ Restbed: @stkrwork
|
||||
* Erlang Server: @galaxie
|
||||
@@ -519,6 +575,7 @@ Here is a list of template creators:
|
||||
* JAX-RS CXF (CDI): @nickcmaynard
|
||||
* JAX-RS RestEasy (JBoss EAP): @jfiala
|
||||
* Kotlin: @jimschubert
|
||||
* PHP Laravel: @renepardon
|
||||
* PHP Lumen: @abcsun
|
||||
* PHP Slim: @jfastnacht
|
||||
* PHP Symfony: @ksm2
|
||||
|
||||
@@ -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
|
||||
|
||||
32
bin/cpp-qt5-qhttpengine-server-petstore.sh
Executable file
32
bin/cpp-qt5-qhttpengine-server-petstore.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
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 -t modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-qt5-qhttpengine-server -o samples/server/petstore/cpp-qt5-qhttpengine-server $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -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 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g elm -o samples/client/petstore/elm $@"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/client/petstore/elm $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -30,6 +30,6 @@ rm -rf samples/client/petstore/go/go-petstore-withXml
|
||||
|
||||
# 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 -t modules/openapi-generator/src/main/resources/go -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g go -o samples/client/petstore/go/go-petstore-withXml -DpackageName=petstore,withXml=true $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/go -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g go -o samples/client/petstore/go/go-petstore-withXml -DpackageName=petstore,withXml=true,withGoCodegenComment=true $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -27,7 +27,7 @@ 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 --artifact-id petstore-java-client-jersey1 -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -o samples/client/petstore/java/jersey1 -DhideGenerationTimestamp=true --library=jersey1 $@"
|
||||
ags="generate --artifact-id petstore-java-client-jersey1 -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -o samples/client/petstore/java/jersey1 -DhideGenerationTimestamp=true --library=jersey1 --additional-properties useNullForUnknownEnumValue=true $@"
|
||||
|
||||
echo "Removing files and folders under samples/client/petstore/java/jersey1/src/main"
|
||||
rm -rf samples/client/petstore/java/jersey1/src/main
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"library": "jersey2",
|
||||
"artifactId": "petstore-jersey2"
|
||||
"artifactId": "petstore-jersey2",
|
||||
"additionalProperties" : {
|
||||
"useNullForUnknownEnumValue" : true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
32
bin/openapi3/cpp-qt5-qhttpengine-server-petstore.sh
Executable file
32
bin/openapi3/cpp-qt5-qhttpengine-server-petstore.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
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 -t modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-qt5-qhttpengine-server -o samples/client/petstore/cpp-qt5-qhttpengine-server $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
42
bin/openapi3/php-laravel-petstore.sh
Executable file
42
bin/openapi3/php-laravel-petstore.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
# Make sure that the working directory is the root dir
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "${SCRIPT_DIR}/../"
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
# Make sure that we are regenerating the sample by removing any existing target directory
|
||||
TARGET_DIR="$SCRIPT_DIR/../../samples/server/petstore/php-laravel"
|
||||
if [ -d "$TARGET_DIR" ]; then
|
||||
rm -rf $TARGET_DIR
|
||||
fi
|
||||
|
||||
executable="$SCRIPT_DIR/../../modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
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 -t $SCRIPT_DIR/../../modules/openapi-generator/src/main/resources/php-laravel -i $SCRIPT_DIR/../../modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php-laravel -o $TARGET_DIR $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -33,6 +33,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 -t modules/openapi-generator/src/main/resources/php -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php -o samples/openapi3/client/petstore/php $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php -o samples/openapi3/client/petstore/php/OpenAPIClient-php $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -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 -t modules/openapi-generator/src/main/resources/php-silex -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php-silex -o samples/server/petstore/php-silex $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php-silex -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php-silex -o samples/server/petstore/php-silex/OpenAPIServer $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -23,7 +23,7 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
fi
|
||||
|
||||
# Make sure that we are regenerating the sample by removing any existing target directory
|
||||
TARGET_DIR="$SCRIPT_DIR/../../samples/server/petstore/php-symfony"
|
||||
TARGET_DIR="$SCRIPT_DIR/../../samples/server/petstore/php-symfony/SymfonyBundle-php"
|
||||
if [ -d "$TARGET_DIR" ]; then
|
||||
rm -rf $TARGET_DIR
|
||||
fi
|
||||
|
||||
32
bin/php-laravel-petstore-server.sh
Executable file
32
bin/php-laravel-petstore-server.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
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 -t modules/openapi-generator/src/main/resources/php-laravel -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php-laravel -o samples/server/petstore/php-laravel $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -33,6 +33,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 -t modules/openapi-generator/src/main/resources/php -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php -o samples/client/petstore/php $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php -o samples/client/petstore/php/OpenAPIClient-php $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -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 -t modules/openapi-generator/src/main/resources/php-silex -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g php-silex -o samples/server/petstore/php-silex $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php-silex -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g php-silex -o samples/server/petstore/php-silex/OpenAPIServer $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -23,7 +23,7 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
fi
|
||||
|
||||
# Make sure that we are regenerating the sample by removing any existing target directory
|
||||
TARGET_DIR="$SCRIPT_DIR/../samples/server/petstore/php-symfony"
|
||||
TARGET_DIR="$SCRIPT_DIR/../samples/server/petstore/php-symfony/SymfonyBundle-php"
|
||||
if [ -d "$TARGET_DIR" ]; then
|
||||
rm -rf $TARGET_DIR
|
||||
fi
|
||||
|
||||
@@ -25,8 +25,10 @@ then
|
||||
mvn -B clean package
|
||||
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 -t modules/openapi-generator/src/main/resources/rust-server -i modules/openapi-generator/src/test/resources/2_0/rust-server/petstore-with-fake-endpoints-models-for-testing.yaml -g rust-server -o samples/server/petstore/rust-server -DpackageName=petstore_api --additional-properties hideGenerationTimestamp=true $@"
|
||||
for spec_path in modules/openapi-generator/src/test/resources/2_0/rust-server/* ; do
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
spec=$(basename "$spec_path" | sed 's/.yaml//')
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/rust-server -i $spec_path -g rust-server -o samples/server/petstore/rust-server/output/$spec -DpackageName=$spec --additional-properties hideGenerationTimestamp=true $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
done
|
||||
|
||||
@@ -29,7 +29,8 @@ sleep 5
|
||||
./bin/typescript-fetch-petstore-all.sh > /dev/null 2>&1
|
||||
./bin/typescript-node-petstore-all.sh > /dev/null 2>&1
|
||||
./bin/typescript-inversify-petstore.sh > /dev/null 2>&1
|
||||
|
||||
./bin/rust-server-petstore.sh > /dev/null 2>&1
|
||||
./bin/openapi3/haskell-http-client-petstore.sh > /dev/null 2>&1
|
||||
|
||||
# Check:
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
|
||||
60
bin/utils/openapi-generator-cli.sh
Normal file
60
bin/utils/openapi-generator-cli.sh
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
####
|
||||
# Save as openapi-generator-cli on your PATH. chmod u+x. Enjoy.
|
||||
#
|
||||
# This script will query github on every invocation to pull the latest released version
|
||||
# of openapi-generator.
|
||||
#
|
||||
# If you want repeatable executions, you can explicitly set a version via
|
||||
# OPENAPI_GENERATOR_VERSION
|
||||
# e.g. (in Bash)
|
||||
# export OPENAPI_GENERATOR_VERSION=3.1.0
|
||||
# openapi-generator-cli.sh
|
||||
# or
|
||||
# OPENAPI_GENERATOR_VERSION=3.1.0 openapi-generator-cli.sh
|
||||
#
|
||||
# This is also helpful, for example, if you want want to evaluate a SNAPSHOT version.
|
||||
#
|
||||
# NOTE: Jars are downloaded on demand from maven into the same directory as this script
|
||||
# for every 'latest' version pulled from github. Consider putting this under its own directory.
|
||||
####
|
||||
set -o pipefail
|
||||
|
||||
for cmd in {mvn,python,curl}; do
|
||||
if ! command -v ${cmd} > /dev/null; then
|
||||
>&2 echo "This script requires '${cmd}' to be installed."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
function latest.tag {
|
||||
local uri="https://api.github.com/repos/${1}/tags"
|
||||
curl -s ${uri} | python -c "import sys, json; print json.load(sys.stdin)[0]['name'][1:]"
|
||||
}
|
||||
|
||||
ghrepo=openapitools/openapi-generator
|
||||
groupid=org.openapitools
|
||||
artifactid=openapi-generator-cli
|
||||
ver=${OPENAPI_GENERATOR_VERSION:-$(latest.tag $ghrepo)}
|
||||
|
||||
jar=${artifactid}-${ver}.jar
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
if [ ! -f ${DIR}/${jar} ]; then
|
||||
repo="central::default::https://repo1.maven.apache.org/maven2"
|
||||
if [[ ${ver} =~ ^.*-SNAPSHOT$ ]]; then
|
||||
repo="central::default::https://oss.sonatype.org/content/repositories/snapshots"
|
||||
fi
|
||||
mvn org.apache.maven.plugins:maven-dependency-plugin:2.9:get \
|
||||
-DremoteRepositories=${repo} \
|
||||
-Dartifact=${groupid}:${artifactid}:${ver} \
|
||||
-Dtransitive=false \
|
||||
-Ddest=${DIR}/${jar}
|
||||
fi
|
||||
|
||||
java -ea \
|
||||
${JAVA_OPTS} \
|
||||
-Xms512M \
|
||||
-Xmx1024M \
|
||||
-server \
|
||||
-jar ${DIR}/${jar} "$@"
|
||||
@@ -40,16 +40,13 @@ declare -a files=("CI/pom.xml.bash"
|
||||
"CI/pom.xml.circleci.java7"
|
||||
"CI/pom.xml.ios"
|
||||
"modules/openapi-generator-cli/pom.xml"
|
||||
"modules/openapi-generator-gradle-plugin/README.adoc"
|
||||
"modules/openapi-generator-gradle-plugin/gradle.properties"
|
||||
"modules/openapi-generator-gradle-plugin/pom.xml"
|
||||
"modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle"
|
||||
"modules/openapi-generator-maven-plugin/pom.xml"
|
||||
"modules/openapi-generator-online/pom.xml"
|
||||
"modules/openapi-generator/pom.xml"
|
||||
"modules/openapi-generator-online/Dockerfile"
|
||||
"pom.xml"
|
||||
"README.md")
|
||||
"pom.xml")
|
||||
|
||||
for filename in "${files[@]}"; do
|
||||
# e.g. sed -i '' "s/3.0.1-SNAPSHOT/3.0.1/g" CI/pom.xml.bash
|
||||
|
||||
57
bin/utils/release_version_update_docs.sh
Executable file
57
bin/utils/release_version_update_docs.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# usage: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1
|
||||
#
|
||||
# Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
if [[ "$1" != "" ]]; then
|
||||
FROM="$1"
|
||||
else
|
||||
echo "Missing argument. Usage e.g.: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [[ "$2" != "" ]]; then
|
||||
TO="$2"
|
||||
else
|
||||
echo "Missing argument. Usage e.g.: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
||||
echo "IMPORTANT: this script works on Mac only"
|
||||
echo "Release preparation: replacing $FROM with $TO in different files"
|
||||
|
||||
declare -a files=("modules/openapi-generator-maven-plugin/README.md"
|
||||
"modules/openapi-generator-maven-plugin/examples/java-client.xml"
|
||||
"modules/openapi-generator-maven-plugin/examples/non-java-invalid-spec.xml"
|
||||
"modules/openapi-generator-maven-plugin/examples/non-java.xml"
|
||||
"modules/openapi-generator-gradle-plugin/README.adoc"
|
||||
"modules/openapi-generator-gradle-plugin/samples/local-spec/gradle.properties"
|
||||
"modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle"
|
||||
"modules/openapi-generator-gradle-plugin/samples/local-spec/README.md"
|
||||
"README.md")
|
||||
|
||||
for filename in "${files[@]}"; do
|
||||
# e.g. sed -i '' "s/3.0.1-SNAPSHOT/3.0.1/g" CI/pom.xml.bash
|
||||
#echo "Running command: sed -i '' "s/$FROM/$TO/g" $filename"
|
||||
if sed -i '' "s/$FROM/$TO/g" $filename; then
|
||||
echo "Updated $filename successfully!"
|
||||
else
|
||||
echo "ERROR: Failed to update $filename with the following command"
|
||||
echo "sed -i '' \"s/$FROM/$TO/g\" $filename"
|
||||
fi
|
||||
done
|
||||
10
bin/windows/cpp-qt5-qhttpengine-server-petstore.bat
Normal file
10
bin/windows/cpp-qt5-qhttpengine-server-petstore.bat
Normal file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-qt5-qhttpengine-server -o samples\server\petstore\cpp-qt5-qhttpengine-server
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php -o samples\client\petstore\php
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php -o samples\client\petstore\php\OpenAPIClient-php
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php-silex -o samples\server\petstore\php-silex
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php-silex -o samples\server\petstore\php-silex\OpenAPIServer
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php-symfony -o samples\server\petstore\php-symfony
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php-symfony -o samples\server\petstore\php-symfony\SymfonyBundle-php
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
28
circle.yml
28
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 }}
|
||||
|
||||
@@ -11,6 +11,42 @@ Another approach to find breaking changes is to look at issue and pull requests
|
||||
* link:https://github.com/OpenAPITools/openapi-generator/labels/Breaking%20change%20%28with%20fallback%29[Breaking change (with fallback)]
|
||||
* link:https://github.com/OpenAPITools/openapi-generator/labels/Breaking%20change%20%28without%20fallback%29[Breaking change (without fallback)]
|
||||
|
||||
=== From 3.1.x to 3.2.0
|
||||
|
||||
Version `3.2.0` is a minor version of OpenAPI-Generator, in comparison to `3.1.x` it contains some breaking changes, but with the possibility to fallback to the old behavior.
|
||||
The default value of some options might change.
|
||||
Projects relying on generated code might need to be adapted.
|
||||
|
||||
==== Validate spec on generation by default
|
||||
|
||||
The default is to validate the spec during generation. If the spec has errors,
|
||||
they will appear as errors or warnings to the user. This prevent generation of the project.
|
||||
|
||||
If you want to switch back to the `3.1.x` behavior you can use:
|
||||
|
||||
* Set the `validateSpec` option to `false` if you are using the Maven or Gradle plugin
|
||||
* Use the command line option `--skip-validate-spec` if you are using the CLI
|
||||
|
||||
|
||||
==== Model (all languages)
|
||||
|
||||
In `CodegenModel` and in `CodegenOperation` we use now our own class `org.openapitools.codegen.CodegenDiscriminator` instead of `io.swagger.v3.oas.models.media.Discriminator`.
|
||||
|
||||
For the templates, this is not an API change, because the same values are available.
|
||||
|
||||
If you have your own `Codegen` class (to support your own generator for example) then you might get some compile error due to the change.
|
||||
|
||||
==== Java
|
||||
|
||||
Schema with enum values are mapped to java enum in the generated code.
|
||||
In previous version, when an unknown value was deserialized, the value was set to `null`.
|
||||
|
||||
With `3.2.0` a new option is introduced: `useNullForUnknownEnumValue`.
|
||||
|
||||
* When set to `false` (default value), an Exception (`IllegalArgumentException`) is thrown when the value not available in the enum.
|
||||
* When set to `true`, unknown values are mapped to `null` as it was the case in previous versions.
|
||||
|
||||
|
||||
=== From 3.0.x to 3.1.0
|
||||
|
||||
Version `3.1.0` is the first minor version of OpenAPI-Generator, in comparison to `3.0.3` it contains some breaking changes, but with the possibility to fallback to the old behavior.
|
||||
|
||||
45
docs/qna.md
45
docs/qna.md
@@ -2,41 +2,40 @@
|
||||
|
||||
#### What is the governance structure of the OpenAPI Generator project?
|
||||
|
||||
OpenAPI generator (openapi-generator) is managed by the [core team members](../README.md#openapi-generator-core-team).
|
||||
OpenAPI generator (openapi-generator) is managed by the members of the [core team](../README.md#openapi-generator-core-team).
|
||||
|
||||
|
||||
#### What is the difference between Swagger Codegen and OpenAPI Generator?
|
||||
|
||||
Swagger Codegen is driven by SmartBear while OpenAPI Generator is driven by the community. More than 40 top contributors and template creators of Swagger Codegen have joined OpenAPI Generator as the founding team members.
|
||||
|
||||
Swagger is a trademark owned by SmartBear and the use of the term "Swagger" in this project is for demo (reference) purposes only.
|
||||
|
||||
|
||||
#### Why was it decided to fork Swagger Codegen and to maintain a community-driven version?
|
||||
|
||||
There are several reasons:
|
||||
|
||||
1. The founding members came to the conclusion that Swagger Codegen 3.0.0 beta contains too many breaking changes while they strongly believe 3.0.0 release should only focus on one thing: OpenAPI specification 3.0 support.
|
||||
1. Swagger Codegen 3.0.0 beta was evaluated as unstable. Changes made directly to 3.0.0 branch without reviews or tests, were breaking the builds from time to time (e.g. a simple `mvn clean package` failed).
|
||||
1. Reviews of code changes in the 3.0.0 branch highlighted a lot of code block removal without any reason. This might produce regressions for edge cases discovered previously.
|
||||
1. Most of the test cases in the generators have been commented out as part of the migration to support OpenAPI 3.0. Test cases are the most valuable assets of the project and should be maintained to ensure a good quality.
|
||||
1. According to SmartBear, [Swagger Codegen 2.x and 3.x should be supported in parallel for a while](https://github.com/swagger-api/swagger-codegen/issues/7754#issuecomment-375039048) without the possibility to work with git branches to merge the fixes from one branch to the next. Having to implement everything twice is not a good idea and the best use of the Swagger Codegen community resources.
|
||||
1. Having a community-driven version can bring the project to the next level.
|
||||
1. The founding members came to the conclusion that Swagger Codegen 3.0.0 beta contains too many breaking changes. They also strongly believe the 3.0.0 release should only focus on one thing: OpenAPI 3.0 support.
|
||||
1. The founding members had concerns about the development practices, which seemed to be contributing to an unstable and insufficiently tested codebase.
|
||||
1. There was a disagreement on the evolutionary strategy for Swagger Codegen. The founding members felt it was important to move forward with OpenAPI 3.0 support, while maintaining backward compatibility with OpenAPI 2.0 in the same codebase.
|
||||
1. The founding members found that the enhancements and bug fixes submitted for Swagger Codegen 2.x need to be submitted again for Swagger Codegen 3.0.0 branch (otherwise, these changes would not appear in the 3.0.0 branch. Having to do the pull request twice is not the best use of community resources).
|
||||
1. The community-driven version has a more rapid [release cycle](https://github.com/OpenAPITools/openapi-generator/releases/) (weekly patch release, monthly minor release) so users do not need to wait for several months to get a stable release.
|
||||
1. Having a community-driven version _can_ bring the project to the next level with reliable releases and a clear [roadmap](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/roadmap.adoc).
|
||||
|
||||
UPDATE: After the public launch of OpenAPI Generator, some of the core team members were contacted by Ron (SmartBear) and we explained to him the reasons of the fork as explained above. We also asked him to contact team@openapitools.org if he wants to discuss further but so far we don't see any email from him to team@openapitools.org.
|
||||
#### Was anything done to attempt to address the issues before deciding to fork Swagger Codegen and maintain a community-driven version?
|
||||
|
||||
#### Has anything been done in attempt to address the issues before deciding to fork Swagger Codegen and maintain a community-driven version?
|
||||
|
||||
There were several conversations with SmartBear (Ron, Hugo) via emails, gitter, Skype call and GitHub issues.
|
||||
There were several conversations with the project owners of Swagger Codegen via emails, Gitter, Skype call and GitHub issues to discuss the state of Swagger Codegen 3.0.0.
|
||||
But there was no consensus on the next steps and on the direction for Swagger Codegen 3.0.0.
|
||||
|
||||
#### Is there any change to the project license?
|
||||
#### Are there any changes to the project license?
|
||||
|
||||
No, OpenAPI Generator is still using [Apache license (version 2)](https://www.apache.org/licenses/LICENSE-2.0).
|
||||
No, OpenAPI Generator is still using the [Apache license (version 2)](https://www.apache.org/licenses/LICENSE-2.0).
|
||||
|
||||
#### What is the difference between Swagger Codegen and OpenAPI Generator?
|
||||
#### I am currently using Swagger Codegen 2.x. How can I upgrade the generator to OpenAPI Generator?
|
||||
|
||||
Swagger Codegen is driven by SmartBear while OpenAPI Generator is driven by the community. More than 40 top contributors and template creators of Swagger Codegen have joined OpenAPI Generator as the founding team members.
|
||||
OpenAPI Generator is based on Swagger Codegen `2.4.0-SNAPSHOT` version so the migration should be relatively straightforward. Refer to the [migration guide](migration-from-swagger-codegen.md) for more information.
|
||||
|
||||
Swagger is a trademark owned by SmartBear and the use of the term "Swagger" found in this project is for demo purpose (reference) only.
|
||||
#### Who maintains this Q&A page?
|
||||
|
||||
#### I’m currently using Swagger Codegen 2.x. How can I upgrade the generator to OpenAPI Generator?
|
||||
|
||||
OpenAPI Generator is based on Swagger Codegen 2.4.0-SNAPSHOT version so the migration should be easy, straightforward and almost seamless. Please refer to the [migration guide](migration-from-swagger-codegen.md) for more information.
|
||||
|
||||
#### May I know who maintains this Q&A page?
|
||||
|
||||
This Q&A page is maintained by the [core team members](../README.md#openapi-generator-core-team). It's not maintained by a single person nor do these Q&As represent the view of an individual.
|
||||
This Q&A page is maintained by the [core team members](../README.md#openapi-generator-core-team). It is not maintained by a single person nor do these Q&As represent the views of any individual or person.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.2.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -72,4 +72,4 @@ public class ConfigHelp implements Runnable {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +194,11 @@ public class Generate implements Runnable {
|
||||
description = CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DESC)
|
||||
private Boolean removeOperationIdPrefix;
|
||||
|
||||
@Option(name = {"--skip-validate-spec"},
|
||||
title = "skip spec validation",
|
||||
description = "Skips the default behavior of validating an input specification.")
|
||||
private Boolean skipValidateSpec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -207,6 +212,10 @@ public class Generate implements Runnable {
|
||||
}
|
||||
|
||||
// now override with any specified parameters
|
||||
if (skipValidateSpec != null) {
|
||||
configurator.setValidateSpec(false);
|
||||
}
|
||||
|
||||
if (verbose != null) {
|
||||
configurator.setVerbose(verbose);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:3.1.1"
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:3.1.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,11 @@ The gradle plugin is not currently published to https://plugins.gradle.org/m2/.
|
||||
|false
|
||||
|The verbosity of generation
|
||||
|
||||
|validateSpec
|
||||
|Boolean
|
||||
|true
|
||||
|Whether or not we should validate the input spec before generation. Invalid specs result in an error.
|
||||
|
||||
|generatorName
|
||||
|String
|
||||
|None
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
openApiGeneratorVersion=3.1.1
|
||||
openApiGeneratorVersion=3.2.0
|
||||
|
||||
# BEGIN placeholders
|
||||
# these are just placeholders to allow contributors to build directly
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.2.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -11,10 +11,11 @@ gradle openApiGenerate
|
||||
gradle openApiMeta
|
||||
gradle openApiValidate
|
||||
gradle buildGoSdk
|
||||
gradle generateGoWithInvalidSpec
|
||||
```
|
||||
|
||||
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
|
||||
|
||||
```bash
|
||||
gradle -PopenApiGeneratorVersion=3.1.1 openApiValidate
|
||||
gradle -PopenApiGeneratorVersion=3.1.2 openApiValidate
|
||||
```
|
||||
|
||||
@@ -54,3 +54,16 @@ task buildGoSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTas
|
||||
dateLibrary: "threetenp"
|
||||
]
|
||||
}
|
||||
|
||||
task generateGoWithInvalidSpec(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask){
|
||||
validateSpec = true
|
||||
generatorName = "go"
|
||||
inputSpec = "$rootDir/petstore-v3.0-invalid.yaml".toString()
|
||||
additionalProperties = [
|
||||
packageName: "petstore"
|
||||
]
|
||||
outputDir = "$buildDir/go".toString()
|
||||
configOptions = [
|
||||
dateLibrary: "threetenp"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
openApiGeneratorVersion=3.1.1
|
||||
openApiGeneratorVersion=3.1.2
|
||||
|
||||
@@ -80,6 +80,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
|
||||
description = "Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents."
|
||||
|
||||
verbose.set(generate.verbose)
|
||||
validateSpec.set(generate.validateSpec)
|
||||
generatorName.set(generate.generatorName)
|
||||
outputDir.set(generate.outputDir)
|
||||
inputSpec.set(generate.inputSpec)
|
||||
|
||||
@@ -32,6 +32,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
*/
|
||||
val verbose = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Whether or not an input specification should be validated upon generation.
|
||||
*/
|
||||
val validateSpec = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* The name of the generator which will handle codegen. (see "openApiGenerators" task)
|
||||
*/
|
||||
@@ -262,6 +267,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
val configOptions = project.objects.property<Map<String, String>>()
|
||||
|
||||
init {
|
||||
applyDefaults()
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
fun applyDefaults(){
|
||||
releaseNote.set("Minor update")
|
||||
modelNamePrefix.set("")
|
||||
modelNameSuffix.set("")
|
||||
@@ -271,5 +281,6 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
generateApiDocumentation.set(true)
|
||||
withXml.set(false)
|
||||
configOptions.set(mapOf())
|
||||
validateSpec.set(true)
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import org.gradle.kotlin.dsl.property
|
||||
import org.openapitools.codegen.CodegenConstants
|
||||
import org.openapitools.codegen.DefaultGenerator
|
||||
import org.openapitools.codegen.config.CodegenConfigurator
|
||||
import org.openapitools.codegen.config.CodegenConfiguratorUtils.*
|
||||
|
||||
|
||||
/**
|
||||
@@ -48,6 +47,12 @@ open class GenerateTask : DefaultTask() {
|
||||
@get:Internal
|
||||
val verbose = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Whether or not an input specification should be validated upon generation.
|
||||
*/
|
||||
@get:Internal
|
||||
val validateSpec = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* The name of the generator which will handle codegen. (see "openApiGenerators" task)
|
||||
*/
|
||||
@@ -382,6 +387,10 @@ open class GenerateTask : DefaultTask() {
|
||||
configurator.isVerbose = value
|
||||
}
|
||||
|
||||
validateSpec.ifNotEmpty { value ->
|
||||
configurator.isValidateSpec = value
|
||||
}
|
||||
|
||||
skipOverwrite.ifNotEmpty { value ->
|
||||
configurator.isSkipOverwrite = value ?: false
|
||||
}
|
||||
@@ -528,8 +537,7 @@ open class GenerateTask : DefaultTask() {
|
||||
|
||||
out.println("Successfully generated code to ${configurator.outputDir}")
|
||||
} catch (e: RuntimeException) {
|
||||
logger.error(e.message)
|
||||
throw GradleException("Code generation failed.")
|
||||
throw GradleException("Code generation failed.", e)
|
||||
}
|
||||
} finally {
|
||||
originalEnvironmentVariables.forEach { entry ->
|
||||
|
||||
@@ -31,7 +31,7 @@ class GenerateTaskDslTest : TestBase() {
|
||||
fun `openApiGenerate should create an expected file structure from DSL config`() {
|
||||
// Arrange
|
||||
val projectFiles = mapOf(
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0-invalid.yaml")
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml")
|
||||
)
|
||||
withProject(defaultBuildGradle, projectFiles)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ Add to your `build->plugins` section (default phase is `generate-sources` phase)
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@@ -38,6 +38,7 @@ mvn clean compile
|
||||
### General Configuration parameters
|
||||
|
||||
- `inputSpec` - OpenAPI Spec file path
|
||||
- `validateSpec` - Whether or not to validate the input spec prior to generation. Invalid specifications will result in an error.
|
||||
- `language` - target generation language (deprecated, replaced by `generatorName` as values here don't represent only 'language' any longer)
|
||||
- `generatorName` - target generator name
|
||||
- `output` - target output path (default is `${project.build.directory}/generated-sources/swagger`)
|
||||
@@ -102,4 +103,8 @@ Specifying a custom generator is a bit different. It doesn't support the classpa
|
||||
|
||||
### Sample configuration
|
||||
|
||||
- Please see [an example configuration](examples) for using the plugin
|
||||
Please see [an example configuration](examples) for using the plugin. To run these examples, explicitly pass the file to maven. Example:
|
||||
|
||||
```bash
|
||||
mvn -f non-java.xml compile
|
||||
```
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.0.1-SNAPSHOT</version>
|
||||
<version>3.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@@ -20,7 +20,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- specify the swagger yaml -->
|
||||
<inputSpec>swagger.yaml</inputSpec>
|
||||
<inputSpec>${project.basedir}/swagger.yaml</inputSpec>
|
||||
|
||||
<!-- target to generate java client code -->
|
||||
<generatorName>java</generatorName>
|
||||
@@ -39,13 +39,22 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<!-- dependencies are needed for the client being generated -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations-version}</version>
|
||||
</dependency>
|
||||
@@ -55,13 +64,8 @@
|
||||
|
||||
<!-- HTTP client: jersey-client -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -69,6 +73,11 @@
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JSON processing: jackson -->
|
||||
<dependency>
|
||||
@@ -96,7 +105,7 @@
|
||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Joda time: if you use it -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
@@ -107,19 +116,19 @@
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
|
||||
<!-- Base64 encoding that works in both JVM and Android -->
|
||||
<dependency>
|
||||
<groupId>com.brsanthu</groupId>
|
||||
<artifactId>migbase64</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.8</swagger-annotations-version>
|
||||
<jersey-version>2.22.2</jersey-version>
|
||||
<jersey-version>2.27</jersey-version>
|
||||
<jackson-version>2.8.9</jackson-version>
|
||||
<jodatime-version>2.7</jodatime-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>sample-project</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>sample-project</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- activate the plugin -->
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<validateSpec>false</validateSpec>
|
||||
<inputSpec>${project.basedir}/petstore-v3.0-invalid.yaml</inputSpec>
|
||||
<generatorName>aspnetcore</generatorName>
|
||||
<configOptions>
|
||||
<additional-properties>optionalProjectFile=true</additional-properties>
|
||||
</configOptions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -12,14 +12,14 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.0.1-SNAPSHOT</version>
|
||||
<version>3.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<inputSpec>swagger.yaml</inputSpec>
|
||||
<inputSpec>${project.basedir}/swagger.yaml</inputSpec>
|
||||
<generatorName>aspnetcore</generatorName>
|
||||
<configOptions>
|
||||
<additional-properties>optionalProjectFile=true</additional-properties>
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
openapi: "3.0.0"
|
||||
servers:
|
||||
- url: http://petstore.swagger.io/v1
|
||||
paths:
|
||||
/pets:
|
||||
get:
|
||||
summary: List all pets
|
||||
operationId: listPets
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
description: How many items to return at one time (max 100)
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: A paged array of pets
|
||||
headers:
|
||||
x-next:
|
||||
description: A link to the next page of responses
|
||||
schema:
|
||||
type: string
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
summary: Create a pet
|
||||
tags:
|
||||
- pets
|
||||
responses:
|
||||
'201':
|
||||
description: Null response
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/pets/{petId}:
|
||||
get:
|
||||
summary: Info for a specific pet
|
||||
operationId: showPetById
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
required: true
|
||||
description: The id of the pet to retrieve
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: Expected response to a valid request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
Pet:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
Pets:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Pet"
|
||||
Error:
|
||||
required:
|
||||
- code
|
||||
- message
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.2.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
|
||||
@@ -60,6 +60,9 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CodeGenMojo.class);
|
||||
|
||||
@Parameter(name="validateSpec", required = false, defaultValue = "true")
|
||||
private Boolean validateSpec;
|
||||
|
||||
@Parameter(name = "verbose", required = false, defaultValue = "false")
|
||||
private boolean verbose;
|
||||
|
||||
@@ -348,6 +351,11 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
|
||||
configurator.setVerbose(verbose);
|
||||
|
||||
// now override with any specified parameters
|
||||
if (validateSpec != null) {
|
||||
configurator.setValidateSpec(validateSpec);
|
||||
}
|
||||
|
||||
if (skipOverwrite != null) {
|
||||
configurator.setSkipOverwrite(skipOverwrite);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ FROM openjdk:8-jre-alpine
|
||||
|
||||
WORKDIR /generator
|
||||
|
||||
COPY target/openapi-generator-online-3.1.1.jar /generator/openapi-generator-online.jar
|
||||
COPY target/openapi-generator-online-3.2.0.jar /generator/openapi-generator-online.jar
|
||||
|
||||
ENV GENERATOR_HOST=http://localhost
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.2.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-online</artifactId>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.2.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -204,9 +204,9 @@
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger.parser.v3</groupId>
|
||||
<artifactId>swagger-parser</artifactId>
|
||||
<version>${swagger-parser-version}</version>
|
||||
<groupId>org.openapitools.swagger.parser</groupId>
|
||||
<artifactId>swagger-parser</artifactId>
|
||||
<version>${swagger-parser-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.samskivert</groupId>
|
||||
|
||||
@@ -230,6 +230,10 @@ public interface CodegenConfig {
|
||||
|
||||
String getHttpUserAgent();
|
||||
|
||||
void setDocExtension(String docExtension);
|
||||
|
||||
String getDocExtension();
|
||||
|
||||
String getCommonTemplateDir();
|
||||
|
||||
void setIgnoreFilePathOverride(String ignoreFileOverride);
|
||||
|
||||
@@ -56,6 +56,9 @@ public class CodegenConstants {
|
||||
public static final String PYTHON_PACKAGE_NAME = "pythonPackageName";
|
||||
public static final String PYTHON_PACKAGE_NAME_DESC = "package name for generated python code";
|
||||
|
||||
public static final String WITH_GO_CODEGEN_COMMENT = "withGoCodegenComment";
|
||||
public static final String WITH_GO_CODEGEN_COMMENT_DESC = "whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs";
|
||||
|
||||
public static final String GROUP_ID = "groupId";
|
||||
public static final String GROUP_ID_DESC = "groupId in generated pom.xml";
|
||||
|
||||
@@ -251,4 +254,11 @@ 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";
|
||||
|
||||
public static final String DATABASE_ADAPTER = "databaseAdapter";
|
||||
public static final String DATABASE_ADAPTER_DESC = "The adapter for database (e.g. mysql, sqlite). Default: sqlite";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenDiscriminator {
|
||||
private String propertyName;
|
||||
private Map<String, String> mapping;
|
||||
private Set<MappedModel> mappedModels = new LinkedHashSet<>();
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public void setPropertyName(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public Map<String, String> getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
public void setMapping(Map<String, String> mapping) {
|
||||
this.mapping = mapping;
|
||||
}
|
||||
|
||||
public Set<MappedModel> getMappedModels() {
|
||||
return mappedModels;
|
||||
}
|
||||
|
||||
public void setMappedModels(Set<MappedModel> mappedModels) {
|
||||
this.mappedModels = mappedModels;
|
||||
}
|
||||
|
||||
public static class MappedModel {
|
||||
private String mappingName;
|
||||
private String modelName;
|
||||
|
||||
public MappedModel(String mappingName, String modelName) {
|
||||
this.mappingName = mappingName;
|
||||
this.modelName = modelName;
|
||||
}
|
||||
|
||||
public String getMappingName() {
|
||||
return mappingName;
|
||||
}
|
||||
|
||||
public void setMappingName(String mappingName) {
|
||||
this.mappingName = mappingName;
|
||||
}
|
||||
|
||||
public String getModelName() {
|
||||
return modelName;
|
||||
}
|
||||
|
||||
public void setModelName(String modelName) {
|
||||
this.modelName = modelName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MappedModel that = (MappedModel) o;
|
||||
return Objects.equals(mappingName, that.mappingName) &&
|
||||
Objects.equals(modelName, that.modelName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mappingName, modelName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CodegenDiscriminator that = (CodegenDiscriminator) o;
|
||||
return Objects.equals(propertyName, that.propertyName) &&
|
||||
Objects.equals(mapping, that.mapping) &&
|
||||
Objects.equals(mappedModels, that.mappedModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(propertyName, mapping, mappedModels);
|
||||
}
|
||||
}
|
||||
@@ -18,15 +18,14 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.models.media.Discriminator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CodegenModel {
|
||||
public String parent, parentSchema;
|
||||
@@ -40,7 +39,7 @@ public class CodegenModel {
|
||||
public String name, classname, title, description, classVarName, modelJson, dataType, xmlPrefix, xmlNamespace, xmlName;
|
||||
public String classFilename; // store the class file name, mainly used for import
|
||||
public String unescapedDescription;
|
||||
public Discriminator discriminator;
|
||||
public CodegenDiscriminator discriminator;
|
||||
public String defaultValue;
|
||||
public String arrayModelType;
|
||||
public boolean isAlias; // Is this effectively an alias of another simple type
|
||||
@@ -349,7 +348,7 @@ public class CodegenModel {
|
||||
this.unescapedDescription = unescapedDescription;
|
||||
}
|
||||
|
||||
public Discriminator getDiscriminator() {
|
||||
public CodegenDiscriminator getDiscriminator() {
|
||||
return discriminator;
|
||||
}
|
||||
|
||||
@@ -357,7 +356,7 @@ public class CodegenModel {
|
||||
return discriminator == null ? null : discriminator.getPropertyName();
|
||||
}
|
||||
|
||||
public void setDiscriminator(Discriminator discriminator) {
|
||||
public void setDiscriminator(CodegenDiscriminator discriminator) {
|
||||
this.discriminator = discriminator;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,17 +18,15 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.models.media.Discriminator;
|
||||
import io.swagger.v3.oas.models.parameters.RequestBody;
|
||||
import io.swagger.v3.oas.models.tags.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CodegenOperation {
|
||||
public final List<CodegenProperty> responseHeaders = new ArrayList<CodegenProperty>();
|
||||
@@ -40,7 +38,7 @@ public class CodegenOperation {
|
||||
isRestful, isDeprecated;
|
||||
public String path, operationId, returnType, httpMethod, returnBaseType,
|
||||
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse;
|
||||
public Discriminator discriminator;
|
||||
public CodegenDiscriminator discriminator;
|
||||
public List<Map<String, String>> consumes, produces, prioritizedContentTypes;
|
||||
public CodegenParameter bodyParam;
|
||||
public List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();
|
||||
|
||||
@@ -54,7 +54,7 @@ public class CodegenProperty implements Cloneable {
|
||||
public boolean exclusiveMinimum;
|
||||
public boolean exclusiveMaximum;
|
||||
public boolean hasMore, required, secondaryParam;
|
||||
public boolean hasMoreNonReadOnly; // for model constructor, true if next properyt is not readonly
|
||||
public boolean hasMoreNonReadOnly; // for model constructor, true if next property is not readonly
|
||||
public boolean isPrimitiveType, isContainer, isNotContainer;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isFile, isBoolean, isDate, isDateTime, isUuid;
|
||||
public boolean isListContainer, isMapContainer;
|
||||
|
||||
@@ -26,7 +26,12 @@ import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.examples.Example;
|
||||
import io.swagger.v3.oas.models.headers.Header;
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.ComposedSchema;
|
||||
import io.swagger.v3.oas.models.media.Content;
|
||||
import io.swagger.v3.oas.models.media.MediaType;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.media.StringSchema;
|
||||
import io.swagger.v3.oas.models.parameters.CookieParameter;
|
||||
import io.swagger.v3.oas.models.parameters.HeaderParameter;
|
||||
import io.swagger.v3.oas.models.parameters.Parameter;
|
||||
@@ -43,6 +48,7 @@ import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CodegenDiscriminator.MappedModel;
|
||||
import org.openapitools.codegen.examples.ExampleGenerator;
|
||||
import org.openapitools.codegen.serializer.SerializerUtils;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
@@ -66,6 +72,7 @@ import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
||||
@@ -114,6 +121,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// When a model is an alias for a simple type
|
||||
protected Map<String, String> typeAliases = null;
|
||||
protected Boolean prependFormOrBodyParameters = false;
|
||||
// The extension of the generated documentation files (defaults to markdown .md)
|
||||
protected String docExtension;
|
||||
|
||||
protected String ignoreFilePathOverride;
|
||||
|
||||
@@ -172,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
|
||||
@@ -754,6 +768,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
public String toVarName(String name) {
|
||||
if (reservedWords.contains(name)) {
|
||||
return escapeReservedWord(name);
|
||||
} else if (((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains( "" + ((char) character)))) {
|
||||
return escapeSpecialCharacters(name, null, null);
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
@@ -770,6 +786,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
name = removeNonNameElementToCamelCase(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
if (reservedWords.contains(name)) {
|
||||
return escapeReservedWord(name);
|
||||
} else if (((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains( "" + ((char) character)))) {
|
||||
return escapeSpecialCharacters(name, null, null);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
@@ -808,6 +826,32 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
throw new RuntimeException("reserved word " + name + " not allowed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name with escaped characters.
|
||||
*
|
||||
* @param name the name to be escaped
|
||||
* @param charactersToAllow characters that are not escaped
|
||||
* @param appdendixToReplacement String to append to replaced characters.
|
||||
* @return the escaped word
|
||||
* <p>
|
||||
* throws Runtime exception as word is not escaped properly.
|
||||
*/
|
||||
public String escapeSpecialCharacters(String name, List<String> charactersToAllow, String appdendixToReplacement) {
|
||||
String result = (String) ((CharSequence) name).chars().mapToObj(c -> {
|
||||
String character = "" + (char) c;
|
||||
if (charactersToAllow != null && charactersToAllow.contains(character)) {
|
||||
return character;
|
||||
} else if (specialCharReplacements.containsKey(character)) {
|
||||
return specialCharReplacements.get(character) + (appdendixToReplacement != null ? appdendixToReplacement: "");
|
||||
} else {
|
||||
return character;
|
||||
}
|
||||
}).reduce( (c1, c2) -> "" + c1 + c2).orElse(null);
|
||||
|
||||
if (result != null) return result;
|
||||
throw new RuntimeException("Word '" + name + "' could not be escaped.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fully-qualified "Model" name for import
|
||||
*
|
||||
@@ -1469,6 +1513,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// unalias schema
|
||||
schema = ModelUtils.unaliasSchema(allDefinitions, schema);
|
||||
if (schema == null) {
|
||||
LOGGER.warn("Schema {} not found", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
CodegenModel m = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
|
||||
|
||||
@@ -1489,7 +1537,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
m.getVendorExtensions().putAll(schema.getExtensions());
|
||||
}
|
||||
m.isAlias = typeAliases.containsKey(name);
|
||||
m.discriminator = schema.getDiscriminator();
|
||||
m.discriminator = createDiscriminator(name, schema, allDefinitions);
|
||||
|
||||
if (schema.getXml() != null) {
|
||||
m.xmlPrefix = schema.getXml().getPrefix();
|
||||
@@ -1516,7 +1564,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
|
||||
for (Schema innerModel : composed.getAllOf()) {
|
||||
if (m.discriminator == null) {
|
||||
m.discriminator = schema.getDiscriminator();
|
||||
m.discriminator = createDiscriminator(name, schema, allDefinitions);
|
||||
}
|
||||
if (innerModel.getXml() != null) {
|
||||
m.xmlPrefix = innerModel.getXml().getPrefix();
|
||||
@@ -1631,6 +1679,34 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return m;
|
||||
}
|
||||
|
||||
private CodegenDiscriminator createDiscriminator(String schemaName, Schema schema, Map<String, Schema> allDefinitions) {
|
||||
if(schema.getDiscriminator() == null) {
|
||||
return null;
|
||||
}
|
||||
CodegenDiscriminator discriminator = new CodegenDiscriminator();
|
||||
discriminator.setPropertyName(schema.getDiscriminator().getPropertyName());
|
||||
discriminator.setMapping(schema.getDiscriminator().getMapping());
|
||||
if(schema.getDiscriminator().getMapping() != null && !schema.getDiscriminator().getMapping().isEmpty()) {
|
||||
for (Entry<String, String> e : schema.getDiscriminator().getMapping().entrySet()) {
|
||||
String name = ModelUtils.getSimpleRef(e.getValue());
|
||||
discriminator.getMappedModels().add(new MappedModel(e.getKey(), name));
|
||||
}
|
||||
} else {
|
||||
allDefinitions.forEach((childName, child) -> {
|
||||
if (child instanceof ComposedSchema && ((ComposedSchema) child).getAllOf() != null) {
|
||||
Set<String> parentSchemas = ((ComposedSchema) child).getAllOf().stream()
|
||||
.filter(s -> s.get$ref() != null)
|
||||
.map(s -> ModelUtils.getSimpleRef(s.get$ref()))
|
||||
.collect(Collectors.toSet());
|
||||
if (parentSchemas.contains(schemaName)) {
|
||||
discriminator.getMappedModels().add(new MappedModel(childName, childName));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return discriminator;
|
||||
}
|
||||
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
addParentContainer(codegenModel, codegenModel.name, schema);
|
||||
}
|
||||
@@ -2314,6 +2390,13 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
CodegenParameter p = fromParameter(param, imports);
|
||||
|
||||
// ensure unique params
|
||||
if (ensureUniqueParams) {
|
||||
if (!isParameterNameUnique(p, allParams)) {
|
||||
p.paramName = generateNextName(p.paramName);
|
||||
}
|
||||
}
|
||||
|
||||
allParams.add(p);
|
||||
|
||||
if (param instanceof QueryParameter || "query".equalsIgnoreCase(param.getIn())) {
|
||||
@@ -2342,17 +2425,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// ensure unique parameter name
|
||||
for (CodegenParameter cp : allParams) {
|
||||
if (ensureUniqueParams) {
|
||||
if (isParameterNameUnique(cp, allParams)) {
|
||||
continue;
|
||||
} else {
|
||||
cp.paramName = generateNextName(cp.paramName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create optional, required parameters
|
||||
for (CodegenParameter cp : allParams) {
|
||||
if (cp.required) { //required parameters
|
||||
@@ -3415,7 +3487,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;
|
||||
}
|
||||
|
||||
@@ -3552,6 +3625,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.
|
||||
*
|
||||
@@ -4331,7 +4423,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(bodyParameterName)) {
|
||||
codegenParameter.baseName = mostInnerItem.complexType;
|
||||
if(StringUtils.isEmpty(mostInnerItem.complexType)) {
|
||||
codegenParameter.baseName = "request_body";
|
||||
} else {
|
||||
codegenParameter.baseName = mostInnerItem.complexType;
|
||||
}
|
||||
} else {
|
||||
codegenParameter.baseName = bodyParameterName;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
|
||||
/**
|
||||
* Programmatically disable the output of .openapi-generator/VERSION, .openapi-generator-ignore,
|
||||
* or other metadata files used by Swagger Codegen.
|
||||
* or other metadata files used by OpenAPI Generator.
|
||||
*
|
||||
* @param generateMetadata true: enable outputs, false: disable outputs
|
||||
*/
|
||||
@@ -193,8 +193,14 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
|
||||
URL url = URLPathUtils.getServerURL(openAPI);
|
||||
contextPath = config.escapeText(url.getPath());
|
||||
basePath = config.escapeText(URLPathUtils.getHost(openAPI));
|
||||
basePathWithoutHost = contextPath; // for backward compatibility
|
||||
basePath = config.escapeText(URLPathUtils.getHost(openAPI));
|
||||
if ("/".equals(basePath.substring(basePath.length() - 1))) {
|
||||
// remove trailing "/"
|
||||
// https://host.example.com/ => https://host.example.com
|
||||
basePath = basePath.substring(0, basePath.length() - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void configureOpenAPIInfo() {
|
||||
@@ -278,7 +284,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
|
||||
private void generateModelDocumentation(List<File> files, Map<String, Object> 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);
|
||||
@@ -895,8 +902,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
if (path.getParameters() != null) {
|
||||
for (Parameter parameter : path.getParameters()) {
|
||||
//skip propagation if a parameter with the same name is already defined at the operation level
|
||||
if (!operationParameters.contains(generateParameterId(parameter)) && operation.getParameters() != null) {
|
||||
operation.getParameters().add(parameter);
|
||||
if (!operationParameters.contains(generateParameterId(parameter))) {
|
||||
operation.addParametersItem(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class SpecValidationException extends RuntimeException {
|
||||
|
||||
private Set<String> errors;
|
||||
private Set<String> warnings;
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with {@code null} as its
|
||||
* detail message. The cause is not initialized, and may subsequently be
|
||||
* initialized by a call to {@link #initCause}.
|
||||
*/
|
||||
public SpecValidationException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified detail message.
|
||||
* The cause is not initialized, and may subsequently be initialized by a
|
||||
* call to {@link #initCause}.
|
||||
*
|
||||
* @param message the detail message. The detail message is saved for
|
||||
* later retrieval by the {@link #getMessage()} method.
|
||||
*/
|
||||
public SpecValidationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified detail message and
|
||||
* cause. <p>Note that the detail message associated with
|
||||
* {@code cause} is <i>not</i> automatically incorporated in
|
||||
* this runtime exception's detail message.
|
||||
*
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
* by the {@link #getMessage()} method).
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
*/
|
||||
public SpecValidationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified cause and a
|
||||
* detail message of <tt>(cause==null ? null : cause.toString())</tt>
|
||||
* (which typically contains the class and detail message of
|
||||
* <tt>cause</tt>). This constructor is useful for runtime exceptions
|
||||
* that are little more than wrappers for other throwables.
|
||||
*
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
*/
|
||||
public SpecValidationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified detail
|
||||
* message, cause, suppression enabled or disabled, and writable
|
||||
* stack trace enabled or disabled.
|
||||
*
|
||||
* @param message the detail message.
|
||||
* @param cause the cause. (A {@code null} value is permitted,
|
||||
* and indicates that the cause is nonexistent or unknown.)
|
||||
* @param enableSuppression whether or not suppression is enabled
|
||||
* or disabled
|
||||
* @param writableStackTrace whether or not the stack trace should
|
||||
* be writable
|
||||
* @since 1.7
|
||||
*/
|
||||
public SpecValidationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public Set<String> getErrors() {
|
||||
return errors;
|
||||
}
|
||||
|
||||
public Set<String> getWarnings() {
|
||||
return warnings;
|
||||
}
|
||||
|
||||
public void setErrors(Set<String> errors) {
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public void setWarnings(Set<String> warnings) {
|
||||
this.warnings = warnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the detail message string of this throwable.
|
||||
*
|
||||
* @return the detail message string of this {@code Throwable} instance
|
||||
* (which may be {@code null}).
|
||||
*/
|
||||
@Override
|
||||
public String getMessage() {
|
||||
int errorCount = 0;
|
||||
if (errors != null) {
|
||||
errorCount = errors.size();
|
||||
}
|
||||
int warningCount = 0;
|
||||
if (warnings != null) {
|
||||
warningCount = warnings.size();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(System.lineSeparator())
|
||||
.append("Errors: ")
|
||||
.append(System.lineSeparator());
|
||||
errors.forEach(msg ->
|
||||
sb.append("\t-").append(msg).append(System.lineSeparator())
|
||||
);
|
||||
|
||||
if (!warnings.isEmpty()) {
|
||||
sb.append("Warnings: ").append(System.lineSeparator());
|
||||
warnings.forEach(msg ->
|
||||
sb.append("\t-").append(msg).append(System.lineSeparator())
|
||||
);
|
||||
}
|
||||
return super.getMessage() + " | " +
|
||||
"Error count: " + errorCount + ", Warning count: " + warningCount + sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,8 @@ package org.openapitools.codegen.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.ClientOpts;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConfigLoader;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.auth.AuthParser;
|
||||
import io.swagger.parser.OpenAPIParser;
|
||||
import io.swagger.v3.core.util.Json;
|
||||
@@ -33,6 +29,7 @@ import io.swagger.v3.parser.core.models.ParseOptions;
|
||||
import io.swagger.v3.parser.core.models.SwaggerParseResult;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.openapitools.codegen.languages.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -80,6 +77,7 @@ public class CodegenConfigurator implements Serializable {
|
||||
private boolean verbose;
|
||||
private boolean skipOverwrite;
|
||||
private boolean removeOperationIdPrefix;
|
||||
private boolean validateSpec;
|
||||
private String templateDir;
|
||||
private String auth;
|
||||
private String apiPackage;
|
||||
@@ -108,6 +106,7 @@ public class CodegenConfigurator implements Serializable {
|
||||
private final Map<String, Object> dynamicProperties = new HashMap<String, Object>(); //the map that holds the JsonAnySetter/JsonAnyGetter values
|
||||
|
||||
public CodegenConfigurator() {
|
||||
this.validateSpec = true;
|
||||
this.setOutputDir(".");
|
||||
}
|
||||
|
||||
@@ -211,6 +210,15 @@ public class CodegenConfigurator implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isValidateSpec() {
|
||||
return validateSpec;
|
||||
}
|
||||
|
||||
public CodegenConfigurator setValidateSpec(final boolean validateSpec) {
|
||||
this.validateSpec = validateSpec;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isSkipOverwrite() {
|
||||
return skipOverwrite;
|
||||
}
|
||||
@@ -514,8 +522,48 @@ public class CodegenConfigurator implements Serializable {
|
||||
options.setResolve(true);
|
||||
options.setFlatten(true);
|
||||
SwaggerParseResult result = new OpenAPIParser().readLocation(inputSpec, authorizationValues, options);
|
||||
|
||||
Set<String> validationMessages = new HashSet<>(result.getMessages());
|
||||
OpenAPI specification = result.getOpenAPI();
|
||||
|
||||
// NOTE: We will only expose errors+warnings if there are already errors in the spec.
|
||||
if (validationMessages.size() > 0) {
|
||||
Set<String> warnings = new HashSet<>();
|
||||
if (specification != null) {
|
||||
List<String> unusedModels = ModelUtils.getUnusedSchemas(specification);
|
||||
if (unusedModels != null) unusedModels.forEach(name -> warnings.add("Unused model: " + name));
|
||||
}
|
||||
|
||||
if (this.isValidateSpec()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).");
|
||||
sb.append(System.lineSeparator());
|
||||
SpecValidationException ex = new SpecValidationException(sb.toString());
|
||||
ex.setErrors(validationMessages);
|
||||
ex.setWarnings(warnings);
|
||||
throw ex;
|
||||
} else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("There were issues with the specification, but validation has been explicitly disabled.");
|
||||
sb.append(System.lineSeparator());
|
||||
|
||||
sb.append("Errors: ").append(System.lineSeparator());
|
||||
validationMessages.forEach(msg ->
|
||||
sb.append("\t-").append(msg).append(System.lineSeparator())
|
||||
);
|
||||
|
||||
if (!warnings.isEmpty()) {
|
||||
sb.append("Warnings: ").append(System.lineSeparator());
|
||||
warnings.forEach(msg ->
|
||||
sb.append("\t-").append(msg).append(System.lineSeparator())
|
||||
);
|
||||
}
|
||||
LOGGER.warn(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
input.opts(new ClientOpts())
|
||||
.openAPI(result.getOpenAPI());
|
||||
.openAPI(specification);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,680 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import java.util.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.google.common.base.Strings;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.DefaultCodegen;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public abstract class AbstractApexCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractApexCodegen.class);
|
||||
|
||||
protected Boolean serializableModel = false;
|
||||
|
||||
public AbstractApexCodegen() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "apex";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates an Apex API client library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
if (this.reservedWordsMappings().containsKey(name)) {
|
||||
return this.reservedWordsMappings().get(name);
|
||||
}
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sanitizeName(String name) {
|
||||
name = super.sanitizeName(name);
|
||||
if (name.contains("__")) { // Preventing namespacing
|
||||
name.replaceAll("__", "_");
|
||||
}
|
||||
if (name.matches("^\\d.*")) { // Prevent named credentials with leading number
|
||||
name.replaceAll("^\\d.*", "");
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
if (name.toLowerCase().matches("^_*class$")) {
|
||||
return "propertyClass";
|
||||
}
|
||||
|
||||
if ("_".equals(name)) {
|
||||
name = "_u";
|
||||
}
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
if (isReservedWord(name)) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
if (startsWithTwoUppercaseLetters(name)) {
|
||||
name = name.substring(0, 2).toLowerCase() + name.substring(2);
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
private boolean startsWithTwoUppercaseLetters(String name) {
|
||||
boolean startsWithTwoUppercaseLetters = false;
|
||||
if (name.length() > 1) {
|
||||
startsWithTwoUppercaseLetters = name.substring(0, 2).equals(name.substring(0, 2).toUpperCase());
|
||||
}
|
||||
return startsWithTwoUppercaseLetters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// to avoid conflicts with 'callback' parameter for async call
|
||||
if ("callback".equals(name)) {
|
||||
return "paramCallback";
|
||||
}
|
||||
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(final String name) {
|
||||
|
||||
final String sanitizedName = sanitizeName(name);
|
||||
|
||||
String nameWithPrefixSuffix = sanitizedName;
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
// add '_' so that model name can be camelized correctly
|
||||
nameWithPrefixSuffix = modelNamePrefix + "_" + nameWithPrefixSuffix;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
// add '_' so that model name can be camelized correctly
|
||||
nameWithPrefixSuffix = nameWithPrefixSuffix + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
final String camelizedName = camelize(nameWithPrefixSuffix);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(camelizedName)) {
|
||||
final String modelName = "Model" + camelizedName;
|
||||
LOGGER.warn(camelizedName + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
// model name starts with number
|
||||
if (camelizedName.matches("^\\d.*")) {
|
||||
final String modelName = "Model" + camelizedName; // e.g. 200Response => Model200Response (after camelize)
|
||||
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
return camelizedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// should be the same as the model name
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
if (inner == null) {
|
||||
LOGGER.warn(ap.getName() + "(array property) does not have a proper inner type defined");
|
||||
// TODO maybe better defaulting to StringProperty than returning null
|
||||
return null;
|
||||
}
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
|
||||
if (inner == null) {
|
||||
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined");
|
||||
// TODO maybe better defaulting to StringProperty than returning null
|
||||
return null;
|
||||
}
|
||||
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlias(String name) {
|
||||
if (typeAliases != null && typeAliases.containsKey(name)) {
|
||||
return typeAliases.get(name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
final ArraySchema ap = (ArraySchema) p;
|
||||
final String pattern = "new ArrayList<%s>()";
|
||||
if (ap.getItems() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return String.format(pattern, getTypeDeclaration(ap.getItems()));
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
final MapSchema ap = (MapSchema) p;
|
||||
final String pattern = "new HashMap<%s>()";
|
||||
if (ap.getAdditionalProperties() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return String.format(pattern, String.format("String, %s", getTypeDeclaration((Schema) ap.getAdditionalProperties())));
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "l";
|
||||
}
|
||||
return "null";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return "null";
|
||||
} else if (ModelUtils.isFloatSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "f";
|
||||
}
|
||||
return "null";
|
||||
} else if (ModelUtils.isDoubleSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "d";
|
||||
}
|
||||
return "null";
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return "null";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
String _default = (String) p.getDefault();
|
||||
if (p.getEnum() == null) {
|
||||
return "\"" + escapeText(_default) + "\"";
|
||||
} else {
|
||||
// convert to enum var name later in postProcessModels
|
||||
return _default;
|
||||
}
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
return super.toDefaultValue(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParameterExampleValue(CodegenParameter p) {
|
||||
|
||||
if (Boolean.TRUE.equals(p.isLong)) {
|
||||
p.example = "2147483648L";
|
||||
} else if (Boolean.TRUE.equals(p.isFile)) {
|
||||
p.example = "Blob.valueOf('Sample text file\\nContents')";
|
||||
} else if (Boolean.TRUE.equals(p.isDate)) {
|
||||
p.example = "Date.newInstance(1960, 2, 17)";
|
||||
} else if (Boolean.TRUE.equals(p.isDateTime)) {
|
||||
p.example = "Datetime.newInstanceGmt(2013, 11, 12, 3, 3, 3)";
|
||||
} else if (Boolean.TRUE.equals(p.isListContainer)) {
|
||||
if (p.items != null && p.items.example != null) {
|
||||
p.example = "new " + p.dataType + "{" + p.items.example + "}";
|
||||
}
|
||||
} else if (Boolean.TRUE.equals(p.isMapContainer)) {
|
||||
if (p.items != null && p.items.example != null) {
|
||||
p.example = "new " + p.dataType + "{" + p.items.example + "}";
|
||||
}
|
||||
} else if (Boolean.TRUE.equals(p.isString)) {
|
||||
p.example = "'" + p.example + "'";
|
||||
} else if ("".equals(p.example) || p.example == null && p.dataType != "Object") {
|
||||
// Get an example object from the generated model
|
||||
if (!isReservedWord(p.dataType.toLowerCase())) {
|
||||
p.example = p.dataType + ".getExample()";
|
||||
}
|
||||
} else {
|
||||
p.example = "''";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toExampleValue(Schema p) {
|
||||
if (p == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Object obj = p.getExample();
|
||||
String example = obj == null ? "" : obj.toString();
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
example = "new " + getTypeDeclaration(p) + "{" + toExampleValue(
|
||||
((ArraySchema) p).getItems()) + "}";
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
example = String.valueOf(!"false".equals(example));
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
if (example.isEmpty()) {
|
||||
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
||||
}
|
||||
((ByteArraySchema) p).setExample(example);
|
||||
example = "EncodingUtil.base64Decode('" + example + "')";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
if (example.matches("^\\d{4}(-\\d{2}){2}")) {
|
||||
example = example.substring(0, 10).replaceAll("-0?", ", ");
|
||||
} else if (example.isEmpty()) {
|
||||
example = "2000, 1, 23";
|
||||
} else {
|
||||
LOGGER.warn(String.format("The example provided for property '%s' is not a valid RFC3339 date. Defaulting to '2000-01-23'. [%s]", p
|
||||
.getName(), example));
|
||||
example = "2000, 1, 23";
|
||||
}
|
||||
example = "Date.newInstance(" + example + ")";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
if (example.matches("^\\d{4}([-T:]\\d{2}){5}.+")) {
|
||||
example = example.substring(0, 19).replaceAll("[-T:]0?", ", ");
|
||||
} else if (example.isEmpty()) {
|
||||
example = "2000, 1, 23, 4, 56, 7";
|
||||
} else {
|
||||
LOGGER.warn(String.format("The example provided for property '%s' is not a valid RFC3339 datetime. Defaulting to '2000-01-23T04-56-07Z'. [%s]", p
|
||||
.getName(), example));
|
||||
example = "2000, 1, 23, 4, 56, 7";
|
||||
}
|
||||
example = "Datetime.newInstanceGmt(" + example + ")";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
example = example.replaceAll("[^-0-9.]", "");
|
||||
example = example.isEmpty() ? "1.3579" : example;
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
if (example.isEmpty()) {
|
||||
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
||||
p.setExample(example);
|
||||
}
|
||||
example = "EncodingUtil.base64Decode(" + example + ")";
|
||||
} else if (ModelUtils.isEmailSchema(p)) {
|
||||
if (example.isEmpty()) {
|
||||
example = "example@example.com";
|
||||
p.setExample(example);
|
||||
}
|
||||
example = "'" + example + "'";
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
example = example.isEmpty() ? "123456789L" : example + "L";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
example = "new " + getTypeDeclaration(p) + "{'key'=>" + toExampleValue((Schema) p.getAdditionalProperties()) + "}";
|
||||
|
||||
} else if (ModelUtils.isPasswordSchema(p)) {
|
||||
example = example.isEmpty() ? "password123" : escapeText(example);
|
||||
p.setExample(example);
|
||||
example = "'" + example + "'";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
List<String> enums = p.getEnum();
|
||||
if (enums != null && example.isEmpty()) {
|
||||
example = enums.get(0);
|
||||
p.setExample(example);
|
||||
} else if (example.isEmpty()) {
|
||||
example = "";
|
||||
} else {
|
||||
example = escapeText(example);
|
||||
p.setExample(example);
|
||||
}
|
||||
example = "'" + example + "'";
|
||||
} else if (ModelUtils.isUUIDSchema(p)) {
|
||||
example = example.isEmpty()
|
||||
? "'046b6c7f-0b8a-43b9-b35d-6489e6daee91'"
|
||||
: "'" + escapeText(example) + "'";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
example = example.matches("^-?\\d+$") ? example : "0";
|
||||
} else if (ModelUtils.isObjectSchema(p)) {
|
||||
example = example.isEmpty() ? "null" : example;
|
||||
} else {
|
||||
example = getTypeDeclaration(p) + ".getExample()";
|
||||
}
|
||||
return example;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchemaType(Schema p) {
|
||||
String schemaType = super.getSchemaType(p);
|
||||
|
||||
schemaType = getAlias(schemaType);
|
||||
|
||||
// don't apply renaming on types from the typeMapping
|
||||
if (typeMapping.containsKey(schemaType)) {
|
||||
return typeMapping.get(schemaType);
|
||||
}
|
||||
|
||||
if (null == schemaType) {
|
||||
LOGGER.error("No Type defined for Property " + p);
|
||||
}
|
||||
return toModelName(schemaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
return operationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Schema model, Map<String, Schema> allDefinitions) {
|
||||
CodegenModel cm = super.fromModel(name, model, allDefinitions);
|
||||
|
||||
// TODO Check enum model handling
|
||||
if (cm.interfaces == null) {
|
||||
cm.interfaces = new ArrayList<String>();
|
||||
}
|
||||
|
||||
Boolean hasDefaultValues = false;
|
||||
|
||||
// for (de)serializing properties renamed for Apex (e.g. reserved words)
|
||||
List<Map<String, String>> propertyMappings = new ArrayList<>();
|
||||
for (CodegenProperty p : cm.allVars) {
|
||||
hasDefaultValues |= p.defaultValue != null;
|
||||
if (!p.baseName.equals(p.name)) {
|
||||
Map<String, String> mapping = new HashMap<>();
|
||||
mapping.put("externalName", p.baseName);
|
||||
mapping.put("internalName", p.name);
|
||||
propertyMappings.add(mapping);
|
||||
}
|
||||
}
|
||||
|
||||
cm.vendorExtensions.put("hasPropertyMappings", !propertyMappings.isEmpty());
|
||||
cm.vendorExtensions.put("hasDefaultValues", hasDefaultValues);
|
||||
cm.vendorExtensions.put("propertyMappings", propertyMappings);
|
||||
|
||||
if (!propertyMappings.isEmpty()) {
|
||||
cm.interfaces.add("OAS.MappedProperties");
|
||||
}
|
||||
return cm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
if (parameter.isBodyParam && parameter.isListContainer) {
|
||||
// items of array bodyParams are being nested an extra level too deep for some reason
|
||||
parameter.items = parameter.items.items;
|
||||
setParameterExampleValue(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
return postProcessModelsEnum(objs);
|
||||
}
|
||||
|
||||
/* the following function is not used anywhere in this class so we'll remove it later
|
||||
private static String getAccept(Operation operation) {
|
||||
String accepts = null;
|
||||
String defaultContentType = "application/json";
|
||||
if (operation.getProduces() != null && !operation.getProduces().isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String produces : operation.getProduces()) {
|
||||
if (defaultContentType.equalsIgnoreCase(produces)) {
|
||||
accepts = defaultContentType;
|
||||
break;
|
||||
} else {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(produces);
|
||||
}
|
||||
}
|
||||
if (accepts == null) {
|
||||
accepts = sb.toString();
|
||||
}
|
||||
} else {
|
||||
accepts = defaultContentType;
|
||||
}
|
||||
|
||||
return accepts;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
protected boolean needToImport(String type) {
|
||||
return super.needToImport(type) && type.indexOf(".") < 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return sanitizeName(camelize(property.name)) + "Enum";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String value, String datatype) {
|
||||
if (value.length() == 0) {
|
||||
return "EMPTY";
|
||||
}
|
||||
|
||||
// for symbol, e.g. $, #
|
||||
if (getSymbolName(value) != null) {
|
||||
return getSymbolName(value).toUpperCase();
|
||||
}
|
||||
|
||||
// number
|
||||
if ("Integer".equals(datatype) || "Long".equals(datatype) ||
|
||||
"Float".equals(datatype) || "Double".equals(datatype)) {
|
||||
String varName = "NUMBER_" + value;
|
||||
varName = varName.replaceAll("-", "MINUS_");
|
||||
varName = varName.replaceAll("\\+", "PLUS_");
|
||||
varName = varName.replaceAll("\\.", "_DOT_");
|
||||
return varName;
|
||||
}
|
||||
|
||||
// string
|
||||
String var = value.replaceAll("\\W+", "_").toUpperCase();
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
} else {
|
||||
return var;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
if ("Integer".equals(datatype) || "Double".equals(datatype)) {
|
||||
return value;
|
||||
} else if ("Long".equals(datatype)) {
|
||||
// add l to number, e.g. 2048 => 2048l
|
||||
return value + "l";
|
||||
} else if ("Float".equals(datatype)) {
|
||||
// add f to number, e.g. 3.14 => 3.14f
|
||||
return value + "f";
|
||||
} else {
|
||||
return "\"" + escapeText(value) + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Schema> definitions, OpenAPI openAPI) {
|
||||
|
||||
CodegenOperation op = super.fromOperation(
|
||||
path, httpMethod, operation, definitions, openAPI);
|
||||
|
||||
if (op.getHasExamples()) {
|
||||
// prepare examples for Apex test classes
|
||||
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
||||
final Schema responseSchema = ModelUtils.getSchemaFromResponse(apiResponse);
|
||||
String deserializedExample = toExampleValue(responseSchema);
|
||||
for (Map<String, String> example : op.examples) {
|
||||
example.put("example", escapeText(example.get("example")));
|
||||
example.put("deserializedExample", deserializedExample);
|
||||
}
|
||||
}
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
// This generator uses inline classes to define enums, which breaks when
|
||||
// dealing with models that have subTypes. To clean this up, we will analyze
|
||||
// the parent and child models, look for enums that match, and remove
|
||||
// them from the child models and leave them in the parent.
|
||||
// Because the child models extend the parents, the enums will be available via the parent.
|
||||
|
||||
// Only bother with reconciliation if the parent model has enums.
|
||||
if (!parentCodegenModel.hasEnums) {
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
// Get the properties for the parent and child models
|
||||
final List<CodegenProperty> parentModelCodegenProperties = parentCodegenModel.vars;
|
||||
List<CodegenProperty> codegenProperties = codegenModel.vars;
|
||||
|
||||
// Iterate over all of the parent model properties
|
||||
boolean removedChildEnum = false;
|
||||
for (CodegenProperty parentModelCodegenPropery : parentModelCodegenProperties) {
|
||||
// Look for enums
|
||||
if (parentModelCodegenPropery.isEnum) {
|
||||
// Now that we have found an enum in the parent class,
|
||||
// and search the child class for the same enum.
|
||||
Iterator<CodegenProperty> iterator = codegenProperties.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
CodegenProperty codegenProperty = iterator.next();
|
||||
if (codegenProperty.isEnum && codegenProperty.equals(parentModelCodegenPropery)) {
|
||||
// We found an enum in the child class that is
|
||||
// a duplicate of the one in the parent, so remove it.
|
||||
iterator.remove();
|
||||
removedChildEnum = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (removedChildEnum) {
|
||||
// If we removed an entry from this model's vars, we need to ensure hasMore is updated
|
||||
int count = 0, numVars = codegenProperties.size();
|
||||
for (CodegenProperty codegenProperty : codegenProperties) {
|
||||
count += 1;
|
||||
codegenProperty.hasMore = (count < numVars) ? true : false;
|
||||
}
|
||||
codegenModel.vars = codegenProperties;
|
||||
}
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
private static String sanitizePackageName(String packageName) {
|
||||
packageName = packageName.trim(); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
|
||||
if (Strings.isNullOrEmpty(packageName)) {
|
||||
return "invalidPackageName";
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
|
||||
public void setSerializableModel(Boolean serializableModel) {
|
||||
this.serializableModel = serializableModel;
|
||||
}
|
||||
|
||||
private String sanitizePath(String p) {
|
||||
//prefer replace a ", instead of a fuLL URL encode for readability
|
||||
return p.replaceAll("\"", "%22");
|
||||
}
|
||||
|
||||
public String toRegularExpression(String pattern) {
|
||||
return escapeText(pattern);
|
||||
}
|
||||
|
||||
public boolean convertPropertyToBoolean(String propertyKey) {
|
||||
boolean booleanValue = false;
|
||||
if (additionalProperties.containsKey(propertyKey)) {
|
||||
booleanValue = Boolean.valueOf(additionalProperties.get(propertyKey).toString());
|
||||
}
|
||||
|
||||
return booleanValue;
|
||||
}
|
||||
|
||||
public void writePropertyBack(String propertyKey, boolean value) {
|
||||
additionalProperties.put(propertyKey, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sanitizeTag(String tag) {
|
||||
return camelize(sanitizeName(tag));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelTestFilename(String name) {
|
||||
return toModelName(name) + "Test";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -603,6 +603,12 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +128,38 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String type) {
|
||||
return sanitizeName(modelNamePrefix + Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
if (type == null) {
|
||||
LOGGER.warn("Model name can't be null. Default to 'UnknownModel'.");
|
||||
type = "UnknownModel";
|
||||
}
|
||||
|
||||
if (typeMapping.keySet().contains(type) || typeMapping.values().contains(type)
|
||||
|| importMapping.values().contains(type) || defaultIncludes.contains(type)
|
||||
|| languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
} else {
|
||||
return sanitizeName(modelNamePrefix + Character.toUpperCase(type.charAt(0)) + type.substring(1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
if (typeMapping.keySet().contains(name) || typeMapping.values().contains(name)
|
||||
|
||||
@@ -37,6 +37,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGoCodegen.class);
|
||||
|
||||
protected boolean withGoCodegenComment = false;
|
||||
protected boolean withXml = false;
|
||||
|
||||
protected String packageName = "openapi";
|
||||
@@ -144,7 +145,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
|
||||
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = sanitizeName(name);
|
||||
|
||||
@@ -266,10 +267,10 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
// the type.
|
||||
String openAPIType = getSchemaType(p);
|
||||
String ref = p.get$ref();
|
||||
if(ref != null && !ref.isEmpty()) {
|
||||
if (ref != null && !ref.isEmpty()) {
|
||||
String tryRefV2 = "#/definitions/" + openAPIType;
|
||||
String tryRefV3 = "#/components/schemas/" + openAPIType;
|
||||
if(ref.equals(tryRefV2) || ref.equals(tryRefV3)) {
|
||||
if (ref.equals(tryRefV2) || ref.equals(tryRefV3)) {
|
||||
return toModelName(openAPIType);
|
||||
}
|
||||
}
|
||||
@@ -295,7 +296,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
String ref = p.get$ref();
|
||||
String type = null;
|
||||
|
||||
if(ref != null && !ref.isEmpty()) {
|
||||
if (ref != null && !ref.isEmpty()) {
|
||||
type = openAPIType;
|
||||
} else if (typeMapping.containsKey(openAPIType)) {
|
||||
type = typeMapping.get(openAPIType);
|
||||
@@ -313,7 +314,13 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(sanitizedOperationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to "
|
||||
+ camelize("call_" + operationId));
|
||||
+ camelize("call_" + sanitizedOperationId));
|
||||
sanitizedOperationId = "call_" + sanitizedOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (sanitizedOperationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize("call_" + sanitizedOperationId));
|
||||
sanitizedOperationId = "call_" + sanitizedOperationId;
|
||||
}
|
||||
|
||||
@@ -563,8 +570,10 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
enumName = enumName.replaceFirst("_$", "");
|
||||
|
||||
if (isReservedWord(enumName) || enumName.matches("\\d.*")) { // reserved word or starts with number
|
||||
if (isReservedWord(enumName)) { // reserved word
|
||||
return escapeReservedWord(enumName);
|
||||
} else if (enumName.matches("\\d.*")) { // starts with a number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
@@ -584,6 +593,10 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
}
|
||||
}
|
||||
|
||||
public void setWithGoCodegenComment(boolean withGoCodegenComment) {
|
||||
this.withGoCodegenComment = withGoCodegenComment;
|
||||
}
|
||||
|
||||
public void setWithXml(boolean withXml) {
|
||||
this.withXml = withXml;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
public static final String DISABLE_HTML_ESCAPING = "disableHtmlEscaping";
|
||||
public static final String BOOLEAN_GETTER_PREFIX = "booleanGetterPrefix";
|
||||
public static final String BOOLEAN_GETTER_PREFIX_DEFAULT = "get";
|
||||
public static final String USE_NULL_FOR_UNKNOWN_ENUM_VALUE = "useNullForUnknownEnumValue";
|
||||
|
||||
protected String dateLibrary = "threetenbp";
|
||||
protected boolean supportAsync = false;
|
||||
@@ -99,6 +100,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
protected boolean supportJava6= false;
|
||||
protected boolean disableHtmlEscaping = false;
|
||||
protected String booleanGetterPrefix = BOOLEAN_GETTER_PREFIX_DEFAULT;
|
||||
protected boolean useNullForUnknownEnumValue = false;
|
||||
|
||||
public AbstractJavaCodegen() {
|
||||
super();
|
||||
@@ -213,6 +215,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
additionalProperties.put(BOOLEAN_GETTER_PREFIX, booleanGetterPrefix);
|
||||
|
||||
if (additionalProperties.containsKey(USE_NULL_FOR_UNKNOWN_ENUM_VALUE)) {
|
||||
this.setUseNullForUnknownEnumValue(Boolean.valueOf(additionalProperties.get(USE_NULL_FOR_UNKNOWN_ENUM_VALUE).toString()));
|
||||
}
|
||||
additionalProperties.put(USE_NULL_FOR_UNKNOWN_ENUM_VALUE, useNullForUnknownEnumValue);
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||
} else if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
|
||||
@@ -574,6 +581,14 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
name = name.substring(0, 2).toLowerCase() + name.substring(2);
|
||||
}
|
||||
|
||||
// If name contains special chars -> replace them.
|
||||
if ((((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains( "" + ((char) character))))) {
|
||||
List<String> allowedCharacters = new ArrayList<>();
|
||||
allowedCharacters.add("_");
|
||||
allowedCharacters.add("$");
|
||||
name = escapeSpecialCharacters(name, allowedCharacters, "_");
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
@@ -869,6 +884,12 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
|
||||
operationId = camelize("call_" + operationId, true);
|
||||
}
|
||||
|
||||
return operationId;
|
||||
}
|
||||
|
||||
@@ -1246,6 +1267,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
this.booleanGetterPrefix = booleanGetterPrefix;
|
||||
}
|
||||
|
||||
public void setUseNullForUnknownEnumValue(boolean useNullForUnknownEnumValue) {
|
||||
this.useNullForUnknownEnumValue = useNullForUnknownEnumValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
|
||||
@@ -23,13 +23,9 @@ import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.DefaultCodegen;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
|
||||
import java.io.File;
|
||||
@@ -50,7 +46,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPhpCodegen.class);
|
||||
|
||||
public static final String VARIABLE_NAMING_CONVENTION = "variableNamingConvention";
|
||||
public static final String PACKAGE_PATH = "packagePath";
|
||||
public static final String PACKAGE_NAME = "packageName";
|
||||
public static final String SRC_BASE_PATH = "srcBasePath";
|
||||
// composerVendorName/composerProjectName has be replaced by gitUserId/gitRepoId. prepare to remove these.
|
||||
// public static final String COMPOSER_VENDOR_NAME = "composerVendorName";
|
||||
@@ -58,7 +54,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
// protected String composerVendorName = null;
|
||||
// protected String composerProjectName = null;
|
||||
protected String invokerPackage = "php";
|
||||
protected String packagePath = "php-base";
|
||||
protected String packageName = "php-base";
|
||||
protected String artifactVersion = null;
|
||||
protected String srcBasePath = "lib";
|
||||
protected String testBasePath = "test";
|
||||
@@ -144,8 +140,8 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
cliOptions.add(new CliOption(VARIABLE_NAMING_CONVENTION, "naming convention of variable name, e.g. camelCase.")
|
||||
.defaultValue("snake_case"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, "The main namespace to use for all classes. e.g. Yay\\Pets"));
|
||||
cliOptions.add(new CliOption(PACKAGE_PATH, "The main package name for classes. e.g. GeneratedPetstore"));
|
||||
cliOptions.add(new CliOption(SRC_BASE_PATH, "The directory under packagePath to serve as source root."));
|
||||
cliOptions.add(new CliOption(PACKAGE_NAME, "The main package name for classes. e.g. GeneratedPetstore"));
|
||||
cliOptions.add(new CliOption(SRC_BASE_PATH, "The directory to serve as source root."));
|
||||
// cliOptions.add(new CliOption(COMPOSER_VENDOR_NAME, "The vendor name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. yaypets. IMPORTANT NOTE (2016/03): composerVendorName will be deprecated and replaced by gitUserId in the next openapi-generator release"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.GIT_USER_ID, CodegenConstants.GIT_USER_ID_DESC));
|
||||
// cliOptions.add(new CliOption(COMPOSER_PROJECT_NAME, "The project name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. petstore-client. IMPORTANT NOTE (2016/03): composerProjectName will be deprecated and replaced by gitRepoId in the next openapi-generator release"));
|
||||
@@ -157,10 +153,10 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(PACKAGE_PATH)) {
|
||||
this.setPackagePath((String) additionalProperties.get(PACKAGE_PATH));
|
||||
if (additionalProperties.containsKey(PACKAGE_NAME)) {
|
||||
this.setPackageName((String) additionalProperties.get(PACKAGE_NAME));
|
||||
} else {
|
||||
additionalProperties.put(PACKAGE_PATH, packagePath);
|
||||
additionalProperties.put(PACKAGE_NAME, packageName);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SRC_BASE_PATH)) {
|
||||
@@ -228,10 +224,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);
|
||||
@@ -240,22 +236,18 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
// make test path available in mustache template
|
||||
additionalProperties.put("testBasePath", testBasePath);
|
||||
|
||||
// // apache v2 license
|
||||
// supportingFiles.add(new SupportingFile("LICENSE", getPackagePath(), "LICENSE"));
|
||||
// apache v2 license
|
||||
// supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
|
||||
}
|
||||
|
||||
public String getPackagePath() {
|
||||
return packagePath;
|
||||
}
|
||||
|
||||
public String toPackagePath(String packageName, String basePath) {
|
||||
return (getPackagePath() + File.separatorChar + toSrcPath(packageName, basePath));
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
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 +266,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
|
||||
@@ -291,32 +283,32 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return (outputFolder + File.separator + toPackagePath(apiPackage, srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(apiPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + File.separator + toPackagePath(modelPackage, srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(modelPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return (outputFolder + File.separator + getPackagePath() + File.separator + testBasePath + File.separator + apiDirName);
|
||||
return (outputFolder + File.separator + testBasePath + File.separator + apiDirName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return (outputFolder + File.separator + getPackagePath() + File.separator + testBasePath + File.separator + modelDirName);
|
||||
return (outputFolder + File.separator + testBasePath + File.separator + modelDirName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
return (outputFolder + File.separator + getPackagePath() + File.separator + apiDocPath);
|
||||
return (outputFolder + File.separator + apiDocPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
return (outputFolder + File.separator + getPackagePath() + File.separator + modelDocPath);
|
||||
return (outputFolder + File.separator + modelDocPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -386,8 +378,8 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
this.artifactVersion = artifactVersion;
|
||||
}
|
||||
|
||||
public void setPackagePath(String packagePath) {
|
||||
this.packagePath = packagePath;
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public void setSrcBasePath(String srcBasePath) {
|
||||
@@ -500,6 +492,12 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
}
|
||||
|
||||
@@ -702,6 +700,22 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
return super.escapeText(input).trim();
|
||||
}
|
||||
|
||||
public void escapeMediaType(List<CodegenOperation> operationList) {
|
||||
for (CodegenOperation op : operationList) {
|
||||
if (!op.hasProduces) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<Map<String, String>> c = op.produces;
|
||||
for (Map<String, String> mediaType : c) {
|
||||
// "*/*" causes a syntax error
|
||||
if ("*/*".equals(mediaType.get("mediaType"))) {
|
||||
mediaType.put("mediaType", "*_/_*");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String extractSimpleName(String phpClassName) {
|
||||
if (phpClassName == null) {
|
||||
return null;
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.NumberSchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.parameters.Parameter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -157,7 +156,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name, "\\W-[\\$]");
|
||||
|
||||
if ("_".equals(name)) {
|
||||
name = "_u";
|
||||
|
||||
@@ -17,65 +17,43 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.BooleanSchema;
|
||||
import io.swagger.v3.oas.models.media.ByteArraySchema;
|
||||
import io.swagger.v3.oas.models.media.EmailSchema;
|
||||
import io.swagger.v3.oas.models.media.FileSchema;
|
||||
import io.swagger.v3.oas.models.media.PasswordSchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.oas.models.info.*;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
public class ApexClientCodegen extends AbstractApexCodegen {
|
||||
|
||||
private static final String CLASS_PREFIX = "classPrefix";
|
||||
private static final String API_VERSION = "apiVersion";
|
||||
private static final String BUILD_METHOD = "buildMethod";
|
||||
private static final String NAMED_CREDENTIAL = "namedCredential";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ApexClientCodegen.class);
|
||||
private String classPrefix = "Swag";
|
||||
private String apiVersion = "39.0";
|
||||
private String classPrefix = "OAS";
|
||||
private String apiVersion = "42.0";
|
||||
private String buildMethod = "sfdx";
|
||||
private String namedCredential = classPrefix;
|
||||
private String srcPath = "force-app/main/default/";
|
||||
private String sfdxConfigPath = "config/";
|
||||
private HashMap<String, Object> primitiveDefaults = new HashMap<String, Object>();
|
||||
|
||||
public ApexClientCodegen() {
|
||||
super();
|
||||
|
||||
importMapping.clear();
|
||||
|
||||
testFolder = sourceFolder = srcPath;
|
||||
|
||||
embeddedTemplateDir = templateDir = "apex";
|
||||
outputFolder = "generated-code" + File.separator + "apex";
|
||||
apiPackage = "classes";
|
||||
modelPackage = "classes";
|
||||
modelPackage = apiPackage = srcPath + "classes";
|
||||
testPackage = "force-app.main.default.classes";
|
||||
modelNamePrefix = classPrefix;
|
||||
dateLibrary = "";
|
||||
|
||||
apiTemplateFiles.put("api.mustache", ".cls");
|
||||
apiTemplateFiles.put("cls-meta.mustache", ".cls-meta.xml");
|
||||
@@ -91,12 +69,12 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
cliOptions.add(CliOption.newString(BUILD_METHOD, "The build method for this package."));
|
||||
cliOptions.add(CliOption.newString(NAMED_CREDENTIAL, "The named credential name for the HTTP callouts"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("Swagger.cls", srcPath + "classes", "Swagger.cls"));
|
||||
supportingFiles.add(new SupportingFile("cls-meta.mustache", srcPath + "classes", "Swagger.cls-meta.xml"));
|
||||
supportingFiles.add(new SupportingFile("SwaggerTest.cls", srcPath + "classes", "SwaggerTest.cls"));
|
||||
supportingFiles.add(new SupportingFile("cls-meta.mustache", srcPath + "classes", "SwaggerTest.cls-meta.xml"));
|
||||
supportingFiles.add(new SupportingFile("SwaggerResponseMock.cls", srcPath + "classes", "SwaggerResponseMock.cls"));
|
||||
supportingFiles.add(new SupportingFile("cls-meta.mustache", srcPath + "classes", "SwaggerResponseMock.cls-meta.xml"));
|
||||
supportingFiles.add(new SupportingFile("OAS.cls", srcPath + "classes", "OAS.cls"));
|
||||
supportingFiles.add(new SupportingFile("cls-meta.mustache", srcPath + "classes", "OAS.cls-meta.xml"));
|
||||
supportingFiles.add(new SupportingFile("OASTest.cls", srcPath + "classes", "OASTest.cls"));
|
||||
supportingFiles.add(new SupportingFile("cls-meta.mustache", srcPath + "classes", "OASTest.cls-meta.xml"));
|
||||
supportingFiles.add(new SupportingFile("OASResponseMock.cls", srcPath + "classes", "OASResponseMock.cls"));
|
||||
supportingFiles.add(new SupportingFile("cls-meta.mustache", srcPath + "classes", "OASResponseMock.cls-meta.xml"));
|
||||
|
||||
typeMapping.put("BigDecimal", "Double");
|
||||
typeMapping.put("binary", "String");
|
||||
@@ -109,14 +87,15 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
typeMapping.put("short", "Integer");
|
||||
typeMapping.put("UUID", "String");
|
||||
|
||||
// https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_reserved_words.htm
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList("abstract", "activate", "and", "any", "array", "as", "asc", "autonomous",
|
||||
"begin", "bigdecimal", "blob", "break", "bulk", "by", "byte", "case", "cast",
|
||||
"catch", "char", "class", "collect", "commit", "const", "continue",
|
||||
"convertcurrency", "date", "decimal", "default", "delete", "desc", "do", "else",
|
||||
"convertcurrency", "currency", "date", "datetime", "decimal", "default", "delete", "desc", "do", "else",
|
||||
"end", "enum", "exception", "exit", "export", "extends", "false", "final",
|
||||
"finally", "float", "for", "from", "future", "global", "goto", "group", "having",
|
||||
"hint", "if", "implements", "import", "inner", "insert", "instanceof", "int",
|
||||
"hint", "if", "implements", "import", "in", "inner", "insert", "instanceof", "int",
|
||||
"interface", "into", "join", "last_90_days", "last_month", "last_n_days",
|
||||
"last_week", "like", "limit", "list", "long", "loop", "map", "merge", "new",
|
||||
"next_90_days", "next_month", "next_n_days", "next_week", "not", "null", "nulls",
|
||||
@@ -124,7 +103,7 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
"pragma", "private", "protected", "public", "retrieve", "return", "returning",
|
||||
"rollback", "savepoint", "search", "select", "set", "short", "sort", "stat",
|
||||
"static", "super", "switch", "synchronized", "system", "testmethod", "then", "this",
|
||||
"this_month", "this_week", "throw", "today", "tolabel", "tomorrow", "transaction",
|
||||
"this_month", "this_week", "throw", "time", "today", "tolabel", "tomorrow", "transaction",
|
||||
"trigger", "true", "try", "type", "undelete", "update", "upsert", "using",
|
||||
"virtual", "webservice", "when", "where", "while", "yesterday"
|
||||
));
|
||||
@@ -133,6 +112,17 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
Arrays.asList("Blob", "Boolean", "Date", "Datetime", "Decimal", "Double", "ID",
|
||||
"Integer", "Long", "Object", "String", "Time"
|
||||
));
|
||||
|
||||
primitiveDefaults.put("Boolean", true);
|
||||
primitiveDefaults.put("Decimal", 1);
|
||||
primitiveDefaults.put("Double", 1);
|
||||
primitiveDefaults.put("Integer", 1);
|
||||
primitiveDefaults.put("Long", 1);
|
||||
primitiveDefaults.put("String", "");
|
||||
|
||||
instantiationTypes.put("array", "List");
|
||||
instantiationTypes.put("map", "Map");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,6 +152,48 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
postProcessOpts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
Info info = openAPI.getInfo();
|
||||
String calloutLabel = info.getTitle();
|
||||
additionalProperties.put("calloutLabel", calloutLabel);
|
||||
String sanitized = sanitizeName(calloutLabel);
|
||||
additionalProperties.put("calloutName", sanitized);
|
||||
supportingFiles.add(new SupportingFile("namedCredential.mustache", srcPath + "/namedCredentials",
|
||||
sanitized + ".namedCredential-meta.xml"
|
||||
));
|
||||
|
||||
if (additionalProperties.get(BUILD_METHOD).equals("sfdx")) {
|
||||
generateSfdxSupportingFiles();
|
||||
} else if (additionalProperties.get(BUILD_METHOD).equals("ant")) {
|
||||
generateAntSupportingFiles();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
return input.replace("'", "\\'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeText(String input) {
|
||||
if (input == null) {
|
||||
return input;
|
||||
}
|
||||
|
||||
return input.replace("'", "\\'").replace("\n", "\\n").replace("\r", "\\r").replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
return camelize(classPrefix + super.toApiName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
// Identifiers must start with a letter
|
||||
@@ -191,16 +223,19 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
// true => "true", false => "false", null => "null"
|
||||
out = String.valueOf(((BooleanSchema) p).getDefault());
|
||||
} else if (ModelUtils.isLongSchema(p)) { // long
|
||||
out = p.getDefault() == null ? out : p.getDefault().toString() + "L";
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
Long def = (Long) p.getDefault();
|
||||
out = def == null ? out : def.toString() + "L";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
String s = inner == null ? "Object" : getTypeDeclaration(inner);
|
||||
out = String.format("new Map<String, %s>()", s);
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
String def = (String) p.getDefault();
|
||||
if (def != null) {
|
||||
out = p.getEnum() == null ? String.format("'%s'", escapeText(def)) : def;
|
||||
if (p.getDefault() != null) {
|
||||
String def = p.getDefault().toString();
|
||||
if (def != null) {
|
||||
out = p.getEnum() == null ? String.format("'%s'", escapeText(def)) : def;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out = super.toDefaultValue(p);
|
||||
@@ -210,256 +245,10 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
return "null".equals(out) ? null : out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParameterExampleValue(CodegenParameter p) {
|
||||
String example;
|
||||
|
||||
if (p.defaultValue == null) {
|
||||
example = p.example;
|
||||
} else {
|
||||
example = p.defaultValue;
|
||||
}
|
||||
|
||||
String type = p.baseType;
|
||||
if (type == null) {
|
||||
type = p.dataType;
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(p.isInteger)) {
|
||||
if (example == null) {
|
||||
example = "56";
|
||||
}
|
||||
} else if (Boolean.TRUE.equals(p.isLong)) {
|
||||
if (example == null) {
|
||||
example = "2147483648L";
|
||||
}
|
||||
} else if (Boolean.TRUE.equals(p.isDouble)
|
||||
|| Boolean.TRUE.equals(p.isFloat)
|
||||
|| Boolean.TRUE.equals(p.isNumber)) {
|
||||
if (example == null) {
|
||||
example = "3.4";
|
||||
}
|
||||
} else if (Boolean.TRUE.equals(p.isBoolean)) {
|
||||
if (Boolean.parseBoolean(p.example)) {
|
||||
p.example = "1";
|
||||
} else {
|
||||
p.example = "0";
|
||||
}
|
||||
} else if (Boolean.TRUE.equals(p.isFile) || Boolean.TRUE.equals(p.isBinary)) {
|
||||
example = "Blob.valueOf('Sample text file\\nContents')";
|
||||
} else if (Boolean.TRUE.equals(p.isByteArray)) {
|
||||
if (example == null) {
|
||||
example = "YmFzZSA2NCBkYXRh";
|
||||
}
|
||||
example = "\"" + escapeText(example) + "\"";
|
||||
} else if (Boolean.TRUE.equals(p.isDate)) {
|
||||
if (example == null) {
|
||||
example = "1960, 2, 17";
|
||||
}
|
||||
example = "Date.newInstance(" + escapeText(p.example) + ")";
|
||||
} else if (Boolean.TRUE.equals(p.isDateTime)) {
|
||||
if (example == null) {
|
||||
example = "2013, 11, 12, 3, 3, 3";
|
||||
}
|
||||
example = "Datetime.newInstanceGmt(" + escapeText(p.example) + ")";
|
||||
} else if (Boolean.TRUE.equals(p.isString)) {
|
||||
if (example == null) {
|
||||
example = p.paramName + "_example";
|
||||
}
|
||||
example = "\'" + escapeText(example) + "\'";
|
||||
|
||||
} else if (!languageSpecificPrimitives.contains(type)) {
|
||||
// type is a model class, e.g. User
|
||||
example = type + ".getExample()";
|
||||
}
|
||||
|
||||
// container
|
||||
if (Boolean.TRUE.equals(p.isListContainer)) {
|
||||
example = setPropertyExampleValue(p.items);
|
||||
example = "new " + p.dataType + "{" + example + "}";
|
||||
} else if (Boolean.TRUE.equals(p.isMapContainer)) {
|
||||
example = setPropertyExampleValue(p.items);
|
||||
example = "new " + p.dataType + "{" + example + "}";
|
||||
} else if (example == null) {
|
||||
example = "null";
|
||||
}
|
||||
|
||||
p.example = example;
|
||||
}
|
||||
|
||||
protected String setPropertyExampleValue(CodegenProperty p) {
|
||||
String example;
|
||||
|
||||
if (p == null) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
if (p.defaultValue == null) {
|
||||
example = p.example;
|
||||
} else {
|
||||
example = p.defaultValue;
|
||||
}
|
||||
|
||||
String type = p.baseType;
|
||||
if (type == null) {
|
||||
type = p.dataType;
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(p.isInteger)) {
|
||||
if (example == null) {
|
||||
example = "56";
|
||||
}
|
||||
} else if (Boolean.TRUE.equals(p.isLong)) {
|
||||
if (example == null) {
|
||||
example = "2147483648L";
|
||||
}
|
||||
} else if (Boolean.TRUE.equals(p.isDouble)
|
||||
|| Boolean.TRUE.equals(p.isFloat)
|
||||
|| Boolean.TRUE.equals(p.isNumber)) {
|
||||
if (example == null) {
|
||||
example = "3.4";
|
||||
}
|
||||
} else if (Boolean.TRUE.equals(p.isBoolean)) {
|
||||
if (example == null) {
|
||||
example = "true";
|
||||
}
|
||||
} else if (Boolean.TRUE.equals(p.isFile) || Boolean.TRUE.equals(p.isBinary)) {
|
||||
if (example == null) {
|
||||
example = "Blob.valueOf('Sample text file\\nContents')";
|
||||
}
|
||||
example = escapeText(example);
|
||||
} else if (Boolean.TRUE.equals(p.isDate)) {
|
||||
if (example == null) {
|
||||
example = "1960, 2, 17";
|
||||
}
|
||||
example = "Date.newInstance(" + escapeText(p.example) + ")";
|
||||
} else if (Boolean.TRUE.equals(p.isDateTime)) {
|
||||
if (example == null) {
|
||||
example = "2013, 11, 12, 3, 3, 3";
|
||||
}
|
||||
example = "Datetime.newInstanceGmt(" + escapeText(p.example) + ")";
|
||||
} else if (Boolean.TRUE.equals(p.isString)) {
|
||||
if (example == null) {
|
||||
example = p.name + "_example";
|
||||
}
|
||||
example = "\'" + escapeText(example) + "\'";
|
||||
|
||||
} else if (!languageSpecificPrimitives.contains(type)) {
|
||||
// type is a model class, e.g. User
|
||||
example = type + ".getExample()";
|
||||
}
|
||||
|
||||
return example;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Schema model, Map<String, Schema> allDefinitions) {
|
||||
CodegenModel cm = super.fromModel(name, model, allDefinitions);
|
||||
if (cm.interfaces == null) {
|
||||
cm.interfaces = new ArrayList<String>();
|
||||
}
|
||||
|
||||
Boolean hasDefaultValues = false;
|
||||
|
||||
// for (de)serializing properties renamed for Apex (e.g. reserved words)
|
||||
List<Map<String, String>> propertyMappings = new ArrayList<>();
|
||||
for (CodegenProperty p : cm.allVars) {
|
||||
hasDefaultValues |= p.defaultValue != null;
|
||||
if (!p.baseName.equals(p.name)) {
|
||||
Map<String, String> mapping = new HashMap<>();
|
||||
mapping.put("externalName", p.baseName);
|
||||
mapping.put("internalName", p.name);
|
||||
propertyMappings.add(mapping);
|
||||
}
|
||||
}
|
||||
|
||||
cm.vendorExtensions.put("hasPropertyMappings", !propertyMappings.isEmpty());
|
||||
cm.vendorExtensions.put("hasDefaultValues", hasDefaultValues);
|
||||
cm.vendorExtensions.put("propertyMappings", propertyMappings);
|
||||
|
||||
if (!propertyMappings.isEmpty()) {
|
||||
cm.interfaces.add("Swagger.MappedProperties");
|
||||
}
|
||||
return cm;
|
||||
}
|
||||
|
||||
/* the following workaround is no longer needed
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
if (parameter.isBodyParam && parameter.isListContainer) {
|
||||
// items of array bodyParams are being nested an extra level too deep for some reason
|
||||
parameter.items = parameter.items.items;
|
||||
setParameterExampleValue(parameter);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
Info info = openAPI.getInfo();
|
||||
String calloutLabel = info.getTitle();
|
||||
additionalProperties.put("calloutLabel", calloutLabel);
|
||||
String sanitized = sanitizeName(calloutLabel);
|
||||
additionalProperties.put("calloutName", sanitized);
|
||||
supportingFiles.add(new SupportingFile("namedCredential.mustache", srcPath + "/namedCredentials",
|
||||
sanitized + ".namedCredential"
|
||||
));
|
||||
|
||||
if (additionalProperties.get(BUILD_METHOD).equals("sfdx")) {
|
||||
generateSfdxSupportingFiles();
|
||||
} else if (additionalProperties.get(BUILD_METHOD).equals("ant")) {
|
||||
generateAntSupportingFiles();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path,
|
||||
String httpMethod,
|
||||
Operation operation,
|
||||
Map<String, Schema> definitions,
|
||||
OpenAPI openAPI) {
|
||||
Boolean hasFormParams = false;
|
||||
// comment out the following as there's no consume/produce in OAS3.0
|
||||
// we can move the logic below to postProcessOperations if needed
|
||||
/*
|
||||
// only support serialization into JSON and urlencoded forms for now
|
||||
operation.setConsumes(
|
||||
Collections.singletonList(hasFormParameter(operation)
|
||||
? "application/x-www-form-urlencoded"
|
||||
: "application/json"));
|
||||
|
||||
// only support deserialization from JSON for now
|
||||
operation.setProduces(Collections.singletonList("application/json"));
|
||||
*/
|
||||
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, openAPI);
|
||||
|
||||
if (op.getHasExamples()) {
|
||||
// prepare examples for Apex test classes
|
||||
ApiResponse responseProperty = findMethodResponse(operation.getResponses());
|
||||
String deserializedExample = toExampleValue(ModelUtils.getSchemaFromResponse(responseProperty));
|
||||
for (Map<String, String> example : op.examples) {
|
||||
example.put("example", escapeText(example.get("example")));
|
||||
example.put("deserializedExample", deserializedExample);
|
||||
}
|
||||
}
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
return input.replace("'", "\\'");
|
||||
}
|
||||
|
||||
public void setBuildMethod(String buildMethod) {
|
||||
if (buildMethod.equals("ant")) {
|
||||
this.srcPath = "deploy/";
|
||||
} else {
|
||||
this.srcPath = "src/";
|
||||
}
|
||||
testFolder = sourceFolder = srcPath;
|
||||
this.buildMethod = buildMethod;
|
||||
}
|
||||
|
||||
@@ -494,114 +283,6 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeText(String input) {
|
||||
if (input == null) {
|
||||
return input;
|
||||
}
|
||||
|
||||
return input.replace("'", "\\'").replace("\n", "\\n").replace("\r", "\\r");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelTestFilename(String name) {
|
||||
return toModelName(name) + "Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toExampleValue(Schema p) {
|
||||
if (p == null) {
|
||||
return "";
|
||||
}
|
||||
Object obj = p.getExample();
|
||||
String example = obj == null ? "" : obj.toString();
|
||||
if (ModelUtils.isArraySchema(p)) { // array
|
||||
example = "new " + getTypeDeclaration(p) + "{" + toExampleValue(
|
||||
((ArraySchema) p).getItems()) + "}";
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
example = String.valueOf(!"false".equals(example));
|
||||
} else if (ModelUtils.isByteArraySchema(p)) { // byte array
|
||||
if (example.isEmpty()) {
|
||||
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
||||
}
|
||||
((ByteArraySchema) p).setExample(example);
|
||||
example = "EncodingUtil.base64Decode('" + example + "')";
|
||||
} else if (ModelUtils.isDateSchema(p)) { // date
|
||||
if (example.matches("^\\d{4}(-\\d{2}){2}")) {
|
||||
example = example.substring(0, 10).replaceAll("-0?", ", ");
|
||||
} else if (example.isEmpty()) {
|
||||
example = "2000, 1, 23";
|
||||
} else {
|
||||
LOGGER.warn(String.format("The example provided for property '%s' is not a valid RFC3339 date. Defaulting to '2000-01-23'. [%s]", p
|
||||
.getName(), example));
|
||||
example = "2000, 1, 23";
|
||||
}
|
||||
example = "Date.newInstance(" + example + ")";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) { // datetime
|
||||
if (example.matches("^\\d{4}([-T:]\\d{2}){5}.+")) {
|
||||
example = example.substring(0, 19).replaceAll("[-T:]0?", ", ");
|
||||
} else if (example.isEmpty()) {
|
||||
example = "2000, 1, 23, 4, 56, 7";
|
||||
} else {
|
||||
LOGGER.warn(String.format("The example provided for property '%s' is not a valid RFC3339 datetime. Defaulting to '2000-01-23T04-56-07Z'. [%s]", p
|
||||
.getName(), example));
|
||||
example = "2000, 1, 23, 4, 56, 7";
|
||||
}
|
||||
example = "Datetime.newInstanceGmt(" + example + ")";
|
||||
} else if (ModelUtils.isNumberSchema(p)) { // number
|
||||
example = example.replaceAll("[^-0-9.]", "");
|
||||
example = example.isEmpty() ? "1.3579" : example;
|
||||
} else if (ModelUtils.isFileSchema(p)) { // file
|
||||
if (example.isEmpty()) {
|
||||
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
||||
((FileSchema) p).setExample(example);
|
||||
}
|
||||
example = "EncodingUtil.base64Decode(" + example + ")";
|
||||
} else if (ModelUtils.isEmailSchema(p)) { // email
|
||||
if (example.isEmpty()) {
|
||||
example = "example@example.com";
|
||||
((EmailSchema) p).setExample(example);
|
||||
}
|
||||
example = "'" + example + "'";
|
||||
} else if (ModelUtils.isLongSchema(p)) { // long
|
||||
example = example.isEmpty() ? "123456789L" : example + "L";
|
||||
} else if (ModelUtils.isMapSchema(p)) { // map
|
||||
example = "new " + getTypeDeclaration(p) + "{'key'=>" + toExampleValue(
|
||||
(Schema) p.getAdditionalProperties()) + "}";
|
||||
} else if (ModelUtils.isObjectSchema(p)) { // object
|
||||
example = example.isEmpty() ? "null" : example;
|
||||
} else if (ModelUtils.isPasswordSchema(p)) { // password
|
||||
example = example.isEmpty() ? "password123" : escapeText(example);
|
||||
((PasswordSchema) p).setExample(example);
|
||||
example = "'" + example + "'";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
example = getTypeDeclaration(p) + ".getExample()";
|
||||
} else if (ModelUtils.isUUIDSchema(p)) {
|
||||
example = example.isEmpty()
|
||||
? "'046b6c7f-0b8a-43b9-b35d-6489e6daee91'"
|
||||
: "'" + escapeText(example) + "'";
|
||||
} else if (ModelUtils.isStringSchema(p)) { // string
|
||||
List<String> enums = p.getEnum();
|
||||
if (enums != null && example.isEmpty()) {
|
||||
example = enums.get(0);
|
||||
p.setExample(example);
|
||||
} else if (example.isEmpty()) {
|
||||
example = "aeiou";
|
||||
} else {
|
||||
example = escapeText(example);
|
||||
p.setExample(example);
|
||||
}
|
||||
example = "'" + example + "'";
|
||||
}
|
||||
|
||||
return example;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
return camelize(classPrefix + super.toApiName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCodegenPropertyEnum(CodegenProperty var) {
|
||||
super.updateCodegenPropertyEnum(var);
|
||||
@@ -612,21 +293,6 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "apex";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates an Apex API client library (beta).";
|
||||
}
|
||||
|
||||
private void generateAntSupportingFiles() {
|
||||
|
||||
supportingFiles.add(new SupportingFile("package.mustache", "deploy", "package.xml"));
|
||||
@@ -638,11 +304,17 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
|
||||
writeOptional(outputFolder, new SupportingFile("README_ant.mustache", "README.md"));
|
||||
|
||||
}
|
||||
|
||||
private void generateSfdxSupportingFiles() {
|
||||
supportingFiles.add(new SupportingFile("sfdx.mustache", "", "sfdx-oss-manifest.json"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("sfdx-project-scratch-def.json", sfdxConfigPath, "project-scratch-def.json"));
|
||||
supportingFiles.add(new SupportingFile("sfdx-project.json.mustache", "sfdx-project.json"));
|
||||
|
||||
writeOptional(outputFolder, new SupportingFile("README_sfdx.mustache", "README.md"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,9 @@ import java.util.Set;
|
||||
|
||||
public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
protected String implFolder = "impl";
|
||||
|
||||
protected boolean isAddExternalLibs = true;
|
||||
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<String, String>();
|
||||
importMapping.put("std::vector", "#include <vector>");
|
||||
@@ -117,19 +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("\\.", "::"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle
|
||||
* escaping those terms here. This logic is only called if a variable
|
||||
* matches the reserved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name; // add an underscore to the name
|
||||
additionalProperties.put("apiNamespace", apiPackage.replaceAll("\\.", "::"));
|
||||
if (additionalProperties.containsKey(OPTIONAL_EXTERNAL_LIB)) {
|
||||
setAddExternalLibs(convertPropertyToBooleanAndWriteBack(OPTIONAL_EXTERNAL_LIB));
|
||||
} else {
|
||||
additionalProperties.put(OPTIONAL_EXTERNAL_LIB, isAddExternalLibs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -292,6 +289,9 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
else if (ModelUtils.isByteArraySchema(p)) {
|
||||
return "std::string";
|
||||
}
|
||||
if (ModelUtils.isStringSchema(p)
|
||||
|| ModelUtils.isDateSchema(p)
|
||||
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|
||||
@@ -320,6 +320,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<std::string, " + inner + ">()";
|
||||
@@ -378,29 +381,15 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
if (typeMapping.keySet().contains(type) || typeMapping.values().contains(type)
|
||||
|| importMapping.values().contains(type) || defaultIncludes.contains(type)
|
||||
|| languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
} else {
|
||||
return Character.toUpperCase(type.charAt(0)) + type.substring(1);
|
||||
}
|
||||
public String getTypeDeclaration(String str) {
|
||||
return toModelName(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String type) {
|
||||
return Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
/**
|
||||
* Specify whether external libraries will be added during the generation
|
||||
* @param value the value to be set
|
||||
*/
|
||||
public void setAddExternalLibs(boolean value){
|
||||
isAddExternalLibs = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,20 +251,6 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
return "#include \"" + folder + toModelName(name) + ".h\"";
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reserved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
if (this.reservedWordsMappings().containsKey(name)) {
|
||||
return this.reservedWordsMappings().get(name);
|
||||
}
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
@@ -378,25 +364,6 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
if (type == null) {
|
||||
LOGGER.warn("Model name can't be null. Default to 'UnknownModel'.");
|
||||
type = "UnknownModel";
|
||||
}
|
||||
|
||||
if (typeMapping.keySet().contains(type) ||
|
||||
typeMapping.values().contains(type) ||
|
||||
importMapping.values().contains(type) ||
|
||||
defaultIncludes.contains(type) ||
|
||||
languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
} else {
|
||||
String typeName = sanitizeName(type);
|
||||
return modelNamePrefix + Character.toUpperCase(typeName.charAt(0)) + typeName.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
@@ -424,22 +391,6 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String type) {
|
||||
return modelNamePrefix + Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
public void setOptionalProjectFileFlag(boolean flag) {
|
||||
this.optionalProjectFileFlag = flag;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,434 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implements CodegenConfig {
|
||||
@SuppressWarnings("unused")
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CppQt5QHttpEngineServerCodegen.class);
|
||||
|
||||
public static final String CPP_NAMESPACE = "cppNamespace";
|
||||
public static final String CPP_NAMESPACE_DESC = "C++ namespace (convention: name::space::for::api).";
|
||||
|
||||
protected final String PREFIX = "OAI";
|
||||
protected final String SRC_DIR = "/src";
|
||||
protected final String MODEL_DIR = "/src/models";
|
||||
protected final String APIHANDLER_DIR = "/src/handlers";
|
||||
protected final String APIREQUEST_DIR = "/src/requests";
|
||||
protected Set<String> foundationClasses = new HashSet<String>();
|
||||
// source folder where to write the files
|
||||
protected String sourceFolder = "server";
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected Map<String, String> namespaces = new HashMap<String, String>();
|
||||
protected Set<String> systemIncludes = new HashSet<String>();
|
||||
protected String cppNamespace = "OpenAPI";
|
||||
|
||||
public CppQt5QHttpEngineServerCodegen() {
|
||||
super();
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/cpp-qt5-qhttpengine-server";
|
||||
|
||||
// set modelNamePrefix as default for QHttpEngine Server
|
||||
if (StringUtils.isEmpty(modelNamePrefix)) {
|
||||
modelNamePrefix = PREFIX;
|
||||
}
|
||||
|
||||
/*
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
||||
* a different extension
|
||||
*/
|
||||
modelTemplateFiles.put(
|
||||
"model-header.mustache",
|
||||
".h");
|
||||
|
||||
modelTemplateFiles.put(
|
||||
"model-body.mustache",
|
||||
".cpp");
|
||||
|
||||
/*
|
||||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
|
||||
* as with models, add multiple entries with different extensions for multiple files per
|
||||
* class
|
||||
*/
|
||||
apiTemplateFiles.put(
|
||||
"apihandler.h.mustache", // the template to use
|
||||
".h"); // the extension for each file to write
|
||||
|
||||
apiTemplateFiles.put(
|
||||
"apihandler.cpp.mustache", // the template to use
|
||||
".cpp"); // the extension for each file to write
|
||||
|
||||
apiTemplateFiles.put(
|
||||
"apirequest.h.mustache", // the template to use
|
||||
".h"); // the extension for each file to write
|
||||
|
||||
apiTemplateFiles.put(
|
||||
"apirequest.cpp.mustache", // the template to use
|
||||
".cpp"); // the extension for each file to write
|
||||
|
||||
/*
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
embeddedTemplateDir = templateDir = "cpp-qt5-qhttpengine-server";
|
||||
|
||||
// CLI options
|
||||
addOption(CPP_NAMESPACE, CPP_NAMESPACE_DESC, this.cppNamespace);
|
||||
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
additionalProperties().put("prefix", PREFIX);
|
||||
|
||||
// Write defaults namespace in properties so that it can be accessible in templates.
|
||||
// At this point command line has not been parsed so if value is given
|
||||
// in command line it will superseed this content
|
||||
additionalProperties.put("cppNamespace", cppNamespace);
|
||||
|
||||
/*
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"bool",
|
||||
"qint32",
|
||||
"qint64",
|
||||
"float",
|
||||
"double")
|
||||
);
|
||||
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, PREFIX + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.h"));
|
||||
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.cpp"));
|
||||
|
||||
|
||||
supportingFiles.add(new SupportingFile("main.cpp.mustache", sourceFolder + SRC_DIR, "main.cpp"));
|
||||
supportingFiles.add(new SupportingFile("src-CMakeLists.txt.mustache", sourceFolder + SRC_DIR, "CMakeLists.txt"));
|
||||
supportingFiles.add(new SupportingFile("README.md.mustache", sourceFolder, "README.MD"));
|
||||
supportingFiles.add(new SupportingFile("Makefile.mustache", sourceFolder, "Makefile"));
|
||||
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
||||
supportingFiles.add(new SupportingFile("Dockerfile.mustache", sourceFolder, "Dockerfile"));
|
||||
supportingFiles.add(new SupportingFile("LICENSE.txt.mustache", sourceFolder, "LICENSE.txt"));
|
||||
|
||||
super.typeMapping = new HashMap<String, String>();
|
||||
|
||||
typeMapping.put("date", "QDate");
|
||||
typeMapping.put("DateTime", "QDateTime");
|
||||
typeMapping.put("string", "QString");
|
||||
typeMapping.put("integer", "qint32");
|
||||
typeMapping.put("long", "qint64");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("array", "QList");
|
||||
typeMapping.put("map", "QMap");
|
||||
typeMapping.put("object", PREFIX + "Object");
|
||||
// mapped as "file" type for OAS 3.0
|
||||
typeMapping.put("ByteArray", "QByteArray");
|
||||
// UUID support - possible enhancement : use QUuid instead of QString.
|
||||
// beware though that Serialisation/deserialisation of QUuid does not
|
||||
// come out of the box and will need to be sorted out (at least imply
|
||||
// modifications on multiple templates)
|
||||
typeMapping.put("UUID", "QString");
|
||||
typeMapping.put("file", "QIODevice");
|
||||
typeMapping.put("binary", "QIODevice");
|
||||
importMapping = new HashMap<String, String>();
|
||||
namespaces = new HashMap<String, String>();
|
||||
|
||||
foundationClasses.add("QString");
|
||||
|
||||
systemIncludes.add("QString");
|
||||
systemIncludes.add("QList");
|
||||
systemIncludes.add("QMap");
|
||||
systemIncludes.add("QDate");
|
||||
systemIncludes.add("QDateTime");
|
||||
systemIncludes.add("QByteArray");
|
||||
systemIncludes.add("QIODevice");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("cppNamespace")) {
|
||||
cppNamespace = (String) additionalProperties.get("cppNamespace");
|
||||
}
|
||||
|
||||
additionalProperties.put("cppNamespaceDeclarations", cppNamespace.split("\\::"));
|
||||
if (additionalProperties.containsKey("modelNamePrefix")) {
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.h"));
|
||||
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.cpp"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("main.cpp.mustache", sourceFolder + SRC_DIR, "main.cpp"));
|
||||
supportingFiles.add(new SupportingFile("src-CMakeLists.txt.mustache", sourceFolder + SRC_DIR, "CMakeLists.txt"));
|
||||
supportingFiles.add(new SupportingFile("README.md.mustache", sourceFolder, "README.MD"));
|
||||
supportingFiles.add(new SupportingFile("Makefile.mustache", sourceFolder, "Makefile"));
|
||||
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
||||
supportingFiles.add(new SupportingFile("Dockerfile.mustache", sourceFolder, "Dockerfile"));
|
||||
supportingFiles.add(new SupportingFile("LICENSE.txt.mustache", sourceFolder, "LICENSE.txt"));
|
||||
|
||||
typeMapping.put("object", modelNamePrefix + "Object");
|
||||
additionalProperties().put("prefix", modelNamePrefix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see org.openapitools.codegen.CodegenType
|
||||
*/
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -g flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "cpp-qt5-qhttpengine-server";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Qt5 C++ Server (beta) using the QHTTPEngine HTTP Library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if( name.isEmpty() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (namespaces.containsKey(name)) {
|
||||
return "using " + namespaces.get(name) + ";";
|
||||
} else if (systemIncludes.contains(name)) {
|
||||
return "#include <" + name + ">";
|
||||
}
|
||||
|
||||
String folder = modelPackage().replace("::", File.separator);
|
||||
if (!folder.isEmpty())
|
||||
folder += File.separator;
|
||||
|
||||
return "#include \"" + folder + name + ".h\"";
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + MODEL_DIR + "/" + modelPackage().replace("::", File.separator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write api files. You can use the apiPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + APIHANDLER_DIR + "/" + apiPackage().replace("::", File.separator);
|
||||
}
|
||||
|
||||
private String requestFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + APIREQUEST_DIR + "/" + apiPackage().replace("::", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return modelNamePrefix + initialCaps(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
|
||||
if (templateName.contains("apirequest")) {
|
||||
result = result.replace("ApiHandler", "ApiRequest");
|
||||
result = result.replace(apiFileFolder(), requestFileFolder());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return modelNamePrefix + initialCaps(name) + "ApiHandler";
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||
* types. There is typically special handling for different property types
|
||||
*
|
||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
String openAPIType = getSchemaType(p);
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return getSchemaType(p) + "*";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return getSchemaType(p) + "*";
|
||||
}
|
||||
if (foundationClasses.contains(openAPIType)) {
|
||||
return openAPIType;
|
||||
} else if (languageSpecificPrimitives.contains(openAPIType)) {
|
||||
return toModelName(openAPIType);
|
||||
} else {
|
||||
return openAPIType;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
return "NULL";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return "NULL";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
||||
return "0.0f";
|
||||
}
|
||||
return "0.0";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
||||
return "0L";
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
return "QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "QList<" + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
return "QString(\"\")";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
}
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - OpenAPI type conversion. This is used to map OpenAPI types in a `Schema` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(openAPIType)) {
|
||||
type = typeMapping.get(openAPIType);
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
return toModelName(type);
|
||||
}
|
||||
if (foundationClasses.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
type = openAPIType;
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
String varName = name;
|
||||
varName = sanitizeName(name);
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (varName.matches("^[A-Z_]*$")) {
|
||||
varName = varName.toLowerCase();
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// petId => pet_id
|
||||
varName = underscore(varName);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(varName) || varName.matches("^\\d.*")) {
|
||||
varName = escapeReservedWord(varName);
|
||||
}
|
||||
|
||||
return varName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(String str) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
|
||||
public static final String DECLSPEC = "declspec";
|
||||
public static final String DEFAULT_INCLUDE = "defaultInclude";
|
||||
public static final String GENERATE_GMOCKS_FOR_APIS = "generateGMocksForApis";
|
||||
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String declspec = "";
|
||||
@@ -114,6 +115,9 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
addOption(DEFAULT_INCLUDE,
|
||||
"The default include statement that should be placed in all headers for including things like the declspec (convention: #include \"Commons.h\" ",
|
||||
this.defaultInclude);
|
||||
addOption(GENERATE_GMOCKS_FOR_APIS,
|
||||
"Generate Google Mock classes for APIs.",
|
||||
null);
|
||||
|
||||
supportingFiles.add(new SupportingFile("modelbase-header.mustache", "", "ModelBase.h"));
|
||||
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "", "ModelBase.cpp"));
|
||||
@@ -153,6 +157,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<String, String>();
|
||||
importMapping.put("std::vector", "#include <vector>");
|
||||
@@ -176,6 +181,11 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
defaultInclude = additionalProperties.get(DEFAULT_INCLUDE).toString();
|
||||
}
|
||||
|
||||
if (convertPropertyToBoolean(GENERATE_GMOCKS_FOR_APIS)) {
|
||||
apiTemplateFiles.put("api-gmock.mustache", "GMock.h");
|
||||
additionalProperties.put("gmockApis", "true");
|
||||
}
|
||||
|
||||
additionalProperties.put("modelNamespaceDeclarations", modelPackage.split("\\."));
|
||||
additionalProperties.put("modelNamespace", modelPackage.replaceAll("\\.", "::"));
|
||||
additionalProperties.put("modelHeaderGuardPrefix", modelPackage.replaceAll("\\.", "_").toUpperCase());
|
||||
@@ -190,6 +200,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
* Location to write model files. You can use the modelPackage() as defined
|
||||
* when the class is instantiated
|
||||
*/
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/model";
|
||||
}
|
||||
@@ -208,7 +219,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
if (importMapping.containsKey(name)) {
|
||||
return importMapping.get(name);
|
||||
} else {
|
||||
return "#include \"" + name + ".h\"";
|
||||
return "#include \"" + sanitizeName(name) + ".h\"";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,12 +282,12 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return initialCaps(name);
|
||||
return sanitizeName(initialCaps(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return initialCaps(name) + "Api";
|
||||
return sanitizeName(initialCaps(name) + "Api");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,33 +389,6 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
if (typeMapping.keySet().contains(type) || typeMapping.values().contains(type)
|
||||
|| importMapping.values().contains(type) || defaultIncludes.contains(type)
|
||||
|| languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
} else {
|
||||
return Character.toUpperCase(type.charAt(0)) + type.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String type) {
|
||||
return Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessAllModels(final Map<String, Object> models) {
|
||||
|
||||
|
||||
@@ -148,18 +148,6 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
additionalProperties.put("defaultInclude", defaultInclude);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle
|
||||
* escaping those terms here. This logic is only called if a variable
|
||||
* matches the reserved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name; // add an underscore to the name
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined
|
||||
* when the class is instantiated
|
||||
@@ -361,33 +349,4 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
type = openAPIType;
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
if (typeMapping.keySet().contains(type) || typeMapping.values().contains(type)
|
||||
|| importMapping.values().contains(type) || defaultIncludes.contains(type)
|
||||
|| languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
} else {
|
||||
return Character.toUpperCase(type.charAt(0)) + type.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String type) {
|
||||
return Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class CppTizenClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public class CppTizenClientCodegen extends AbstractCppCodegen implements CodegenConfig {
|
||||
protected static String PREFIX = "ArtikCloud";
|
||||
protected String sourceFolder = "src";
|
||||
protected String documentationFolder = "doc";
|
||||
@@ -270,14 +270,6 @@ public class CppTizenClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
return "" + paramName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
if (this.reservedWordsMappings().containsKey(name)) {
|
||||
return this.reservedWordsMappings().get(name);
|
||||
}
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
@@ -293,16 +285,13 @@ public class CppTizenClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
// add_pet_by_id => addPetById
|
||||
return camelize(operationId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
return input.replace("\"", "");
|
||||
/**
|
||||
* Output the Getter name for boolean property, e.g. getActive
|
||||
*
|
||||
* @param name the name of the property
|
||||
* @return getter name based on naming convention
|
||||
*/
|
||||
public String toBooleanGetter(String name) {
|
||||
return "get" + getterAndSetterCapitalize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
public static final String WITH_GO_CODEGEN_COMMENT = "withGoCodegenComment";
|
||||
public static final String WITH_XML = "withXml";
|
||||
|
||||
public GoClientCodegen() {
|
||||
@@ -49,8 +50,10 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Go package version.")
|
||||
.defaultValue("1.0.0"));
|
||||
cliOptions.add(CliOption.newBoolean(WITH_GO_CODEGEN_COMMENT, "whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs"));
|
||||
cliOptions.add(CliOption.newBoolean(WITH_XML, "whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)"));
|
||||
|
||||
|
||||
// option to change the order of form/body parameter
|
||||
cliOptions.add(CliOption.newBoolean(
|
||||
CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS,
|
||||
@@ -93,6 +96,13 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
supportingFiles.add(new SupportingFile("response.mustache", "", "response.go"));
|
||||
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
|
||||
|
||||
if (additionalProperties.containsKey(WITH_GO_CODEGEN_COMMENT)) {
|
||||
setWithGoCodegenComment(Boolean.parseBoolean(additionalProperties.get(WITH_GO_CODEGEN_COMMENT).toString()));
|
||||
if (withGoCodegenComment) {
|
||||
additionalProperties.put(WITH_GO_CODEGEN_COMMENT, "true");
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(WITH_XML)) {
|
||||
setWithXml(Boolean.parseBoolean(additionalProperties.get(WITH_XML).toString()));
|
||||
if (withXml) {
|
||||
|
||||
@@ -523,25 +523,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
|
||||
Map<String, Object> allProcessedModels = super.postProcessAllModels(objs);
|
||||
if (!additionalProperties.containsKey("gsonFactoryMethod")) {
|
||||
List<Object> allModels = new ArrayList<Object>();
|
||||
for (String name : allProcessedModels.keySet()) {
|
||||
Map<String, Object> models = (Map<String, Object>) allProcessedModels.get(name);
|
||||
try {
|
||||
allModels.add(((List<Object>) models.get("models")).get(0));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
additionalProperties.put("parent", modelInheritanceSupportInGson(allModels));
|
||||
}
|
||||
return allProcessedModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
|
||||
objs = super.postProcessModelsEnum(objs);
|
||||
@@ -564,34 +545,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
return objs;
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> modelInheritanceSupportInGson(List<?> allModels) {
|
||||
Map<CodegenModel, List<CodegenModel>> byParent = new LinkedHashMap<>();
|
||||
for (Object model : allModels) {
|
||||
Map entry = (Map) model;
|
||||
CodegenModel parent = ((CodegenModel)entry.get("model")).parentModel;
|
||||
if(null!= parent) {
|
||||
byParent.computeIfAbsent(parent, k -> new LinkedList<>()).add((CodegenModel)entry.get("model"));
|
||||
}
|
||||
}
|
||||
List<Map<String, Object>> parentsList = new ArrayList<>();
|
||||
for (CodegenModel parentModel : byParent.keySet()) {
|
||||
List<Map<String, Object>> childrenList = new ArrayList<>();
|
||||
Map<String, Object> parent = new HashMap<>();
|
||||
parent.put("classname", parentModel.classname);
|
||||
List<CodegenModel> childrenModels = byParent.get(parentModel);
|
||||
for (CodegenModel model : childrenModels) {
|
||||
Map<String, Object> child = new HashMap<>();
|
||||
child.put("name", model.name);
|
||||
child.put("classname", model.classname);
|
||||
childrenList.add(child);
|
||||
}
|
||||
parent.put("children", childrenList);
|
||||
parent.put("discriminator", parentModel.discriminator);
|
||||
parentsList.add(parent);
|
||||
}
|
||||
return parentsList;
|
||||
}
|
||||
|
||||
public void setUseRxJava(boolean useRxJava) {
|
||||
this.useRxJava = useRxJava;
|
||||
doNotUseRx = false;
|
||||
|
||||
@@ -377,8 +377,14 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore("call_" + operationId));
|
||||
return underscore("call_" + operationId);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
|
||||
return underscore(sanitizeName("call_" + operationId));
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
//return underscore(operationId).replaceAll("[^A-Za-z0-9_]", "");
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PhpClientCodegen extends AbstractPhpCodegen {
|
||||
setInvokerPackage("OpenAPI\\Client");
|
||||
setApiPackage(getInvokerPackage() + "\\" + apiDirName);
|
||||
setModelPackage(getInvokerPackage() + "\\" + modelDirName);
|
||||
setPackagePath("OpenAPIClient-php");
|
||||
setPackageName("OpenAPIClient-php");
|
||||
supportsInheritance = true;
|
||||
setOutputDir("generated-code" + File.separator + "php");
|
||||
modelTestTemplateFiles.put("model_test.mustache", ".php");
|
||||
@@ -103,17 +103,17 @@ public class PhpClientCodegen extends AbstractPhpCodegen {
|
||||
additionalProperties.put(COMPOSER_VENDOR_NAME, composerVendorName);
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", toPackagePath(invokerPackage, srcBasePath), "ApiException.php"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", toPackagePath(invokerPackage, srcBasePath), "Configuration.php"));
|
||||
supportingFiles.add(new SupportingFile("ObjectSerializer.mustache", toPackagePath(invokerPackage, srcBasePath), "ObjectSerializer.php"));
|
||||
supportingFiles.add(new SupportingFile("ModelInterface.mustache", toPackagePath(modelPackage, srcBasePath), "ModelInterface.php"));
|
||||
supportingFiles.add(new SupportingFile("HeaderSelector.mustache", toPackagePath(invokerPackage, srcBasePath), "HeaderSelector.php"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", getPackagePath(), "README.md"));
|
||||
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", getPackagePath(), "phpunit.xml.dist"));
|
||||
supportingFiles.add(new SupportingFile(".travis.yml", getPackagePath(), ".travis.yml"));
|
||||
supportingFiles.add(new SupportingFile(".php_cs", getPackagePath(), ".php_cs"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", getPackagePath(), "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", toSrcPath(invokerPackage, srcBasePath), "ApiException.php"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", toSrcPath(invokerPackage, srcBasePath), "Configuration.php"));
|
||||
supportingFiles.add(new SupportingFile("ObjectSerializer.mustache", toSrcPath(invokerPackage, srcBasePath), "ObjectSerializer.php"));
|
||||
supportingFiles.add(new SupportingFile("ModelInterface.mustache", toSrcPath(modelPackage, srcBasePath), "ModelInterface.php"));
|
||||
supportingFiles.add(new SupportingFile("HeaderSelector.mustache", toSrcPath(invokerPackage, srcBasePath), "HeaderSelector.php"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", "", "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", "", "phpunit.xml.dist"));
|
||||
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
|
||||
supportingFiles.add(new SupportingFile(".php_cs", "", ".php_cs"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
}
|
||||
|
||||
public void setComposerVendorName(String composerVendorName) {
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.v3.oas.models.*;
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.oas.models.parameters.*;
|
||||
import org.openapitools.codegen.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.PathItem.HttpMethod;
|
||||
import io.swagger.v3.oas.models.*;
|
||||
import io.swagger.v3.oas.models.parameters.*;
|
||||
import io.swagger.v3.core.util.Yaml;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class PhpLaravelServerCodegen extends AbstractPhpCodegen {
|
||||
@SuppressWarnings("hiding")
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected String variableNamingConvention = "camelCase";
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see org.openapitools.codegen.CodegenType
|
||||
*/
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -g flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
public String getName() {
|
||||
return "php-laravel";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
public String getHelp() {
|
||||
return "Generates a PHP laravel server library.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
public PhpLaravelServerCodegen() {
|
||||
super();
|
||||
|
||||
embeddedTemplateDir = templateDir = "php-laravel";
|
||||
|
||||
/*
|
||||
* packPath
|
||||
*/
|
||||
invokerPackage = "php-laravel";
|
||||
outputFolder = srcBasePath;
|
||||
|
||||
/*
|
||||
* Api Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
apiPackage = "app.Http.Controllers";
|
||||
|
||||
/*
|
||||
* Model Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
modelPackage = "app\\Models";
|
||||
|
||||
// template files want to be ignored
|
||||
apiTestTemplateFiles.clear();
|
||||
apiDocTemplateFiles.clear();
|
||||
modelDocTemplateFiles.clear();
|
||||
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
|
||||
/*
|
||||
* Supporting Files. You can write single files for the generator with the
|
||||
* entire object tree available. If the input file has a suffix of `.mustache
|
||||
* it will be processed by the template engine. Otherwise, it will be copied
|
||||
*/
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", outputFolder, "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("README.md", outputFolder, "README.md"));
|
||||
supportingFiles.add(new SupportingFile("artisan", outputFolder, "artisan"));
|
||||
supportingFiles.add(new SupportingFile("package.json", outputFolder, "package.json"));
|
||||
supportingFiles.add(new SupportingFile("phpunit.xml", outputFolder, "phpunit.xml"));
|
||||
supportingFiles.add(new SupportingFile("webpack.mix.js", outputFolder, "webpack.mix.js"));
|
||||
supportingFiles.add(new SupportingFile(".env.example", outputFolder, ".env.example"));
|
||||
supportingFiles.add(new SupportingFile("server.php", outputFolder, "server.php"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("bootstrap/cache/.gitignore", outputFolder + File.separator + "bootstrap" + File.separator + "cache", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("bootstrap/app.php", outputFolder + File.separator + "bootstrap", "app.php"));
|
||||
supportingFiles.add(new SupportingFile("bootstrap/testingAutoload.php", outputFolder + File.separator + "bootstrap", "testingAutoload.php"));
|
||||
|
||||
/* /public/ */
|
||||
supportingFiles.add(new SupportingFile("public/css/app.css", outputFolder + File.separator + "public" + File.separator + "css", "app.css"));
|
||||
supportingFiles.add(new SupportingFile("public/js/app.js", outputFolder + File.separator + "public" + File.separator + "js", "app.js"));
|
||||
supportingFiles.add(new SupportingFile("public/.htaccess", outputFolder + File.separator + "public", ".htaccess"));
|
||||
supportingFiles.add(new SupportingFile("public/favicon.ico", outputFolder + File.separator + "public", "favicon.ico"));
|
||||
supportingFiles.add(new SupportingFile("public/index.php", outputFolder + File.separator + "public", "index.php"));
|
||||
supportingFiles.add(new SupportingFile("public/robots.txt", outputFolder + File.separator + "public", "robots.txt"));
|
||||
supportingFiles.add(new SupportingFile("public/web.config", outputFolder + File.separator + "public", "web.config"));
|
||||
|
||||
/* /routes/ */
|
||||
supportingFiles.add(new SupportingFile("routes/api.mustache", outputFolder + File.separator + "routes", "api.php"));
|
||||
supportingFiles.add(new SupportingFile("routes/web.mustache", outputFolder + File.separator + "routes", "web.php"));
|
||||
supportingFiles.add(new SupportingFile("routes/channels.mustache", outputFolder + File.separator + "routes", "channels.php"));
|
||||
supportingFiles.add(new SupportingFile("routes/console.mustache", outputFolder + File.separator + "routes", "console.php"));
|
||||
|
||||
/* /app/Http/Controllers/ */
|
||||
supportingFiles.add(new SupportingFile("app/Http/Kernel.php", outputFolder + File.separator + "app" + File.separator + "Http", "Kernel.php"));
|
||||
supportingFiles.add(new SupportingFile("app/Http/Controllers/Controller.php", outputFolder + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers", "Controller.php"));
|
||||
supportingFiles.add(new SupportingFile("app/Http/Middleware/EncryptCookies.php", outputFolder + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware", "EncryptCookies.php"));
|
||||
supportingFiles.add(new SupportingFile("app/Http/Middleware/RedirectIfAuthenticated.php", outputFolder + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware", "RedirectIfAuthenticated.php"));
|
||||
supportingFiles.add(new SupportingFile("app/Http/Middleware/TrimStrings.php", outputFolder + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware", "TrimStrings.php"));
|
||||
supportingFiles.add(new SupportingFile("app/Http/Middleware/TrustProxies.php", outputFolder + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware", "TrustProxies.php"));
|
||||
supportingFiles.add(new SupportingFile("app/Http/Middleware/VerifyCsrfToken.php", outputFolder + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware", "VerifyCsrfToken.php"));
|
||||
|
||||
// /app/Console
|
||||
supportingFiles.add(new SupportingFile("app/Console/Kernel.php", outputFolder + File.separator + "app" + File.separator + "Console", "Kernel.php"));
|
||||
// /app/Exceptions
|
||||
supportingFiles.add(new SupportingFile("app/Exceptions/Handler.php", outputFolder + File.separator + "app" + File.separator + "Exceptions", "Handler.php"));
|
||||
// /app/Providers
|
||||
supportingFiles.add(new SupportingFile("app/Providers/AppServiceProvider.php", outputFolder + File.separator + "app" + File.separator + "Providers", "AppServiceProvider.php"));
|
||||
supportingFiles.add(new SupportingFile("app/Providers/AuthServiceProvider.php", outputFolder + File.separator + "app" + File.separator + "Providers", "AuthServiceProvider.php"));
|
||||
supportingFiles.add(new SupportingFile("app/Providers/BroadcastServiceProvider.php", outputFolder + File.separator + "app" + File.separator + "Providers", "BroadcastServiceProvider.php"));
|
||||
supportingFiles.add(new SupportingFile("app/Providers/EventServiceProvider.php", outputFolder + File.separator + "app" + File.separator + "Providers", "EventServiceProvider.php"));
|
||||
supportingFiles.add(new SupportingFile("app/Providers/RouteServiceProvider.php", outputFolder + File.separator + "app" + File.separator + "Providers", "RouteServiceProvider.php"));
|
||||
|
||||
// /database/
|
||||
supportingFiles.add(new SupportingFile("database/factories/UserFactory.php", outputFolder + File.separator + "database" + File.separator + "factories", "UserFactory.php"));
|
||||
supportingFiles.add(new SupportingFile("database/migrations/2014_10_12_000000_create_users_table.php", outputFolder + File.separator + "database" + File.separator + "migrations", "2014_10_12_000000_create_users_table.php"));
|
||||
supportingFiles.add(new SupportingFile("database/migrations/2014_10_12_100000_create_password_resets_table.php", outputFolder + File.separator + "database" + File.separator + "migrations", "2014_10_12_100000_create_password_resets_table.php"));
|
||||
supportingFiles.add(new SupportingFile("database/seeds/DatabaseSeeder.php", outputFolder + File.separator + "database" + File.separator + "seeds", "DatabaseSeeder.php"));
|
||||
supportingFiles.add(new SupportingFile("database/.gitignore", outputFolder + File.separator + "database", ".gitignore"));
|
||||
|
||||
// /config/
|
||||
supportingFiles.add(new SupportingFile("config/app.php", outputFolder + File.separator + "config", "app.php"));
|
||||
supportingFiles.add(new SupportingFile("config/auth.php", outputFolder + File.separator + "config", "auth.php"));
|
||||
supportingFiles.add(new SupportingFile("config/broadcasting.php", outputFolder + File.separator + "config", "broadcasting.php"));
|
||||
supportingFiles.add(new SupportingFile("config/cache.php", outputFolder + File.separator + "config", "cache.php"));
|
||||
supportingFiles.add(new SupportingFile("config/database.php", outputFolder + File.separator + "config", "database.php"));
|
||||
supportingFiles.add(new SupportingFile("config/filesystems.php", outputFolder + File.separator + "config", "filesystems.php"));
|
||||
supportingFiles.add(new SupportingFile("config/hashing.php", outputFolder + File.separator + "config", "hashing.php"));
|
||||
supportingFiles.add(new SupportingFile("config/logging.php", outputFolder + File.separator + "config", "logging.php"));
|
||||
supportingFiles.add(new SupportingFile("config/mail.php", outputFolder + File.separator + "config", "mail.php"));
|
||||
supportingFiles.add(new SupportingFile("config/queue.php", outputFolder + File.separator + "config", "queue.php"));
|
||||
supportingFiles.add(new SupportingFile("config/services.php", outputFolder + File.separator + "config", "services.php"));
|
||||
supportingFiles.add(new SupportingFile("config/session.php", outputFolder + File.separator + "config", "session.php"));
|
||||
supportingFiles.add(new SupportingFile("config/view.php", outputFolder + File.separator + "config", "view.php"));
|
||||
|
||||
// /resources/
|
||||
supportingFiles.add(new SupportingFile("resources/assets/js/components/ExampleComponent.vue", outputFolder + File.separator + "resources" + File.separator + "assets" + File.separator + "js" + File.separator + "components", "ExampleComponent.vue"));
|
||||
supportingFiles.add(new SupportingFile("resources/assets/js/app.js", outputFolder + File.separator + "resources" + File.separator + "assets" + File.separator + "js", "app.js"));
|
||||
supportingFiles.add(new SupportingFile("resources/assets/js/bootstrap.js", outputFolder + File.separator + "resources" + File.separator + "assets" + File.separator + "js", "bootstrap.js"));
|
||||
supportingFiles.add(new SupportingFile("resources/assets/sass/_variables.scss", outputFolder + File.separator + "resources" + File.separator + "assets" + File.separator + "sass", "_variables.scss"));
|
||||
supportingFiles.add(new SupportingFile("resources/assets/sass/app.scss", outputFolder + File.separator + "resources" + File.separator + "assets" + File.separator + "sass", "app.scss"));
|
||||
supportingFiles.add(new SupportingFile("resources/lang/en/auth.php", outputFolder + File.separator + "resources" + File.separator + "lang" + File.separator + "en", "auth.php"));
|
||||
supportingFiles.add(new SupportingFile("resources/lang/en/pagination.php", outputFolder + File.separator + "resources" + File.separator + "lang" + File.separator + "en", "pagination.php"));
|
||||
supportingFiles.add(new SupportingFile("resources/lang/en/passwords.php", outputFolder + File.separator + "resources" + File.separator + "lang" + File.separator + "en", "passwords.php"));
|
||||
supportingFiles.add(new SupportingFile("resources/lang/en/validation.php", outputFolder + File.separator + "resources" + File.separator + "lang" + File.separator + "en", "validation.php"));
|
||||
supportingFiles.add(new SupportingFile("resources/views/welcome.blade.php", outputFolder + File.separator + "resources" + File.separator + "views", "welcome.blade.php"));
|
||||
|
||||
// /storage/
|
||||
supportingFiles.add(new SupportingFile("storage/app/.gitignore", outputFolder + File.separator + "storage" + File.separator + "app", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("storage/app/public/.gitignore", outputFolder + File.separator + "storage" + File.separator + "app" + File.separator + "public", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("storage/framework/.gitignore", outputFolder + File.separator + "storage" + File.separator + "framework", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("storage/framework/cache/.gitignore", outputFolder + File.separator + "storage" + File.separator + "framework" + File.separator + "cache", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("storage/framework/sessions/.gitignore", outputFolder + File.separator + "storage" + File.separator + "framework" + File.separator + "sessions", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("storage/framework/testing/.gitignore", outputFolder + File.separator + "storage" + File.separator + "framework" + File.separator + "testing", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("storage/framework/views/.gitignore", outputFolder + File.separator + "storage" + File.separator + "framework" + File.separator + "views", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("storage/logs/.gitignore", outputFolder + File.separator + "storage" + File.separator + "logs", ".gitignore"));
|
||||
|
||||
// /tests/
|
||||
supportingFiles.add(new SupportingFile("tests/Feature/ExampleTest.php", outputFolder + File.separator + "tests" + File.separator + "Feature", "ExampleTest.php"));
|
||||
supportingFiles.add(new SupportingFile("tests/Unit/ExampleTest.php", outputFolder + File.separator + "tests" + File.separator + "Unit", "ExampleTest.php"));
|
||||
supportingFiles.add(new SupportingFile("tests/CreatesApplication.php", outputFolder + File.separator + "tests", "CreatesApplication.php"));
|
||||
supportingFiles.add(new SupportingFile("tests/TestCase.php", outputFolder + File.separator + "tests", "TestCase.php"));
|
||||
}
|
||||
|
||||
// override with any special post-processing
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
|
||||
for (CodegenOperation op : operations) {
|
||||
op.httpMethod = op.httpMethod.toLowerCase();
|
||||
// check to see if the path contains ".", which is not supported by PHP laravel
|
||||
// ref: https://github.com/swagger-api/swagger-codegen/issues/6897
|
||||
if (op.path != null && op.path.contains(".")) {
|
||||
throw new IllegalArgumentException("'.' (dot) is not supported by PHP laravel. Please refer to https://github.com/swagger-api/swagger-codegen/issues/6897 for more info.");
|
||||
}
|
||||
|
||||
if (op.hasProduces) {
|
||||
// need to escape */* values because they breakes current mustaches
|
||||
List<Map<String, String>> c = op.produces;
|
||||
for (Map<String, String> mediaType : c) {
|
||||
if ("*/*".equals(mediaType.get("mediaType"))) {
|
||||
mediaType.put("mediaType", "*_/_*");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sort the endpoints in ascending to avoid the route priority issure.
|
||||
// https://github.com/swagger-api/swagger-codegen/issues/2643
|
||||
Collections.sort(operations, new Comparator<CodegenOperation>() {
|
||||
@Override
|
||||
public int compare(CodegenOperation lhs, CodegenOperation rhs) {
|
||||
return lhs.path.compareTo(rhs.path);
|
||||
}
|
||||
});
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.isEmpty()) {
|
||||
return "DefaultController";
|
||||
}
|
||||
|
||||
return camelize(name, false) + "Controller";
|
||||
}
|
||||
|
||||
protected String controllerFileFolder() {
|
||||
return (outputFolder + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String suffix = apiTemplateFiles().get(templateName);
|
||||
if (templateName.equals("api.mustache")) {
|
||||
return controllerFileFolder() + '/' + toControllerName(tag) + suffix;
|
||||
}
|
||||
|
||||
return apiFileFolder() + '/' + toApiFilename(tag) + suffix;
|
||||
}
|
||||
|
||||
protected String toControllerName(String name) {
|
||||
if (name.isEmpty()) {
|
||||
return "DefaultController";
|
||||
}
|
||||
|
||||
return camelize(name, false) + "Controller";
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import org.openapitools.codegen.*;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
@@ -66,7 +65,6 @@ public class PhpLumenServerCodegen extends AbstractPhpCodegen {
|
||||
* packPath
|
||||
*/
|
||||
invokerPackage = "lumen";
|
||||
packagePath = "";
|
||||
|
||||
/*
|
||||
* Api Package. Optional, if needed, this can be used in templates
|
||||
@@ -95,17 +93,16 @@ public class PhpLumenServerCodegen extends AbstractPhpCodegen {
|
||||
* entire object tree available. If the input file has a suffix of `.mustache
|
||||
* it will be processed by the template engine. Otherwise, it will be copied
|
||||
*/
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", packagePath + File.separator + srcBasePath, "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("readme.md", packagePath + File.separator + srcBasePath, "readme.md"));
|
||||
supportingFiles.add(new SupportingFile("app.php", packagePath + File.separator + srcBasePath + File.separator + "bootstrap", "app.php"));
|
||||
supportingFiles.add(new SupportingFile("index.php", packagePath + File.separator + srcBasePath + File.separator + "public", "index.php"));
|
||||
supportingFiles.add(new SupportingFile("User.php", packagePath + File.separator + srcBasePath + File.separator + "app", "User.php"));
|
||||
supportingFiles.add(new SupportingFile("Kernel.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Console", "Kernel.php"));
|
||||
supportingFiles.add(new SupportingFile("Handler.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Exceptions", "Handler.php"));
|
||||
supportingFiles.add(new SupportingFile("routes.mustache", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http", "routes.php"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("Controller.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "Controller.php"));
|
||||
supportingFiles.add(new SupportingFile("Authenticate.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "Authenticate.php"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", srcBasePath, "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("readme.md", srcBasePath, "readme.md"));
|
||||
supportingFiles.add(new SupportingFile("app.php", srcBasePath + File.separator + "bootstrap", "app.php"));
|
||||
supportingFiles.add(new SupportingFile("index.php", srcBasePath + File.separator + "public", "index.php"));
|
||||
supportingFiles.add(new SupportingFile("User.php", srcBasePath + File.separator + "app", "User.php"));
|
||||
supportingFiles.add(new SupportingFile("Kernel.php", srcBasePath + File.separator + "app" + File.separator + "Console", "Kernel.php"));
|
||||
supportingFiles.add(new SupportingFile("Handler.php", srcBasePath + File.separator + "app" + File.separator + "Exceptions", "Handler.php"));
|
||||
supportingFiles.add(new SupportingFile("routes.mustache", srcBasePath + File.separator + "app" + File.separator + "Http", "routes.php"));
|
||||
supportingFiles.add(new SupportingFile("Controller.php", srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "Controller.php"));
|
||||
supportingFiles.add(new SupportingFile("Authenticate.php", srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "Authenticate.php"));
|
||||
|
||||
}
|
||||
|
||||
@@ -133,6 +130,8 @@ public class PhpLumenServerCodegen extends AbstractPhpCodegen {
|
||||
}
|
||||
});
|
||||
|
||||
escapeMediaType(operations);
|
||||
|
||||
return objs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ public class PhpSilexServerCodegen extends DefaultCodegen implements CodegenConf
|
||||
super();
|
||||
|
||||
invokerPackage = camelize("OpenAPIServer");
|
||||
String packagePath = "OpenAPIServer";
|
||||
modelPackage = packagePath + File.separator + "lib" + File.separator + "models";
|
||||
apiPackage = packagePath + File.separator + "lib";
|
||||
String packageName = "OpenAPIServer";
|
||||
modelPackage = "lib" + File.separator + "models";
|
||||
apiPackage = "lib";
|
||||
outputFolder = "generated-code" + File.separator + "php-silex";
|
||||
|
||||
// no model, api files
|
||||
@@ -112,10 +112,10 @@ public class PhpSilexServerCodegen extends DefaultCodegen implements CodegenConf
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", packagePath.replace('/', File.separatorChar), "README.md"));
|
||||
supportingFiles.add(new SupportingFile("composer.json", packagePath.replace('/', File.separatorChar), "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", packagePath.replace('/', File.separatorChar), "index.php"));
|
||||
supportingFiles.add(new SupportingFile(".htaccess", packagePath.replace('/', File.separatorChar), ".htaccess"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("composer.json", "", "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", "", "index.php"));
|
||||
supportingFiles.add(new SupportingFile(".htaccess", "", ".htaccess"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,6 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen {
|
||||
|
||||
variableNamingConvention = "camelCase";
|
||||
artifactVersion = "1.0.0";
|
||||
packagePath = ""; // empty packagePath (top folder)
|
||||
setInvokerPackage("OpenAPIServer");
|
||||
apiPackage = invokerPackage + "\\" + apiDirName;
|
||||
modelPackage = invokerPackage + "\\" + modelDirName;
|
||||
@@ -92,49 +91,39 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen {
|
||||
public String apiFileFolder() {
|
||||
if (apiPackage.matches("^" + invokerPackage + "\\\\*(.+)")) {
|
||||
// need to strip out invokerPackage from path
|
||||
return (outputFolder + File.separator + toPackagePath(apiPackage.replaceFirst("^" + invokerPackage + "\\\\*(.+)", "$1"), srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(apiPackage.replaceFirst("^" + invokerPackage + "\\\\*(.+)", "$1"), srcBasePath));
|
||||
}
|
||||
return (outputFolder + File.separator + toPackagePath(apiPackage, srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(apiPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
if (modelPackage.matches("^" + invokerPackage + "\\\\*(.+)")) {
|
||||
// need to strip out invokerPackage from path
|
||||
return (outputFolder + File.separator + toPackagePath(modelPackage.replaceFirst("^" + invokerPackage + "\\\\*(.+)", "$1"), srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(modelPackage.replaceFirst("^" + invokerPackage + "\\\\*(.+)", "$1"), srcBasePath));
|
||||
}
|
||||
return (outputFolder + File.separator + toPackagePath(modelPackage, srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(modelPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", getPackagePath(), "README.md"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", getPackagePath(), "index.php"));
|
||||
supportingFiles.add(new SupportingFile(".htaccess", getPackagePath(), ".htaccess"));
|
||||
supportingFiles.add(new SupportingFile(".gitignore", getPackagePath(), ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", "", "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", "", "index.php"));
|
||||
supportingFiles.add(new SupportingFile(".htaccess", "", ".htaccess"));
|
||||
supportingFiles.add(new SupportingFile(".gitignore", "", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("AbstractApiController.mustache", toSrcPath(invokerPackage, srcBasePath), "AbstractApiController.php"));
|
||||
supportingFiles.add(new SupportingFile("SlimRouter.mustache", toSrcPath(invokerPackage, srcBasePath), "SlimRouter.php"));
|
||||
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", getPackagePath(), "phpunit.xml.dist"));
|
||||
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", "", "phpunit.xml.dist"));
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (op.hasProduces) {
|
||||
// need to escape */* values because they breakes current mustaches
|
||||
List<Map<String, String>> c = op.produces;
|
||||
for (Map<String, String> mediaType : c) {
|
||||
if ("*/*".equals(mediaType.get("mediaType"))) {
|
||||
mediaType.put("mediaType", "*_/_*");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
escapeMediaType(operationList);
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,6 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
|
||||
srcBasePath = ".";
|
||||
setInvokerPackage("OpenAPI\\Server");
|
||||
setBundleName("OpenAPIServer");
|
||||
packagePath = "SymfonyBundle-php";
|
||||
modelDirName = "Model";
|
||||
docsBasePath = "Resources" + File.separator + "docs";
|
||||
apiDocPath = docsBasePath + File.separator + apiDirName;
|
||||
@@ -203,7 +202,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
|
||||
}
|
||||
|
||||
public String controllerFileFolder() {
|
||||
return (outputFolder + File.separator + toPackagePath(controllerPackage, srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(controllerPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -295,39 +294,39 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
|
||||
// make test path available in mustache template
|
||||
additionalProperties.put("testsDirName", testsDirName);
|
||||
|
||||
final String configDir = getPackagePath() + File.separator + "Resources" + File.separator + "config";
|
||||
final String dependencyInjectionDir = getPackagePath() + File.separator + "DependencyInjection";
|
||||
final String configDir = "Resources" + File.separator + "config";
|
||||
final String dependencyInjectionDir = "DependencyInjection";
|
||||
|
||||
supportingFiles.add(new SupportingFile("Controller.mustache", toPackagePath(controllerPackage, srcBasePath), "Controller.php"));
|
||||
supportingFiles.add(new SupportingFile("Bundle.mustache", getPackagePath(), bundleClassName + ".php"));
|
||||
supportingFiles.add(new SupportingFile("Controller.mustache", toSrcPath(controllerPackage, srcBasePath), "Controller.php"));
|
||||
supportingFiles.add(new SupportingFile("Bundle.mustache", "", bundleClassName + ".php"));
|
||||
supportingFiles.add(new SupportingFile("Extension.mustache", dependencyInjectionDir, bundleExtensionName + ".php"));
|
||||
supportingFiles.add(new SupportingFile("ApiPass.mustache", dependencyInjectionDir + File.separator + "Compiler", bundleName + "ApiPass.php"));
|
||||
supportingFiles.add(new SupportingFile("ApiServer.mustache", toPackagePath(apiPackage, srcBasePath), "ApiServer.php"));
|
||||
supportingFiles.add(new SupportingFile("ApiServer.mustache", toSrcPath(apiPackage, srcBasePath), "ApiServer.php"));
|
||||
|
||||
// Serialization components
|
||||
supportingFiles.add(new SupportingFile("serialization/SerializerInterface.mustache", toPackagePath(servicePackage, srcBasePath), "SerializerInterface.php"));
|
||||
supportingFiles.add(new SupportingFile("serialization/JmsSerializer.mustache", toPackagePath(servicePackage, srcBasePath), "JmsSerializer.php"));
|
||||
supportingFiles.add(new SupportingFile("serialization/StrictJsonDeserializationVisitor.mustache", toPackagePath(servicePackage, srcBasePath), "StrictJsonDeserializationVisitor.php"));
|
||||
supportingFiles.add(new SupportingFile("serialization/TypeMismatchException.mustache", toPackagePath(servicePackage, srcBasePath), "TypeMismatchException.php"));
|
||||
supportingFiles.add(new SupportingFile("serialization/SerializerInterface.mustache", toSrcPath(servicePackage, srcBasePath), "SerializerInterface.php"));
|
||||
supportingFiles.add(new SupportingFile("serialization/JmsSerializer.mustache", toSrcPath(servicePackage, srcBasePath), "JmsSerializer.php"));
|
||||
supportingFiles.add(new SupportingFile("serialization/StrictJsonDeserializationVisitor.mustache", toSrcPath(servicePackage, srcBasePath), "StrictJsonDeserializationVisitor.php"));
|
||||
supportingFiles.add(new SupportingFile("serialization/TypeMismatchException.mustache", toSrcPath(servicePackage, srcBasePath), "TypeMismatchException.php"));
|
||||
// Validation components
|
||||
supportingFiles.add(new SupportingFile("validation/ValidatorInterface.mustache", toPackagePath(servicePackage, srcBasePath), "ValidatorInterface.php"));
|
||||
supportingFiles.add(new SupportingFile("validation/SymfonyValidator.mustache", toPackagePath(servicePackage, srcBasePath), "SymfonyValidator.php"));
|
||||
supportingFiles.add(new SupportingFile("validation/ValidatorInterface.mustache", toSrcPath(servicePackage, srcBasePath), "ValidatorInterface.php"));
|
||||
supportingFiles.add(new SupportingFile("validation/SymfonyValidator.mustache", toSrcPath(servicePackage, srcBasePath), "SymfonyValidator.php"));
|
||||
|
||||
// Testing components
|
||||
supportingFiles.add(new SupportingFile("testing/phpunit.xml.mustache", getPackagePath(), "phpunit.xml.dist"));
|
||||
supportingFiles.add(new SupportingFile("testing/pom.xml", getPackagePath(), "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("testing/AppKernel.php", toPackagePath(testsPackage, srcBasePath), "AppKernel.php"));
|
||||
supportingFiles.add(new SupportingFile("testing/test_config.yml", toPackagePath(testsPackage, srcBasePath), "test_config.yml"));
|
||||
supportingFiles.add(new SupportingFile("testing/phpunit.xml.mustache", "", "phpunit.xml.dist"));
|
||||
supportingFiles.add(new SupportingFile("testing/pom.xml", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("testing/AppKernel.php", toSrcPath(testsPackage, srcBasePath), "AppKernel.php"));
|
||||
supportingFiles.add(new SupportingFile("testing/test_config.yml", toSrcPath(testsPackage, srcBasePath), "test_config.yml"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("routing.mustache", configDir, "routing.yml"));
|
||||
supportingFiles.add(new SupportingFile("services.mustache", configDir, "services.yml"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", getPackagePath(), "README.md"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", "", "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("autoload.mustache", "", "autoload.php"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
supportingFiles.add(new SupportingFile(".travis.yml", getPackagePath(), ".travis.yml"));
|
||||
supportingFiles.add(new SupportingFile(".php_cs", getPackagePath(), ".php_cs"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", getPackagePath(), "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
|
||||
supportingFiles.add(new SupportingFile(".php_cs", "", ".php_cs"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
|
||||
// Type-hintable primitive types
|
||||
// ref: http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
|
||||
@@ -461,12 +460,12 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return (outputFolder + File.separator + toPackagePath(apiTestsPackage, srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(apiTestsPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return (outputFolder + File.separator + toPackagePath(modelTestsPackage, srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(modelTestsPackage, srcBasePath));
|
||||
}
|
||||
|
||||
public void setComposerVendorName(String composerVendorName) {
|
||||
|
||||
@@ -64,7 +64,6 @@ public class PhpZendExpressivePathHandlerServerCodegen extends AbstractPhpCodege
|
||||
|
||||
embeddedTemplateDir = templateDir = "ze-ph";
|
||||
invokerPackage = "App";
|
||||
packagePath = "";
|
||||
srcBasePath = "src" + File.separator + "App";
|
||||
apiDirName = "Handler";
|
||||
modelDirName = "DTO";
|
||||
@@ -76,22 +75,22 @@ public class PhpZendExpressivePathHandlerServerCodegen extends AbstractPhpCodege
|
||||
apiDocTemplateFiles.clear();
|
||||
modelDocTemplateFiles.clear();
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.md.mustache", packagePath, "README.md"));
|
||||
supportingFiles.add(new SupportingFile("composer.json.mustache", packagePath, "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("index.php", packagePath + File.separator + "public", "index.php"));
|
||||
supportingFiles.add(new SupportingFile("container.php", packagePath + File.separator + "application", "container.php"));
|
||||
supportingFiles.add(new SupportingFile("config.yml", packagePath + File.separator + "application", "config.yml"));
|
||||
supportingFiles.add(new SupportingFile("app.yml.mustache", packagePath + File.separator + "application" + File.separator + "config", "app.yml"));
|
||||
supportingFiles.add(new SupportingFile("path_handler.yml.mustache", packagePath + File.separator + "application" + File.separator + "config", "path_handler.yml"));
|
||||
supportingFiles.add(new SupportingFile("data_transfer.yml.mustache", packagePath + File.separator + "application" + File.separator + "config", "data_transfer.yml"));
|
||||
supportingFiles.add(new SupportingFile("ErrorMiddleware.php.mustache", packagePath + File.separator + srcBasePath, "ErrorMiddleware.php"));
|
||||
supportingFiles.add(new SupportingFile("Date.php.mustache", packagePath + File.separator + srcBasePath + File.separator + "Strategy", "Date.php"));
|
||||
supportingFiles.add(new SupportingFile("DateTime.php.mustache", packagePath + File.separator + srcBasePath + File.separator + "Strategy", "DateTime.php"));
|
||||
supportingFiles.add(new SupportingFile("QueryParameter.php.mustache", packagePath + File.separator + srcBasePath + File.separator + "Strategy", "QueryParameter.php"));
|
||||
supportingFiles.add(new SupportingFile("QueryParameterArray.php.mustache", packagePath + File.separator + srcBasePath + File.separator + "Strategy", "QueryParameterArray.php"));
|
||||
supportingFiles.add(new SupportingFile("Type.php.mustache", packagePath + File.separator + srcBasePath + File.separator + "Validator", "Type.php"));
|
||||
supportingFiles.add(new SupportingFile("QueryParameterType.php.mustache", packagePath + File.separator + srcBasePath + File.separator + "Validator", "QueryParameterType.php"));
|
||||
supportingFiles.add(new SupportingFile("QueryParameterArrayType.php.mustache", packagePath + File.separator + srcBasePath + File.separator + "Validator", "QueryParameterArrayType.php"));
|
||||
supportingFiles.add(new SupportingFile("README.md.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("composer.json.mustache", "", "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("index.php", "public", "index.php"));
|
||||
supportingFiles.add(new SupportingFile("container.php", "application", "container.php"));
|
||||
supportingFiles.add(new SupportingFile("config.yml", "application", "config.yml"));
|
||||
supportingFiles.add(new SupportingFile("app.yml.mustache", "application" + File.separator + "config", "app.yml"));
|
||||
supportingFiles.add(new SupportingFile("path_handler.yml.mustache", "application" + File.separator + "config", "path_handler.yml"));
|
||||
supportingFiles.add(new SupportingFile("data_transfer.yml.mustache", "application" + File.separator + "config", "data_transfer.yml"));
|
||||
supportingFiles.add(new SupportingFile("ErrorMiddleware.php.mustache", srcBasePath, "ErrorMiddleware.php"));
|
||||
supportingFiles.add(new SupportingFile("Date.php.mustache", srcBasePath + File.separator + "Strategy", "Date.php"));
|
||||
supportingFiles.add(new SupportingFile("DateTime.php.mustache", srcBasePath + File.separator + "Strategy", "DateTime.php"));
|
||||
supportingFiles.add(new SupportingFile("QueryParameter.php.mustache", srcBasePath + File.separator + "Strategy", "QueryParameter.php"));
|
||||
supportingFiles.add(new SupportingFile("QueryParameterArray.php.mustache", srcBasePath + File.separator + "Strategy", "QueryParameterArray.php"));
|
||||
supportingFiles.add(new SupportingFile("Type.php.mustache", srcBasePath + File.separator + "Validator", "Type.php"));
|
||||
supportingFiles.add(new SupportingFile("QueryParameterType.php.mustache", srcBasePath + File.separator + "Validator", "QueryParameterType.php"));
|
||||
supportingFiles.add(new SupportingFile("QueryParameterArrayType.php.mustache", srcBasePath + File.separator + "Validator", "QueryParameterArrayType.php"));
|
||||
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, "1.0.0");
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCECODEONLY_GENERATION, CodegenConstants.SOURCECODEONLY_GENERATION_DESC)
|
||||
.defaultValue(Boolean.FALSE.toString()));
|
||||
.defaultValue(Boolean.FALSE.toString()));
|
||||
|
||||
supportedLibraries.put("urllib3", "urllib3-based client");
|
||||
supportedLibraries.put("asyncio", "Asyncio-based client (python 3.5+)");
|
||||
@@ -224,7 +224,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
setPackageUrl((String) additionalProperties.get(PACKAGE_URL));
|
||||
}
|
||||
|
||||
String readmePath ="README.md";
|
||||
String readmePath = "README.md";
|
||||
String readmeTemplate = "README.mustache";
|
||||
if (generateSourceCodeOnly) {
|
||||
readmePath = packageName + "_" + readmePath;
|
||||
@@ -232,7 +232,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
supportingFiles.add(new SupportingFile(readmeTemplate, "", readmePath));
|
||||
|
||||
if (!generateSourceCodeOnly){
|
||||
if (!generateSourceCodeOnly) {
|
||||
supportingFiles.add(new SupportingFile("tox.mustache", "", "tox.ini"));
|
||||
supportingFiles.add(new SupportingFile("test-requirements.mustache", "", "test-requirements.txt"));
|
||||
supportingFiles.add(new SupportingFile("requirements.mustache", "", "requirements.txt"));
|
||||
@@ -552,6 +552,12 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return underscore(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
|
||||
@@ -462,6 +462,12 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return underscore(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,10 @@ package org.openapitools.codegen.languages;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
@@ -64,6 +67,8 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen {
|
||||
protected String pidFolder = tmpFolder + File.separator + "pids";
|
||||
protected String socketsFolder = tmpFolder + File.separator + "sockets";
|
||||
protected String vendorFolder = "vendor";
|
||||
protected String databaseAdapter = "sqlite";
|
||||
|
||||
|
||||
public RubyOnRailsServerCodegen() {
|
||||
super();
|
||||
@@ -87,6 +92,9 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen {
|
||||
|
||||
// remove modelPackage and apiPackage added by default
|
||||
cliOptions.clear();
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.DATABASE_ADAPTER, CodegenConstants.DATABASE_ADAPTER_DESC).
|
||||
defaultValue("sqlite"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +105,24 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen {
|
||||
//setModelPackage("models");
|
||||
setApiPackage("app/controllers");
|
||||
|
||||
supportingFiles.add(new SupportingFile("Gemfile", "", "Gemfile"));
|
||||
// determine which db adapter to use
|
||||
if (additionalProperties.containsKey(CodegenConstants.DATABASE_ADAPTER)) {
|
||||
setDatabaseAdapter((String) additionalProperties.get(CodegenConstants.DATABASE_ADAPTER));
|
||||
} else {
|
||||
// not set, pass the default value to template
|
||||
additionalProperties.put(CodegenConstants.DATABASE_ADAPTER, databaseAdapter);
|
||||
}
|
||||
|
||||
if ("sqlite".equals(databaseAdapter)) {
|
||||
additionalProperties.put("isDBSQLite", Boolean.TRUE);
|
||||
} else if ("mysql".equals(databaseAdapter)) {
|
||||
additionalProperties.put("isDBMySQL", Boolean.TRUE);
|
||||
} else {
|
||||
LOGGER.warn("Unknown database {}. Defaul to 'sqlite'.", databaseAdapter);
|
||||
additionalProperties.put("isDBSQLite", Boolean.TRUE);
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("Gemfile.mustache", "", "Gemfile"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("Rakefile", "", "Rakefile"));
|
||||
supportingFiles.add(new SupportingFile("config.ru", "", "config.ru"));
|
||||
@@ -130,7 +155,7 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen {
|
||||
supportingFiles.add(new SupportingFile("application.rb", configFolder, "application.rb"));
|
||||
supportingFiles.add(new SupportingFile("boot.rb", configFolder, "boot.rb"));
|
||||
supportingFiles.add(new SupportingFile("cable.yml", configFolder, "cable.yml"));
|
||||
supportingFiles.add(new SupportingFile("database.yml", configFolder, "database.yml"));
|
||||
supportingFiles.add(new SupportingFile("database.mustache", configFolder, "database.yml"));
|
||||
supportingFiles.add(new SupportingFile("environment.rb", configFolder, "environment.rb"));
|
||||
supportingFiles.add(new SupportingFile("puma.rb", configFolder, "puma.rb"));
|
||||
supportingFiles.add(new SupportingFile("routes.mustache", configFolder, "routes.rb"));
|
||||
@@ -156,6 +181,8 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen {
|
||||
supportingFiles.add(new SupportingFile(".keep", socketsFolder, ".keep"));
|
||||
supportingFiles.add(new SupportingFile("restart.txt", tmpFolder, "restart.txt"));
|
||||
supportingFiles.add(new SupportingFile(".keep", vendorFolder, ".keep"));
|
||||
supportingFiles.add(new SupportingFile("Dockerfile", "", "Dockerfile"));
|
||||
supportingFiles.add(new SupportingFile("docker-entrypoint.sh", "", "docker-entrypoint.sh"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -225,12 +252,22 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen {
|
||||
return underscore(name) + "_controller";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiVarName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "api";
|
||||
}
|
||||
|
||||
// e.g. PhoneNumber => phone_number
|
||||
return underscore(sanitizeName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "ApiController";
|
||||
}
|
||||
// e.g. phone_number_api => PhoneNumberApi
|
||||
// e.g. phone_number_controller => PhoneNumberController
|
||||
return camelize(name) + "Controller";
|
||||
}
|
||||
|
||||
@@ -239,4 +276,8 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen {
|
||||
generateYAMLSpecFile(objs);
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
|
||||
public void setDatabaseAdapter(String databaseAdapter) {
|
||||
this.databaseAdapter = databaseAdapter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,8 +165,9 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", apiFolder, "configuration.rs"));
|
||||
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("client.mustache", apiFolder, "client.rs"));
|
||||
supportingFiles.add(new SupportingFile("api_mod.mustache", apiFolder, "mod.rs"));
|
||||
supportingFiles.add(new SupportingFile("client.mustache", apiFolder, "client.rs"));
|
||||
supportingFiles.add(new SupportingFile("request.rs", apiFolder, "request.rs"));
|
||||
supportingFiles.add(new SupportingFile("model_mod.mustache", modelFolder, "mod.rs"));
|
||||
supportingFiles.add(new SupportingFile("lib.rs", "src", "lib.rs"));
|
||||
supportingFiles.add(new SupportingFile("Cargo.mustache", "", "Cargo.toml"));
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user