mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-07 17:46:09 +00:00
Compare commits
83 Commits
v4.0.2
...
revert-318
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b3e9eb72f | ||
|
|
c4d61af20b | ||
|
|
7cef5ed8ab | ||
|
|
0e37719162 | ||
|
|
3943d1cc9d | ||
|
|
3f9e374c8d | ||
|
|
7b7e147696 | ||
|
|
51e7005373 | ||
|
|
366ca24062 | ||
|
|
45da167f8e | ||
|
|
109808e60d | ||
|
|
78551d0180 | ||
|
|
fa10103363 | ||
|
|
e9809294a5 | ||
|
|
bd17a15572 | ||
|
|
90bd90c41a | ||
|
|
441f6327d9 | ||
|
|
0b79c5b6be | ||
|
|
65fdce7036 | ||
|
|
1e380850c0 | ||
|
|
267c9bdcf8 | ||
|
|
8d27857f83 | ||
|
|
cbca86b43a | ||
|
|
2c342cc2b4 | ||
|
|
310f5feda0 | ||
|
|
0cb921251d | ||
|
|
dda2f3c141 | ||
|
|
95ba9525f9 | ||
|
|
35262aa7d1 | ||
|
|
b44f6c302a | ||
|
|
1fc7740f2e | ||
|
|
b87806834b | ||
|
|
4e62e92daf | ||
|
|
c012dcd754 | ||
|
|
dd0c2a84ee | ||
|
|
40a293dcda | ||
|
|
1730a4efce | ||
|
|
3e5e82460f | ||
|
|
731b162942 | ||
|
|
e46bd7dd18 | ||
|
|
51014839fd | ||
|
|
23e63dccfa | ||
|
|
6578cef260 | ||
|
|
a41448ab9c | ||
|
|
3a1b29b90c | ||
|
|
73966a0152 | ||
|
|
325ed4b72e | ||
|
|
35a6f9d6e6 | ||
|
|
6c9fefa7b5 | ||
|
|
68a5fa4c8b | ||
|
|
7af2bc8dff | ||
|
|
f41cd234d9 | ||
|
|
c1771c94bd | ||
|
|
01f991a034 | ||
|
|
94c583b6ce | ||
|
|
fe8dd343a8 | ||
|
|
5b9283beca | ||
|
|
f681764067 | ||
|
|
9518e2a02e | ||
|
|
2b55413371 | ||
|
|
74c569ebf8 | ||
|
|
3ee76a0662 | ||
|
|
6b428d65f6 | ||
|
|
034064be4c | ||
|
|
4ac33d80f0 | ||
|
|
06cfdbbdc6 | ||
|
|
55ae485fd0 | ||
|
|
38008e669e | ||
|
|
a882e4b3a5 | ||
|
|
1d8c9dcc0b | ||
|
|
038afd6650 | ||
|
|
2773b32c36 | ||
|
|
a038fcc9c8 | ||
|
|
f6c738ed9e | ||
|
|
e3fe12eacf | ||
|
|
1540ae7951 | ||
|
|
b6bb13b93c | ||
|
|
2a5af92cdf | ||
|
|
b9451e91af | ||
|
|
0e2eed6892 | ||
|
|
46c18ad4dd | ||
|
|
8e0dc2f150 | ||
|
|
8e11fd9fe4 |
@@ -28,7 +28,7 @@ WORKDIR ${TARGET_DIR}
|
||||
|
||||
COPY --from=builder ${GEN_DIR}/modules/openapi-generator-online/target/openapi-generator-online.jar ${TARGET_DIR}/openapi-generator-online.jar
|
||||
|
||||
ENV GENERATOR_HOST=http://localhost
|
||||
ENV GENERATOR_HOST=""
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ if [ "$NODE_INDEX" = "1" ]; then
|
||||
#cp CI/pom.xml.circleci pom.xml
|
||||
java -version
|
||||
mvn --quiet verify -Psamples.circleci
|
||||
mvn --quiet javadoc:javadoc -Psamples.circleci
|
||||
|
||||
# generate all petstore samples (client, servers, doc)
|
||||
./bin/run-all-petstore
|
||||
|
||||
@@ -31,6 +31,8 @@ Please file the pull request against the correct branch, e.g. `master` for non-b
|
||||
|
||||
All the code generators can be found in [modules/openapi-generator/src/main/java/org/openapitools/codegen/languages](https://github.com/openapitools/openapi-generator/tree/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages)
|
||||
|
||||
If you want to add a new generator, follow the [new-generator](https://openapi-generator.tech/docs/new-generator) guide.
|
||||
|
||||
### Templates
|
||||
|
||||
All the templates ([mustache](https://mustache.github.io/)) can be found in [modules/openapi-generator/src/main/resources](https://github.com/openapitools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources).
|
||||
|
||||
31
README.md
31
README.md
@@ -2,7 +2,7 @@
|
||||
|
||||
<div align="center">
|
||||
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`4.0.2`): [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`4.0.3`): [](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)
|
||||
@@ -99,8 +99,8 @@ OpenAPI Generator Version | Release Date | Notes
|
||||
---------------------------- | ------------ | -----
|
||||
5.0.0 (upcoming major release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.0.0-SNAPSHOT/)| 13.05.2020 | Major release with breaking changes (no fallback)
|
||||
4.1.0 (upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.1.0-SNAPSHOT/)| 15.07.2019 | Minor release (breaking changes with fallbacks)
|
||||
4.0.2 (upcoming patch release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.2-SNAPSHOT/)| 15.06.2019 | Patch release (minor bug fixes, etc)
|
||||
[4.0.2](https://github.com/OpenAPITools/openapi-generator/releases/tag/v4.0.2) (latest stable release) | 31.05.2019 | Patch release (bug fixes, minor enhancements, etc)
|
||||
4.0.3 (upcoming patch release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.3-SNAPSHOT/)| 04.07.2019 | Patch release (minor bug fixes, etc)
|
||||
[4.0.2](https://github.com/OpenAPITools/openapi-generator/releases/tag/v4.0.2) (latest stable release) | 20.06.2019 | Patch release (bug fixes, minor enhancements, etc)
|
||||
|
||||
OpenAPI Spec compatibility: 1.0, 1.1, 1.2, 2.0, 3.0
|
||||
|
||||
@@ -153,7 +153,7 @@ See the different versions of the [openapi-generator-cli](https://mvnrepository.
|
||||
* [Readme](https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/README.adoc)
|
||||
|
||||
### [1.3 - Download JAR](#table-of-contents)
|
||||
|
||||
<!-- RELEASE_VERSION -->
|
||||
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/4.0.2/openapi-generator-cli-4.0.2.jar`
|
||||
@@ -175,7 +175,7 @@ For Mac users, please make sure Java 8 is installed (Tips: run `java -version` t
|
||||
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
|
||||
export PATH=${JAVA_HOME}/bin:$PATH
|
||||
```
|
||||
|
||||
<!-- /RELEASE_VERSION -->
|
||||
### 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.
|
||||
@@ -281,7 +281,7 @@ Example usage:
|
||||
|
||||
```sh
|
||||
# Start container at port 8888 and save the container id
|
||||
> CID=$(docker run -d -p 8888:8080 -e GENERATOR_HOST=http://localhost:8888 openapitools/openapi-generator-online)
|
||||
> CID=$(docker run -d -p 8888:8080 openapitools/openapi-generator-online)
|
||||
|
||||
# allow for startup
|
||||
> sleep 10
|
||||
@@ -368,7 +368,8 @@ npm install @openapitools/openapi-generator-cli -g
|
||||
openapi-generator version
|
||||
```
|
||||
|
||||
Or install a particualar OpenAPI Generator version (e.g. v4.0.2):
|
||||
<!-- RELEASE_VERSION -->
|
||||
Or install a particular OpenAPI Generator version (e.g. v4.0.2):
|
||||
|
||||
```sh
|
||||
npm install @openapitools/openapi-generator-cli@cli-4.0.2 -g
|
||||
@@ -379,7 +380,7 @@ Or install it as dev-dependency:
|
||||
```sh
|
||||
npm install @openapitools/openapi-generator-cli -D
|
||||
```
|
||||
|
||||
<!-- /RELEASE_VERSION -->
|
||||
## [2 - Getting Started](#table-of-contents)
|
||||
|
||||
To generate a PHP client for [petstore.yaml](https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml), please run the following
|
||||
@@ -394,7 +395,9 @@ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generat
|
||||
```
|
||||
(if you're on Windows, replace the last command with `java -jar modules\openapi-generator-cli\target\openapi-generator-cli.jar generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g php -o c:\temp\php_api_client`)
|
||||
|
||||
<!-- RELEASE_VERSION -->
|
||||
You can also download the JAR (latest release) directly from [maven.org](http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/4.0.2/openapi-generator-cli-4.0.2.jar)
|
||||
<!-- /RELEASE_VERSION -->
|
||||
|
||||
To get a list of **general** options available, please run `java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar help generate`
|
||||
|
||||
@@ -535,6 +538,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- [Camptocamp](https://www.camptocamp.com/en)
|
||||
- [codecentric AG](https://www.codecentric.de/)
|
||||
- [Cupix](https://www.cupix.com/)
|
||||
- [DB Systel](https://www.dbsystel.de)
|
||||
- [FormAPI](https://formapi.io/)
|
||||
- [Fuse](https://www.fuse.no/)
|
||||
- [GenFlow](https://github.com/RepreZen/GenFlow)
|
||||
@@ -591,7 +595,9 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- 2019-05-01 - [Design and generate a REST API from Swagger / OpenAPI in Java, Python, C# and more](https://simply-how.com/design-and-generate-api-code-from-openapi) by [Simply How](https://simply-how.com/)
|
||||
- 2019-05-17 - [Generate Spring Boot REST API using Swagger/OpenAPI](https://www.47northlabs.com/knowledge-base/generate-spring-boot-rest-api-using-swagger-openapi/) by [Antonie Zafirov](https://www.47northlabs.com/author/antonie-zafirov/)
|
||||
- 2019-05-22 - [REST APIs代码生成指南(OpenAPI Generator)](https://gum.co/openapi_generator_ebook_gb) by [William Cheng](https://twitter.com/wing328), [Xin Meng](https://github.com/xmeng1)
|
||||
- 2019-05/24 - [REST API 代碼生成指南 (OpenAPI Generator)](https://gum.co/openapi_generator_ebook_big5) by [William Cheng](https://twitter.com/wing328)
|
||||
- 2019-05-24 - [REST API 代碼生成指南 (OpenAPI Generator)](https://gum.co/openapi_generator_ebook_big5) by [William Cheng](https://twitter.com/wing328)
|
||||
- 2019-06-24 - [Kubernetes Clients and OpenAPI Generator](https://speakerdeck.com/wing328/kubernetes-clients-and-openapi-generator) by [William Cheng](https://twitter.com/wing328) at [Kubernetes Contributor Summits Shanghai 2019](https://www.lfasiallc.com/events/contributors-summit-china-2019/)
|
||||
- 2019-07-04 - [REST API のためのコード生成入門 (OpenAPI Generator)](https://gum.co/openapi_generator_ebook_big5) by [William Cheng](https://twitter.com/wing328), [中野暁人](https://github.com/ackintosh), [和田拓朗](https://github.com/taxpon)
|
||||
|
||||
## [6 - About Us](#table-of-contents)
|
||||
|
||||
@@ -677,7 +683,8 @@ Here is a list of template creators:
|
||||
* TypeScript (Inversify): @gualtierim
|
||||
* Server Stubs
|
||||
* Ada: @stcarrez
|
||||
* C# ASP.NET5: @jimschubert [:heart:](https://www.patreon.com/jimschubert)
|
||||
* C# ASP.NET 5: @jimschubert [:heart:](https://www.patreon.com/jimschubert)
|
||||
* C# ASP.NET Core 3.0: @A-Joshi
|
||||
* C# NancyFX: @mstefaniuk
|
||||
* C++ (Qt5 QHttpEngine): @etherealjoy
|
||||
* C++ Pistache: @sebymiano
|
||||
@@ -776,11 +783,11 @@ If you want to join the committee, please kindly apply by sending an email to te
|
||||
| Lua | @daurnimator (2017/08) |
|
||||
| NodeJS/Javascript | @CodeNinjai (2017/07) @frol (2017/07) @cliffano (2017/07) |
|
||||
| ObjC | |
|
||||
| Perl | @wing328 (2017/07) [:heart:](https://www.patreon.com/wing328) |
|
||||
| Perl | @wing328 (2017/07) [:heart:](https://www.patreon.com/wing328) @yue9944882 (2019/06) |
|
||||
| PHP | @jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), @ackintosh (2017/09) [:heart:](https://www.patreon.com/ackintosh/overview), @ybelenko (2018/07), @renepardon (2018/12) |
|
||||
| PowerShell | |
|
||||
| Python | @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01) |
|
||||
| R | |
|
||||
| R | @Ramanth (2019/07) @saigiridhar21 (2019/07) |
|
||||
| Ruby | @cliffano (2017/07) @zlx (2017/09) @autopp (2019/02) |
|
||||
| Rust | @frol (2017/07) @farcaller (2017/08) @bjgill (2017/12) |
|
||||
| Scala | @clasnake (2017/07), @jimschubert (2017/09) [:heart:](https://www.patreon.com/jimschubert), @shijinkui (2018/01), @ramzimaalej (2018/03) |
|
||||
|
||||
39
bin/go-experimental-petstore.sh
Executable file
39
bin/go-experimental-petstore.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/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
|
||||
|
||||
SPEC="modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml"
|
||||
GENERATOR="go-experimental"
|
||||
STUB_DIR="samples/client/petstore/go-experimental/go-petstore"
|
||||
|
||||
echo "Removing files and folders under $STUB_DIR"
|
||||
rm -rf $STUB_DIR
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/$GENERATOR -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstore $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
39
bin/openapi3/go-experimental-petstore.sh
Executable file
39
bin/openapi3/go-experimental-petstore.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/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
|
||||
|
||||
SPEC="modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml"
|
||||
GENERATOR="go-experimental"
|
||||
STUB_DIR="samples/openapi3/client/petstore/go-experimental/go-petstore"
|
||||
|
||||
echo "Removing files and folders under $STUB_DIR"
|
||||
rm -rf $STUB_DIR
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/$GENERATOR -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstore $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -26,7 +26,7 @@ then
|
||||
fi
|
||||
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -t modules/openapi-generator/src/main/resources/kotlin-spring -g kotlin-spring -o samples/server/openapi3/petstore/kotlin-springboot-reactive --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true,reactive=true"
|
||||
ags="$@ generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -t modules/openapi-generator/src/main/resources/kotlin-spring -g kotlin-spring -o samples/openapi3/server/petstore/kotlin-springboot-reactive --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true,reactive=true"
|
||||
|
||||
echo "Cleaning previously generated files if any from samples/server/openapi3/petstore/kotlin-springboot-reactive"
|
||||
rm -rf samples/server/openapi3/petstore/kotlin-springboot-reactive
|
||||
|
||||
@@ -26,7 +26,7 @@ then
|
||||
fi
|
||||
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -t modules/openapi-generator/src/main/resources/kotlin-spring -g kotlin-spring -o samples/server/openapi3/petstore/kotlin-springboot --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true"
|
||||
ags="$@ generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -t modules/openapi-generator/src/main/resources/kotlin-spring -g kotlin-spring -o samples/openapi3/server/petstore/kotlin-springboot --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true"
|
||||
|
||||
echo "Cleaning previously generated files if any from samples/server/openapi3/petstore/kotlin-springboot"
|
||||
rm -rf samples/server/openapi3/petstore/kotlin-springboot
|
||||
|
||||
@@ -26,7 +26,7 @@ then
|
||||
fi
|
||||
|
||||
input=modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
out_folder=samples/server/openapi3/petstore/php-ze-ph
|
||||
out_folder=samples/openapi3/server/petstore/php-ze-ph
|
||||
resources=modules/openapi-generator/src/main/resources/php-ze-ph
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
|
||||
@@ -27,7 +27,7 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
input=modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
out_folder=samples/server/openapi3/petstore/python-flask-python2
|
||||
out_folder=samples/openapi3/server/petstore/python-flask-python2
|
||||
resources=modules/openapi-generator/src/main/resources/python-flask
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
|
||||
@@ -27,7 +27,7 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
input=modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
out_folder=samples/server/openapi3/petstore/python-flask
|
||||
out_folder=samples/openapi3/server/petstore/python-flask
|
||||
resources=modules/openapi-generator/src/main/resources/python-flask
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
|
||||
32
bin/python-experimental-petstore.sh
Executable file
32
bin/python-experimental-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} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/python -i modules/openapi-generator/src/test/resources/2_0/python-client-experimental/petstore-with-fake-endpoints-models-for-testing.yaml -g python-experimental -o samples/client/petstore/python-experimental -DpackageName=petstore_api $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -25,6 +25,7 @@ declare -a scripts=(
|
||||
"./bin/kotlin-client-threetenbp.sh"
|
||||
"./bin/kotlin-server-petstore.sh"
|
||||
"./bin/kotlin-springboot-petstore-server.sh"
|
||||
"./bin/kotlin-springboot-petstore-server-reactive.sh"
|
||||
"./bin/mysql-schema-petstore.sh"
|
||||
"./bin/python-petstore-all.sh"
|
||||
"./bin/openapi3/python-petstore.sh"
|
||||
@@ -55,6 +56,7 @@ declare -a scripts=(
|
||||
"./bin/go-gin-petstore-server.sh"
|
||||
"./bin/groovy-petstore.sh"
|
||||
"./bin/apex-petstore.sh"
|
||||
"./bin/perl-petstore-all.sh"
|
||||
#"./bin/elm-petstore-all.sh"
|
||||
"./bin/meta-codegen.sh"
|
||||
# OTHERS
|
||||
|
||||
221
bin/utils/release/bump.sh
Executable file
221
bin/utils/release/bump.sh
Executable file
@@ -0,0 +1,221 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This script bumps from one version to another
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
declare -r version_regex="([0-9]+).([0-9]+).([0-9]+)-?(SNAPSHOT){0,1}"
|
||||
declare start="<!-- RELEASE_VERSION -->"
|
||||
declare end="<!-- \/RELEASE_VERSION -->"
|
||||
declare from="${version_regex}"
|
||||
declare to=""
|
||||
declare debug=${debug:-false}
|
||||
declare -a from_parts=()
|
||||
declare -a to_parts=()
|
||||
declare -ar inc=(major minor build snapshot)
|
||||
|
||||
USAGE="
|
||||
USAGE: $0 OPTIONS input_file
|
||||
|
||||
This script will bump a version number (or other value) between marker tags.
|
||||
|
||||
OPTIONS:
|
||||
-f The 'from' version
|
||||
-t The 'to' version
|
||||
-s The start tag regex
|
||||
default: $start
|
||||
-e The end tag regex
|
||||
default: $end
|
||||
-i Increase by one of: ${inc[@]}
|
||||
-h Print this message
|
||||
|
||||
EXAMPLES:
|
||||
|
||||
Update to next snapshot version:
|
||||
$0 -f 3.0.0 -t 3.0.1-SNAPSHOT pom.xml
|
||||
Update build version only (useful for docs)
|
||||
$0 -f 3.0.0 -t 3.0.1 pom.xml
|
||||
Update from any version to any other version
|
||||
$0 -f 1.2.3 -t 9.9.9-SNAPSHOT pom.xml
|
||||
Customize the start/end tags
|
||||
$0 -f 1.0.0 1.0.1-SNAPSHOT -s \"<!-- START -->\" -e \"<!-- END -->\" pom.xml
|
||||
"
|
||||
|
||||
|
||||
## print an error message and exit
|
||||
err() {
|
||||
>&2 echo -e "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
## debug log messages. Run with debug=true ./bump.sh
|
||||
d() {
|
||||
if [[ true = "${debug}" ]]; then
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
## outputs usage and exits
|
||||
usage()
|
||||
{
|
||||
err "${USAGE}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
## usage: version input extracted_array
|
||||
## - Checks that 'input' is a valid version
|
||||
## - Extracts the version parts into 'extracted_array'
|
||||
version()
|
||||
{
|
||||
if [[ "$#" -ne 2 ]]; then
|
||||
err "Call function version with two parameters: version string arr"
|
||||
fi
|
||||
local v=$1
|
||||
if [[ "${v}" =~ $version_regex ]]; then
|
||||
local major=${BASH_REMATCH[1]}
|
||||
local minor=${BASH_REMATCH[2]}
|
||||
local build=${BASH_REMATCH[3]}
|
||||
local snapshot=false
|
||||
if [[ "SNAPSHOT" = "${BASH_REMATCH[4]}" ]]; then
|
||||
snapshot=true
|
||||
fi
|
||||
|
||||
d "major=$major minor=$minor build=$build snapshot=$snapshot"
|
||||
|
||||
eval "$2=(${major} ${minor} ${build} ${snapshot})"
|
||||
else
|
||||
err "Invalid version: $v"
|
||||
fi
|
||||
}
|
||||
|
||||
while getopts "hf:t:s:e:i:" OPTION
|
||||
do
|
||||
case ${OPTION} in
|
||||
f)
|
||||
from=${OPTARG}
|
||||
;;
|
||||
t)
|
||||
to=${OPTARG}
|
||||
;;
|
||||
s)
|
||||
start=${OPTARG}
|
||||
;;
|
||||
e)
|
||||
end=${OPTARG}
|
||||
;;
|
||||
i)
|
||||
increase=${OPTARG}
|
||||
if [[ ! "${inc[@]}" =~ ${increase} ]];then
|
||||
err "Only support increasing by one of: ${inc[@]}"
|
||||
fi
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
file=( "$@" )
|
||||
|
||||
if [[ ${#file[@]} -eq 0 ]];then
|
||||
echo "No file specified" >&2
|
||||
usage
|
||||
fi
|
||||
|
||||
if [[ -z "${from}" ]]; then
|
||||
echo "No 'from' version specified." >&2
|
||||
usage
|
||||
fi
|
||||
|
||||
# TODO: compare steps in from_parts and to_parts.
|
||||
version "${from}" from_parts
|
||||
|
||||
if [[ -z "${to}" ]]; then
|
||||
if [[ -z "${increase}" ]]; then
|
||||
err "No 'to' version specified."
|
||||
else
|
||||
case ${increase} in
|
||||
major)
|
||||
to="$(( ${from_parts[0]} + 1 )).0.0"
|
||||
version "$to" to_parts
|
||||
;;
|
||||
minor)
|
||||
to="${from_parts[0]}.$(( ${from_parts[1]} + 1 )).0"
|
||||
version "$to" to_parts
|
||||
;;
|
||||
build)
|
||||
to="${from_parts[0]}.${from_parts[1]}.$(( ${from_parts[2]} + 1 ))"
|
||||
version "$to" to_parts
|
||||
;;
|
||||
snapshot)
|
||||
if [[ true = ${from_parts[3]} ]]; then
|
||||
err "Can't move from SNAPSHOT to SNAPSHOT (from=${from})."
|
||||
else
|
||||
to="${from_parts[0]}.${from_parts[1]}.$(( ${from_parts[2]} + 1 ))-SNAPSHOT"
|
||||
version "$to" to_parts
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
version "${to}" to_parts
|
||||
fi
|
||||
|
||||
if [[ ${from_parts[3]} = true && ${to_parts[3]} = true ]]; then
|
||||
err "Moving from SNAPSHOT to SNAPSHOT is not supported."
|
||||
fi
|
||||
|
||||
cat <<EOF > sedscript.sed
|
||||
/${start}/,/${end}/{
|
||||
s/${from}/${to}/g
|
||||
}
|
||||
EOF
|
||||
|
||||
d "Moving from=${from} to=${to}"
|
||||
|
||||
trap 'rm -f sedscript.sed' EXIT
|
||||
|
||||
sed_cross() {
|
||||
# Cross-platform sed invocation. OSX has no option to show a version number in sed.
|
||||
local target=$1
|
||||
sed --version >/dev/null 2>&1 && sed -e -i '' -f sedscript.sed "$target" || sed -i '' -E -f sedscript.sed "$target"
|
||||
}
|
||||
|
||||
update_file() {
|
||||
local filename=$1
|
||||
local error_message="ERROR: Failed to update $filename to target version ${to}"
|
||||
local original_hash=$(ruby -r digest -e "p Digest::SHA2.file(\"$filename\").hexdigest")
|
||||
local final_hash=""
|
||||
if ! sed_cross ${filename}; then
|
||||
# occurs if, for example, the file doesn't exist.
|
||||
echo "ERROR: Failed to update $filename to target version ${to}" >&2
|
||||
fi
|
||||
|
||||
local final_hash=$(ruby -r digest -e "p Digest::SHA2.file(\"$filename\").hexdigest")
|
||||
|
||||
if [[ "${original_hash}" = "${final_hash}" ]]; then
|
||||
# occurs if, for example, the file doesn't have expected marker tags for replacement
|
||||
echo "ERROR: $filename was not modified." >&2
|
||||
else
|
||||
echo "Updated $filename successfully!"
|
||||
fi
|
||||
}
|
||||
|
||||
for filename in "${file[@]}"; do
|
||||
update_file ${filename}
|
||||
done
|
||||
|
||||
96
bin/utils/release/release_version_update.sh
Executable file
96
bin/utils/release/release_version_update.sh
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This script is used to update files to the "latest" version.
|
||||
#
|
||||
# usage: ./bin/utils/release_version_update.sh <from> <to>
|
||||
# example: ./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.
|
||||
#
|
||||
|
||||
declare cwd=$(cd $(dirname "${BASH_SOURCE}") && pwd)
|
||||
declare root=$(cd "$cwd" && cd ../../../ && pwd)
|
||||
|
||||
USAGE="
|
||||
USAGE: $0 target
|
||||
|
||||
This script will convert the current version in target files to the specified 'target'
|
||||
where target is one of:
|
||||
|
||||
major
|
||||
minor
|
||||
build
|
||||
snapshot
|
||||
|
||||
EXAMPLES:
|
||||
|
||||
Update to new snapshot (1.0.0 -> 1.0.1-SNAPSHOT):
|
||||
$0 snapshot
|
||||
Update build version (1.0.0 -> 1.0.1)
|
||||
$0 build
|
||||
Update minor version (1.2.3 -> 1.3.0)
|
||||
$0 minor
|
||||
Update major version (1.2.3 -> 2.0.0)
|
||||
$0 major
|
||||
"
|
||||
|
||||
version=$(ruby -r rexml/document -e 'include REXML;
|
||||
p XPath.first(Document.new($stdin), "/project/version/text()")' < ${cwd}/../../../pom.xml | tr -d '"')
|
||||
|
||||
if [[ -n "$1" ]]; then
|
||||
case $1 in
|
||||
--help|-h)
|
||||
echo -e "$USAGE" >&2
|
||||
exit 1
|
||||
;;
|
||||
major|minor|build|snapshot)
|
||||
inc="$1"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid target.Must be one of: major minor build or snapshot" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
inc="snapshot"
|
||||
fi
|
||||
|
||||
echo "Release preparation: Moving from $version to next $inc version."
|
||||
|
||||
# These files should wrap target version replacement blocks with <!-- RELEASE_VERSION --> and <!-- /RELEASE_VERSION -->
|
||||
# We can include xml and md files here.
|
||||
declare -a xml_files=(
|
||||
"${root}/modules/openapi-generator-cli/pom.xml"
|
||||
"${root}/modules/openapi-generator-gradle-plugin/pom.xml"
|
||||
"${root}/modules/openapi-generator-core/pom.xml"
|
||||
"${root}/modules/openapi-generator-maven-plugin/pom.xml"
|
||||
"${root}/modules/openapi-generator-online/pom.xml"
|
||||
"${root}/modules/openapi-generator/pom.xml"
|
||||
"${root}/modules/openapi-generator-maven-plugin/examples/multi-module/java-client/pom.xml"
|
||||
"${root}/modules/openapi-generator-maven-plugin/examples/java-client.xml"
|
||||
"${root}/modules/openapi-generator-maven-plugin/examples/non-java-invalid-spec.xml"
|
||||
"${root}/modules/openapi-generator-maven-plugin/examples/non-java.xml"
|
||||
"${root}/samples/meta-codegen/lib/pom.xml"
|
||||
"${root}/pom.xml"
|
||||
)
|
||||
|
||||
# These files should wrap target version replacement blocks with # RELEASE_VERSION and # /RELEASE_VERSION
|
||||
declare -a properties_files=(
|
||||
"${root}/modules/openapi-generator-gradle-plugin/gradle.properties"
|
||||
"${root}/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle.properties"
|
||||
)
|
||||
|
||||
${cwd}/bump.sh -f ${version} -i ${inc} ${xml_files[@]}
|
||||
${cwd}/bump.sh -f ${version} -t ${inc} -s '# RELEASE_VERSION' -e '# \/RELEASE_VERSION' ${properties_files[@]}
|
||||
115
bin/utils/release/release_version_update_docs.sh
Executable file
115
bin/utils/release/release_version_update_docs.sh
Executable file
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This script is used to update reference files to the "next" version.
|
||||
#
|
||||
# usage: ./bin/utils/release_version_update.sh <from> <to>
|
||||
# example: ./bin/utils/release_version_update.sh 3.0.1 3.0.2
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
declare cwd=$(cd $(dirname "${BASH_SOURCE}") && pwd)
|
||||
declare root=$(cd "$cwd" && cd ../../../ && pwd)
|
||||
|
||||
USAGE="
|
||||
USAGE: $0 version target
|
||||
|
||||
This script will convert the specified version in DOC target files to the 'target'
|
||||
where target is one of:
|
||||
|
||||
major
|
||||
minor
|
||||
build
|
||||
|
||||
or an explicitly defined version number.
|
||||
|
||||
NOTE:
|
||||
|
||||
Files prepped by this script should never target SNAPSHOT, as the docs should refer to release artifacts.
|
||||
If intending to update to/from snapshots, please add target files to release_version_update.sh instead.
|
||||
|
||||
EXAMPLES:
|
||||
|
||||
Update build version (1.0.0 -> 1.0.1)
|
||||
$0 1.0.0 build
|
||||
Update minor version (1.2.3 -> 1.3.0)
|
||||
$0 1.2.3 minor
|
||||
Update major version (1.2.3 -> 2.0.0)
|
||||
$0 1.2.3 major
|
||||
"
|
||||
|
||||
declare version=$(ruby -r rexml/document -e 'include REXML;
|
||||
p XPath.first(Document.new($stdin), "/project/version/text()")' < ${cwd}/../../../pom.xml | tr -d '"')
|
||||
|
||||
declare target="${2:-build}"
|
||||
declare inc=""
|
||||
declare next_version=""
|
||||
declare ags=""
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
echo "Missing argument." >&2
|
||||
echo -e "$USAGE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get version number we're changing
|
||||
case $1 in
|
||||
--help|-h)
|
||||
echo -e "$USAGE" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
version="$1"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Get the target…
|
||||
case ${target} in
|
||||
major|minor|build)
|
||||
inc="$target"
|
||||
;;
|
||||
snapshot)
|
||||
echo -e "Files prepped by this script should never target SNAPSHOT, as the docs should refer to release artifacts.
|
||||
If intending to update to/from snapshots, please add target files to release_version_update.sh instead.
|
||||
" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
next_version="$target"
|
||||
;;
|
||||
esac
|
||||
|
||||
ags="-f ${version}"
|
||||
|
||||
if [[ -n "${next_version}" ]];then
|
||||
echo "Release preparation: Moving from $version to ${next_version}."
|
||||
ags="$ags -t ${next_version}"
|
||||
else
|
||||
echo "Release preparation: Moving from $version to next $inc version."
|
||||
ags="$ags -i ${inc}"
|
||||
fi
|
||||
|
||||
declare -a xml_files=(
|
||||
"${root}/modules/openapi-generator-maven-plugin/README.md"
|
||||
"${root}/modules/openapi-generator-gradle-plugin/samples/local-spec/README.md"
|
||||
"${root}/README.md"
|
||||
)
|
||||
|
||||
declare -a commented_files=(
|
||||
"${root}/modules/openapi-generator-gradle-plugin/README.adoc"
|
||||
)
|
||||
|
||||
${cwd}/bump.sh ${ags} ${xml_files[@]}
|
||||
${cwd}/bump.sh ${ags} -s '# RELEASE_VERSION' -e '# \/RELEASE_VERSION' ${commented_files[@]}
|
||||
17
bin/utils/release/testing.txt
Normal file
17
bin/utils/release/testing.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
This is a test simple:
|
||||
<!-- RELEASE_VERSION -->3.0.1<!-- /RELEASE_VERSION -->
|
||||
|
||||
Testing with other data:
|
||||
<!-- RELEASE_VERSION -->
|
||||
Version 1.2.3
|
||||
<!-- /RELEASE_VERSION -->
|
||||
|
||||
Testing with -SNAPSHOT data:
|
||||
<!-- RELEASE_VERSION -->
|
||||
Version 2.3.4-SNAPSHOT
|
||||
<!-- /RELEASE_VERSION -->
|
||||
|
||||
Testing with a value not to be replaced:
|
||||
<!-- RELEASE_VERSION -->
|
||||
Version 3.2.2
|
||||
<!-- /RELEASE_VERSION -->
|
||||
17
bin/utils/release/testing2.txt
Normal file
17
bin/utils/release/testing2.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
This is a test simple:
|
||||
<!-- RELEASE_VERSION -->3.0.1<!-- /RELEASE_VERSION -->
|
||||
|
||||
Testing with other data:
|
||||
<!-- RELEASE_VERSION -->
|
||||
Version 1.2.3
|
||||
<!-- /RELEASE_VERSION -->
|
||||
|
||||
Testing with -SNAPSHOT data:
|
||||
<!-- RELEASE_VERSION -->
|
||||
Version 2.3.4-SNAPSHOT
|
||||
<!-- /RELEASE_VERSION -->
|
||||
|
||||
Testing with a value not to be replaced:
|
||||
<!-- RELEASE_VERSION -->
|
||||
Version 3.2.2
|
||||
<!-- /RELEASE_VERSION -->
|
||||
@@ -40,7 +40,8 @@ end
|
||||
def check_openapi_generator_online_docker
|
||||
print "Checking openapi-generator-online docker ... "
|
||||
|
||||
url = "https://hub.docker.com/r/openapitools/openapi-generator-online/tags/"
|
||||
url = "https://hub.docker.com/v2/repositories/openapitools/openapi-generator-online/tags/?page_size=25&page=1"
|
||||
|
||||
docker_tag = "v#{$version}"
|
||||
open(url) do |f|
|
||||
content = f.read
|
||||
@@ -56,7 +57,7 @@ end
|
||||
def check_openapi_generator_cli_docker
|
||||
print "Checking openapi-generator-cli docker ... "
|
||||
|
||||
url = "https://hub.docker.com/r/openapitools/openapi-generator-cli/tags/"
|
||||
url = "https://hub.docker.com/v2/repositories/openapitools/openapi-generator-cli/tags/?page_size=25&page=1"
|
||||
docker_tag = "v#{$version}"
|
||||
open(url) do |f|
|
||||
content = f.read
|
||||
@@ -202,6 +203,8 @@ $version = ARGV[0]
|
||||
|
||||
puts "Running checkout on OpenAPI Generator release #{$version}"
|
||||
|
||||
check_openapi_generator_online_docker
|
||||
check_openapi_generator_cli_docker
|
||||
check_npmjs
|
||||
check_homebrew
|
||||
check_openapi_generator_jar
|
||||
@@ -211,5 +214,3 @@ check_openapi_generator_gradle_plugin_jar
|
||||
check_openapi_generator_online_jar
|
||||
check_openapi_generator_project_pom
|
||||
check_readme
|
||||
check_openapi_generator_online_docker
|
||||
check_openapi_generator_cli_docker
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
#!/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 "Release preparation: replacing $FROM with $TO in different files"
|
||||
|
||||
# This script assumes the files defined here have a version surrounded by angle brackets within an xml node.
|
||||
# For example, >4.0.0< becomes >4.0.1-SNAPSHOT<.
|
||||
# Verify the sed command below against a file before adding here.
|
||||
declare -a files=("modules/openapi-generator-cli/pom.xml"
|
||||
"modules/openapi-generator-gradle-plugin/pom.xml"
|
||||
"modules/openapi-generator-core/pom.xml"
|
||||
"modules/openapi-generator-maven-plugin/pom.xml"
|
||||
"modules/openapi-generator-online/pom.xml"
|
||||
"modules/openapi-generator/pom.xml"
|
||||
"samples/meta-codegen/lib/pom.xml"
|
||||
"pom.xml")
|
||||
|
||||
sedi () {
|
||||
# Cross-platform version of sed -i that works both on Mac and Linux
|
||||
sed --version >/dev/null 2>&1 && sed -i -e "$@" || sed -i "" "$@"
|
||||
}
|
||||
|
||||
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 sedi "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
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g android -o samples\client\petstore\android\httpclient-Dlibrary=httpclient
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g android -o samples\client\petstore\android\httpclient -Dlibrary=httpclient
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
21
bin/windows/go-experimental-petstore.bat
Executable file
21
bin/windows/go-experimental-petstore.bat
Executable file
@@ -0,0 +1,21 @@
|
||||
setlocal
|
||||
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set SPEC=modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
set GENERATOR=go-experimental
|
||||
set STUB_DIR=samples\client\petstore\go-experimental\go-petstore
|
||||
|
||||
echo Removing files and folders under %STUB_DIR%
|
||||
del /F /S /Q %STUB_DIR%
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\openapi-generator\src\main\resources\%GENERATOR% -i %SPEC% -g %GENERATOR% -o %STUB_DIR% -DpackageName=petstore
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
endlocal
|
||||
@@ -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\3_0\petstore.yaml -g kotlin-spring -o samples\server\openapi3\petstore\kotlin-springboot --additional-properties=library=spring-boot
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -g kotlin-spring -o samples\openapi3\server\petstore\kotlin-springboot --additional-properties=library=spring-boot
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g r -o samples\client\petstore\R
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g r -o samples\client\petstore\R --additional-properties packageName=petstore,returnExceptionOnFailure=false,exceptionPackage=default
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -35,6 +35,8 @@ Please file the pull request against the correct branch, e.g. `master` for non-b
|
||||
|
||||
All the code generators can be found in [modules/openapi-generator/src/main/java/org/openapitools/codegen/languages](https://github.com/openapitools/openapi-generator/tree/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages)
|
||||
|
||||
If you want to add a new generator, follow the [new-generator](https://openapi-generator.tech/docs/new-generator) guide.
|
||||
|
||||
### Templates
|
||||
|
||||
All the templates ([mustache](https://mustache.github.io/)) can be found in [modules/openapi-generator/src/main/resources](https://github.com/openapitools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources).
|
||||
|
||||
@@ -248,7 +248,7 @@ CONFIG OPTIONS
|
||||
retrofit - HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)
|
||||
retrofit2 - HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta2)
|
||||
google-api-client - HTTP client: google-api-client 1.23.0. JSON processing: Jackson 2.8.9
|
||||
rest-assured - HTTP client: rest-assured : 3.3.0. JSON processing: Gson 2.8.5. Only for Java8
|
||||
rest-assured - HTTP client: rest-assured : 4.0.0. JSON processing: Gson 2.8.5. Only for Java8
|
||||
```
|
||||
|
||||
Your config file for Java can look like
|
||||
|
||||
@@ -27,6 +27,7 @@ The following generators are available:
|
||||
- [erlang-proper](generators/erlang-proper.md)
|
||||
- [flash](generators/flash.md)
|
||||
- [go](generators/go.md)
|
||||
- [go-experimental](generators/go-experimental.md)
|
||||
- [groovy](generators/groovy.md)
|
||||
- [haskell-http-client](generators/haskell-http-client.md)
|
||||
- [java](generators/java.md)
|
||||
@@ -42,6 +43,7 @@ The following generators are available:
|
||||
- [php](generators/php.md)
|
||||
- [powershell](generators/powershell.md)
|
||||
- [python](generators/python.md)
|
||||
- [python-experimental](generators/python-experimental.md)
|
||||
- [r](generators/r.md)
|
||||
- [ruby](generators/ruby.md)
|
||||
- [rust](generators/rust.md)
|
||||
|
||||
@@ -16,14 +16,19 @@ sidebar_label: aspnetcore
|
||||
|packageVersion|C# package version.| |1.0.0|
|
||||
|packageGuid|The GUID that will be associated with the C# project| |null|
|
||||
|sourceFolder|source folder for generated code| |src|
|
||||
|compatibilityVersion|ASP.Net Core CompatibilityVersion| |Version_2_1|
|
||||
|aspnetCoreVersion|ASP.NET Core version: 2.2 (default), 2.1, 2.0 (deprecated)| |2.2|
|
||||
|compatibilityVersion|ASP.Net Core CompatibilityVersion| |Version_2_2|
|
||||
|aspnetCoreVersion|ASP.NET Core version: 3.0 (preview4 only), 2.2, 2.1, 2.0 (deprecated)| |2.2|
|
||||
|swashbuckleVersion|Swashbucke version: 3.0.0, 4.0.0| |3.0.0|
|
||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|
|
||||
|useCollection|Deserialize array types to Collection<T> instead of List<T>.| |false|
|
||||
|returnICollection|Return ICollection<T> instead of the concrete type.| |false|
|
||||
|useSwashbuckle|Uses the Swashbuckle.AspNetCore NuGet package for documentation.| |true|
|
||||
|isLibrary|Is the build a library| |false|
|
||||
|useFrameworkReference|Use frameworkReference for ASP.NET Core 3.0+ and PackageReference ASP.NET Core 2.2 or earlier.| |false|
|
||||
|useNewtonsoft|Uses the Newtonsoft JSON library.| |true|
|
||||
|newtonsoftVersion|Version for Microsoft.AspNetCore.Mvc.NewtonsoftJson for ASP.NET Core 3.0+| |3.0.0-preview5-19227-01|
|
||||
|useDefaultRouting|Use default routing for the ASP.NET Core version. For 3.0 turn off default because it is not yet supported.| |true|
|
||||
|classModifier|Class Modifier can be empty, abstract| ||
|
||||
|operationModifier|Operation Modifier can be virtual, abstract or partial| |virtual|
|
||||
|buildTarget|Target to build an application or library| |program|
|
||||
|
||||
16
docs/generators/go-experimental.md
Normal file
16
docs/generators/go-experimental.md
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
---
|
||||
id: generator-opts-client-go-experimental
|
||||
title: Config Options for go-experimental
|
||||
sidebar_label: go-experimental
|
||||
---
|
||||
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|packageName|Go package name (convention: lowercase).| |openapi|
|
||||
|packageVersion|Go package version.| |1.0.0|
|
||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||
|isGoSubmodule|whether the generated Go module is a submodule| |false|
|
||||
|withGoCodegenComment|whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs| |false|
|
||||
|withXml|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)| |false|
|
||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||
@@ -43,4 +43,5 @@ sidebar_label: java-vertx
|
||||
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|
||||
|snapshotVersion|Uses a SNAPSHOT version.|<dl><dt>**true**</dt><dd>Use a SnapShot Version</dd><dt>**false**</dt><dd>Use a Release Version</dd><dl>|null|
|
||||
|rxInterface|When specified, API interfaces are generated with RX and methods return Single<> and Comparable.| |false|
|
||||
|rxVersion2|When specified in combination with rxInterface, API interfaces are generated with RxJava2.| |false|
|
||||
|vertxSwaggerRouterVersion|Specify the version of the swagger router library| |null|
|
||||
|
||||
@@ -27,4 +27,5 @@ sidebar_label: kotlin-spring
|
||||
|serviceImplementation|generate stub service implementations that extends service interfaces. If this is set to true service interfaces will also be generated| |false|
|
||||
|useBeanValidation|Use BeanValidation API annotations to validate data types| |true|
|
||||
|reactive|use coroutines for reactive behavior| |false|
|
||||
|interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
|
||||
|library|library template (sub-template)|<dl><dt>**spring-boot**</dt><dd>Spring-boot Server application.</dd><dl>|spring-boot|
|
||||
|
||||
17
docs/generators/python-experimental.md
Normal file
17
docs/generators/python-experimental.md
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
---
|
||||
id: generator-opts-client-python-experimental
|
||||
title: Config Options for python-experimental
|
||||
sidebar_label: python-experimental
|
||||
---
|
||||
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|packageName|python package name (convention: snake_case).| |openapi_client|
|
||||
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|
||||
|packageVersion|python package version.| |1.0.0|
|
||||
|packageUrl|python package URL.| |null|
|
||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||
|generateSourceCodeOnly|Specifies that only a library source code is to be generated.| |false|
|
||||
|library|library template (sub-template) to use: asyncio, tornado, urllib3| |urllib3|
|
||||
@@ -10,3 +10,5 @@ sidebar_label: r
|
||||
|packageName|R package name (convention: lowercase).| |openapi|
|
||||
|packageVersion|R package version.| |1.0.0|
|
||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||
|returnExceptionOnFailure|Throw an exception on non success response codes| |false|
|
||||
|exceptionPackage|Specify the exception handling package|<dl><dt>**default**</dt><dd>Use stop() for raising exceptions.</dd><dt>**rlang**</dt><dd>Use rlang package for exceptions.</dd><dl>|default|
|
||||
|
||||
@@ -35,7 +35,7 @@ sidebar_label: spring
|
||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |false|
|
||||
|withXml|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)| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date (if you really have a good reason not to use threetenbp</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+) - note: this also sets "java8" to true</dd><dt>**threetenbp**</dt><dd>Backport of JSR310 (preferred for jdk < 1.8)</dd><dl>|threetenbp|
|
||||
|java8|Option. Use Java8 classes instead of third party equivalents|<dl><dt>**true**</dt><dd>Use Java 8 classes such as Base64</dd><dt>**false**</dt><dd>Various third party libraries as needed</dd><dl>|false|
|
||||
|java8|Option. Use Java8 classes instead of third party equivalents|<dl><dt>**true**</dt><dd>Use Java 8 classes such as Base64. Use java8 default interface when a responseWrapper is used</dd><dt>**false**</dt><dd>Various third party libraries as needed</dd><dl>|false|
|
||||
|disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|
||||
@@ -48,7 +48,7 @@ sidebar_label: spring
|
||||
|interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
|
||||
|delegatePattern|Whether to generate the server files using the delegate pattern| |false|
|
||||
|singleContentTypes|Whether to select only one produces/consumes content-type by operation.| |false|
|
||||
|java8|use java8 default interface| |true|
|
||||
|skipDefaultInterface|Whether to generate default implementations for java8 interfaces| |false|
|
||||
|async|use async Callable controllers| |false|
|
||||
|reactive|wrap responses in Mono/Flux Reactor types (spring-boot only)| |false|
|
||||
|responseWrapper|wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)| |null|
|
||||
@@ -62,4 +62,5 @@ sidebar_label: spring
|
||||
|useOptional|Use Optional container for optional parameters| |false|
|
||||
|hateoas|Use Spring HATEOAS library to allow adding HATEOAS links| |false|
|
||||
|returnSuccessCode|Generated server returns 2xx code| |false|
|
||||
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
|
||||
|library|library template (sub-template)|<dl><dt>**spring-boot**</dt><dd>Spring-boot Server application using the SpringFox integration.</dd><dt>**spring-mvc**</dt><dd>Spring-MVC Server application using the SpringFox integration.</dd><dt>**spring-cloud**</dt><dd>Spring-Cloud-Feign client with Spring-Boot auto-configured settings.</dd><dl>|spring-boot|
|
||||
|
||||
@@ -23,9 +23,7 @@ Example usage:
|
||||
|
||||
```bash
|
||||
# Start container at port 8888 and save the container id
|
||||
CID=$(docker run -d -p 8888:8080 \
|
||||
-e GENERATOR_HOST=http://localhost:8888 \
|
||||
openapitools/openapi-generator-online)
|
||||
CID=$(docker run -d -p 8888:8080 openapitools/openapi-generator-online)
|
||||
|
||||
# allow for startup
|
||||
sleep 10
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
<parent>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -13,4 +15,11 @@
|
||||
<artifactId>openapi-generator-core</artifactId>
|
||||
<name>openapi-generator-core</name>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A generic implementation of a validator instance which simply applies rules to an input instance.
|
||||
*
|
||||
* @param <TInput> The type of object being evaluated.
|
||||
*/
|
||||
@SuppressWarnings({"WeakerAccess"})
|
||||
public class GenericValidator<TInput> implements Validator<TInput> {
|
||||
private List<ValidationRule> rules;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of {@link GenericValidator}.
|
||||
*
|
||||
* @param rules The rules to be evaluated during validation.
|
||||
*/
|
||||
public GenericValidator(List<ValidationRule> rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates input, resulting in a instance of {@link ValidationResult} which provides details on all validations performed (success, error, warning).
|
||||
*
|
||||
* @param input The object instance to be validated.
|
||||
*
|
||||
* @return A {@link ValidationResult} which details the success, error, and warning validation results.
|
||||
*/
|
||||
@Override
|
||||
public ValidationResult validate(TInput input) {
|
||||
ValidationResult result = new ValidationResult();
|
||||
if (rules != null) {
|
||||
rules.forEach(it -> {
|
||||
boolean passes = it.evaluate(input);
|
||||
if (passes) {
|
||||
result.addResult(Validated.valid(it));
|
||||
} else {
|
||||
result.addResult(Validated.invalid(it, it.getFailureMessage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
/**
|
||||
* Represents a {@link Validated} state which is "Invalid" to some degree of {@link Severity}.
|
||||
*/
|
||||
@SuppressWarnings({"WeakerAccess"})
|
||||
public final class Invalid extends Validated {
|
||||
private String message;
|
||||
private ValidationRule rule;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link Invalid} instance.
|
||||
*
|
||||
* @param rule The rule which was evaluated and resulted in this state.
|
||||
* @param message The message to be displayed for this invalid state.
|
||||
*/
|
||||
Invalid(ValidationRule rule, String message) {
|
||||
this.rule = rule;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
ValidationRule getRule() {
|
||||
return rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get details about the severity of this invalid state.
|
||||
* For instance, is this an {@link Severity#ERROR} or simply a {@link Severity#WARNING}.
|
||||
*
|
||||
* @return The {@link Severity} enum detailing this state's severity.
|
||||
*/
|
||||
public Severity getSeverity() {
|
||||
return rule.getSeverity();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
/**
|
||||
* Defines different levels of severity to be used during validation.
|
||||
*/
|
||||
public enum Severity {
|
||||
/**
|
||||
* Lower severity indicating that the target state may be unpredictable, no longer supported, or known to have issues.
|
||||
* Marking a type with this value should not result in application exceptions under normal operating circumstances.
|
||||
*/
|
||||
WARNING,
|
||||
/**
|
||||
* Higher severity indicating that the target state is not supported, or is known to cause problems with the application.
|
||||
* Marking a type with this value should result in an application exception or error exit code under normal operating circumstances.
|
||||
*/
|
||||
ERROR
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
/**
|
||||
* Represents a {@link Validated} state which is "valid" according to the defined rule.
|
||||
*/
|
||||
public final class Valid extends Validated {
|
||||
private ValidationRule rule;
|
||||
|
||||
/**
|
||||
* Defines whether or not the validation resulted in a "valid" condition.
|
||||
*
|
||||
* @return <code>true</code> if the instance passed validation of the rule returned by {@link Validated#getRule()}.
|
||||
*/
|
||||
@Override
|
||||
boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link Valid} instance.
|
||||
*
|
||||
* @param rule The rule which was evaluated and resulted in this state.
|
||||
*/
|
||||
Valid(ValidationRule rule) {
|
||||
this.rule = rule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationRule getRule() {
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
/**
|
||||
* Provides details about the state of a completed validation.
|
||||
*/
|
||||
public abstract class Validated {
|
||||
/**
|
||||
* Defines whether or not the validation resulted in a "valid" condition.
|
||||
*
|
||||
* @return <code>true</code> if the instance passed validation of the rule returned by {@link Validated#getRule()}.
|
||||
*/
|
||||
boolean isValid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rule which was evaluated and resulted in this state.
|
||||
*
|
||||
* @return The instance of {@link ValidationRule} which was evaluated.
|
||||
*/
|
||||
abstract ValidationRule getRule();
|
||||
|
||||
/**
|
||||
* Gets the message with details about this validated state.
|
||||
*
|
||||
* @return A string intended to be displayed to a user.
|
||||
*/
|
||||
abstract String getMessage();
|
||||
|
||||
/**
|
||||
* Creates an instance of an {@link Invalid} validation state.
|
||||
*
|
||||
* @param rule The rule which was evaluated.
|
||||
* @param message The message to display to a user.
|
||||
*
|
||||
* @return A {@link Validated} instance representing an invalid state according to the rule.
|
||||
*/
|
||||
public static Validated invalid(ValidationRule rule, String message) {
|
||||
return new Invalid(rule, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of an {@link Valid} validation state.
|
||||
*
|
||||
* @param rule The rule which was evaluated.
|
||||
*
|
||||
* @return A {@link Validated} instance representing a valid state according to the rule.
|
||||
*/
|
||||
public static Validated valid(ValidationRule rule) {
|
||||
return new Valid(rule);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Encapsulates details about the result of a validation test.
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public final class ValidationResult {
|
||||
private final List<Validated> validations;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link ValidationResult} instance, backed by the provided validations (useful for testing).
|
||||
*
|
||||
* @param validations A pre-defined set of validations to begin with.
|
||||
*/
|
||||
private ValidationResult(List<Validated> validations) {
|
||||
this.validations = Collections.synchronizedList(validations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link ValidationResult} instance.
|
||||
*/
|
||||
public ValidationResult() {
|
||||
this(new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the validated states resulting from the evaluation. This includes all {@link Valid} and {@link Invalid} instances.
|
||||
*
|
||||
* @return All validated results.
|
||||
*/
|
||||
public List<Validated> getAll() {
|
||||
return validations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a filtered list of {@link Valid} states.
|
||||
*
|
||||
* @return A list containing only {@link Valid} states.
|
||||
*/
|
||||
public List<Valid> getValid(){
|
||||
return validations.stream().filter(Validated::isValid).map(it -> (Valid)it).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a filters list of {@link Invalid} states with the level of {@link Severity#ERROR}
|
||||
*
|
||||
* @return A list of all validation errors.
|
||||
*/
|
||||
public List<Invalid> getErrors(){
|
||||
return validations.stream()
|
||||
.filter(it -> !it.isValid())
|
||||
.map(it -> (Invalid)it)
|
||||
.filter(it -> it.getSeverity().equals(Severity.ERROR))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a filtered list of {@link Invalid} states with the level of {@link Severity#WARNING}
|
||||
*
|
||||
* @return A list of all validation warnings.
|
||||
*/
|
||||
public List<Invalid> getWarnings(){
|
||||
return validations.stream()
|
||||
.filter(it -> !it.isValid())
|
||||
.map(it -> (Invalid)it)
|
||||
.filter(it -> it.getSeverity().equals(Severity.WARNING))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a validation state to the final results.
|
||||
*
|
||||
* @param validated The {@link Valid} or {@link Invalid} instance to add to validations.
|
||||
*/
|
||||
public void addResult(Validated validated) {
|
||||
synchronized (validations) {
|
||||
ValidationRule rule = validated.getRule();
|
||||
if (rule != null && !rule.equals(ValidationRule.empty())) {
|
||||
validations.add(validated);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Defines a rule to be evaluated against some target object.
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class ValidationRule {
|
||||
private Severity severity;
|
||||
private String description;
|
||||
private String failureMessage;
|
||||
private Function<Object, Boolean> test;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of {@link ValidationRule}
|
||||
*
|
||||
* @param severity The declared severity if this validation rule fails.
|
||||
* @param description A description to help differentiate this rule from others (not intended to be user-facing).
|
||||
* @param failureMessage The message to be displayed in the event of a test failure (intended to be user-facing).
|
||||
* @param test The test condition to be applied as a part of this rule, when this function returns <code>true</code>,
|
||||
* the evaluated instance will be considered "valid" according to this rule.
|
||||
*/
|
||||
ValidationRule(Severity severity, String description, String failureMessage, Function<Object, Boolean> test) {
|
||||
this.severity = severity;
|
||||
this.description = description;
|
||||
this.failureMessage = failureMessage;
|
||||
this.test = test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message to be displayed in the event of a test failure (intended to be user-facing).
|
||||
*
|
||||
* @return A string message
|
||||
*/
|
||||
public String getFailureMessage() {
|
||||
return failureMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evalute an instance of an object against this rule.
|
||||
*
|
||||
* @param input The instance to be evaluated.
|
||||
*
|
||||
* @return <code>true</code> if the object state is valid according to this rule, otherwise <code>false</code>.
|
||||
*/
|
||||
public boolean evaluate(Object input) {
|
||||
return test.apply(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level of severity which this rule considers a failure in evaluation. For example, if this is {@link Severity#WARNING} and
|
||||
* a call to {@link ValidationRule#evaluate(Object)} returns <code>false</code>, a user should not expect an error to be thrown under
|
||||
* normal operation.
|
||||
*
|
||||
* @return An enum defining how severe a failure to evaluate this rule should be considered by the caller.
|
||||
*/
|
||||
public Severity getSeverity() {
|
||||
return severity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a description to help differentiate this rule from others (not intended to be user-facing).
|
||||
*
|
||||
* @return A string description.
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an empty rule (useful for testing).
|
||||
*
|
||||
* @return An "empty" rule.
|
||||
*/
|
||||
static ValidationRule empty() {
|
||||
return new ValidationRule(Severity.ERROR, "empty", "failure message", (i) -> false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a {@link ValidationRule}
|
||||
*
|
||||
* @param severity The declared severity if this validation rule fails.
|
||||
* @param description A description to help differentiate this rule from others (not intended to be user-facing).
|
||||
* @param failureMessage The message to be displayed in the event of a test failure (intended to be user-facing).
|
||||
* @param fn The test condition to be applied as a part of this rule, when this function returns <code>true</code>,
|
||||
* the evaluated instance will be considered "valid" according to this rule.
|
||||
* @param <T> The type of the object being evaluated.
|
||||
*
|
||||
* @return A new instance of a {@link ValidationRule}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> ValidationRule create(Severity severity, String description, String failureMessage, Function<T, Boolean> fn) {
|
||||
return new ValidationRule(severity, description, failureMessage, (Function<Object, Boolean>) fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a {@link ValidationRule} which should result in an error should the evaluate of this rule fail.
|
||||
*
|
||||
* @param failureMessage The message to be displayed in the event of a test failure (intended to be user-facing).
|
||||
* @param fn The test condition to be applied as a part of this rule, when this function returns <code>true</code>,
|
||||
* the evaluated instance will be considered "valid" according to this rule.
|
||||
* @param <T> The type of the object being evaluated.
|
||||
*
|
||||
* @return A new instance of a {@link ValidationRule}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> ValidationRule error(String failureMessage, Function<T, Boolean> fn) {
|
||||
return new ValidationRule(Severity.ERROR, null, failureMessage, (Function<Object, Boolean>) fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a {@link ValidationRule} which should result in a warning should the evaluate of this rule fail.
|
||||
*
|
||||
* @param description A description to help differentiate this rule from others (not intended to be user-facing).
|
||||
* @param failureMessage The message to be displayed in the event of a test failure (intended to be user-facing).
|
||||
* @param fn The test condition to be applied as a part of this rule, when this function returns <code>true</code>,
|
||||
* the evaluated instance will be considered "valid" according to this rule.
|
||||
* @param <T> The type of the object being evaluated.
|
||||
*
|
||||
* @return A new instance of a {@link ValidationRule}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> ValidationRule warn(String description, String failureMessage, Function<T, Boolean> fn) {
|
||||
return new ValidationRule(Severity.WARNING, description, failureMessage, (Function<Object, Boolean>) fn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ValidationRule{" +
|
||||
"severity=" + severity +
|
||||
", description='" + description + '\'' +
|
||||
", failureMessage='" + failureMessage + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
/**
|
||||
* Defines a contract allowing some input to be validated.
|
||||
*
|
||||
* @param <TInput> The type of the input object.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Validator<TInput> {
|
||||
/**
|
||||
* Validates input, resulting in a instance of {@link ValidationResult} which provides details on all validations performed (success, error, warning).
|
||||
*
|
||||
* @param input The object instance to be validated.
|
||||
*
|
||||
* @return A {@link ValidationResult} which details the success, error, and warning validation results.
|
||||
*/
|
||||
ValidationResult validate(TInput input);
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class GenericValidatorTest {
|
||||
class Person {
|
||||
private int age;
|
||||
private String name;
|
||||
|
||||
Person(String name, int age) {
|
||||
this.age = age;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValidAge(Person person) {
|
||||
return person.age > 0;
|
||||
}
|
||||
|
||||
private static boolean isAdult(Person person) {
|
||||
return person.age > 18;
|
||||
}
|
||||
|
||||
private static boolean isNameSet(Person person) {
|
||||
return person.name != null && person.name.length() > 0;
|
||||
}
|
||||
|
||||
private static boolean isNameValid(Person person) {
|
||||
String pattern = "^[A-Z][a-z]*$";
|
||||
return person.name.matches(pattern);
|
||||
}
|
||||
|
||||
private static boolean isNameNormalLength(Person person) {
|
||||
return person.name.length() < 10;
|
||||
}
|
||||
|
||||
private List<ValidationRule> validationRules = Arrays.asList(
|
||||
ValidationRule.error("Age must be positive and more than zero", GenericValidatorTest::isValidAge),
|
||||
ValidationRule.error("Only adults (18 years old and older)", GenericValidatorTest::isAdult),
|
||||
ValidationRule.error("Name isn't set!", GenericValidatorTest::isNameSet),
|
||||
ValidationRule.error("Name isn't formatted correct", GenericValidatorTest::isNameValid),
|
||||
ValidationRule.warn("Name too long?", "Name may be too long.", GenericValidatorTest::isNameNormalLength)
|
||||
);
|
||||
|
||||
@Test
|
||||
public void testGenericValidatorSuccesses(){
|
||||
Person person = new Person("Jim", 23);
|
||||
GenericValidator<Person> validator = new GenericValidator<>(validationRules);
|
||||
ValidationResult result = validator.validate(person);
|
||||
List<Validated> validated = result.getAll();
|
||||
List<Valid> valid = result.getValid();
|
||||
List<Invalid> invalid = result.getErrors();
|
||||
|
||||
assertEquals(validated.size(), 5, "Expected 5 validations to run.");
|
||||
assertEquals(valid.size(), 5, "Expected all validations to succeed");
|
||||
assertEquals(invalid.size(), 0, "Expected zero validations to fail.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericValidatorSingleConditionFails(){
|
||||
Person person = new Person("Jim", 3);
|
||||
GenericValidator<Person> validator = new GenericValidator<>(validationRules);
|
||||
ValidationResult result = validator.validate(person);
|
||||
List<Validated> validated = result.getAll();
|
||||
List<Valid> valid = result.getValid();
|
||||
List<Invalid> errors = result.getErrors();
|
||||
List<Invalid> warnings = result.getWarnings();
|
||||
|
||||
assertEquals(validated.size(), 5, "Expected 5 validations to run.");
|
||||
assertEquals(valid.size(), 4, "Expected 4 validations to succeed");
|
||||
assertEquals(errors.size(), 1, "Expected 1 validation to fail.");
|
||||
assertEquals(warnings.size(), 0, "Expected no warnings to be triggered.");
|
||||
|
||||
Invalid failed = errors.get(0);
|
||||
assertEquals(failed.getMessage(), "Only adults (18 years old and older)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericValidatorMultipleConditionsFail(){
|
||||
Person person = new Person("asdf", 3);
|
||||
GenericValidator<Person> validator = new GenericValidator<>(validationRules);
|
||||
ValidationResult result = validator.validate(person);
|
||||
List<Validated> validated = result.getAll();
|
||||
List<Valid> valid = result.getValid();
|
||||
List<Invalid> errors = result.getErrors();
|
||||
List<Invalid> warnings = result.getWarnings();
|
||||
|
||||
assertEquals(validated.size(), 5, "Expected 5 validations to run.");
|
||||
assertEquals(valid.size(), 3, "Expected 3 validations to succeed");
|
||||
assertEquals(errors.size(), 2, "Expected 2 validations to fail.");
|
||||
assertEquals(warnings.size(), 0, "Expected no warnings to be triggered.");
|
||||
|
||||
Optional<Invalid> nameValidation = errors.stream().filter(it -> it.getMessage().contains("formatted")).findFirst();
|
||||
Optional<Invalid> ageValidation = errors.stream().filter(it -> it.getMessage().contains("adults")).findFirst();
|
||||
|
||||
assertTrue(nameValidation.isPresent(), "Expected validation on name formatting to fail.");
|
||||
assertTrue(ageValidation.isPresent(), "Expected validation on age requirements to fail.");
|
||||
assertEquals(nameValidation.get().getMessage(), "Name isn't formatted correct");
|
||||
assertEquals(ageValidation.get().getMessage(), "Only adults (18 years old and older)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericValidatorErrorsAndWarnings(){
|
||||
Person person = new Person("0123456789asdfghjkl", 3);
|
||||
GenericValidator<Person> validator = new GenericValidator<>(validationRules);
|
||||
ValidationResult result = validator.validate(person);
|
||||
List<Validated> validated = result.getAll();
|
||||
List<Valid> valid = result.getValid();
|
||||
List<Invalid> errors = result.getErrors();
|
||||
List<Invalid> warnings = result.getWarnings();
|
||||
|
||||
assertEquals(validated.size(), 5, "Expected 5 validations to run.");
|
||||
assertEquals(valid.size(), 2, "Expected 2 validations to succeed");
|
||||
assertEquals(errors.size(), 2, "Expected 2 validations to fail.");
|
||||
assertEquals(warnings.size(), 1, "Expected 1 warning to be triggered.");
|
||||
|
||||
Optional<Invalid> nameValidation = errors.stream().filter(it -> it.getMessage().contains("formatted")).findFirst();
|
||||
Optional<Invalid> ageValidation = errors.stream().filter(it -> it.getMessage().contains("adults")).findFirst();
|
||||
Invalid nameLengthWarning = warnings.get(0);
|
||||
|
||||
assertTrue(nameValidation.isPresent(), "Expected validation on name formatting to fail.");
|
||||
assertTrue(ageValidation.isPresent(), "Expected validation on age requirements to fail.");
|
||||
assertEquals(nameValidation.get().getMessage(), "Name isn't formatted correct");
|
||||
assertEquals(ageValidation.get().getMessage(), "Only adults (18 years old and older)");
|
||||
assertEquals(nameLengthWarning.getMessage(), "Name may be too long.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class ValidatedTest {
|
||||
@Test
|
||||
public void isValidTrueForValidType(){
|
||||
boolean isValid = Validated.valid(ValidationRule.empty()).isValid();
|
||||
assertTrue(isValid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValidFalseForInvalidType(){
|
||||
boolean isValid = Validated.invalid(ValidationRule.empty(), "test").isValid();
|
||||
assertFalse(isValid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.validation;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class ValidationRuleTest {
|
||||
class Sample {
|
||||
private String name;
|
||||
|
||||
public Sample(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkName(Sample input) {
|
||||
return input.getName() != null && input.getName().length() > 7;
|
||||
}
|
||||
|
||||
private static boolean checkPattern(Sample input) {
|
||||
String pattern = "^[A-Z][a-z]*$";
|
||||
return input.getName() != null && input.getName().matches(pattern);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createMethodUsingMethodReference(){
|
||||
Sample nil = new Sample(null);
|
||||
Sample six = new Sample("123456");
|
||||
Sample seven = new Sample("1234567");
|
||||
Sample eight = new Sample("12345678");
|
||||
ValidationRule result = ValidationRule.error("test", ValidationRuleTest::checkName);
|
||||
assertFalse(result.evaluate(nil));
|
||||
assertFalse(result.evaluate(six));
|
||||
assertFalse(result.evaluate(seven));
|
||||
assertTrue(result.evaluate(eight));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createMethodUsingLambda(){
|
||||
Sample nil = new Sample(null);
|
||||
Sample lowercase = new Sample("jim");
|
||||
Sample titlecase = new Sample("Jim");
|
||||
ValidationRule result = ValidationRule.error("test", i -> checkPattern((Sample)i));
|
||||
assertFalse(result.evaluate(nil));
|
||||
assertFalse(result.evaluate(lowercase));
|
||||
assertTrue(result.evaluate(titlecase));
|
||||
}
|
||||
}
|
||||
@@ -40,10 +40,12 @@ compileJava.dependsOn tasks.openApiGenerate
|
||||
|
||||
== Plugin Setup
|
||||
|
||||
//# RELEASE_VERSION
|
||||
|
||||
[source,group]
|
||||
----
|
||||
plugins {
|
||||
id "org.openapi.generator" version "4.0.2"
|
||||
id "org.openapi.generator" version "4.0.3-SNAPSHOT"
|
||||
}
|
||||
----
|
||||
|
||||
@@ -59,12 +61,13 @@ buildscript {
|
||||
// url "https://plugins.gradle.org/m2/"
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:4.0.2"
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:4.0.3-SNAPSHOT"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.openapi.generator'
|
||||
----
|
||||
//# /RELEASE_VERSION
|
||||
|
||||
== Configuration
|
||||
|
||||
@@ -597,6 +600,7 @@ Android Studio may experience a Windows-specific Guava dependency conflict with
|
||||
|
||||
As a workaround, you may force exclude conflicting Guava dependencies.
|
||||
|
||||
//# RELEASE_VERSION
|
||||
```gradle
|
||||
buildscript {
|
||||
repositories {
|
||||
@@ -605,7 +609,7 @@ buildscript {
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
classpath('org.openapitools:openapi-generator-gradle-plugin:4.0.2') {
|
||||
classpath('org.openapitools:openapi-generator-gradle-plugin:4.0.3-SNAPSHOT') {
|
||||
exclude group: 'com.google.guava'
|
||||
}
|
||||
}
|
||||
@@ -618,5 +622,6 @@ configurations {
|
||||
// …
|
||||
apply plugin: 'org.openapi.generator'
|
||||
```
|
||||
//# /RELEASE_VERSION
|
||||
|
||||
See https://github.com/OpenAPITools/openapi-generator/issues/1818[OpenAPITools/openapi-generator#1818] for more details.
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
openApiGeneratorVersion=4.0.2
|
||||
# RELEASE_VERSION
|
||||
openApiGeneratorVersion=4.0.3-SNAPSHOT
|
||||
# /RELEASE_VERSION
|
||||
|
||||
# BEGIN placeholders
|
||||
# these are just placeholders to allow contributors to build directly
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -17,5 +17,5 @@ gradle generateGoWithInvalidSpec
|
||||
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
|
||||
|
||||
```bash
|
||||
gradle -PopenApiGeneratorVersion=4.0.2 openApiValidate
|
||||
gradle -PopenApiGeneratorVersion=4.0.3-SNAPSHOT openApiValidate
|
||||
```
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
openApiGeneratorVersion=4.0.2
|
||||
# RELEASE_VERSION
|
||||
openApiGeneratorVersion=4.0.3-SNAPSHOT
|
||||
# /RELEASE_VERSION
|
||||
|
||||
@@ -11,7 +11,9 @@ Add to your `build->plugins` section (default phase is `generate-sources` phase)
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
|
||||
@@ -4,9 +4,12 @@ WORKDIR /generator
|
||||
|
||||
COPY target/openapi-generator-online.jar /generator/openapi-generator-online.jar
|
||||
|
||||
ENV GENERATOR_HOST=http://localhost
|
||||
# GENERATOR_HOST can be used to determine the target location of a download link.
|
||||
# The default value asumes binding to host via: docker -p 8080:8080 image_name
|
||||
# Generally, this "just works" without GENERATOR_HOST, and this is provided only as
|
||||
# a workaround if all else fails.
|
||||
ENV GENERATOR_HOST=""
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["java", "-jar", "/generator/openapi-generator-online.jar"]
|
||||
|
||||
CMD ["java", "-jar", "/generator/openapi-generator-online.jar" ]
|
||||
|
||||
@@ -1,15 +1,57 @@
|
||||
# OpenAPI generated server
|
||||
|
||||
Spring Boot Server
|
||||
A Spring Boot Server application which hosts a client/server generator API.
|
||||
|
||||
|
||||
## Overview
|
||||
|
||||
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
|
||||
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
|
||||
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub or one of 100+ client packages.
|
||||
|
||||
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.
|
||||
|
||||
The underlying library integrating OpenAPI to SpringBoot is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
Start your server as a simple java application
|
||||
## Building
|
||||
|
||||
Change default port value in application.properties
|
||||
Refer to [root README](../../README.md) for build directions.
|
||||
|
||||
## Running
|
||||
|
||||
### Via command line
|
||||
|
||||
Running is as simple as:
|
||||
|
||||
```
|
||||
java -jar ./target/openapi-generator-online.jar
|
||||
```
|
||||
|
||||
This exposes the API on local port 8080.
|
||||
|
||||
Springfox supports configuration of the "host" value in the output OpenAPI document by setting the `Host` HTTP header in the request.
|
||||
To set this explicitly, pass the system property `springfox.documentation.swagger.v2.host` with the desired host. For example:
|
||||
|
||||
```
|
||||
java -Dspringfox.documentation.swagger.v2.host=example.com:8888 -jar ./target/openapi-generator-online.jar
|
||||
```
|
||||
|
||||
### Via Docker
|
||||
|
||||
After building from source, change to this module directory (`cd modules/openapi-generator-online`) and build the docker image:
|
||||
|
||||
```
|
||||
docker build -t openapitools/openapi-generator-online:latest .
|
||||
```
|
||||
|
||||
Now, run the docker image:
|
||||
|
||||
```
|
||||
docker run -d -p 8888:8080 openapitools/openapi-generator-online
|
||||
```
|
||||
|
||||
The `GENERATOR_HOST` variable is used here to ensure download links generated by the API refer to the proper API location.
|
||||
|
||||
## Environment
|
||||
|
||||
`GENERATOR_HOST` can be set to force the scheme/host/port used for download link generation. In most cases, this environment variable is not
|
||||
necessary to be set and the download link will be generated to match the originating request. The variable is provided simply as a fallback.
|
||||
@@ -3,7 +3,9 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-online</artifactId>
|
||||
@@ -31,6 +33,14 @@
|
||||
<build>
|
||||
<finalName>openapi-generator-online</finalName>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<excludes>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -67,11 +77,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
public class HomeController {
|
||||
@RequestMapping(value = "/")
|
||||
public String index() {
|
||||
return "redirect:swagger-ui.html";
|
||||
return "redirect:index.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,11 @@ import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
@Configuration
|
||||
@@ -37,13 +41,24 @@ import java.io.InputStream;
|
||||
public class OpenAPIDocumentationConfig {
|
||||
|
||||
ApiInfo apiInfo() {
|
||||
final Properties properties = new Properties();
|
||||
try (InputStream stream = this.getClass().getResourceAsStream("/version.properties")) {
|
||||
if (stream != null) {
|
||||
properties.load(stream);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
String version = properties.getProperty("version", "unknown");
|
||||
|
||||
return new ApiInfoBuilder()
|
||||
.title("OpenAPI Generator Online")
|
||||
.description("This is an online openapi generator server. You can find out more at https://github.com/OpenAPITools/openapi-generator.")
|
||||
.license("Apache 2.0")
|
||||
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
|
||||
.termsOfServiceUrl("")
|
||||
.version("3.0.0")
|
||||
.version(version)
|
||||
.contact(new Contact("","", ""))
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -2,3 +2,4 @@ springfox.documentation.swagger.v2.path=/api-docs
|
||||
server.port=8080
|
||||
spring.jackson.date-format=org.openapitools.codegen.online.RFC3339DateFormat
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
|
||||
|
||||
17
modules/openapi-generator-online/src/main/resources/static/index.html
Executable file
17
modules/openapi-generator-online/src/main/resources/static/index.html
Executable file
@@ -0,0 +1,17 @@
|
||||
<!doctype html> <!-- Important: must specify -->
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"> <!-- Important: rapi-doc uses utf8 charecters -->
|
||||
<script src="rapidoc-min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<rapi-doc spec-url="api-docs"
|
||||
theme="dark">
|
||||
<img
|
||||
slot="logo"
|
||||
src="logo.png"
|
||||
style="margin:0 -0.3em 0 0.8em;"
|
||||
/>
|
||||
</rapi-doc>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
182
modules/openapi-generator-online/src/main/resources/static/rapidoc-min.js
vendored
Normal file
182
modules/openapi-generator-online/src/main/resources/static/rapidoc-min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
version = ${project.version}
|
||||
@@ -3,7 +3,9 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -313,7 +315,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-core</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
|
||||
@@ -306,4 +306,6 @@ public class CodegenConstants {
|
||||
public static final String SNAPSHOT_VERSION = "snapshotVersion";
|
||||
public static final String SNAPSHOT_VERSION_DESC = "Uses a SNAPSHOT version.";
|
||||
|
||||
public static final String EXCEPTION_ON_FAILURE = "returnExceptionOnFailure";
|
||||
public static final String EXCEPTION_ON_FAILURE_DESC = "Throw an exception on non success response codes";
|
||||
}
|
||||
|
||||
@@ -810,7 +810,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @return the snake-cased variable name
|
||||
*/
|
||||
public String toApiVarName(String name) {
|
||||
return snakeCase(name);
|
||||
return lowerCamelCase(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1475,7 +1475,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @param schema
|
||||
* @return type
|
||||
*/
|
||||
private static String getPrimitiveType(Schema schema) {
|
||||
private String getPrimitiveType(Schema schema) {
|
||||
if (schema == null) {
|
||||
throw new RuntimeException("schema cannot be null in getPrimitiveType");
|
||||
} else if (ModelUtils.isStringSchema(schema) && "number".equals(schema.getFormat())) {
|
||||
@@ -1519,6 +1519,13 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
} else if (ModelUtils.isURISchema(schema)) {
|
||||
return "URI";
|
||||
} else if (ModelUtils.isStringSchema(schema)) {
|
||||
if(typeMapping.containsKey(schema.getFormat())) {
|
||||
// If the format matches a typeMapping (supplied with the --typeMappings flag)
|
||||
// then treat the format as a primitive type.
|
||||
// This allows the typeMapping flag to add a new custom type which can then
|
||||
// be used in the format field.
|
||||
return schema.getFormat();
|
||||
}
|
||||
return "string";
|
||||
} else if (ModelUtils.isFreeFormObject(schema)) {
|
||||
return "object";
|
||||
@@ -1533,13 +1540,13 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the snake-case of the string
|
||||
* Return the lowerCamelCase of the string
|
||||
*
|
||||
* @param name string to be snake-cased
|
||||
* @return snake-cased string
|
||||
* @param name string to be lowerCamelCased
|
||||
* @return lowerCamelCase string
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String snakeCase(String name) {
|
||||
public String lowerCamelCase(String name) {
|
||||
return (name.length() > 0) ? (Character.toLowerCase(name.charAt(0)) + name.substring(1)) : "";
|
||||
}
|
||||
|
||||
@@ -1756,10 +1763,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
m.interfaces.add(modelName);
|
||||
addImport(m, modelName);
|
||||
if (allDefinitions != null && refSchema != null) {
|
||||
if (allParents.contains(modelName) && supportsMultipleInheritance) {
|
||||
if (allParents.contains(ref) && supportsMultipleInheritance) {
|
||||
// multiple inheritance
|
||||
addProperties(allProperties, allRequired, refSchema);
|
||||
} else if (parentName != null && parentName.equals(modelName) && supportsInheritance) {
|
||||
} else if (parentName != null && parentName.equals(ref) && supportsInheritance) {
|
||||
// single inheritance
|
||||
addProperties(allProperties, allRequired, refSchema);
|
||||
} else {
|
||||
@@ -1860,8 +1867,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
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 = toModelName(ModelUtils.getSimpleRef(e.getValue())); // e.g e.getValue => #/components/schemas/Dog
|
||||
discriminator.getMappedModels().add(new MappedModel(e.getKey(), name));
|
||||
String nameOrRef = e.getValue();
|
||||
String name = nameOrRef.indexOf('/') >= 0 ? ModelUtils.getSimpleRef(nameOrRef) : nameOrRef;
|
||||
String modelName = toModelName(name);
|
||||
discriminator.getMappedModels().add(new MappedModel(e.getKey(), modelName));
|
||||
}
|
||||
} else {
|
||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
||||
@@ -3668,7 +3677,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @param schemas The complete set of model definitions (schemas).
|
||||
* @return A mapping from model name to type alias
|
||||
*/
|
||||
static Map<String, String> getAllAliases(Map<String, Schema> schemas) {
|
||||
Map<String, String> getAllAliases(Map<String, Schema> schemas) {
|
||||
if (schemas == null || schemas.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@@ -562,6 +562,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
operation.put("classVarName", config.toApiVarName(tag));
|
||||
operation.put("importPath", config.toApiImport(tag));
|
||||
operation.put("classFilename", config.toApiFilename(tag));
|
||||
operation.put("strictSpecBehavior", config.isStrictSpecBehavior());
|
||||
|
||||
if (allModels == null || allModels.isEmpty()) {
|
||||
operation.put("hasModel", false);
|
||||
|
||||
@@ -175,7 +175,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
dateLibrary.setEnum(dateOptions);
|
||||
cliOptions.add(dateLibrary);
|
||||
|
||||
CliOption java8Mode = new CliOption(JAVA8_MODE, "Option. Use Java8 classes instead of third party equivalents").defaultValue(String.valueOf(this.java8Mode));
|
||||
CliOption java8Mode = CliOption.newBoolean(JAVA8_MODE, "Option. Use Java8 classes instead of third party equivalents", this.java8Mode);
|
||||
Map<String, String> java8ModeOptions = new HashMap<>();
|
||||
java8ModeOptions.put("true", "Use Java 8 classes such as Base64");
|
||||
java8ModeOptions.put("false", "Various third party libraries as needed");
|
||||
@@ -784,6 +784,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return null;
|
||||
} else if (ModelUtils.isURISchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "URI.create(\"" + escapeText((String) p.getDefault()) + "\")";
|
||||
}
|
||||
return null;
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
String _default = (String) p.getDefault();
|
||||
|
||||
@@ -834,6 +834,10 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isURISchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "URI.create('" + p.getDefault() + "')";
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "'" + p.getDefault() + "'";
|
||||
|
||||
@@ -38,6 +38,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
public static final String USE_SWASHBUCKLE = "useSwashbuckle";
|
||||
public static final String ASPNET_CORE_VERSION = "aspnetCoreVersion";
|
||||
public static final String SWASHBUCKLE_VERSION = "swashbuckleVersion";
|
||||
public static final String CLASS_MODIFIER = "classModifier";
|
||||
public static final String OPERATION_MODIFIER = "operationModifier";
|
||||
public static final String OPERATION_IS_ASYNC = "operationIsAsync";
|
||||
@@ -51,6 +52,10 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
public static final String SDK_LIB = "Microsoft.NET.Sdk";
|
||||
public static final String COMPATIBILITY_VERSION = "compatibilityVersion";
|
||||
public static final String IS_LIBRARY = "isLibrary";
|
||||
public static final String USE_FRAMEWORK_REFERENCE = "useFrameworkReference";
|
||||
public static final String USE_NEWTONSOFT = "useNewtonsoft";
|
||||
public static final String USE_DEFAULT_ROUTING = "useDefaultRouting";
|
||||
public static final String NEWTONSOFT_VERSION = "newtonsoftVersion";
|
||||
|
||||
private String packageGuid = "{" + randomUUID().toString().toUpperCase(Locale.ROOT) + "}";
|
||||
|
||||
@@ -60,18 +65,23 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
private boolean useSwashbuckle = true;
|
||||
protected int serverPort = 8080;
|
||||
protected String serverHost = "0.0.0.0";
|
||||
protected CliOption aspnetCoreVersion = new CliOption(ASPNET_CORE_VERSION, "ASP.NET Core version: 2.2 (default), 2.1, 2.0 (deprecated)");
|
||||
protected CliOption swashbuckleVersion = new CliOption(SWASHBUCKLE_VERSION, "Swashbucke version: 3.0.0, 4.0.0");
|
||||
; // default to 2.1
|
||||
protected CliOption aspnetCoreVersion = new CliOption(ASPNET_CORE_VERSION, "ASP.NET Core version: 3.0 (preview4 only), 2.2, 2.1, 2.0 (deprecated)");
|
||||
private CliOption classModifier = new CliOption(CLASS_MODIFIER, "Class Modifier can be empty, abstract");
|
||||
private CliOption operationModifier = new CliOption(OPERATION_MODIFIER, "Operation Modifier can be virtual, abstract or partial");
|
||||
private CliOption modelClassModifier = new CliOption(MODEL_CLASS_MODIFIER, "Model Class Modifier can be nothing or partial");
|
||||
private boolean generateBody = true;
|
||||
private CliOption buildTarget = new CliOption("buildTarget", "Target to build an application or library");
|
||||
private String projectSdk = SDK_WEB;
|
||||
private String compatibilityVersion = "Version_2_1";
|
||||
private String compatibilityVersion = "Version_2_2";
|
||||
private boolean operationIsAsync = false;
|
||||
private boolean operationResultTask = false;
|
||||
private boolean isLibrary = false;
|
||||
private boolean useFrameworkReference = false;
|
||||
private boolean useNewtonsoft = true;
|
||||
private boolean useDefaultRouting = true;
|
||||
private String newtonsoftVersion = "3.0.0-preview5-19227-01";
|
||||
|
||||
public AspNetCoreServerCodegen() {
|
||||
super();
|
||||
@@ -146,10 +156,18 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
aspnetCoreVersion.addEnum("2.0", "ASP.NET COre 2.0");
|
||||
aspnetCoreVersion.addEnum("2.1", "ASP.NET Core 2.1");
|
||||
aspnetCoreVersion.addEnum("2.2", "ASP.NET Core 2.2");
|
||||
aspnetCoreVersion.addEnum("3.0", "ASP.NET Core 3.0");
|
||||
aspnetCoreVersion.setDefault("2.2");
|
||||
aspnetCoreVersion.setOptValue(aspnetCoreVersion.getDefault());
|
||||
addOption(aspnetCoreVersion.getOpt(), aspnetCoreVersion.getDescription(), aspnetCoreVersion.getOptValue());
|
||||
|
||||
swashbuckleVersion.addEnum("3.0.0", "Swashbuckle 3.0.0");
|
||||
swashbuckleVersion.addEnum("4.0.0", "Swashbuckle 4.0.0");
|
||||
swashbuckleVersion.addEnum("5.0.0", "Swashbuckle 5.0.0");
|
||||
swashbuckleVersion.setDefault("3.0.0");
|
||||
swashbuckleVersion.setOptValue(swashbuckleVersion.getDefault());
|
||||
addOption(swashbuckleVersion.getOpt(), swashbuckleVersion.getDescription(), swashbuckleVersion.getOptValue());
|
||||
|
||||
// CLI Switches
|
||||
addSwitch(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG,
|
||||
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC,
|
||||
@@ -175,6 +193,23 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
"Is the build a library",
|
||||
isLibrary);
|
||||
|
||||
addSwitch(USE_FRAMEWORK_REFERENCE,
|
||||
"Use frameworkReference for ASP.NET Core 3.0+ and PackageReference ASP.NET Core 2.2 or earlier.",
|
||||
useFrameworkReference);
|
||||
|
||||
addSwitch(USE_NEWTONSOFT,
|
||||
"Uses the Newtonsoft JSON library.",
|
||||
useNewtonsoft);
|
||||
|
||||
addOption(NEWTONSOFT_VERSION,
|
||||
"Version for Microsoft.AspNetCore.Mvc.NewtonsoftJson for ASP.NET Core 3.0+",
|
||||
newtonsoftVersion);
|
||||
|
||||
|
||||
addSwitch(USE_DEFAULT_ROUTING,
|
||||
"Use default routing for the ASP.NET Core version. For 3.0 turn off default because it is not yet supported.",
|
||||
useDefaultRouting);
|
||||
|
||||
classModifier.addEnum("", "Keep class default with no modifier");
|
||||
classModifier.addEnum("abstract", "Make class abstract");
|
||||
classModifier.setDefault("");
|
||||
@@ -246,6 +281,11 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
additionalProperties.put("packageGuid", packageGuid);
|
||||
|
||||
if (!additionalProperties.containsKey(NEWTONSOFT_VERSION)) {
|
||||
additionalProperties.put(NEWTONSOFT_VERSION, newtonsoftVersion);
|
||||
} else {
|
||||
newtonsoftVersion = (String)additionalProperties.get(NEWTONSOFT_VERSION);
|
||||
}
|
||||
|
||||
// CHeck for the modifiers etc.
|
||||
// The order of the checks is important.
|
||||
@@ -275,6 +315,10 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
// determine the ASP.NET core version setting
|
||||
setAspnetCoreVersion(packageFolder);
|
||||
setSwashbuckleVersion();
|
||||
setIsFramework();
|
||||
setUseNewtonsoft();
|
||||
setUseEndpointRouting();
|
||||
|
||||
supportingFiles.add(new SupportingFile("build.sh.mustache", "", "build.sh"));
|
||||
supportingFiles.add(new SupportingFile("build.bat.mustache", "", "build.bat"));
|
||||
@@ -309,6 +353,8 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
supportingFiles.add(new SupportingFile("Filters" + File.separator + "GeneratePathParamsValidationFilter.mustache",
|
||||
packageFolder + File.separator + "Filters", "GeneratePathParamsValidationFilter.cs"));
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("Authentication" + File.separator + "ApiAuthentication.mustache",packageFolder + File.separator + "Authentication", "ApiAuthentication.cs"));
|
||||
}
|
||||
|
||||
public void setPackageGuid(String packageGuid) {
|
||||
@@ -477,10 +523,66 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
if (isLibrary) {
|
||||
operationIsAsync = false;
|
||||
additionalProperties.put(OPERATION_IS_ASYNC, operationIsAsync);
|
||||
} else if (additionalProperties.containsKey(OPERATION_IS_ASYNC)) {
|
||||
} else if (additionalProperties.containsKey(OPERATION_IS_ASYNC)) {
|
||||
operationIsAsync = convertPropertyToBooleanAndWriteBack(OPERATION_IS_ASYNC);
|
||||
} else {
|
||||
additionalProperties.put(OPERATION_IS_ASYNC, operationIsAsync);
|
||||
}
|
||||
}
|
||||
|
||||
private void setIsFramework() {
|
||||
if (aspnetCoreVersion.getOptValue().startsWith("3.")) {// default, do nothing
|
||||
LOGGER.warn("ASP.NET core version is " + aspnetCoreVersion.getOptValue() + " so changing to use frameworkReference instead of packageReference ");
|
||||
useFrameworkReference = true;
|
||||
additionalProperties.put(USE_FRAMEWORK_REFERENCE, useFrameworkReference);
|
||||
} else {
|
||||
if (additionalProperties.containsKey(USE_FRAMEWORK_REFERENCE)) {
|
||||
useFrameworkReference = convertPropertyToBooleanAndWriteBack(USE_FRAMEWORK_REFERENCE);
|
||||
} else {
|
||||
additionalProperties.put(USE_FRAMEWORK_REFERENCE, useFrameworkReference);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setUseNewtonsoft() {
|
||||
if (aspnetCoreVersion.getOptValue().startsWith("2.")) {
|
||||
LOGGER.warn("ASP.NET core version is " + aspnetCoreVersion.getOptValue() + " so staying on default json library.");
|
||||
useNewtonsoft = false;
|
||||
additionalProperties.put(USE_NEWTONSOFT, useNewtonsoft);
|
||||
} else {
|
||||
if (additionalProperties.containsKey(USE_NEWTONSOFT)) {
|
||||
useNewtonsoft = convertPropertyToBooleanAndWriteBack(USE_NEWTONSOFT);
|
||||
} else {
|
||||
additionalProperties.put(USE_NEWTONSOFT, useNewtonsoft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setUseEndpointRouting() {
|
||||
if (aspnetCoreVersion.getOptValue().startsWith("3.")) {
|
||||
LOGGER.warn("ASP.NET core version is " + aspnetCoreVersion.getOptValue() + " so switching to old style endpoint routing.");
|
||||
useDefaultRouting = false;
|
||||
additionalProperties.put(USE_DEFAULT_ROUTING, useDefaultRouting);
|
||||
} else {
|
||||
if (additionalProperties.containsKey(USE_DEFAULT_ROUTING)) {
|
||||
useDefaultRouting = convertPropertyToBooleanAndWriteBack(USE_DEFAULT_ROUTING);
|
||||
} else {
|
||||
additionalProperties.put(USE_DEFAULT_ROUTING, useDefaultRouting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setSwashbuckleVersion() {
|
||||
setCliOption(swashbuckleVersion);
|
||||
|
||||
if (aspnetCoreVersion.getOptValue().startsWith("3.")) {
|
||||
LOGGER.warn("ASP.NET core version is " + aspnetCoreVersion.getOptValue() + " so changing default Swashbuckle version to 4.0.0.");
|
||||
swashbuckleVersion.setOptValue("4.0.0");
|
||||
additionalProperties.put(SWASHBUCKLE_VERSION, swashbuckleVersion.getOptValue());
|
||||
} else {
|
||||
// default, do nothing
|
||||
LOGGER.info("Swashbuckle version: " + swashbuckleVersion.getOptValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,7 +446,9 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", "");
|
||||
} else {
|
||||
final List<String> paths = Arrays.asList(op.path.substring(1).split("/"));
|
||||
String path = paths.stream().map(str -> str.charAt(0) == '{' ? str : "\"" + str + "\"").collect(Collectors.joining(", "));
|
||||
String path = paths.stream()
|
||||
.map(str -> str.startsWith("{") && str.endsWith("}") ? str : "\"" + str + "\"")
|
||||
.collect(Collectors.joining(", "));
|
||||
for (CodegenParameter param : op.pathParams) {
|
||||
String str = paramToString("params", param, false, null);
|
||||
path = path.replace("{" + param.paramName + "}", str);
|
||||
|
||||
@@ -128,7 +128,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
if (languageSpecificPrimitives.contains(type))
|
||||
return (type);
|
||||
} else
|
||||
type = getTypeDeclaration(toModelName(snakeCase(schemaType)));
|
||||
type = getTypeDeclaration(toModelName(lowerCamelCase(schemaType)));
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
||||
} else if (typeMapping.containsKey(typeDeclaration)) {
|
||||
return typeMapping.get(typeDeclaration);
|
||||
} else {
|
||||
return getTypeDeclaration(toModelName(snakeCase(typeDeclaration)));
|
||||
return getTypeDeclaration(toModelName(lowerCamelCase(typeDeclaration)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
||||
} else if (typeMapping.containsKey(schemaType)) {
|
||||
return typeMapping.get(schemaType);
|
||||
} else {
|
||||
return getTypeDeclaration(toModelName(snakeCase(schemaType)));
|
||||
return getTypeDeclaration(toModelName(lowerCamelCase(schemaType)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GoClientExperimentalCodegen extends GoClientCodegen {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GoClientExperimentalCodegen.class);
|
||||
|
||||
public GoClientExperimentalCodegen() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 "go-experimental";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Go client library (experimental and may subject to breaking changes without further notice).";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -411,6 +411,11 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
for (CodegenParameter param : pathParams) {
|
||||
captureTypes.put(param.baseName, param.dataType);
|
||||
}
|
||||
|
||||
// Properly handle root-only routes (#3256)
|
||||
if (path.contentEquals("/")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// Cut off the leading slash, if it is present.
|
||||
if (path.startsWith("/")) {
|
||||
|
||||
@@ -138,7 +138,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
supportedLibraries.put(RESTEASY, "HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.8.x");
|
||||
supportedLibraries.put(VERTX, "HTTP client: VertX client 3.x. JSON processing: Jackson 2.8.x");
|
||||
supportedLibraries.put(GOOGLE_API_CLIENT, "HTTP client: Google API client 1.x. JSON processing: Jackson 2.8.x");
|
||||
supportedLibraries.put(REST_ASSURED, "HTTP client: rest-assured : 3.x. JSON processing: Gson 2.x. Only for Java8");
|
||||
supportedLibraries.put(REST_ASSURED, "HTTP client: rest-assured : 4.x. JSON processing: Gson 2.x. Only for Java8");
|
||||
|
||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
libraryOption.setEnum(supportedLibraries);
|
||||
@@ -695,4 +695,12 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
return mime != null && JSON_VENDOR_MIME_PATTERN.matcher(mime).matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiVarName(String name) {
|
||||
String apiVarName = super.toApiVarName(name);
|
||||
if (reservedWords.contains(apiVarName)) {
|
||||
apiVarName = escapeReservedWord(apiVarName);
|
||||
}
|
||||
return apiVarName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public class JavaVertXServerCodegen extends AbstractJavaCodegen {
|
||||
public static final String ROOT_PACKAGE = "rootPackage";
|
||||
|
||||
public static final String RX_INTERFACE_OPTION = "rxInterface";
|
||||
public static final String RX_VERSION_2_OPTION = "rxVersion2";
|
||||
public static final String VERTX_SWAGGER_ROUTER_VERSION_OPTION = "vertxSwaggerRouterVersion";
|
||||
|
||||
/**
|
||||
@@ -88,6 +89,9 @@ public class JavaVertXServerCodegen extends AbstractJavaCodegen {
|
||||
cliOptions.add(CliOption.newBoolean(RX_INTERFACE_OPTION,
|
||||
"When specified, API interfaces are generated with RX "
|
||||
+ "and methods return Single<> and Comparable."));
|
||||
cliOptions.add(CliOption.newBoolean(RX_VERSION_2_OPTION,
|
||||
"When specified in combination with rxInterface, "
|
||||
+ "API interfaces are generated with RxJava2."));
|
||||
cliOptions.add(CliOption.newString(VERTX_SWAGGER_ROUTER_VERSION_OPTION,
|
||||
"Specify the version of the swagger router library"));
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
public static final String SERVICE_INTERFACE = "serviceInterface";
|
||||
public static final String SERVICE_IMPLEMENTATION = "serviceImplementation";
|
||||
public static final String REACTIVE = "reactive";
|
||||
|
||||
public static final String INTERFACE_ONLY = "interfaceOnly";
|
||||
|
||||
private String basePackage;
|
||||
private String invokerPackage;
|
||||
@@ -75,12 +75,11 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
private boolean serviceInterface = false;
|
||||
private boolean serviceImplementation = false;
|
||||
private boolean reactive = false;
|
||||
private boolean interfaceOnly = false;
|
||||
|
||||
public KotlinSpringServerCodegen() {
|
||||
super();
|
||||
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".kt");
|
||||
|
||||
reservedWords.addAll(VARIABLE_RESERVED_WORDS);
|
||||
|
||||
outputFolder = "generated-code/kotlin-spring";
|
||||
@@ -124,6 +123,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
"interfaces. If this is set to true service interfaces will also be generated", serviceImplementation);
|
||||
addSwitch(USE_BEANVALIDATION, "Use BeanValidation API annotations to validate data types", useBeanValidation);
|
||||
addSwitch(REACTIVE, "use coroutines for reactive behavior", reactive);
|
||||
addSwitch(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.", interfaceOnly);
|
||||
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
|
||||
setLibrary(SPRING_BOOT);
|
||||
|
||||
@@ -209,6 +209,10 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
return this.useBeanValidation;
|
||||
}
|
||||
|
||||
public void setInterfaceOnly(boolean interfaceOnly) {
|
||||
this.interfaceOnly = interfaceOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
@@ -322,9 +326,18 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
writePropertyBack(REACTIVE, reactive);
|
||||
writePropertyBack(EXCEPTION_HANDLER, exceptionHandler);
|
||||
|
||||
if (additionalProperties.containsKey(INTERFACE_ONLY)) {
|
||||
this.setInterfaceOnly(Boolean.valueOf(additionalProperties.get(INTERFACE_ONLY).toString()));
|
||||
}
|
||||
|
||||
modelTemplateFiles.put("model.mustache", ".kt");
|
||||
apiTemplateFiles.put("api.mustache", ".kt");
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
if (interfaceOnly) {
|
||||
apiTemplateFiles.put("apiInterface.mustache", ".kt");
|
||||
} else {
|
||||
apiTemplateFiles.put("api.mustache", ".kt");
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".kt");
|
||||
}
|
||||
|
||||
if (this.serviceInterface) {
|
||||
apiTemplateFiles.put("service.mustache", "Service.kt");
|
||||
@@ -335,6 +348,9 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
apiTemplateFiles.put("serviceImpl.mustache", "ServiceImpl.kt");
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
|
||||
if (this.exceptionHandler) {
|
||||
supportingFiles.add(new SupportingFile("exceptions.mustache",
|
||||
sanitizeDirectory(sourceFolder + File.separator + apiPackage), "Exceptions.kt"));
|
||||
|
||||
@@ -28,7 +28,7 @@ public class OpenAPIYamlGenerator extends DefaultCodegen implements CodegenConfi
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(OpenAPIYamlGenerator.class);
|
||||
|
||||
protected String outputFile = "openapi.yaml";
|
||||
protected String outputFile = "openapi/openapi.yaml";
|
||||
|
||||
public OpenAPIYamlGenerator() {
|
||||
super();
|
||||
@@ -36,9 +36,6 @@ public class OpenAPIYamlGenerator extends DefaultCodegen implements CodegenConfi
|
||||
outputFolder = "generated-code/openapi-yaml";
|
||||
cliOptions.add(new CliOption(OUTPUT_NAME, "output filename"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("openapi.mustache",
|
||||
"openapi",
|
||||
"openapi.yaml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,13 +53,14 @@ public class OpenAPIYamlGenerator extends DefaultCodegen implements CodegenConfi
|
||||
return "Creates a static openapi.yaml file (OpenAPI spec v3).";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
if (additionalProperties.containsKey(OUTPUT_NAME)) {
|
||||
this.outputFile = additionalProperties.get(OUTPUT_NAME).toString();
|
||||
outputFile = additionalProperties.get(OUTPUT_NAME).toString();
|
||||
}
|
||||
LOGGER.info("Output file [outputFile={}]", outputFile);
|
||||
supportingFiles.add(new SupportingFile("openapi.mustache", outputFile));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +69,6 @@ public class OpenAPIYamlGenerator extends DefaultCodegen implements CodegenConfi
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// just return the original string
|
||||
|
||||
@@ -167,6 +167,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -200,7 +200,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
|
||||
if (alias != null && !alias.isEmpty()) {
|
||||
this.bundleAlias = alias.toLowerCase(Locale.ROOT);
|
||||
} else {
|
||||
this.bundleAlias = snakeCase(bundleName).replaceAll("([A-Z]+)", "\\_$1").toLowerCase(Locale.ROOT);
|
||||
this.bundleAlias = lowerCamelCase(bundleName).replaceAll("([A-Z]+)", "\\_$1").toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PythonClientExperimentalCodegen extends PythonClientCodegen {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PythonClientExperimentalCodegen.class);
|
||||
|
||||
public PythonClientExperimentalCodegen() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 "python-experimental";
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,18 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
protected String testFolder = "tests/testthat";
|
||||
protected boolean returnExceptionOnFailure = false;
|
||||
protected String exceptionPackage = "default";
|
||||
protected Map<String, String> exceptionPackages = new LinkedHashMap<String, String>();
|
||||
|
||||
public static final String EXCEPTION_PACKAGE = "exceptionPackage";
|
||||
public static final String USE_DEFAULT_EXCEPTION = "useDefaultExceptionHandling";
|
||||
public static final String USE_RLANG_EXCEPTION = "useRlangExceptionHandling";
|
||||
public static final String DEFAULT = "default";
|
||||
public static final String RLANG = "rlang";
|
||||
|
||||
protected boolean useDefaultExceptionHandling = false;
|
||||
protected boolean useRlangExceptionHandling = false;
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
@@ -103,8 +115,10 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("file", "data.frame");
|
||||
typeMapping.put("binary", "data.frame");
|
||||
typeMapping.put("ByteArray", "character");
|
||||
typeMapping.put("map", "object");
|
||||
typeMapping.put("map", "map");
|
||||
typeMapping.put("object", "object");
|
||||
|
||||
importMapping.clear();
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "R package name (convention: lowercase).")
|
||||
.defaultValue("openapi"));
|
||||
@@ -112,7 +126,16 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
.defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.EXCEPTION_ON_FAILURE, CodegenConstants.EXCEPTION_ON_FAILURE_DESC)
|
||||
.defaultValue(Boolean.FALSE.toString()));
|
||||
|
||||
exceptionPackages.put(DEFAULT, "Use stop() for raising exceptions.");
|
||||
exceptionPackages.put(RLANG, "Use rlang package for exceptions.");
|
||||
|
||||
CliOption exceptionPackage = new CliOption(EXCEPTION_PACKAGE, "Specify the exception handling package");
|
||||
exceptionPackage.setEnum(exceptionPackages);
|
||||
exceptionPackage.setDefault(DEFAULT);
|
||||
cliOptions.add(exceptionPackage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,8 +154,27 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
setPackageVersion("1.0.0");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.EXCEPTION_ON_FAILURE)) {
|
||||
boolean booleanValue = Boolean.valueOf(additionalProperties.get(CodegenConstants.EXCEPTION_ON_FAILURE).toString());
|
||||
setReturnExceptionOnFailure(booleanValue);
|
||||
} else {
|
||||
setReturnExceptionOnFailure(false);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(EXCEPTION_PACKAGE)) {
|
||||
String exceptionPackage = additionalProperties.get(EXCEPTION_PACKAGE).toString();
|
||||
setExceptionPackageToUse(exceptionPackage);
|
||||
} else {
|
||||
setExceptionPackageToUse(DEFAULT);
|
||||
}
|
||||
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||
additionalProperties.put(CodegenConstants.EXCEPTION_ON_FAILURE, returnExceptionOnFailure);
|
||||
|
||||
additionalProperties.put(USE_DEFAULT_EXCEPTION, this.useDefaultExceptionHandling);
|
||||
additionalProperties.put(USE_RLANG_EXCEPTION, this.useRlangExceptionHandling);
|
||||
|
||||
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
@@ -288,10 +330,10 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getTypeDeclaration(inner);
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner)+ "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getTypeDeclaration(inner);
|
||||
return getSchemaType(p) + "(" + getTypeDeclaration(inner) + ")";
|
||||
}
|
||||
|
||||
// Not using the supertype invocation, because we want to UpperCamelize
|
||||
@@ -382,6 +424,19 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.packageVersion = packageVersion;
|
||||
}
|
||||
|
||||
public void setReturnExceptionOnFailure(boolean returnExceptionOnFailure) {
|
||||
this.returnExceptionOnFailure = returnExceptionOnFailure;
|
||||
}
|
||||
|
||||
public void setExceptionPackageToUse(String exceptionPackage) {
|
||||
if(DEFAULT.equals(exceptionPackage))
|
||||
this.useDefaultExceptionHandling = true;
|
||||
if(RLANG.equals(exceptionPackage)){
|
||||
supportingFiles.add(new SupportingFile("api_exception.mustache", File.separator + "R", "api_exception.R"));
|
||||
this.useRlangExceptionHandling = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
|
||||
@@ -91,7 +91,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
// local variable names used in API methods (endpoints)
|
||||
for (String word : Arrays.asList(
|
||||
"local_var_path", "query_params", "header_params", "_header_accept", "_header_accept_result",
|
||||
"_header_content_type", "form_params", "post_body", "auth_names")) {
|
||||
"_header_content_type", "form_params", "post_body", "auth_names", "send")) {
|
||||
reservedWords.add(word.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.samskivert.mustache.Mustache;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
|
||||
@@ -53,6 +52,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
public static final String DELEGATE_PATTERN = "delegatePattern";
|
||||
public static final String SINGLE_CONTENT_TYPES = "singleContentTypes";
|
||||
public static final String VIRTUAL_SERVICE = "virtualService";
|
||||
public static final String SKIP_DEFAULT_INTERFACE = "skipDefaultInterface";
|
||||
|
||||
public static final String JAVA_8 = "java8";
|
||||
public static final String ASYNC = "async";
|
||||
@@ -67,6 +67,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
public static final String API_FIRST = "apiFirst";
|
||||
public static final String HATEOAS = "hateoas";
|
||||
public static final String RETURN_SUCCESS_CODE = "returnSuccessCode";
|
||||
public static final String UNHANDLED_EXCEPTION_HANDLING = "unhandledException";
|
||||
|
||||
protected String title = "OpenAPI Spring";
|
||||
protected String configPackage = "org.openapitools.configuration";
|
||||
@@ -79,6 +80,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
protected boolean async = false;
|
||||
protected boolean reactive = false;
|
||||
protected String responseWrapper = "";
|
||||
protected boolean skipDefaultInterface = false;
|
||||
protected boolean useTags = false;
|
||||
protected boolean useBeanValidation = true;
|
||||
protected boolean performBeanValidation = false;
|
||||
@@ -89,6 +91,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
protected boolean virtualService = false;
|
||||
protected boolean hateoas = false;
|
||||
protected boolean returnSuccessCode = false;
|
||||
protected boolean unhandledException = false;
|
||||
|
||||
public SpringCodegen() {
|
||||
super();
|
||||
@@ -117,7 +120,8 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.", interfaceOnly));
|
||||
cliOptions.add(CliOption.newBoolean(DELEGATE_PATTERN, "Whether to generate the server files using the delegate pattern", delegatePattern));
|
||||
cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES, "Whether to select only one produces/consumes content-type by operation.", singleContentTypes));
|
||||
cliOptions.add(CliOption.newBoolean(JAVA_8, "use java8 default interface", java8));
|
||||
updateJava8CliOptions();
|
||||
cliOptions.add(CliOption.newBoolean(SKIP_DEFAULT_INTERFACE, "Whether to generate default implementations for java8 interfaces", skipDefaultInterface));
|
||||
cliOptions.add(CliOption.newBoolean(ASYNC, "use async Callable controllers", async));
|
||||
cliOptions.add(CliOption.newBoolean(REACTIVE, "wrap responses in Mono/Flux Reactor types (spring-boot only)", reactive));
|
||||
cliOptions.add(new CliOption(RESPONSE_WRAPPER, "wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)"));
|
||||
@@ -131,6 +135,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
cliOptions.add(CliOption.newBoolean(USE_OPTIONAL,"Use Optional container for optional parameters", useOptional));
|
||||
cliOptions.add(CliOption.newBoolean(HATEOAS, "Use Spring HATEOAS library to allow adding HATEOAS links", hateoas));
|
||||
cliOptions.add(CliOption.newBoolean(RETURN_SUCCESS_CODE, "Generated server returns 2xx code", returnSuccessCode));
|
||||
cliOptions.add(CliOption.newBoolean(UNHANDLED_EXCEPTION_HANDLING, "Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).", unhandledException));
|
||||
|
||||
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application using the SpringFox integration.");
|
||||
supportedLibraries.put(SPRING_MVC_LIBRARY, "Spring-MVC Server application using the SpringFox integration.");
|
||||
@@ -142,6 +147,13 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
|
||||
}
|
||||
|
||||
private void updateJava8CliOptions() {
|
||||
CliOption option = cliOptions.stream().filter(o -> JAVA_8.equals(o.getOpt())).findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("Missing java8 option"));
|
||||
Map<String, String> java8ModeOptions = option.getEnum();
|
||||
java8ModeOptions.put("true", "Use Java 8 classes such as Base64. Use java8 default interface when a responseWrapper is used");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
@@ -225,6 +237,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.setSingleContentTypes(Boolean.valueOf(additionalProperties.get(SINGLE_CONTENT_TYPES).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SKIP_DEFAULT_INTERFACE)) {
|
||||
this.setSkipDefaultInterface(Boolean.valueOf(additionalProperties.get(SKIP_DEFAULT_INTERFACE).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(ASYNC)) {
|
||||
this.setAsync(Boolean.valueOf(additionalProperties.get(ASYNC).toString()));
|
||||
//fix for issue/1164
|
||||
@@ -280,6 +296,12 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.setReturnSuccessCode(Boolean.valueOf(additionalProperties.get(RETURN_SUCCESS_CODE).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(UNHANDLED_EXCEPTION_HANDLING)) {
|
||||
this.setUnhandledException(Boolean.valueOf(additionalProperties.get(UNHANDLED_EXCEPTION_HANDLING).toString()));
|
||||
} else {
|
||||
additionalProperties.put(UNHANDLED_EXCEPTION_HANDLING, this.isUnhandledException());
|
||||
}
|
||||
|
||||
typeMapping.put("file", "Resource");
|
||||
importMapping.put("Resource", "org.springframework.core.io.Resource");
|
||||
|
||||
@@ -378,6 +400,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
|
||||
if (this.java8) {
|
||||
additionalProperties.put("javaVersion", "1.8");
|
||||
additionalProperties.put("jdk8-default-interface", !this.skipDefaultInterface);
|
||||
if (!SPRING_CLOUD_LIBRARY.equals(library)) {
|
||||
additionalProperties.put("jdk8", true);
|
||||
}
|
||||
@@ -399,6 +422,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
// Some well-known Spring or Spring-Cloud response wrappers
|
||||
if (isNotEmpty(this.responseWrapper)) {
|
||||
additionalProperties.put("jdk8", false);
|
||||
additionalProperties.put("jdk8-default-interface", false);
|
||||
switch (this.responseWrapper) {
|
||||
case "Future":
|
||||
case "Callable":
|
||||
@@ -681,6 +705,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
return this.configPackage;
|
||||
}
|
||||
|
||||
public boolean isUnhandledException() {
|
||||
return unhandledException;
|
||||
}
|
||||
|
||||
public void setBasePackage(String basePackage) {
|
||||
this.basePackage = basePackage;
|
||||
}
|
||||
@@ -697,6 +725,8 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.singleContentTypes = singleContentTypes;
|
||||
}
|
||||
|
||||
public void setSkipDefaultInterface(boolean skipDefaultInterface) { this.skipDefaultInterface = skipDefaultInterface; }
|
||||
|
||||
public void setJava8(boolean java8) { this.java8 = java8; }
|
||||
|
||||
public void setVirtualService(boolean virtualService) { this.virtualService = virtualService; }
|
||||
@@ -731,6 +761,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.returnSuccessCode = returnSuccessCode;
|
||||
}
|
||||
|
||||
public void setUnhandledException(boolean unhandledException) {
|
||||
this.unhandledException = unhandledException;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
|
||||
@@ -35,7 +35,6 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TypeScriptJqueryClientCodegen.class);
|
||||
|
||||
public static final String NPM_REPOSITORY = "npmRepository";
|
||||
public static final String SNAPSHOT = "snapshot";
|
||||
public static final String JQUERY_ALREADY_IMPORTED = "jqueryAlreadyImported";
|
||||
|
||||
protected String npmRepository = null;
|
||||
|
||||
@@ -170,23 +170,12 @@ public class ModelUtils {
|
||||
if (allOperations != null) {
|
||||
for (Operation operation : allOperations) {
|
||||
//Params:
|
||||
if (operation.getParameters() != null) {
|
||||
for (Parameter p : operation.getParameters()) {
|
||||
Parameter parameter = getReferencedParameter(openAPI, p);
|
||||
if (parameter.getSchema() != null) {
|
||||
visitSchema(openAPI, parameter.getSchema(), null, visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
visitParameters(openAPI, operation.getParameters(), visitor, visitedSchemas);
|
||||
|
||||
//RequestBody:
|
||||
RequestBody requestBody = getReferencedRequestBody(openAPI, operation.getRequestBody());
|
||||
if (requestBody != null && requestBody.getContent() != null) {
|
||||
for (Entry<String, MediaType> e : requestBody.getContent().entrySet()) {
|
||||
if (e.getValue().getSchema() != null) {
|
||||
visitSchema(openAPI, e.getValue().getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
if (requestBody != null) {
|
||||
visitContent(openAPI, requestBody.getContent(), visitor, visitedSchemas);
|
||||
}
|
||||
|
||||
//Responses:
|
||||
@@ -194,19 +183,14 @@ public class ModelUtils {
|
||||
for (ApiResponse r : operation.getResponses().values()) {
|
||||
ApiResponse apiResponse = getReferencedApiResponse(openAPI, r);
|
||||
if (apiResponse != null) {
|
||||
if (apiResponse.getContent() != null) {
|
||||
for (Entry<String, MediaType> e : apiResponse.getContent().entrySet()) {
|
||||
if (e.getValue().getSchema() != null) {
|
||||
visitSchema(openAPI, e.getValue().getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
visitContent(openAPI, apiResponse.getContent(), visitor, visitedSchemas);
|
||||
if (apiResponse.getHeaders() != null) {
|
||||
for (Entry<String, Header> e : apiResponse.getHeaders().entrySet()) {
|
||||
Header header = getReferencedHeader(openAPI, e.getValue());
|
||||
if (header.getSchema() != null) {
|
||||
visitSchema(openAPI, header.getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||
}
|
||||
visitContent(openAPI, header.getContent(), visitor, visitedSchemas);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,6 +210,31 @@ public class ModelUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
//Params:
|
||||
visitParameters(openAPI, pathItem.getParameters(), visitor, visitedSchemas);
|
||||
}
|
||||
|
||||
private static void visitParameters(OpenAPI openAPI, List<Parameter> parameters, OpenAPISchemaVisitor visitor,
|
||||
List<String> visitedSchemas) {
|
||||
if (parameters != null) {
|
||||
for (Parameter p : parameters) {
|
||||
Parameter parameter = getReferencedParameter(openAPI, p);
|
||||
if (parameter.getSchema() != null) {
|
||||
visitSchema(openAPI, parameter.getSchema(), null, visitedSchemas, visitor);
|
||||
}
|
||||
visitContent(openAPI, parameter.getContent(), visitor, visitedSchemas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void visitContent(OpenAPI openAPI, Content content, OpenAPISchemaVisitor visitor, List<String> visitedSchemas) {
|
||||
if (content != null) {
|
||||
for (Entry<String, MediaType> e : content.entrySet()) {
|
||||
if (e.getValue().getSchema() != null) {
|
||||
visitSchema(openAPI, e.getValue().getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void visitSchema(OpenAPI openAPI, Schema schema, String mimeType, List<String> visitedSchemas, OpenAPISchemaVisitor visitor) {
|
||||
|
||||
@@ -161,3 +161,7 @@ dependencies {
|
||||
{{/java8}}
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options.tags = [ "http.response.details:a:Http Response Details" ]
|
||||
}
|
||||
|
||||
@@ -170,17 +170,17 @@
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tags>
|
||||
<tag>
|
||||
<name>http.response.details</name>
|
||||
<placement>a</placement>
|
||||
<head>Http Response Details:</head>
|
||||
</tag>
|
||||
</tags>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<tags>
|
||||
<tag>
|
||||
<name>http.response.details</name>
|
||||
<placement>a</placement>
|
||||
<head>Http Response Details:</head>
|
||||
</tag>
|
||||
</tags>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -235,6 +235,13 @@
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
{{^supportJava6}}
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.inject</groupId>
|
||||
<artifactId>jersey-hk2</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
{{/supportJava6}}
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
|
||||
@@ -88,8 +88,9 @@ public class ApiClient {
|
||||
public ApiClient() {
|
||||
init();
|
||||
|
||||
// Setup authentications (key: authentication name, value: authentication).{{#authMethods}}{{#isBasic}}
|
||||
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
|
||||
// Setup authentications (key: authentication name, value: authentication).{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
|
||||
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasicBasic}}{{^isBasicBasic}}
|
||||
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));{{/isBasicBasic}}{{/isBasic}}{{#isApiKey}}
|
||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
||||
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||
// Prevent the authentications from being modified.
|
||||
|
||||
@@ -143,3 +143,7 @@ dependencies {
|
||||
{{/threetenbp}}
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options.tags = [ "http.response.details:a:Http Response Details" ]
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ lazy val root = (project in file(".")).
|
||||
"org.threeten" % "threetenbp" % "1.3.5" % "compile",
|
||||
{{/threetenbp}}
|
||||
"io.gsonfire" % "gson-fire" % "1.8.3" % "compile",
|
||||
"javax.annotation" % "jsr250-api" % "1.0" % "compile",
|
||||
"junit" % "junit" % "4.12" % "test",
|
||||
"com.novocode" % "junit-interface" % "0.10" % "test"
|
||||
)
|
||||
|
||||
@@ -149,17 +149,17 @@
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tags>
|
||||
<tag>
|
||||
<name>http.response.details</name>
|
||||
<placement>a</placement>
|
||||
<head>Http Response Details:</head>
|
||||
</tag>
|
||||
</tags>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<tags>
|
||||
<tag>
|
||||
<name>http.response.details</name>
|
||||
<placement>a</placement>
|
||||
<head>Http Response Details:</head>
|
||||
</tag>
|
||||
</tags>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -284,6 +284,11 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
{{/parcelableModel}}
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
<version>${javax-annotation-version}</version>
|
||||
</dependency>
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@@ -297,7 +302,7 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<gson-fire-version>1.8.3</gson-fire-version>
|
||||
<swagger-core-version>1.5.21</swagger-core-version>
|
||||
<swagger-core-version>1.5.22</swagger-core-version>
|
||||
<okhttp-version>3.14.2</okhttp-version>
|
||||
<gson-version>2.8.5</gson-version>
|
||||
<commons-lang3-version>3.9</commons-lang3-version>
|
||||
@@ -308,6 +313,7 @@
|
||||
<threetenbp-version>1.3.8</threetenbp-version>
|
||||
{{/threetenbp}}
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<javax-annotation-version>1.0</javax-annotation-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@@ -96,7 +96,7 @@ if(hasProperty('target') && target == 'android') {
|
||||
|
||||
ext {
|
||||
swagger_annotations_version = "1.5.21"
|
||||
rest_assured_version = "3.3.0"
|
||||
rest_assured_version = "4.0.0"
|
||||
junit_version = "4.12"
|
||||
gson_version = "2.8.5"
|
||||
gson_fire_version = "1.8.3"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user