forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 4.0.x
This commit is contained in:
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.3.x`, `4.0.x`. Default: `master`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master` (3.3.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
|
||||
|
||||
35
README.md
35
README.md
@@ -42,7 +42,7 @@ 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 - 6.x), Aurelia, Fetch, Inversify, jQuery, Node)
|
||||
**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 - 6.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node)
|
||||
**Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go**, **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/)
|
||||
@@ -366,21 +366,23 @@ To get a list of PHP specified options (which can be passed to the generator wit
|
||||
You can build a client against the [Petstore API](https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml) as follows:
|
||||
|
||||
```sh
|
||||
./bin/java-petstore.sh
|
||||
./bin/java-petstore-okhttp-gson.sh
|
||||
```
|
||||
|
||||
(On Windows, run `.\bin\windows\java-petstore.bat` instead)
|
||||
(On Windows, run `.\bin\windows\java-petstore-okhttp-gson.bat` instead)
|
||||
|
||||
This will run the generator with this command:
|
||||
This script uses the default library, which is `okhttp-gson`. It will run the generator with this command:
|
||||
|
||||
```sh
|
||||
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
|
||||
-i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml \
|
||||
-g java \
|
||||
-o samples/client/petstore/java
|
||||
-o samples/client/petstore/java/okhttp-gson
|
||||
```
|
||||
|
||||
with a number of options. You can get the options with the `help generate` command (below only shows partial results):
|
||||
with a number of options. [The java options are documented here.](docs/generators/java.md)
|
||||
|
||||
You can also get the options with the `help generate` command (below only shows partial results):
|
||||
|
||||
```
|
||||
NAME
|
||||
@@ -432,16 +434,19 @@ OPTIONS
|
||||
You can then compile and run the client, as well as unit tests against it:
|
||||
|
||||
```sh
|
||||
cd samples/client/petstore/java
|
||||
cd samples/client/petstore/java/okhttp-gson
|
||||
mvn package
|
||||
```
|
||||
|
||||
Other languages have petstore samples, too:
|
||||
```sh
|
||||
./bin/android-petstore.sh
|
||||
./bin/java-petstore.sh
|
||||
./bin/android-petstore-all.sh
|
||||
./bin/java-petstore-all.sh
|
||||
./bin/objc-petstore.sh
|
||||
```
|
||||
|
||||
... and others. [Here is a list of all scripts.](wiki/Samples-folder#scripts)
|
||||
|
||||
### [3.1 - Customization](#table-of-contents)
|
||||
|
||||
Please refer to [customization.md](docs/customization.md) on how to customize the output (e.g. package name, version)
|
||||
@@ -471,6 +476,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- [Boxever](https://www.boxever.com/)
|
||||
- [GMO Pepabo](https://pepabo.com/en/)
|
||||
- [JustStar](https://www.juststarinfo.com)
|
||||
- [Myworkout](https://myworkout.com)
|
||||
- [Raiffeisen Schweiz Genossenschaft](https://www.raiffeisen.ch)
|
||||
- [RepreZen API Studio](https://www.reprezen.com/swagger-openapi-code-generation-api-first-microservices-enterprise-development)
|
||||
- [REST United](https://restunited.com)
|
||||
@@ -488,6 +494,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- 2018/06/21 - [Connect your JHipster apps to the world of APIs with OpenAPI and gRPC](https://fr.slideshare.net/chbornet/jhipster-conf-2018-connect-your-jhipster-apps-to-the-world-of-apis-with-openapi-and-grpc) by [Christophe Bornet](https://github.com/cbornet) at [JHipster Conf 2018](https://jhipster-conf.github.io/)
|
||||
- 2018/06/27 - [Lessons Learned from Leading an Open-Source Project Supporting 30+ Programming Languages](https://speakerdeck.com/wing328/lessons-learned-from-leading-an-open-source-project-supporting-30-plus-programming-languages) - [William Cheng](https://github.com/wing328) at [LinuxCon + ContainerCon + CloudOpen China 2018](http://bit.ly/2waDKKX)
|
||||
- 2018/07/19 - [OpenAPI Generator Contribution Quickstart - RingCentral Go SDK](https://medium.com/ringcentral-developers/openapi-generator-for-go-contribution-quickstart-8cc72bf37b53) by [John Wang](https://github.com/grokify)
|
||||
- 2018/08/22 - [OpenAPI Generatorのプロジェクト構成などのメモ](https://yinm.info/20180822/) by [Yusuke Iinuma](https://github.com/yinm)
|
||||
|
||||
## [6 - About Us](#table-of-contents)
|
||||
|
||||
@@ -519,6 +526,7 @@ Here is a list of template creators:
|
||||
* Dart: @yissachar
|
||||
* Dart (refactor): @joernahrens
|
||||
* Dart 2: @swipesight
|
||||
* Dart (Jaguar): @jaumard
|
||||
* Elixir: @niku
|
||||
* Elm: @trenneman
|
||||
* Eiffel: @jvelilla
|
||||
@@ -554,11 +562,12 @@ Here is a list of template creators:
|
||||
* Swift: @tkqubo
|
||||
* Swift 3: @hexelon
|
||||
* Swift 4: @ehyche
|
||||
* TypeScript (Node): @mhardorf
|
||||
* TypeScript (Angular1): @mhardorf
|
||||
* TypeScript (Fetch): @leonyu
|
||||
* TypeScript (Angular2): @roni-frantchi
|
||||
* TypeScript (Axios): @nicokoenig
|
||||
* TypeScript (Fetch): @leonyu
|
||||
* TypeScript (jQuery): @bherila
|
||||
* TypeScript (Node): @mhardorf
|
||||
* Server Stubs
|
||||
* Ada: @stcarrez
|
||||
* C# ASP.NET5: @jimschubert
|
||||
@@ -634,7 +643,7 @@ If you want to join the committee, please kindly apply by sending an email to te
|
||||
| C++ | @ravinikam (2017/07) @stkrwork (2017/07) @fvarose (2017/11) @etherealjoy (2018/02) @martindelille (2018/03) |
|
||||
| C# | @mandrean (2017/08) @jimschubert (2017/09) |
|
||||
| Clojure | |
|
||||
| Dart | @ircecho (2017/07) @swipesight (2018/09) |
|
||||
| Dart | @ircecho (2017/07) @swipesight (2018/09) @jaumard (2018/09) |
|
||||
| Eiffel | @jvelilla (2017/09) |
|
||||
| Elixir | |
|
||||
| Elm | @trenneman (2018/09) |
|
||||
@@ -656,7 +665,7 @@ If you want to join the committee, please kindly apply by sending an email to te
|
||||
| Rust | @frol (2017/07) @farcaller (2017/08) @bjgill (2017/12) |
|
||||
| Scala | @clasnake (2017/07) @jimschubert (2017/09) @shijinkui (2018/01) @ramzimaalej (2018/03) |
|
||||
| Swift | @jgavris (2017/07) @ehyche (2017/08) @Edubits (2017/09) @jaz-ah (2017/09) @d-date (2018/03) |
|
||||
| TypeScript | @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) |
|
||||
| TypeScript | @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) |
|
||||
|
||||
### [6.3 - History of OpenAPI Generator](#table-of-contents)
|
||||
|
||||
|
||||
34
bin/go-gin-petstore-server.sh
Executable file
34
bin/go-gin-petstore-server.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/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/go-gin-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g go-gin-server -o samples/server/petstore/go-gin-api-server -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
#!/usr/bin/env bash
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
./bin/java-petstore-retrofit2-play24.sh
|
||||
./bin/java-petstore-retrofit2-play25.sh
|
||||
./bin/java-petstore-retrofit2-play26.sh
|
||||
./bin/java-petstore-retrofit2.sh
|
||||
./bin/java-petstore-retrofit2rx.sh
|
||||
./bin/java-petstore-retrofit2rx2.sh
|
||||
|
||||
32
bin/mysql-schema-petstore.sh
Normal file
32
bin/mysql-schema-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/mysql-schema -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g mysql-schema -o samples/schema/petstore/mysql $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
32
bin/security/mysql-schema-petstore.sh
Normal file
32
bin/security/mysql-schema-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 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/mysql-schema -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g mysql-schema -o samples/schema/petstore-security-test/mysql $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
6
bin/typescript-axios-petstore-all.sh
Normal file
6
bin/typescript-axios-petstore-all.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
./bin/typescript-axios-petstore-target-es6.sh
|
||||
./bin/typescript-axios-petstore-with-npm-version.sh
|
||||
./bin/typescript-axios-petstore-interfaces.sh
|
||||
./bin/typescript-axios-petstore.sh
|
||||
32
bin/typescript-axios-petstore-interfaces.sh
Normal file
32
bin/typescript-axios-petstore-interfaces.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 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-axios -o samples/client/petstore/typescript-axios/builds/with-interfaces -D withInterfaces=true $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
7
bin/typescript-axios-petstore-target-es6.json
Normal file
7
bin/typescript-axios-petstore-target-es6.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"npmName": "@swagger/typescript-axios-petstore",
|
||||
"npmVersion": "1.0.0",
|
||||
"npmRepository": "https://skimdb.npmjs.com/registry",
|
||||
"snapshot": false,
|
||||
"supportsES6": true
|
||||
}
|
||||
32
bin/typescript-axios-petstore-target-es6.sh
Normal file
32
bin/typescript-axios-petstore-target-es6.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 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-axios -c bin/typescript-axios-petstore-target-es6.json -o samples/client/petstore/typescript-axios/builds/es6-target $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
6
bin/typescript-axios-petstore-with-npm-version.json
Normal file
6
bin/typescript-axios-petstore-with-npm-version.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"npmName": "@swagger/typescript-axios-petstore",
|
||||
"npmVersion": "1.0.0",
|
||||
"npmRepository": "https://skimdb.npmjs.com/registry",
|
||||
"snapshot": false
|
||||
}
|
||||
32
bin/typescript-axios-petstore-with-npm-version.sh
Normal file
32
bin/typescript-axios-petstore-with-npm-version.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 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-axios -c bin/typescript-axios-petstore-with-npm-version.json -o samples/client/petstore/typescript-axios/builds/with-npm-version $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
32
bin/typescript-axios-petstore.sh
Normal file
32
bin/typescript-axios-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 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-axios -o samples/client/petstore/typescript-axios/builds/default $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -18,6 +18,7 @@ sleep 5
|
||||
./bin/kotlin-client-string.sh > /dev/null 2>&1
|
||||
./bin/kotlin-client-threetenbp.sh > /dev/null 2>&1
|
||||
./bin/kotlin-server-petstore.sh > /dev/null 2>&1
|
||||
./bin/mysql-schema-petstore.sh > /dev/null 2>&1
|
||||
./bin/php-petstore.sh > /dev/null 2>&1
|
||||
./bin/php-silex-petstore-server.sh > /dev/null 2>&1
|
||||
./bin/php-symfony-petstore.sh > /dev/null 2>&1
|
||||
@@ -30,10 +31,11 @@ sleep 5
|
||||
./bin/typescript-node-petstore-all.sh > /dev/null 2>&1
|
||||
./bin/typescript-inversify-petstore.sh > /dev/null 2>&1
|
||||
./bin/rust-server-petstore.sh > /dev/null 2>&1
|
||||
./bin/openapi3/haskell-http-client-petstore.sh > /dev/null 2>&1
|
||||
./bin/haskell-http-client-petstore.sh > /dev/null 2>&1
|
||||
./bin/csharp-petstore.sh > /dev/null 2>&1
|
||||
./bin/meta-codegen.sh > /dev/null 2>&1
|
||||
./bin/utils/export_docs_generators.sh > /dev/null 2>&1
|
||||
./bin/go-gin-petstore-server.sh > /dev/null 2>&1
|
||||
|
||||
# Check:
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
|
||||
10
bin/windows/go-gin-petstore-server.bat
Normal file
10
bin/windows/go-gin-petstore-server.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 go-gin-server -o samples\server\petstore\go-gin-api-server -DpackageName=petstoreserver -Dservice
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
6
bin/windows/typescript-axios-petstore-all.bat
Normal file
6
bin/windows/typescript-axios-petstore-all.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@ECHO OFF
|
||||
|
||||
call bin\windows\typescript-axios-petstore.bat
|
||||
call bin\windows\typescript-axios-petstore-target-es6.bat
|
||||
call bin\windows\typescript-axios-petstore-with-npm-version.bat
|
||||
call bin\windows\typescript-axios-petstore-interfaces.bat
|
||||
12
bin/windows/typescript-axios-petstore-interfaces.bat
Normal file
12
bin/windows/typescript-axios-petstore-interfaces.bat
Normal file
@@ -0,0 +1,12 @@
|
||||
@ECHO OFF
|
||||
|
||||
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 typescript-axios -o samples\client\petstore\typescript-axios\builds\with-interfaces -D withInterfaces=true
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
12
bin/windows/typescript-axios-petstore-target-es6.bat
Normal file
12
bin/windows/typescript-axios-petstore-target-es6.bat
Normal file
@@ -0,0 +1,12 @@
|
||||
@ECHO OFF
|
||||
|
||||
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 typescript-axios -c bin\typescript-axios-petstore-target-es6.json -o samples\client\petstore\typescript-axios\builds\es6-target
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
12
bin/windows/typescript-axios-petstore-with-npm-version.bat
Normal file
12
bin/windows/typescript-axios-petstore-with-npm-version.bat
Normal file
@@ -0,0 +1,12 @@
|
||||
@ECHO OFF
|
||||
|
||||
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 typescript-axios -c bin\typescript-axios-petstore-with-npm-version.json -o samples\client\petstore\typescript-axios\builds\with-npm-version
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
14
bin/windows/typescript-axios-petstore.bat
Normal file
14
bin/windows/typescript-axios-petstore.bat
Normal file
@@ -0,0 +1,14 @@
|
||||
@ECHO OFF
|
||||
|
||||
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
|
||||
|
||||
echo
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g typescript-axios -o samples\client\petstore\typescript-axios\builds\default
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -61,6 +61,7 @@ The following generators are available:
|
||||
- [csharp-nancyfx](csharp-nancyfx.md)
|
||||
- [erlang-server](erlang-server.md)
|
||||
- [go-server](go-server.md)
|
||||
- [go-gin-server](go-gin-server.md)
|
||||
- [haskell](haskell.md)
|
||||
- [java-inflector](java-inflector.md)
|
||||
- [java-msf4j](java-msf4j.md)
|
||||
|
||||
10
docs/generators/go-gin-server.md
Normal file
10
docs/generators/go-gin-server.md
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
CONFIG OPTIONS for go-gin-server
|
||||
|
||||
packageName
|
||||
Go package name (convention: lowercase). (Default: openapi)
|
||||
|
||||
hideGenerationTimestamp
|
||||
Hides the generation timestamp when files are generated. (Default: true)
|
||||
|
||||
Back to the [generators list](README.md)
|
||||
@@ -98,7 +98,7 @@
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum CodegenType {
|
||||
CLIENT, SERVER, DOCUMENTATION, CONFIG, OTHER;
|
||||
CLIENT, SERVER, DOCUMENTATION, SCHEMA, CONFIG, OTHER;
|
||||
|
||||
private static Map<String, CodegenType> names = new HashMap<String, CodegenType>();
|
||||
|
||||
@@ -49,6 +49,7 @@ public enum CodegenType {
|
||||
names.put("client", CLIENT);
|
||||
names.put("server", SERVER);
|
||||
names.put("documentation", DOCUMENTATION);
|
||||
names.put("schema", SCHEMA);
|
||||
names.put("other", OTHER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -841,15 +841,14 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
/**
|
||||
* Return the name with escaped characters.
|
||||
*
|
||||
* @param name the name to be escaped
|
||||
* @param charactersToAllow characters that are not escaped
|
||||
* @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.
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
* @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) {
|
||||
@@ -1096,11 +1095,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
public String toInstantiationType(Schema schema) {
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
Schema additionalProperties = ModelUtils.getAdditionalProperties(schema);
|
||||
String type = additionalProperties.getType();
|
||||
if (null == type) {
|
||||
LOGGER.error("No Type defined for Additional Property " + additionalProperties + "\n" //
|
||||
+ "\tIn Property: " + schema);
|
||||
}
|
||||
String inner = getSchemaType(additionalProperties);
|
||||
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
||||
} else if (ModelUtils.isArraySchema(schema)) {
|
||||
@@ -2254,7 +2248,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
operationId = removeNonNameElementToCamelCase(operationId);
|
||||
|
||||
op.path = path;
|
||||
if (path.startsWith("/")) {
|
||||
op.path = path;
|
||||
} else {
|
||||
op.path = "/" + path;
|
||||
}
|
||||
op.operationId = toOperationId(operationId);
|
||||
op.summary = escapeText(operation.getSummary());
|
||||
op.unescapedNotes = operation.getDescription();
|
||||
@@ -2291,7 +2289,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
op.responses.get(op.responses.size() - 1).hasMore = false;
|
||||
|
||||
if (methodResponse != null) {
|
||||
final Schema responseSchema = ModelUtils.getSchemaFromResponse(methodResponse);
|
||||
Schema responseSchema = ModelUtils.getSchemaFromResponse(methodResponse);
|
||||
if (openAPI != null && openAPI.getComponents() != null) { // has models/aliases defined
|
||||
responseSchema = ModelUtils.unaliasSchema(openAPI.getComponents().getSchemas(), responseSchema);
|
||||
}
|
||||
if (responseSchema != null) {
|
||||
CodegenProperty cm = fromProperty("response", responseSchema);
|
||||
|
||||
@@ -2658,12 +2659,12 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
Stream.of(
|
||||
Pair.of("get", pi.getGet()),
|
||||
Pair.of("head", pi.getHead()),
|
||||
Pair.of("put", pi.getPut()),
|
||||
Pair.of("post", pi.getPost()),
|
||||
Pair.of("delete", pi.getDelete()),
|
||||
Pair.of("patch", pi.getPatch()),
|
||||
Pair.of("get", pi.getGet()),
|
||||
Pair.of("head", pi.getHead()),
|
||||
Pair.of("put", pi.getPut()),
|
||||
Pair.of("post", pi.getPost()),
|
||||
Pair.of("delete", pi.getDelete()),
|
||||
Pair.of("patch", pi.getPatch()),
|
||||
Pair.of("options", pi.getOptions()))
|
||||
.filter(p -> p.getValue() != null)
|
||||
.forEach(p -> {
|
||||
@@ -2672,7 +2673,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
boolean genId = op.getOperationId() == null;
|
||||
if (genId) {
|
||||
op.setOperationId(getOrGenerateOperationId(op, c.name+"_"+expression.replaceAll("\\{\\$.*}", ""), method));
|
||||
op.setOperationId(getOrGenerateOperationId(op, c.name + "_" + expression.replaceAll("\\{\\$.*}", ""), method));
|
||||
}
|
||||
|
||||
if (op.getExtensions() == null) {
|
||||
@@ -3261,8 +3262,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*
|
||||
* @param word The word
|
||||
* @return The underscored version of the word
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
* @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) {
|
||||
@@ -3274,8 +3275,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*
|
||||
* @param word The word
|
||||
* @return The dashized version of the word, e.g. "my-name"
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
* @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
|
||||
@@ -3488,8 +3489,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*
|
||||
* @param word string to be camelize
|
||||
* @return camelized string
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
* @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) {
|
||||
@@ -3502,8 +3503,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @param word string to be camelize
|
||||
* @param lowercaseFirstLetter lower case for first letter if set to true
|
||||
* @return camelized string
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
* @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) {
|
||||
@@ -4693,10 +4694,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* Post-process the auto-generated file, e.g. using go-fmt to format the Go code. The file type can be "model-test",
|
||||
* "model-doc", "model", "api", "api-test", "api-doc", "supporting-mustache", "supporting-common",
|
||||
* "openapi-generator-ignore", "openapi-generator-version"
|
||||
*
|
||||
* <p>
|
||||
* TODO: store these values in enum instead
|
||||
*
|
||||
* @param file file to be processed
|
||||
* @param file file to be processed
|
||||
* @param fileType file type
|
||||
*/
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
|
||||
@@ -193,15 +193,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
|
||||
URL url = URLPathUtils.getServerURL(openAPI);
|
||||
contextPath = config.escapeText(url.getPath());
|
||||
basePathWithoutHost = contextPath; // for backward compatibility
|
||||
basePath = config.escapeText(URLPathUtils.getHost(openAPI));
|
||||
if ("/".equals(basePath.substring(basePath.length() - 1))) {
|
||||
// remove trailing "/"
|
||||
// https://host.example.com/ => https://host.example.com
|
||||
basePath = basePath.substring(0, basePath.length() - 1);
|
||||
}
|
||||
|
||||
contextPath = config.escapeText(url.getPath()).replaceAll("/$", ""); // for backward compatibility
|
||||
basePathWithoutHost = contextPath;
|
||||
basePath = config.escapeText(URLPathUtils.getHost(openAPI)).replaceAll("/$", "");
|
||||
}
|
||||
|
||||
private void configureOpenAPIInfo() {
|
||||
|
||||
@@ -24,6 +24,8 @@ import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
@@ -414,9 +416,38 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add a vendor extension attribute that provides a map of auth methods and the scopes
|
||||
// which are expected by the operation. This map is then used by postProcessOperationsWithModels
|
||||
// to build another vendor extension that provides a subset of the auth methods with only
|
||||
// the scopes required by the operation.
|
||||
final List<SecurityRequirement> securities = operation.getSecurity();
|
||||
if (securities != null && securities.size() > 0) {
|
||||
final Map<String, SecurityScheme> securitySchemes = openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null;
|
||||
final List<SecurityRequirement> globalSecurities = openAPI.getSecurity();
|
||||
|
||||
Map<String, List<String>> scopes = getAuthScopes(securities, securitySchemes);
|
||||
if (scopes.isEmpty() && globalSecurities != null) {
|
||||
scopes = getAuthScopes(globalSecurities, securitySchemes);
|
||||
}
|
||||
op.vendorExtensions.put("x-scopes", scopes);
|
||||
}
|
||||
return op;
|
||||
}
|
||||
|
||||
private Map<String, List<String>> getAuthScopes(List<SecurityRequirement> securities, Map<String, SecurityScheme> securitySchemes) {
|
||||
final Map<String, List<String>> scopes = new HashMap<>();
|
||||
for (SecurityRequirement requirement : securities) {
|
||||
for (String key : requirement.keySet()) {
|
||||
SecurityScheme securityScheme = securitySchemes.get(key);
|
||||
if (securityScheme != null) {
|
||||
scopes.put(key, requirement.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return scopes;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||
@@ -449,7 +480,14 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
p.dataType = "Swagger.File_Part_Type";
|
||||
}
|
||||
}
|
||||
postProcessAuthMethod(op1.authMethods);
|
||||
|
||||
// Given the operation scopes and the auth methods, build a list of auth methods that only
|
||||
// describe the auth methods and scopes required by the operation.
|
||||
final Map<String, List<String>> scopes = (Map<String, List<String>>) op1.vendorExtensions.get("x-scopes");
|
||||
List<CodegenSecurity> opScopes = postProcessAuthMethod(op1.authMethods, scopes);
|
||||
if (opScopes != null) {
|
||||
op1.vendorExtensions.put("x-auth-scopes", opScopes);
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan the path parameter to construct a x-path-index that tells the index of
|
||||
@@ -584,7 +622,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
* Collect the scopes to generate unique identifiers for each of them.
|
||||
*/
|
||||
List<CodegenSecurity> authMethods = (List<CodegenSecurity>) objs.get("authMethods");
|
||||
postProcessAuthMethod(authMethods);
|
||||
postProcessAuthMethod(authMethods, null);
|
||||
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
@@ -593,8 +631,11 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
* Collect the scopes to generate a unique identifier for each of them.
|
||||
*
|
||||
* @param authMethods the auth methods with their scopes.
|
||||
* @param scopes the optional auth methods and scopes required by an operation
|
||||
* @return the authMethods to be used by the operation with its required scopes.
|
||||
*/
|
||||
private void postProcessAuthMethod(List<CodegenSecurity> authMethods) {
|
||||
private List<CodegenSecurity> postProcessAuthMethod(List<CodegenSecurity> authMethods, Map<String, List<String>> scopes) {
|
||||
List<CodegenSecurity> result = (scopes == null) ? null : new ArrayList<CodegenSecurity>();
|
||||
if (authMethods != null) {
|
||||
for (CodegenSecurity authMethod : authMethods) {
|
||||
if (authMethod.scopes != null) {
|
||||
@@ -620,8 +661,39 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we have operation scopes, filter the auth method to describe the operation auth
|
||||
// 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);
|
||||
if (opScopes != null) {
|
||||
CodegenSecurity opSecurity = new CodegenSecurity();
|
||||
opSecurity.name = authMethod.name;
|
||||
opSecurity.type = authMethod.type;
|
||||
opSecurity.hasMore = false;
|
||||
opSecurity.isBasic = authMethod.isBasic;
|
||||
opSecurity.isApiKey = authMethod.isApiKey;
|
||||
opSecurity.isKeyInCookie = authMethod.isKeyInCookie;
|
||||
opSecurity.isKeyInHeader = authMethod.isKeyInHeader;
|
||||
opSecurity.isKeyInQuery = authMethod.isKeyInQuery;
|
||||
opSecurity.flow = authMethod.flow;
|
||||
opSecurity.tokenUrl = authMethod.tokenUrl;
|
||||
List<Map<String, Object>> opAuthScopes = new ArrayList<Map<String, Object>>();
|
||||
for (String opScopeName : opScopes) {
|
||||
for (Map<String, Object> scope : authMethod.scopes) {
|
||||
String name = (String) scope.get("scope");
|
||||
if (opScopeName.equals(name)) {
|
||||
opAuthScopes.add(scope);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
opSecurity.scopes = opAuthScopes;
|
||||
result.add(opSecurity);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,8 +374,8 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
}
|
||||
}
|
||||
|
||||
// import "optionals" package if the parameter is primitive and optional
|
||||
if (!param.required && param.isPrimitiveType) {
|
||||
// import "optionals" package if the parameter is optional
|
||||
if (!param.required) {
|
||||
if (!addedOptionalImport) {
|
||||
imports.add(createMapping("import", "github.com/antihax/optional"));
|
||||
addedOptionalImport = true;
|
||||
@@ -639,12 +639,12 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0) {
|
||||
LOGGER.error("Error running the command ({}): {}", command, p.exitValue());
|
||||
LOGGER.error("Error running the command ({}). Exit code: {}", command, p.exitValue());
|
||||
}
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}): {}", command, e.getMessage());
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
@@ -25,6 +27,7 @@ import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -77,6 +80,15 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf
|
||||
typeMapping.put("UUID", "String");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("RUBY_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Hint: Environment variable 'RUBY_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export RUBY_POST_PROCESS_FILE=/usr/local/bin/rubocop -a' (Linux/Mac)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
if (this.reservedWordsMappings().containsKey(name)) {
|
||||
@@ -162,4 +174,30 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("=end", "=_end").replace("=begin", "=_begin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
String rubyPostProcessFile = System.getenv("RUBY_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(rubyPostProcessFile)) {
|
||||
return; // skip if RUBY_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
// only process files with rb extension
|
||||
if ("rb".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
String command = rubyPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.samskivert.mustache.Escapers;
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
@@ -113,6 +114,10 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("SCALA_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Environment variable SCALA_POST_PROCESS_FILE not defined so the Scala code may not be properly formatted. To define it, try 'export SCALA_POST_PROCESS_FILE=/usr/local/bin/scalafmt' (Linux/Mac)");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
|
||||
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
|
||||
}
|
||||
@@ -298,4 +303,32 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String scalaPostProcessFile = System.getenv("SCALA_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(scalaPostProcessFile)) {
|
||||
return; // skip if SCALA_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only process files with scala extension
|
||||
if ("scala".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
String command = scalaPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.openapitools.codegen.languages;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.parameters.Parameter;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
@@ -48,7 +49,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
importMapping.clear();
|
||||
|
||||
supportsInheritance = true;
|
||||
|
||||
|
||||
// NOTE: TypeScript uses camel cased reserved words, while models are title cased. We don't want lowercase comparisons.
|
||||
reservedWords.addAll(Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
@@ -116,6 +117,10 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("TS_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Hint: Environment variable 'TS_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export TS_POST_PROCESS_FILE=\"/usr/local/bin/prettier --write\"' (Linux/Mac)");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) {
|
||||
setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING));
|
||||
}
|
||||
@@ -328,10 +333,10 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return UNDEFINED_VALUE;
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return UNDEFINED_VALUE;
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return UNDEFINED_VALUE;
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
@@ -347,7 +352,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean isReservedWord(String word) {
|
||||
// NOTE: This differs from super's implementation in that TypeScript does _not_ want case insensitive matching.
|
||||
@@ -561,4 +566,32 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
super.postProcessFile(file, fileType);
|
||||
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
String tsPostProcessFile = System.getenv("TS_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(tsPostProcessFile)) {
|
||||
return; // skip if TS_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
// only process files with ts extension
|
||||
if ("ts".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
String command = tsPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,14 +28,12 @@ import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -152,8 +150,8 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("DART_FMT_PATH"))) {
|
||||
LOGGER.info("Environment variable DART_FMT_PATH not defined so the Dart code may not be properly formatted. To define it, try 'export DART_FMT_PATH=/usr/local/bin/dartfmt' (Linux/Mac)");
|
||||
if (StringUtils.isEmpty(System.getenv("DART_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Environment variable DART_POST_PROCESS_FILE not defined so the Dart code may not be properly formatted. To define it, try `export DART_POST_PROCESS_FILE=\"/usr/local/bin/dartfmt -w\"` (Linux/Mac)");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(BROWSER_CLIENT)) {
|
||||
@@ -200,7 +198,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
|
||||
final Object isSupportDart2 = additionalProperties.get(SUPPORT_DART2);
|
||||
if (Boolean.FALSE.equals(isSupportDart2) || (isSupportDart2 instanceof String && !Boolean.parseBoolean((String)isSupportDart2))) {
|
||||
if (Boolean.FALSE.equals(isSupportDart2) || (isSupportDart2 instanceof String && !Boolean.parseBoolean((String) isSupportDart2))) {
|
||||
// dart 1.x
|
||||
LOGGER.info("Dart version: 1.x");
|
||||
supportingFiles.add(new SupportingFile("analysis_options.mustache", "", ".analysis_options"));
|
||||
@@ -514,9 +512,9 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return;
|
||||
}
|
||||
|
||||
String dartFmtPath = System.getenv("DART_FMT_PATH");
|
||||
if (StringUtils.isEmpty(dartFmtPath)) {
|
||||
return; // skip if DART_FMT_PATH env variable is not defined
|
||||
String dartPostProcessFile = System.getenv("DART_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(dartPostProcessFile)) {
|
||||
return; // skip if DART_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only procees the following type (or we can simply rely on the file extension to check if it's a Dart file)
|
||||
@@ -531,20 +529,21 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return;
|
||||
}
|
||||
|
||||
// only process files with dart extension
|
||||
// only process files with dart extension
|
||||
if ("dart".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
// currently only support "dartfmt -w yourcode.dart"
|
||||
String command = dartFmtPath + " -w " + file.toString();
|
||||
String command = dartPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0) {
|
||||
LOGGER.error("Error running the command ({}): {}", command, p.exitValue());
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit code: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}): {}", command, e.getMessage());
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,9 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import io.swagger.models.Model;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.DefaultCodegen;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
@@ -35,9 +27,6 @@ import io.swagger.v3.oas.models.media.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -46,12 +35,14 @@ import java.util.Set;
|
||||
|
||||
public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||
private static Set<String> modelToIgnore = new HashSet<>();
|
||||
|
||||
static {
|
||||
modelToIgnore.add("datetime");
|
||||
modelToIgnore.add("list");
|
||||
modelToIgnore.add("map");
|
||||
modelToIgnore.add("list");
|
||||
modelToIgnore.add("file");
|
||||
}
|
||||
|
||||
public DartJaguarClientCodegen() {
|
||||
super();
|
||||
browserClient = false;
|
||||
@@ -133,7 +124,6 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||
supportingFiles.add(new SupportingFile("auth/auth.mustache", authFolder, "auth.dart"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
objs = super.postProcessModels(objs);
|
||||
@@ -143,14 +133,13 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||
Set<String> modelImports = new HashSet<>();
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
for (String modelImport : cm.imports) {
|
||||
if(!modelToIgnore.contains(modelImport.toLowerCase(Locale.ROOT))) {
|
||||
if (!modelToIgnore.contains(modelImport.toLowerCase(Locale.ROOT))) {
|
||||
modelImports.add(underscore(modelImport));
|
||||
}
|
||||
}
|
||||
cm.imports = modelImports;
|
||||
cm.vendorExtensions.put("hasVars", cm.vars.size() > 0);
|
||||
}
|
||||
//objs.put("modelImports", modelImports);
|
||||
return objs;
|
||||
}
|
||||
|
||||
@@ -167,7 +156,7 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||
boolean isJson = true; //default to JSON
|
||||
boolean isForm = false;
|
||||
boolean isMultipart = false;
|
||||
if(op.consumes != null) {
|
||||
if (op.consumes != null) {
|
||||
for (Map<String, String> consume : op.consumes) {
|
||||
if (consume.containsKey("mediaType")) {
|
||||
String type = consume.get("mediaType");
|
||||
@@ -185,7 +174,7 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||
|
||||
Set<String> imports = new HashSet<>();
|
||||
for (String item : op.imports) {
|
||||
if(!modelToIgnore.contains(item.toLowerCase(Locale.ROOT))) {
|
||||
if (!modelToIgnore.contains(item.toLowerCase(Locale.ROOT))) {
|
||||
imports.add(underscore(item));
|
||||
}
|
||||
}
|
||||
@@ -202,7 +191,7 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||
jaguarPath = jaguarPath + items[i];
|
||||
}
|
||||
|
||||
if (i != items.length -1) {
|
||||
if (i != items.length - 1) {
|
||||
jaguarPath = jaguarPath + "/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ElmClientCodegen.class);
|
||||
@@ -62,7 +63,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final String ELM_VERSION = "elmVersion";
|
||||
private static final String ENCODER = "elmEncoder";
|
||||
private static final String DECODER = "elmDecoder";
|
||||
private static final String X_DISCRIMINATOR_TYPE = "x-discriminator-value";
|
||||
private static final String DISCRIMINATOR_NAME = "discriminatorName";
|
||||
private static final String UNION_TYPE = "elmUnionType";
|
||||
|
||||
protected String packageName = "openapi";
|
||||
@@ -132,6 +133,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
instantiationTypes.clear();
|
||||
instantiationTypes.put("array", "List");
|
||||
instantiationTypes.put("map", "Dict");
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "Int");
|
||||
@@ -142,11 +144,12 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("boolean", "Bool");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("map", "Dict");
|
||||
typeMapping.put("date", "DateOnly");
|
||||
typeMapping.put("DateTime", "DateTime");
|
||||
typeMapping.put("password", "String");
|
||||
typeMapping.put("file", "String");
|
||||
typeMapping.put("ByteArray", "Byte");
|
||||
typeMapping.put("file", "String");
|
||||
typeMapping.put("binary", "String");
|
||||
|
||||
importMapping.clear();
|
||||
@@ -165,23 +168,40 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("ELM_FORMAT_PATH"))) {
|
||||
LOGGER.info("Environment variable ELM_FORMAT_PATH not defined so the Elm code may not be properly formatted. To define it, try 'export ELM_FORMAT_PATH=/usr/local/bin/elm-format' (Linux/Mac)");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(ELM_VERSION)) {
|
||||
final String version = (String) additionalProperties.get(ELM_VERSION);
|
||||
if ("0.18".equals(version)) {
|
||||
elmVersion = ElmVersion.ELM_018;
|
||||
} else {
|
||||
elmVersion = ElmVersion.ELM_019;
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("ELM_POST_PROCESS_FILE"))) {
|
||||
if (elmVersion.equals(ElmVersion.ELM_018)) { // 0.18
|
||||
LOGGER.info("Environment variable ELM_POST_PROCESS_FILE not defined so the Elm code may not be properly formatted. To define it, try `export ELM_POST_PROCESS_FILE=\"/usr/local/bin/elm-format --elm-version={} --yes\"` (Linux/Mac)", "0.18");
|
||||
} else { // 0.19
|
||||
LOGGER.info("Environment variable ELM_POST_PROCESS_FILE not defined so the Elm code may not be properly formatted. To define it, try `export ELM_POST_PROCESS_FILE=\"/usr/local/bin/elm-format --elm-version={} --yes\"` (Linux/Mac)", "0.19");
|
||||
}
|
||||
}
|
||||
|
||||
switch (elmVersion) {
|
||||
case ELM_018:
|
||||
LOGGER.info("Elm version = 0.18");
|
||||
additionalProperties.put("isElm018", true);
|
||||
supportingFiles.add(new SupportingFile("DateOnly018.mustache", "src", "DateOnly.elm"));
|
||||
supportingFiles.add(new SupportingFile("DateTime018.mustache", "src", "DateTime.elm"));
|
||||
supportingFiles.add(new SupportingFile("elm-package018.mustache", "", "elm-package.json"));
|
||||
supportingFiles.add(new SupportingFile("Main018.mustache", "src", "Main.elm"));
|
||||
break;
|
||||
case ELM_019:
|
||||
LOGGER.info("Elm version = 0.19");
|
||||
additionalProperties.put("isElm019", true);
|
||||
supportingFiles.add(new SupportingFile("DateOnly.mustache", "src", "DateOnly.elm"));
|
||||
supportingFiles.add(new SupportingFile("DateTime.mustache", "src", "DateTime.elm"));
|
||||
supportingFiles.add(new SupportingFile("elm.mustache", "", "elm.json"));
|
||||
supportingFiles.add(new SupportingFile("Main.mustache", "src", "Main.elm"));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Undefined Elm version");
|
||||
@@ -190,19 +210,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("Byte.mustache", "src", "Byte.elm"));
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
if (ElmVersion.ELM_018.equals(elmVersion)) {
|
||||
supportingFiles.add(new SupportingFile("DateOnly018.mustache", "src", "DateOnly.elm"));
|
||||
supportingFiles.add(new SupportingFile("DateTime018.mustache", "src", "DateTime.elm"));
|
||||
supportingFiles.add(new SupportingFile("elm-package.mustache", "", "elm-package.json"));
|
||||
supportingFiles.add(new SupportingFile("Main018.mustache", "src", "Main.elm"));
|
||||
}
|
||||
if (ElmVersion.ELM_019.equals(elmVersion)) {
|
||||
supportingFiles.add(new SupportingFile("DateOnly019.mustache", "src", "DateOnly.elm"));
|
||||
supportingFiles.add(new SupportingFile("DateTime019.mustache", "src", "DateTime.elm"));
|
||||
supportingFiles.add(new SupportingFile("elm.mustache", "", "elm.json"));
|
||||
supportingFiles.add(new SupportingFile("Main019.mustache", "src", "Main.elm"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -330,55 +337,40 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
for (Map<String, Object> mo : models) {
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
if (cm.isEnum) {
|
||||
this.addEncoderAndDecoder(cm.vendorExtensions, cm.classname, false, false);
|
||||
addEncoderAndDecoder(cm.vendorExtensions, cm.classname, DataTypeExposure.EXPOSED);
|
||||
cm.vendorExtensions.put(UNION_TYPE, cm.classname);
|
||||
} else if (cm.isAlias) {
|
||||
this.addEncoderAndDecoder(cm.vendorExtensions, cm.dataType, false, true);
|
||||
addEncoderAndDecoder(cm.vendorExtensions, cm.dataType, DataTypeExposure.EXPOSED);
|
||||
}
|
||||
|
||||
List<ElmImport> elmImports = new ArrayList<>();
|
||||
for (CodegenProperty property : cm.allVars) {
|
||||
if (property.complexType != null) {
|
||||
elmImports.add(createPropertyImport(property));
|
||||
final ElmImport elmImport = createImport(property.complexType);
|
||||
elmImports.add(elmImport);
|
||||
}
|
||||
}
|
||||
if (cm.isArrayModel) {
|
||||
if (cm.arrayModelType != null) {
|
||||
// add type imports
|
||||
final ElmImport elmImport = new ElmImport();
|
||||
final String modulePrefix = customPrimitives.contains(cm.arrayModelType) ? "" : "Data.";
|
||||
elmImport.moduleName = modulePrefix + cm.arrayModelType;
|
||||
elmImport.exposures = new TreeSet<>();
|
||||
elmImport.exposures.add(cm.arrayModelType);
|
||||
elmImport.exposures.add(org.openapitools.codegen.utils.StringUtils.camelize(cm.arrayModelType, true) + "Decoder");
|
||||
elmImport.exposures.add(org.openapitools.codegen.utils.StringUtils.camelize(cm.arrayModelType, true) + "Encoder");
|
||||
elmImport.hasExposures = true;
|
||||
final ElmImport elmImport = createImport(cm.arrayModelType);
|
||||
elmImports.add(elmImport);
|
||||
}
|
||||
}
|
||||
if (cm.discriminator != null) {
|
||||
for (CodegenModel child : cm.children) {
|
||||
// add child imports
|
||||
final ElmImport elmImport = new ElmImport();
|
||||
final String modulePrefix = customPrimitives.contains(child.classname) ? "" : "Data.";
|
||||
elmImport.moduleName = modulePrefix + child.classname;
|
||||
elmImport.exposures = new TreeSet<>();
|
||||
elmImport.exposures.add(child.classname);
|
||||
elmImport.exposures.add(child.classVarName + "Decoder");
|
||||
elmImport.exposures.add(child.classVarName + "Encoder");
|
||||
elmImport.hasExposures = true;
|
||||
final ElmImport elmImport = createImport(child.classname);
|
||||
elmImports.add(elmImport);
|
||||
|
||||
// set discriminator value to all children (recursively)
|
||||
this.setDiscriminatorValue(child, cm.getDiscriminatorName(), this.getDiscriminatorValue(child));
|
||||
final String propertyName = cm.discriminator.getPropertyName();
|
||||
final List<CodegenProperty> allVars = child.allVars.stream()
|
||||
.filter(var -> !var.baseName.equals(propertyName))
|
||||
.collect(Collectors.toList());
|
||||
child.allVars.clear();
|
||||
child.allVars.addAll(allVars);
|
||||
|
||||
// add all non-discriminator vars
|
||||
int index = 0;
|
||||
for (CodegenProperty property : cm.vars) {
|
||||
if (!cm.discriminator.equals(property.baseName)) {
|
||||
child.vars.add(index++, property);
|
||||
}
|
||||
}
|
||||
child.vendorExtensions.put(DISCRIMINATOR_NAME, propertyName);
|
||||
}
|
||||
}
|
||||
inner.put("elmImports", elmImports);
|
||||
@@ -387,42 +379,16 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return objs;
|
||||
}
|
||||
|
||||
private void setDiscriminatorValue(CodegenModel model, String baseName, String value) {
|
||||
for (CodegenProperty prop : model.vars) {
|
||||
if (prop.baseName.equals(baseName)) {
|
||||
prop.discriminatorValue = value;
|
||||
}
|
||||
}
|
||||
for (CodegenProperty prop : model.allVars) {
|
||||
if (prop.baseName.equals(baseName)) {
|
||||
prop.discriminatorValue = value;
|
||||
}
|
||||
}
|
||||
if (model.children != null) {
|
||||
final boolean newDiscriminator = model.discriminator != null;
|
||||
for (CodegenModel child : model.children) {
|
||||
this.setDiscriminatorValue(child, baseName, newDiscriminator ? value : this.getDiscriminatorValue(child));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getDiscriminatorValue(CodegenModel model) {
|
||||
return model.vendorExtensions.containsKey(X_DISCRIMINATOR_TYPE) ?
|
||||
(String) model.vendorExtensions.get(X_DISCRIMINATOR_TYPE) : model.classname;
|
||||
}
|
||||
|
||||
private ElmImport createPropertyImport(final CodegenProperty property) {
|
||||
private ElmImport createImport(final String name) {
|
||||
final ElmImport elmImport = new ElmImport();
|
||||
final String modulePrefix = customPrimitives.contains(property.complexType) ? "" : "Data.";
|
||||
elmImport.moduleName = modulePrefix + property.complexType;
|
||||
final boolean isData = !customPrimitives.contains(name);
|
||||
final String modulePrefix = isData ? "Data." : "";
|
||||
elmImport.moduleName = modulePrefix + name;
|
||||
if (isData) {
|
||||
elmImport.as = name;
|
||||
}
|
||||
elmImport.exposures = new TreeSet<>();
|
||||
elmImport.exposures.add(property.complexType);
|
||||
if (property.vendorExtensions.containsKey(DECODER)) {
|
||||
elmImport.exposures.add((String) property.vendorExtensions.get(DECODER));
|
||||
}
|
||||
if (property.vendorExtensions.containsKey(ENCODER)) {
|
||||
elmImport.exposures.add((String) property.vendorExtensions.get(ENCODER));
|
||||
}
|
||||
elmImport.exposures.add(name);
|
||||
elmImport.hasExposures = true;
|
||||
return elmImport;
|
||||
}
|
||||
@@ -438,13 +404,17 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Map<String, Object> objs = (Map<String, Object>) operations.get("operations");
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) objs.get("operation");
|
||||
|
||||
Map<String, Set<String>> dependencies = new HashMap<>();
|
||||
boolean hasDateTime = false;
|
||||
boolean hasDate = false;
|
||||
final Map<String, Set<String>> dependencies = new HashMap<>();
|
||||
|
||||
for (CodegenOperation op : ops) {
|
||||
String path = op.path;
|
||||
for (CodegenParameter param : op.pathParams) {
|
||||
final String var = paramToString(param);
|
||||
path = path.replace("{" + param.paramName + "}", "\" ++ " + var + " ++ \"");
|
||||
hasDateTime = hasDateTime || param.isDateTime;
|
||||
hasDate = hasDate || param.isDate;
|
||||
}
|
||||
op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", "");
|
||||
|
||||
@@ -454,7 +424,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (!dependencies.containsKey(op.bodyParam.dataType)) {
|
||||
dependencies.put(op.bodyParam.dataType, new TreeSet<String>());
|
||||
}
|
||||
dependencies.get(op.bodyParam.dataType).add(encoder);
|
||||
}
|
||||
}
|
||||
for (CodegenResponse resp : op.responses) {
|
||||
@@ -466,21 +435,37 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (!dependencies.containsKey(resp.dataType)) {
|
||||
dependencies.put(resp.dataType, new TreeSet<String>());
|
||||
}
|
||||
dependencies.get(resp.dataType).add(decoder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<ElmImport> elmImports = new ArrayList<>();
|
||||
final List<ElmImport> elmImports = new ArrayList<>();
|
||||
for (Map.Entry<String, Set<String>> entry : dependencies.entrySet()) {
|
||||
final ElmImport elmImport = new ElmImport();
|
||||
final String key = entry.getKey();
|
||||
elmImport.moduleName = "Data." + key;
|
||||
elmImport.as = key;
|
||||
elmImport.exposures = entry.getValue();
|
||||
elmImport.exposures.add(key);
|
||||
elmImport.hasExposures = true;
|
||||
elmImports.add(elmImport);
|
||||
}
|
||||
if (hasDate) {
|
||||
final ElmImport elmImport = new ElmImport();
|
||||
elmImport.moduleName = "DateOnly";
|
||||
elmImport.exposures = new TreeSet<>();
|
||||
elmImport.exposures.add("DateOnly");
|
||||
elmImport.hasExposures = true;
|
||||
elmImports.add(elmImport);
|
||||
}
|
||||
if (hasDateTime) {
|
||||
final ElmImport elmImport = new ElmImport();
|
||||
elmImport.moduleName = "DateTime";
|
||||
elmImport.exposures = new TreeSet<>();
|
||||
elmImport.exposures.add("DateTime");
|
||||
elmImport.hasExposures = true;
|
||||
elmImports.add(elmImport);
|
||||
}
|
||||
operations.put("elmImports", elmImports);
|
||||
|
||||
return operations;
|
||||
@@ -527,19 +512,24 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private String paramToString(final CodegenParameter param) {
|
||||
final String paramName = param.paramName;
|
||||
if (param.isString) {
|
||||
|
||||
if (param.isString || param.isUuid || param.isBinary || param.isByteArray) {
|
||||
return paramName;
|
||||
}
|
||||
if (ElmVersion.ELM_018.equals(elmVersion)) {
|
||||
} else if (param.isBoolean) {
|
||||
return "if " + paramName + " then \"true\" else \"false\"";
|
||||
} else if (param.isDateTime) {
|
||||
return "DateTime.toString " + paramName;
|
||||
} else if (param.isDate) {
|
||||
return "DateOnly.toString " + paramName;
|
||||
} else if (ElmVersion.ELM_018.equals(elmVersion)) {
|
||||
return "toString " + paramName;
|
||||
}
|
||||
if (param.isInteger || param.isLong) {
|
||||
} else if (param.isInteger || param.isLong) {
|
||||
return "String.fromInt " + paramName;
|
||||
}
|
||||
if (param.isFloat || param.isDouble) {
|
||||
} else if (param.isFloat || param.isDouble) {
|
||||
return "String.fromFloat " + paramName;
|
||||
}
|
||||
throw new RuntimeException("Parameter '" + paramName + "' cannot be converted to a string");
|
||||
|
||||
throw new RuntimeException("Parameter '" + paramName + "' cannot be converted to a string. Please report the issue.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -573,10 +563,12 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public CodegenProperty fromProperty(String name, Schema p) {
|
||||
final CodegenProperty property = super.fromProperty(name, p);
|
||||
|
||||
final String dataType = property.isEnum ? property.baseName : property.dataType;
|
||||
addEncoderAndDecoder(property.vendorExtensions, dataType, property.isMapContainer, property.isPrimitiveType && !property.isEnum);
|
||||
if (property.isEnum) {
|
||||
addEncoderAndDecoder(property.vendorExtensions, property.baseName, DataTypeExposure.INTERNAL);
|
||||
property.vendorExtensions.put(UNION_TYPE, property.datatypeWithEnum);
|
||||
} else {
|
||||
final boolean isPrimitiveType = property.isMapContainer ? isPrimitiveDataType(property.dataType) : property.isPrimitiveType;
|
||||
addEncoderAndDecoder(property.vendorExtensions, property.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL);
|
||||
}
|
||||
|
||||
return property;
|
||||
@@ -586,33 +578,46 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public CodegenResponse fromResponse(OpenAPI openAPI, String responseCode, ApiResponse resp) {
|
||||
final CodegenResponse response = super.fromResponse(openAPI, responseCode, resp);
|
||||
if (response.dataType != null) {
|
||||
addEncoderAndDecoder(response.vendorExtensions, response.dataType, response.isMapContainer, response.primitiveType);
|
||||
final boolean isPrimitiveType = response.isMapContainer ? isPrimitiveDataType(response.dataType) : response.primitiveType;
|
||||
addEncoderAndDecoder(response.vendorExtensions, response.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
addEncoderAndDecoder(parameter.vendorExtensions, parameter.dataType, parameter.isMapContainer, parameter.isPrimitiveType);
|
||||
final boolean isPrimitiveType = parameter.isMapContainer ? isPrimitiveDataType(parameter.dataType) : parameter.isPrimitiveType;
|
||||
addEncoderAndDecoder(parameter.vendorExtensions, parameter.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL);
|
||||
}
|
||||
|
||||
private boolean isPrimitiveDataType(String dataType) {
|
||||
return languageSpecificPrimitives.contains(dataType);
|
||||
}
|
||||
|
||||
private void addEncoderAndDecoder(Map<String, Object> vendorExtensions, String dataType, Boolean isMapContainer, Boolean isPrimitiveType) {
|
||||
if (isMapContainer) {
|
||||
isPrimitiveType = isPrimitiveDataType(dataType);
|
||||
}
|
||||
private void addEncoderAndDecoder(final Map<String, Object> vendorExtensions, final String dataType, final DataTypeExposure dataTypeExposure) {
|
||||
final String baseName = org.openapitools.codegen.utils.StringUtils.camelize(dataType, true);
|
||||
String encoderName;
|
||||
String decoderName;
|
||||
if (isPrimitiveType) {
|
||||
encoderName = "Encode." + baseName;
|
||||
decoderName = "Decode." + baseName;
|
||||
} else {
|
||||
encoderName = baseName + "Encoder";
|
||||
decoderName = baseName + "Decoder";
|
||||
switch (dataTypeExposure) {
|
||||
case EXPOSED:
|
||||
decoderName = "decoder";
|
||||
encoderName = "encoder";
|
||||
break;
|
||||
case INTERNAL:
|
||||
encoderName = baseName + "Encoder";
|
||||
decoderName = baseName + "Decoder";
|
||||
break;
|
||||
case EXTERNAL:
|
||||
encoderName = dataType + ".encoder";
|
||||
decoderName = dataType + ".decoder";
|
||||
break;
|
||||
case PRIMITIVE:
|
||||
encoderName = "Encode." + baseName;
|
||||
decoderName = "Decode." + baseName;
|
||||
break;
|
||||
default:
|
||||
encoderName = "";
|
||||
decoderName = "";
|
||||
}
|
||||
if (!vendorExtensions.containsKey(ENCODER)) {
|
||||
vendorExtensions.put(ENCODER, encoderName);
|
||||
@@ -622,6 +627,13 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private enum DataTypeExposure {
|
||||
EXPOSED,
|
||||
INTERNAL,
|
||||
EXTERNAL,
|
||||
PRIMITIVE
|
||||
}
|
||||
|
||||
private static class ElmImport {
|
||||
public String moduleName;
|
||||
public String as;
|
||||
@@ -640,29 +652,27 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return;
|
||||
}
|
||||
|
||||
String elmFmtPath = System.getenv("ELM_FORMAT_PATH");
|
||||
if (StringUtils.isEmpty(elmFmtPath)) {
|
||||
return; // skip if ELM_FORMAT_PATH env variable is not defined
|
||||
String elmPostProcessFile = System.getenv("ELM_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(elmPostProcessFile)) {
|
||||
return; // skip if ELM_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only process files with elm extension
|
||||
if ("elm".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
// currently only support "elm-format -w yourcode.elm"
|
||||
String command = elmFmtPath + " --yes " + file.toString();
|
||||
if (ElmVersion.ELM_018.equals(elmVersion)) {
|
||||
command += " --elm-version=0.18";
|
||||
}
|
||||
// e.g. elm-format -w yourcode.elm
|
||||
String command = elmPostProcessFile + " " + file.toString();
|
||||
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0) {
|
||||
LOGGER.error("Error running the command ({}): {}", command, p.exitValue());
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit code: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}): {}", command, e.getMessage());
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GoGinServerCodegen extends AbstractGoCodegen {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GoGinServerCodegen.class);
|
||||
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected int serverPort = 8080;
|
||||
protected String projectName = "openapi-server";
|
||||
protected String apiPath = "go";
|
||||
|
||||
public GoGinServerCodegen() {
|
||||
super();
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/go";
|
||||
|
||||
/*
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
||||
* a different extension
|
||||
*/
|
||||
modelTemplateFiles.put(
|
||||
"model.mustache",
|
||||
".go");
|
||||
|
||||
/*
|
||||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
|
||||
* as with models, add multiple entries with different extensions for multiple files per
|
||||
* class
|
||||
*/
|
||||
apiTemplateFiles.put(
|
||||
"controller-api.mustache", // the template to use
|
||||
".go"); // the extension for each file to write
|
||||
|
||||
/*
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
embeddedTemplateDir = templateDir = "go-gin-server";
|
||||
|
||||
/*
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// data type
|
||||
"string", "bool", "uint", "uint8", "uint16", "uint32", "uint64",
|
||||
"int", "int8", "int16", "int32", "int64", "float32", "float64",
|
||||
"complex64", "complex128", "rune", "byte", "uintptr",
|
||||
|
||||
"break", "default", "func", "interface", "select",
|
||||
"case", "defer", "go", "map", "struct",
|
||||
"chan", "else", "goto", "package", "switch",
|
||||
"const", "fallthrough", "if", "range", "type",
|
||||
"continue", "for", "import", "return", "var", "error", "nil")
|
||||
// Added "error" as it's used so frequently that it may as well be a keyword
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||
objs = super.postProcessOperationsWithModels(objs, allModels);
|
||||
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation op : operationList) {
|
||||
if (op.path != null) {
|
||||
op.path = op.path.replaceAll("\\{(.*?)\\}", ":$1");
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("GO_FMT_PATH"))) {
|
||||
LOGGER.info("Environment variable GO_FMT_PATH not defined so Go code may not be properly formatted. To define it, try 'export GO_FMT_PATH=/usr/local/bin/gofmt' (Linux/Mac)");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
} else {
|
||||
setPackageName("openapi");
|
||||
}
|
||||
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
additionalProperties.put("serverPort", serverPort);
|
||||
additionalProperties.put("apiPath", apiPath);
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
|
||||
modelPackage = packageName;
|
||||
apiPackage = packageName;
|
||||
|
||||
/*
|
||||
* Supporting Files. You can write single files for the generator with the
|
||||
* entire object tree available. If the input file has a suffix of `.mustache
|
||||
* it will be processed by the template engine. Otherwise, it will be copied
|
||||
*/
|
||||
supportingFiles.add(new SupportingFile("openapi.mustache", "api", "openapi.yaml"));
|
||||
supportingFiles.add(new SupportingFile("main.mustache", "", "main.go"));
|
||||
supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile"));
|
||||
supportingFiles.add(new SupportingFile("routers.mustache", apiPath, "routers.go"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", apiPath, "README.md"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiPackage() {
|
||||
return apiPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see org.openapitools.codegen.CodegenType
|
||||
*/
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -g flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "go-gin-server";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Go server library with the gin framework using OpenAPI-Generator." +
|
||||
"By default, it will also generate service classes.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write api files. You can use the apiPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
@@ -361,6 +362,10 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("HASKELL_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Hint: Environment variable HASKELL_POST_PROCESS_FILE not defined so the Haskell code may not be properly formatted. To define it, try 'export HASKELL_POST_PROCESS_FILE=\"$HOME/.local/bin/hfmt -w\"' (Linux/Mac)");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(PROP_ALLOW_FROMJSON_NULLS)) {
|
||||
setAllowFromJsonNulls(convertPropertyToBoolean(PROP_ALLOW_FROMJSON_NULLS));
|
||||
} else {
|
||||
@@ -1345,4 +1350,31 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
.replace("\\", "\\\\")
|
||||
.replace("\"", "\\\""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
String haskellPostProcessFile = System.getenv("HASKELL_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(haskellPostProcessFile)) {
|
||||
return; // skip if HASKELL_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only process files with hs extension
|
||||
if ("hs".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
String command = haskellPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
@@ -36,6 +37,7 @@ import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -100,20 +102,20 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/haskell-servant";
|
||||
|
||||
/*
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
/*
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
embeddedTemplateDir = templateDir = "haskell-servant";
|
||||
|
||||
/*
|
||||
* Api Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
/*
|
||||
* Api Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
apiPackage = "API";
|
||||
|
||||
/*
|
||||
* Model Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
/*
|
||||
* Model Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
modelPackage = "Types";
|
||||
|
||||
// Haskell keywords and reserved function names, taken mostly from https://wiki.haskell.org/Keywords
|
||||
@@ -133,25 +135,25 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
|
||||
/*
|
||||
* Supporting Files. You can write single files for the generator with the
|
||||
* entire object tree available. If the input file has a suffix of `.mustache
|
||||
* it will be processed by the template engine. Otherwise, it will be copied
|
||||
*/
|
||||
/*
|
||||
* Supporting Files. You can write single files for the generator with the
|
||||
* entire object tree available. If the input file has a suffix of `.mustache
|
||||
* it will be processed by the template engine. Otherwise, it will be copied
|
||||
*/
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("stack.mustache", "", "stack.yaml"));
|
||||
supportingFiles.add(new SupportingFile("Setup.mustache", "", "Setup.hs"));
|
||||
|
||||
/*
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
/*
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Bool",
|
||||
@@ -179,6 +181,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("DateTime", "Integer");
|
||||
typeMapping.put("file", "FilePath");
|
||||
typeMapping.put("binary", "FilePath");
|
||||
typeMapping.put("number", "Double");
|
||||
typeMapping.put("any", "Value");
|
||||
typeMapping.put("UUID", "Text");
|
||||
@@ -192,6 +195,15 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("HASKELL_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Hint: Environment variable HASKELL_POST_PROCESS_FILE not defined so the Haskell code may not be properly formatted. To define it, try 'export HASKELL_POST_PROCESS_FILE=\"$HOME/.local/bin/hfmt -w\"' (Linux/Mac)");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reserved words
|
||||
@@ -200,7 +212,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
if(this.reservedWordsMappings().containsKey(name)) {
|
||||
if (this.reservedWordsMappings().containsKey(name)) {
|
||||
return this.reservedWordsMappings().get(name);
|
||||
}
|
||||
return "_" + name;
|
||||
@@ -232,7 +244,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
String title = openAPI.getInfo().getTitle();
|
||||
|
||||
// Drop any API suffix
|
||||
if(title == null) {
|
||||
if (title == null) {
|
||||
title = "OpenAPI";
|
||||
} else {
|
||||
title = title.trim();
|
||||
@@ -272,7 +284,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
List<Map<String, Object>> replacements = new ArrayList<>();
|
||||
Object[] replacementChars = specialCharReplacements.keySet().toArray();
|
||||
for(int i = 0; i < replacementChars.length; i++) {
|
||||
for (int i = 0; i < replacementChars.length; i++) {
|
||||
String c = (String) replacementChars[i];
|
||||
Map<String, Object> o = new HashMap<>();
|
||||
o.put("char", c);
|
||||
@@ -321,7 +333,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
return type;
|
||||
//if (languageSpecificPrimitives.contains(type))
|
||||
// return toModelName(type);
|
||||
} else if(typeMapping.containsValue(schemaType)) {
|
||||
} else if (typeMapping.containsValue(schemaType)) {
|
||||
// TODO what's this case for?
|
||||
type = schemaType + "_";
|
||||
} else {
|
||||
@@ -452,7 +464,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
path.add("ReqBody '[JSON] " + param.dataType);
|
||||
bodyType = param.dataType;
|
||||
}
|
||||
} else if(op.getHasFormParams()) {
|
||||
} else if (op.getHasFormParams()) {
|
||||
// Use the FormX data type, where X is the conglomerate of all things being passed
|
||||
String formName = "Form" + org.openapitools.codegen.utils.StringUtils.camelize(op.operationId);
|
||||
bodyType = formName;
|
||||
@@ -496,7 +508,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
op.vendorExtensions.put("x-routeType", joinStrings(" :> ", path));
|
||||
op.vendorExtensions.put("x-clientType", joinStrings(" -> ", type));
|
||||
op.vendorExtensions.put("x-formName", "Form" + org.openapitools.codegen.utils.StringUtils.camelize(op.operationId));
|
||||
for(CodegenParameter param : op.formParams) {
|
||||
for (CodegenParameter param : op.formParams) {
|
||||
param.vendorExtensions.put("x-formPrefix", org.openapitools.codegen.utils.StringUtils.camelize(op.operationId, true));
|
||||
}
|
||||
return op;
|
||||
@@ -504,12 +516,17 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
private String makeQueryListType(String type, String collectionFormat) {
|
||||
type = type.substring(1, type.length() - 1);
|
||||
switch(collectionFormat) {
|
||||
case "csv": return "(QueryList 'CommaSeparated (" + type + "))";
|
||||
case "tsv": return "(QueryList 'TabSeparated (" + type + "))";
|
||||
case "ssv": return "(QueryList 'SpaceSeparated (" + type + "))";
|
||||
case "pipes": return "(QueryList 'PipeSeparated (" + type + "))";
|
||||
case "multi": return "(QueryList 'MultiParamArray (" + type + "))";
|
||||
switch (collectionFormat) {
|
||||
case "csv":
|
||||
return "(QueryList 'CommaSeparated (" + type + "))";
|
||||
case "tsv":
|
||||
return "(QueryList 'TabSeparated (" + type + "))";
|
||||
case "ssv":
|
||||
return "(QueryList 'SpaceSeparated (" + type + "))";
|
||||
case "pipes":
|
||||
return "(QueryList 'PipeSeparated (" + type + "))";
|
||||
case "multi":
|
||||
return "(QueryList 'MultiParamArray (" + type + "))";
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -550,19 +567,19 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
// Clean up the class name to remove invalid characters
|
||||
model.classname = fixModelChars(model.classname);
|
||||
if(typeMapping.containsValue(model.classname)) {
|
||||
if (typeMapping.containsValue(model.classname)) {
|
||||
model.classname += "_";
|
||||
}
|
||||
|
||||
// From the model name, compute the prefix for the fields.
|
||||
String prefix = org.openapitools.codegen.utils.StringUtils.camelize(model.classname, true);
|
||||
for(CodegenProperty prop : model.vars) {
|
||||
for (CodegenProperty prop : model.vars) {
|
||||
prop.name = toVarName(prefix + org.openapitools.codegen.utils.StringUtils.camelize(fixOperatorChars(prop.name)));
|
||||
}
|
||||
|
||||
// Create newtypes for things with non-object types
|
||||
String dataOrNewtype = "data";
|
||||
if(model.dataType != "object" && typeMapping.containsKey(model.dataType)) {
|
||||
if (!"object".equals(model.dataType) && typeMapping.containsKey(model.dataType)) {
|
||||
String newtype = typeMapping.get(model.dataType);
|
||||
model.vendorExtensions.put("x-customNewtype", newtype);
|
||||
}
|
||||
@@ -585,4 +602,30 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
return input.replace("{-", "{_-").replace("-}", "-_}");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
String haskellPostProcessFile = System.getenv("HASKELL_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(haskellPostProcessFile)) {
|
||||
return; // skip if HASKELL_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only process files with hs extension
|
||||
if ("hs".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
String command = haskellPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,6 +288,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
supportingFiles.add(new SupportingFile("ProgressRequestBody.mustache", invokerFolder, "ProgressRequestBody.java"));
|
||||
supportingFiles.add(new SupportingFile("ProgressResponseBody.mustache", invokerFolder, "ProgressResponseBody.java"));
|
||||
supportingFiles.add(new SupportingFile("GzipRequestInterceptor.mustache", invokerFolder, "GzipRequestInterceptor.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/RetryingOAuth.mustache", authFolder, "RetryingOAuth.java"));
|
||||
additionalProperties.put("gson", "true");
|
||||
} else if (usesAnyRetrofitLibrary()) {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
|
||||
|
||||
@@ -1179,12 +1179,12 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0) {
|
||||
LOGGER.error("Error running the command ({}): {}", command, p.exitValue());
|
||||
LOGGER.error("Error running the command ({}). Exit code: {}", command, p.exitValue());
|
||||
}
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}): {}", command, e.getMessage());
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
|
||||
import org.openapitools.codegen.utils.URLPathUtils;
|
||||
@@ -32,6 +33,7 @@ import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
@@ -84,6 +86,38 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
apiPackage = "org.openapitools.api";
|
||||
modelPackage = "org.openapitools.model";
|
||||
|
||||
// Use lists instead of arrays
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("boolean", "Boolean");
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("long", "Long");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("ByteArray", "ByteArray");
|
||||
typeMapping.put("list", "List");
|
||||
typeMapping.put("map", "Map");
|
||||
typeMapping.put("object", "Any");
|
||||
typeMapping.put("binary", "Array<kotlin.Byte>");
|
||||
|
||||
languageSpecificPrimitives.addAll(Arrays.asList(
|
||||
"Any",
|
||||
"Byte",
|
||||
"ByteArray",
|
||||
"Short",
|
||||
"Int",
|
||||
"Long",
|
||||
"Float",
|
||||
"Double",
|
||||
"Boolean",
|
||||
"Char",
|
||||
"String",
|
||||
"Array",
|
||||
"List",
|
||||
"Map",
|
||||
"Set"
|
||||
));
|
||||
|
||||
addOption(TITLE, "server title name or client service name", title);
|
||||
addOption(BASE_PACKAGE, "base package (invokerPackage) for generated code", basePackage);
|
||||
addOption(SERVER_PORT, "configuration the port in which the sever is to run on", serverPort);
|
||||
@@ -386,7 +420,6 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
if (Boolean.TRUE.equals(model.hasEnums)) {
|
||||
model.imports.add("JsonValue");
|
||||
}
|
||||
|
||||
} else {
|
||||
//Needed imports for Jackson's JsonCreator
|
||||
if (additionalProperties.containsKey("jackson")) {
|
||||
@@ -394,6 +427,9 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
}
|
||||
}
|
||||
|
||||
if (model.discriminator != null && additionalProperties.containsKey("jackson")) {
|
||||
model.imports.addAll(Arrays.asList("JsonSubTypes", "JsonTypeInfo"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -479,16 +515,16 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
private void doDataTypeAssignment(final String returnType, DataTypeAssigner dataTypeAssigner) {
|
||||
if (returnType == null) {
|
||||
dataTypeAssigner.setReturnType("Unit");
|
||||
} else if (returnType.startsWith("kotlin.Array")) {
|
||||
} else if (returnType.startsWith("List")) {
|
||||
int end = returnType.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
dataTypeAssigner.setReturnType(returnType.substring("kotlin.Array<".length(), end).trim());
|
||||
dataTypeAssigner.setReturnType(returnType.substring("List<".length(), end).trim());
|
||||
dataTypeAssigner.setReturnContainer("List");
|
||||
}
|
||||
} else if (returnType.startsWith("kotlin.collections.Map")) {
|
||||
} else if (returnType.startsWith("Map")) {
|
||||
int end = returnType.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
dataTypeAssigner.setReturnType(returnType.substring("kotlin.collections.Map<".length(), end).split(",")[1].trim());
|
||||
dataTypeAssigner.setReturnType(returnType.substring("Map<".length(), end).split(",")[1].trim());
|
||||
dataTypeAssigner.setReturnContainer("Map");
|
||||
}
|
||||
}
|
||||
@@ -513,4 +549,16 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
writer.write(fragment.execute().replaceAll(from, to));
|
||||
}
|
||||
}
|
||||
|
||||
// Can't figure out the logic in DefaultCodegen but optional vars are getting duplicated when there's
|
||||
// inheritance involved. Also, isInherited doesn't seem to be getting set properly ¯\_(ツ)_/¯
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> allDefinitions) {
|
||||
CodegenModel m = super.fromModel(name, schema, allDefinitions);
|
||||
|
||||
m.optionalVars = m.optionalVars.stream().distinct().collect(Collectors.toList());
|
||||
m.allVars.stream().filter(p -> !m.vars.contains(p)).forEach(p -> p.isInherited = true);
|
||||
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -585,12 +585,12 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0) {
|
||||
LOGGER.error("Error running the command ({}): {}", command, p.exitValue());
|
||||
LOGGER.error("Error running the command ({}). Exit code: {}", command, p.exitValue());
|
||||
}
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}): {}", command, e.getMessage());
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
@@ -170,6 +171,11 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("PYTHON_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE=\"/usr/local/bin/yapf -i\"' (Linux/Mac)");
|
||||
}
|
||||
|
||||
Boolean excludeTests = false;
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.EXCLUDE_TESTS)) {
|
||||
@@ -709,4 +715,31 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return input.replace("'''", "'_'_'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
String pythonPostProcessFile = System.getenv("PYTHON_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(pythonPostProcessFile)) {
|
||||
return; // skip if PYTHON_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only process files with py extension
|
||||
if ("py".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
String command = pythonPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.swagger.v3.oas.models.PathItem.HttpMethod;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -153,6 +154,11 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("PYTHON_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE=\"/usr/local/bin/yapf -i\"' (Linux/Mac)");
|
||||
}
|
||||
|
||||
//apiTemplateFiles.clear();
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
@@ -312,7 +318,8 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
// need vendor extensions for x-openapi-router-controller
|
||||
// need vendor extensions for x-swagger-router-controller
|
||||
// can be changed to x-openapi-router-controller when https://github.com/zalando/connexion/issues/683 is done
|
||||
Map<String, PathItem> paths = openAPI.getPaths();
|
||||
if (paths != null) {
|
||||
for (String pathname : paths.keySet()) {
|
||||
@@ -330,9 +337,9 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements
|
||||
operationId = getOrGenerateOperationId(operation, pathname, method.toString());
|
||||
}
|
||||
operation.setOperationId(toOperationId(operationId));
|
||||
if (operation.getExtensions() == null || operation.getExtensions().get("x-openapi-router-controller") == null) {
|
||||
if (operation.getExtensions() == null || operation.getExtensions().get("x-swagger-router-controller") == null) {
|
||||
operation.addExtension(
|
||||
"x-openapi-router-controller",
|
||||
"x-swagger-router-controller",
|
||||
controllerPackage + "." + toApiFilename(tag)
|
||||
);
|
||||
}
|
||||
@@ -691,4 +698,31 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
String pythonPostProcessFile = System.getenv("PYTHON_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(pythonPostProcessFile)) {
|
||||
return; // skip if PYTHON_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only process files with py extension
|
||||
if ("py".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
String command = pythonPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RubyClientCodegen.class);
|
||||
public static final String GEM_NAME = "gemName";
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
@@ -242,6 +243,10 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("SWIFT_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Environment variable SWIFT_POST_PROCESS_FILE not defined so the Swift code may not be properly formatted. To define it, try 'export SWIFT_POST_PROCESS_FILE=/usr/local/bin/swiftformat' (Linux/Mac)");
|
||||
}
|
||||
|
||||
// Setup project name
|
||||
if (additionalProperties.containsKey(PROJECT_NAME)) {
|
||||
setProjectName((String) additionalProperties.get(PROJECT_NAME));
|
||||
@@ -681,4 +686,31 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
String swiftPostProcessFile = System.getenv("SWIFT_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(swiftPostProcessFile)) {
|
||||
return; // skip if SWIFT_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only process files with swift extension
|
||||
if ("swift".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
String command = swiftPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
@@ -26,6 +27,7 @@ import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@@ -296,6 +298,10 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("SWIFT_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Environment variable SWIFT_POST_PROCESS_FILE not defined so the Swift code may not be properly formatted. To define it, try 'export SWIFT_POST_PROCESS_FILE=/usr/local/bin/swiftformat' (Linux/Mac)");
|
||||
}
|
||||
|
||||
// Setup project name
|
||||
if (additionalProperties.containsKey(PROJECT_NAME)) {
|
||||
setProjectName((String) additionalProperties.get(PROJECT_NAME));
|
||||
@@ -836,4 +842,30 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
String swiftPostProcessFile = System.getenv("SWIFT_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(swiftPostProcessFile)) {
|
||||
return; // skip if SWIFT_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
// only process files with swift extension
|
||||
if ("swift".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
String command = swiftPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm", Locale.ROOT);
|
||||
|
||||
public static final String NPM_NAME = "npmName";
|
||||
public static final String NPM_VERSION = "npmVersion";
|
||||
public static final String NPM_REPOSITORY = "npmRepository";
|
||||
public static final String SNAPSHOT = "snapshot";
|
||||
public static final String WITH_INTERFACES = "withInterfaces";
|
||||
|
||||
protected String npmName = null;
|
||||
protected String npmVersion = "1.0.0";
|
||||
protected String npmRepository = null;
|
||||
|
||||
public TypeScriptAxiosClientCodegen() {
|
||||
super();
|
||||
|
||||
// clear import mapping (from default generator) as TS does not use it
|
||||
// at the moment
|
||||
importMapping.clear();
|
||||
|
||||
outputFolder = "generated-code/typescript-axios";
|
||||
embeddedTemplateDir = templateDir = "typescript-axios";
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package"));
|
||||
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package"));
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "typescript-axios";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a TypeScript client library using axios.";
|
||||
}
|
||||
|
||||
public String getNpmName() {
|
||||
return npmName;
|
||||
}
|
||||
|
||||
public void setNpmName(String npmName) {
|
||||
this.npmName = npmName;
|
||||
}
|
||||
|
||||
public String getNpmVersion() {
|
||||
return npmVersion;
|
||||
}
|
||||
|
||||
public void setNpmVersion(String npmVersion) {
|
||||
this.npmVersion = npmVersion;
|
||||
}
|
||||
|
||||
public String getNpmRepository() {
|
||||
return npmRepository;
|
||||
}
|
||||
|
||||
public void setNpmRepository(String npmRepository) {
|
||||
this.npmRepository = npmRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
supportingFiles.add(new SupportingFile("index.mustache", "", "index.ts"));
|
||||
supportingFiles.add(new SupportingFile("api.mustache", "", "api.ts"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.ts"));
|
||||
supportingFiles.add(new SupportingFile("custom.d.mustache", "", "custom.d.ts"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
|
||||
|
||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||
addNpmPackageGeneration();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
Schema inner;
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
inner = ((ArraySchema) p).getItems();
|
||||
return this.getSchemaType(p) + "<" + this.getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return "any";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return "any";
|
||||
} else {
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration(ModelUtils.getAdditionalProperties(schema));
|
||||
addImport(codegenModel, codegenModel.additionalPropertiesType);
|
||||
}
|
||||
|
||||
private void addNpmPackageGeneration() {
|
||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(NPM_VERSION)) {
|
||||
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||
}
|
||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||
|
||||
if (additionalProperties.containsKey(NPM_REPOSITORY)) {
|
||||
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
|
||||
}
|
||||
|
||||
//Files for building our lib
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -308,7 +308,7 @@ public class ModelUtils {
|
||||
if (schema.getAdditionalProperties() instanceof Schema) {
|
||||
return true;
|
||||
}
|
||||
if (schema.getAdditionalProperties() instanceof Boolean && (Boolean)schema.getAdditionalProperties()) {
|
||||
if (schema.getAdditionalProperties() instanceof Boolean && (Boolean) schema.getAdditionalProperties()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -638,21 +638,42 @@ public class ModelUtils {
|
||||
* Get the actual schema from aliases. If the provided schema is not an alias, the schema itself will be returned.
|
||||
*
|
||||
* @param allSchemas all schemas
|
||||
* @param schema schema (alias or direct reference)
|
||||
* @param schema schema (alias or direct reference)
|
||||
* @return actual schema
|
||||
*/
|
||||
public static Schema unaliasSchema(Map<String, Schema> allSchemas, Schema schema) {
|
||||
if (allSchemas == null || allSchemas.isEmpty()) {
|
||||
LOGGER.warn("allSchemas cann't be null/empty in unaliasSchema. Returned 'schema'");
|
||||
return schema;
|
||||
}
|
||||
|
||||
if (schema != null && StringUtils.isNotEmpty(schema.get$ref())) {
|
||||
Schema ref = allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref()));
|
||||
if (ref == null) {
|
||||
LOGGER.warn("{} is not defined", schema.get$ref());
|
||||
return schema;
|
||||
} else if (isObjectSchema(ref)) { // model
|
||||
return schema;
|
||||
} else if (isStringSchema(ref) && (ref.getEnum() != null && !ref.getEnum().isEmpty())) {
|
||||
} else if (ref.getEnum() != null && !ref.getEnum().isEmpty()) {
|
||||
// top-level enum class
|
||||
return schema;
|
||||
} else if (isMapSchema(ref) || isArraySchema(ref) || isComposedSchema(ref)) { // map/array def should be created as models
|
||||
} else if (isArraySchema(ref) || isComposedSchema(ref)) { // array def should be created as models
|
||||
return schema;
|
||||
} else if (isMapSchema(ref)) {
|
||||
if (ref.getProperties() != null && !ref.getProperties().isEmpty()) // has properties
|
||||
return schema; // treat it as model
|
||||
else {
|
||||
// treat it as a typical map
|
||||
/* TODO unalias the map item if it's an alias
|
||||
if (ref.getAdditionalProperties() != null) {
|
||||
|
||||
Schema innerSchema = (Schema) ref.getAdditionalProperties();
|
||||
if (StringUtils.isNotEmpty(innerSchema.get$ref())) { // map item is a ref to something else
|
||||
//Schema unaliasInnerSchema = unaliasSchema(allSchemas, allSchemas.get(ModelUtils.getSimpleRef(innerSchema.get$ref())));
|
||||
//ref.setAdditionalProperties(unaliasInnerSchema);
|
||||
}
|
||||
}*/
|
||||
return unaliasSchema(allSchemas, allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())));
|
||||
}
|
||||
} else if (isObjectSchema(ref)) { // model
|
||||
return schema;
|
||||
} else {
|
||||
return unaliasSchema(allSchemas, allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())));
|
||||
@@ -662,10 +683,10 @@ public class ModelUtils {
|
||||
}
|
||||
|
||||
public static Schema getAdditionalProperties(Schema schema) {
|
||||
if(schema.getAdditionalProperties() instanceof Schema) {
|
||||
if (schema.getAdditionalProperties() instanceof Schema) {
|
||||
return (Schema) schema.getAdditionalProperties();
|
||||
}
|
||||
if(schema.getAdditionalProperties() instanceof Boolean && (Boolean)schema.getAdditionalProperties()) {
|
||||
if (schema.getAdditionalProperties() instanceof Boolean && (Boolean) schema.getAdditionalProperties()) {
|
||||
return new ObjectSchema();
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -13,7 +13,7 @@ package body {{package}}.Skeletons is
|
||||
package API_{{operationId}} is
|
||||
new Swagger.Servers.Operation (Handler => {{operationId}},
|
||||
Method => Swagger.Servers.{{httpMethod}},
|
||||
URI => "{{path}}");
|
||||
URI => URI_Prefix & "{{path}}");
|
||||
|
||||
-- {{summary}}
|
||||
procedure {{operationId}}
|
||||
@@ -32,7 +32,7 @@ package body {{package}}.Skeletons is
|
||||
Result : {{returnType}};
|
||||
{{/returnType}}
|
||||
begin
|
||||
{{#authMethods}}
|
||||
{{#vendorExtensions.x-auth-scopes}}
|
||||
if not Context.Is_Authenticated then
|
||||
Context.Set_Error (401, "Not authenticated");
|
||||
return;
|
||||
@@ -43,7 +43,7 @@ package body {{package}}.Skeletons is
|
||||
return;
|
||||
end if;
|
||||
{{/scopes}}
|
||||
{{/authMethods}}
|
||||
{{/vendorExtensions.x-auth-scopes}}
|
||||
{{#queryParams}}
|
||||
Swagger.Servers.Get_Query_Parameter (Req, "{{baseName}}", {{paramName}});
|
||||
{{/queryParams}}
|
||||
@@ -128,7 +128,7 @@ package body {{package}}.Skeletons is
|
||||
Result : {{returnType}};
|
||||
{{/returnType}}
|
||||
begin
|
||||
{{#authMethods}}
|
||||
{{#vendorExtensions.x-auth-scopes}}
|
||||
if not Context.Is_Authenticated then
|
||||
Context.Set_Error (401, "Not authenticated");
|
||||
return;
|
||||
@@ -139,7 +139,7 @@ package body {{package}}.Skeletons is
|
||||
return;
|
||||
end if;
|
||||
{{/scopes}}
|
||||
{{/authMethods}}
|
||||
{{/vendorExtensions.x-auth-scopes}}
|
||||
{{#queryParams}}
|
||||
Swagger.Servers.Get_Query_Parameter (Req, "{{baseName}}", {{paramName}});
|
||||
{{/queryParams}}
|
||||
@@ -185,7 +185,7 @@ package body {{package}}.Skeletons is
|
||||
package API_{{operationId}} is
|
||||
new Swagger.Servers.Operation (Handler => {{operationId}},
|
||||
Method => Swagger.Servers.{{httpMethod}},
|
||||
URI => "{{path}}");
|
||||
URI => URI_Prefix & "{{path}}");
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
|
||||
@@ -32,6 +32,7 @@ package {{package}}.Skeletons is
|
||||
|
||||
generic
|
||||
type Implementation_Type is limited new Server_Type with private;
|
||||
URI_Prefix : String := "";
|
||||
package Skeleton is
|
||||
|
||||
procedure Register (Server : in out Swagger.Servers.Application_Type'Class);
|
||||
@@ -56,6 +57,7 @@ package {{package}}.Skeletons is
|
||||
|
||||
generic
|
||||
type Implementation_Type is limited new Server_Type with private;
|
||||
URI_Prefix : String := "";
|
||||
package Shared_Instance is
|
||||
|
||||
procedure Register (Server : in out Swagger.Servers.Application_Type'Class);
|
||||
|
||||
@@ -19,6 +19,9 @@ import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
{{/threetenbp}}
|
||||
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
||||
import org.apache.oltu.oauth2.common.message.types.GrantType;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -50,6 +53,7 @@ import {{invokerPackage}}.auth.Authentication;
|
||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||
import {{invokerPackage}}.auth.OAuth;
|
||||
import {{invokerPackage}}.auth.RetryingOAuth;
|
||||
|
||||
public class ApiClient {
|
||||
|
||||
@@ -78,6 +82,38 @@ public class ApiClient {
|
||||
* Constructor for ApiClient
|
||||
*/
|
||||
public ApiClient() {
|
||||
init();
|
||||
|
||||
// Setup authentications (key: authentication name, value: authentication).{{#authMethods}}{{#isBasic}}
|
||||
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
|
||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
||||
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
{{#authMethods}}{{#isOAuth}}
|
||||
/*
|
||||
* Constructor for ApiClient to support access token retry on 401/403
|
||||
*/
|
||||
public ApiClient(
|
||||
String clientId,
|
||||
String clientSecret,
|
||||
Map<String, String> parameters
|
||||
) {
|
||||
init();
|
||||
|
||||
RetryingOAuth retryingOAuth = new RetryingOAuth("{{tokenUrl}}", clientId, GrantType.valueOf("{{flow}}"), clientSecret, parameters);
|
||||
authentications.put(
|
||||
"{{name}}",
|
||||
retryingOAuth
|
||||
);
|
||||
httpClient.interceptors().add(retryingOAuth);
|
||||
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
{{/isOAuth}}{{/authMethods}}
|
||||
private void init() {
|
||||
httpClient = new OkHttpClient();
|
||||
|
||||
{{#useGzipFeature}}
|
||||
@@ -92,13 +128,7 @@ public class ApiClient {
|
||||
// Set default User-Agent.
|
||||
setUserAgent("{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{artifactVersion}}}/java{{/httpUserAgent}}");
|
||||
|
||||
// Setup authentications (key: authentication name, value: authentication).
|
||||
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}
|
||||
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
|
||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
||||
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
authentications = new HashMap<String, Authentication>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,6 +532,20 @@ public class ApiClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
|
||||
* @return Token request builder
|
||||
*/
|
||||
public TokenRequestBuilder getTokenEndPoint() {
|
||||
for (Authentication apiAuth : authentications.values()) {
|
||||
if (apiAuth instanceof RetryingOAuth) {
|
||||
RetryingOAuth retryingOAuth = (RetryingOAuth) apiAuth;
|
||||
return retryingOAuth.getTokenRequestBuilder();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given parameter object into string.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.MediaType;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import com.squareup.okhttp.Response;
|
||||
|
||||
import org.apache.oltu.oauth2.client.HttpClient;
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
|
||||
import org.apache.oltu.oauth2.client.response.OAuthClientResponse;
|
||||
import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class OAuthOkHttpClient implements HttpClient {
|
||||
private OkHttpClient client;
|
||||
|
||||
public OAuthOkHttpClient() {
|
||||
this.client = new OkHttpClient();
|
||||
}
|
||||
|
||||
public OAuthOkHttpClient(OkHttpClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map<String, String> headers,
|
||||
String requestMethod, Class<T> responseClass)
|
||||
throws OAuthSystemException, OAuthProblemException {
|
||||
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
Request.Builder requestBuilder = new Request.Builder().url(request.getLocationUri());
|
||||
|
||||
if(headers != null) {
|
||||
for (Entry<String, String> entry : headers.entrySet()) {
|
||||
if (entry.getKey().equalsIgnoreCase("Content-Type")) {
|
||||
mediaType = MediaType.parse(entry.getValue());
|
||||
} else {
|
||||
requestBuilder.addHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RequestBody body = request.getBody() != null ? RequestBody.create(mediaType, request.getBody()) : null;
|
||||
requestBuilder.method(requestMethod, body);
|
||||
|
||||
try {
|
||||
Response response = client.newCall(requestBuilder.build()).execute();
|
||||
return OAuthClientResponseFactory.createCustomResponse(
|
||||
response.body().string(),
|
||||
response.body().contentType().toString(),
|
||||
response.code(),
|
||||
responseClass);
|
||||
} catch (IOException e) {
|
||||
throw new OAuthSystemException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// Nothing to do here
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import com.squareup.okhttp.Interceptor;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.Response;
|
||||
|
||||
import org.apache.oltu.oauth2.client.OAuthClient;
|
||||
import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest;
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
||||
import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
||||
import org.apache.oltu.oauth2.common.message.types.GrantType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.Map;
|
||||
|
||||
public class RetryingOAuth extends OAuth implements Interceptor {
|
||||
private OAuthClient oAuthClient;
|
||||
|
||||
private TokenRequestBuilder tokenRequestBuilder;
|
||||
|
||||
public RetryingOAuth(OkHttpClient client, TokenRequestBuilder tokenRequestBuilder) {
|
||||
this.oAuthClient = new OAuthClient(new OAuthOkHttpClient(client));
|
||||
this.tokenRequestBuilder = tokenRequestBuilder;
|
||||
}
|
||||
|
||||
public RetryingOAuth(TokenRequestBuilder tokenRequestBuilder) {
|
||||
this(new OkHttpClient(), tokenRequestBuilder);
|
||||
}
|
||||
|
||||
public RetryingOAuth(
|
||||
String tokenUrl,
|
||||
String clientId,
|
||||
GrantType grantType,
|
||||
String clientSecret,
|
||||
Map<String, String> parameters
|
||||
) {
|
||||
this(OAuthClientRequest.tokenLocation(tokenUrl)
|
||||
.setClientId(clientId)
|
||||
.setGrantType(grantType)
|
||||
.setClientSecret(clientSecret));
|
||||
|
||||
if (parameters != null) {
|
||||
for (String paramName : parameters.keySet()) {
|
||||
tokenRequestBuilder.setParameter(paramName, parameters.get(paramName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
return retryingIntercept(chain, true);
|
||||
}
|
||||
|
||||
private Response retryingIntercept(Chain chain, boolean updateTokenAndRetryOnAuthorizationFailure) throws IOException {
|
||||
Request request = chain.request();
|
||||
|
||||
// If the request already has an authorization (e.g. Basic auth), proceed with the request as is
|
||||
if (request.header("Authorization") != null) {
|
||||
return chain.proceed(request);
|
||||
}
|
||||
|
||||
// Get the token if it has not yet been acquired
|
||||
if (getAccessToken() == null) {
|
||||
updateAccessToken(null);
|
||||
}
|
||||
|
||||
OAuthClientRequest oAuthRequest;
|
||||
if (getAccessToken() != null) {
|
||||
// Build the request
|
||||
Request.Builder requestBuilder = request.newBuilder();
|
||||
|
||||
String requestAccessToken = getAccessToken();
|
||||
try {
|
||||
oAuthRequest =
|
||||
new OAuthBearerClientRequest(request.urlString()).
|
||||
setAccessToken(requestAccessToken).
|
||||
buildHeaderMessage();
|
||||
} catch (OAuthSystemException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
||||
Map<String, String> headers = oAuthRequest.getHeaders();
|
||||
for (String headerName : headers.keySet()) {
|
||||
requestBuilder.addHeader(headerName, headers.get(headerName));
|
||||
}
|
||||
requestBuilder.url(oAuthRequest.getLocationUri());
|
||||
|
||||
// Execute the request
|
||||
Response response = chain.proceed(requestBuilder.build());
|
||||
|
||||
// 401/403 response codes most likely indicate an expired access token, unless it happens two times in a row
|
||||
if (
|
||||
response != null &&
|
||||
( response.code() == HttpURLConnection.HTTP_UNAUTHORIZED ||
|
||||
response.code() == HttpURLConnection.HTTP_FORBIDDEN ) &&
|
||||
updateTokenAndRetryOnAuthorizationFailure
|
||||
) {
|
||||
try {
|
||||
if (updateAccessToken(requestAccessToken)) {
|
||||
response.body().close();
|
||||
return retryingIntercept(chain, false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
response.body().close();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
else {
|
||||
return chain.proceed(chain.request());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if the access token has been updated
|
||||
*/
|
||||
public synchronized boolean updateAccessToken(String requestAccessToken) throws IOException {
|
||||
if (getAccessToken() == null || getAccessToken().equals(requestAccessToken)) {
|
||||
try {
|
||||
OAuthJSONAccessTokenResponse accessTokenResponse =
|
||||
oAuthClient.accessToken(tokenRequestBuilder.buildBodyMessage());
|
||||
if (accessTokenResponse != null && accessTokenResponse.getAccessToken() != null) {
|
||||
setAccessToken(accessTokenResponse.getAccessToken());
|
||||
return !getAccessToken().equals(requestAccessToken);
|
||||
}
|
||||
} catch (OAuthSystemException | OAuthProblemException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public TokenRequestBuilder getTokenRequestBuilder() {
|
||||
return tokenRequestBuilder;
|
||||
}
|
||||
|
||||
public void setTokenRequestBuilder(TokenRequestBuilder tokenRequestBuilder) {
|
||||
this.tokenRequestBuilder = tokenRequestBuilder;
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,7 @@ dependencies {
|
||||
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
|
||||
compile 'com.google.code.gson:gson:2.8.1'
|
||||
compile 'io.gsonfire:gson-fire:1.8.0'
|
||||
compile group: 'org.apache.oltu.oauth2', name: 'org.apache.oltu.oauth2.client', version: '1.0.1'
|
||||
{{#joda}}
|
||||
compile 'joda-time:joda-time:2.9.9'
|
||||
{{/joda}}
|
||||
|
||||
@@ -213,6 +213,11 @@
|
||||
<artifactId>gson-fire</artifactId>
|
||||
<version>${gson-fire-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.oltu.oauth2</groupId>
|
||||
<artifactId>org.apache.oltu.oauth2.client</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
{{#joda}}
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
|
||||
@@ -1 +1 @@
|
||||
{{#isFormParam}}{{^isFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}("{{baseName}}") {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}("{{baseName}}") MultipartBody.Part {{paramName}}{{/isFile}}{{/isFormParam}}
|
||||
{{#isFormParam}}{{^isFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}("{{baseName}}") {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field("{{baseName}}"){{/isMultipart}} MultipartBody.Part {{paramName}}{{/isFile}}{{/isFormParam}}
|
||||
@@ -26,6 +26,7 @@ import javax.ws.rs.core.SecurityContext;
|
||||
import javax.ws.rs.*;
|
||||
{{#useBeanValidation}}
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.Valid;
|
||||
{{/useBeanValidation}}
|
||||
|
||||
{{#commonPath}}@Path("/{{{commonPath}}}"){{/commonPath}}{{^commonPath}}@Path(""){{/commonPath}}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/isBodyParam}}
|
||||
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{#useBeanValidation}}@Valid {{/useBeanValidation}}{{{dataType}}} {{paramName}}{{/isBodyParam}}
|
||||
@@ -7,11 +7,6 @@ import {{package}}.factories.{{classname}}ServiceFactory;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.jaxrs.*;
|
||||
|
||||
import com.sun.jersey.multipart.FormDataParam;
|
||||
{{#useBeanValidation}}
|
||||
import javax.validation.constraints.*;
|
||||
{{/useBeanValidation}}
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
@@ -28,6 +23,10 @@ import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.SecurityContext;
|
||||
import javax.ws.rs.*;
|
||||
{{#useBeanValidation}}
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.Valid;
|
||||
{{/useBeanValidation}}
|
||||
|
||||
@Path("/{{{baseName}}}")
|
||||
{{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.io.Serializable;
|
||||
{{/serializableModel}}
|
||||
{{#useBeanValidation}}
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.Valid;
|
||||
{{/useBeanValidation}}
|
||||
|
||||
{{#models}}
|
||||
|
||||
@@ -83,7 +83,8 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
|
||||
@JsonProperty("{{baseName}}")
|
||||
{{/jackson}}
|
||||
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
{{#useBeanValidation}}{{>beanValidation}}{{^isPrimitiveType}}{{^isDate}}{{^isDateTime}}{{^isString}}{{^isFile}}@Valid{{/isFile}}{{/isString}}{{/isDateTime}}{{/isDate}}{{/isPrimitiveType}}{{/useBeanValidation}}
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
{{^isReadOnly}}
|
||||
|
||||
@@ -7,7 +7,26 @@
|
||||
<version>{{artifactVersion}}</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>{{#interfaceOnly}}
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.9.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/gen/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>{{#interfaceOnly}}
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
@@ -39,9 +58,28 @@
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>2.1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
{{#java8}}
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
{{^java8}}
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
{{#useSwaggerAnnotations}}
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
@@ -87,6 +125,7 @@
|
||||
{{/useBeanValidation}}
|
||||
</dependencies>
|
||||
<properties>
|
||||
<jackson-version>2.8.9</jackson-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
@@ -27,6 +27,7 @@ org.openapitools.codegen.languages.FlashClientCodegen
|
||||
org.openapitools.codegen.languages.FinchServerCodegen
|
||||
org.openapitools.codegen.languages.GoClientCodegen
|
||||
org.openapitools.codegen.languages.GoServerCodegen
|
||||
org.openapitools.codegen.languages.GoGinServerCodegen
|
||||
org.openapitools.codegen.languages.GroovyClientCodegen
|
||||
org.openapitools.codegen.languages.KotlinClientCodegen
|
||||
org.openapitools.codegen.languages.KotlinServerCodegen
|
||||
@@ -52,6 +53,7 @@ org.openapitools.codegen.languages.JavascriptFlowtypedClientCodegen
|
||||
org.openapitools.codegen.languages.JavascriptClosureAngularClientCodegen
|
||||
org.openapitools.codegen.languages.JMeterClientCodegen
|
||||
org.openapitools.codegen.languages.LuaClientCodegen
|
||||
org.openapitools.codegen.languages.MysqlSchemaCodegen
|
||||
org.openapitools.codegen.languages.NodeJSServerCodegen
|
||||
org.openapitools.codegen.languages.ObjcClientCodegen
|
||||
org.openapitools.codegen.languages.OpenAPIGenerator
|
||||
@@ -89,6 +91,7 @@ org.openapitools.codegen.languages.Swift4Codegen
|
||||
org.openapitools.codegen.languages.TypeScriptAngularClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptAngularJsClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptAureliaClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptAxiosClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptFetchClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptInversifyClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptJqueryClientCodegen
|
||||
|
||||
@@ -204,36 +204,35 @@ void {{classname}}::fromJson(web::json::value& val)
|
||||
{{/required}}
|
||||
for( auto& item : val[utility::conversions::to_string_t("{{baseName}}")].as_array() )
|
||||
{
|
||||
utility::string_t key;
|
||||
if(item.has_field(utility::conversions::to_string_t("key")))
|
||||
{
|
||||
key = ModelBase::stringFromJson(item[utility::conversions::to_string_t("key")]);
|
||||
utility::string_t key = ModelBase::stringFromJson(item[utility::conversions::to_string_t("key")]);
|
||||
{{#items.isPrimitiveType}}
|
||||
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::{{items.baseType}}FromJson(item[utility::conversions::to_string_t("value")])));
|
||||
{{/items.isPrimitiveType}}
|
||||
{{^items.isPrimitiveType}}
|
||||
{{#items.isString}}
|
||||
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::stringFromJson(item[utility::conversions::to_string_t("value")])));
|
||||
{{/items.isString}}
|
||||
{{^items.isString}}
|
||||
{{#items.isDateTime}}
|
||||
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::dateFromJson(item[utility::conversions::to_string_t("value")])));
|
||||
{{/items.isDateTime}}
|
||||
{{^items.isDateTime}}
|
||||
if(item.is_null())
|
||||
{
|
||||
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, {{{items.datatype}}}(nullptr) ));
|
||||
}
|
||||
else
|
||||
{
|
||||
{{{items.datatype}}} newItem({{{items.defaultValue}}});
|
||||
newItem->fromJson(item[utility::conversions::to_string_t("value")]);
|
||||
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, newItem ));
|
||||
}
|
||||
{{/items.isDateTime}}
|
||||
{{/items.isString}}
|
||||
{{/items.isPrimitiveType}}
|
||||
}
|
||||
{{#items.isPrimitiveType}}
|
||||
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::{{items.baseType}}FromJson(item[utility::conversions::to_string_t("value")])));
|
||||
{{/items.isPrimitiveType}}
|
||||
{{^items.isPrimitiveType}}
|
||||
{{#items.isString}}
|
||||
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::stringFromJson(item[utility::conversions::to_string_t("value")])));
|
||||
{{/items.isString}}
|
||||
{{^items.isString}}
|
||||
{{#items.isDateTime}}
|
||||
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, ModelBase::dateFromJson(item[utility::conversions::to_string_t("value")])));
|
||||
{{/items.isDateTime}}
|
||||
{{^items.isDateTime}}
|
||||
if(item.is_null())
|
||||
{
|
||||
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, {{{items.datatype}}}(nullptr) ));
|
||||
}
|
||||
else
|
||||
{
|
||||
{{{items.datatype}}} newItem({{{items.defaultValue}}});
|
||||
newItem->fromJson(item[utility::conversions::to_string_t("value")]);
|
||||
m_{{name}}.insert(std::pair<utility::string_t,{{{items.datatype}}}>( key, newItem ));
|
||||
}
|
||||
{{/items.isDateTime}}
|
||||
{{/items.isString}}
|
||||
{{/items.isPrimitiveType}}
|
||||
}
|
||||
{{^required}}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ part '{{classFilename}}.jser.dart';
|
||||
|
||||
class {{classname}} {
|
||||
{{#vars}}{{#description}} /* {{{description}}} */{{/description}}
|
||||
@Alias('{{{baseName}}}')
|
||||
final {{{datatype}}} {{name}};
|
||||
{{#allowableValues}}{{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}{{/allowableValues}}{{/vars}}
|
||||
|
||||
|
||||
@@ -72,10 +72,10 @@ class {{classname}} {
|
||||
return json == null ? new List<{{classname}}>() : json.map((value) => new {{classname}}.fromJson(value)).toList();
|
||||
}
|
||||
|
||||
static Map<String, {{classname}}> mapFromJson(Map<String, Map<String, dynamic>> json) {
|
||||
static Map<String, {{classname}}> mapFromJson(Map<String, dynamic> json) {
|
||||
var map = new Map<String, {{classname}}>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((String key, Map<String, dynamic> value) => map[key] = new {{classname}}.fromJson(value));
|
||||
json.forEach((String key, dynamic value) => map[key] = new {{classname}}.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module DateOnly exposing (DateOnly, dateOnlyDecoder, dateOnlyEncoder)
|
||||
module DateOnly exposing (DateOnly, decoder, encoder, toString)
|
||||
|
||||
import Iso8601
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
@@ -11,17 +11,15 @@ type alias DateOnly =
|
||||
Time.Posix
|
||||
|
||||
|
||||
dateOnlyDecoder : Decoder DateOnly
|
||||
dateOnlyDecoder =
|
||||
decoder : Decoder DateOnly
|
||||
decoder =
|
||||
Decode.string
|
||||
|> Decode.andThen decodeIsoString
|
||||
|
||||
|
||||
dateOnlyEncoder : DateOnly -> Encode.Value
|
||||
dateOnlyEncoder model =
|
||||
Iso8601.fromTime model
|
||||
|> String.left 10
|
||||
|> Encode.string
|
||||
encoder : DateOnly -> Encode.Value
|
||||
encoder =
|
||||
Encode.string << toString
|
||||
|
||||
|
||||
decodeIsoString : String -> Decoder DateOnly
|
||||
@@ -32,3 +30,8 @@ decodeIsoString str =
|
||||
|
||||
Result.Err _ ->
|
||||
Decode.fail <| "Invalid date: " ++ str
|
||||
|
||||
|
||||
toString : DateOnly -> String
|
||||
toString =
|
||||
String.left 10 << Iso8601.fromTime
|
||||
@@ -1,4 +1,4 @@
|
||||
module DateOnly exposing (DateOnly, dateOnlyDecoder, dateOnlyEncoder)
|
||||
module DateOnly exposing (DateOnly, decoder, encoder, toString)
|
||||
|
||||
import Date
|
||||
import Date.Extra exposing (fromIsoString, toFormattedString)
|
||||
@@ -11,15 +11,15 @@ type alias DateOnly =
|
||||
Date.Date
|
||||
|
||||
|
||||
dateOnlyDecoder : Decoder DateOnly
|
||||
dateOnlyDecoder =
|
||||
decoder : Decoder DateOnly
|
||||
decoder =
|
||||
Decode.string
|
||||
|> Decode.andThen decodeIsoString
|
||||
|
||||
|
||||
dateOnlyEncoder : DateOnly -> Encode.Value
|
||||
dateOnlyEncoder model =
|
||||
Encode.string <| toFormattedString "yyyy-MM-dd" model
|
||||
encoder : DateOnly -> Encode.Value
|
||||
encoder =
|
||||
Encode.string << toString
|
||||
|
||||
|
||||
decodeIsoString : String -> Decoder DateOnly
|
||||
@@ -30,3 +30,8 @@ decodeIsoString str =
|
||||
|
||||
Result.Err msg ->
|
||||
Decode.fail msg
|
||||
|
||||
|
||||
toString : DateOnly -> String
|
||||
toString =
|
||||
toFormattedString "yyyy-MM-dd"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module DateTime exposing (DateTime, dateTimeDecoder, dateTimeEncoder)
|
||||
module DateTime exposing (DateTime, decoder, encoder, toString)
|
||||
|
||||
import Iso8601
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
@@ -11,15 +11,15 @@ type alias DateTime =
|
||||
Time.Posix
|
||||
|
||||
|
||||
dateTimeDecoder : Decoder DateTime
|
||||
dateTimeDecoder =
|
||||
decoder : Decoder DateTime
|
||||
decoder =
|
||||
Decode.string
|
||||
|> Decode.andThen decodeIsoString
|
||||
|
||||
|
||||
dateTimeEncoder : DateTime -> Encode.Value
|
||||
dateTimeEncoder model =
|
||||
Encode.string <| Iso8601.fromTime model
|
||||
encoder : DateTime -> Encode.Value
|
||||
encoder =
|
||||
Encode.string << toString
|
||||
|
||||
|
||||
decodeIsoString : String -> Decoder DateTime
|
||||
@@ -30,3 +30,8 @@ decodeIsoString str =
|
||||
|
||||
Result.Err _ ->
|
||||
Decode.fail <| "Invalid date: " ++ str
|
||||
|
||||
|
||||
toString : DateTime -> String
|
||||
toString =
|
||||
Iso8601.fromTime
|
||||
@@ -1,4 +1,4 @@
|
||||
module DateTime exposing (DateTime, dateTimeDecoder, dateTimeEncoder)
|
||||
module DateTime exposing (DateTime, decoder, encoder, toString)
|
||||
|
||||
import Date
|
||||
import Date.Extra exposing (fromIsoString, toIsoString)
|
||||
@@ -11,15 +11,15 @@ type alias DateTime =
|
||||
Date.Date
|
||||
|
||||
|
||||
dateTimeDecoder : Decoder DateTime
|
||||
dateTimeDecoder =
|
||||
decoder : Decoder DateTime
|
||||
decoder =
|
||||
Decode.string
|
||||
|> Decode.andThen decodeIsoString
|
||||
|
||||
|
||||
dateTimeEncoder : DateTime -> Encode.Value
|
||||
dateTimeEncoder model =
|
||||
Encode.string <| toIsoString model
|
||||
encoder : DateTime -> Encode.Value
|
||||
encoder =
|
||||
Encode.string << toString
|
||||
|
||||
|
||||
decodeIsoString : String -> Decoder DateTime
|
||||
@@ -30,3 +30,8 @@ decodeIsoString str =
|
||||
|
||||
Result.Err msg ->
|
||||
Decode.fail msg
|
||||
|
||||
|
||||
toString : DateTime -> String
|
||||
toString =
|
||||
toIsoString
|
||||
@@ -1,7 +1,6 @@
|
||||
{{classVarName}}Decoder : Decoder {{classname}}
|
||||
{{classVarName}}Decoder =
|
||||
decoder : Decoder {{classname}}
|
||||
decoder =
|
||||
{{#isElm018}}decode{{/isElm018}}{{#isElm019}}Decode.succeed{{/isElm019}} {{classname}}
|
||||
{{#allVars}}
|
||||
{{^discriminatorValue}} |> {{>fieldDecoder}}
|
||||
{{/discriminatorValue}}
|
||||
|> {{>fieldDecoder}}
|
||||
{{/allVars}}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{classVarName}}Encoder : {{classname}} -> Encode.Value
|
||||
{{classVarName}}Encoder model =
|
||||
encoder : {{#vendorExtensions.discriminatorName}}String -> {{/vendorExtensions.discriminatorName}}{{classname}} -> Encode.Value
|
||||
encoder {{#vendorExtensions.discriminatorName}}tag {{/vendorExtensions.discriminatorName}}model =
|
||||
Encode.object
|
||||
{{#allVars}}
|
||||
{{#-first}}[{{/-first}}{{^-first}},{{/-first}} {{>fieldEncoder}}
|
||||
{{/allVars}}
|
||||
]
|
||||
{{/allVars}}{{#vendorExtensions.discriminatorName}} , ( "{{{vendorExtensions.discriminatorName}}}", Encode.string tag ){{/vendorExtensions.discriminatorName}}
|
||||
]
|
||||
|
||||
@@ -1 +1 @@
|
||||
( "{{baseName}}", {{#discriminatorValue}}Encode.string "{{discriminatorValue}}"{{/discriminatorValue}}{{^discriminatorValue}}{{^required}}withDefault Encode.null (map {{/required}}{{#isContainer}}(Encode.list {{#isElm018}}<< List.map {{/isElm018}}{{/isContainer}}{{vendorExtensions.elmEncoder}}{{#isContainer}}){{/isContainer}} model.{{name}}{{^required}}){{/required}}{{/discriminatorValue}} )
|
||||
( "{{baseName}}", {{#discriminatorValue}}Encode.string "{{discriminatorValue}}"{{/discriminatorValue}}{{^discriminatorValue}}{{^required}}Maybe.withDefault Encode.null (Maybe.map {{/required}}{{#isContainer}}(Encode.list {{#isElm018}}<< List.map {{/isElm018}}{{/isContainer}}{{vendorExtensions.elmEncoder}}{{#isContainer}}){{/isContainer}} model.{{name}}{{^required}}){{/required}}{{/discriminatorValue}} )
|
||||
@@ -1,11 +1,10 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
module Data.{{classname}} exposing ({{#models}}{{#model}}{{classname}}{{#hasChildren}}(..){{/hasChildren}}{{#isEnum}}(..){{/isEnum}}{{^isEnum}}{{#vars}}{{#isEnum}}, {{vendorExtensions.elmUnionType}}(..){{/isEnum}}{{/vars}}{{/isEnum}}, {{classVarName}}Decoder, {{classVarName}}Encoder{{/model}}{{/models}})
|
||||
module Data.{{classname}} exposing ({{#models}}{{#model}}{{classname}}{{#hasChildren}}(..){{/hasChildren}}{{#isEnum}}(..){{/isEnum}}{{^isEnum}}{{#vars}}{{#isEnum}}, {{vendorExtensions.elmUnionType}}(..){{/isEnum}}{{/vars}}{{/isEnum}}, decoder, encoder{{/model}}{{/models}})
|
||||
|
||||
{{>imports}}import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing ({{#isElm018}}decode, {{/isElm018}}optional, required)
|
||||
import Json.Encode as Encode
|
||||
import Maybe exposing (map, withDefault)
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
|
||||
@@ -14,6 +13,6 @@ import Maybe exposing (map, withDefault)
|
||||
{-| {{{description}}}
|
||||
-}
|
||||
{{/description}}
|
||||
{{#isEnum}}{{>modelTypeUnion}}{{/isEnum}}{{^isEnum}}{{#hasChildren}}{{>modelTypeDiscriminator}}{{/hasChildren}}{{^hasChildren}}{{#isAlias}}{{>modelTypePrimitive}}{{/isAlias}}{{^isAlias}}{{#isArrayModel}}{{>modelTypeArray}}{{/isArrayModel}}{{^isArrayModel}}{{>modelTypeAlias}}{{/isArrayModel}}{{/isAlias}}{{/hasChildren}}{{/isEnum}}
|
||||
{{#isEnum}}{{>modelTypeUnion}}{{/isEnum}}{{^isEnum}}{{#discriminator}}{{>modelTypeDiscriminator}}{{/discriminator}}{{^discriminator}}{{#isAlias}}{{>modelTypePrimitive}}{{/isAlias}}{{^isAlias}}{{#isArrayModel}}{{>modelTypeArray}}{{/isArrayModel}}{{^isArrayModel}}{{>modelTypeAlias}}{{/isArrayModel}}{{/isAlias}}{{/discriminator}}{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
type alias {{classname}} =
|
||||
{ {{#vars}}{{^-first}} , {{/-first}}{{name}} : {{^required}}Maybe {{#isContainer}}({{/isContainer}}{{/required}}{{#isContainer}}List {{/isContainer}}{{#isEnum}}{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{dataType}}{{/isEnum}}{{^required}}{{#isContainer}}){{/isContainer}}{{/required}}
|
||||
{{/vars}} }
|
||||
{ {{#allVars}}{{^-first}} , {{/-first}}{{name}} : {{^required}}Maybe {{#isContainer}}({{/isContainer}}{{/required}}{{#isContainer}}List {{/isContainer}}{{#isEnum}}{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{dataType}}{{/isEnum}}{{^required}}{{#isContainer}}){{/isContainer}}{{/required}}
|
||||
{{/allVars}} }
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ type alias {{classname}} =
|
||||
{{parent}}
|
||||
|
||||
|
||||
{{classVarName}}Decoder : Decoder {{classname}}
|
||||
{{classVarName}}Decoder =
|
||||
decoder : Decoder {{classname}}
|
||||
decoder =
|
||||
Decode.list {{vendorExtensions.elmDecoder}}
|
||||
|
||||
|
||||
{{classVarName}}Encoder : {{classname}} -> Encode.Value
|
||||
{{classVarName}}Encoder items =
|
||||
encoder : {{classname}} -> Encode.Value
|
||||
encoder items =
|
||||
Encode.list {{#isElm018}}(List.map {{/isElm018}}{{vendorExtensions.elmEncoder}} items{{#isElm018}}){{/isElm018}}
|
||||
|
||||
@@ -1,34 +1,32 @@
|
||||
type {{classname}}
|
||||
{{#children}}
|
||||
{{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{classname}}Type {{classname}}
|
||||
{{/children}}
|
||||
{{#mappedModels}}
|
||||
{{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{modelName}}Type {{modelName}}
|
||||
{{/mappedModels}}
|
||||
|
||||
|
||||
{{classVarName}}Decoder : Decoder {{classname}}
|
||||
{{classVarName}}Decoder =
|
||||
Decode.field "{{{discriminatorName}}}" Decode.string
|
||||
|> Decode.andThen {{classVarName}}TypeDecoder
|
||||
decoder : Decoder {{classname}}
|
||||
decoder =
|
||||
Decode.field "{{{discriminator.propertyName}}}" Decode.string
|
||||
|> Decode.andThen {{classVarName}}Decoder
|
||||
|
||||
|
||||
{{classVarName}}TypeDecoder : String -> Decoder {{classname}}
|
||||
{{classVarName}}TypeDecoder {{{discriminatorName}}} =
|
||||
case {{{discriminatorName}}} of
|
||||
{{#children}}
|
||||
"{{vendorExtensions.x-discriminator-value}}" ->
|
||||
Decode.map {{classname}}Type {{classVarName}}Decoder
|
||||
{{classVarName}}Decoder : String -> Decoder {{classname}}
|
||||
{{classVarName}}Decoder tag =
|
||||
case tag of
|
||||
{{#mappedModels}}
|
||||
"{{mappingName}}" ->
|
||||
Decode.map {{modelName}}Type {{modelName}}.decoder
|
||||
|
||||
{{/children}}
|
||||
{{/mappedModels}}
|
||||
_ ->
|
||||
Decode.fail <|
|
||||
"Trying to decode {{classname}}, but {{{discriminatorName}}} "
|
||||
++ {{{discriminatorName}}} ++ " is not supported."
|
||||
Decode.fail <| "Trying to decode {{classname}}, but {{{discriminatorName}}} " ++ tag ++ " is not supported."
|
||||
|
||||
|
||||
{{classVarName}}Encoder : {{classname}} -> Encode.Value
|
||||
{{classVarName}}Encoder model =
|
||||
encoder : {{classname}} -> Encode.Value
|
||||
encoder model =
|
||||
case model of
|
||||
{{#children}}
|
||||
{{classname}}Type subModel ->
|
||||
{{classVarName}}Encoder subModel
|
||||
{{#mappedModels}}
|
||||
{{modelName}}Type subModel ->
|
||||
{{modelName}}.encoder "{{mappingName}}" subModel
|
||||
|
||||
{{/children}}
|
||||
{{/mappedModels}}
|
||||
|
||||
@@ -2,11 +2,11 @@ type alias {{classname}}
|
||||
= {{dataType}}
|
||||
|
||||
|
||||
{{classVarName}}Decoder : Decoder {{classname}}
|
||||
{{classVarName}}Decoder =
|
||||
decoder : Decoder {{classname}}
|
||||
decoder =
|
||||
{{vendorExtensions.elmDecoder}}
|
||||
|
||||
|
||||
{{classVarName}}Encoder : {{classname}} -> Encode.Value
|
||||
{{classVarName}}Encoder =
|
||||
encoder : {{classname}} -> Encode.Value
|
||||
encoder =
|
||||
{{vendorExtensions.elmEncoder}}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
{{vendorExtensions.elmDecoder}} : Decoder {{vendorExtensions.elmUnionType}}
|
||||
{{vendorExtensions.elmDecoder}} =
|
||||
Decode.string
|
||||
|> Decode.andThen (\str ->
|
||||
case str of
|
||||
|> Decode.andThen
|
||||
(\str ->
|
||||
case str of
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{{value}}} ->
|
||||
Decode.succeed {{name}}
|
||||
{{{value}}} ->
|
||||
Decode.succeed {{name}}
|
||||
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
other ->
|
||||
Decode.fail <| "Unknown type: " ++ other
|
||||
)
|
||||
other ->
|
||||
Decode.fail <| "Unknown type: " ++ other
|
||||
)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
connexion == 1.1.15
|
||||
# Install flask-connexion from git branch dev-2.0. Change when connexion 2.0 is released
|
||||
git+https://github.com/zalando/connexion.git@35e4e678ef69e703eaf84a48126049808c73b17c#egg=connexion
|
||||
swagger-ui-bundle
|
||||
python_dateutil == 2.6.0
|
||||
{{#supportPython2}}
|
||||
typing == 3.5.2.2
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
FROM golang:1.10 AS build
|
||||
WORKDIR /go/src
|
||||
COPY {{apiPath}} ./{{apiPath}}
|
||||
COPY main.go .
|
||||
|
||||
ENV CGO_ENABLED=0
|
||||
RUN go get -d -v ./...
|
||||
|
||||
RUN go build -a -installsuffix cgo -o {{packageName}} .
|
||||
|
||||
FROM scratch AS runtime
|
||||
COPY --from=build /go/src/{{packageName}} ./
|
||||
EXPOSE 8080/tcp
|
||||
ENTRYPOINT ["./{{packageName}}"]
|
||||
@@ -0,0 +1,46 @@
|
||||
# Go API Server for {{packageName}}
|
||||
|
||||
{{#appDescription}}
|
||||
{{{appDescription}}}
|
||||
{{/appDescription}}
|
||||
|
||||
## Overview
|
||||
This server was generated by the [openapi-generator]
|
||||
(https://openapi-generator.tech) project.
|
||||
By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
|
||||
-
|
||||
|
||||
To see how to make this your own, look here:
|
||||
|
||||
[README](https://openapi-generator.tech)
|
||||
|
||||
- API version: {{appVersion}}{{^hideGenerationTimestamp}}
|
||||
- Build date: {{generatedDate}}{{/hideGenerationTimestamp}}
|
||||
{{#infoUrl}}
|
||||
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
|
||||
{{/infoUrl}}
|
||||
|
||||
### Running the server
|
||||
|
||||
To run the server, follow these simple steps:
|
||||
|
||||
```
|
||||
go run main.go
|
||||
```
|
||||
|
||||
To run the server in a docker container
|
||||
```
|
||||
docker build --network=host -t {{{packageName}}} .
|
||||
```
|
||||
|
||||
Once the image is built, just run
|
||||
```
|
||||
docker run --rm -it {{{packageName}}}
|
||||
```
|
||||
|
||||
### Known Issue
|
||||
|
||||
Endpoints sharing a common path may result in issues. For example, `/v2/pet/findByTags` and `/v2/pet/:petId` will result in an issue with the Gin framework. For more information about this known limitation, please refer to [gin-gonic/gin#388](https://github.com/gin-gonic/gin/issues/388) for more information.
|
||||
|
||||
A workaround is to manually update the path and handler. Please refer to [gin-gonic/gin/issues/205#issuecomment-296155497](https://github.com/gin-gonic/gin/issues/205#issuecomment-296155497) for more information.
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{{>partial_header}}
|
||||
package {{packageName}}
|
||||
|
||||
{{#operations}}
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
){{#operation}}
|
||||
|
||||
// {{nickname}} - {{{summary}}}
|
||||
func {{nickname}}(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
}{{/operation}}{{/operations}}
|
||||
@@ -0,0 +1,23 @@
|
||||
{{>partial_header}}
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
// WARNING!
|
||||
// Change this to a fully-qualified import path
|
||||
// once you place this file into your project.
|
||||
// For example,
|
||||
//
|
||||
// sw "github.com/myname/myrepo/{{apiPath}}"
|
||||
//
|
||||
sw "./{{apiPath}}"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Printf("Server started")
|
||||
|
||||
router := sw.NewRouter()
|
||||
|
||||
log.Fatal(router.Run(":{{serverPort}}"))
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{{>partial_header}}
|
||||
package {{packageName}}
|
||||
{{#models}}{{#imports}}
|
||||
import ({{/imports}}{{#imports}}
|
||||
"{{import}}"{{/imports}}{{#imports}}
|
||||
)
|
||||
{{/imports}}{{#model}}{{#isEnum}}{{#description}}// {{{classname}}} : {{{description}}}{{/description}}
|
||||
type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}}
|
||||
|
||||
// List of {{{name}}}
|
||||
const (
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{name}} {{{classname}}} = "{{{value}}}"
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
){{/isEnum}}{{^isEnum}}{{#description}}
|
||||
// {{classname}} - {{{description}}}{{/description}}
|
||||
type {{classname}} struct {
|
||||
{{#vars}}{{#description}}
|
||||
// {{{description}}}{{/description}}
|
||||
{{name}} {{^isEnum}}{{^isPrimitiveType}}{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{/isPrimitiveType}}{{/isEnum}}{{{dataType}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"`
|
||||
{{/vars}}
|
||||
}{{/isEnum}}{{/model}}{{/models}}
|
||||
@@ -0,0 +1 @@
|
||||
{{{openapi-yaml}}}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
{{#appName}}
|
||||
* {{{appName}}}
|
||||
*
|
||||
{{/appName}}
|
||||
{{#appDescription}}
|
||||
* {{{appDescription}}}
|
||||
*
|
||||
{{/appDescription}}
|
||||
{{#version}}
|
||||
* API version: {{{version}}}
|
||||
{{/version}}
|
||||
{{#infoEmail}}
|
||||
* Contact: {{{infoEmail}}}
|
||||
{{/infoEmail}}
|
||||
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
|
||||
*/
|
||||
@@ -0,0 +1,64 @@
|
||||
{{>partial_header}}
|
||||
package {{packageName}}
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Route is the information for every URI.
|
||||
type Route struct {
|
||||
// Name is the name of this Route.
|
||||
Name string
|
||||
// Method is the string for the HTTP method. ex) GET, POST etc..
|
||||
Method string
|
||||
// Pattern is the pattern of the URI.
|
||||
Pattern string
|
||||
// HandlerFunc is the handler function of this route.
|
||||
HandlerFunc gin.HandlerFunc
|
||||
}
|
||||
|
||||
// Routes is the list of the generated Route.
|
||||
type Routes []Route
|
||||
|
||||
// NewRouter returns a new router.
|
||||
func NewRouter() *gin.Engine {
|
||||
router := gin.Default()
|
||||
for _, route := range routes {
|
||||
switch route.Method {
|
||||
case "GET":
|
||||
router.GET(route.Pattern, route.HandlerFunc)
|
||||
case "POST":
|
||||
router.POST(route.Pattern, route.HandlerFunc)
|
||||
case "PUT":
|
||||
router.PUT(route.Pattern, route.HandlerFunc)
|
||||
case "DELETE":
|
||||
router.DELETE(route.Pattern, route.HandlerFunc)
|
||||
}
|
||||
}
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
// Index is the index handler.
|
||||
func Index(c *gin.Context) {
|
||||
c.String(http.StatusOK, "Hello World!")
|
||||
}
|
||||
|
||||
var routes = Routes{
|
||||
{
|
||||
"Index",
|
||||
"GET",
|
||||
"{{{basePathWithoutHost}}}/",
|
||||
Index,
|
||||
},{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}
|
||||
|
||||
{
|
||||
"{{operationId}}",
|
||||
strings.ToUpper("{{httpMethod}}"),
|
||||
"{{{basePathWithoutHost}}}{{{path}}}",
|
||||
{{operationId}},
|
||||
},{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a
|
||||
|
||||
To see how to make this your own, look here:
|
||||
|
||||
[README]((https://openapi-generator.tech))
|
||||
[README](https://openapi-generator.tech)
|
||||
|
||||
- API version: {{appVersion}}{{^hideGenerationTimestamp}}
|
||||
- Build date: {{generatedDate}}{{/hideGenerationTimestamp}}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{{#isBodyParam}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{^isContainer}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{/swaggerAnnotations}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestBody {{paramName}}: {{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isListContainer}}Mono{{/isListContainer}}{{#isListContainer}}Flux{{/isListContainer}}<{{{baseType}}}>{{/reactive}}{{/isBodyParam}}
|
||||
{{#isBodyParam}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{^isContainer}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{/swaggerAnnotations}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestBody {{paramName}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isListContainer}}Mono{{/isListContainer}}{{#isListContainer}}Flux{{/isListContainer}}<{{{baseType}}}>{{/reactive}}{{/isBodyParam}}
|
||||
@@ -3,14 +3,23 @@
|
||||
{{#vars}}
|
||||
* @param {{name}} {{{description}}}
|
||||
{{/vars}}
|
||||
*/
|
||||
data class {{classname}} (
|
||||
*/{{#discriminator}}
|
||||
{{>typeInfoAnnotation}}{{/discriminator}}
|
||||
{{#discriminator}}interface {{classname}}{{/discriminator}}{{^discriminator}}data class {{classname}} (
|
||||
{{#requiredVars}}
|
||||
{{>dataClassReqVar}}{{^-last}},
|
||||
{{/-last}}{{/requiredVars}}{{#hasRequired}}{{#hasOptional}},
|
||||
{{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>dataClassOptVar}}{{^-last}},
|
||||
{{/-last}}{{/optionalVars}}
|
||||
) {
|
||||
) {{/discriminator}}{{#parent}}: {{{parent}}}{{/parent}}{
|
||||
{{#discriminator}}
|
||||
{{#requiredVars}}
|
||||
{{>interfaceReqVar}}
|
||||
{{/requiredVars}}
|
||||
{{#optionalVars}}
|
||||
{{>interfaceOptVar}}
|
||||
{{/optionalVars}}
|
||||
{{/discriminator}}
|
||||
{{#hasEnums}}{{#vars}}{{#isEnum}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{#useBeanValidation}}{{#required}}
|
||||
@get:NotNull {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}}
|
||||
{{^isReadOnly}}@get:NotNull{{/isReadOnly}} {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}}
|
||||
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
||||
@JsonProperty("{{{baseName}}}") val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
||||
@JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
||||
@@ -1,4 +1,4 @@
|
||||
{{#useBeanValidation}}{{#required}}
|
||||
@get:NotNull {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}}
|
||||
{{^isReadOnly}}@get:NotNull{{/isReadOnly}} {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}}
|
||||
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
||||
@JsonProperty("{{{baseName}}}") val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
||||
@JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isReadOnly}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}{{/isReadOnly}}
|
||||
@@ -1 +1 @@
|
||||
{{#isFormParam}}{{^isFile}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{/swaggerAnnotations}} @RequestParam(value="{{baseName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{paramName}}: {{{dataType}}} {{/isFile}}{{#isFile}}{{#swaggerAnnotations}}@ApiParam(value = "file detail"){{/swaggerAnnotations}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestPart("file") {{baseName}}: MultipartFile{{/isFile}}{{/isFormParam}}
|
||||
{{#isFormParam}}{{^isFile}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{/swaggerAnnotations}} @RequestParam(value="{{baseName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{paramName}}: {{>optionalDataType}} {{/isFile}}{{#isFile}}{{#swaggerAnnotations}}@ApiParam(value = "file detail"){{/swaggerAnnotations}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestPart("file") {{baseName}}: MultipartFile{{/isFile}}{{/isFormParam}}
|
||||
@@ -0,0 +1,3 @@
|
||||
{{#swaggerAnnotations}}
|
||||
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
||||
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}{{/discriminator}}
|
||||
@@ -0,0 +1,3 @@
|
||||
{{#swaggerAnnotations}}
|
||||
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
||||
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
||||
@@ -1 +1 @@
|
||||
{{#useOptional}}{{#required}}{{{dataType}}}{{/required}}{{^required}}Optional<{{{dataType}}}>{{/required}}{{/useOptional}}{{^useOptional}}{{{dataType}}}{{/useOptional}}
|
||||
{{#required}}{{{dataType}}}{{/required}}{{^required}}{{#defaultValue}}{{{dataType}}}{{/defaultValue}}{{^defaultValue}}{{{dataType}}}?{{/defaultValue}}{{/required}}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user