forked from loafle/openapi-generator-original
Compare commits
152 Commits
v3.3.3
...
duke_scrip
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb627dedfd | ||
|
|
774013c7e1 | ||
|
|
c0634ac213 | ||
|
|
92d60b684a | ||
|
|
d40cbf9dbd | ||
|
|
d57009d14d | ||
|
|
ced6e0502e | ||
|
|
314b4cc54f | ||
|
|
21b2b20c2d | ||
|
|
1e023f3b6e | ||
|
|
df19c13347 | ||
|
|
32d228c33a | ||
|
|
fcd37a6006 | ||
|
|
4be605bcb7 | ||
|
|
01ac429954 | ||
|
|
10ea00066a | ||
|
|
4930f75dc7 | ||
|
|
8795bff35e | ||
|
|
6976a8c775 | ||
|
|
110d057384 | ||
|
|
d75392e056 | ||
|
|
e84c59f4cc | ||
|
|
0a33ad465f | ||
|
|
8ee1553654 | ||
|
|
001f89f1d9 | ||
|
|
cd61442387 | ||
|
|
e3ab059530 | ||
|
|
dfa7e616c0 | ||
|
|
2353d71d4b | ||
|
|
2f4dc9a049 | ||
|
|
54b5093381 | ||
|
|
cf2ddb8b8c | ||
|
|
8f8d3547f6 | ||
|
|
b226f52d13 | ||
|
|
eae958f293 | ||
|
|
308515bbc1 | ||
|
|
6930433def | ||
|
|
c537557a91 | ||
|
|
f7c857cc39 | ||
|
|
777bf1f3aa | ||
|
|
41185d3c6f | ||
|
|
1d4e24b203 | ||
|
|
c63f58f1ef | ||
|
|
9df70798b3 | ||
|
|
3efe56752e | ||
|
|
d8dde6855f | ||
|
|
ebf67e683c | ||
|
|
5b4a19849e | ||
|
|
9b99b6b6bf | ||
|
|
33016f2790 | ||
|
|
963173b357 | ||
|
|
d31fa4f7c4 | ||
|
|
247bd68880 | ||
|
|
4eae430cca | ||
|
|
51a3a22928 | ||
|
|
172448fa28 | ||
|
|
46a4ffe64c | ||
|
|
ce0253892c | ||
|
|
34abedeb8a | ||
|
|
2146081ffb | ||
|
|
7db12aa4af | ||
|
|
bf2932d41c | ||
|
|
f8ada391c4 | ||
|
|
0ba9278308 | ||
|
|
e91d6d735d | ||
|
|
5f1362daad | ||
|
|
dd33434064 | ||
|
|
cf04ba30db | ||
|
|
5aa1da7c2e | ||
|
|
9be5b99266 | ||
|
|
792f95eb09 | ||
|
|
2b58f6737a | ||
|
|
363b095721 | ||
|
|
b9949e1a8e | ||
|
|
f58bd6d839 | ||
|
|
0e693cd9a8 | ||
|
|
65a86eee3b | ||
|
|
334415dec2 | ||
|
|
7f8ff35245 | ||
|
|
2c418e1b71 | ||
|
|
941b3ea015 | ||
|
|
c656194f22 | ||
|
|
5b57eae5de | ||
|
|
edc05df774 | ||
|
|
6ab6896a13 | ||
|
|
32b8d7fee7 | ||
|
|
dc3a3dd15a | ||
|
|
736e8348b6 | ||
|
|
2bcf5b2263 | ||
|
|
a87a544bf5 | ||
|
|
8d9542207a | ||
|
|
31d9928734 | ||
|
|
e5c0d227ab | ||
|
|
8ba4b3a276 | ||
|
|
d59230fd27 | ||
|
|
75b1403c1e | ||
|
|
a023a0d0ca | ||
|
|
e6c97a1bc1 | ||
|
|
a186efed35 | ||
|
|
ceffdde2c0 | ||
|
|
71ecee02e9 | ||
|
|
ed2f6ea72e | ||
|
|
ef98971746 | ||
|
|
3482a0a993 | ||
|
|
4a47acce19 | ||
|
|
9422dea149 | ||
|
|
30062afc7c | ||
|
|
bbfaa90242 | ||
|
|
eccab2c025 | ||
|
|
40e90b5883 | ||
|
|
a3dc5ecc20 | ||
|
|
649d5a97b4 | ||
|
|
83c55ec016 | ||
|
|
e42cac636a | ||
|
|
cfbc72f444 | ||
|
|
9e3c7781bb | ||
|
|
257a97b6cd | ||
|
|
5490bb8e9c | ||
|
|
0f7557ca9d | ||
|
|
5357791337 | ||
|
|
c9625f3fd5 | ||
|
|
94eb1c3c63 | ||
|
|
a08f8d13e0 | ||
|
|
adbe478e0b | ||
|
|
780ba49da1 | ||
|
|
e5b6d525c7 | ||
|
|
d1f7e16daa | ||
|
|
74d70121d1 | ||
|
|
aed8e38584 | ||
|
|
3746fae2ca | ||
|
|
c44d91c673 | ||
|
|
be2a0170b7 | ||
|
|
2f85867963 | ||
|
|
3b1029ada4 | ||
|
|
8cbd57d829 | ||
|
|
75e5ed2f68 | ||
|
|
6460bb2897 | ||
|
|
22c79cf470 | ||
|
|
024dde11d7 | ||
|
|
d2db799a93 | ||
|
|
07b8040122 | ||
|
|
eb09731a65 | ||
|
|
f98000753d | ||
|
|
deb5dcaad1 | ||
|
|
7f4fc4de93 | ||
|
|
7938677efa | ||
|
|
b0c02d8ea6 | ||
|
|
05f177b6d6 | ||
|
|
b1921ce484 | ||
|
|
4a4fb77081 | ||
|
|
f5f744ad2c | ||
|
|
b887efdc1c |
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -2,7 +2,7 @@
|
||||
|
||||
- [ ] Read the [contribution guidelines](https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md).
|
||||
- [ ] Ran the shell script under `./bin/` to update Petstore sample so that CIs can verify the change. (For instance, only need to run `./bin/{LANG}-petstore.sh` and `./bin/security/{LANG}-petstore.sh` if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in `.\bin\windows\`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`, `3.4.x`, `4.0.x`. Default: `master`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`~~, `3.4.x`, `4.0.x`~~. Default: `master`.
|
||||
- [ ] Copied the [technical committee](https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee) to review the pull request if your PR is targeting a particular programming language.
|
||||
|
||||
### Description of the PR
|
||||
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -184,6 +184,9 @@ samples/server/petstore/kotlin-server/ktor/build
|
||||
.stack-work
|
||||
.cabal-sandbox
|
||||
cabal.project.local
|
||||
samples/client/petstore/haskell-http-client/docs/haddock-bundle.min.js
|
||||
samples/client/petstore/haskell-http-client/docs/meta.json
|
||||
samples/client/petstore/haskell-http-client/docs/quick-jump.css
|
||||
|
||||
# R
|
||||
.Rproj.user
|
||||
@@ -212,3 +215,7 @@ samples/client/petstore/javascript/package-lock.json
|
||||
|
||||
# elm
|
||||
samples/client/petstore/elm/index.html
|
||||
|
||||
# C
|
||||
samples/client/petstore/c/build
|
||||
samples/client/petstore/c/*.so
|
||||
|
||||
17
.travis.yml
17
.travis.yml
@@ -75,11 +75,14 @@ before_install:
|
||||
- sudo apt-get install -qq curl
|
||||
# install dart
|
||||
#- sudo apt-get update
|
||||
- sudo apt-get install apt-transport-https
|
||||
- sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
|
||||
- sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
|
||||
- sudo apt-get update
|
||||
- sudo apt-get install dart
|
||||
#- sudo apt-get install apt-transport-https
|
||||
#- sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
|
||||
#- sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
|
||||
#- sudo apt-get update
|
||||
#- sudo apt-get install dart
|
||||
# switch to php7
|
||||
- phpenv global 7.1
|
||||
- php -v
|
||||
# install perl module
|
||||
#- cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
|
||||
#- cpanm Test::Exception Test::More Log::Any LWP::UserAgent JSON URI:Query Module::Runtime DateTime Module::Find Moose::Role
|
||||
@@ -109,8 +112,8 @@ install:
|
||||
- gcc -v
|
||||
- echo $CC
|
||||
- echo $CXX
|
||||
- pub version
|
||||
- dart --version
|
||||
#- pub version
|
||||
#- dart --version
|
||||
|
||||
script:
|
||||
# fail fast
|
||||
|
||||
@@ -15,7 +15,7 @@ elif [ "$NODE_INDEX" = "2" ]; then
|
||||
java -version
|
||||
#export GO_POST_PROCESS_FILE="/usr/local/bin/gofmt -w"
|
||||
# not formatting the code as different go versions may format the code a bit different
|
||||
#./bin/utils/ensure-up-to-date
|
||||
./bin/utils/ensure-up-to-date
|
||||
else
|
||||
echo "Running node $NODE_INDEX to test 'samples.circleci.jdk7' defined in pom.xml ..."
|
||||
sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>TypeScriptAngularBuildPestoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>TS Fetch Default Petstore Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,59 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>TypeScriptAngularBuildES6PestoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>TS Fetch ES6 Petstore Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>npm-install</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,73 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>TypeScriptAngularBuildWithNPMVersionPestoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>TS Fetch Petstore Client (with npm)</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>npm-install</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-build</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>run</argument>
|
||||
<argument>build</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,59 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>TypeScriptFetchPestoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>TS Fetch Petstore Test Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>npm-install</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1 @@
|
||||
c2fcc2ae9693a8e8d02b25e286844aad88188fcb
|
||||
Binary file not shown.
73
README.md
73
README.md
@@ -2,20 +2,11 @@
|
||||
|
||||
<div align="center">
|
||||
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`3.3.3`): [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`4.0.0`): [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
|
||||
|
||||
[`3.4.x`](https://github.com/OpenAPITools/openapi-generator/tree/3.4.x) branch: [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
|
||||
|
||||
[`4.0.x`](https://github.com/OpenAPITools/openapi-generator/tree/4.0.x) branch: [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
@@ -47,11 +38,11 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
|
||||
|
||||
| | Languages/Frameworks |
|
||||
|-|-|
|
||||
**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C#** (.net 2.0, 3.5 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client), **Kotlin**, **Lua**, **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (AngularJS, Angular (2.x - 7.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node)
|
||||
**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client), **Kotlin**, **Lua**, **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (AngularJS, Angular (2.x - 7.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node)
|
||||
**Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go** (net/http, Gin), **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples)), **Kotlin** (Spring Boot), **PHP** (Laravel, Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** (rust-server), **Scala** ([Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), Scalatra)
|
||||
**API documentation generators** | **HTML**, **Confluence Wiki**
|
||||
**Configuration files** | [**Apache2**](https://httpd.apache.org/)
|
||||
**Others** | **JMeter**, **MySQL Schema**
|
||||
**Others** | **GraphQL**, **JMeter**, **MySQL Schema**
|
||||
|
||||
## Table of contents
|
||||
|
||||
@@ -88,10 +79,8 @@ The OpenAPI Specification has undergone 3 revisions since initial creation in 20
|
||||
|
||||
OpenAPI Generator Version | Release Date | Notes
|
||||
---------------------------- | ------------ | -----
|
||||
4.0.0 (upcoming major release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/)| TBD | Major release with breaking changes (no fallback)
|
||||
3.4.0 (upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.4.0-SNAPSHOT/)| 01.11.2018 | Minor release (breaking changes with fallbacks)
|
||||
3.3.3 (current master, upcoming patch release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.3.3-SNAPSHOT/) | 15.11.2018 | Bugfix release
|
||||
[3.3.3](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.3.3) (latest stable release) | 15.11.2018 | Bugfix release
|
||||
4.0.0 (upcoming release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/)| 20.12.2018 | Major release with breaking changes (with or without fallback)
|
||||
[3.3.4](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.3.4) (latest stable release) | 30.11.2018 | Bugfix release
|
||||
|
||||
OpenAPI Spec compatibility: 1.0, 1.1, 1.2, 2.0, 3.0
|
||||
|
||||
@@ -147,16 +136,16 @@ See the different versions of the [openapi-generator-cli](https://mvnrepository.
|
||||
|
||||
If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum):
|
||||
|
||||
JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.3.3/openapi-generator-cli-3.3.3.jar`
|
||||
JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.3.4/openapi-generator-cli-3.3.4.jar`
|
||||
|
||||
For **Mac/Linux** users:
|
||||
```sh
|
||||
wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.3.3/openapi-generator-cli-3.3.3.jar -O openapi-generator-cli.jar
|
||||
wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.3.4/openapi-generator-cli-3.3.4.jar -O openapi-generator-cli.jar
|
||||
```
|
||||
|
||||
For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.
|
||||
```
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.3.3/openapi-generator-cli-3.3.3.jar
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.3.4/openapi-generator-cli-3.3.4.jar
|
||||
```
|
||||
|
||||
After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage.
|
||||
@@ -216,7 +205,7 @@ To build from source, you need the following installed and available in your `$P
|
||||
|
||||
* [Java 8](http://java.oracle.com)
|
||||
|
||||
* [Apache maven 3.3.3 or greater](http://maven.apache.org/)
|
||||
* [Apache maven 3.3.4 or greater](http://maven.apache.org/)
|
||||
|
||||
After cloning the project, you can build it from source with this command:
|
||||
```sh
|
||||
@@ -285,13 +274,13 @@ GEN_IP=$(docker inspect --format '{{.NetworkSettings.IPAddress}}' $CID)
|
||||
-d '{"openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml"}' \
|
||||
'http://localhost:8888/api/gen/clients/ruby'
|
||||
|
||||
{"code":"c2d483d3-3672-40e9-91df-b9ffd18d22b8","link":"http://localhost:8888/api/gen/download/c2d483d3-3672-40e9-91df-b9ffd18d22b8"}
|
||||
{"code":"c2d483.3.4672-40e9-91df-b9ffd18d22b8","link":"http://localhost:8888/api/gen/download/c2d483.3.4672-40e9-91df-b9ffd18d22b8"}
|
||||
|
||||
# Download the generated zip file
|
||||
> wget http://localhost:8888/api/gen/download/c2d483d3-3672-40e9-91df-b9ffd18d22b8
|
||||
> wget http://localhost:8888/api/gen/download/c2d483.3.4672-40e9-91df-b9ffd18d22b8
|
||||
|
||||
# Unzip the file
|
||||
> unzip c2d483d3-3672-40e9-91df-b9ffd18d22b8
|
||||
> unzip c2d483.3.4672-40e9-91df-b9ffd18d22b8
|
||||
|
||||
# Shutdown the openapi generator image
|
||||
> docker stop $CID && docker rm $CID
|
||||
@@ -349,20 +338,26 @@ cd /vagrant
|
||||
|
||||
### [1.7 - NPM](#table-of-contents)
|
||||
|
||||
There is also an [NPM package wrapper](https://github.com/HarmoWatch/openapi-generator-cli), available.
|
||||
Please see the [docs](https://github.com/HarmoWatch/openapi-generator-cli) there for more information.
|
||||
There is also an [NPM package wrapper](https://www.npmjs.com/package/@openapitools/openapi-generator-cli) available for different platforms (e.g. Linux, Mac, Windows). (JVM is still required)
|
||||
Please see the [project's README](https://github.com/openapitools/openapi-generator-cli) there for more information.
|
||||
|
||||
Install it globally to get the CLI available on the command line:
|
||||
|
||||
```sh
|
||||
npm install @harmowatch/openapi-generator-cli -g
|
||||
npm install @openapitools/openapi-generator-cli -g
|
||||
openapi-generator version
|
||||
```
|
||||
|
||||
Or you install it as dev-dependency like this:
|
||||
Or install a particualar OpenAPI Generator version (e.g. v3.3.4):
|
||||
|
||||
```sh
|
||||
npm install @harmowatch/openapi-generator-cli -D
|
||||
npm install @openapitools/openapi-generator-cli@cli-3.3.4 -g
|
||||
```
|
||||
|
||||
Or install it as dev-dependency:
|
||||
|
||||
```sh
|
||||
npm install @openapitools/openapi-generator-cli -D
|
||||
```
|
||||
|
||||
## [2 - Getting Started](#table-of-contents)
|
||||
@@ -470,7 +465,7 @@ Other languages have petstore samples, too:
|
||||
./bin/objc-petstore.sh
|
||||
```
|
||||
|
||||
... and others. [Here is a list of all scripts.](wiki/Samples-folder#scripts)
|
||||
... and others. [Here is a list of all scripts.](https://github.com/OpenAPITools/openapi-generator/wiki/Samples-folder#scripts)
|
||||
|
||||
### [3.1 - Customization](#table-of-contents)
|
||||
|
||||
@@ -482,6 +477,15 @@ Please refer to [integration.md](docs/integration.md) on how to integrate OpenAP
|
||||
|
||||
### [3.3 - Online OpenAPI generator](#table-of-contents)
|
||||
|
||||
Here are the public online services:
|
||||
|
||||
- latest stable version: http://api.openapi-generator.tech
|
||||
- latest master: http://api-latest-master.openapi-generator.tech (updated with latest master every hour)
|
||||
|
||||
The server is sponsored by [Linode](https://www.linode.com/) [](https://www.linode.com/)
|
||||
|
||||
(These services are beta and do not have any guarantee on service level)
|
||||
|
||||
Please refer to [online-openapi-generator.md](docs/online-openapi-generator.md) on how to run and use the `openapi-generator-online` - a web service for `openapi-generator`.
|
||||
|
||||
### [3.4 - License information on Generated Code](#table-of-contents)
|
||||
@@ -497,6 +501,7 @@ When code is generated from this project, it shall be considered **AS IS** and o
|
||||
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/)
|
||||
- [b<>com](https://b-com.com/en)
|
||||
- [Bithost GmbH](https://www.bithost.ch)
|
||||
- [Boxever](https://www.boxever.com/)
|
||||
- [GMO Pepabo](https://pepabo.com/en/)
|
||||
@@ -508,6 +513,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- [REST United](https://restunited.com)
|
||||
- [Suva](https://www.suva.ch/)
|
||||
- [Telstra](https://dev.telstra.com)
|
||||
- [TUI InfoTec GmbH](http://www.tui-infotec.com/)
|
||||
- [unblu inc.](https://www.unblu.com/)
|
||||
- [Zalando](https://www.zalando.com)
|
||||
|
||||
@@ -523,7 +529,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- 2018/08/22 - [OpenAPI Generatorのプロジェクト構成などのメモ](https://yinm.info/20180822/) by [Yusuke Iinuma](https://github.com/yinm)
|
||||
- 2018/10/31 - [A node package wrapper for openapi-generator](https://github.com/HarmoWatch/openapi-generator-cli)
|
||||
- 2018/11/03 - [OpenAPI Generator + golang + Flutter でアプリ開発](http://ryuichi111std.hatenablog.com/entry/2018/11/03/214005) by [Ryuichi Daigo](https://github.com/ryuichi111)
|
||||
|
||||
- 2018/11/19 - [OpenAPIs are everywhere](https://youtu.be/-lDot4Yn7Dg) by [Jeremie Bresson (Unblu)](https://github.com/jmini) at [EclipseCon Europe 2018](https://www.eclipsecon.org/europe2018)
|
||||
|
||||
## [6 - About Us](#table-of-contents)
|
||||
|
||||
@@ -547,6 +553,7 @@ Here is a list of template creators:
|
||||
* Akka-Scala: @cchafer
|
||||
* Apex: @asnelling
|
||||
* Bash: @bkryza
|
||||
* C: @PowerOfCreation @zhemant
|
||||
* C++ REST: @Danielku15
|
||||
* C# (.NET 2.0): @who
|
||||
* C# (.NET Standard 1.3 ): @Gronsak
|
||||
@@ -610,6 +617,7 @@ Here is a list of template creators:
|
||||
* Erlang Server: @galaxie
|
||||
* Go Server: @guohuang
|
||||
* Go (Gin) Server: @kemokemo
|
||||
* GraphQL Express Server: @renepardon
|
||||
* Haskell Servant: @algas
|
||||
* Java MSF4J: @sanjeewa-malalgoda
|
||||
* Java Spring Boot: @diyfr
|
||||
@@ -637,6 +645,7 @@ Here is a list of template creators:
|
||||
* Configuration
|
||||
* Apache2: @stkrwork
|
||||
* Schema
|
||||
* GraphQL: @wing328
|
||||
* MySQL: @ybelenko
|
||||
|
||||
#### How to join the core team
|
||||
@@ -675,6 +684,7 @@ If you want to join the committee, please kindly apply by sending an email to te
|
||||
| Android | @jaz-ah (2017/09) |
|
||||
| Apex | |
|
||||
| Bash | @frol (2017/07) @bkryza (2017/08) @kenjones-cisco (2017/09) |
|
||||
| C | @zhemant (2018/11) |
|
||||
| C++ | @ravinikam (2017/07) @stkrwork (2017/07) @fvarose (2017/11) @etherealjoy (2018/02) @martindelille (2018/03) |
|
||||
| C# | @mandrean (2017/08) @jimschubert (2017/09) |
|
||||
| Clojure | |
|
||||
@@ -684,6 +694,7 @@ If you want to join the committee, please kindly apply by sending an email to te
|
||||
| Elm | @trenneman (2018/09) |
|
||||
| Erlang | @tsloughter (2017/11) @jfacorro (2018/10) @robertoaloi (2018/10) |
|
||||
| Go | @antihax (2017/11) @bvwells (2017/12) @grokify (2018/07) @kemokemo (2018/09 |
|
||||
| GraphQL | @renepardon (2018/12) |
|
||||
| Groovy | |
|
||||
| Haskell | |
|
||||
| Java | @bbdouglas (2017/07) @JFCote (2017/08) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) |
|
||||
@@ -692,7 +703,7 @@ If you want to join the committee, please kindly apply by sending an email to te
|
||||
| NodeJS/Javascript | @CodeNinjai (2017/07) @frol (2017/07) @cliffano (2017/07) |
|
||||
| ObjC | |
|
||||
| Perl | @wing328 (2017/07) |
|
||||
| PHP | @jebentier (2017/07) @dkarlovi (2017/07) @mandrean (2017/08) @jfastnacht (2017/09) @ackintosh (2017/09) @ybelenko (2018/07) |
|
||||
| PHP | @jebentier (2017/07) @dkarlovi (2017/07) @mandrean (2017/08) @jfastnacht (2017/09) @ackintosh (2017/09) @ybelenko (2018/07) @renepardon (2018/12) |
|
||||
| PowerShell | |
|
||||
| Python | @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) |
|
||||
| R | |
|
||||
|
||||
32
bin/c-petstore.sh
Executable file
32
bin/c-petstore.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/C-libcurl -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g c -o samples/client/petstore/c $@"
|
||||
|
||||
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/cpp-qt5-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-qt5 -o samples/client/petstore/cpp-qt5 $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-qt5-client -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 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cwiki -o samples/documentation/cwiki $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/confluenceWikiDocs -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cwiki -o samples/documentation/cwiki $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
32
bin/dukescript-petstore.sh
Normal file
32
bin/dukescript-petstore.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/dukescript -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dukescript -o samples/client/petstore/dukescript $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
32
bin/graphql-schema-petstore.sh
Executable file
32
bin/graphql-schema-petstore.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/graphql-schema -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g graphql-schema -o samples/config/petstore/graphql-schema -DpackageName=petstore $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
32
bin/graphql-server-petstore.sh
Executable file
32
bin/graphql-server-petstore.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/graphql-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g graphql-server -o samples/server/petstore/graphql-server -DpackageName=petstore $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g html -o samples/documentation/html $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/htmlDocs -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g html -o samples/documentation/html $@"
|
||||
|
||||
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/cpp-qt5-client -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-qt5 -o samples/client/petstore/cpp-qt5 $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-client -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-qt5-client -o samples/client/petstore/cpp-qt5 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
42
bin/openapi3/graphql-petstore-server.sh
Executable file
42
bin/openapi3/graphql-petstore-server.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
# Make sure that the working directory is the root dir
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "${SCRIPT_DIR}/../"
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
# Make sure that we are regenerating the sample by removing any existing target directory
|
||||
TARGET_DIR="$SCRIPT_DIR/../../samples/server/petstore/graphql-server"
|
||||
if [ -d "$TARGET_DIR" ]; then
|
||||
rm -rf $TARGET_DIR
|
||||
fi
|
||||
|
||||
executable="$SCRIPT_DIR/../../modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t $SCRIPT_DIR/../../modules/openapi-generator/src/main/resources/graphql-server -i $SCRIPT_DIR/../../modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g graphql-server -o $TARGET_DIR $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -25,8 +25,13 @@ then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# purge lib/doc folder
|
||||
echo "purge ruby petstore lib, docs folder"
|
||||
rm -Rf samples/openapi3/client/petstore/ruby/lib
|
||||
rm -Rf samples/openapi3/client/petstore/ruby/docs
|
||||
|
||||
# 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/ruby-client -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ruby -c bin/ruby-petstore.json -o samples/client/petstore/ruby -DskipFormModel=true $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/ruby-client -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ruby -c bin/ruby-petstore.json -o samples/openapi3/client/petstore/ruby -DskipFormModel=true $@"
|
||||
|
||||
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/cpp-qt5-client -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g cpp-qt5 -o samples/client/petstore-security-test/cpp-qt5 $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-client -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g cpp-qt5-client -o samples/client/petstore-security-test/cpp-qt5 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -9,3 +9,7 @@
|
||||
./bin/typescript-angular-v6-petstore-not-provided-in-root-with-npm.sh
|
||||
./bin/typescript-angular-v6-petstore-provided-in-root.sh
|
||||
./bin/typescript-angular-v6-petstore-provided-in-root-with-npm.sh
|
||||
./bin/typescript-angular-v7-petstore-not-provided-in-root.sh
|
||||
./bin/typescript-angular-v7-petstore-not-provided-in-root-with-npm.sh
|
||||
./bin/typescript-angular-v7-petstore-provided-in-root.sh
|
||||
./bin/typescript-angular-v7-petstore-provided-in-root-with-npm.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 -i modules/openapi-generator/src/test\resources/2_0/petstore.yaml -g typescript-angular -c bin/typescript-angular-v6-petstore-not-provided-in-root-with-npm.json -o samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm -D providedInRoot=false --additional-properties ngVersion=6.0.0 $@"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-angular -c bin/typescript-angular-v6-petstore-not-provided-in-root-with-npm.json -o samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm -D providedInRoot=false --additional-properties ngVersion=6.0.0 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test\resources/2_0/petstore.yaml -g typescript-angular -o samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default -D providedInRoot=false --additional-properties ngVersion=6.0.0 $@"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-angular -o samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default -D providedInRoot=false --additional-properties ngVersion=6.0.0 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"npmName": "@swagger/typescript-angular-petstore",
|
||||
"npmVersion": "1.0.0",
|
||||
"npmRepository" : "https://skimdb.npmjs.com/registry",
|
||||
"snapshot" : false
|
||||
}
|
||||
32
bin/typescript-angular-v7-petstore-not-provided-in-root-with-npm.sh
Executable file
32
bin/typescript-angular-v7-petstore-not-provided-in-root-with-npm.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-angular -c bin/typescript-angular-v7-petstore-not-provided-in-root-with-npm.json -o samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm -D providedInRoot=false --additional-properties ngVersion=7.0.0 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
32
bin/typescript-angular-v7-petstore-not-provided-in-root.sh
Executable file
32
bin/typescript-angular-v7-petstore-not-provided-in-root.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-angular -o samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default -D providedInRoot=false --additional-properties ngVersion=7.0.0 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"npmName": "@swagger/typescript-angular-petstore",
|
||||
"npmVersion": "1.0.0",
|
||||
"npmRepository" : "https://skimdb.npmjs.com/registry",
|
||||
"snapshot" : false
|
||||
}
|
||||
32
bin/typescript-angular-v7-petstore-provided-in-root-with-npm.sh
Executable file
32
bin/typescript-angular-v7-petstore-provided-in-root-with-npm.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-angular -c bin/typescript-angular-v7-petstore-provided-in-root-with-npm.json -o samples/client/petstore/typescript-angular-v7-provided-in-root/builds/with-npm --additional-properties ngVersion=7.0.0 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
32
bin/typescript-angular-v7-petstore-provided-in-root.sh
Executable file
32
bin/typescript-angular-v7-petstore-provided-in-root.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-angular -o samples/client/petstore/typescript-angular-v7-provided-in-root/builds/default --additional-properties ngVersion=7.0.0 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -30,3 +30,5 @@ export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-fetch -c bin/typescript-fetch-petstore-target-es6.json -o samples/client/petstore/typescript-fetch/builds/es6-target $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/builds/es6-target/pom.xml samples/client/petstore/typescript-fetch/builds/es6-target/pom.xml
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/tests/default/pom.xml samples/client/petstore/typescript-fetch/tests/default/pom.xml
|
||||
@@ -30,3 +30,5 @@ export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-fetch -c bin/typescript-fetch-petstore-with-npm-version.json -o samples/client/petstore/typescript-fetch/builds/with-npm-version $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/builds/with-npm-version/pom.xml samples/client/petstore/typescript-fetch/builds/with-npm-version/pom.xml
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/tests/default/pom.xml samples/client/petstore/typescript-fetch/tests/default/pom.xml
|
||||
@@ -30,3 +30,5 @@ export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-fetch -o samples/client/petstore/typescript-fetch/builds/default $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/builds/default/pom.xml samples/client/petstore/typescript-fetch/builds/default/pom.xml
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/tests/default/pom.xml samples/client/petstore/typescript-fetch/tests/default/pom.xml
|
||||
@@ -11,6 +11,7 @@ sleep 5
|
||||
|
||||
# LIST OF SCRIPTS:
|
||||
declare -a scripts=("./bin/openapi3/ruby-client-petstore.sh"
|
||||
"./bin/ruby-client-petstore.sh"
|
||||
"./bin/java-petstore-all.sh"
|
||||
"./bin/java-jaxrs-petstore-server-all.sh"
|
||||
"./bin/openapi3/jaxrs-jersey-petstore.sh"
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
#release_chekcout.rb
|
||||
#!/usr/bin/env ruby
|
||||
#
|
||||
# release_chekcout.rb
|
||||
#
|
||||
require 'rubygems'
|
||||
require 'open-uri'
|
||||
require 'net/http'
|
||||
|
||||
def check_npmjs
|
||||
print "Checking npmjs... "
|
||||
|
||||
url = "https://www.npmjs.com/package/@openapitools/openapi-generator-cli?activeTab=versions"
|
||||
open(url) do |f|
|
||||
content = f.read
|
||||
if !content.nil? && content.include?($version)
|
||||
puts "[OK]"
|
||||
else
|
||||
puts "[ERROR]"
|
||||
puts "> #{url} not yet updated with #{$version}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_homebrew
|
||||
print "Checking homebrew forumla ... "
|
||||
|
||||
@@ -184,6 +202,7 @@ $version = ARGV[0]
|
||||
|
||||
puts "Running checkout on OpenAPI Generator release #{$version}"
|
||||
|
||||
check_npmjs
|
||||
check_homebrew
|
||||
check_openapi_generator_jar
|
||||
check_openapi_generator_cli_jar
|
||||
|
||||
10
bin/windows/c-petstore.bat
Executable file
10
bin/windows/c-petstore.bat
Executable file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g c -o samples\client\petstore\c
|
||||
|
||||
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-qt5 -o samples\client\petstore\cpp-qt5
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-qt5-client -o samples\client\petstore\cpp-qt5
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
10
bin/windows/dukescript-petstore.bat
Normal file
10
bin/windows/dukescript-petstore.bat
Normal file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g dukescript -o samples\client\petstore\dukescript
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
10
bin/windows/graphql-petstore-server.bat
Executable file
10
bin/windows/graphql-petstore-server.bat
Executable file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -t modules\openapi-generator\src\main\resources\graphql-server -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g graphql-server -o samples\server\petstore\graphql-server
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
10
bin/windows/graphql-schema-petstore.bat
Executable file
10
bin/windows/graphql-schema-petstore.bat
Executable file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -t modules\openapi-generator\src\main\resources\graphql-schema -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g graphql-schema -o samples\config\petstore\graphql-schema
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -7,5 +7,8 @@ call .\bin\windows\typescript-angular-v6-provided-in-root.bat
|
||||
call .\bin\windows\typescript-angular-v6-provided-in-root-with-npm.bat
|
||||
call .\bin\windows\typescript-angular-v6-not-provided-in-root.bat
|
||||
call .\bin\windows\typescript-angular-v6-not-provided-in-root-with-npm.bat
|
||||
|
||||
call .\bin\windows\typescript-angular-v7-provided-in-root.bat
|
||||
call .\bin\windows\typescript-angular-v7-provided-in-root-with-npm.bat
|
||||
call .\bin\windows\typescript-angular-v7-not-provided-in-root.bat
|
||||
call .\bin\windows\typescript-angular-v7-not-provided-in-root-with-npm.bat
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l typescript-angular -c bin\typescript-angular-v7-petstore-not-provided-in-root-with-npm.json -o samples\client\petstore\typescript-angular-v7-not-provided-in-root\builds\with-npm -D providedInRoot=false --additional-properties ngVersion=7.0.0
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
10
bin/windows/typescript-angular-v7-not-provided-in-root.bat
Normal file
10
bin/windows/typescript-angular-v7-not-provided-in-root.bat
Normal file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l typescript-angular -o samples\client\petstore\typescript-angular-v7-not-provided-in-root\builds\default -D providedInRoot=false --additional-properties ngVersion=7.0.0
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -0,0 +1,9 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l typescript-angular -c bin/typescript-angular-v7-petstore-provided-in-root-with-npm.json -o samples\client\petstore\typescript-angular-v7-provided-in-root\builds\with-npm --additional-properties ngVersion=7.0.0
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
9
bin/windows/typescript-angular-v7-provided-in-root.bat
Normal file
9
bin/windows/typescript-angular-v7-provided-in-root.bat
Normal file
@@ -0,0 +1,9 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l typescript-angular -o samples\client\petstore\typescript-angular-v7-provided-in-root\builds\default --additional-properties ngVersion=7.0.0
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -17,7 +17,7 @@ CONFIG OPTIONS for clojure
|
||||
name of the project (Default: generated from info.title or "openapi-clj-client")
|
||||
|
||||
projectDescription
|
||||
description of the project (Default: using info.description or "Client library of <projectNname>")
|
||||
description of the project (Default: using info.description or "Client library of <projectName>")
|
||||
|
||||
projectVersion
|
||||
version of the project (Default: using info.version or "1.0.0")
|
||||
|
||||
@@ -16,4 +16,7 @@ CONFIG OPTIONS for cpp-qt5-qhttpengine-server
|
||||
cppNamespace
|
||||
C++ namespace (convention: name::space::for::api). (Default: OpenAPI)
|
||||
|
||||
cppNamespace
|
||||
C++ namespace (convention: name::space::for::api). (Default: OpenAPI)
|
||||
|
||||
Back to the [generators list](README.md)
|
||||
|
||||
@@ -34,4 +34,7 @@ CONFIG OPTIONS for dart-jaguar
|
||||
supportDart2
|
||||
support dart2 (Default: true)
|
||||
|
||||
nullableFields
|
||||
Is the null fields should be in the JSON payload
|
||||
|
||||
Back to the [generators list](README.md)
|
||||
|
||||
@@ -9,4 +9,10 @@ CONFIG OPTIONS for elm
|
||||
elmPrefixCustomTypeVariants
|
||||
Prefix custom type variants (Default: false)
|
||||
|
||||
elmEnableCustomBasePaths
|
||||
Enable setting the base path for each request (Default: false)
|
||||
|
||||
elmEnableHttpRequestTrackers
|
||||
Enable adding a tracker to each http request (Default: false)
|
||||
|
||||
Back to the [generators list](README.md)
|
||||
|
||||
@@ -28,4 +28,9 @@ CONFIG OPTIONS for kotlin
|
||||
java8 - Java 8 native JSR310
|
||||
threetenbp - Threetenbp
|
||||
|
||||
collectionType
|
||||
Option. Collection type to use
|
||||
array - kotlin.Array
|
||||
list - kotlin.collections.List
|
||||
|
||||
Back to the [generators list](README.md)
|
||||
|
||||
@@ -170,6 +170,9 @@ CONFIG OPTIONS for spring
|
||||
hateoas
|
||||
Use Spring HATEOAS library to allow adding HATEOAS links (Default: false)
|
||||
|
||||
returnSuccessCode
|
||||
Generated server returns 2xx code (Default: false)
|
||||
|
||||
library
|
||||
library template (sub-template) to use (Default: spring-boot)
|
||||
spring-boot - Spring-boot Server application using the SpringFox integration.
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
## Online OpenAPI generator
|
||||
|
||||
One can also generate API client or server using the online openapi-generator.
|
||||
One can also generate API clients or server stubs using the online openapi-generator.
|
||||
|
||||
Here are the steps to run it locally:
|
||||
Here are the public online services:
|
||||
|
||||
- latest stable version: http://api.openapi-generator.tech
|
||||
- latest master: http://api-latest-master.openapi-generator.tech (updated with latest master every hour)
|
||||
|
||||
The server is sponsored by [Linode](https://www.linode.com/) [](https://www.linode.com/)
|
||||
|
||||
(These services are beta and do not have any guarantee on service level)
|
||||
|
||||
If you prefer to run the service locally, here are the steps:
|
||||
```
|
||||
mvn clean install
|
||||
cd modules/openapi-generator-online
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
|
||||
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.*;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
@@ -246,6 +247,11 @@ public class Generate implements Runnable {
|
||||
}
|
||||
|
||||
if (isNotEmpty(spec)) {
|
||||
if (!spec.matches("^http(s)?://.*") && !new File(spec).exists()) {
|
||||
System.err.println("[error] The spec file is not found: " + spec);
|
||||
System.err.println("[error] Check the path of the OpenAPI spec and try again.");
|
||||
System.exit(1);
|
||||
}
|
||||
configurator.setInputSpec(spec);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class GenerateTest {
|
||||
|
||||
@Test
|
||||
public void testRequiredArgs_ShortArgs() throws Exception {
|
||||
setupAndRunTest("-i", "swagger.yaml", "-g", "java", "-o", "src/main/java", false, null);
|
||||
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", false, null);
|
||||
new FullVerifications() {
|
||||
{
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class GenerateTest {
|
||||
|
||||
@Test
|
||||
public void testRequiredArgs_LongArgs() throws Exception {
|
||||
setupAndRunTest("--input-spec", "swagger.yaml", "--generator-name", "java", "--output",
|
||||
setupAndRunTest("--input-spec", "src/test/resources/swagger.yaml", "--generator-name", "java", "--output",
|
||||
"src/main/java", false, null);
|
||||
new FullVerifications() {
|
||||
{
|
||||
@@ -220,7 +220,7 @@ public class GenerateTest {
|
||||
@Test
|
||||
public void testConfig() throws Exception {
|
||||
|
||||
setupAndRunTest("-i", "swagger.yaml", "-g", "java", "-o", "src/main/java", true,
|
||||
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", true,
|
||||
"config.json", "-c", "config.json");
|
||||
|
||||
new FullVerifications() {
|
||||
@@ -228,7 +228,7 @@ public class GenerateTest {
|
||||
}
|
||||
};
|
||||
|
||||
setupAndRunTest("-i", "swagger.yaml", "-g", "java", "-o", "src/main/java", true,
|
||||
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", true,
|
||||
"config.json", "--config", "config.json");
|
||||
|
||||
new FullVerifications() {
|
||||
@@ -570,7 +570,7 @@ public class GenerateTest {
|
||||
}
|
||||
|
||||
private void setupAndRunGenericTest(String... additionalParameters) {
|
||||
setupAndRunTest("-i", "swagger.yaml", "-g", "java", "-o", "src/main/java", false, null,
|
||||
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", false, null,
|
||||
additionalParameters);
|
||||
}
|
||||
}
|
||||
|
||||
109
modules/openapi-generator-cli/src/test/resources/swagger.yaml
Normal file
109
modules/openapi-generator-cli/src/test/resources/swagger.yaml
Normal file
@@ -0,0 +1,109 @@
|
||||
openapi: "3.0.0"
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: Swagger Petstore
|
||||
license:
|
||||
name: MIT
|
||||
servers:
|
||||
- url: http://petstore.swagger.io/v1
|
||||
paths:
|
||||
/pets:
|
||||
get:
|
||||
summary: List all pets
|
||||
operationId: listPets
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
description: How many items to return at one time (max 100)
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: A paged array of pets
|
||||
headers:
|
||||
x-next:
|
||||
description: A link to the next page of responses
|
||||
schema:
|
||||
type: string
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
summary: Create a pet
|
||||
operationId: createPets
|
||||
tags:
|
||||
- pets
|
||||
responses:
|
||||
'201':
|
||||
description: Null response
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/pets/{petId}:
|
||||
get:
|
||||
summary: Info for a specific pet
|
||||
operationId: showPetById
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
required: true
|
||||
description: The id of the pet to retrieve
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: Expected response to a valid request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
Pet:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
Pets:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Pet"
|
||||
Error:
|
||||
required:
|
||||
- code
|
||||
- message
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
@@ -48,7 +48,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:3.3.3"
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:3.3.4"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.invoke
|
||||
import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorGenerateExtension
|
||||
import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorMetaExtension
|
||||
import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorValidateExtension
|
||||
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
|
||||
import org.openapitools.generator.gradle.plugin.tasks.GeneratorsTask
|
||||
import org.openapitools.generator.gradle.plugin.tasks.MetaTask
|
||||
import org.openapitools.generator.gradle.plugin.tasks.ValidateTask
|
||||
|
||||
/**
|
||||
* A plugin providing common Open API Generator use cases.
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
@Suppress("unused")
|
||||
class OpenApiGeneratorPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
project.run {
|
||||
val meta = extensions.create(
|
||||
"openApiMeta",
|
||||
OpenApiGeneratorMetaExtension::class.java,
|
||||
project
|
||||
)
|
||||
|
||||
val validate = extensions.create(
|
||||
"openApiValidate",
|
||||
OpenApiGeneratorValidateExtension::class.java,
|
||||
project
|
||||
)
|
||||
|
||||
val generate = extensions.create(
|
||||
"openApiGenerate",
|
||||
OpenApiGeneratorGenerateExtension::class.java,
|
||||
project
|
||||
)
|
||||
|
||||
generate.outputDir.set("$buildDir/generate-resources/main")
|
||||
|
||||
tasks {
|
||||
"openApiGenerators"(GeneratorsTask::class) {
|
||||
group = pluginGroup
|
||||
description = "Lists generators available via Open API Generators."
|
||||
}
|
||||
"openApiMeta"(MetaTask::class) {
|
||||
group = pluginGroup
|
||||
description = "Generates a new generator to be consumed via Open API Generator."
|
||||
|
||||
generatorName.set(meta.generatorName)
|
||||
packageName.set(meta.packageName)
|
||||
outputFolder.set(meta.outputFolder)
|
||||
}
|
||||
"openApiValidate"(ValidateTask::class) {
|
||||
group = pluginGroup
|
||||
description = "Validates an Open API 2.0 or 3.x specification document."
|
||||
|
||||
inputSpec.set(validate.inputSpec)
|
||||
}
|
||||
"openApiGenerate"(GenerateTask::class) {
|
||||
group = pluginGroup
|
||||
description = "Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents."
|
||||
|
||||
verbose.set(generate.verbose)
|
||||
validateSpec.set(generate.validateSpec)
|
||||
generatorName.set(generate.generatorName)
|
||||
outputDir.set(generate.outputDir)
|
||||
inputSpec.set(generate.inputSpec)
|
||||
templateDir.set(generate.templateDir)
|
||||
auth.set(generate.auth)
|
||||
systemProperties.set(generate.systemProperties)
|
||||
configFile.set(generate.configFile)
|
||||
skipOverwrite.set(generate.skipOverwrite)
|
||||
apiPackage.set(generate.apiPackage)
|
||||
modelPackage.set(generate.modelPackage)
|
||||
modelNamePrefix.set(generate.modelNamePrefix)
|
||||
modelNameSuffix.set(generate.modelNameSuffix)
|
||||
instantiationTypes.set(generate.instantiationTypes)
|
||||
typeMappings.set(generate.typeMappings)
|
||||
additionalProperties.set(generate.additionalProperties)
|
||||
languageSpecificPrimitives.set(generate.languageSpecificPrimitives)
|
||||
importMappings.set(generate.importMappings)
|
||||
invokerPackage.set(generate.invokerPackage)
|
||||
groupId.set(generate.groupId)
|
||||
id.set(generate.id)
|
||||
version.set(generate.version)
|
||||
library.set(generate.library)
|
||||
gitUserId.set(generate.gitUserId)
|
||||
gitRepoId.set(generate.gitRepoId)
|
||||
releaseNote.set(generate.releaseNote)
|
||||
httpUserAgent.set(generate.httpUserAgent)
|
||||
reservedWordsMappings.set(generate.reservedWordsMappings)
|
||||
ignoreFileOverride.set(generate.ignoreFileOverride)
|
||||
removeOperationIdPrefix.set(generate.removeOperationIdPrefix)
|
||||
apiFilesConstrainedTo.set(generate.apiFilesConstrainedTo)
|
||||
modelFilesConstrainedTo.set(generate.modelFilesConstrainedTo)
|
||||
supportingFilesConstrainedTo.set(generate.supportingFilesConstrainedTo)
|
||||
generateModelTests.set(generate.generateModelTests)
|
||||
generateModelDocumentation.set(generate.generateModelDocumentation)
|
||||
generateApiTests.set(generate.generateApiTests)
|
||||
generateApiDocumentation.set(generate.generateApiDocumentation)
|
||||
withXml.set(generate.withXml)
|
||||
configOptions.set(generate.configOptions)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val pluginGroup = "OpenAPI Tools"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.extensions
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.listProperty
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
/**
|
||||
* Gradle project level extension object definition for the generate task
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
|
||||
/**
|
||||
* The verbosity of generation
|
||||
*/
|
||||
val verbose = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Whether or not an input specification should be validated upon generation.
|
||||
*/
|
||||
val validateSpec = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* The name of the generator which will handle codegen. (see "openApiGenerators" task)
|
||||
*/
|
||||
val generatorName = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The output target directory into which code will be generated.
|
||||
*/
|
||||
val outputDir = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The Open API 2.0/3.x specification location.
|
||||
*/
|
||||
val inputSpec = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The template directory holding a custom template.
|
||||
*/
|
||||
val templateDir = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Adds authorization headers when fetching the OpenAPI definitions remotely.
|
||||
* Pass in a URL-encoded string of name:header with a comma separating multiple values
|
||||
*/
|
||||
val auth = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Sets specified system properties.
|
||||
*/
|
||||
val systemProperties = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Path to json configuration file.
|
||||
* File content should be in a json format { "optionKey":"optionValue", "optionKey1":"optionValue1"...}
|
||||
* Supported options can be different for each language. Run config-help -g {generator name} command for language specific config options.
|
||||
*/
|
||||
val configFile = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Specifies if the existing files should be overwritten during the generation.
|
||||
*/
|
||||
val skipOverwrite = project.objects.property<Boolean?>()
|
||||
|
||||
/**
|
||||
* Package for generated api classes
|
||||
*/
|
||||
val apiPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Package for generated models
|
||||
*/
|
||||
val modelPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Prefix that will be prepended to all model names. Default is the empty string.
|
||||
*/
|
||||
val modelNamePrefix = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Suffix that will be appended to all model names. Default is the empty string.
|
||||
*/
|
||||
val modelNameSuffix = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Sets instantiation type mappings.
|
||||
*/
|
||||
val instantiationTypes = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Sets mappings between OpenAPI spec types and generated code types.
|
||||
*/
|
||||
val typeMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Sets additional properties that can be referenced by the mustache templates.
|
||||
*/
|
||||
val additionalProperties = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double.
|
||||
*/
|
||||
val languageSpecificPrimitives = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Specifies mappings between a given class and the import that should be used for that class.
|
||||
*/
|
||||
val importMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Root package for generated code.
|
||||
*/
|
||||
val invokerPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* GroupId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
val groupId = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* ArtifactId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
val id = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Artifact version in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
val version = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Reference the library template (sub-template) of a generator.
|
||||
*/
|
||||
val library = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Git user ID, e.g. openapitools.
|
||||
*/
|
||||
val gitUserId = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Git repo ID, e.g. openapi-generator.
|
||||
*/
|
||||
val gitRepoId = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Release note, default to 'Minor update'.
|
||||
*/
|
||||
val releaseNote = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}}/{language}'
|
||||
*/
|
||||
val httpUserAgent = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Specifies how a reserved name should be escaped to. Otherwise, the default _<name> is used.
|
||||
*/
|
||||
val reservedWordsMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Specifies an override location for the .openapi-generator-ignore file. Most useful on initial generation.
|
||||
*/
|
||||
val ignoreFileOverride = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Remove prefix of operationId, e.g. config_getId => getId
|
||||
*/
|
||||
val removeOperationIdPrefix = project.objects.property<Boolean?>()
|
||||
|
||||
/**
|
||||
* Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val apiFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines which model-related files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val modelFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines which supporting files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* Supporting files are those related to projects/frameworks which may be modified
|
||||
* by consumers.
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val supportingFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines whether or not model-related _test_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL model-related _test_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val generateModelTests = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not model-related _documentation_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL model-related _documentation_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val generateModelDocumentation = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not api-related _test_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL api-related _test_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val generateApiTests = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not api-related _documentation_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL api-related _documentation_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val generateApiDocumentation = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* A special-case setting which configures some generators with XML support. In some cases,
|
||||
* this forces json OR xml, so the default here is false.
|
||||
*/
|
||||
val withXml = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* A map of options specific to a generator.
|
||||
*/
|
||||
val configOptions = project.objects.property<Map<String, String>>()
|
||||
|
||||
init {
|
||||
applyDefaults()
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
fun applyDefaults(){
|
||||
releaseNote.set("Minor update")
|
||||
modelNamePrefix.set("")
|
||||
modelNameSuffix.set("")
|
||||
generateModelTests.set(true)
|
||||
generateModelDocumentation.set(true)
|
||||
generateApiTests.set(true)
|
||||
generateApiDocumentation.set(true)
|
||||
withXml.set(false)
|
||||
configOptions.set(mapOf())
|
||||
validateSpec.set(true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.extensions
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
/**
|
||||
* Gradle project level extension object definition for the meta-generator task
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class OpenApiGeneratorMetaExtension(project: Project) {
|
||||
/**
|
||||
* The human-readable generator name of the newly created template generator.
|
||||
*/
|
||||
val generatorName = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The packageName generatorName to put the main class into (defaults to org.openapitools.codegen)
|
||||
*/
|
||||
val packageName = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Where to write the generated files (current dir by default).
|
||||
*/
|
||||
val outputFolder = project.objects.property<String>()
|
||||
|
||||
init {
|
||||
generatorName.set("default")
|
||||
packageName.set("org.openapitools.codegen")
|
||||
outputFolder.set("")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.extensions
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
/**
|
||||
* Gradle project level extension object definition for the generators task
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class OpenApiGeneratorValidateExtension(project: Project) {
|
||||
/**
|
||||
* The input specification to validate. Supports all formats supported by the Parser.
|
||||
*/
|
||||
val inputSpec = project.objects.property<String>()
|
||||
}
|
||||
@@ -0,0 +1,554 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.internal.logging.text.StyledTextOutput
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
import org.gradle.kotlin.dsl.listProperty
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import org.openapitools.codegen.CodegenConstants
|
||||
import org.openapitools.codegen.DefaultGenerator
|
||||
import org.openapitools.codegen.config.CodegenConfigurator
|
||||
|
||||
|
||||
/**
|
||||
* A task which generates the desired code.
|
||||
*
|
||||
* Example (CLI):
|
||||
*
|
||||
* ./gradlew -q openApiGenerate
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class GenerateTask : DefaultTask() {
|
||||
|
||||
/**
|
||||
* The verbosity of generation
|
||||
*/
|
||||
@get:Internal
|
||||
val verbose = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Whether or not an input specification should be validated upon generation.
|
||||
*/
|
||||
@get:Internal
|
||||
val validateSpec = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* The name of the generator which will handle codegen. (see "openApiGenerators" task)
|
||||
*/
|
||||
@get:Internal
|
||||
val generatorName = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The output target directory into which code will be generated.
|
||||
*/
|
||||
@get:Internal
|
||||
val outputDir = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The Open API 2.0/3.x specification location.
|
||||
*/
|
||||
@get:Internal
|
||||
val inputSpec = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The template directory holding a custom template.
|
||||
*/
|
||||
@get:Internal
|
||||
val templateDir = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Adds authorization headers when fetching the OpenAPI definitions remotely.
|
||||
* Pass in a URL-encoded string of name:header with a comma separating multiple values
|
||||
*/
|
||||
@get:Internal
|
||||
val auth = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Sets specified system properties.
|
||||
*/
|
||||
@get:Internal
|
||||
val systemProperties = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Path to json configuration file.
|
||||
* File content should be in a json format { "optionKey":"optionValue", "optionKey1":"optionValue1"...}
|
||||
* Supported options can be different for each language. Run config-help -g {generator name} command for language specific config options.
|
||||
*/
|
||||
@get:Internal
|
||||
val configFile = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Specifies if the existing files should be overwritten during the generation.
|
||||
*/
|
||||
@get:Internal
|
||||
val skipOverwrite = project.objects.property<Boolean?>()
|
||||
|
||||
/**
|
||||
* Package for generated api classes
|
||||
*/
|
||||
@get:Internal
|
||||
val apiPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Package for generated models
|
||||
*/
|
||||
@get:Internal
|
||||
val modelPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Prefix that will be prepended to all model names. Default is the empty string.
|
||||
*/
|
||||
@get:Internal
|
||||
val modelNamePrefix = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Suffix that will be appended to all model names. Default is the empty string.
|
||||
*/
|
||||
@get:Internal
|
||||
val modelNameSuffix = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Sets instantiation type mappings.
|
||||
*/
|
||||
@get:Internal
|
||||
val instantiationTypes = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Sets mappings between OpenAPI spec types and generated code types.
|
||||
*/
|
||||
@get:Internal
|
||||
val typeMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value.
|
||||
* You can also have multiple occurrences of this option.
|
||||
*/
|
||||
@get:Internal
|
||||
val additionalProperties = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double.
|
||||
*/
|
||||
@get:Internal
|
||||
val languageSpecificPrimitives = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Specifies mappings between a given class and the import that should be used for that class.
|
||||
*/
|
||||
@get:Internal
|
||||
val importMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Root package for generated code.
|
||||
*/
|
||||
@get:Internal
|
||||
val invokerPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* GroupId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
@get:Internal
|
||||
val groupId = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* ArtifactId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
@get:Internal
|
||||
val id = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Artifact version in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
@get:Internal
|
||||
val version = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Reference the library template (sub-template) of a generator.
|
||||
*/
|
||||
@get:Internal
|
||||
val library = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Git user ID, e.g. openapitools.
|
||||
*/
|
||||
@get:Internal
|
||||
val gitUserId = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Git repo ID, e.g. openapi-generator.
|
||||
*/
|
||||
@get:Internal
|
||||
val gitRepoId = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Release note, default to 'Minor update'.
|
||||
*/
|
||||
@get:Internal
|
||||
val releaseNote = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}}/{language}'
|
||||
*/
|
||||
@get:Internal
|
||||
val httpUserAgent = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Specifies how a reserved name should be escaped to.
|
||||
*/
|
||||
@get:Internal
|
||||
val reservedWordsMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Specifies an override location for the .openapi-generator-ignore file. Most useful on initial generation.
|
||||
*/
|
||||
@get:Internal
|
||||
val ignoreFileOverride = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Remove prefix of operationId, e.g. config_getId => getId
|
||||
*/
|
||||
@get:Internal
|
||||
val removeOperationIdPrefix = project.objects.property<Boolean?>()
|
||||
|
||||
/**
|
||||
* Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* This option enables/disables generation of ALL api-related files.
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val apiFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines which model-related files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val modelFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines which supporting files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* Supporting files are those related to projects/frameworks which may be modified
|
||||
* by consumers.
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val supportingFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines whether or not model-related _test_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL model-related _test_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val generateModelTests = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not model-related _documentation_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL model-related _documentation_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val generateModelDocumentation = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not api-related _test_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL api-related _test_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val generateApiTests = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not api-related _documentation_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL api-related _documentation_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val generateApiDocumentation = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* A special-case setting which configures some generators with XML support. In some cases,
|
||||
* this forces json OR xml, so the default here is false.
|
||||
*/
|
||||
@get:Internal
|
||||
val withXml = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* A dynamic map of options specific to a generator.
|
||||
*/
|
||||
@get:Internal
|
||||
val configOptions = project.objects.property<Map<String, String>>()
|
||||
|
||||
private val originalEnvironmentVariables = mutableMapOf<String, String?>()
|
||||
|
||||
private fun <T : Any?> Property<T>.ifNotEmpty(block: Property<T>.(T) -> Unit) {
|
||||
if (isPresent) {
|
||||
val item: T? = get()
|
||||
if (item != null) {
|
||||
when (get()) {
|
||||
is String -> if ((get() as String).isNotEmpty()) {
|
||||
block(get())
|
||||
}
|
||||
is String? -> if (true == (get() as String?)?.isNotEmpty()) {
|
||||
block(get())
|
||||
}
|
||||
else -> block(get())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
@TaskAction
|
||||
fun doWork() {
|
||||
val configurator: CodegenConfigurator = if (configFile.isPresent) {
|
||||
CodegenConfigurator.fromFile(configFile.get())
|
||||
} else CodegenConfigurator()
|
||||
|
||||
try {
|
||||
if (systemProperties.isPresent) {
|
||||
systemProperties.get().forEach { (key, value) ->
|
||||
// System.setProperty returns the original value for a key, or null.
|
||||
// Cache the original value or null…we will late put the properties back in their original state.
|
||||
originalEnvironmentVariables[key] = System.setProperty(key, value)
|
||||
configurator.addSystemProperty(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
if (supportingFilesConstrainedTo.isPresent && supportingFilesConstrainedTo.get().isNotEmpty()) {
|
||||
System.setProperty(CodegenConstants.SUPPORTING_FILES, supportingFilesConstrainedTo.get().joinToString(","))
|
||||
} else {
|
||||
System.clearProperty(CodegenConstants.SUPPORTING_FILES)
|
||||
}
|
||||
|
||||
if (modelFilesConstrainedTo.isPresent && modelFilesConstrainedTo.get().isNotEmpty()) {
|
||||
System.setProperty(CodegenConstants.MODELS, modelFilesConstrainedTo.get().joinToString(","))
|
||||
} else {
|
||||
System.clearProperty(CodegenConstants.MODELS)
|
||||
}
|
||||
|
||||
if (apiFilesConstrainedTo.isPresent && apiFilesConstrainedTo.get().isNotEmpty()) {
|
||||
System.setProperty(CodegenConstants.APIS, apiFilesConstrainedTo.get().joinToString(","))
|
||||
} else {
|
||||
System.clearProperty(CodegenConstants.APIS)
|
||||
}
|
||||
|
||||
System.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.get().toString())
|
||||
System.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.get().toString())
|
||||
System.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.get().toString())
|
||||
System.setProperty(CodegenConstants.API_TESTS, generateApiTests.get().toString())
|
||||
System.setProperty(CodegenConstants.WITH_XML, withXml.get().toString())
|
||||
|
||||
// now override with any specified parameters
|
||||
verbose.ifNotEmpty { value ->
|
||||
configurator.isVerbose = value
|
||||
}
|
||||
|
||||
validateSpec.ifNotEmpty { value ->
|
||||
configurator.isValidateSpec = value
|
||||
}
|
||||
|
||||
skipOverwrite.ifNotEmpty { value ->
|
||||
configurator.isSkipOverwrite = value ?: false
|
||||
}
|
||||
|
||||
inputSpec.ifNotEmpty { value ->
|
||||
configurator.inputSpec = value
|
||||
}
|
||||
|
||||
generatorName.ifNotEmpty { value ->
|
||||
configurator.generatorName = value
|
||||
}
|
||||
|
||||
outputDir.ifNotEmpty { value ->
|
||||
configurator.outputDir = value
|
||||
}
|
||||
|
||||
auth.ifNotEmpty { value ->
|
||||
configurator.auth = value
|
||||
}
|
||||
|
||||
templateDir.ifNotEmpty { value ->
|
||||
configurator.templateDir = value
|
||||
}
|
||||
|
||||
apiPackage.ifNotEmpty { value ->
|
||||
configurator.apiPackage = value
|
||||
}
|
||||
|
||||
modelPackage.ifNotEmpty { value ->
|
||||
configurator.modelPackage = value
|
||||
}
|
||||
|
||||
modelNamePrefix.ifNotEmpty { value ->
|
||||
configurator.modelNamePrefix = value
|
||||
}
|
||||
|
||||
modelNameSuffix.ifNotEmpty { value ->
|
||||
configurator.modelNameSuffix = value
|
||||
}
|
||||
|
||||
invokerPackage.ifNotEmpty { value ->
|
||||
configurator.invokerPackage = value
|
||||
}
|
||||
|
||||
groupId.ifNotEmpty { value ->
|
||||
configurator.groupId = value
|
||||
}
|
||||
|
||||
id.ifNotEmpty { value ->
|
||||
configurator.artifactId = value
|
||||
}
|
||||
|
||||
version.ifNotEmpty { value ->
|
||||
configurator.artifactVersion = value
|
||||
}
|
||||
|
||||
library.ifNotEmpty { value ->
|
||||
configurator.library = value
|
||||
}
|
||||
|
||||
gitUserId.ifNotEmpty { value ->
|
||||
configurator.gitUserId = value
|
||||
}
|
||||
|
||||
gitRepoId.ifNotEmpty { value ->
|
||||
configurator.gitRepoId = value
|
||||
}
|
||||
|
||||
releaseNote.ifNotEmpty { value ->
|
||||
configurator.releaseNote = value
|
||||
}
|
||||
|
||||
httpUserAgent.ifNotEmpty { value ->
|
||||
configurator.httpUserAgent = value
|
||||
}
|
||||
|
||||
ignoreFileOverride.ifNotEmpty { value ->
|
||||
configurator.ignoreFileOverride = value
|
||||
}
|
||||
|
||||
removeOperationIdPrefix.ifNotEmpty { value ->
|
||||
configurator.removeOperationIdPrefix = value!!
|
||||
}
|
||||
|
||||
if (systemProperties.isPresent) {
|
||||
systemProperties.get().forEach { entry ->
|
||||
configurator.addSystemProperty(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (instantiationTypes.isPresent) {
|
||||
instantiationTypes.get().forEach { entry ->
|
||||
configurator.addInstantiationType(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (importMappings.isPresent) {
|
||||
importMappings.get().forEach { entry ->
|
||||
configurator.addImportMapping(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (typeMappings.isPresent) {
|
||||
typeMappings.get().forEach { entry ->
|
||||
configurator.addTypeMapping(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalProperties.isPresent) {
|
||||
additionalProperties.get().forEach { entry ->
|
||||
configurator.addAdditionalProperty(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (languageSpecificPrimitives.isPresent) {
|
||||
languageSpecificPrimitives.get().forEach {
|
||||
configurator.addLanguageSpecificPrimitive(it)
|
||||
}
|
||||
}
|
||||
|
||||
if (reservedWordsMappings.isPresent) {
|
||||
reservedWordsMappings.get().forEach { entry ->
|
||||
configurator.addAdditionalReservedWordMapping(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
val clientOptInput = configurator.toClientOptInput()
|
||||
val codgenConfig = clientOptInput.config
|
||||
|
||||
if (configOptions.isPresent) {
|
||||
val userSpecifiedConfigOptions = configOptions.get()
|
||||
codgenConfig.cliOptions().forEach {
|
||||
if (userSpecifiedConfigOptions.containsKey(it.opt)) {
|
||||
clientOptInput.config.additionalProperties()[it.opt] = userSpecifiedConfigOptions[it.opt]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
val out = services.get(StyledTextOutputFactory::class.java).create("openapi")
|
||||
out.withStyle(StyledTextOutput.Style.Success)
|
||||
|
||||
DefaultGenerator().opts(clientOptInput).generate()
|
||||
|
||||
out.println("Successfully generated code to ${configurator.outputDir}")
|
||||
} catch (e: RuntimeException) {
|
||||
throw GradleException("Code generation failed.", e)
|
||||
}
|
||||
} finally {
|
||||
// Reset all modified system properties back to their original state
|
||||
originalEnvironmentVariables.forEach {
|
||||
when {
|
||||
it.value == null -> System.clearProperty(it.key)
|
||||
else -> System.setProperty(it.key, it.value)
|
||||
}
|
||||
}
|
||||
originalEnvironmentVariables.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.internal.logging.text.StyledTextOutput
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
import org.openapitools.codegen.CodegenConfigLoader
|
||||
import org.openapitools.codegen.CodegenType
|
||||
|
||||
/**
|
||||
* A task which lists out the generators available in OpenAPI Generator
|
||||
*
|
||||
* Example (CLI):
|
||||
*
|
||||
* ./gradlew -q openApiGenerators
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class GeneratorsTask : DefaultTask() {
|
||||
@Suppress("unused")
|
||||
@TaskAction
|
||||
fun doWork() {
|
||||
val generators = CodegenConfigLoader.getAll()
|
||||
|
||||
val out = services.get(StyledTextOutputFactory::class.java).create("openapi")
|
||||
|
||||
StringBuilder().apply {
|
||||
val types = CodegenType.values()
|
||||
|
||||
append("The following generators are available:")
|
||||
|
||||
append(System.lineSeparator())
|
||||
append(System.lineSeparator())
|
||||
|
||||
for (type in types) {
|
||||
append(type.name).append(" generators:")
|
||||
append(System.lineSeparator())
|
||||
|
||||
generators.filter { it.tag == type }
|
||||
.sortedBy { it.name }
|
||||
.forEach({ generator ->
|
||||
append(" - ")
|
||||
append(generator.name)
|
||||
append(System.lineSeparator())
|
||||
})
|
||||
|
||||
append(System.lineSeparator())
|
||||
append(System.lineSeparator())
|
||||
}
|
||||
|
||||
out.withStyle(StyledTextOutput.Style.Success)
|
||||
out.formatln("%s%n", toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.tasks
|
||||
|
||||
import com.samskivert.mustache.Mustache
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.internal.logging.text.StyledTextOutput
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import org.openapitools.codegen.CodegenConfig
|
||||
import org.openapitools.codegen.CodegenConstants
|
||||
import org.openapitools.codegen.DefaultGenerator
|
||||
import org.openapitools.codegen.SupportingFile
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.charset.Charset
|
||||
|
||||
/**
|
||||
* A task which generates a new generator (meta). Useful for redistributable generator packages.
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class MetaTask : DefaultTask() {
|
||||
|
||||
@get:Internal
|
||||
val generatorName = project.objects.property<String>()
|
||||
|
||||
@get:Internal
|
||||
val packageName = project.objects.property<String>()
|
||||
|
||||
@get:Internal
|
||||
val outputFolder = project.objects.property<String>()
|
||||
|
||||
@Suppress("unused")
|
||||
@TaskAction
|
||||
fun doWork() {
|
||||
|
||||
val packageToPath = packageName.get().replace(".", File.separator)
|
||||
val dir = File(outputFolder.get())
|
||||
val klass = "${generatorName.get().titleCasedTextOnly()}Generator"
|
||||
|
||||
val templateResourceDir = generatorName.get().hyphenatedTextOnly()
|
||||
|
||||
val out = services.get(StyledTextOutputFactory::class.java).create("openapi")
|
||||
|
||||
out.withStyle(StyledTextOutput.Style.Info)
|
||||
|
||||
logger.debug("package: {}", packageName.get())
|
||||
logger.debug("dir: {}", dir.absolutePath)
|
||||
logger.debug("generator class: {}", klass)
|
||||
|
||||
val supportingFiles = listOf(
|
||||
SupportingFile("pom.mustache", "", "pom.xml"),
|
||||
SupportingFile("generatorClass.mustache", dir("src", "main", "java", packageToPath), "$klass.java"),
|
||||
SupportingFile("README.mustache", "", "README.md"),
|
||||
SupportingFile("api.template", dir("src", "main", "resources", templateResourceDir), "api.mustache"),
|
||||
SupportingFile("model.template", dir("src", "main", "resources", templateResourceDir), "model.mustache"),
|
||||
SupportingFile("myFile.template", dir("src", "main", "resources", templateResourceDir), "myFile.mustache"),
|
||||
SupportingFile("services.mustache", dir("src", "main", "resources", "META-INF", "services"), CodegenConfig::class.java.canonicalName))
|
||||
|
||||
val currentVersion = CodegenConstants::class.java.`package`.implementationVersion
|
||||
|
||||
val data = mapOf("generatorPackage" to packageToPath,
|
||||
"generatorClass" to klass,
|
||||
"name" to templateResourceDir,
|
||||
"fullyQualifiedGeneratorClass" to "${packageName.get()}.$klass",
|
||||
"openapiGeneratorVersion" to currentVersion)
|
||||
|
||||
val generator = DefaultGenerator()
|
||||
supportingFiles.map {
|
||||
try {
|
||||
val destinationFolder = File(File(dir.absolutePath), it.folder)
|
||||
destinationFolder.mkdirs()
|
||||
val outputFile = File(destinationFolder, it.destinationFilename)
|
||||
|
||||
val template = generator.readTemplate(File("codegen", it.templateFile).path)
|
||||
var formatted = template
|
||||
|
||||
if (it.templateFile.endsWith(".mustache")) {
|
||||
formatted = Mustache.compiler()
|
||||
.withLoader(loader(generator))
|
||||
.defaultValue("")
|
||||
.compile(template).execute(data)
|
||||
}
|
||||
|
||||
outputFile.writeText(formatted, Charset.forName("UTF8"))
|
||||
|
||||
out.formatln("Wrote file to %s", outputFile.absolutePath)
|
||||
|
||||
// TODO: register outputs
|
||||
// return outputFile
|
||||
} catch (e: IOException) {
|
||||
logger.error(e.message)
|
||||
throw GradleException("Can't generate project", e)
|
||||
}
|
||||
}
|
||||
out.withStyle(StyledTextOutput.Style.Success)
|
||||
out.formatln("Created generator %s", klass)
|
||||
}
|
||||
|
||||
private fun loader(generator: DefaultGenerator): Mustache.TemplateLoader {
|
||||
return Mustache.TemplateLoader { name ->
|
||||
generator.getTemplateReader("codegen${File.separator}$name.mustache")
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.titleCasedTextOnly(): String =
|
||||
this.split(Regex("[^a-zA-Z0-9]")).joinToString(separator = "", transform = String::capitalize)
|
||||
|
||||
private fun String.hyphenatedTextOnly(): String =
|
||||
this.split(Regex("[^a-zA-Z0-9]")).joinToString(separator = "-", transform = String::toLowerCase)
|
||||
|
||||
private fun dir(vararg parts: String): String =
|
||||
parts.joinToString(separator = File.separator)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.tasks
|
||||
|
||||
import io.swagger.parser.OpenAPIParser
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.options.Option
|
||||
import org.gradle.internal.logging.text.StyledTextOutput
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
/**
|
||||
* A generator which validates an Open API spec. This task outputs a list of validation issues and errors.
|
||||
*
|
||||
* Example:
|
||||
* cli:
|
||||
*
|
||||
* ./gradlew openApiValidate --input=/path/to/file
|
||||
*
|
||||
* build.gradle:
|
||||
*
|
||||
* openApiMeta {
|
||||
* inputSpec = "path/to/spec.yaml"
|
||||
* }
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class ValidateTask : DefaultTask() {
|
||||
@get:Internal
|
||||
var inputSpec = project.objects.property<String>()
|
||||
|
||||
@Suppress("unused")
|
||||
@get:Internal
|
||||
@set:Option(option = "input", description = "The input specification.")
|
||||
var input: String? = null
|
||||
set(value) {
|
||||
inputSpec.set(value)
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
@TaskAction
|
||||
fun doWork() {
|
||||
val spec = inputSpec.get()
|
||||
logger.quiet("Validating spec $spec")
|
||||
val result = OpenAPIParser().readLocation(spec, null, null)
|
||||
val messages = result.messages.toSet()
|
||||
val out = services.get(StyledTextOutputFactory::class.java).create("openapi")
|
||||
|
||||
if (messages.isNotEmpty()) {
|
||||
|
||||
out.withStyle(StyledTextOutput.Style.Error)
|
||||
out.println("\nSpec is invalid.\nIssues:\n")
|
||||
|
||||
messages.forEach {
|
||||
out.withStyle(StyledTextOutput.Style.Error)
|
||||
out.println("\t$it\n")
|
||||
}
|
||||
|
||||
throw GradleException("Validation failed.")
|
||||
} else {
|
||||
out.withStyle(StyledTextOutput.Style.Success)
|
||||
out.println("Spec is valid.")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class GenerateTaskDslTest : TestBase() {
|
||||
override var temp: File = createTempDir(javaClass.simpleName)
|
||||
|
||||
private val defaultBuildGradle = """
|
||||
plugins {
|
||||
id 'org.openapi.generator'
|
||||
}
|
||||
openApiGenerate {
|
||||
generatorName = "kotlin"
|
||||
inputSpec = file("spec.yaml").absolutePath
|
||||
outputDir = file("build/kotlin").absolutePath
|
||||
apiPackage = "org.openapitools.example.api"
|
||||
invokerPackage = "org.openapitools.example.invoker"
|
||||
modelPackage = "org.openapitools.example.model"
|
||||
configOptions = [
|
||||
dateLibrary: "java8"
|
||||
]
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@Test
|
||||
fun `openApiGenerate should create an expected file structure from DSL config`() {
|
||||
// Arrange
|
||||
val projectFiles = mapOf(
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml")
|
||||
)
|
||||
withProject(defaultBuildGradle, projectFiles)
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiGenerate")
|
||||
.withPluginClasspath()
|
||||
.build()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("Successfully generated code to"), "User friendly generate notice is missing.")
|
||||
|
||||
listOf(
|
||||
"build/kotlin/.openapi-generator-ignore",
|
||||
"build/kotlin/docs/PetsApi.md",
|
||||
"build/kotlin/docs/Pets.md",
|
||||
"build/kotlin/docs/Error.md",
|
||||
"build/kotlin/docs/Pet.md",
|
||||
"build/kotlin/README.md",
|
||||
"build/kotlin/build.gradle",
|
||||
"build/kotlin/.openapi-generator/VERSION",
|
||||
"build/kotlin/settings.gradle",
|
||||
"build/kotlin/src/main/kotlin/org/openapitools/example/model/Pets.kt",
|
||||
"build/kotlin/src/main/kotlin/org/openapitools/example/model/Pet.kt",
|
||||
"build/kotlin/src/main/kotlin/org/openapitools/example/model/Error.kt",
|
||||
"build/kotlin/src/main/kotlin/org/openapitools/example/api/PetsApi.kt",
|
||||
"build/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt"
|
||||
).map {
|
||||
val f = File(temp, it)
|
||||
assertTrue(f.exists() && f.isFile, "An expected file was not generated when invoking the generation.")
|
||||
}
|
||||
|
||||
assertEquals(TaskOutcome.SUCCESS, result.task(":openApiGenerate")?.outcome,
|
||||
"Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class GeneratorsTaskDslTest : TestBase() {
|
||||
override var temp: File = createTempDir(javaClass.simpleName)
|
||||
|
||||
@Test
|
||||
fun `openApiGenerators should list generators available to the user`() {
|
||||
// Arrange
|
||||
withProject("""
|
||||
| plugins {
|
||||
| id 'org.openapi.generator'
|
||||
| }
|
||||
""".trimMargin())
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiGenerators")
|
||||
.withPluginClasspath()
|
||||
.build()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("The following generators are available:"), "User friendly generator notice is missing.")
|
||||
assertTrue(result.output.contains("CLIENT generators:"), "Expected client generator header is missing.")
|
||||
assertTrue(result.output.contains("android"), "Spot-checking listed client generators is missing a client generator.")
|
||||
assertTrue(result.output.contains("SERVER generators:"), "Expected server generator header is missing.")
|
||||
assertTrue(result.output.contains("kotlin-server"), "Spot-checking listed server generators is missing a server generator.")
|
||||
assertEquals(TaskOutcome.SUCCESS, result.task(":openApiGenerators")?.outcome,
|
||||
"Expected a successful run, but found ${result.task(":openApiGenerators")?.outcome}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class MetaTaskDslTest : TestBase() {
|
||||
override var temp: File = createTempDir(javaClass.simpleName)
|
||||
|
||||
@Test
|
||||
fun `openApiMeta should generate desired project contents`() {
|
||||
// Arrange
|
||||
val buildDirReplacement = "\$buildDir/meta"
|
||||
withProject("""
|
||||
| plugins {
|
||||
| id 'org.openapi.generator'
|
||||
| }
|
||||
|
|
||||
| openApiMeta {
|
||||
| generatorName = "Sample"
|
||||
| packageName = "org.openapitools.example"
|
||||
| outputFolder = "$buildDirReplacement".toString()
|
||||
| }
|
||||
""".trimMargin())
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiMeta")
|
||||
.withPluginClasspath()
|
||||
.build()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("Wrote file to"), "User friendly write notice is missing.")
|
||||
|
||||
// To avoid any OS-specific output causing issues with our stdout comparisons, only compare on expected filenames.
|
||||
listOf(
|
||||
"SampleGenerator.java",
|
||||
"README.md",
|
||||
"api.mustache",
|
||||
"model.mustache",
|
||||
"myFile.mustache",
|
||||
"org.openapitools.codegen.CodegenConfig",
|
||||
"pom.xml"
|
||||
).map {
|
||||
assertTrue(result.output.contains(it), "Expected $it to be listed in gradle stdout.")
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
TaskOutcome.SUCCESS,
|
||||
result.task(":openApiMeta")?.outcome,
|
||||
"Expected a successful run, but found ${result.task(":openApiMeta")?.outcome}"
|
||||
)
|
||||
}
|
||||
}
|
||||
34
modules/openapi-generator-gradle-plugin/bin/test/TestBase.kt
Normal file
34
modules/openapi-generator-gradle-plugin/bin/test/TestBase.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.testng.annotations.AfterMethod
|
||||
import org.testng.annotations.BeforeMethod
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
abstract class TestBase {
|
||||
protected open lateinit var temp: File
|
||||
|
||||
@BeforeMethod
|
||||
protected fun before() {
|
||||
temp = createTempDir(javaClass.simpleName)
|
||||
temp.deleteOnExit()
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
protected fun after(){
|
||||
temp.deleteRecursively()
|
||||
}
|
||||
|
||||
protected fun withProject(
|
||||
buildContents: String,
|
||||
projectFiles: Map<String, InputStream> = mapOf()
|
||||
) {
|
||||
val buildFile = File(temp,"build.gradle")
|
||||
buildFile.writeText(buildContents)
|
||||
|
||||
projectFiles.forEach { entry ->
|
||||
val target = File(temp, entry.key)
|
||||
entry.value.copyTo(target.outputStream())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.testkit.runner.TaskOutcome.FAILED
|
||||
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class ValidateTaskDslTest : TestBase() {
|
||||
override var temp: File = createTempDir(javaClass.simpleName)
|
||||
|
||||
@Test
|
||||
fun `openApiValidate should fail on non-file spec`() {
|
||||
// Arrange
|
||||
withProject("""
|
||||
| plugins {
|
||||
| id 'org.openapi.generator'
|
||||
| }
|
||||
|
|
||||
| openApiValidate {
|
||||
| inputSpec = "some_location"
|
||||
| }
|
||||
""".trimMargin())
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiValidate")
|
||||
.withPluginClasspath()
|
||||
.buildAndFail()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("unable to read location `some_location`"), "Unexpected/no message presented to the user for a spec pointing to an invalid URI.")
|
||||
assertEquals(FAILED, result.task(":openApiValidate")?.outcome,
|
||||
"Expected a failed run, but found ${result.task(":openApiValidate")?.outcome}")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `openApiValidate should succeed on valid spec`() {
|
||||
// Arrange
|
||||
val projectFiles = mapOf(
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml")
|
||||
)
|
||||
|
||||
withProject("""
|
||||
| plugins {
|
||||
| id 'org.openapi.generator'
|
||||
| }
|
||||
|
|
||||
| openApiValidate {
|
||||
| inputSpec = file("spec.yaml").absolutePath
|
||||
| }
|
||||
""".trimMargin(), projectFiles)
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiValidate")
|
||||
.withPluginClasspath()
|
||||
.build()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("Spec is valid."), "Unexpected/no message presented to the user for a valid spec.")
|
||||
assertEquals(SUCCESS, result.task(":openApiValidate")?.outcome,
|
||||
"Expected a successful run, but found ${result.task(":openApiValidate")?.outcome}")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `openApiValidate should fail on invalid spec`() {
|
||||
// Arrange
|
||||
val projectFiles = mapOf(
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0-invalid.yaml")
|
||||
)
|
||||
withProject("""
|
||||
| plugins {
|
||||
| id 'org.openapi.generator'
|
||||
| }
|
||||
|
|
||||
| openApiValidate {
|
||||
| inputSpec = file('spec.yaml').absolutePath
|
||||
| }
|
||||
""".trimMargin(), projectFiles)
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiValidate")
|
||||
.withPluginClasspath()
|
||||
.buildAndFail()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("Spec is invalid."), "Unexpected/no message presented to the user for an invalid spec.")
|
||||
assertEquals(FAILED, result.task(":openApiValidate")?.outcome,
|
||||
"Expected a failed run, but found ${result.task(":openApiValidate")?.outcome}")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
openapi: "3.0.0"
|
||||
servers:
|
||||
- url: http://petstore.swagger.io/v1
|
||||
paths:
|
||||
/pets:
|
||||
get:
|
||||
summary: List all pets
|
||||
operationId: listPets
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
description: How many items to return at one time (max 100)
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: A paged array of pets
|
||||
headers:
|
||||
x-next:
|
||||
description: A link to the next page of responses
|
||||
schema:
|
||||
type: string
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
summary: Create a pet
|
||||
tags:
|
||||
- pets
|
||||
responses:
|
||||
'201':
|
||||
description: Null response
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/pets/{petId}:
|
||||
get:
|
||||
summary: Info for a specific pet
|
||||
operationId: showPetById
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
required: true
|
||||
description: The id of the pet to retrieve
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: Expected response to a valid request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
Pet:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
Pets:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Pet"
|
||||
Error:
|
||||
required:
|
||||
- code
|
||||
- message
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
@@ -0,0 +1,109 @@
|
||||
openapi: "3.0.0"
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: Swagger Petstore
|
||||
license:
|
||||
name: MIT
|
||||
servers:
|
||||
- url: http://petstore.swagger.io/v1
|
||||
paths:
|
||||
/pets:
|
||||
get:
|
||||
summary: List all pets
|
||||
operationId: listPets
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
description: How many items to return at one time (max 100)
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: A paged array of pets
|
||||
headers:
|
||||
x-next:
|
||||
description: A link to the next page of responses
|
||||
schema:
|
||||
type: string
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
summary: Create a pet
|
||||
operationId: createPets
|
||||
tags:
|
||||
- pets
|
||||
responses:
|
||||
'201':
|
||||
description: Null response
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/pets/{petId}:
|
||||
get:
|
||||
summary: Info for a specific pet
|
||||
operationId: showPetById
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
required: true
|
||||
description: The id of the pet to retrieve
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: Expected response to a valid request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
Pet:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
Pets:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Pet"
|
||||
Error:
|
||||
required:
|
||||
- code
|
||||
- message
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
@@ -1,4 +1,4 @@
|
||||
openApiGeneratorVersion=3.3.3
|
||||
openApiGeneratorVersion=4.0.0-SNAPSHOT
|
||||
|
||||
# BEGIN placeholders
|
||||
# these are just placeholders to allow contributors to build directly
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -17,5 +17,5 @@ gradle generateGoWithInvalidSpec
|
||||
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
|
||||
|
||||
```bash
|
||||
gradle -PopenApiGeneratorVersion=3.3.3 openApiValidate
|
||||
gradle -PopenApiGeneratorVersion=3.3.4 openApiValidate
|
||||
```
|
||||
|
||||
@@ -1 +1 @@
|
||||
openApiGeneratorVersion=3.3.3
|
||||
openApiGeneratorVersion=3.3.4
|
||||
|
||||
@@ -11,7 +11,7 @@ Add to your `build->plugins` section (default phase is `generate-sources` phase)
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<version>3.3.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<version>3.3.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<version>3.3.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<version>3.3.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
|
||||
@@ -56,6 +56,10 @@ import org.sonatype.plexus.build.incremental.DefaultBuildContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
/**
|
||||
* Goal which generates client/server code from a OpenAPI json/yaml definition.
|
||||
*/
|
||||
@@ -317,6 +321,12 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
@Parameter(name = "skip", property = "codegen.skip", required = false, defaultValue = "false")
|
||||
private Boolean skip;
|
||||
|
||||
/**
|
||||
* Skip the execution if the source file is older than the output folder.
|
||||
*/
|
||||
@Parameter(name = "skipIfSpecIsUnchanged", property = "codegen.skipIfSpecIsUnchanged", required = false, defaultValue = "false")
|
||||
private Boolean skipIfSpecIsUnchanged;
|
||||
|
||||
/**
|
||||
* Add the output directory to the project as a source root, so that the generated java types
|
||||
* are compiled and included in the project artifact.
|
||||
@@ -368,6 +378,21 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
}
|
||||
}
|
||||
|
||||
if (skipIfSpecIsUnchanged) {
|
||||
if (inputSpecFile.exists()) {
|
||||
File storedInputSpecHashFile = getHashFile(inputSpecFile);
|
||||
if(storedInputSpecHashFile.exists()) {
|
||||
String inputSpecHash = Files.asByteSource(inputSpecFile).hash(Hashing.sha256()).toString();
|
||||
String storedInputSpecHash = Files.asCharSource(storedInputSpecHashFile, Charsets.UTF_8).read();
|
||||
if (inputSpecHash.equals(storedInputSpecHash)) {
|
||||
getLog().info(
|
||||
"Code generation is skipped because input was unchanged");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// attempt to read from config file
|
||||
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configurationFile);
|
||||
|
||||
@@ -606,6 +631,17 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
if (buildContext != null) {
|
||||
buildContext.refresh(new File(getCompileSourceRoot()));
|
||||
}
|
||||
|
||||
// Store a checksum of the input spec
|
||||
File storedInputSpecHashFile = getHashFile(inputSpecFile);
|
||||
String inputSpecHash = Files.asByteSource(inputSpecFile).hash(Hashing.sha256()).toString();
|
||||
|
||||
if (storedInputSpecHashFile.getParent() != null && !new File(storedInputSpecHashFile.getParent()).exists()) {
|
||||
File parent = new File(storedInputSpecHashFile.getParent());
|
||||
parent.mkdirs();
|
||||
}
|
||||
Files.asCharSink(storedInputSpecHashFile, Charsets.UTF_8).write(inputSpecHash);
|
||||
|
||||
} catch (Exception e) {
|
||||
// Maven logs exceptions thrown by plugins only if invoked with -e
|
||||
// I find it annoying to jump through hoops to get basic diagnostic information,
|
||||
@@ -618,7 +654,11 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
"Code generation failed. See above for the full exception.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private File getHashFile(File inputSpecFile) {
|
||||
return new File(output.getPath() + File.separator + ".openapi-generator" + File.separator + inputSpecFile.getName() + ".sha256");
|
||||
}
|
||||
|
||||
private String getCompileSourceRoot() {
|
||||
final Object sourceFolderObject =
|
||||
configOptions == null ? null : configOptions
|
||||
@@ -647,10 +687,10 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This method enables conversion of true/false strings in
|
||||
* This method enables conversion of true/false strings in
|
||||
* config.additionalProperties (configuration/configOptions) to proper booleans.
|
||||
* This enables mustache files to handle the properties better.
|
||||
*
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
private void adjustAdditionalProperties(final CodegenConfig config) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-online</artifactId>
|
||||
@@ -13,7 +13,9 @@
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<spring-boot-version>2.0.7.RELEASE</spring-boot-version>
|
||||
<springfox-version>2.8.0</springfox-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@@ -85,5 +87,23 @@
|
||||
<artifactId>openapi-generator</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>2.0.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -19,11 +19,11 @@ package org.openapitools.codegen.online.service;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.online.api.GenApiDelegate;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConfigLoader;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.online.api.GenApiDelegate;
|
||||
import org.openapitools.codegen.online.model.Generated;
|
||||
import org.openapitools.codegen.online.model.GeneratorInput;
|
||||
import org.openapitools.codegen.online.model.ResponseCode;
|
||||
@@ -36,8 +36,9 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -68,12 +69,8 @@ public class GenApiService implements GenApiDelegate {
|
||||
servers.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
}
|
||||
|
||||
private final NativeWebRequest request;
|
||||
|
||||
@Autowired
|
||||
public GenApiService(NativeWebRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
private NativeWebRequest request;
|
||||
|
||||
@Override
|
||||
public Optional<NativeWebRequest> getRequest() {
|
||||
@@ -114,33 +111,7 @@ public class GenApiService implements GenApiDelegate {
|
||||
@Override
|
||||
public ResponseEntity<ResponseCode> generateClient(String language, GeneratorInput generatorInput) {
|
||||
String filename = Generator.generateClient(language, generatorInput);
|
||||
String host = System.getenv("GENERATOR_HOST");
|
||||
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
|
||||
|
||||
if (StringUtils.isBlank(host)) {
|
||||
String scheme = servletRequest.getHeader("X-SSL");
|
||||
String port = "";
|
||||
if ("1".equals(scheme)) {
|
||||
scheme = "https";
|
||||
} else {
|
||||
scheme = servletRequest.getScheme();
|
||||
port = ":" + servletRequest.getServerPort();
|
||||
}
|
||||
host = scheme + "://" + servletRequest.getServerName() + port;
|
||||
}
|
||||
|
||||
if (filename != null) {
|
||||
String code = String.valueOf(UUID.randomUUID().toString());
|
||||
Generated g = new Generated();
|
||||
g.setFilename(filename);
|
||||
g.setFriendlyName(language + "-client");
|
||||
fileMap.put(code, g);
|
||||
System.out.println(code + ", " + filename);
|
||||
String link = host + "/api/gen/download/" + code;
|
||||
return ResponseEntity.ok().body(new ResponseCode(code, link));
|
||||
} else {
|
||||
return ResponseEntity.status(500).build();
|
||||
}
|
||||
return getResponse(filename, language + "-client");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,20 +154,27 @@ public class GenApiService implements GenApiDelegate {
|
||||
String filename = Generator.generateServer(framework, generatorInput);
|
||||
System.out.println("generated name: " + filename);
|
||||
|
||||
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
|
||||
return getResponse(filename, framework + "-server");
|
||||
}
|
||||
|
||||
String host =
|
||||
servletRequest.getScheme() + "://" + servletRequest.getServerName() + ":"
|
||||
+ servletRequest.getServerPort();
|
||||
private ResponseEntity<ResponseCode> getResponse(String filename, String friendlyName) {
|
||||
String host = System.getenv("GENERATOR_HOST");
|
||||
|
||||
UriComponentsBuilder uriBuilder;
|
||||
if (!StringUtils.isBlank(host)) {
|
||||
uriBuilder = UriComponentsBuilder.fromUriString(host);
|
||||
} else {
|
||||
uriBuilder = ServletUriComponentsBuilder.fromCurrentContextPath();
|
||||
}
|
||||
|
||||
if (filename != null) {
|
||||
String code = String.valueOf(UUID.randomUUID().toString());
|
||||
String code = UUID.randomUUID().toString();
|
||||
Generated g = new Generated();
|
||||
g.setFilename(filename);
|
||||
g.setFriendlyName(framework + "-server");
|
||||
g.setFriendlyName(friendlyName);
|
||||
fileMap.put(code, g);
|
||||
System.out.println(code + ", " + filename);
|
||||
String link = host + "/api/gen/download/" + code;
|
||||
String link = uriBuilder.path("/api/gen/download/").path(code).toUriString();
|
||||
return ResponseEntity.ok().body(new ResponseCode(code, link));
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Generator {
|
||||
try {
|
||||
config = CodegenConfigLoader.forName(language);
|
||||
} catch (Exception e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format(Locale.ROOT,"Unsupported target %s supplied. %s",
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, String.format(Locale.ROOT,"Unsupported target %s supplied. %s",
|
||||
language, e));
|
||||
}
|
||||
Map<String, CliOption> map = new LinkedHashMap<>();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.swagger.v3.oas.models.servers.Server;
|
||||
import io.swagger.v3.oas.models.servers.ServerVariable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -261,4 +262,9 @@ public interface CodegenConfig {
|
||||
|
||||
public void setEnablePostProcessFile(boolean isEnablePostProcessFile);
|
||||
|
||||
// set OpenAPI and schemas
|
||||
public void setGlobalOpenAPI(OpenAPI openAPI);
|
||||
|
||||
public void setGlobalSchemas(OpenAPI openAPI);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenDiscriminator {
|
||||
@@ -85,4 +87,13 @@ public class CodegenDiscriminator {
|
||||
public int hashCode() {
|
||||
return Objects.hash(propertyName, mapping, mappedModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("propertyName", propertyName)
|
||||
.append("mapping", mapping)
|
||||
.append("mappedModels", mappedModels)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,7 @@ package org.openapitools.codegen;
|
||||
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
@@ -40,6 +33,11 @@ public class CodegenModel {
|
||||
public List<CodegenModel> interfaceModels;
|
||||
public List<CodegenModel> children;
|
||||
|
||||
// anyOf, oneOf, allOf
|
||||
public Set<String> anyOf = new TreeSet<String>();
|
||||
public Set<String> oneOf = new TreeSet<String>();
|
||||
public Set<String> allOf = new TreeSet<String>();
|
||||
|
||||
public String name, classname, title, description, classVarName, modelJson, dataType, xmlPrefix, xmlNamespace, xmlName;
|
||||
public String classFilename; // store the class file name, mainly used for import
|
||||
public String unescapedDescription;
|
||||
@@ -53,8 +51,8 @@ public class CodegenModel {
|
||||
public List<CodegenProperty> optionalVars = new ArrayList<CodegenProperty>(); // a list of optional properties
|
||||
public List<CodegenProperty> readOnlyVars = new ArrayList<CodegenProperty>(); // a list of read-only properties
|
||||
public List<CodegenProperty> readWriteVars = new ArrayList<CodegenProperty>(); // a list of properties for read, write
|
||||
public List<CodegenProperty> allVars;
|
||||
public List<CodegenProperty> parentVars = new ArrayList<>();
|
||||
public List<CodegenProperty> allVars = new ArrayList<CodegenProperty>();
|
||||
public List<CodegenProperty> parentVars = new ArrayList<CodegenProperty>();
|
||||
public Map<String, Object> allowableValues;
|
||||
|
||||
// Sorted sets of required parameters.
|
||||
@@ -195,11 +193,11 @@ public class CodegenModel {
|
||||
result = 31 * result + (mandatory != null ? mandatory.hashCode() : 0);
|
||||
result = 31 * result + (allMandatory != null ? allMandatory.hashCode() : 0);
|
||||
result = 31 * result + (imports != null ? imports.hashCode() : 0);
|
||||
result = 31 * result + (hasVars ? 13:31);
|
||||
result = 31 * result + (emptyVars ? 13:31);
|
||||
result = 31 * result + (hasMoreModels ? 13:31);
|
||||
result = 31 * result + (hasEnums ? 13:31);
|
||||
result = 31 * result + (isEnum ? 13:31);
|
||||
result = 31 * result + (hasVars ? 13 : 31);
|
||||
result = 31 * result + (emptyVars ? 13 : 31);
|
||||
result = 31 * result + (hasMoreModels ? 13 : 31);
|
||||
result = 31 * result + (hasEnums ? 13 : 31);
|
||||
result = 31 * result + (isEnum ? 13 : 31);
|
||||
result = 31 * result + (externalDocumentation != null ? externalDocumentation.hashCode() : 0);
|
||||
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);
|
||||
result = 31 * result + Objects.hash(hasOnlyReadOnly);
|
||||
@@ -499,4 +497,67 @@ public class CodegenModel {
|
||||
public void setAdditionalPropertiesType(String additionalPropertiesType) {
|
||||
this.additionalPropertiesType = additionalPropertiesType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove duplicated properties in all variable list and update "hasMore"
|
||||
*/
|
||||
public void removeAllDuplicatedProperty() {
|
||||
// remove duplicated properties
|
||||
vars = removeDuplicatedProperty(vars);
|
||||
optionalVars = removeDuplicatedProperty(optionalVars);
|
||||
requiredVars = removeDuplicatedProperty(requiredVars);
|
||||
parentVars = removeDuplicatedProperty(parentVars);
|
||||
allVars = removeDuplicatedProperty(allVars);
|
||||
readOnlyVars = removeDuplicatedProperty(readOnlyVars);
|
||||
readWriteVars = removeDuplicatedProperty(readWriteVars);
|
||||
|
||||
// update property list's "hasMore"
|
||||
updatePropertyListHasMore(vars);
|
||||
updatePropertyListHasMore(optionalVars);
|
||||
updatePropertyListHasMore(requiredVars);
|
||||
updatePropertyListHasMore(parentVars);
|
||||
updatePropertyListHasMore(allVars);
|
||||
updatePropertyListHasMore(readOnlyVars);
|
||||
updatePropertyListHasMore(readWriteVars);
|
||||
}
|
||||
|
||||
private List<CodegenProperty> removeDuplicatedProperty(List<CodegenProperty> vars) {
|
||||
// clone the list first
|
||||
List<CodegenProperty> newList = new ArrayList<CodegenProperty>();
|
||||
for (CodegenProperty cp : vars) {
|
||||
newList.add(cp.clone());
|
||||
}
|
||||
|
||||
Set<String> propertyNames = new TreeSet<String>();
|
||||
Set<String> duplicatedNames = new TreeSet<String>();
|
||||
|
||||
ListIterator<CodegenProperty> iterator = newList.listIterator();
|
||||
while (iterator.hasNext()) {
|
||||
CodegenProperty element = iterator.next();
|
||||
|
||||
if (propertyNames.contains(element.baseName)) {
|
||||
duplicatedNames.add(element.baseName);
|
||||
iterator.remove();
|
||||
} else {
|
||||
propertyNames.add(element.baseName);
|
||||
}
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the element and update "hasMore" in the list of codegen properties
|
||||
*/
|
||||
private void updatePropertyListHasMore(List<CodegenProperty> vars) {
|
||||
if (vars != null) {
|
||||
for (int i = 0; i < vars.size(); i++) {
|
||||
if (i < vars.size() - 1) {
|
||||
vars.get(i).hasMore = true;
|
||||
} else { // last element
|
||||
vars.get(i).hasMore = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,12 @@ public class CodegenParameter {
|
||||
isCookieParam, isBodyParam, hasMore, isContainer,
|
||||
secondaryParam, isCollectionFormatMulti, isPrimitiveType, isModel;
|
||||
public String baseName, paramName, dataType, datatypeWithEnum, dataFormat,
|
||||
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName;
|
||||
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName;
|
||||
|
||||
public String example; // example value (x-example)
|
||||
public String jsonSchema;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isEmail;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary,
|
||||
isBoolean, isDate, isDateTime, isUuid, isEmail, isFreeFormObject;
|
||||
public boolean isListContainer, isMapContainer;
|
||||
public boolean isFile;
|
||||
public boolean isEnum;
|
||||
@@ -94,7 +95,7 @@ public class CodegenParameter {
|
||||
* See http://json-schema.org/latest/json-schema-validation.html#anchor14
|
||||
*/
|
||||
public Number multipleOf;
|
||||
|
||||
|
||||
public CodegenParameter copy() {
|
||||
CodegenParameter output = new CodegenParameter();
|
||||
output.isFile = this.isFile;
|
||||
@@ -148,7 +149,7 @@ public class CodegenParameter {
|
||||
if (this.mostInnerItems != null) {
|
||||
output.mostInnerItems = this.mostInnerItems;
|
||||
}
|
||||
if(this.vendorExtensions != null){
|
||||
if (this.vendorExtensions != null) {
|
||||
output.vendorExtensions = new HashMap<String, Object>(this.vendorExtensions);
|
||||
}
|
||||
output.hasValidation = this.hasValidation;
|
||||
@@ -167,6 +168,7 @@ public class CodegenParameter {
|
||||
output.isDateTime = this.isDateTime;
|
||||
output.isUuid = this.isUuid;
|
||||
output.isEmail = this.isEmail;
|
||||
output.isFreeFormObject = this.isFreeFormObject;
|
||||
output.isListContainer = this.isListContainer;
|
||||
output.isMapContainer = this.isMapContainer;
|
||||
|
||||
@@ -259,6 +261,8 @@ public class CodegenParameter {
|
||||
return false;
|
||||
if (isEmail != that.isEmail)
|
||||
return false;
|
||||
if (isFreeFormObject != that.isFreeFormObject)
|
||||
return false;
|
||||
if (isListContainer != that.isListContainer)
|
||||
return false;
|
||||
if (isMapContainer != that.isMapContainer)
|
||||
@@ -307,18 +311,18 @@ public class CodegenParameter {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = isFormParam ? 13:31;
|
||||
result = 31 * result + (isQueryParam ? 13:31);
|
||||
result = 31 * result + (isPathParam ? 13:31);
|
||||
result = 31 * result + (isHeaderParam ? 13:31);
|
||||
result = 31 * result + (isCookieParam ? 13:31);
|
||||
result = 31 * result + (isBodyParam ? 13:31);
|
||||
result = 31 * result + (hasMore ? 13:31);
|
||||
result = 31 * result + (isContainer ? 13:31);
|
||||
result = 31 * result + (secondaryParam ? 13:31);
|
||||
result = 31 * result + (isCollectionFormatMulti ? 13:31);
|
||||
result = 31 * result + (isPrimitiveType ? 13:31);
|
||||
result = 31 * result + (isModel ? 13:31);
|
||||
int result = isFormParam ? 13 : 31;
|
||||
result = 31 * result + (isQueryParam ? 13 : 31);
|
||||
result = 31 * result + (isPathParam ? 13 : 31);
|
||||
result = 31 * result + (isHeaderParam ? 13 : 31);
|
||||
result = 31 * result + (isCookieParam ? 13 : 31);
|
||||
result = 31 * result + (isBodyParam ? 13 : 31);
|
||||
result = 31 * result + (hasMore ? 13 : 31);
|
||||
result = 31 * result + (isContainer ? 13 : 31);
|
||||
result = 31 * result + (secondaryParam ? 13 : 31);
|
||||
result = 31 * result + (isCollectionFormatMulti ? 13 : 31);
|
||||
result = 31 * result + (isPrimitiveType ? 13 : 31);
|
||||
result = 31 * result + (isModel ? 13 : 31);
|
||||
result = 31 * result + (baseName != null ? baseName.hashCode() : 0);
|
||||
result = 31 * result + (paramName != null ? paramName.hashCode() : 0);
|
||||
result = 31 * result + (dataType != null ? dataType.hashCode() : 0);
|
||||
@@ -332,42 +336,43 @@ public class CodegenParameter {
|
||||
result = 31 * result + (defaultValue != null ? defaultValue.hashCode() : 0);
|
||||
result = 31 * result + (example != null ? example.hashCode() : 0);
|
||||
result = 31 * result + (jsonSchema != null ? jsonSchema.hashCode() : 0);
|
||||
result = 31 * result + (isString ? 13:31);
|
||||
result = 31 * result + (isNumeric ? 13:31);
|
||||
result = 31 * result + (isInteger ? 13:31);
|
||||
result = 31 * result + (isLong ? 13:31);
|
||||
result = 31 * result + (isFloat ? 13:31);
|
||||
result = 31 * result + (isNumber ? 13:31);
|
||||
result = 31 * result + (isDouble ? 13:31);
|
||||
result = 31 * result + (isByteArray ? 13:31);
|
||||
result = 31 * result + (isBinary ? 13:31);
|
||||
result = 31 * result + (isBoolean ? 13:31);
|
||||
result = 31 * result + (isDate ? 13:31);
|
||||
result = 31 * result + (isDateTime ? 13:31);
|
||||
result = 31 * result + (isUuid ? 13:31);
|
||||
result = 31 * result + (isEmail ? 13:31);
|
||||
result = 31 * result + (isListContainer ? 13:31);
|
||||
result = 31 * result + (isMapContainer ? 13:31);
|
||||
result = 31 * result + (isFile ? 13:31);
|
||||
result = 31 * result + (isString ? 13 : 31);
|
||||
result = 31 * result + (isNumeric ? 13 : 31);
|
||||
result = 31 * result + (isInteger ? 13 : 31);
|
||||
result = 31 * result + (isLong ? 13 : 31);
|
||||
result = 31 * result + (isFloat ? 13 : 31);
|
||||
result = 31 * result + (isNumber ? 13 : 31);
|
||||
result = 31 * result + (isDouble ? 13 : 31);
|
||||
result = 31 * result + (isByteArray ? 13 : 31);
|
||||
result = 31 * result + (isBinary ? 13 : 31);
|
||||
result = 31 * result + (isBoolean ? 13 : 31);
|
||||
result = 31 * result + (isDate ? 13 : 31);
|
||||
result = 31 * result + (isDateTime ? 13 : 31);
|
||||
result = 31 * result + (isUuid ? 13 : 31);
|
||||
result = 31 * result + (isEmail ? 13 : 31);
|
||||
result = 31 * result + (isFreeFormObject ? 13 : 31);
|
||||
result = 31 * result + (isListContainer ? 13 : 31);
|
||||
result = 31 * result + (isMapContainer ? 13 : 31);
|
||||
result = 31 * result + (isFile ? 13 : 31);
|
||||
result = 31 * result + (isEnum ? 1 : 0);
|
||||
result = 31 * result + (_enum != null ? _enum.hashCode() : 0);
|
||||
result = 31 * result + (allowableValues != null ? allowableValues.hashCode() : 0);
|
||||
result = 31 * result + (items != null ? items.hashCode() : 0);
|
||||
result = 31 * result + (mostInnerItems != null ? mostInnerItems.hashCode() : 0);
|
||||
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);
|
||||
result = 31 * result + (hasValidation ? 13:31);
|
||||
result = 31 * result + (isNullable ? 13:31);
|
||||
result = 31 * result + (required ? 13:31);
|
||||
result = 31 * result + (hasValidation ? 13 : 31);
|
||||
result = 31 * result + (isNullable ? 13 : 31);
|
||||
result = 31 * result + (required ? 13 : 31);
|
||||
result = 31 * result + (maximum != null ? maximum.hashCode() : 0);
|
||||
result = 31 * result + (exclusiveMaximum ? 13:31);
|
||||
result = 31 * result + (exclusiveMaximum ? 13 : 31);
|
||||
result = 31 * result + (minimum != null ? minimum.hashCode() : 0);
|
||||
result = 31 * result + (exclusiveMinimum ? 13:31);
|
||||
result = 31 * result + (exclusiveMinimum ? 13 : 31);
|
||||
result = 31 * result + (maxLength != null ? maxLength.hashCode() : 0);
|
||||
result = 31 * result + (minLength != null ? minLength.hashCode() : 0);
|
||||
result = 31 * result + (pattern != null ? pattern.hashCode() : 0);
|
||||
result = 31 * result + (maxItems != null ? maxItems.hashCode() : 0);
|
||||
result = 31 * result + (minItems != null ? minItems.hashCode() : 0);
|
||||
result = 31 * result + (uniqueItems ? 13:31);
|
||||
result = 31 * result + (uniqueItems ? 13 : 31);
|
||||
result = 31 * result + (multipleOf != null ? multipleOf.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
@@ -414,6 +419,7 @@ public class CodegenParameter {
|
||||
", isDateTime=" + isDateTime +
|
||||
", isUuid=" + isUuid +
|
||||
", isEmail=" + isEmail +
|
||||
", isFreeFormObject=" + isFreeFormObject +
|
||||
", isListContainer=" + isListContainer +
|
||||
", isMapContainer=" + isMapContainer +
|
||||
", isFile=" + isFile +
|
||||
|
||||
@@ -17,18 +17,16 @@
|
||||
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenProperty implements Cloneable {
|
||||
public String baseName, complexType, getter, setter, description, dataType,
|
||||
datatypeWithEnum, dataFormat, name, min, max, defaultValue, defaultValueWithParam,
|
||||
baseType, containerType, title;
|
||||
datatypeWithEnum, dataFormat, name, min, max, defaultValue, defaultValueWithParam,
|
||||
baseType, containerType, title;
|
||||
|
||||
/** The 'description' string without escape charcters needed by some programming languages/targets */
|
||||
/**
|
||||
* The 'description' string without escape charcters needed by some programming languages/targets
|
||||
*/
|
||||
public String unescapedDescription;
|
||||
|
||||
/**
|
||||
@@ -56,7 +54,8 @@ public class CodegenProperty implements Cloneable {
|
||||
public boolean hasMore, required, secondaryParam;
|
||||
public boolean hasMoreNonReadOnly; // for model constructor, true if next property is not readonly
|
||||
public boolean isPrimitiveType, isModel, isContainer, isNotContainer;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isFile, isBoolean, isDate, isDateTime, isUuid, isEmail;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isFile,
|
||||
isBoolean, isDate, isDateTime, isUuid, isEmail, isFreeFormObject;
|
||||
public boolean isListContainer, isMapContainer;
|
||||
public boolean isEnum;
|
||||
public boolean isReadOnly;
|
||||
@@ -84,7 +83,7 @@ public class CodegenProperty implements Cloneable {
|
||||
public String xmlNamespace;
|
||||
public boolean isXmlWrapped = false;
|
||||
|
||||
public String getBaseName() {
|
||||
public String getBaseName() {
|
||||
return baseName;
|
||||
}
|
||||
|
||||
@@ -125,9 +124,9 @@ public class CodegenProperty implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return dataType
|
||||
* @deprecated since version 3.0.0, use {@link #getDataType()} instead.<br>
|
||||
* May be removed with the next major release (4.0)
|
||||
* @return dataType
|
||||
*/
|
||||
@Deprecated
|
||||
public String getDatatype() {
|
||||
@@ -411,8 +410,7 @@ public class CodegenProperty implements Cloneable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((_enum == null) ? 0 : _enum.hashCode());
|
||||
@@ -429,19 +427,19 @@ public class CodegenProperty implements Cloneable {
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((title == null) ? 0 : title.hashCode());
|
||||
result = prime * result + ((example == null) ? 0 : example.hashCode());
|
||||
result = prime * result + (exclusiveMaximum ? 13:31);
|
||||
result = prime * result + (exclusiveMinimum ? 13:31);
|
||||
result = prime * result + (exclusiveMaximum ? 13 : 31);
|
||||
result = prime * result + (exclusiveMinimum ? 13 : 31);
|
||||
result = prime * result + ((getter == null) ? 0 : getter.hashCode());
|
||||
result = prime * result + (hasMore ? 13:31);
|
||||
result = prime * result + ((hasMoreNonReadOnly ? 13:31));
|
||||
result = prime * result + ((isContainer ? 13:31));
|
||||
result = prime * result + (hasMore ? 13 : 31);
|
||||
result = prime * result + ((hasMoreNonReadOnly ? 13 : 31));
|
||||
result = prime * result + ((isContainer ? 13 : 31));
|
||||
result = prime * result + (isEnum ? 1231 : 1237);
|
||||
result = prime * result + ((isNotContainer ? 13:31));
|
||||
result = prime * result + ((isPrimitiveType ? 13:31));
|
||||
result = prime * result + ((isModel ? 13:31));
|
||||
result = prime * result + ((isReadOnly ? 13:31));
|
||||
result = prime * result + ((isWriteOnly ? 13:31));
|
||||
result = prime * result + ((isNullable ? 13:31));
|
||||
result = prime * result + ((isNotContainer ? 13 : 31));
|
||||
result = prime * result + ((isPrimitiveType ? 13 : 31));
|
||||
result = prime * result + ((isModel ? 13 : 31));
|
||||
result = prime * result + ((isReadOnly ? 13 : 31));
|
||||
result = prime * result + ((isWriteOnly ? 13 : 31));
|
||||
result = prime * result + ((isNullable ? 13 : 31));
|
||||
result = prime * result + ((items == null) ? 0 : items.hashCode());
|
||||
result = prime * result + ((mostInnerItems == null) ? 0 : mostInnerItems.hashCode());
|
||||
result = prime * result + ((jsonSchema == null) ? 0 : jsonSchema.hashCode());
|
||||
@@ -453,29 +451,30 @@ public class CodegenProperty implements Cloneable {
|
||||
result = prime * result + ((minimum == null) ? 0 : minimum.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((pattern == null) ? 0 : pattern.hashCode());
|
||||
result = prime * result + ((required ? 13:31));
|
||||
result = prime * result + ((secondaryParam ? 13:31));
|
||||
result = prime * result + ((required ? 13 : 31));
|
||||
result = prime * result + ((secondaryParam ? 13 : 31));
|
||||
result = prime * result + ((setter == null) ? 0 : setter.hashCode());
|
||||
result = prime * result + ((unescapedDescription == null) ? 0 : unescapedDescription.hashCode());
|
||||
result = prime * result + ((vendorExtensions == null) ? 0 : vendorExtensions.hashCode());
|
||||
result = prime * result + ((hasValidation ? 13:31));
|
||||
result = prime * result + ((isString ? 13:31));
|
||||
result = prime * result + ((isNumeric ? 13:31));
|
||||
result = prime * result + ((isInteger ? 13:31));
|
||||
result = prime * result + ((isLong ?13:31));
|
||||
result = prime * result + ((isNumber ? 13:31));
|
||||
result = prime * result + ((isFloat ? 13:31));
|
||||
result = prime * result + ((isDouble ? 13:31));
|
||||
result = prime * result + ((isByteArray ? 13:31));
|
||||
result = prime * result + ((isBinary ? 13:31));
|
||||
result = prime * result + ((isFile ? 13:31));
|
||||
result = prime * result + ((isBoolean ? 13:31));
|
||||
result = prime * result + ((isDate ? 13:31));
|
||||
result = prime * result + ((isDateTime ? 13:31));
|
||||
result = prime * result + ((isUuid ? 13:31));
|
||||
result = prime * result + ((isEmail ? 13:31));
|
||||
result = prime * result + ((isMapContainer ? 13:31));
|
||||
result = prime * result + ((isListContainer ? 13:31));
|
||||
result = prime * result + ((hasValidation ? 13 : 31));
|
||||
result = prime * result + ((isString ? 13 : 31));
|
||||
result = prime * result + ((isNumeric ? 13 : 31));
|
||||
result = prime * result + ((isInteger ? 13 : 31));
|
||||
result = prime * result + ((isLong ? 13 : 31));
|
||||
result = prime * result + ((isNumber ? 13 : 31));
|
||||
result = prime * result + ((isFloat ? 13 : 31));
|
||||
result = prime * result + ((isDouble ? 13 : 31));
|
||||
result = prime * result + ((isByteArray ? 13 : 31));
|
||||
result = prime * result + ((isBinary ? 13 : 31));
|
||||
result = prime * result + ((isFile ? 13 : 31));
|
||||
result = prime * result + ((isBoolean ? 13 : 31));
|
||||
result = prime * result + ((isDate ? 13 : 31));
|
||||
result = prime * result + ((isDateTime ? 13 : 31));
|
||||
result = prime * result + ((isUuid ? 13 : 31));
|
||||
result = prime * result + ((isEmail ? 13 : 31));
|
||||
result = prime * result + ((isFreeFormObject ? 13 : 31));
|
||||
result = prime * result + ((isMapContainer ? 13 : 31));
|
||||
result = prime * result + ((isListContainer ? 13 : 31));
|
||||
result = prime * result + Objects.hashCode(isInherited);
|
||||
result = prime * result + Objects.hashCode(discriminatorValue);
|
||||
result = prime * result + Objects.hashCode(nameInCamelCase);
|
||||
@@ -483,11 +482,11 @@ public class CodegenProperty implements Cloneable {
|
||||
result = prime * result + Objects.hashCode(enumName);
|
||||
result = prime * result + ((maxItems == null) ? 0 : maxItems.hashCode());
|
||||
result = prime * result + ((minItems == null) ? 0 : minItems.hashCode());
|
||||
result = prime * result + ((isXmlAttribute ? 13:31));
|
||||
result = prime * result + ((isXmlAttribute ? 13 : 31));
|
||||
result = prime * result + ((xmlPrefix == null) ? 0 : xmlPrefix.hashCode());
|
||||
result = prime * result + ((xmlName == null) ? 0 : xmlName.hashCode());
|
||||
result = prime * result + ((xmlNamespace == null) ? 0 : xmlNamespace.hashCode());
|
||||
result = prime * result + ((isXmlWrapped ? 13:31));
|
||||
result = prime * result + ((isXmlWrapped ? 13 : 31));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -657,6 +656,9 @@ public class CodegenProperty implements Cloneable {
|
||||
if (this.isEmail != other.isEmail) {
|
||||
return false;
|
||||
}
|
||||
if (this.isFreeFormObject != other.isFreeFormObject) {
|
||||
return false;
|
||||
}
|
||||
if (this.isBinary != other.isBinary) {
|
||||
return false;
|
||||
}
|
||||
@@ -724,9 +726,10 @@ public class CodegenProperty implements Cloneable {
|
||||
if (this.mostInnerItems != null) {
|
||||
cp.mostInnerItems = this.mostInnerItems;
|
||||
}
|
||||
if(this.vendorExtensions != null){
|
||||
if (this.vendorExtensions != null) {
|
||||
cp.vendorExtensions = new HashMap<String, Object>(this.vendorExtensions);
|
||||
}
|
||||
|
||||
return cp;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new IllegalStateException(e);
|
||||
@@ -785,11 +788,12 @@ public class CodegenProperty implements Cloneable {
|
||||
", isDateTime=" + isDateTime +
|
||||
", isUuid=" + isUuid +
|
||||
", isEmail=" + isEmail +
|
||||
", isFreeFormObject=" + isFreeFormObject +
|
||||
", isListContainer=" + isListContainer +
|
||||
", isMapContainer=" + isMapContainer +
|
||||
", isEnum=" + isEnum +
|
||||
", isReadOnly=" + isReadOnly +
|
||||
", isWriteOnly=" + isWriteOnly+
|
||||
", isWriteOnly=" + isWriteOnly +
|
||||
", isNullable=" + isNullable +
|
||||
", _enum=" + _enum +
|
||||
", allowableValues=" + allowableValues +
|
||||
@@ -810,4 +814,6 @@ public class CodegenProperty implements Cloneable {
|
||||
", isXmlWrapped=" + isXmlWrapped +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,11 +17,7 @@
|
||||
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenResponse {
|
||||
public final List<CodegenProperty> headers = new ArrayList<CodegenProperty>();
|
||||
@@ -30,7 +26,8 @@ public class CodegenResponse {
|
||||
public List<Map<String, Object>> examples;
|
||||
public String dataType, baseType, containerType;
|
||||
public boolean hasHeaders;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBoolean, isDate, isDateTime, isUuid, isEmail;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBoolean, isDate,
|
||||
isDateTime, isUuid, isEmail, isModel, isFreeFormObject;
|
||||
public boolean isDefault;
|
||||
public boolean simpleType;
|
||||
public boolean primitiveType;
|
||||
@@ -48,76 +45,90 @@ public class CodegenResponse {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(Locale.ROOT, "%s(%s)", code, containerType);
|
||||
return "CodegenResponse{" +
|
||||
"headers=" + headers +
|
||||
", code='" + code + '\'' +
|
||||
", message='" + message + '\'' +
|
||||
", hasMore=" + hasMore +
|
||||
", examples=" + examples +
|
||||
", dataType='" + dataType + '\'' +
|
||||
", baseType='" + baseType + '\'' +
|
||||
", containerType='" + containerType + '\'' +
|
||||
", hasHeaders=" + hasHeaders +
|
||||
", isString=" + isString +
|
||||
", isNumeric=" + isNumeric +
|
||||
", isInteger=" + isInteger +
|
||||
", isLong=" + isLong +
|
||||
", isNumber=" + isNumber +
|
||||
", isFloat=" + isFloat +
|
||||
", isDouble=" + isDouble +
|
||||
", isByteArray=" + isByteArray +
|
||||
", isBoolean=" + isBoolean +
|
||||
", isDate=" + isDate +
|
||||
", isDateTime=" + isDateTime +
|
||||
", isUuid=" + isUuid +
|
||||
", isEmail=" + isEmail +
|
||||
", isFreeFormObject=" + isFreeFormObject +
|
||||
", isModel=" + isModel +
|
||||
", isDefault=" + isDefault +
|
||||
", simpleType=" + simpleType +
|
||||
", primitiveType=" + primitiveType +
|
||||
", isMapContainer=" + isMapContainer +
|
||||
", isListContainer=" + isListContainer +
|
||||
", isBinary=" + isBinary +
|
||||
", isFile=" + isFile +
|
||||
", schema=" + schema +
|
||||
", jsonSchema='" + jsonSchema + '\'' +
|
||||
", vendorExtensions=" + vendorExtensions +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
CodegenResponse that = (CodegenResponse) o;
|
||||
|
||||
if (!headers.equals(that.headers))
|
||||
return false;
|
||||
if (code != null ? !code.equals(that.code) : that.code != null)
|
||||
return false;
|
||||
if (message != null ? !message.equals(that.message) : that.message != null)
|
||||
return false;
|
||||
if (hasMore != that.hasMore)
|
||||
return false;
|
||||
if (examples != null ? !examples.equals(that.examples) : that.examples != null)
|
||||
return false;
|
||||
if (dataType != null ? !dataType.equals(that.dataType) : that.dataType != null)
|
||||
return false;
|
||||
if (baseType != null ? !baseType.equals(that.baseType) : that.baseType != null)
|
||||
return false;
|
||||
if (containerType != null ? !containerType.equals(that.containerType) : that.containerType != null)
|
||||
return false;
|
||||
if (isDefault != that.isDefault)
|
||||
return false;
|
||||
if (simpleType != that.simpleType)
|
||||
return false;
|
||||
if (primitiveType != that.primitiveType)
|
||||
return false;
|
||||
if (isMapContainer != that.isMapContainer)
|
||||
return false;
|
||||
if (isListContainer != that.isListContainer)
|
||||
return false;
|
||||
if (isBinary != that.isBinary)
|
||||
return false;
|
||||
if (isFile != that.isFile)
|
||||
return false;
|
||||
if (isNumeric != that.isNumeric)
|
||||
return false;
|
||||
if (schema != null ? !schema.equals(that.schema) : that.schema != null)
|
||||
return false;
|
||||
if (vendorExtensions != null ? !vendorExtensions.equals(that.vendorExtensions) : that.vendorExtensions != null)
|
||||
return false;
|
||||
return jsonSchema != null ? jsonSchema.equals(that.jsonSchema) : that.jsonSchema == null;
|
||||
return hasMore == that.hasMore &&
|
||||
hasHeaders == that.hasHeaders &&
|
||||
isString == that.isString &&
|
||||
isNumeric == that.isNumeric &&
|
||||
isInteger == that.isInteger &&
|
||||
isLong == that.isLong &&
|
||||
isNumber == that.isNumber &&
|
||||
isFloat == that.isFloat &&
|
||||
isDouble == that.isDouble &&
|
||||
isByteArray == that.isByteArray &&
|
||||
isBoolean == that.isBoolean &&
|
||||
isDate == that.isDate &&
|
||||
isDateTime == that.isDateTime &&
|
||||
isUuid == that.isUuid &&
|
||||
isEmail == that.isEmail &&
|
||||
isFreeFormObject == that.isFreeFormObject &&
|
||||
isModel == that.isModel &&
|
||||
isDefault == that.isDefault &&
|
||||
simpleType == that.simpleType &&
|
||||
primitiveType == that.primitiveType &&
|
||||
isMapContainer == that.isMapContainer &&
|
||||
isListContainer == that.isListContainer &&
|
||||
isBinary == that.isBinary &&
|
||||
isFile == that.isFile &&
|
||||
Objects.equals(headers, that.headers) &&
|
||||
Objects.equals(code, that.code) &&
|
||||
Objects.equals(message, that.message) &&
|
||||
Objects.equals(examples, that.examples) &&
|
||||
Objects.equals(dataType, that.dataType) &&
|
||||
Objects.equals(baseType, that.baseType) &&
|
||||
Objects.equals(containerType, that.containerType) &&
|
||||
Objects.equals(schema, that.schema) &&
|
||||
Objects.equals(jsonSchema, that.jsonSchema) &&
|
||||
Objects.equals(vendorExtensions, that.vendorExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = headers.hashCode();
|
||||
result = 31 * result + (code != null ? code.hashCode() : 0);
|
||||
result = 31 * result + (message != null ? message.hashCode() : 0);
|
||||
result = 31 * result + (hasMore ? 13:31);
|
||||
result = 31 * result + (examples != null ? examples.hashCode() : 0);
|
||||
result = 31 * result + (dataType != null ? dataType.hashCode() : 0);
|
||||
result = 31 * result + (baseType != null ? baseType.hashCode() : 0);
|
||||
result = 31 * result + (containerType != null ? containerType.hashCode() : 0);
|
||||
result = 31 * result + (isDefault ? 13:31);
|
||||
result = 31 * result + (isNumeric ? 13:31);
|
||||
result = 31 * result + (simpleType ? 13:31);
|
||||
result = 31 * result + (primitiveType ? 13:31);
|
||||
result = 31 * result + (isMapContainer ? 13:31);
|
||||
result = 31 * result + (isListContainer ? 13:31);
|
||||
result = 31 * result + (isBinary ? 13:31);
|
||||
result = 31 * result + (isFile ? 13:31);
|
||||
result = 31 * result + (schema != null ? schema.hashCode() : 0);
|
||||
result = 31 * result + (jsonSchema != null ? jsonSchema.hashCode() : 0);
|
||||
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);
|
||||
return result;
|
||||
return Objects.hash(headers, code, message, hasMore, examples, dataType, baseType, containerType, hasHeaders,
|
||||
isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBoolean, isDate,
|
||||
isDateTime, isUuid, isEmail, isFreeFormObject, isModel, isDefault, simpleType, primitiveType, isMapContainer,
|
||||
isListContainer, isBinary, isFile, schema, jsonSchema, vendorExtensions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -137,6 +138,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// flag to indicate whether to use environment variable to post process file
|
||||
protected boolean enablePostProcessFile = false;
|
||||
|
||||
// make openapi and schemas available to all methods
|
||||
protected OpenAPI globalOpenAPI;
|
||||
protected Map<String, Schema> globalSchemas;
|
||||
|
||||
public List<CliOption> cliOptions() {
|
||||
return cliOptions;
|
||||
@@ -383,6 +387,32 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set global OpenAPI based on OpenAPI object
|
||||
*
|
||||
* @param openAPI OpenAPI object
|
||||
*/
|
||||
public void setGlobalOpenAPI(OpenAPI openAPI) {
|
||||
this.globalOpenAPI = openAPI;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set global schema based on OpenAPI object
|
||||
*
|
||||
* @param openAPI OpenAPI object
|
||||
*/
|
||||
public void setGlobalSchemas(OpenAPI openAPI) {
|
||||
if (openAPI != null && openAPI.getComponents() != null) {
|
||||
this.globalSchemas = openAPI.getComponents().getSchemas();
|
||||
}
|
||||
|
||||
if (this.globalSchemas == null) { // initalize with empty map if it's null
|
||||
this.globalSchemas = new HashMap<String, Schema>();
|
||||
}
|
||||
}
|
||||
|
||||
// override with any special post-processing
|
||||
@SuppressWarnings("static-method")
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
@@ -846,23 +876,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
throw new RuntimeException("reserved word " + name + " not allowed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name with escaped characters.
|
||||
*
|
||||
* @param name the name to be escaped
|
||||
* @param charactersToAllow characters that are not escaped
|
||||
* @param appdendixToReplacement String to append to replaced characters.
|
||||
* @return the escaped word
|
||||
* <p>
|
||||
* throws Runtime exception as word is not escaped properly.
|
||||
* @see org.openapitools.codegen.utils.StringUtils#escape directly instead
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public String escapeSpecialCharacters(String name, List<String> charactersToAllow, String appdendixToReplacement) {
|
||||
return escape(name, specialCharReplacements, charactersToAllow, appdendixToReplacement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fully-qualified "Model" name for import
|
||||
*
|
||||
@@ -1152,6 +1165,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
codegenParameter.example = "38400000-8cf0-11bd-b23e-10b96e4ef00d";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isString)) {
|
||||
codegenParameter.example = codegenParameter.paramName + "_example";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isFreeFormObject)) {
|
||||
codegenParameter.example = "Object";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1298,16 +1313,53 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
**/
|
||||
@SuppressWarnings("static-method")
|
||||
public String getSchemaType(Schema schema) {
|
||||
// TODO better logic to handle compose schema
|
||||
if (schema instanceof ComposedSchema) { // composed schema
|
||||
ComposedSchema cs = (ComposedSchema) schema;
|
||||
List<Schema> schemas = ModelUtils.getInterfaces(cs);
|
||||
if (cs.getAllOf() != null) {
|
||||
for (Schema s : cs.getAllOf()) {
|
||||
if (s != null) {
|
||||
// using the first schema defined in allOf
|
||||
schema = s;
|
||||
break;
|
||||
//schema = s;
|
||||
}
|
||||
//LOGGER.info("ALL OF SCHEMA: {}", s);
|
||||
}
|
||||
|
||||
LOGGER.info("Composed schema not yet supported: {}", cs);
|
||||
// get the model (allOf)
|
||||
return getAlias("UNKNOWN_COMPOSED_SCHMEA");
|
||||
} else if (cs.getAnyOf() != null) { // anyOf
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (Schema s : schemas) {
|
||||
if (StringUtils.isNotBlank(s.get$ref())) { // reference to another definition/schema
|
||||
String schemaName = ModelUtils.getSimpleRef(s.get$ref());
|
||||
if (StringUtils.isNotEmpty(schemaName)) {
|
||||
names.add(getAlias(schemaName));
|
||||
} else {
|
||||
LOGGER.warn("Error obtaining the datatype from ref:" + schema.get$ref() + ". Default to 'object'");
|
||||
return "object";
|
||||
}
|
||||
} else {
|
||||
// primitive type or model
|
||||
names.add(getAlias(getPrimitiveType(s)));
|
||||
}
|
||||
return "anyOf<" + String.join(",", names) + ">";
|
||||
}
|
||||
} else if (cs.getOneOf() != null) { // oneOf
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (Schema s : schemas) {
|
||||
if (StringUtils.isNotBlank(s.get$ref())) { // reference to another definition/schema
|
||||
String schemaName = ModelUtils.getSimpleRef(s.get$ref());
|
||||
if (StringUtils.isNotEmpty(schemaName)) {
|
||||
names.add(getAlias(schemaName));
|
||||
} else {
|
||||
LOGGER.warn("Error obtaining the datatype from ref:" + schema.get$ref() + ". Default to 'object'");
|
||||
return "object";
|
||||
}
|
||||
} else {
|
||||
// primitive type or model
|
||||
names.add(getAlias(getPrimitiveType(s)));
|
||||
}
|
||||
return "oneOf<" + String.join(",", names) + ">";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1375,6 +1427,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return "UUID";
|
||||
} else if (ModelUtils.isStringSchema(schema)) {
|
||||
return "string";
|
||||
} else if (ModelUtils.isFreeFormObject(schema)) {
|
||||
return "object";
|
||||
} else if (schema.getProperties() != null && !schema.getProperties().isEmpty()) { // having property implies it's a model
|
||||
return "object";
|
||||
} else if (StringUtils.isNotEmpty(schema.getType())) {
|
||||
@@ -1559,42 +1613,43 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
final ComposedSchema composed = (ComposedSchema) schema;
|
||||
Map<String, Schema> properties = new LinkedHashMap<String, Schema>();
|
||||
List<String> required = new ArrayList<String>();
|
||||
Map<String, Schema> allProperties;
|
||||
List<String> allRequired;
|
||||
Map<String, Schema> allProperties = new LinkedHashMap<String, Schema>();
|
||||
List<String> allRequired = new ArrayList<String>();
|
||||
|
||||
// parent model
|
||||
final String parentName = ModelUtils.getParentName(composed, allDefinitions);
|
||||
final Schema parent = StringUtils.isBlank(parentName) || allDefinitions == null ? null : allDefinitions.get(parentName);
|
||||
final boolean hasParent = StringUtils.isNotBlank(parentName);
|
||||
|
||||
// TODO revise the logic below to set dicriminator, xml attributes
|
||||
if (supportsInheritance || supportsMixins) {
|
||||
allProperties = new LinkedHashMap<String, Schema>();
|
||||
allRequired = new ArrayList<String>();
|
||||
m.allVars = new ArrayList<CodegenProperty>();
|
||||
if (composed.getAllOf() != null) {
|
||||
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
|
||||
for (Schema innerModel : composed.getAllOf()) {
|
||||
for (Schema innerSchema : composed.getAllOf()) { // TOOD need to work with anyOf, oneOf as well
|
||||
if (m.discriminator == null) {
|
||||
LOGGER.debug("discriminator is set to null (not correctly set earlier): {}", name);
|
||||
m.discriminator = createDiscriminator(name, schema, allDefinitions);
|
||||
}
|
||||
if (innerModel.getXml() != null) {
|
||||
m.xmlPrefix = innerModel.getXml().getPrefix();
|
||||
m.xmlNamespace = innerModel.getXml().getNamespace();
|
||||
m.xmlName = innerModel.getXml().getName();
|
||||
|
||||
if (innerSchema.getXml() != null) {
|
||||
m.xmlPrefix = innerSchema.getXml().getPrefix();
|
||||
m.xmlNamespace = innerSchema.getXml().getNamespace();
|
||||
m.xmlName = innerSchema.getXml().getName();
|
||||
}
|
||||
|
||||
if (modelImplCnt++ > 1) {
|
||||
LOGGER.warn("More than one inline schema specified in allOf:. Only the first one is recognized. All others are ignored.");
|
||||
break; // only one ModelImpl with discriminator allowed in allOf
|
||||
break; // only one schema with discriminator allowed in allOf
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
allProperties = null;
|
||||
allRequired = null;
|
||||
}
|
||||
// parent model
|
||||
final String parentName = getParentName(composed, allDefinitions);
|
||||
final Schema parent = StringUtils.isBlank(parentName) || allDefinitions == null ? null : allDefinitions.get(parentName);
|
||||
|
||||
List<Schema> interfaces = getInterfaces(composed);
|
||||
|
||||
// interfaces (intermediate models)
|
||||
if (interfaces != null) {
|
||||
// interfaces (schemas defined in allOf, anyOf, oneOf)
|
||||
List<Schema> interfaces = ModelUtils.getInterfaces(composed);
|
||||
if (!interfaces.isEmpty()) {
|
||||
// m.interfaces is for backward compatibility
|
||||
if (m.interfaces == null)
|
||||
m.interfaces = new ArrayList<String>();
|
||||
|
||||
@@ -1611,12 +1666,29 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
m.interfaces.add(modelName);
|
||||
addImport(m, modelName);
|
||||
if (allDefinitions != null && refSchema != null) {
|
||||
if (!supportsMixins && !supportsInheritance) {
|
||||
if (hasParent || supportsInheritance) {
|
||||
if (supportsInheritance || parentName.equals(modelName)) {
|
||||
// inheritance
|
||||
addProperties(allProperties, allRequired, refSchema, allDefinitions);
|
||||
} else {
|
||||
// composition
|
||||
//LOGGER.debug("Parent {} not set to model name {}", parentName, modelName);
|
||||
addProperties(properties, required, refSchema, allDefinitions);
|
||||
}
|
||||
} else if (!supportsMixins && !supportsInheritance) {
|
||||
addProperties(properties, required, refSchema, allDefinitions);
|
||||
}
|
||||
if (supportsInheritance) {
|
||||
addProperties(allProperties, allRequired, refSchema, allDefinitions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (composed.getAnyOf() != null) {
|
||||
m.anyOf.add(modelName);
|
||||
} else if (composed.getOneOf() != null) {
|
||||
m.oneOf.add(modelName);
|
||||
} else if (composed.getAllOf() != null) {
|
||||
m.allOf.add(modelName);
|
||||
} else {
|
||||
LOGGER.error("Composed schema has incorrect anyOf, allOf, oneOf defined: {}", composed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1626,7 +1698,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
m.parent = toModelName(parentName);
|
||||
addImport(m, m.parent);
|
||||
if (allDefinitions != null && !allDefinitions.isEmpty()) {
|
||||
if (supportsInheritance) {
|
||||
if (hasParent || supportsInheritance) {
|
||||
addProperties(allProperties, allRequired, parent, allDefinitions);
|
||||
} else {
|
||||
addProperties(properties, required, parent, allDefinitions);
|
||||
@@ -1634,23 +1706,24 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// child model (properties owned by the model itself)
|
||||
Schema child = null;
|
||||
if (composed.getAllOf() != null && !composed.getAllOf().isEmpty()) {
|
||||
for (Schema component : composed.getAllOf()) {
|
||||
if (component.get$ref() == null) {
|
||||
child = component;
|
||||
// child schema (properties owned by the schema itself)
|
||||
for (Schema component : interfaces) {
|
||||
if (component.get$ref() == null) {
|
||||
if (component != null) {
|
||||
// component is the child schema
|
||||
addProperties(properties, required, component, allDefinitions);
|
||||
|
||||
if (hasParent || supportsInheritance) {
|
||||
addProperties(allProperties, allRequired, component, allDefinitions);
|
||||
}
|
||||
}
|
||||
break; // at most one schema not using $ref
|
||||
}
|
||||
}
|
||||
if (child != null) {
|
||||
addProperties(properties, required, child, allDefinitions);
|
||||
if (supportsInheritance) {
|
||||
addProperties(allProperties, allRequired, child, allDefinitions);
|
||||
}
|
||||
}
|
||||
|
||||
addVars(m, unaliasPropertySchema(allDefinitions, properties), required, allProperties, allRequired);
|
||||
|
||||
// end of code block for composed schema
|
||||
} else {
|
||||
m.dataType = getSchemaType(schema);
|
||||
if (schema.getEnum() != null && !schema.getEnum().isEmpty()) {
|
||||
@@ -1675,17 +1748,21 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
addVars(m, unaliasPropertySchema(allDefinitions, schema.getProperties()), schema.getRequired());
|
||||
}
|
||||
|
||||
// remove duplicated properties
|
||||
m.removeAllDuplicatedProperty();
|
||||
|
||||
// post process model properties
|
||||
if (m.vars != null) {
|
||||
for (CodegenProperty prop : m.vars) {
|
||||
postProcessModelProperty(m, prop);
|
||||
}
|
||||
}
|
||||
LOGGER.debug("debugging fromModel return: " + m);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
private CodegenDiscriminator createDiscriminator(String schemaName, Schema schema, Map<String, Schema> allDefinitions) {
|
||||
private CodegenDiscriminator createDiscriminator(String schemaName, Schema
|
||||
schema, Map<String, Schema> allDefinitions) {
|
||||
if (schema.getDiscriminator() == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -1694,7 +1771,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
discriminator.setMapping(schema.getDiscriminator().getMapping());
|
||||
if (schema.getDiscriminator().getMapping() != null && !schema.getDiscriminator().getMapping().isEmpty()) {
|
||||
for (Entry<String, String> e : schema.getDiscriminator().getMapping().entrySet()) {
|
||||
String name = ModelUtils.getSimpleRef(e.getValue());
|
||||
String name = toModelName(ModelUtils.getSimpleRef(e.getValue())); // e.g e.getValue => #/components/schemas/Dog
|
||||
if (allDefinitions.get(name) == null) {
|
||||
LOGGER.warn("Discriminator's mapping: model {} (mapped to {}) couldn't be found", name, e.getKey());
|
||||
}
|
||||
discriminator.getMappedModels().add(new MappedModel(e.getKey(), name));
|
||||
}
|
||||
} else {
|
||||
@@ -1717,7 +1797,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
addParentContainer(codegenModel, codegenModel.name, schema);
|
||||
}
|
||||
|
||||
protected void addProperties(Map<String, Schema> properties, List<String> required, Schema schema, Map<String, Schema> allSchemas) {
|
||||
protected void addProperties(Map<String, Schema> properties, List<String> required, Schema
|
||||
schema, Map<String, Schema> allSchemas) {
|
||||
if (schema instanceof ComposedSchema) {
|
||||
ComposedSchema composedSchema = (ComposedSchema) schema;
|
||||
if (composedSchema.getAllOf() == null) {
|
||||
@@ -1753,9 +1834,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
if (name == null || name.length() == 0) {
|
||||
return name;
|
||||
}
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(toVarName(name));
|
||||
return camelize(toVarName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert OAS Property object to Codegen Property object
|
||||
*
|
||||
@@ -1769,10 +1851,14 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return null;
|
||||
}
|
||||
LOGGER.debug("debugging fromProperty for " + name + " : " + p);
|
||||
|
||||
// unalias schema
|
||||
p = ModelUtils.unaliasSchema(globalSchemas, p);
|
||||
|
||||
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
|
||||
property.name = toVarName(name);
|
||||
property.baseName = name;
|
||||
property.nameInCamelCase = org.openapitools.codegen.utils.StringUtils.camelize(property.name, false);
|
||||
property.nameInCamelCase = camelize(property.name, false);
|
||||
property.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, property.nameInCamelCase);
|
||||
property.description = escapeText(p.getDescription());
|
||||
property.unescapedDescription = p.getDescription();
|
||||
@@ -1997,7 +2083,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
if (itemName == null) {
|
||||
itemName = property.name;
|
||||
}
|
||||
CodegenProperty cp = fromProperty(itemName, ((ArraySchema) p).getItems());
|
||||
Schema innerSchema = ModelUtils.unaliasSchema(globalSchemas, ((ArraySchema) p).getItems());
|
||||
CodegenProperty cp = fromProperty(itemName, innerSchema);
|
||||
updatePropertyForArray(property, cp);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
property.isContainer = true;
|
||||
@@ -2008,8 +2095,12 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
property.maxItems = p.getMaxProperties();
|
||||
|
||||
// handle inner property
|
||||
CodegenProperty cp = fromProperty("inner", ModelUtils.getAdditionalProperties(p));
|
||||
Schema innerSchema = ModelUtils.unaliasSchema(globalSchemas, ModelUtils.getAdditionalProperties(p));
|
||||
CodegenProperty cp = fromProperty("inner", innerSchema);
|
||||
updatePropertyForMap(property, cp);
|
||||
} else if (ModelUtils.isFreeFormObject(p)) {
|
||||
property.isFreeFormObject = true;
|
||||
property.baseType = getSchemaType(p);
|
||||
} else { // model
|
||||
// TODO revise the logic below
|
||||
//if (StringUtils.isNotBlank(p.get$ref())) {
|
||||
@@ -2186,7 +2277,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* Override with any special handling of response codes
|
||||
*
|
||||
* @param responses OAS Operation's responses
|
||||
* @return default method response or <tt>null</tt> if not found
|
||||
* @return default method response or <code>null</code> if not found
|
||||
*/
|
||||
protected ApiResponse findMethodResponse(ApiResponses responses) {
|
||||
String code = null;
|
||||
@@ -2212,7 +2303,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @param schemas a map of OAS models
|
||||
* @return Codegen Operation object
|
||||
*/
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Schema> schemas) {
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation
|
||||
operation, Map<String, Schema> schemas) {
|
||||
return fromOperation(path, httpMethod, operation, schemas, null);
|
||||
}
|
||||
|
||||
@@ -2298,10 +2390,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
op.responses.get(op.responses.size() - 1).hasMore = false;
|
||||
|
||||
if (methodResponse != null) {
|
||||
Schema responseSchema = ModelUtils.getSchemaFromResponse(methodResponse);
|
||||
if (openAPI != null && openAPI.getComponents() != null) { // has models/aliases defined
|
||||
responseSchema = ModelUtils.unaliasSchema(openAPI.getComponents().getSchemas(), responseSchema);
|
||||
}
|
||||
Schema responseSchema = ModelUtils.unaliasSchema(globalSchemas, ModelUtils.getSchemaFromResponse(methodResponse));
|
||||
|
||||
if (responseSchema != null) {
|
||||
CodegenProperty cm = fromProperty("response", responseSchema);
|
||||
|
||||
@@ -2321,7 +2411,13 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
// generate examples
|
||||
op.examples = new ExampleGenerator(schemas, openAPI).generateFromResponseSchema(responseSchema, getProducesInfo(openAPI, operation));
|
||||
String exampleStatusCode = "200";
|
||||
for (String key : operation.getResponses().keySet()) {
|
||||
if (operation.getResponses().get(key) == methodResponse && !key.equals("default")) {
|
||||
exampleStatusCode = key;
|
||||
}
|
||||
}
|
||||
op.examples = new ExampleGenerator(schemas, openAPI).generateFromResponseSchema(exampleStatusCode, responseSchema, getProducesInfo(openAPI, operation));
|
||||
op.defaultResponse = toDefaultValue(responseSchema);
|
||||
op.returnType = cm.dataType;
|
||||
op.hasReference = schemas != null && schemas.containsKey(op.returnBaseType);
|
||||
@@ -2549,7 +2645,12 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
} else {
|
||||
r.code = responseCode;
|
||||
}
|
||||
final Schema responseSchema = ModelUtils.getSchemaFromResponse(response);
|
||||
Schema responseSchema;
|
||||
if (openAPI != null && openAPI.getComponents() != null) {
|
||||
responseSchema = ModelUtils.unaliasSchema(openAPI.getComponents().getSchemas(), ModelUtils.getSchemaFromResponse(response));
|
||||
} else { // no model/alias defined
|
||||
responseSchema = ModelUtils.getSchemaFromResponse(response);
|
||||
}
|
||||
r.schema = responseSchema;
|
||||
r.message = escapeText(response.getDescription());
|
||||
// TODO need to revise and test examples in responses
|
||||
@@ -2563,6 +2664,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
r.hasHeaders = !r.headers.isEmpty();
|
||||
|
||||
if (r.schema != null) {
|
||||
Map<String, Schema> allSchemas = null;
|
||||
CodegenProperty cp = fromProperty("response", responseSchema);
|
||||
|
||||
if (ModelUtils.isArraySchema(responseSchema)) {
|
||||
@@ -2576,6 +2678,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
} else {
|
||||
if (cp.complexType != null) {
|
||||
r.baseType = cp.complexType;
|
||||
r.isModel = true;
|
||||
} else {
|
||||
r.baseType = cp.baseType;
|
||||
}
|
||||
@@ -2616,6 +2719,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
r.isDate = true;
|
||||
} else if (Boolean.TRUE.equals(cp.isDateTime)) {
|
||||
r.isDateTime = true;
|
||||
} else if (Boolean.TRUE.equals(cp.isFreeFormObject)) {
|
||||
r.isFreeFormObject = true;
|
||||
} else {
|
||||
LOGGER.debug("Property type is not primitive: " + cp.dataType);
|
||||
}
|
||||
@@ -2651,7 +2756,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @param openAPI a OAS object representing the spec
|
||||
* @return Codegen Response object
|
||||
*/
|
||||
public CodegenCallback fromCallback(String name, Callback callback, Map<String, Schema> schemas, OpenAPI openAPI) {
|
||||
public CodegenCallback fromCallback(String name, Callback callback, Map<String, Schema> schemas, OpenAPI
|
||||
openAPI) {
|
||||
CodegenCallback c = new CodegenCallback();
|
||||
c.name = name;
|
||||
|
||||
@@ -3195,6 +3301,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
String description = headers.getValue().getDescription();
|
||||
// follow the $ref
|
||||
Header header = ModelUtils.getReferencedHeader(openAPI, headers.getValue());
|
||||
|
||||
CodegenProperty cp = fromProperty(headers.getKey(), header.getSchema());
|
||||
cp.setDescription(escapeText(description));
|
||||
cp.setUnescapedDescription(description);
|
||||
@@ -3227,7 +3334,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @param operations map of Codegen operations
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation
|
||||
co, Map<String, List<CodegenOperation>> operations) {
|
||||
List<CodegenOperation> opList = operations.get(tag);
|
||||
if (opList == null) {
|
||||
opList = new ArrayList<CodegenOperation>();
|
||||
@@ -3247,8 +3355,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
co.operationId = uniqueName;
|
||||
co.operationIdLowerCase = uniqueName.toLowerCase(Locale.ROOT);
|
||||
co.operationIdCamelCase = org.openapitools.codegen.utils.StringUtils.camelize(uniqueName);
|
||||
co.operationIdSnakeCase = org.openapitools.codegen.utils.StringUtils.underscore(uniqueName);
|
||||
co.operationIdCamelCase = camelize(uniqueName);
|
||||
co.operationIdSnakeCase = underscore(uniqueName);
|
||||
opList.add(co);
|
||||
co.baseName = tag;
|
||||
}
|
||||
@@ -3270,35 +3378,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Underscore the given word.
|
||||
* Copied from Twitter elephant bird
|
||||
* https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/util/Strings.java
|
||||
*
|
||||
* @param word The word
|
||||
* @return The underscored version of the word
|
||||
* @see org.openapitools.codegen.utils.StringUtils#underscore
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public static String underscore(String word) {
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(word);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashize the given word.
|
||||
*
|
||||
* @param word The word
|
||||
* @return The dashized version of the word, e.g. "my-name"
|
||||
* @see org.openapitools.codegen.utils.StringUtils#dashize
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
@Deprecated
|
||||
protected String dashize(String word) {
|
||||
return org.openapitools.codegen.utils.StringUtils.dashize(word);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the next name for the given name, i.e. append "2" to the base name if not ending with a number,
|
||||
* otherwise increase the number by 1. For example:
|
||||
@@ -3334,7 +3413,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @param properties model properties (schemas)
|
||||
* @return model properties with direct reference to schemas
|
||||
*/
|
||||
private Map<String, Schema> unaliasPropertySchema(Map<String, Schema> allSchemas, Map<String, Schema> properties) {
|
||||
private Map<String, Schema> unaliasPropertySchema
|
||||
(Map<String, Schema> allSchemas, Map<String, Schema> properties) {
|
||||
if (properties != null) {
|
||||
for (String key : properties.keySet()) {
|
||||
properties.put(key, ModelUtils.unaliasSchema(allSchemas, properties.get(key)));
|
||||
@@ -3375,7 +3455,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private void addVars(CodegenModel m, List<CodegenProperty> vars, Map<String, Schema> properties, Set<String> mandatory) {
|
||||
private void addVars(CodegenModel
|
||||
m, List<CodegenProperty> vars, Map<String, Schema> properties, Set<String> mandatory) {
|
||||
// convert set to list so that we can access the next entry in the loop
|
||||
List<Map.Entry<String, Schema>> propertyList = new ArrayList<Map.Entry<String, Schema>>(properties.entrySet());
|
||||
final int totalCount = propertyList.size();
|
||||
@@ -3496,37 +3577,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Camelize name (parameter, property, method, etc) with upper case for first letter
|
||||
* copied from Twitter elephant bird
|
||||
* https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/util/Strings.java
|
||||
*
|
||||
* @param word string to be camelize
|
||||
* @return camelized string
|
||||
* @see org.openapitools.codegen.utils.StringUtils#camelize(String)
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public static String camelize(String word) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(word);
|
||||
}
|
||||
|
||||
/**
|
||||
* Camelize name (parameter, property, method, etc)
|
||||
*
|
||||
* @param word string to be camelize
|
||||
* @param lowercaseFirstLetter lower case for first letter if set to true
|
||||
* @return camelized string
|
||||
* @see org.openapitools.codegen.utils.StringUtils#camelize(String, boolean)
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public static String camelize(String word, boolean lowercaseFirstLetter) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(word, lowercaseFirstLetter);
|
||||
}
|
||||
|
||||
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String suffix = apiTemplateFiles().get(templateName);
|
||||
return apiFileFolder() + File.separator + toApiFilename(tag) + suffix;
|
||||
@@ -3888,6 +3938,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
} else if (Boolean.TRUE.equals(property.isDateTime)) {
|
||||
parameter.isDateTime = true;
|
||||
parameter.isPrimitiveType = true;
|
||||
} else if (Boolean.TRUE.equals(property.isFreeFormObject)) {
|
||||
parameter.isFreeFormObject = true;
|
||||
} else {
|
||||
LOGGER.debug("Property type is not primitive: " + property.dataType);
|
||||
}
|
||||
@@ -3961,7 +4013,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateEnumVarsWithExtensions(List<Map<String, Object>> enumVars, Map<String, Object> vendorExtensions) {
|
||||
private void updateEnumVarsWithExtensions
|
||||
(List<Map<String, Object>> enumVars, Map<String, Object> vendorExtensions) {
|
||||
if (vendorExtensions != null && vendorExtensions.containsKey("x-enum-varnames")) {
|
||||
List<String> alias = (List<String>) vendorExtensions.get("x-enum-varnames");
|
||||
int size = Math.min(enumVars.size(), alias.size());
|
||||
@@ -4080,19 +4133,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private List<Schema> getInterfaces(ComposedSchema composed) {
|
||||
List<Schema> interfaces;
|
||||
if (composed.getAllOf() != null && !composed.getAllOf().isEmpty()) {
|
||||
return composed.getAllOf();
|
||||
} else if (composed.getAnyOf() != null && !composed.getAnyOf().isEmpty()) {
|
||||
return composed.getAnyOf();
|
||||
} else if (composed.getOneOf() != null && !composed.getOneOf().isEmpty()) {
|
||||
return composed.getOneOf();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void addConsumesInfo(OpenAPI openAPI, Operation operation, CodegenOperation codegenOperation) {
|
||||
RequestBody requestBody = ModelUtils.getReferencedRequestBody(openAPI, operation.getRequestBody());
|
||||
if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) {
|
||||
@@ -4229,18 +4269,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return produces;
|
||||
}
|
||||
|
||||
protected String getParentName(ComposedSchema composedSchema, Map<String, Schema> allSchemas) {
|
||||
if (composedSchema.getAllOf() != null && !composedSchema.getAllOf().isEmpty()) {
|
||||
for (Schema schema : composedSchema.getAllOf()) {
|
||||
String ref = schema.get$ref();
|
||||
if (!StringUtils.isBlank(ref)) {
|
||||
return ModelUtils.getSimpleRef(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getCollectionFormat(Parameter parameter) {
|
||||
if (Parameter.StyleEnum.FORM.equals(parameter.getStyle())) {
|
||||
// Ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#style-values
|
||||
@@ -4272,7 +4300,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body, Map<String, Schema> schemas, Set<String> imports) {
|
||||
public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody
|
||||
body, Map<String, Schema> schemas, Set<String> imports) {
|
||||
List<CodegenParameter> parameters = new ArrayList<CodegenParameter>();
|
||||
LOGGER.debug("debugging fromRequestBodyToFormParameters= " + body);
|
||||
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
|
||||
@@ -4428,7 +4457,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return codegenParameter;
|
||||
}
|
||||
|
||||
public CodegenParameter fromRequestBody(RequestBody body, Map<String, Schema> schemas, Set<String> imports, String bodyParameterName) {
|
||||
public CodegenParameter fromRequestBody(RequestBody
|
||||
body, Map<String, Schema> schemas, Set<String> imports, String bodyParameterName) {
|
||||
if (body == null) {
|
||||
LOGGER.error("body in fromRequestBody cannot be null!");
|
||||
}
|
||||
@@ -4735,7 +4765,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
/**
|
||||
* Set the boolean value indicating the state of the option for post-processing file using envirionment variables.
|
||||
*
|
||||
* @param enablePostProcessFile true to enable post-processing file
|
||||
* @param enablePostProcessFile true to enable post-processing file
|
||||
*/
|
||||
public void setEnablePostProcessFile(boolean enablePostProcessFile) {
|
||||
this.enablePostProcessFile = enablePostProcessFile;
|
||||
|
||||
@@ -38,7 +38,6 @@ import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.ignore.CodegenIgnoreProcessor;
|
||||
//import org.openapitools.codegen.languages.AbstractJavaCodegen;
|
||||
import org.openapitools.codegen.utils.ImplementationVersion;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.openapitools.codegen.utils.URLPathUtils;
|
||||
@@ -181,6 +180,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
|
||||
config.processOpts();
|
||||
config.preprocessOpenAPI(openAPI);
|
||||
|
||||
// set OpenAPI and schemas to make these available to all methods
|
||||
config.setGlobalOpenAPI(openAPI);
|
||||
config.setGlobalSchemas(openAPI);
|
||||
|
||||
config.additionalProperties().put("generatorVersion", ImplementationVersion.read());
|
||||
config.additionalProperties().put("generatedDate", ZonedDateTime.now().toString());
|
||||
config.additionalProperties().put("generatedYear", String.valueOf(ZonedDateTime.now().getYear()));
|
||||
@@ -424,6 +428,25 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
|
||||
Schema schema = schemas.get(name);
|
||||
|
||||
// check to see if it's a "map" model
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
if (schema.getProperties() == null || schema.getProperties().isEmpty()) {
|
||||
// schema without property, i.e. alias to map
|
||||
LOGGER.info("Model " + name + " not generated since it's an alias to map (without property)");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// check to see if it's an "array" model
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
if (schema.getProperties() == null || schema.getProperties().isEmpty()) {
|
||||
// schema without property, i.e. alias to array
|
||||
LOGGER.info("Model " + name + " not generated since it's an alias to array (without property)");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Schema> schemaMap = new HashMap<>();
|
||||
schemaMap.put(name, schema);
|
||||
Map<String, Object> models = processModels(config, schemaMap, schemas);
|
||||
|
||||
@@ -34,7 +34,7 @@ public class GeneratorNotFoundException extends RuntimeException {
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
* by the {@link #getMessage()} method).
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* {@link #getCause()} method). (A <code>null</code> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
@@ -45,13 +45,13 @@ public class GeneratorNotFoundException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified cause and a
|
||||
* detail message of <tt>(cause==null ? null : cause.toString())</tt>
|
||||
* detail message of <code>(cause==null ? null : cause.toString())</code>
|
||||
* (which typically contains the class and detail message of
|
||||
* <tt>cause</tt>). This constructor is useful for runtime exceptions
|
||||
* <code>cause</code>). This constructor is useful for runtime exceptions
|
||||
* that are little more than wrappers for other throwables.
|
||||
*
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* {@link #getCause()} method). (A <code>null</code> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SpecValidationException extends RuntimeException {
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
* by the {@link #getMessage()} method).
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* {@link #getCause()} method). (A <code>null</code> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
@@ -47,13 +47,13 @@ public class SpecValidationException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified cause and a
|
||||
* detail message of <tt>(cause==null ? null : cause.toString())</tt>
|
||||
* detail message of <code>(cause==null ? null : cause.toString())</code>
|
||||
* (which typically contains the class and detail message of
|
||||
* <tt>cause</tt>). This constructor is useful for runtime exceptions
|
||||
* <code>cause</code>). This constructor is useful for runtime exceptions
|
||||
* that are little more than wrappers for other throwables.
|
||||
*
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* {@link #getCause()} method). (A <code>null</code> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
|
||||
@@ -42,6 +42,7 @@ public class ExampleGenerator {
|
||||
private static final String NONE = "none";
|
||||
private static final String URL = "url";
|
||||
private static final String URI = "uri";
|
||||
private static final String STATUS_CODE = "statusCode";
|
||||
|
||||
protected Map<String, Schema> examples;
|
||||
private OpenAPI openAPI;
|
||||
@@ -54,7 +55,20 @@ public class ExampleGenerator {
|
||||
this.random = new Random("ExampleGenerator".hashCode());
|
||||
}
|
||||
|
||||
public List<Map<String, String>> generateFromResponseSchema(Schema responseSchema, Set<String> producesInfo) {
|
||||
public List<Map<String, String>> generateFromResponseSchema(String statusCode, Schema responseSchema, Set<String> producesInfo) {
|
||||
List<Map<String, String>> examples = generateFromResponseSchema(responseSchema, producesInfo);
|
||||
if (examples == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Map<String, String> example : examples) {
|
||||
example.put(STATUS_CODE, statusCode);
|
||||
}
|
||||
|
||||
return examples;
|
||||
}
|
||||
|
||||
private List<Map<String, String>> generateFromResponseSchema(Schema responseSchema, Set<String> producesInfo) {
|
||||
if (responseSchema.getExample() == null && StringUtils.isEmpty(responseSchema.get$ref()) && !ModelUtils.isArraySchema(responseSchema)) {
|
||||
// no example provided
|
||||
return null;
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
abstract public class AbstractAdaCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractAdaCodegen.class);
|
||||
@@ -666,7 +667,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
// method with only the scope that it requires. We have to create a new auth method
|
||||
// instance because the original object must not be modified.
|
||||
List<String> opScopes = (scopes == null) ? null : scopes.get(authMethod.name);
|
||||
authMethod.name = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(authMethod.name), true);
|
||||
authMethod.name = camelize(sanitizeName(authMethod.name), true);
|
||||
if (opScopes != null) {
|
||||
CodegenSecurity opSecurity = new CodegenSecurity();
|
||||
opSecurity.name = authMethod.name;
|
||||
|
||||
@@ -36,6 +36,8 @@ import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public abstract class AbstractApexCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractApexCodegen.class);
|
||||
|
||||
@@ -112,7 +114,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(name, true);
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@@ -159,7 +161,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
final String camelizedName = org.openapitools.codegen.utils.StringUtils.camelize(nameWithPrefixSuffix);
|
||||
final String camelizedName = camelize(nameWithPrefixSuffix);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(camelizedName)) {
|
||||
@@ -422,11 +424,11 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
@@ -515,7 +517,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum";
|
||||
return sanitizeName(camelize(property.name)) + "Enum";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -669,7 +671,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String sanitizeTag(String tag) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(tag));
|
||||
return camelize(sanitizeName(tag));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user