forked from loafle/openapi-generator-original
Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0453e64fa6 | ||
|
|
0a479f77f6 | ||
|
|
2392a09eeb | ||
|
|
f5f00069bd | ||
|
|
640fd87e3b | ||
|
|
43b60e667e | ||
|
|
a2c27ba8a6 | ||
|
|
f5708218ea | ||
|
|
276afefc85 | ||
|
|
36d1ec364e | ||
|
|
dbbeffa712 | ||
|
|
0adfd9f8e9 | ||
|
|
178949038f | ||
|
|
5a332f3c57 | ||
|
|
f72059e7ac | ||
|
|
992afd51eb | ||
|
|
8de5c62cf2 | ||
|
|
ebaa7021a4 | ||
|
|
51437af1cd | ||
|
|
c45dba1691 | ||
|
|
fbe9626b7e | ||
|
|
cf657f1c7b | ||
|
|
f65193e6fb | ||
|
|
7a1945e154 | ||
|
|
f4c66d9e53 | ||
|
|
0fb1ffa88b | ||
|
|
69a3852ef7 | ||
|
|
d649c1311e | ||
|
|
f7eacbb0c5 | ||
|
|
3e928fff2d | ||
|
|
967cc5bd3b | ||
|
|
b8f1e5afa1 | ||
|
|
fe04a0e347 | ||
|
|
0e4d3e7815 | ||
|
|
e631c16b96 | ||
|
|
501245d0c2 | ||
|
|
df55ab3efb | ||
|
|
1e5e1d4458 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,7 @@
|
||||
out/
|
||||
*.ipr
|
||||
*.iws
|
||||
*.gpg
|
||||
classpath.txt
|
||||
version.properties
|
||||
!modules/openapi-generator-cli/src/main/resources/version.properties
|
||||
|
||||
19
.travis.yml
19
.travis.yml
@@ -9,8 +9,9 @@ cache:
|
||||
- $HOME/.ivy2
|
||||
- $HOME/.gradle/caches/
|
||||
- $HOME/.gradle/wrapper/
|
||||
- $HOME/samples/client/petstore/javascript/node_modules
|
||||
- $HOME/samples/client/petstore/php/OpenAPIToolsClient-php/vendor
|
||||
- $HOME/samples/client/petstore/ruby/venodr/bundle
|
||||
- $HOME/samples/client/petstore/ruby/vendor/bundle
|
||||
- $HOME/samples/client/petstore/python/.venv/
|
||||
- $HOME/samples/client/petstore/typescript-node/npm/node_modules
|
||||
- $HOME/samples/client/petstore/typescript-node/npm/typings/
|
||||
@@ -72,6 +73,11 @@ before_install:
|
||||
- cat /etc/hosts
|
||||
# show java version
|
||||
- java -version
|
||||
- if [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
||||
openssl aes-256-cbc -K $encrypted_6e2c8bba47c6_key -iv $encrypted_6e2c8bba47c6_iv -in sec.gpg.enc -out sec.gpg -d ;
|
||||
gpg --keyserver keyserver.ubuntu.com --recv-key $SIGNING_KEY ;
|
||||
gpg --check-trustdb ;
|
||||
fi;
|
||||
|
||||
install:
|
||||
# Add Godeps dependencies to GOPATH and PATH
|
||||
@@ -93,10 +99,15 @@ script:
|
||||
- mvn --quiet clean install
|
||||
- mvn --quiet verify -Psamples
|
||||
after_success:
|
||||
# push a snapshot version to maven repo
|
||||
- if [ $SONATYPE_USERNAME ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_BRANCH" = "master" ]; then
|
||||
mvn clean deploy --settings CI/settings.xml;
|
||||
# push to maven repo
|
||||
- if [ $SONATYPE_USERNAME ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
||||
mvn clean deploy -DskipTests=true -B -U -P release --settings CI/settings.xml;
|
||||
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
|
||||
pushd .;
|
||||
cd modules/openapi-generator-gradle-plugin;
|
||||
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" uploadArchives --no-daemon;
|
||||
echo "Finished ./gradlew uploadArchives";
|
||||
popd;
|
||||
fi;
|
||||
## docker: build and push openapi-generator-online to DockerHub
|
||||
- if [ $DOCKER_HUB_USERNAME ]; then echo "$DOCKER_HUB_PASSWORD" | docker login --username=$DOCKER_HUB_USERNAME --password-stdin && docker build -t $DOCKER_GENERATOR_IMAGE_NAME ./modules/openapi-generator-online && if [ ! -z "$TRAVIS_TAG" ]; then docker tag $DOCKER_GENERATOR_IMAGE_NAME:latest $DOCKER_GENERATOR_IMAGE_NAME:$TRAVIS_TAG; fi && if [ ! -z "$TRAVIS_TAG" ] || [ "$TRAVIS_BRANCH" = "master" ]; then docker push $DOCKER_GENERATOR_IMAGE_NAME && echo "Pushed to $DOCKER_GENERATOR_IMAGE_NAME"; fi; fi
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<url>https://github.com/openapi-tools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapi-tools/openapi-generator.git</connection>
|
||||
@@ -214,12 +214,13 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.4</version>
|
||||
<version>3.0.1</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<source>1.8</source>
|
||||
<encoding>UTF-8</encoding>
|
||||
<maxmemory>1g</maxmemory>
|
||||
<failOnWarnings>true</failOnWarnings>
|
||||
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -218,12 +218,13 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.4</version>
|
||||
<version>3.0.1</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<source>1.8</source>
|
||||
<encoding>UTF-8</encoding>
|
||||
<maxmemory>1g</maxmemory>
|
||||
<failOnWarnings>true</failOnWarnings>
|
||||
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -218,12 +218,13 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.4</version>
|
||||
<version>3.0.1</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<source>1.8</source>
|
||||
<encoding>UTF-8</encoding>
|
||||
<maxmemory>1g</maxmemory>
|
||||
<failOnWarnings>true</failOnWarnings>
|
||||
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -214,12 +214,13 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.4</version>
|
||||
<version>3.0.1</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<source>1.8</source>
|
||||
<encoding>UTF-8</encoding>
|
||||
<maxmemory>1g</maxmemory>
|
||||
<failOnWarnings>true</failOnWarnings>
|
||||
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<artifactId>openapi-generator-shippable-pom</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.0.0</version>
|
||||
<name>openapi-generator-shippable-pom</name>
|
||||
<version>3.0.1</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -214,12 +214,13 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.4</version>
|
||||
<version>3.0.1</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<source>1.8</source>
|
||||
<encoding>UTF-8</encoding>
|
||||
<maxmemory>1g</maxmemory>
|
||||
<failOnWarnings>true</failOnWarnings>
|
||||
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>
|
||||
</configuration>
|
||||
<executions>
|
||||
@@ -857,10 +858,7 @@
|
||||
</profile>
|
||||
</profiles>
|
||||
<modules>
|
||||
<module>../modules/openapi-generator</module>
|
||||
<module>../modules/openapi-generator-cli</module>
|
||||
<module>../modules/openapi-generator-maven-plugin</module>
|
||||
<module>../modules/openapi-generator-online</module>
|
||||
<module>../</module>
|
||||
</modules>
|
||||
<reporting>
|
||||
<outputDirectory>target/site</outputDirectory>
|
||||
|
||||
@@ -10,9 +10,27 @@
|
||||
<username>${env.SONATYPE_USERNAME}</username>
|
||||
<password>${env.SONATYPE_PASSWORD}</password>
|
||||
</server>
|
||||
<server>
|
||||
<id>ossrh</id>
|
||||
<username>${env.SONATYPE_USERNAME}</username>
|
||||
<password>${env.SONATYPE_PASSWORD}</password>
|
||||
</server>
|
||||
</servers>
|
||||
<mirrors/>
|
||||
<proxies/>
|
||||
<profiles/>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<gpg.executable>gpg</gpg.executable>
|
||||
<gpg.keyname>${env.SIGNING_KEY}</gpg.keyname>
|
||||
<gpg.passphrase>${env.SIGNING_PASSPHRASE}</gpg.passphrase>
|
||||
<gpg.secretKeyring>${env.TRAVIS_BUILD_DIR}/sec.gpg</gpg.secretKeyring>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
<activeProfiles/>
|
||||
</settings>
|
||||
|
||||
79
README.md
79
README.md
@@ -4,7 +4,7 @@
|
||||
|
||||
Master (3.0.0): [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator/dashboard)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
|
||||
|
||||
</div>
|
||||
@@ -47,10 +47,11 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
|
||||
- [Table of Contents](#table-of-contents)
|
||||
- [1 - Installation](#1---installation)
|
||||
- [1.1 - Compatibility](#11---compatibility)
|
||||
- [1.2 - Download JAR](#12---download-jar)
|
||||
- [1.3 - Build Projects](#13---build-projects)
|
||||
- [1.4 - Homebrew](#14---homebrew)
|
||||
- [1.5 - Docker](#15---docker)
|
||||
- [1.2 - Artifacts on Maven Central](#12---artifacts-on-maven-central)
|
||||
- [1.3 - Download JAR](#13---download-jar)
|
||||
- [1.4 - Build Projects](#14---build-projects)
|
||||
- [1.5 - Homebrew](#15---homebrew)
|
||||
- [1.6 - Docker](#16---docker)
|
||||
- [2 - Getting Started](#2---getting-started)
|
||||
- [3 - Usage](#3---usage)
|
||||
- [3.1 - Customization](#31---customization)
|
||||
@@ -75,10 +76,56 @@ OpenAPI Generator Version | Release Date | OpenAPI Spec compatibility | Notes
|
||||
---------------------------- | ------------ | -------------------------- | -----
|
||||
4.0.0 (upcoming major release) | TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Major release with breaking changes (no fallback)
|
||||
3.1.0 (upcoming minor release) | TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release with breaking changes (with fallbacks)
|
||||
3.0.0 (current master, upcoming release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.0.0-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | First release with breaking changes
|
||||
3.0.1 (current master, upcoming release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.0.1/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Bug fixes release
|
||||
3.0.0 | 01.06.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | First release with breaking changes
|
||||
|
||||
### [1.2 - Artifacts on Maven Central](#table-of-contents)
|
||||
|
||||
### [1.2 - Download JAR](#table-of-contents)
|
||||
You can find our released artefacts on maven central:
|
||||
|
||||
**Core:**
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator</artifactId>
|
||||
<version>${openapi-generator-version}</version>
|
||||
</dependency>
|
||||
```
|
||||
* [openapi-generator](https://mvnrepository.com/artifact/org.openapitools/openapi-generator)
|
||||
|
||||
**Cli:**
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-cli</artifactId>
|
||||
<version>${openapi-generator-version}</version>
|
||||
</dependency>
|
||||
```
|
||||
* [openapi-generator-cli](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-cli)
|
||||
|
||||
**Maven plugin:**
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>${openapi-generator-version}</version>
|
||||
</dependency>
|
||||
```
|
||||
* [openapi-generator-maven-plugin](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-maven-plugin)
|
||||
* [Readme](https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-maven-plugin/README.adoc)
|
||||
|
||||
**Gradle plugin:**
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-gradle-plugin</artifactId>
|
||||
<version>${openapi-generator-version}</version>
|
||||
</dependency>
|
||||
```
|
||||
* [openapi-generator-gradle-plugin](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-gradle-plugin)
|
||||
* [Readme](https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/README.adoc)
|
||||
|
||||
### [1.3 - Download JAR](#table-of-contents)
|
||||
|
||||
If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum):
|
||||
|
||||
@@ -102,7 +149,7 @@ export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
|
||||
export PATH=${JAVA_HOME}/bin:$PATH
|
||||
```
|
||||
|
||||
### [1.3 - Build Projects](#table-of-contents)
|
||||
### [1.4 - Build Projects](#table-of-contents)
|
||||
|
||||
To build from source, you need the following installed and available in your `$PATH:`
|
||||
|
||||
@@ -120,16 +167,16 @@ If you don't have maven installed, you may directly use the included [maven wrap
|
||||
./mvnw clean install
|
||||
```
|
||||
|
||||
### [1.4 - Homebrew](#table-of-contents)
|
||||
### [1.5 - Homebrew](#table-of-contents)
|
||||
|
||||
To install, run `brew install openapi-generator`
|
||||
To install, run `brew install openapi-generator` (the new brew formula is pending https://github.com/Homebrew/homebrew-core/pull/28584)
|
||||
|
||||
Here is an example usage to generate a Ruby client:
|
||||
```sh
|
||||
openapi-generator generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g ruby -o /tmp/test/
|
||||
```
|
||||
|
||||
### [1.5 - Docker](#table-of-contents)
|
||||
### [1.6 - Docker](#table-of-contents)
|
||||
|
||||
#### Public Pre-built Docker images
|
||||
|
||||
@@ -346,15 +393,23 @@ The OpenAPI Generator project is intended as a benefit for users of the Open API
|
||||
When code is generated from this project, it shall be considered **AS IS** and owned by the user of the software. There are no warranties--expressed or implied--for generated code. You can do what you wish with it, and once generated, the code is your responsibility and subject to the licensing terms that you deem appropriate.
|
||||
|
||||
## [4 - Companies/Projects using OpenAPI Generator](#table-of-contents)
|
||||
Here are some companies/projects using OpenAPI Generator in production. To add your company/project to the list, please visit [README.md](README.md) and click on the icon to edit the page.
|
||||
Here are some companies/projects (alphabetical order) using OpenAPI Generator in production. To add your company/project to the list, please visit [README.md](README.md) and click on the icon to edit the page.
|
||||
|
||||
- [Angular.Schule](https://angular.schule/)
|
||||
- [Bithost GmbH](https://www.bithost.ch)
|
||||
- [GMO Pepabo](https://pepabo.com/en/)
|
||||
- [Raiffeisen Schweiz Genossenschaft](https://www.raiffeisen.ch)
|
||||
- [REST United](https://restunited.com)
|
||||
- [unblu inc.](https://www.unblu.com/)
|
||||
|
||||
|
||||
## [5 - Presentations/Videos/Tutorials/Books](#table-of-contents)
|
||||
|
||||
- 2018/05/12 - [OpenAPI Generator - community drivenで成長するコードジェネレータ](https://ackintosh.github.io/blog/2018/05/12/openapi-generator/) by [中野暁人](https://github.com/ackintosh)
|
||||
- 2018/05/15 - [Starting a new open-source project](http://jmini.github.io/blog/2018/2018-05-15_new-open-source-project.html) by [Jeremie Bresson](https://github.com/jmini)
|
||||
- 2018/05/15 - [REST API仕様からAPIクライアントやスタブサーバを自動生成する「OpenAPI Generator」オープンソースで公開。Swagger Codegenからのフォーク](https://www.publickey1.jp/blog/18/rest_apiapiopenapi_generatorswagger_generator.html) by [Publickey](https://www.publickey1.jp)
|
||||
- 2018/04/12 - [Generate Angular API clients with Swagger](https://angular.schule/blog/2018-04-swagger-codegen) by [JohannesHoppe](https://github.com/JohannesHoppe)
|
||||
- 2018/06/08 - [Swagger Codegen is now OpenAPI Generator](https://angular.schule/blog/2018-06-swagger-codegen-is-now-openapi-generator) by [JohannesHoppe](https://github.com/JohannesHoppe)
|
||||
|
||||
## [6 - About Us](#table-of-contents)
|
||||
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -g cpp-pistache-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/pistache-server $@"
|
||||
ags="generate -g cpp-pistache-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/cpp-pistache $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/qt5cpp -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-qt5 -o samples/client/petstore/qt5cpp $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/qt5cpp -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-qt5 -o samples/client/petstore/cpp-qt5 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -g cpp-restbed-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/restbed $@"
|
||||
ags="generate -g cpp-restbed-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/cpp-restbed $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpprest -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-restsdk -o samples/client/petstore/cpprest $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpprest -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-restsdk -o samples/client/petstore/cpp-restsdk $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/tizen -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-tizen -o samples/client/petstore/tizen $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/tizen -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-tizen -o samples/client/petstore/cpp-tizen $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -12,6 +12,7 @@ sleep 5
|
||||
# LIST OF SCRIPTS:
|
||||
./bin/ruby-petstore.sh
|
||||
./bin/java-petstore-all.sh
|
||||
./bin/java-jaxrs-petstore-server-all.sh
|
||||
./bin/spring-all-pestore.sh
|
||||
./bin/kotlin-client-petstore.sh
|
||||
./bin/kotlin-client-string.sh
|
||||
@@ -29,8 +30,11 @@ sleep 5
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
echo "UNCOMMITTED CHANGES ERROR"
|
||||
echo "There are uncommitted changes in working tree after execution of 'bin/ensure-up-to-date'"
|
||||
echo "Perform git diff"
|
||||
git --no-pager diff
|
||||
echo "Perform git status"
|
||||
git status
|
||||
echo "Please run 'bin/ensure-up-to-date' locally and commit changes"
|
||||
echo "Please run 'bin/ensure-up-to-date' locally and commit changes (UNCOMMITTED CHANGES ERROR)"
|
||||
exit 1
|
||||
else
|
||||
echo "Git working tree is clean"
|
||||
|
||||
19
bin/java-jaxrs-petstore-server-all.sh
Executable file
19
bin/java-jaxrs-petstore-server-all.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
# script to run all generators extending AbstractJavaJAXRSServerCodegen
|
||||
|
||||
./bin/jaxrs-petstore-server-datelib-j8.sh
|
||||
./bin/jaxrs-cxf-cdi-petstore-server.sh
|
||||
./bin/jaxrs-cxf-petstore-server-annotated-base-path.sh
|
||||
./bin/jaxrs-cxf-petstore-server-non-spring-application.sh
|
||||
./bin/jaxrs-cxf-petstore-server.sh
|
||||
./bin/jaxrs-jersey1-petstore-server.sh
|
||||
./bin/jaxrs-jersey1-usetags-petstore-server.sh
|
||||
./bin/jaxrs-petstore-server.sh
|
||||
./bin/jaxrs-resteasy-eap-java8-petstore-server.sh
|
||||
./bin/jaxrs-resteasy-eap-joda-petstore-server.sh
|
||||
./bin/jaxrs-resteasy-eap-petstore-server.sh
|
||||
./bin/jaxrs-resteasy-joda-petstore-server.sh
|
||||
./bin/jaxrs-resteasy-petstore-server.sh
|
||||
./bin/jaxrs-spec-petstore-server-interface.sh
|
||||
./bin/jaxrs-spec-petstore-server.sh
|
||||
./bin/jaxrs-usetags-petstore-server.sh
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/qt5cpp -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-qt5 -o samples/client/petstore/qt5cpp $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/qt5cpp -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-qt5 -o samples/client/petstore/cpp-qt5 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/tizen -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-tizen -o samples/client/petstore/tizen $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/tizen -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-tizen -o samples/client/petstore/cpp-tizen $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/qt5cpp -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g cpp-qt5 -o samples/client/petstore-security-test/qt5cpp $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/qt5cpp -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g cpp-qt5 -o samples/client/petstore-security-test/cpp-qt5 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
64
bin/utils/release_version_update.sh
Executable file
64
bin/utils/release_version_update.sh
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# usage: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1
|
||||
#
|
||||
# Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
if [[ "$1" != "" ]]; then
|
||||
FROM="$1"
|
||||
else
|
||||
echo "Missing argument. Usage e.g.: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [[ "$2" != "" ]]; then
|
||||
TO="$2"
|
||||
else
|
||||
echo "Missing argument. Usage e.g.: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
||||
echo "IMPORTANT: this script works on Mac only"
|
||||
echo "Release preparation: replacing $FROM with $TO in different files"
|
||||
|
||||
declare -a files=("CI/pom.xml.bash"
|
||||
"CI/pom.xml.circleci"
|
||||
"CI/pom.xml.circleci.java7"
|
||||
"CI/pom.xml.ios"
|
||||
"CI/pom.xml.shippable"
|
||||
"modules/openapi-generator-cli/pom.xml"
|
||||
"modules/openapi-generator-gradle-plugin/README.adoc"
|
||||
"modules/openapi-generator-gradle-plugin/gradle.properties"
|
||||
"modules/openapi-generator-gradle-plugin/pom.xml"
|
||||
"modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle"
|
||||
"modules/openapi-generator-maven-plugin/pom.xml"
|
||||
"modules/openapi-generator-online/pom.xml"
|
||||
"modules/openapi-generator/pom.xml"
|
||||
"modules/openapi-generator-online/Dockerfile"
|
||||
"pom.xml"
|
||||
"README.md")
|
||||
|
||||
for filename in "${files[@]}"; do
|
||||
# e.g. sed -i '' "s/3.0.1-SNAPSHOT/3.0.1/g" CI/pom.xml.bash
|
||||
#echo "Running command: sed -i '' "s/$FROM/$TO/g" $filename"
|
||||
if sed -i '' "s/$FROM/$TO/g" $filename; then
|
||||
echo "Updated $filename successfully!"
|
||||
else
|
||||
echo "ERROR: Failed to update $filename with the following command"
|
||||
echo "sed -i '' \"s/$FROM/$TO/g\" $filename"
|
||||
fi
|
||||
done
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-qt5 -o samples\client\petstore\qt5cpp
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-qt5 -o samples\client\petstore\cpp-qt5
|
||||
|
||||
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 cpp-restsdk -o samples\client\petstore\cpprest
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-restsdk -o samples\client\petstore\cpp-restsdk
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-tizen -o samples\client\petstore\tizen
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-tizen -o samples\client\petstore\cpp-tizen
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -8,11 +8,19 @@ JAVA_OPTS=${JAVA_OPTS:-"-Xmx1024M -DloggerPath=conf/log4j.properties"}
|
||||
|
||||
cli="${GEN_DIR}/modules/openapi-generator-cli"
|
||||
codegen="${cli}/target/openapi-generator-cli.jar"
|
||||
cmdsrc="${cli}/src/main/java/org/openapitools/codegen/cmd"
|
||||
|
||||
pattern="@Command(name = \"$1\""
|
||||
if expr "x$1" : 'x[a-z][a-z-]*$' > /dev/null && fgrep -qe "$pattern" "$cmdsrc"/*.java || expr "$1" = 'help' > /dev/null; then
|
||||
# If ${GEN_DIR} has been mapped elsewhere from default, and that location has not been built
|
||||
# We code in a list of commands here as source processing is potentially buggy (requires undocumented conventional use of annotations).
|
||||
# A list of known commands helps us determine if we should compile CLI. There's an edge-case where a new command not added to this
|
||||
# list won't be considered a "real" command. We can get around that a bit by checking CLI completions beforehand if it exists.
|
||||
commands="list,generate,meta,langs,help,config-help,validate,version"
|
||||
|
||||
# if CLI jar exists, check $1 against completions available in the CLI
|
||||
if [[ -f "${codegen}" && -n "$(java ${JAVA_OPTS} -jar "${codegen}" completion | grep "^$1\$" )" ]]; then
|
||||
command=$1
|
||||
shift
|
||||
exec java ${JAVA_OPTS} -jar "${codegen}" "${command}" "$@"
|
||||
elif [[ -n "$(echo commands | tr ',' '\n' | grep "^$1\$" )" ]]; then
|
||||
# If CLI jar does not exist, and $1 is a known CLI command, build the CLI jar and run that command.
|
||||
if [[ ! -f "${codegen}" ]]; then
|
||||
(cd "${GEN_DIR}" && exec mvn -am -pl "modules/openapi-generator-cli" -Duser.home=$(dirname $MAVEN_CONFIG) package)
|
||||
fi
|
||||
@@ -20,5 +28,6 @@ if expr "x$1" : 'x[a-z][a-z-]*$' > /dev/null && fgrep -qe "$pattern" "$cmdsrc"/*
|
||||
shift
|
||||
exec java ${JAVA_OPTS} -jar "${codegen}" "${command}" "$@"
|
||||
else
|
||||
# Pass args as linux commands. This allows us to do something like: docker run -it (-e…, -v…) image ls -la
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
@@ -49,7 +49,7 @@ You can find our released artefact on maven central:
|
||||
|
||||
Old:
|
||||
|
||||
```
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen</artifactId>
|
||||
@@ -58,7 +58,7 @@ Old:
|
||||
|
||||
New:
|
||||
|
||||
```
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator</artifactId>
|
||||
@@ -67,7 +67,7 @@ New:
|
||||
|
||||
**Cli:**
|
||||
|
||||
```
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen-cli</artifactId>
|
||||
@@ -76,7 +76,7 @@ New:
|
||||
|
||||
New:
|
||||
|
||||
```
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-cli</artifactId>
|
||||
@@ -85,7 +85,7 @@ New:
|
||||
|
||||
**Maven plugin:**
|
||||
|
||||
```
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen-maven-plugin</artifactId>
|
||||
@@ -94,7 +94,7 @@ New:
|
||||
|
||||
New:
|
||||
|
||||
```
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
@@ -187,7 +187,7 @@ Example: `org.openapitools.codegen.DefaultGenerator`
|
||||
In OpenAPI spec v3, there's no body parameter, which is replaced by [Request Body Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#request-body-object). The parameter name for Request Body is named automatically based on the model name (e.g. User). To control how the "Request Body" parmaeter is named, please add the vendor extension `x-codegen-request-body-name` to the operation:
|
||||
|
||||
OpenAPI Spec v3:
|
||||
```
|
||||
```yaml
|
||||
paths:
|
||||
/pet:
|
||||
post:
|
||||
@@ -209,7 +209,7 @@ paths:
|
||||
```
|
||||
|
||||
OpenAPI Spec v2:
|
||||
```
|
||||
```yaml
|
||||
paths:
|
||||
/pet:
|
||||
post:
|
||||
|
||||
@@ -18,7 +18,7 @@ There are several reasons:
|
||||
|
||||
#### Has anything been done in attempt to address the issues before deciding to fork Swagger Codegen and maintain a community-driven version?
|
||||
|
||||
There was several conversations with SmartBear (Ron, Hugo) via emails, gitter, Skype call and GitHub issues.
|
||||
There were several conversations with SmartBear (Ron, Hugo) via emails, gitter, Skype call and GitHub issues.
|
||||
But there was no consensus on the next steps and on the direction for Swagger Codegen 3.0.0.
|
||||
|
||||
#### Is there any change to the project license?
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -20,7 +20,6 @@
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<excludes>
|
||||
<exclude>logback.xml</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
@@ -78,6 +77,12 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!--https://github.com/airlift/airline-->
|
||||
<dependency>
|
||||
@@ -91,9 +96,9 @@
|
||||
<version>2.3.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
|
||||
@@ -23,8 +23,6 @@ import io.airlift.airline.ParseOptionMissingException;
|
||||
import io.airlift.airline.ParseOptionMissingValueException;
|
||||
import org.openapitools.codegen.cmd.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* User: lanwen Date: 24.03.15 Time: 17:56
|
||||
* <p>
|
||||
@@ -52,21 +50,23 @@ public class OpenAPIGenerator {
|
||||
Help.class,
|
||||
ConfigHelp.class,
|
||||
Validate.class,
|
||||
Version.class
|
||||
Version.class,
|
||||
CompletionCommand.class
|
||||
);
|
||||
|
||||
// If CLI is run without a command, consider this an error.
|
||||
// We can check against empty args because unrecognized arguments/commands result in an exception.
|
||||
// This is useful to exit with status 1, for example, so that misconfigured scripts fail fast.
|
||||
// We don't want the default command to exit internally with status 1 because when the default command is something like "list",
|
||||
// it would prevent scripting using the command directly. Example:
|
||||
// java -jar cli.jar list --short | tr ',' '\n' | xargs -I{} echo "Doing something with {}"
|
||||
if (args.length == 0) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
builder.build().parse(args).run();
|
||||
|
||||
// If CLI is run without a command, consider this an error. This exists after initial parse/run
|
||||
// so we can present the configured "default command".
|
||||
// We can check against empty args because unrecognized arguments/commands result in an exception.
|
||||
// This is useful to exit with status 1, for example, so that misconfigured scripts fail fast.
|
||||
// We don't want the default command to exit internally with status 1 because when the default command is something like "list",
|
||||
// it would prevent scripting using the command directly. Example:
|
||||
// java -jar cli.jar list --short | tr ',' '\n' | xargs -I{} echo "Doing something with {}"
|
||||
if (args.length == 0) {
|
||||
System.exit(1);
|
||||
}
|
||||
} catch (ParseOptionMissingException | ParseOptionMissingValueException e) {
|
||||
System.err.printf("[error] %s%n", e.getMessage());
|
||||
System.exit(1);
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2010 the original author or authors.
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* NOTICE: File originally taken from:
|
||||
* https://github.com/airlift/airline/blob/fc7a55e34b6361cb97235de5a1b21cba9b508f4b/src/main/java/io/airlift/airline/SuggestCommand.java#L1
|
||||
* Modifications have been made to fit the needs of OpenAPI Tools CLI.
|
||||
*/
|
||||
package org.openapitools.codegen.cmd;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.airlift.airline.*;
|
||||
import io.airlift.airline.model.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static io.airlift.airline.ParserUtil.createInstance;
|
||||
|
||||
@Command(name = "completion", description = "Complete commands (for using in tooling such as Bash Completions).", hidden = true)
|
||||
public class CompletionCommand
|
||||
implements Runnable, Callable<Void> {
|
||||
private static final Map<Context, Class<? extends Suggester>> BUILTIN_SUGGESTERS = ImmutableMap.<Context, Class<? extends Suggester>>builder()
|
||||
.put(Context.GLOBAL, GlobalSuggester.class)
|
||||
.put(Context.GROUP, GroupSuggester.class)
|
||||
.put(Context.COMMAND, CommandSuggester.class)
|
||||
.build();
|
||||
|
||||
@Inject
|
||||
public GlobalMetadata metadata;
|
||||
|
||||
@Arguments
|
||||
public List<String> arguments = newArrayList();
|
||||
|
||||
@Override
|
||||
public Void call() {
|
||||
run();
|
||||
return null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public Iterable<String> generateSuggestions() {
|
||||
Parser parser = new Parser();
|
||||
ParseState state = parser.parse(metadata, arguments);
|
||||
|
||||
Class<? extends Suggester> suggesterClass = BUILTIN_SUGGESTERS.get(state.getLocation());
|
||||
if (suggesterClass != null) {
|
||||
SuggesterMetadata suggesterMetadata = MetadataLoader.loadSuggester(suggesterClass);
|
||||
|
||||
if (suggesterMetadata != null) {
|
||||
ImmutableMap.Builder<Class<?>, Object> bindings = ImmutableMap.<Class<?>, Object>builder()
|
||||
.put(GlobalMetadata.class, metadata);
|
||||
|
||||
if (state.getGroup() != null) {
|
||||
bindings.put(CommandGroupMetadata.class, state.getGroup());
|
||||
}
|
||||
|
||||
if (state.getCommand() != null) {
|
||||
bindings.put(CommandMetadata.class, state.getCommand());
|
||||
}
|
||||
|
||||
Suggester suggester = createInstance(suggesterMetadata.getSuggesterClass(),
|
||||
ImmutableList.<OptionMetadata>of(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
suggesterMetadata.getMetadataInjections(),
|
||||
bindings.build());
|
||||
|
||||
return suggester.suggest();
|
||||
}
|
||||
}
|
||||
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println(Joiner.on("\n").join(generateSuggestions()));
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
|
||||
</layout>
|
||||
<target>System.out</target>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>[%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>ERROR</level>
|
||||
<onMatch>DENY</onMatch>
|
||||
<onMismatch>NEUTRAL</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
<logger name="io.swagger" level="debug"/>
|
||||
<root level="error">
|
||||
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<target>System.err</target>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>[%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
</appender>
|
||||
<logger name="io.swagger" level="warn">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="STDERR"/>
|
||||
</logger>
|
||||
<logger name="org.openapitools" level="info">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="STDERR"/>
|
||||
</logger>
|
||||
<root level="error">
|
||||
<appender-ref ref="STDERR"/>
|
||||
</root>
|
||||
</configuration>
|
||||
|
||||
@@ -34,7 +34,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:3.0.0"
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,12 @@ buildscript {
|
||||
maven {
|
||||
url "https://plugins.gradle.org/m2/"
|
||||
}
|
||||
maven {
|
||||
url "https://oss.sonatype.org/content/repositories/releases/"
|
||||
}
|
||||
maven {
|
||||
url "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
@@ -21,9 +27,11 @@ This plugin supports common functionality found in Open API Generator CLI as a g
|
||||
This gives you the ability to generate client SDKs, documentation, new generators, and to validate Open API 2.0 and 3.x
|
||||
specifications as part of your build. Other tasks are available as command line tasks.
|
||||
"""
|
||||
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
|
||||
|
||||
apply plugin: 'java-gradle-plugin'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'signing'
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: "org.gradle.kotlin.kotlin-dsl"
|
||||
|
||||
@@ -33,6 +41,12 @@ targetCompatibility = 1.8
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven {
|
||||
url "https://oss.sonatype.org/content/repositories/releases/"
|
||||
}
|
||||
maven {
|
||||
url "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -67,7 +81,6 @@ test {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
openApiGenerator {
|
||||
@@ -77,6 +90,87 @@ gradlePlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// signing will require three keys to be defined: signing.keyId, signing.password, and signing.secretKeyRingFile.
|
||||
// These can be passed to the gradle command:
|
||||
// ./gradlew -Psigning.keyId=yourid
|
||||
// or stored as key=value pairs in ~/.gradle/gradle.properties
|
||||
// You can also apply them in CI via environment variables. See Gradle's docs for details.
|
||||
signing {
|
||||
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
|
||||
sign configurations.archives
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar) {
|
||||
from sourceSets.main.allSource
|
||||
classifier = 'sources'
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives javadocJar, sourcesJar
|
||||
}
|
||||
|
||||
def pomConfig = {
|
||||
description project.description
|
||||
name 'OpenAPI-Generator Contributors'
|
||||
url 'https://openapi-generator.tech'
|
||||
organization {
|
||||
name 'org.openapitools'
|
||||
url 'https://github.com/OpenAPITools'
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name "The Apache Software License, Version 2.0"
|
||||
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
|
||||
distribution "repo"
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id "openapitools"
|
||||
name "OpenAPI-Generator Contributors"
|
||||
email "team@openapitools.org"
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url 'https://github.com/OpenAPITools/openapi-generator'
|
||||
connection 'scm:git:git://github.com/OpenAPITools/openapi-generator.git'
|
||||
developerConnection 'scm:git:ssh://git@github.com:OpenAPITools/openapi-generator.git'
|
||||
}
|
||||
issueManagement {
|
||||
system 'GitHub'
|
||||
url 'https://github.com/OpenAPITools/openapi-generator/issues'
|
||||
}
|
||||
}
|
||||
|
||||
uploadArchives {
|
||||
repositories {
|
||||
|
||||
// credentials here would need to be passed along with the gradle command:
|
||||
// ./gradlew -P ossrhUsername=yourUser
|
||||
// or stored in ~/.gradle/gradle.properties as key=value pairs
|
||||
mavenDeployer {
|
||||
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
|
||||
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
|
||||
authentication(userName: ossrhUsername, password: ossrhPassword)
|
||||
}
|
||||
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
|
||||
authentication(userName: ossrhUsername, password: ossrhPassword)
|
||||
}
|
||||
|
||||
pom.withXml {
|
||||
def root = asNode()
|
||||
root.appendNode('description', project.description)
|
||||
root.children().last() + pomConfig
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
@@ -86,4 +180,4 @@ compileTestKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,10 @@
|
||||
openApiGeneratorVersion=3.0.0
|
||||
openApiGeneratorVersion=3.0.1
|
||||
|
||||
# BEGIN placeholders
|
||||
# these are just placeholders to allow contributors to build directly
|
||||
ossrhUsername=user
|
||||
ossrhPassword=pass
|
||||
signing.keyId=unset
|
||||
signing.password=unset
|
||||
# signing.secretKeyRingFile=unset
|
||||
# END placeholders
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>openapi-generator-gradle-plugin</artifactId>
|
||||
<artifactId>openapi-generator-gradle-plugin-mvn-wrapper</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-gradle-plugin (maven wrapper)</name>
|
||||
<description>This is a maven wrapper to call gradle during installation phase</description>
|
||||
|
||||
<name>openapi-generator-gradle-plugin (gradle-plugin)</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -24,7 +26,17 @@
|
||||
<plugins>
|
||||
|
||||
<!-- NOTE: Consider this temporary, as a way to cleanly hook into our pipeline.
|
||||
We've discussed moving the entire project to gradle, which would avoid this fitting. -->
|
||||
We've discussed moving the entire project to gradle https://github.com/OpenAPITools/openapi-generator/issues/200, which would avoid this fitting. -->
|
||||
<!-- 1) disable maven install. This wrapper is not needed. (gradle will install a jar and a pom into the local maven repo) -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- 2) run gradle -->
|
||||
<plugin>
|
||||
<groupId>org.fortasoft</groupId>
|
||||
<artifactId>gradle-maven-plugin</artifactId>
|
||||
@@ -44,15 +56,24 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<!-- calls "clean build publishToMavenLocal" -->
|
||||
<!-- calls "clean assemble install" -->
|
||||
<task>clean</task>
|
||||
<task>build</task>
|
||||
<task>publishToMavenLocal</task>
|
||||
<task>assemble</task>
|
||||
<task>install</task>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- 3) disable maven deploy. This wrapper is not needed. -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
This example assumes you have Gradle 4.7+ installed. No gradle wrapper is provided in samples.
|
||||
|
||||
First, publish the openapi-generator-gradle-plugin locally via `sh gradlew build publishToMavenLocal` in the module directory.
|
||||
First, publish the openapi-generator-gradle-plugin locally via `./gradlew assemble install` in the module directory.
|
||||
|
||||
Then, run the following tasks in this example directory.
|
||||
|
||||
@@ -12,3 +12,9 @@ gradle openApiMeta
|
||||
gradle openApiValidate
|
||||
gradle buildGoSdk
|
||||
```
|
||||
|
||||
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
|
||||
|
||||
```bash
|
||||
gradle -PopenApiGeneratorVersion=3.0.1-SNAPSHOT openApiValidate
|
||||
```
|
||||
|
||||
@@ -5,9 +5,16 @@ buildscript {
|
||||
maven {
|
||||
url "https://plugins.gradle.org/m2/"
|
||||
}
|
||||
maven {
|
||||
url "https://oss.sonatype.org/content/repositories/releases/"
|
||||
}
|
||||
maven {
|
||||
url "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:3.0.0"
|
||||
// Updated version can be passed via command line arg as -PopenApiGeneratorVersion=VERSION
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:$openApiGeneratorVersion"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
openApiGeneratorVersion=3.0.1-SNAPSHOT
|
||||
@@ -11,7 +11,7 @@ Add to your `build->plugins` section (default phase is `generate-sources` phase)
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>2.4.0-SNAPSHOT</version>
|
||||
<version>3.0.1-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<version>3.0.1-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
|
||||
@@ -2,7 +2,7 @@ FROM openjdk:8-jre-alpine
|
||||
|
||||
WORKDIR /generator
|
||||
|
||||
COPY target/openapi-generator-online-3.0.0.jar /generator/openapi-generator-online.jar
|
||||
COPY target/openapi-generator-online-3.0.1.jar /generator/openapi-generator-online.jar
|
||||
|
||||
ENV GENERATOR_HOST=http://localhost
|
||||
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-online</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>openapi-generator-online</name>
|
||||
<version>3.0.0</version>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -160,7 +160,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.4</version>
|
||||
<version>3.0.1</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<debug>true</debug>
|
||||
@@ -243,11 +243,6 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -108,7 +109,7 @@ public class CliOption {
|
||||
* @param opt Option name
|
||||
* @param description Option description
|
||||
* @param defaultValue the default value to use if option not specified
|
||||
* @return
|
||||
* @return the CliOption created
|
||||
*/
|
||||
public static CliOption newBoolean(String opt, String description, boolean defaultValue) {
|
||||
return new CliOption(opt, description, SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(String.valueOf(defaultValue));
|
||||
|
||||
@@ -30,7 +30,7 @@ public class CodegenSecurity {
|
||||
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
|
||||
// ApiKey specific
|
||||
public String keyParamName;
|
||||
public Boolean isKeyInQuery, isKeyInHeader;
|
||||
public Boolean isKeyInQuery, isKeyInHeader, isKeyInCookie;
|
||||
// Oauth specific
|
||||
public String flow, authorizationUrl, tokenUrl;
|
||||
public List<Map<String, Object>> scopes;
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.google.common.base.CaseFormat;
|
||||
import com.samskivert.mustache.Mustache.Compiler;
|
||||
|
||||
import io.swagger.v3.core.util.Json;
|
||||
import io.swagger.v3.core.util.Yaml;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.headers.Header;
|
||||
@@ -47,6 +46,7 @@ import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.examples.ExampleGenerator;
|
||||
import org.openapitools.codegen.serializer.SerializerUtils;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -1535,36 +1535,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively look for a discriminator in the interface tree
|
||||
*
|
||||
* @param schema composed schema
|
||||
* @param allDefinitions all schema defintion
|
||||
* @return true if it's a discriminator
|
||||
*/
|
||||
private boolean isDiscriminatorInInterfaceTree(ComposedSchema schema, Map<String, Schema> allDefinitions) {
|
||||
if (schema == null || allDefinitions == null || allDefinitions.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (schema.getDiscriminator() != null) {
|
||||
return true;
|
||||
}
|
||||
final List<Schema> interfaces = getInterfaces(schema);
|
||||
if (interfaces == null) {
|
||||
return false;
|
||||
}
|
||||
for (Schema interfaceSchema : interfaces) {
|
||||
if (interfaceSchema.getDiscriminator() != null) {
|
||||
return true;
|
||||
}
|
||||
// TODO revise the logic below
|
||||
if (interfaceSchema instanceof ComposedSchema) {
|
||||
return isDiscriminatorInInterfaceTree((ComposedSchema) interfaceSchema, allDefinitions);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
addParentContainer(codegenModel, codegenModel.name, schema);
|
||||
}
|
||||
@@ -2801,12 +2771,13 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
cs.isApiKey = true;
|
||||
cs.keyParamName = securityScheme.getName();
|
||||
cs.isKeyInHeader = securityScheme.getIn() == SecurityScheme.In.HEADER;
|
||||
cs.isKeyInQuery = !cs.isKeyInHeader;
|
||||
cs.isKeyInQuery = securityScheme.getIn() == SecurityScheme.In.QUERY;
|
||||
cs.isKeyInCookie = securityScheme.getIn() == SecurityScheme.In.COOKIE; //it assumes a validation step prior to generation. (cookie-auth supported from OpenAPI 3.0.0)
|
||||
} else if (SecurityScheme.Type.HTTP.equals(securityScheme.getType())) {
|
||||
cs.isKeyInHeader = cs.isKeyInQuery = cs.isApiKey = cs.isOAuth = false;
|
||||
cs.isKeyInHeader = cs.isKeyInQuery = cs.isKeyInCookie = cs.isApiKey = cs.isOAuth = false;
|
||||
cs.isBasic = true;
|
||||
} else if (SecurityScheme.Type.OAUTH2.equals(securityScheme.getType())) {
|
||||
cs.isKeyInHeader = cs.isKeyInQuery = cs.isApiKey = cs.isBasic = false;
|
||||
cs.isKeyInHeader = cs.isKeyInQuery = cs.isKeyInCookie = cs.isApiKey = cs.isBasic = false;
|
||||
cs.isOAuth = true;
|
||||
final OAuthFlows flows = securityScheme.getFlows();
|
||||
if (securityScheme.getFlows() == null) {
|
||||
@@ -2958,20 +2929,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return objs;
|
||||
}
|
||||
|
||||
private static Map<String, Object> addHasMore(Map<String, Object> objs) {
|
||||
if (objs != null) {
|
||||
for (int i = 0; i < objs.size() - 1; i++) {
|
||||
if (i > 0) {
|
||||
objs.put("secondaryParam", true);
|
||||
}
|
||||
if (i < objs.size() - 1) {
|
||||
objs.put("hasMore", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add operation to group
|
||||
*
|
||||
@@ -3989,19 +3946,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return produces;
|
||||
}
|
||||
|
||||
protected Schema detectParent(ComposedSchema composedSchema, Map<String, Schema> allSchemas) {
|
||||
if (composedSchema.getAllOf() != null && !composedSchema.getAllOf().isEmpty()) {
|
||||
Schema schema = composedSchema.getAllOf().get(0);
|
||||
String ref = schema.get$ref();
|
||||
if (StringUtils.isBlank(ref)) {
|
||||
return null;
|
||||
}
|
||||
ref = ModelUtils.getSimpleRef(ref);
|
||||
return allSchemas.get(ref);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getParentName(ComposedSchema composedSchema, Map<String, Schema> allSchemas) {
|
||||
if (composedSchema.getAllOf() != null && !composedSchema.getAllOf().isEmpty()) {
|
||||
Schema schema = composedSchema.getAllOf().get(0);
|
||||
@@ -4033,12 +3977,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO do we still need the methdo below?
|
||||
protected static boolean hasSchemaProperties(Schema schema) {
|
||||
final Object additionalProperties = schema.getAdditionalProperties();
|
||||
return additionalProperties != null && additionalProperties instanceof Schema;
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
return null;
|
||||
}
|
||||
@@ -4362,10 +4300,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return codegenParameter;
|
||||
}
|
||||
|
||||
protected void addOption(String key, String description) {
|
||||
addOption(key, description, null);
|
||||
}
|
||||
|
||||
protected void addOption(String key, String description, String defaultValue) {
|
||||
CliOption option = new CliOption(key, description);
|
||||
if (defaultValue != null)
|
||||
@@ -4403,12 +4337,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*/
|
||||
public void generateYAMLSpecFile(Map<String, Object> objs) {
|
||||
OpenAPI openAPI = (OpenAPI) objs.get("openAPI");
|
||||
if (openAPI != null) {
|
||||
try {
|
||||
objs.put("openapi-yaml", Yaml.mapper().writeValueAsString(openAPI));
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
String yaml = SerializerUtils.toYamlString(openAPI);
|
||||
if(yaml != null) {
|
||||
objs.put("openapi-yaml", yaml);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class CodegenConfigurator implements Serializable {
|
||||
nameMigrationMap.put("scala", new ScalaHttpClientCodegen().getName());
|
||||
nameMigrationMap.put("jaxrs", new JavaJerseyServerCodegen().getName());
|
||||
nameMigrationMap.put("qt5cpp", new CppQt5ClientCodegen().getName());
|
||||
nameMigrationMap.put("cpprest", new CppRestClientCodegen().getName());
|
||||
nameMigrationMap.put("cpprest", new CppRestSdkClientCodegen().getName());
|
||||
nameMigrationMap.put("tizen", new CppTizenClientCodegen().getName());
|
||||
nameMigrationMap.put("sinatra", new RubySinatraServerCodegen().getName());
|
||||
nameMigrationMap.put("swift", new SwiftClientCodegen().getName());
|
||||
|
||||
@@ -51,9 +51,9 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
protected String packageName = "defaultPackage";
|
||||
protected String projectName = "defaultProject";
|
||||
protected List<Map<String, Object>> orderedModels;
|
||||
protected Map<String, List<String>> modelDepends;
|
||||
protected Map<String, String> nullableTypeMapping;
|
||||
protected HashMap<String, String> operationsScopes;
|
||||
protected final Map<String, List<String>> modelDepends;
|
||||
protected final Map<String, String> nullableTypeMapping;
|
||||
protected final HashMap<String, String> operationsScopes;
|
||||
protected int scopeIndex = 0;
|
||||
|
||||
public AbstractAdaCodegen() {
|
||||
@@ -153,14 +153,15 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
typeMapping.put("file", "Swagger.Http_Content_Type");
|
||||
typeMapping.put("binary", "Swagger.Binary");
|
||||
|
||||
// Mapping to convert an Ada required type to an optional type (nullable).
|
||||
nullableTypeMapping = new HashMap<String, String>();
|
||||
nullableTypeMapping.put("date", "Swagger.Nullable_Date");
|
||||
nullableTypeMapping.put("DateTime", "Swagger.Nullable_Date");
|
||||
nullableTypeMapping.put("string", "Swagger.Nullable_UString");
|
||||
nullableTypeMapping.put("integer", "Swagger.Nullable_Integer");
|
||||
nullableTypeMapping.put("long", "Swagger.Nullable_Long");
|
||||
nullableTypeMapping.put("boolean", "Swagger.Nullable_Boolean");
|
||||
nullableTypeMapping.put("object", "Swagger.Object");
|
||||
nullableTypeMapping.put("Swagger.Date", "Swagger.Nullable_Date");
|
||||
nullableTypeMapping.put("Swagger.Datetime", "Swagger.Nullable_Date");
|
||||
nullableTypeMapping.put("Swagger.UString", "Swagger.Nullable_UString");
|
||||
nullableTypeMapping.put("Integer", "Swagger.Nullable_Integer");
|
||||
nullableTypeMapping.put("Swagger.Long", "Swagger.Nullable_Long");
|
||||
nullableTypeMapping.put("Boolean", "Swagger.Nullable_Boolean");
|
||||
nullableTypeMapping.put("Swagger.Object", "Swagger.Object");
|
||||
|
||||
modelDepends = new HashMap<String, List<String>>();
|
||||
orderedModels = new ArrayList<Map<String, Object>>();
|
||||
@@ -336,13 +337,8 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
return "Swagger." + name;
|
||||
}
|
||||
}
|
||||
// TODO need to revise/test the logic below to check "required"
|
||||
if (typeMapping.containsKey(schemaType)) {
|
||||
if (p.getRequired() != null && p.getRequired().contains(p.getName())) {
|
||||
return typeMapping.get(schemaType);
|
||||
} else {
|
||||
return nullableTypeMapping.get(schemaType);
|
||||
}
|
||||
return typeMapping.get(schemaType);
|
||||
}
|
||||
// LOGGER.info("Swagger type " + schemaType);
|
||||
if (languageSpecificPrimitives.contains(schemaType)) {
|
||||
@@ -443,6 +439,10 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
if (p.isFormParam && p.isFile) {
|
||||
p.dataType = "Swagger.File_Part_Type";
|
||||
}
|
||||
// Convert optional parameters to use the Nullable_<T> type.
|
||||
if (!p.required && nullableTypeMapping.containsKey(p.dataType)) {
|
||||
p.dataType = nullableTypeMapping.get(p.dataType);
|
||||
}
|
||||
}
|
||||
for (CodegenParameter p : op1.formParams) {
|
||||
if (p.isFile) {
|
||||
@@ -471,7 +471,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
if (last < 0) {
|
||||
break;
|
||||
}
|
||||
if (path.substring(pos, last - 1) == p.baseName) {
|
||||
if (path.substring(pos, last - 1).equals(p.baseName)) {
|
||||
break;
|
||||
}
|
||||
pos = last + 1;
|
||||
@@ -505,6 +505,11 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
isModel = true;
|
||||
}
|
||||
p.vendorExtensions.put("x-is-model-type", isModel);
|
||||
|
||||
// Convert optional members to use the Nullable_<T> type.
|
||||
if (!p.required && nullableTypeMapping.containsKey(p.dataType)) {
|
||||
p.dataType = nullableTypeMapping.get(p.dataType);
|
||||
}
|
||||
}
|
||||
// let us work with fully qualified names only
|
||||
modelDepends.put(modelPackage + ".Models." + m.classname, d);
|
||||
@@ -518,7 +523,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
// cycle over orderedModels
|
||||
// if I find a model that has no dependencies, or all of its dependencies are in revisedOrderedModels, consider it the independentModel
|
||||
// put the independentModel at the end of revisedOrderedModels, and remove it from orderedModels
|
||||
//
|
||||
//
|
||||
List<Map<String, Object>> revisedOrderedModels = new ArrayList<Map<String, Object>>();
|
||||
List<String> collectedModelNames = new ArrayList<String>();
|
||||
int sizeOrderedModels = orderedModels.size();
|
||||
|
||||
@@ -442,4 +442,9 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
public void setOptionalProjectFileFlag(boolean flag) {
|
||||
this.optionalProjectFileFlag = flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(String str) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class CppRestClientCodegen extends AbstractCppCodegen {
|
||||
public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
|
||||
public static final String DECLSPEC = "declspec";
|
||||
public static final String DEFAULT_INCLUDE = "defaultInclude";
|
||||
@@ -87,7 +87,7 @@ public class CppRestClientCodegen extends AbstractCppCodegen {
|
||||
return "Generates a C++ API client with C++ REST SDK (https://github.com/Microsoft/cpprestsdk).";
|
||||
}
|
||||
|
||||
public CppRestClientCodegen() {
|
||||
public CppRestSdkClientCodegen() {
|
||||
super();
|
||||
|
||||
apiPackage = "org.openapitools.client.api";
|
||||
@@ -178,7 +178,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
generateJSONSpecFile(objs);
|
||||
generateYAMLSpecFile(objs);
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ 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.tuple.Pair;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
@@ -41,12 +42,9 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SpringCodegen extends AbstractJavaCodegen
|
||||
implements BeanValidationFeatures, OptionalFeatures {
|
||||
@@ -69,6 +67,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
public static final String SPRING_CLOUD_LIBRARY = "spring-cloud";
|
||||
public static final String IMPLICIT_HEADERS = "implicitHeaders";
|
||||
public static final String OPENAPI_DOCKET_CONFIG = "swaggerDocketConfig";
|
||||
public static final String API_FIRST = "apiFirst";
|
||||
|
||||
protected String title = "OpenAPI Spring";
|
||||
protected String configPackage = "org.openapitools.configuration";
|
||||
@@ -85,6 +84,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
protected boolean useBeanValidation = true;
|
||||
protected boolean implicitHeaders = false;
|
||||
protected boolean openapiDocketConfig = false;
|
||||
protected boolean apiFirst = false;
|
||||
protected boolean useOptional = false;
|
||||
|
||||
public SpringCodegen() {
|
||||
@@ -103,18 +103,19 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
cliOptions.add(new CliOption(TITLE, "server title name or client service name"));
|
||||
cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code"));
|
||||
cliOptions.add(new CliOption(BASE_PACKAGE, "base package (invokerPackage) for generated code"));
|
||||
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));
|
||||
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(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));
|
||||
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)"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames",useTags));
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations",useBeanValidation));
|
||||
cliOptions.add(CliOption.newBoolean(IMPLICIT_HEADERS, "Use of @ApiImplicitParams for headers.",implicitHeaders));
|
||||
cliOptions.add(CliOption.newBoolean(OPENAPI_DOCKET_CONFIG, "Generate Spring OpenAPI Docket configuration class.",openapiDocketConfig));
|
||||
cliOptions.add(CliOption.newBoolean(USE_OPTIONAL,"Use Optional container for optional parameters",useOptional));
|
||||
cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames", useTags));
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations", useBeanValidation));
|
||||
cliOptions.add(CliOption.newBoolean(IMPLICIT_HEADERS, "Use of @ApiImplicitParams for headers.", implicitHeaders));
|
||||
cliOptions.add(CliOption.newBoolean(OPENAPI_DOCKET_CONFIG, "Generate Spring OpenAPI Docket configuration class.", openapiDocketConfig));
|
||||
cliOptions.add(CliOption.newBoolean(API_FIRST, "Generate the API from the OAI spec at server compile time (API first approach)", apiFirst));
|
||||
cliOptions.add(CliOption.newBoolean(USE_OPTIONAL,"Use Optional container for optional parameters", useOptional));
|
||||
|
||||
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.");
|
||||
@@ -145,9 +146,19 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
@Override
|
||||
public void processOpts() {
|
||||
|
||||
List<Pair<String,String>> configOptions = additionalProperties.entrySet().stream()
|
||||
.filter(e -> !Arrays.asList(API_FIRST, "hideGenerationTimestamp").contains(e.getKey()))
|
||||
.filter(e -> cliOptions.stream().map(CliOption::getOpt).anyMatch(opt -> opt.equals(e.getKey())))
|
||||
.map(e -> Pair.of(e.getKey(), e.getValue().toString()))
|
||||
.collect(Collectors.toList());
|
||||
additionalProperties.put("configOptions", configOptions);
|
||||
|
||||
// Process java8 option before common java ones to change the default dateLibrary to java8.
|
||||
System.out.println("----------------------------------");
|
||||
if (additionalProperties.containsKey(JAVA_8)) {
|
||||
System.out.println("has JAVA8");
|
||||
this.setJava8(Boolean.valueOf(additionalProperties.get(JAVA_8).toString()));
|
||||
additionalProperties.put(JAVA_8, java8);
|
||||
}
|
||||
if (this.java8 && !additionalProperties.containsKey(DATE_LIBRARY)) {
|
||||
setDateLibrary("java8");
|
||||
@@ -232,6 +243,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.setOpenapiDocketConfig(Boolean.valueOf(additionalProperties.get(OPENAPI_DOCKET_CONFIG).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(API_FIRST)) {
|
||||
this.setApiFirst(Boolean.valueOf(additionalProperties.get(API_FIRST).toString()));
|
||||
}
|
||||
|
||||
typeMapping.put("file", "Resource");
|
||||
importMapping.put("Resource", "org.springframework.core.io.Resource");
|
||||
|
||||
@@ -255,16 +270,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
|
||||
if (!this.interfaceOnly) {
|
||||
if (library.equals(SPRING_BOOT)) {
|
||||
if (!this.reactive) {
|
||||
supportingFiles.add(new SupportingFile("homeController.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
|
||||
}
|
||||
supportingFiles.add(new SupportingFile("openapi2SpringBoot.mustache",
|
||||
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), "OpenAPI2SpringBoot.java"));
|
||||
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache",
|
||||
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), "RFC3339DateFormat.java"));
|
||||
supportingFiles.add(new SupportingFile("application.mustache",
|
||||
("src.main.resources").replace(".", java.io.File.separator), "application.properties"));
|
||||
}
|
||||
if (library.equals(SPRING_MVC_LIBRARY)) {
|
||||
supportingFiles.add(new SupportingFile("webApplication.mustache",
|
||||
@@ -275,8 +284,6 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "OpenAPIUiConfiguration.java"));
|
||||
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "RFC3339DateFormat.java"));
|
||||
supportingFiles.add(new SupportingFile("application.properties",
|
||||
("src.main.resources").replace(".", java.io.File.separator), "openapi.properties"));
|
||||
}
|
||||
if (library.equals(SPRING_CLOUD_LIBRARY)) {
|
||||
supportingFiles.add(new SupportingFile("apiKeyRequestInterceptor.mustache",
|
||||
@@ -290,20 +297,19 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
} else {
|
||||
apiTemplateFiles.put("apiController.mustache", "Controller.java");
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("apiResponseMessage.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiResponseMessage.java"));
|
||||
supportingFiles.add(new SupportingFile("notFoundException.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "NotFoundException.java"));
|
||||
if (!this.reactive) {
|
||||
supportingFiles.add(new SupportingFile("apiOriginFilter.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiOriginFilter.java"));
|
||||
supportingFiles.add(new SupportingFile("application.mustache",
|
||||
("src.main.resources").replace(".", java.io.File.separator), "application.properties"));
|
||||
supportingFiles.add(new SupportingFile("homeController.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
|
||||
if (!this.reactive && !this.apiFirst) {
|
||||
supportingFiles.add(new SupportingFile("openapiDocumentationConfig.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "OpenAPIDocumentationConfig.java"));
|
||||
} else {
|
||||
supportingFiles.add(new SupportingFile("openapi.mustache",
|
||||
("src/main/resources").replace("/", java.io.File.separator), "openapi.yaml"));
|
||||
}
|
||||
}
|
||||
} else if (this.openapiDocketConfig && !library.equals(SPRING_CLOUD_LIBRARY) && !this.reactive) {
|
||||
} else if (this.openapiDocketConfig && !library.equals(SPRING_CLOUD_LIBRARY) && !this.reactive && !this.apiFirst) {
|
||||
supportingFiles.add(new SupportingFile("openapiDocumentationConfig.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "OpenAPIDocumentationConfig.java"));
|
||||
}
|
||||
@@ -313,6 +319,11 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiUtil.java"));
|
||||
}
|
||||
|
||||
if (this.apiFirst) {
|
||||
apiTemplateFiles.clear();
|
||||
modelTemplateFiles.clear();
|
||||
}
|
||||
|
||||
if ("threetenbp".equals(dateLibrary)) {
|
||||
supportingFiles.add(new SupportingFile("customInstantDeserializer.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "CustomInstantDeserializer.java"));
|
||||
@@ -344,6 +355,11 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
additionalProperties.put(RESPONSE_WRAPPER, "Callable");
|
||||
}
|
||||
|
||||
if(!this.apiFirst && !this.reactive) {
|
||||
additionalProperties.put("useSpringfox", true);
|
||||
}
|
||||
|
||||
|
||||
// Some well-known Spring or Spring-Cloud response wrappers
|
||||
switch (this.responseWrapper) {
|
||||
case "Future":
|
||||
@@ -565,6 +581,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
generateYAMLSpecFile(objs);
|
||||
if(library.equals(SPRING_CLOUD_LIBRARY)) {
|
||||
List<CodegenSecurity> authMethods = (List<CodegenSecurity>) objs.get("authMethods");
|
||||
if (authMethods != null) {
|
||||
@@ -659,6 +676,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.openapiDocketConfig = openapiDocketConfig;
|
||||
}
|
||||
|
||||
public void setApiFirst(boolean apiFirst) {
|
||||
this.apiFirst = apiFirst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.openapitools.codegen.serializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class OpenAPISerializer extends JsonSerializer<OpenAPI> {
|
||||
|
||||
@Override
|
||||
public void serialize(OpenAPI value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
if (value != null) {
|
||||
gen.writeStartObject();
|
||||
gen.writeStringField("openapi", value.getOpenapi());
|
||||
if(value.getInfo() != null) {
|
||||
gen.writeObjectField("info", value.getInfo());
|
||||
}
|
||||
if(value.getExternalDocs() != null) {
|
||||
gen.writeObjectField("externalDocs", value.getExternalDocs());
|
||||
}
|
||||
if(value.getServers() != null) {
|
||||
gen.writeObjectField("servers", value.getServers());
|
||||
}
|
||||
if(value.getSecurity() != null) {
|
||||
gen.writeObjectField("security", value.getSecurity());
|
||||
}
|
||||
if(value.getTags() != null) {
|
||||
gen.writeObjectField("tags", value.getTags());
|
||||
}
|
||||
if(value.getPaths() != null) {
|
||||
gen.writeObjectField("paths", value.getPaths());
|
||||
}
|
||||
if(value.getComponents() != null) {
|
||||
gen.writeObjectField("components", value.getComponents());
|
||||
}
|
||||
if(value.getExtensions() != null) {
|
||||
for (Entry<String, Object> e : value.getExtensions().entrySet()) {
|
||||
gen.writeObjectField(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
gen.writeEndObject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.openapitools.codegen.serializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
|
||||
import io.swagger.v3.core.util.Yaml;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SerializerUtils {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SerializerUtils.class);
|
||||
|
||||
public static String toYamlString(OpenAPI openAPI) {
|
||||
if(openAPI == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SimpleModule module = new SimpleModule("OpenAPIModule");
|
||||
module.addSerializer(OpenAPI.class, new OpenAPISerializer());
|
||||
try {
|
||||
return Yaml.mapper()
|
||||
.registerModule(module)
|
||||
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
|
||||
.writeValueAsString(openAPI)
|
||||
.replace("\r\n", "\n");
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.warn("Can not create yaml content", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -159,6 +159,7 @@ public class ModelUtils {
|
||||
*/
|
||||
private static void visitOpenAPI(OpenAPI openAPI, OpenAPISchemaVisitor visitor) {
|
||||
Map<String, PathItem> paths = openAPI.getPaths();
|
||||
List<String> visitedSchemas = new ArrayList<>();
|
||||
|
||||
if (paths != null) {
|
||||
for (PathItem path : paths.values()) {
|
||||
@@ -170,7 +171,7 @@ public class ModelUtils {
|
||||
for (Parameter p : operation.getParameters()) {
|
||||
Parameter parameter = getReferencedParameter(openAPI, p);
|
||||
if (parameter.getSchema() != null) {
|
||||
visitor.visit(parameter.getSchema(), null);
|
||||
visitSchema(openAPI, parameter.getSchema(), null, visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,7 +181,7 @@ public class ModelUtils {
|
||||
if (requestBody != null && requestBody.getContent() != null) {
|
||||
for (Entry<String, MediaType> e : requestBody.getContent().entrySet()) {
|
||||
if (e.getValue().getSchema() != null) {
|
||||
visitor.visit(e.getValue().getSchema(), e.getKey());
|
||||
visitSchema(openAPI, e.getValue().getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,7 +193,7 @@ public class ModelUtils {
|
||||
if (apiResponse != null && apiResponse.getContent() != null) {
|
||||
for (Entry<String, MediaType> e : apiResponse.getContent().entrySet()) {
|
||||
if (e.getValue().getSchema() != null) {
|
||||
visitor.visit(e.getValue().getSchema(), e.getKey());
|
||||
visitSchema(openAPI, e.getValue().getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,6 +205,59 @@ public class ModelUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static void visitSchema(OpenAPI openAPI, Schema schema, String mimeType, List<String> visitedSchemas, OpenAPISchemaVisitor visitor) {
|
||||
visitor.visit(schema, mimeType);
|
||||
if(schema.get$ref() != null) {
|
||||
String ref = getSimpleRef(schema.get$ref());
|
||||
if(!visitedSchemas.contains(ref)) {
|
||||
visitedSchemas.add(ref);
|
||||
Schema referencedSchema = getSchemas(openAPI).get(ref);
|
||||
if(referencedSchema != null) {
|
||||
visitSchema(openAPI, referencedSchema, mimeType, visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(schema instanceof ComposedSchema) {
|
||||
List<Schema> oneOf = ((ComposedSchema) schema).getOneOf();
|
||||
if(oneOf != null) {
|
||||
for (Schema s : oneOf) {
|
||||
visitSchema(openAPI, s, mimeType, visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
List<Schema> allOf = ((ComposedSchema) schema).getAllOf();
|
||||
if(allOf != null) {
|
||||
for (Schema s : allOf) {
|
||||
visitSchema(openAPI, s, mimeType, visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
List<Schema> anyOf = ((ComposedSchema) schema).getAnyOf();
|
||||
if(anyOf != null) {
|
||||
for (Schema s : anyOf) {
|
||||
visitSchema(openAPI, s, mimeType, visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
} else if(schema instanceof ArraySchema) {
|
||||
Schema itemsSchema = ((ArraySchema) schema).getItems();
|
||||
if(itemsSchema != null) {
|
||||
visitSchema(openAPI, itemsSchema, mimeType, visitedSchemas, visitor);
|
||||
}
|
||||
} else if(isMapSchema(schema)) {
|
||||
Object additionalProperties = schema.getAdditionalProperties();
|
||||
if(additionalProperties instanceof Schema) {
|
||||
visitSchema(openAPI, (Schema) additionalProperties, mimeType, visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
if(schema.getNot() != null) {
|
||||
visitSchema(openAPI, schema.getNot(), mimeType, visitedSchemas, visitor);
|
||||
}
|
||||
Map<String, Schema> properties = schema.getProperties();
|
||||
if(properties != null) {
|
||||
for (Schema property : properties.values()) {
|
||||
visitSchema(openAPI, property, mimeType, visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private static interface OpenAPISchemaVisitor {
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ public class {{classname}} {
|
||||
@Deprecated
|
||||
{{/isDeprecated}}
|
||||
public ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{operationId}}WithHttpInfo({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}new Object(){{/bodyParam}};
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) {
|
||||
|
||||
@@ -82,7 +82,7 @@ public class {{classname}} {
|
||||
@Deprecated
|
||||
{{/isDeprecated}}
|
||||
public com.squareup.okhttp.Call {{operationId}}Call({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}new Object(){{/bodyParam}};
|
||||
|
||||
// create path and map variables
|
||||
String {{localVariablePrefix}}localVarPath = "{{{path}}}"{{#pathParams}}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class {{classname}} {
|
||||
@Deprecated
|
||||
{{/isDeprecated}}
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}new Object(){{/bodyParam}};
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) {
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
@@ -527,6 +528,18 @@ public class ApiClient {
|
||||
|
||||
final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath).path(path);
|
||||
if (queryParams != null) {
|
||||
//encode the query parameters in case they contain unsafe characters
|
||||
for (List<String> values : queryParams.values()) {
|
||||
if (values != null) {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
try {
|
||||
values.set(i, URLEncoder.encode(values.get(i), "utf8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
builder.queryParams(queryParams);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class {{classname}} {
|
||||
{{/externalDocs}}
|
||||
*/
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws RestClientException {
|
||||
Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}new Object(){{/bodyParam}};
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) {
|
||||
|
||||
@@ -5,12 +5,12 @@ import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DateTimeUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.Function;
|
||||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.DateTimeUtils;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
@@ -205,7 +205,7 @@ public class CustomInstantDeserializer<T extends Temporal>
|
||||
|
||||
private ZoneId getZone(DeserializationContext context) {
|
||||
// Instants are always in UTC, so don't waste compute cycles
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.timeZoneToZoneId(context.getTimeZone());
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.toZoneId(context.getTimeZone());
|
||||
}
|
||||
|
||||
private static class FromIntegerArguments {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package {{configPackage}};
|
||||
|
||||
{{^useSpringfox}}
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.Resource;
|
||||
{{/useSpringfox}}
|
||||
import org.springframework.stereotype.Controller;
|
||||
{{^useSpringfox}}
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
{{/useSpringfox}}
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
{{^useSpringfox}}
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
{{/useSpringfox}}
|
||||
{{#reactive}}
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
{{/reactive}}
|
||||
|
||||
{{^useSpringfox}}
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
{{/useSpringfox}}
|
||||
{{#reactive}}
|
||||
import java.net.URI;
|
||||
{{/reactive}}
|
||||
{{^useSpringfox}}
|
||||
import java.nio.charset.Charset;
|
||||
{{/useSpringfox}}
|
||||
{{#reactive}}
|
||||
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
{{/reactive}}
|
||||
|
||||
/**
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
|
||||
{{^useSpringfox}}
|
||||
private static YAMLMapper yamlMapper = new YAMLMapper();
|
||||
|
||||
@Value("classpath:/openapi.yaml")
|
||||
private Resource openapi;
|
||||
|
||||
@Bean
|
||||
public String openapiContent() throws IOException {
|
||||
try(InputStream is = openapi.getInputStream()) {
|
||||
return StreamUtils.copyToString(is, Charset.defaultCharset());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/openapi.yaml", produces = "application/vnd.oai.openapi")
|
||||
@ResponseBody
|
||||
public String openapiYaml() throws IOException {
|
||||
return openapiContent();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/openapi.json", produces = "application/json")
|
||||
@ResponseBody
|
||||
public Object openapiJson() throws IOException {
|
||||
return yamlMapper.readValue(openapiContent(), Object.class);
|
||||
}
|
||||
|
||||
{{/useSpringfox}}
|
||||
{{#reactive}}
|
||||
@Bean
|
||||
RouterFunction<ServerResponse> index() {
|
||||
return route(
|
||||
GET("/"),
|
||||
req -> ServerResponse.temporaryRedirect(URI.create("{{#useSpringfox}}swagger-ui.html{{/useSpringfox}}{{^useSpringfox}}swagger-ui/index.html?url=../openapi.json{{/useSpringfox}}")).build()
|
||||
);
|
||||
}
|
||||
{{/reactive}}
|
||||
{{^reactive}}
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "redirect:{{#useSpringfox}}swagger-ui.html{{/useSpringfox}}{{^useSpringfox}}swagger-ui/index.html?url=../openapi.json{{/useSpringfox}}";
|
||||
}
|
||||
{{/reactive}}
|
||||
|
||||
|
||||
}
|
||||
@@ -8,13 +8,15 @@ This server was generated by the [OpenAPI Generator](https://openapi-generator.t
|
||||
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
|
||||
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.
|
||||
|
||||
{{#useSpringfox}}
|
||||
The underlying library integrating OpenAPI to SpringBoot is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
{{/useSpringfox}}
|
||||
Start your server as an simple java application
|
||||
|
||||
{{^reactive}}
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
http://localhost:{{serverPort}}/
|
||||
|
||||
{{/reactive}}
|
||||
Change default port value in application.properties{{/interfaceOnly}}{{#interfaceOnly}}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
{{#useSpringfox}}
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
{{/useSpringfox}}
|
||||
server.port={{serverPort}}
|
||||
spring.jackson.date-format={{basePackage}}.RFC3339DateFormat
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||
@@ -4,10 +4,28 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
{{^reactive}}
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
{{^useSpringfox}}
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
{{/useSpringfox}}
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
{{^java8}}
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
{{/java8}}
|
||||
{{/reactive}}
|
||||
{{#reactive}}
|
||||
import org.springframework.web.reactive.config.CorsRegistry;
|
||||
{{^useSpringfox}}
|
||||
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
|
||||
{{/useSpringfox}}
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||
{{/reactive}}
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = { "{{basePackage}}", "{{apiPackage}}" , "{{configPackage}}"})
|
||||
@ComponentScan(basePackages = {"{{basePackage}}", "{{apiPackage}}" , "{{configPackage}}"})
|
||||
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
@@ -30,4 +48,25 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Web{{^reactive}}Mvc{{/reactive}}{{#reactive}}Flux{{/reactive}}Configurer webConfigurer() {
|
||||
return new Web{{^reactive}}Mvc{{/reactive}}{{#reactive}}Flux{{/reactive}}Configurer{{^java8}}Adapter{{/java8}}() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
{{^useSpringfox}}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.14.2/");
|
||||
}
|
||||
{{/useSpringfox}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
{{^reactive}}
|
||||
{{#useSpringfox}}
|
||||
<springfox-version>2.8.0</springfox-version>
|
||||
{{/reactive}}
|
||||
{{/useSpringfox}}
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -33,6 +33,38 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
{{#apiFirst}}
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>{{{generatorVersion}}}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<inputSpec>src/main/resources/openapi.yaml</inputSpec>
|
||||
<generatorName>spring</generatorName>
|
||||
<apiPackage>{{{apiPackage}}}</apiPackage>
|
||||
<modelPackage>{{{modelPackage}}}</modelPackage>
|
||||
<generateSupportingFiles>false</generateSupportingFiles>
|
||||
{{#modelNamePrefix}}
|
||||
<modelNamePrefix>{{{.}}}</modelNamePrefix>
|
||||
{{/modelNamePrefix}}
|
||||
{{#modelNameSuffix}}
|
||||
<modelNameSuffix>{{{.}}}</modelNameSuffix>
|
||||
{{/modelNameSuffix}}
|
||||
<configOptions>
|
||||
{{#configOptions}}
|
||||
<{{left}}>{{right}}</{{left}}>
|
||||
{{/configOptions}}
|
||||
</configOptions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
{{/apiFirst}}
|
||||
</plugins>
|
||||
{{/interfaceOnly}}
|
||||
</build>
|
||||
@@ -41,7 +73,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web{{#reactive}}flux{{/reactive}}</artifactId>
|
||||
</dependency>
|
||||
{{^reactive}}
|
||||
{{#useSpringfox}}
|
||||
<!--SpringFox dependencies -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
@@ -53,43 +85,47 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
{{/reactive}}
|
||||
{{#reactive}}
|
||||
{{/useSpringfox}}
|
||||
{{^useSpringfox}}
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>3.14.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.5.14</version>
|
||||
</dependency>
|
||||
{{/reactive}}
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
</dependency>
|
||||
{{/useSpringfox}}
|
||||
{{#withXml}}
|
||||
|
||||
<!-- XML processing: Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
|
||||
{{/withXml}}
|
||||
{{#java8}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
{{#joda}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
</dependency>
|
||||
{{/joda}}
|
||||
{{#threetenbp}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
<version>2.6.4</version>
|
||||
<version>2.8.4</version>
|
||||
</dependency>
|
||||
{{/threetenbp}}
|
||||
{{#useBeanValidation}}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package {{configPackage}};
|
||||
|
||||
import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZonedDateTime;
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(ThreeTenModule.class)
|
||||
ThreeTenModule threeTenModule() {
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
return module;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@ Spring MVC Server
|
||||
## 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. This is an example of building a OpenAPI-enabled server in Java using the Spring MVC framework.
|
||||
|
||||
{{#useSpringfox}}
|
||||
The underlying library integrating OpenAPI to Spring-MVC is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
{{/useSpringfox}}
|
||||
You can view the server in swagger-ui by pointing to
|
||||
http://localhost:{{serverPort}}{{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}/swagger-ui.html
|
||||
http://localhost:{{serverPort}}{{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}/
|
||||
@@ -0,0 +1,3 @@
|
||||
{{#useSpringfox}}
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
{{/useSpringfox}}
|
||||
@@ -8,9 +8,12 @@ import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
{{#useSpringfox}}
|
||||
import org.springframework.context.annotation.Import;
|
||||
{{/useSpringfox}}
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
@@ -26,10 +29,12 @@ import java.util.List;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "{{apiPackage}}")
|
||||
@ComponentScan(basePackages = {"{{apiPackage}}", "{{configPackage}}"})
|
||||
@EnableWebMvc
|
||||
@PropertySource("classpath:openapi.properties")
|
||||
@PropertySource("classpath:application.properties")
|
||||
{{#useSpringfox}}
|
||||
@Import(OpenAPIDocumentationConfig.class)
|
||||
{{/useSpringfox}}
|
||||
public class OpenAPIUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
|
||||
|
||||
@@ -63,20 +68,42 @@ public class OpenAPIUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
if (!registry.hasMappingForPattern("/**")) {
|
||||
registry.addResourceHandler("/**").addResourceLocations(RESOURCE_LOCATIONS);
|
||||
}
|
||||
{{^useSpringfox}}
|
||||
if (!registry.hasMappingForPattern("/swagger-ui/**")) {
|
||||
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.14.2/");
|
||||
}
|
||||
{{/useSpringfox}}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilder builder() {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
|
||||
{{#threetenbp}}
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
{{/threetenbp}}
|
||||
return new Jackson2ObjectMapperBuilder()
|
||||
.indentOutput(true)
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
{{#threetenbp}}
|
||||
.modulesToInstall(module)
|
||||
{{/threetenbp}}
|
||||
.dateFormat(new RFC3339DateFormat());
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
||||
converters.add(new StringHttpMessageConverter());
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,39 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
{{#apiFirst}}
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>{{{generatorVersion}}}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<inputSpec>src/main/resources/openapi.yaml</inputSpec>
|
||||
<generatorName>spring</generatorName>
|
||||
<library>spring-mvc</library>
|
||||
<apiPackage>{{{apiPackage}}}</apiPackage>
|
||||
<modelPackage>{{{modelPackage}}}</modelPackage>
|
||||
<generateSupportingFiles>false</generateSupportingFiles>
|
||||
{{#modelNamePrefix}}
|
||||
<modelNamePrefix>{{{.}}}</modelNamePrefix>
|
||||
{{/modelNamePrefix}}
|
||||
{{#modelNameSuffix}}
|
||||
<modelNameSuffix>{{{.}}}</modelNameSuffix>
|
||||
{{/modelNameSuffix}}
|
||||
<configOptions>
|
||||
{{#configOptions}}
|
||||
<{{left}}>{{right}}</{{left}}>
|
||||
{{/configOptions}}
|
||||
</configOptions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
{{/apiFirst}}
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
@@ -96,7 +129,7 @@
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
|
||||
{{#useSpringfox}}
|
||||
<!--SpringFox dependencies-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
@@ -114,18 +147,33 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
{{/useSpringfox}}
|
||||
{{^useSpringfox}}
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>3.14.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.5.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
{{/useSpringfox}}
|
||||
{{#withXml}}
|
||||
|
||||
<!-- XML processing: Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
|
||||
{{/withXml}}
|
||||
{{#java8}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
@@ -133,7 +181,6 @@
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
{{#joda}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
@@ -141,7 +188,6 @@
|
||||
</dependency>
|
||||
{{/joda}}
|
||||
{{#threetenbp}}
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
@@ -161,13 +207,13 @@
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
{{#useBeanValidation}}
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>${beanvalidation-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>${beanvalidation-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
{{/useBeanValidation}}
|
||||
</dependencies>
|
||||
<properties>
|
||||
@@ -178,9 +224,9 @@
|
||||
<slf4j-version>1.7.21</slf4j-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<springfox-version>2.7.0</springfox-version>
|
||||
<jackson-version>2.8.9</jackson-version>
|
||||
<jackson-threetenbp-version>2.6.4</jackson-threetenbp-version>
|
||||
<springfox-version>2.8.0</springfox-version>
|
||||
<jackson-version>2.9.5</jackson-version>
|
||||
<jackson-threetenbp-version>2.8.4</jackson-threetenbp-version>
|
||||
{{#useBeanValidation}}
|
||||
<beanvalidation-version>1.1.0.Final</beanvalidation-version>
|
||||
{{/useBeanValidation}}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{{{openapi-yaml}}}
|
||||
@@ -10,7 +10,7 @@ org.openapitools.codegen.languages.ConfluenceWikiCodegen
|
||||
org.openapitools.codegen.languages.CppQt5ClientCodegen
|
||||
org.openapitools.codegen.languages.CppPistacheServerCodegen
|
||||
org.openapitools.codegen.languages.CppRestbedServerCodegen
|
||||
org.openapitools.codegen.languages.CppRestClientCodegen
|
||||
org.openapitools.codegen.languages.CppRestSdkClientCodegen
|
||||
org.openapitools.codegen.languages.CppTizenClientCodegen
|
||||
org.openapitools.codegen.languages.CSharpClientCodegen
|
||||
org.openapitools.codegen.languages.CSharpDotNet2ClientCodegen
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.1" />
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
|
||||
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
<logger name="io.swagger" level="DEBUG"/>
|
||||
<root level="error">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -3,6 +3,7 @@
|
||||
#define _{{prefix}}_OBJECT_H_
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
@@ -11,22 +12,51 @@ namespace {{this}} {
|
||||
class {{prefix}}Object {
|
||||
public:
|
||||
virtual QJsonObject asJsonObject() {
|
||||
return QJsonObject();
|
||||
if(jObj != nullptr){
|
||||
return *jObj;
|
||||
}
|
||||
return QJsonObject();
|
||||
}
|
||||
virtual ~{{prefix}}Object() {}
|
||||
|
||||
{{prefix}}Object() {
|
||||
jObj = nullptr;
|
||||
}
|
||||
|
||||
virtual ~{{prefix}}Object() {
|
||||
if(jObj != nullptr){
|
||||
delete jObj;
|
||||
}
|
||||
}
|
||||
|
||||
virtual {{prefix}}Object* fromJson(QString jsonString) {
|
||||
Q_UNUSED(jsonString);
|
||||
return new {{prefix}}Object();
|
||||
QJsonDocument doc = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||
auto ret = new {{prefix}}Object();
|
||||
ret->fromJsonObject(doc.object());
|
||||
return ret;
|
||||
}
|
||||
|
||||
virtual void fromJsonObject(QJsonObject json) {
|
||||
Q_UNUSED(json);
|
||||
if(jObj != nullptr)
|
||||
{
|
||||
delete jObj;
|
||||
}
|
||||
jObj = new QJsonObject(json);
|
||||
}
|
||||
|
||||
virtual QString asJson() {
|
||||
return QString("");
|
||||
if(jObj != nullptr)
|
||||
{
|
||||
QJsonDocument doc(*jObj);
|
||||
return doc.toJson(QJsonDocument::Compact);
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
virtual bool isSet() {
|
||||
return false;
|
||||
}
|
||||
private :
|
||||
QJsonObject *jObj;
|
||||
};
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
|
||||
@@ -226,7 +226,7 @@ export class {{classname}} {
|
||||
{{/produces}}
|
||||
];
|
||||
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
|
||||
if (httpHeaderAcceptSelected != undefined) {
|
||||
if (httpHeaderAcceptSelected !== undefined) {
|
||||
{{^useHttpClient}}
|
||||
headers.set('Accept', httpHeaderAcceptSelected);
|
||||
{{/useHttpClient}}
|
||||
@@ -243,7 +243,7 @@ export class {{classname}} {
|
||||
];
|
||||
{{#bodyParam}}
|
||||
const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
|
||||
if (httpContentTypeSelected != undefined) {
|
||||
if (httpContentTypeSelected !== undefined) {
|
||||
{{^useHttpClient}}
|
||||
headers.set('Content-Type', httpContentTypeSelected);
|
||||
{{/useHttpClient}}
|
||||
|
||||
@@ -32,7 +32,7 @@ export class Configuration {
|
||||
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
|
||||
*/
|
||||
public selectHeaderContentType (contentTypes: string[]): string | undefined {
|
||||
if (contentTypes.length == 0) {
|
||||
if (contentTypes.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export class Configuration {
|
||||
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
|
||||
*/
|
||||
public selectHeaderAccept(accepts: string[]): string | undefined {
|
||||
if (accepts.length == 0) {
|
||||
if (accepts.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,6 @@ export class Configuration {
|
||||
*/
|
||||
public isJsonMime(mime: string): boolean {
|
||||
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
||||
return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
||||
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,6 @@ import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.DefaultCodegen;
|
||||
import org.openapitools.codegen.languages.PhpClientCodegen;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
@@ -46,7 +44,6 @@ import java.util.Map;
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public class PhpModelTest {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PhpModelTest.class);
|
||||
|
||||
@Test(description = "convert a simple php model")
|
||||
public void simpleModelTest() {
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
package org.openapitools.codegen.serializer;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import io.swagger.v3.oas.models.Components;
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.media.ObjectSchema;
|
||||
import io.swagger.v3.oas.models.media.StringSchema;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import io.swagger.v3.oas.models.tags.Tag;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SerializerUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testToYamlStringCompleteExample() throws Exception {
|
||||
OpenAPI openAPI = new OpenAPI();
|
||||
openAPI.setInfo(new Info().title("Some title").description("Some description"));
|
||||
openAPI.setExternalDocs(new ExternalDocumentation().url("http://abcdef.com").description("a-description"));
|
||||
openAPI.setServers(Arrays.asList(
|
||||
new Server().url("http://www.server1.com").description("first server"),
|
||||
new Server().url("http://www.server2.com").description("second server")
|
||||
));
|
||||
openAPI.setSecurity(Arrays.asList(
|
||||
new SecurityRequirement().addList("some_auth", Arrays.asList("write", "read"))
|
||||
));
|
||||
openAPI.setTags(Arrays.asList(
|
||||
new Tag().name("tag1").description("some 1 description"),
|
||||
new Tag().name("tag2").description("some 2 description"),
|
||||
new Tag().name("tag3").description("some 3 description")
|
||||
));
|
||||
openAPI.path("/ping/pong", new PathItem().get(new Operation()
|
||||
.description("Some description")
|
||||
.operationId("pingOp")
|
||||
.responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("Ok")))));
|
||||
openAPI.components(new Components().addSchemas("SomeObject", new ObjectSchema().description("An Obj").addProperties("id", new StringSchema())));
|
||||
openAPI.addExtension("x-custom", "value1");
|
||||
openAPI.addExtension("x-other", "value2");
|
||||
|
||||
String content = SerializerUtils.toYamlString(openAPI);
|
||||
String expected = "openapi: 3.0.1\n" +
|
||||
"info:\n" +
|
||||
" description: Some description\n" +
|
||||
" title: Some title\n" +
|
||||
"externalDocs:\n" +
|
||||
" description: a-description\n" +
|
||||
" url: http://abcdef.com\n" +
|
||||
"servers:\n" +
|
||||
"- description: first server\n" +
|
||||
" url: http://www.server1.com\n" +
|
||||
"- description: second server\n" +
|
||||
" url: http://www.server2.com\n" +
|
||||
"security:\n" +
|
||||
"- some_auth:\n" +
|
||||
" - write\n" +
|
||||
" - read\n" +
|
||||
"tags:\n" +
|
||||
"- description: some 1 description\n" +
|
||||
" name: tag1\n" +
|
||||
"- description: some 2 description\n" +
|
||||
" name: tag2\n" +
|
||||
"- description: some 3 description\n" +
|
||||
" name: tag3\n" +
|
||||
"paths:\n" +
|
||||
" /ping/pong:\n" +
|
||||
" get:\n" +
|
||||
" description: Some description\n" +
|
||||
" operationId: pingOp\n" +
|
||||
" responses:\n" +
|
||||
" 200:\n" +
|
||||
" description: Ok\n" +
|
||||
"components:\n" +
|
||||
" schemas:\n" +
|
||||
" SomeObject:\n" +
|
||||
" description: An Obj\n" +
|
||||
" properties:\n" +
|
||||
" id:\n" +
|
||||
" type: string\n" +
|
||||
" type: object\n" +
|
||||
"x-other: value2\n" +
|
||||
"x-custom: value1\n";
|
||||
assertEquals(content, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToYamlStringMinimalExample() throws Exception {
|
||||
OpenAPI openAPI = new OpenAPI();
|
||||
openAPI.setInfo(new Info().title("Some title"));
|
||||
openAPI.setServers(Arrays.asList(
|
||||
new Server().url("http://www.server1.com")
|
||||
));
|
||||
openAPI.path("/ping/pong", new PathItem().get(new Operation()
|
||||
.description("Some description")
|
||||
.operationId("pingOp")
|
||||
.responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("Ok")))));
|
||||
|
||||
String content = SerializerUtils.toYamlString(openAPI);
|
||||
String expected = "openapi: 3.0.1\n" +
|
||||
"info:\n" +
|
||||
" title: Some title\n" +
|
||||
"servers:\n" +
|
||||
"- url: http://www.server1.com\n" +
|
||||
"paths:\n" +
|
||||
" /ping/pong:\n" +
|
||||
" get:\n" +
|
||||
" description: Some description\n" +
|
||||
" operationId: pingOp\n" +
|
||||
" responses:\n" +
|
||||
" 200:\n" +
|
||||
" description: Ok\n";
|
||||
assertEquals(content, expected);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class ModelUtilsTest {
|
||||
public void testGetAllUsedSchemas() {
|
||||
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/unusedSchemas.yaml", null, new ParseOptions()).getOpenAPI();
|
||||
List<String> allUsedSchemas = ModelUtils.getAllUsedSchemas(openAPI);
|
||||
Assert.assertEquals(allUsedSchemas.size(), 12);
|
||||
Assert.assertEquals(allUsedSchemas.size(), 28);
|
||||
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeObjShared"), "contains 'SomeObjShared'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeObj1"), "contains 'UnusedObj1'");
|
||||
@@ -54,6 +54,22 @@ public class ModelUtilsTest {
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeObj10A"), "contains 'SomeObj10A'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeObj10B"), "contains 'SomeObj10B'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeObj11"), "contains 'SomeObj11'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeArrayObj12"), "contains 'SomeArrayObj12'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("ArrayItem12"), "contains 'ArrayItem12'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeArrayObj13"), "contains 'SomeArrayObj13'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("ArrayItem13"), "contains 'ArrayItem13'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeObj14"), "contains 'SomeObj14'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("PropertyObj14"), "contains 'PropertyObj14'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeObj15"), "contains 'SomeObj15'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeMapObj16"), "contains 'SomeMapObj16'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("MapItem16"), "contains 'MapItem16'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeObj17"), "contains 'SomeObj17'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeObj18"), "contains 'SomeObj18'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("Common18"), "contains 'Common18'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("Obj19ByAge"), "contains 'Obj19ByAge'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("Obj19ByType"), "contains 'Obj19ByType'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeObj20"), "contains 'SomeObj20'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("OtherObj20"), "contains 'OtherObj20'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -135,6 +135,104 @@ paths:
|
||||
200:
|
||||
description: Successful Operation
|
||||
content: {}
|
||||
/some/p12:
|
||||
post:
|
||||
operationId: p12
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SomeArrayObj12'
|
||||
responses:
|
||||
200:
|
||||
description: Successful Operation
|
||||
content: {}
|
||||
/some/p13:
|
||||
get:
|
||||
operationId: p13
|
||||
responses:
|
||||
200:
|
||||
description: Successful Operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SomeArrayObj13'
|
||||
/some/p14:
|
||||
get:
|
||||
operationId: p14
|
||||
responses:
|
||||
200:
|
||||
description: Successful Operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SomeObj14'
|
||||
/some/p15:
|
||||
get:
|
||||
operationId: p15
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SomeObj15'
|
||||
/some/p16:
|
||||
get:
|
||||
operationId: p16
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SomeMapObj16'
|
||||
/some/p17:
|
||||
get:
|
||||
operationId: p17
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
oneOf:
|
||||
- type: string
|
||||
- $ref: '#/components/schemas/SomeObj17'
|
||||
/some/p18:
|
||||
get:
|
||||
operationId: p18
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SomeObj18'
|
||||
responses:
|
||||
200:
|
||||
description: Successful Operation
|
||||
content: {}
|
||||
/some/p19:
|
||||
patch:
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
anyOf:
|
||||
- $ref: '#/components/schemas/Obj19ByAge'
|
||||
- $ref: '#/components/schemas/Obj19ByType'
|
||||
responses:
|
||||
'200':
|
||||
description: Updated
|
||||
/some/p20:
|
||||
get:
|
||||
operationId: op20
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SomeObj20'
|
||||
components:
|
||||
schemas:
|
||||
UnusedObj1:
|
||||
@@ -254,6 +352,117 @@ components:
|
||||
- v1
|
||||
- v2
|
||||
default: v1
|
||||
SomeArrayObj12:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/ArrayItem12"
|
||||
ArrayItem12:
|
||||
type: object
|
||||
properties:
|
||||
prop1:
|
||||
type: string
|
||||
prop2:
|
||||
type: integer
|
||||
format: int32
|
||||
SomeArrayObj13:
|
||||
type: array
|
||||
items:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/ArrayItem13"
|
||||
ArrayItem13:
|
||||
type: object
|
||||
properties:
|
||||
prop1:
|
||||
type: string
|
||||
prop2:
|
||||
type: integer
|
||||
format: int64
|
||||
SomeObj14:
|
||||
type: object
|
||||
properties:
|
||||
obj14:
|
||||
$ref: "#/components/schemas/PropertyObj14"
|
||||
PropertyObj14:
|
||||
type: object
|
||||
properties:
|
||||
prop1:
|
||||
type: string
|
||||
SomeObj15:
|
||||
type: object
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
details:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/SomeObj15'
|
||||
SomeMapObj16:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/MapItem16"
|
||||
MapItem16:
|
||||
type: object
|
||||
properties:
|
||||
prop1:
|
||||
type: integer
|
||||
format: int32
|
||||
prop2:
|
||||
type: integer
|
||||
format: int64
|
||||
SomeObj17:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: String
|
||||
message:
|
||||
type: String
|
||||
SomeObj18:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Common18'
|
||||
- type: object
|
||||
properties:
|
||||
firstName:
|
||||
type: String
|
||||
lastName:
|
||||
type: String
|
||||
Common18:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: String
|
||||
active:
|
||||
type: boolean
|
||||
Obj19ByAge:
|
||||
type: object
|
||||
properties:
|
||||
age:
|
||||
type: integer
|
||||
firstName:
|
||||
type: String
|
||||
lastName:
|
||||
type: String
|
||||
required:
|
||||
- age
|
||||
Obj19ByType:
|
||||
type: object
|
||||
properties:
|
||||
sometype:
|
||||
type: string
|
||||
enum: [A, B, C]
|
||||
enabled:
|
||||
type: boolean
|
||||
required:
|
||||
- sometype
|
||||
SomeObj20:
|
||||
type: object
|
||||
properties:
|
||||
other:
|
||||
not:
|
||||
$ref: '#/components/schemas/OtherObj20'
|
||||
OtherObj20:
|
||||
type: string
|
||||
enum: [A, B, C]
|
||||
SomeObjShared:
|
||||
type: object
|
||||
properties:
|
||||
|
||||
49
pom.xml
49
pom.xml
@@ -9,7 +9,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -60,6 +60,16 @@
|
||||
<system>github</system>
|
||||
<url>https://github.com/openapitools/openapi-generator/issues</url>
|
||||
</issueManagement>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License 2.0</name>
|
||||
@@ -214,12 +224,13 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.4</version>
|
||||
<version>3.0.1</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<source>1.8</source>
|
||||
<encoding>UTF-8</encoding>
|
||||
<maxmemory>1g</maxmemory>
|
||||
<failOnWarnings>true</failOnWarnings>
|
||||
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>
|
||||
</configuration>
|
||||
<executions>
|
||||
@@ -278,6 +289,40 @@
|
||||
</pluginManagement>
|
||||
</build>
|
||||
<profiles>
|
||||
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.6.8</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>release-profile</id>
|
||||
<properties>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
3.0.1-SNAPSHOT
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user