forked from loafle/openapi-generator-original
Compare commits
81 Commits
security-t
...
nodejs-fas
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
605030dfeb | ||
|
|
ecb11fbe7f | ||
|
|
5cd3a16e56 | ||
|
|
182264cbdd | ||
|
|
ee69861a90 | ||
|
|
69ad9a9957 | ||
|
|
9c7d4073f4 | ||
|
|
f4fa941e2b | ||
|
|
c81c09b941 | ||
|
|
822234dd76 | ||
|
|
18b500218a | ||
|
|
977df6e232 | ||
|
|
976ab4fd0f | ||
|
|
8977d7b366 | ||
|
|
c4d982f775 | ||
|
|
f26d7bdea7 | ||
|
|
3bb4edf865 | ||
|
|
0bc06f8d4d | ||
|
|
d056df6250 | ||
|
|
cd6779584f | ||
|
|
09ba78b26a | ||
|
|
e58d7d09d5 | ||
|
|
9d10ffdb38 | ||
|
|
88cdbbc41f | ||
|
|
3a0d520c38 | ||
|
|
1313cff93a | ||
|
|
a079f70fb2 | ||
|
|
74fbd3454b | ||
|
|
46e8ccbd1e | ||
|
|
0f99cd0d37 | ||
|
|
7ab73ff587 | ||
|
|
1c1c1ef9c3 | ||
|
|
2ce3574868 | ||
|
|
81c57eefd5 | ||
|
|
6e7c621629 | ||
|
|
41b5d0e8fc | ||
|
|
09d27e82e7 | ||
|
|
393f5e499e | ||
|
|
d795c4e9d0 | ||
|
|
01e8c67da9 | ||
|
|
d4244be654 | ||
|
|
5a6f4cb4a9 | ||
|
|
5d05cc0e66 | ||
|
|
28ae33cb13 | ||
|
|
9e391efd1d | ||
|
|
173ae6f368 | ||
|
|
7af272a249 | ||
|
|
879d47ccd0 | ||
|
|
65e36e8369 | ||
|
|
f015363dbd | ||
|
|
3677bdcfc7 | ||
|
|
3810d12086 | ||
|
|
c918d7ad64 | ||
|
|
5346eb4c34 | ||
|
|
3e065db2c6 | ||
|
|
5074f4d9c5 | ||
|
|
df0d53795c | ||
|
|
3b017c59f1 | ||
|
|
e0caa6fd66 | ||
|
|
0935f5345d | ||
|
|
f7943257c5 | ||
|
|
033ab8a6f5 | ||
|
|
1adc962f2b | ||
|
|
94c267ee42 | ||
|
|
4a7dfecf24 | ||
|
|
db1b63780d | ||
|
|
e3716262e5 | ||
|
|
ee75366051 | ||
|
|
d839af5b1e | ||
|
|
2e777c04d4 | ||
|
|
b1955f3517 | ||
|
|
45ad72b032 | ||
|
|
2101780a09 | ||
|
|
1a19edb0e5 | ||
|
|
2f8e4fe32b | ||
|
|
77545df80d | ||
|
|
dc78405a68 | ||
|
|
fef2970dab | ||
|
|
522ccee7f3 | ||
|
|
d32564da51 | ||
|
|
49f3e9a355 |
@@ -1 +1 @@
|
|||||||
oracle64-1.8.0.152
|
oracle64-1.8.0.152
|
||||||
@@ -133,18 +133,16 @@ after_success:
|
|||||||
cd modules/openapi-generator-gradle-plugin;
|
cd modules/openapi-generator-gradle-plugin;
|
||||||
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" uploadArchives --no-daemon;
|
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" uploadArchives --no-daemon;
|
||||||
echo "Finished ./gradlew uploadArchives";
|
echo "Finished ./gradlew uploadArchives";
|
||||||
#./gradlew publishPlugins;
|
|
||||||
#echo "Finished ./gradlew publishPlugins (plugin portal)";
|
|
||||||
popd;
|
popd;
|
||||||
elif ([[ "$TRAVIS_BRANCH" =~ ^[0-9]+\.[0-9]+\.x$ ]]) ; then
|
elif ([[ "$TRAVIS_BRANCH" =~ ^[0-9]+\.[0-9]+\.x$ ]]) ; then
|
||||||
mvn clean deploy --settings CI/settings.xml;
|
mvn clean deploy --settings CI/settings.xml;
|
||||||
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
|
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
|
||||||
pushd .;
|
pushd .;
|
||||||
cd modules/openapi-generator-gradle-plugin;
|
cd modules/openapi-generator-gradle-plugin;
|
||||||
|
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" publishPlugins -Dgradle.publish.key=$GRADLE_PUBLISH_KEY -Dgradle.publish.secret=$GRADLE_PUBLISH_SECRET --no-daemon;
|
||||||
|
echo "Finished ./gradlew publishPlugins (plugin portal)";
|
||||||
./gradlew -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" uploadArchives --no-daemon;
|
./gradlew -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" uploadArchives --no-daemon;
|
||||||
echo "Finished ./gradlew uploadArchives";
|
echo "Finished ./gradlew uploadArchives";
|
||||||
#./gradlew publishPlugins;
|
|
||||||
#echo "Finished ./gradlew publishPlugins (plugin portal)";
|
|
||||||
popd;
|
popd;
|
||||||
fi;
|
fi;
|
||||||
fi;
|
fi;
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -39,7 +39,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
|
|||||||
| | Languages/Frameworks |
|
| | Languages/Frameworks |
|
||||||
|-|-|
|
|-|-|
|
||||||
**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client), **Kotlin**, **Lua**, **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (AngularJS, Angular (2.x - 7.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node, Rxjs)
|
**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client), **Kotlin**, **Lua**, **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (AngularJS, Angular (2.x - 7.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node, Rxjs)
|
||||||
**Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go** (net/http, Gin), **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples)), **Kotlin** (Spring Boot, Ktor), **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)
|
**Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go** (net/http, Gin), **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples)), **Kotlin** (Spring Boot, Ktor), **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), [Play](https://www.playframework.com/), Scalatra)
|
||||||
**API documentation generators** | **HTML**, **Confluence Wiki**
|
**API documentation generators** | **HTML**, **Confluence Wiki**
|
||||||
**Configuration files** | [**Apache2**](https://httpd.apache.org/)
|
**Configuration files** | [**Apache2**](https://httpd.apache.org/)
|
||||||
**Others** | **GraphQL**, **JMeter**, **MySQL Schema**
|
**Others** | **GraphQL**, **JMeter**, **MySQL Schema**
|
||||||
@@ -511,6 +511,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
|||||||
- [FormAPI](https://formapi.io/)
|
- [FormAPI](https://formapi.io/)
|
||||||
- [GenFlow](https://github.com/RepreZen/GenFlow)
|
- [GenFlow](https://github.com/RepreZen/GenFlow)
|
||||||
- [GMO Pepabo](https://pepabo.com/en/)
|
- [GMO Pepabo](https://pepabo.com/en/)
|
||||||
|
- [GoDaddy](https://godaddy.com)
|
||||||
- [JustStar](https://www.juststarinfo.com)
|
- [JustStar](https://www.juststarinfo.com)
|
||||||
- [Klarna](https://www.klarna.com/)
|
- [Klarna](https://www.klarna.com/)
|
||||||
- [Metaswitch](https://www.metaswitch.com/)
|
- [Metaswitch](https://www.metaswitch.com/)
|
||||||
@@ -551,6 +552,10 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
|||||||
- 2019/02/20 - [An adventure in OpenAPI V3 code generation](https://mux.com/blog/an-adventure-in-openapi-v3-api-code-generation/) by [Phil Cluff](https://mux.com/blog/author/philc/)
|
- 2019/02/20 - [An adventure in OpenAPI V3 code generation](https://mux.com/blog/an-adventure-in-openapi-v3-api-code-generation/) by [Phil Cluff](https://mux.com/blog/author/philc/)
|
||||||
- 2019/02/26 - [Building API Services: A Beginner’s Guide](https://medium.com/google-cloud/building-api-services-a-beginners-guide-7274ae4c547f) by [Ratros Y.](https://medium.com/@ratrosy) in [Google Cloud Platofrm Blog](https://medium.com/google-cloud)
|
- 2019/02/26 - [Building API Services: A Beginner’s Guide](https://medium.com/google-cloud/building-api-services-a-beginners-guide-7274ae4c547f) by [Ratros Y.](https://medium.com/@ratrosy) in [Google Cloud Platofrm Blog](https://medium.com/google-cloud)
|
||||||
- 2019/02/26 - [Building APIs with OpenAPI: Continued](https://medium.com/@ratrosy/building-apis-with-openapi-continued-5d0faaed32eb) by [Ratros Y.](https://medium.com/@ratrosy) in [Google Cloud Platofrm Blog](https://medium.com/google-cloud)
|
- 2019/02/26 - [Building APIs with OpenAPI: Continued](https://medium.com/@ratrosy/building-apis-with-openapi-continued-5d0faaed32eb) by [Ratros Y.](https://medium.com/@ratrosy) in [Google Cloud Platofrm Blog](https://medium.com/google-cloud)
|
||||||
|
- 2019-03-07 - [OpenAPI Generator で Spring Boot と Angular をタイプセーフに繋ぐ](https://qiita.com/chibato/items/e4a748db12409b40c02f) by [Tomofumi Chiba](https://github.com/chibat)
|
||||||
|
- 2019-03-25 - [Access any REST service with the SAP S/4HANA Cloud SDK](https://blogs.sap.com/2019/03/25/integrate-sap-s4hana-cloud-sdk-with-open-api/) by [Alexander Duemont](https://people.sap.com/alexander.duemont)
|
||||||
|
- 2019-03-25 - [OpenAPI generatorを試してみる](https://qiita.com/amuyikam/items/e8a45daae59c68be0fc8) by [@amuyikam](https://twitter.com/amuyikam)
|
||||||
|
|
||||||
|
|
||||||
## [6 - About Us](#table-of-contents)
|
## [6 - About Us](#table-of-contents)
|
||||||
|
|
||||||
@@ -662,6 +667,7 @@ Here is a list of template creators:
|
|||||||
* Rust (rust-server): @metaswitch
|
* Rust (rust-server): @metaswitch
|
||||||
* Scala Finch: @jimschubert [:heart:](https://www.patreon.com/jimschubert)
|
* Scala Finch: @jimschubert [:heart:](https://www.patreon.com/jimschubert)
|
||||||
* Scala Lagom: @gmkumar2005
|
* Scala Lagom: @gmkumar2005
|
||||||
|
* Scala Play: @adigerber
|
||||||
* Documentation
|
* Documentation
|
||||||
* HTML Doc 2: @jhitchcock
|
* HTML Doc 2: @jhitchcock
|
||||||
* Confluence Wiki: @jhitchcock
|
* Confluence Wiki: @jhitchcock
|
||||||
@@ -722,8 +728,8 @@ If you want to join the committee, please kindly apply by sending an email to te
|
|||||||
| GraphQL | @renepardon (2018/12) |
|
| GraphQL | @renepardon (2018/12) |
|
||||||
| Groovy | |
|
| Groovy | |
|
||||||
| Haskell | |
|
| Haskell | |
|
||||||
| Java | @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) |
|
| Java | @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) |
|
||||||
| Kotlin | @jimschubert (2017/09) [:heart:](https://www.patreon.com/jimschubert), @dr4ke616 (2018/08) |
|
| Kotlin | @jimschubert (2017/09) [:heart:](https://www.patreon.com/jimschubert), @dr4ke616 (2018/08) @karismann (2019/03) |
|
||||||
| Lua | @daurnimator (2017/08) |
|
| Lua | @daurnimator (2017/08) |
|
||||||
| NodeJS/Javascript | @CodeNinjai (2017/07) @frol (2017/07) @cliffano (2017/07) |
|
| NodeJS/Javascript | @CodeNinjai (2017/07) @frol (2017/07) @cliffano (2017/07) |
|
||||||
| ObjC | |
|
| ObjC | |
|
||||||
|
|||||||
@@ -35,6 +35,14 @@ java $JAVA_OPTS -jar $executable $ags
|
|||||||
ags="$@ generate -t modules/openapi-generator/src/main/resources/dart-jaguar -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dart-jaguar -o samples/client/petstore/dart-jaguar/flutter_petstore/openapi -DhideGenerationTimestamp=true -DpubName=openapi"
|
ags="$@ generate -t modules/openapi-generator/src/main/resources/dart-jaguar -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dart-jaguar -o samples/client/petstore/dart-jaguar/flutter_petstore/openapi -DhideGenerationTimestamp=true -DpubName=openapi"
|
||||||
java $JAVA_OPTS -jar $executable $ags
|
java $JAVA_OPTS -jar $executable $ags
|
||||||
|
|
||||||
|
# Generate proto and put it to the flutter sample app
|
||||||
|
ags="$@ generate -t modules/openapi-generator/src/main/resources/dart-jaguar -i modules/openapi-generator/src/test/resources/2_0/petstore-proto.yaml -g dart-jaguar -o samples/client/petstore/dart-jaguar/flutter_proto_petstore/openapi -Dserialization=proto -DhideGenerationTimestamp=true -DpubName=openapi"
|
||||||
|
java $JAVA_OPTS -jar $executable $ags
|
||||||
|
|
||||||
|
# Generate proto and put it to the sample
|
||||||
|
ags="$@ generate -t modules/openapi-generator/src/main/resources/dart-jaguar -i modules/openapi-generator/src/test/resources/2_0/petstore-proto.yaml -g dart-jaguar -o samples/client/petstore/dart-jaguar/openapi_proto -Dserialization=proto -DhideGenerationTimestamp=true -DpubName=openapi"
|
||||||
|
java $JAVA_OPTS -jar $executable $ags
|
||||||
|
|
||||||
# There is a proposal to allow importing different libraries depending on the environment:
|
# There is a proposal to allow importing different libraries depending on the environment:
|
||||||
# https://github.com/munificent/dep-interface-libraries
|
# https://github.com/munificent/dep-interface-libraries
|
||||||
# When this is implemented there will only be one library.
|
# When this is implemented there will only be one library.
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"library": "vertx",
|
"library": "vertx",
|
||||||
|
"dateLibrary": "java8",
|
||||||
"artifactId": "petstore-vertx"
|
"artifactId": "petstore-vertx"
|
||||||
}
|
}
|
||||||
|
|||||||
32
bin/nodejs-fastify-petstore-server.sh
Executable file
32
bin/nodejs-fastify-petstore-server.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SCRIPT="$0"
|
||||||
|
echo "# START SCRIPT: $SCRIPT"
|
||||||
|
|
||||||
|
while [ -h "$SCRIPT" ] ; do
|
||||||
|
ls=`ls -ld "$SCRIPT"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
SCRIPT="$link"
|
||||||
|
else
|
||||||
|
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -d "${APP_DIR}" ]; then
|
||||||
|
APP_DIR=`dirname "$SCRIPT"`/..
|
||||||
|
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||||
|
fi
|
||||||
|
|
||||||
|
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||||
|
|
||||||
|
if [ ! -f "$executable" ]
|
||||||
|
then
|
||||||
|
mvn -B clean package
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if you've executed sbt assembly previously it will use that instead.
|
||||||
|
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||||
|
ags="generate -t modules/openapi-generator/src/main/resources/nodejs-fastify-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g nodejs-fastify-server -o samples/server/petstore/nodejs-fastify-server $@"
|
||||||
|
|
||||||
|
java $JAVA_OPTS -jar $executable $ags
|
||||||
@@ -25,6 +25,11 @@ then
|
|||||||
mvn -B clean package
|
mvn -B clean package
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "purge ruby petstore lib, docs, spec folder"
|
||||||
|
rm -Rf samples/client/petstore/ruby/lib
|
||||||
|
rm -Rf samples/client/petstore/ruby/docs
|
||||||
|
rm -Rf samples/client/petstore/ruby/spec
|
||||||
|
|
||||||
# if you've executed sbt assembly previously it will use that instead.
|
# 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"
|
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||||
ags="generate -t modules/openapi-generator/src/main/resources/ruby-client -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ruby -c bin/ruby-petstore.json -o samples/client/petstore/ruby $@"
|
ags="generate -t modules/openapi-generator/src/main/resources/ruby-client -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ruby -c bin/ruby-petstore.json -o samples/client/petstore/ruby $@"
|
||||||
|
|||||||
32
bin/scala-play-framework-petstore.sh
Executable file
32
bin/scala-play-framework-petstore.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SCRIPT="$0"
|
||||||
|
echo "# START SCRIPT: $SCRIPT"
|
||||||
|
|
||||||
|
while [ -h "$SCRIPT" ] ; do
|
||||||
|
ls=`ls -ld "$SCRIPT"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
SCRIPT="$link"
|
||||||
|
else
|
||||||
|
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -d "${APP_DIR}" ]; then
|
||||||
|
APP_DIR=`dirname "$SCRIPT"`/..
|
||||||
|
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||||
|
fi
|
||||||
|
|
||||||
|
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||||
|
|
||||||
|
if [ ! -f "$executable" ]
|
||||||
|
then
|
||||||
|
mvn -B clean package
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if you've executed sbt assembly previously it will use that instead.
|
||||||
|
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||||
|
ags="generate -t modules/openapi-generator/src/main/resources/scala-play-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g scala-play-server -o samples/server/petstore/scala-play-server $@"
|
||||||
|
|
||||||
|
java $JAVA_OPTS -jar $executable $ags
|
||||||
@@ -24,6 +24,7 @@ declare -a scripts=(
|
|||||||
"./bin/kotlin-client-string.sh"
|
"./bin/kotlin-client-string.sh"
|
||||||
"./bin/kotlin-client-threetenbp.sh"
|
"./bin/kotlin-client-threetenbp.sh"
|
||||||
"./bin/kotlin-server-petstore.sh"
|
"./bin/kotlin-server-petstore.sh"
|
||||||
|
"./bin/kotlin-springboot-petstore-server.sh"
|
||||||
"./bin/mysql-schema-petstore.sh"
|
"./bin/mysql-schema-petstore.sh"
|
||||||
"./bin/python-petstore-all.sh"
|
"./bin/python-petstore-all.sh"
|
||||||
"./bin/openapi3/python-petstore.sh"
|
"./bin/openapi3/python-petstore.sh"
|
||||||
@@ -34,7 +35,9 @@ declare -a scripts=(
|
|||||||
"./bin/php-slim-server-petstore.sh"
|
"./bin/php-slim-server-petstore.sh"
|
||||||
"./bin/php-ze-ph-petstore-server.sh"
|
"./bin/php-ze-ph-petstore-server.sh"
|
||||||
"./bin/openapi3/php-petstore.sh"
|
"./bin/openapi3/php-petstore.sh"
|
||||||
|
"./bin/typescript-angularjs-petstore.sh"
|
||||||
"./bin/typescript-angular-petstore-all.sh"
|
"./bin/typescript-angular-petstore-all.sh"
|
||||||
|
"./bin/typescript-aurelia-petstore.sh"
|
||||||
"./bin/typescript-axios-petstore-all.sh"
|
"./bin/typescript-axios-petstore-all.sh"
|
||||||
"./bin/typescript-fetch-petstore-all.sh"
|
"./bin/typescript-fetch-petstore-all.sh"
|
||||||
"./bin/typescript-node-petstore-all.sh"
|
"./bin/typescript-node-petstore-all.sh"
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||||
|
|
||||||
If Not Exist %executable% (
|
If Not Exist %executable% (
|
||||||
mvn clean package
|
mvn clean package
|
||||||
)
|
)
|
||||||
|
|
||||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g kotlin-spring -o samples\server\petstore\kotlin-springboot --additional-properties=library=spring-boot
|
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g kotlin-spring -o samples\server\petstore\kotlin-springboot --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true
|
||||||
|
|
||||||
java %JAVA_OPTS% -jar %executable% %ags%
|
java %JAVA_OPTS% -jar %executable% %ags%
|
||||||
|
|||||||
10
bin/windows/nodejs-fastify-petstore-server.bat
Executable file
10
bin/windows/nodejs-fastify-petstore-server.bat
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||||
|
|
||||||
|
If Not Exist %executable% (
|
||||||
|
mvn clean package
|
||||||
|
)
|
||||||
|
|
||||||
|
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||||
|
set ags=generate -t modules\openapi-generator\src\main\resources\nodejs-fastify-server -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g nodejs-fastify-server -o samples\server\petstore\nodejs-fastify-server
|
||||||
|
|
||||||
|
java %JAVA_OPTS% -jar %executable% %ags%
|
||||||
10
bin/windows/scala-play-framework-petstore.bat
Executable file
10
bin/windows/scala-play-framework-petstore.bat
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||||
|
|
||||||
|
If Not Exist %executable% (
|
||||||
|
mvn clean package
|
||||||
|
)
|
||||||
|
|
||||||
|
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||||
|
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g scala-play-server -o samples\server\petstore\scala-play-server
|
||||||
|
|
||||||
|
java %JAVA_OPTS% -jar %executable% %ags%
|
||||||
@@ -105,6 +105,7 @@ The following generators are available:
|
|||||||
- [rust-server](generators/rust-server.md)
|
- [rust-server](generators/rust-server.md)
|
||||||
- [scala-finch](generators/scala-finch.md)
|
- [scala-finch](generators/scala-finch.md)
|
||||||
- [scala-lagom-server](generators/scala-lagom-server.md)
|
- [scala-lagom-server](generators/scala-lagom-server.md)
|
||||||
|
- [scala-play-server](generators/scala-play-server.md)
|
||||||
- [scalatra](generators/scalatra.md)
|
- [scalatra](generators/scalatra.md)
|
||||||
- [spring](generators/spring.md)
|
- [spring](generators/spring.md)
|
||||||
|
|
||||||
|
|||||||
@@ -19,3 +19,4 @@ sidebar_label: dart-jaguar
|
|||||||
|sourceFolder|source folder for generated code| |null|
|
|sourceFolder|source folder for generated code| |null|
|
||||||
|supportDart2|support dart2| |true|
|
|supportDart2|support dart2| |true|
|
||||||
|nullableFields|Is the null fields should be in the JSON payload| |null|
|
|nullableFields|Is the null fields should be in the JSON payload| |null|
|
||||||
|
|serialization|Choose serialization format JSON or PROTO is supported| |null|
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ sidebar_label: go-gin-server
|
|||||||
| Option | Description | Values | Default |
|
| Option | Description | Values | Default |
|
||||||
| ------ | ----------- | ------ | ------- |
|
| ------ | ----------- | ------ | ------- |
|
||||||
|packageName|Go package name (convention: lowercase).| |openapi|
|
|packageName|Go package name (convention: lowercase).| |openapi|
|
||||||
|
|packageVersion|Go package version.| |1.0.0|
|
||||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||||
|
|||||||
@@ -8,4 +8,7 @@ sidebar_label: go-server
|
|||||||
| Option | Description | Values | Default |
|
| Option | Description | Values | Default |
|
||||||
| ------ | ----------- | ------ | ------- |
|
| ------ | ----------- | ------ | ------- |
|
||||||
|packageName|Go package name (convention: lowercase).| |openapi|
|
|packageName|Go package name (convention: lowercase).| |openapi|
|
||||||
|
|packageVersion|Go package version.| |1.0.0|
|
||||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||||
|
|sourceFolder|source folder for generated code| |go|
|
||||||
|
|serverPort|The network port the generated server binds to| |8080|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ sidebar_label: go
|
|||||||
| Option | Description | Values | Default |
|
| Option | Description | Values | Default |
|
||||||
| ------ | ----------- | ------ | ------- |
|
| ------ | ----------- | ------ | ------- |
|
||||||
|packageName|Go package name (convention: lowercase).| |openapi|
|
|packageName|Go package name (convention: lowercase).| |openapi|
|
||||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
|
||||||
|packageVersion|Go package version.| |1.0.0|
|
|packageVersion|Go package version.| |1.0.0|
|
||||||
|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||||
|withGoCodegenComment|whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs| |false|
|
|withGoCodegenComment|whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs| |false|
|
||||||
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
|
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
|
||||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||||
|
|||||||
@@ -54,4 +54,4 @@ sidebar_label: java
|
|||||||
|useRuntimeException|Use RuntimeException instead of Exception| |false|
|
|useRuntimeException|Use RuntimeException instead of Exception| |false|
|
||||||
|feignVersion|Version of OpenFeign: '10.x', '9.x' (default)| |false|
|
|feignVersion|Version of OpenFeign: '10.x', '9.x' (default)| |false|
|
||||||
|useReflectionEqualsHashCode|Use org.apache.commons.lang3.builder for equals and hashCode in the models. WARNING: This will fail under a security manager, unless the appropriate permissions are set up correctly and also there's potential performance impact.| |false|
|
|useReflectionEqualsHashCode|Use org.apache.commons.lang3.builder for equals and hashCode in the models. WARNING: This will fail under a security manager, unless the appropriate permissions are set up correctly and also there's potential performance impact.| |false|
|
||||||
|library|library template (sub-template) to use|<dl><dt>**jersey1**</dt><dd>HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.8.9. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.</dd><dt>**feign**</dt><dd>HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.8.9. To enable OpenFeign 10.x, set the 'feignVersion' option to '10.x'</dd><dt>**jersey2**</dt><dd>HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.8.9</dd><dt>**okhttp-gson**</dt><dd>HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.8.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.</dd><dt>**retrofit**</dt><dd>HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.</dd><dt>**retrofit2**</dt><dd>HTTP client: OkHttp 3.8.0. JSON processing: Gson 2.6.1 (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)</dd><dt>**resttemplate**</dt><dd>HTTP client: Spring RestTemplate 4.3.9-RELEASE. JSON processing: Jackson 2.8.9</dd><dt>**webclient**</dt><dd>HTTP client: Spring WebClient 5.0.7-RELEASE. JSON processing: Jackson 2.9.5</dd><dt>**resteasy**</dt><dd>HTTP client: Resteasy client 3.1.3.Final. JSON processing: Jackson 2.8.9</dd><dt>**vertx**</dt><dd>HTTP client: VertX client 3.2.4. JSON processing: Jackson 2.8.9</dd><dt>**google-api-client**</dt><dd>HTTP client: Google API client 1.23.0. JSON processing: Jackson 2.8.9</dd><dt>**rest-assured**</dt><dd>HTTP client: rest-assured : 3.1.0. JSON processing: Gson 2.6.1. Only for Java8</dd><dl>|okhttp-gson|
|
|library|library template (sub-template) to use|<dl><dt>**jersey1**</dt><dd>HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.8.x. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.</dd><dt>**feign**</dt><dd>HTTP client: OpenFeign 9.x or 10.x. JSON processing: Jackson 2.8.x. To enable OpenFeign 10.x, set the 'feignVersion' option to '10.x'</dd><dt>**jersey2**</dt><dd>HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.8.x</dd><dt>**okhttp-gson**</dt><dd>HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.</dd><dt>**retrofit**</dt><dd>HTTP client: OkHttp 2.x. JSON processing: Gson 2.x (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.</dd><dt>**retrofit2**</dt><dd>HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)</dd><dt>**resttemplate**</dt><dd>HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.8.x</dd><dt>**webclient**</dt><dd>HTTP client: Spring WebClient 5.x. JSON processing: Jackson 2.9.x</dd><dt>**resteasy**</dt><dd>HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.8.x</dd><dt>**vertx**</dt><dd>HTTP client: VertX client 3.x. JSON processing: Jackson 2.8.x</dd><dt>**google-api-client**</dt><dd>HTTP client: Google API client 1.x. JSON processing: Jackson 2.8.x</dd><dt>**rest-assured**</dt><dd>HTTP client: rest-assured : 3.x. JSON processing: Gson 2.x. Only for Java8</dd><dl>|okhttp-gson|
|
||||||
|
|||||||
22
docs/generators/scala-play-framework.md
Normal file
22
docs/generators/scala-play-framework.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
---
|
||||||
|
id: generator-opts-server-scala-play-framework
|
||||||
|
title: Config Options for scala-play-framework
|
||||||
|
sidebar_label: scala-play-framework
|
||||||
|
---
|
||||||
|
|
||||||
|
| Option | Description | Values | Default |
|
||||||
|
| ------ | ----------- | ------ | ------- |
|
||||||
|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||||
|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
||||||
|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|
||||||
|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||||
|
|modelPackage|package for generated models| |null|
|
||||||
|
|apiPackage|package for generated api classes| |null|
|
||||||
|
|sourceFolder|source folder for generated code| |null|
|
||||||
|
|routesFileName|Name of the routes file to generate.| |routes|
|
||||||
|
|routesFileName|Base package in which supporting classes are generated.| |org.openapitools|
|
||||||
|
|skipStubs|If set, skips generation of stub classes.| |false|
|
||||||
|
|supportAsync|If set, wraps API return types with Futures and generates async actions.| |false|
|
||||||
|
|generateCustomExceptions|If set, generates custom exception types.| |true|
|
||||||
|
|useSwaggerUI|Add a route to /api which show your documentation in swagger-ui. Will also import needed dependencies| |true|
|
||||||
22
docs/generators/scala-play-server.md
Normal file
22
docs/generators/scala-play-server.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
---
|
||||||
|
id: generator-opts-server-scala-play-server
|
||||||
|
title: Config Options for scala-play-server
|
||||||
|
sidebar_label: scala-play-server
|
||||||
|
---
|
||||||
|
|
||||||
|
| Option | Description | Values | Default |
|
||||||
|
| ------ | ----------- | ------ | ------- |
|
||||||
|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||||
|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
||||||
|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|
||||||
|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||||
|
|modelPackage|package for generated models| |null|
|
||||||
|
|apiPackage|package for generated api classes| |null|
|
||||||
|
|sourceFolder|source folder for generated code| |null|
|
||||||
|
|routesFileName|Name of the routes file to generate.| |routes|
|
||||||
|
|routesFileName|Base package in which supporting classes are generated.| |org.openapitools|
|
||||||
|
|skipStubs|If set, skips generation of stub classes.| |false|
|
||||||
|
|supportAsync|If set, wraps API return types with Futures and generates async actions.| |false|
|
||||||
|
|generateCustomExceptions|If set, generates custom exception types.| |true|
|
||||||
|
|useSwaggerUI|Add a route to /api which show your documentation in swagger-ui. Will also import needed dependencies| |true|
|
||||||
@@ -249,4 +249,4 @@ If your API client is using named parameters in the function call (e.g. Perl req
|
|||||||
|
|
||||||
## Default basePath
|
## Default basePath
|
||||||
|
|
||||||
The default `basePath` has been changed from `https://localhost` to `http://locallhost` (http without s)
|
The default `basePath` has been changed from `https://localhost` to `http://localhost` (http without s)
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ SYNOPSIS
|
|||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
-f <output format>, --format <output format>
|
-f <output format>, --format <output format>
|
||||||
Write output files in the desired format. Options are 'text' and
|
Write output files in the desired format. Options are 'text',
|
||||||
'markdown'. Default is 'text'.
|
'markdown' or 'yamlsample'. Default is 'text'.
|
||||||
|
|
||||||
-g <generator name>, --generator-name <generator name>
|
-g <generator name>, --generator-name <generator name>
|
||||||
generator to get config help for
|
generator to get config help for
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
|
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
|
||||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||||
@@ -40,30 +40,34 @@ public class ConfigHelp implements Runnable {
|
|||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(Generate.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(Generate.class);
|
||||||
|
|
||||||
@Option(name = {"-g", "--generator-name"}, title = "generator name",
|
public static final String FORMAT_TEXT = "text";
|
||||||
description = "generator to get config help for")
|
public static final String FORMAT_MARKDOWN = "markdown";
|
||||||
|
public static final String FORMAT_YAMLSAMPLE = "yamlsample";
|
||||||
|
|
||||||
|
@Option(name = {"-g",
|
||||||
|
"--generator-name"}, title = "generator name", description = "generator to get config help for")
|
||||||
private String generatorName;
|
private String generatorName;
|
||||||
|
|
||||||
@Option(name = {"--named-header"}, title = "named header",
|
@Option(name = {
|
||||||
description = "Header includes the generator name, for clarity in output")
|
"--named-header"}, title = "named header", description = "Header includes the generator name, for clarity in output")
|
||||||
private Boolean namedHeader;
|
private Boolean namedHeader;
|
||||||
|
|
||||||
@Option(name = {"-o", "--output"}, title = "output location",
|
@Option(name = {"-o",
|
||||||
description = "Optionally write help to this location, otherwise default is standard output")
|
"--output"}, title = "output location", description = "Optionally write help to this location, otherwise default is standard output")
|
||||||
private String outputFile;
|
private String outputFile;
|
||||||
|
|
||||||
@Option(name = {"-f", "--format"}, title = "output format",
|
@Option(name = {"-f",
|
||||||
description = "Write output files in the desired format. Options are 'text' and 'markdown'. Default is 'text'.")
|
"--format"}, title = "output format", description = "Write output files in the desired format. Options are 'text', 'markdown' or 'yamlsample'. Default is 'text'.", allowedValues = {
|
||||||
|
FORMAT_TEXT, FORMAT_MARKDOWN, FORMAT_YAMLSAMPLE})
|
||||||
private String format;
|
private String format;
|
||||||
|
|
||||||
@Option(name = {"--markdown-header"}, title = "markdown header",
|
@Option(name = {
|
||||||
description = "When format=markdown, include this option to write out markdown headers (e.g. for docusaurus).")
|
"--markdown-header"}, title = "markdown header", description = "When format=markdown, include this option to write out markdown headers (e.g. for docusaurus).")
|
||||||
private Boolean markdownHeader;
|
private Boolean markdownHeader;
|
||||||
|
|
||||||
private String newline = System.lineSeparator();
|
private String newline = System.lineSeparator();
|
||||||
|
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
if (isEmpty(generatorName)) {
|
if (isEmpty(generatorName)) {
|
||||||
LOGGER.error("[error] A generator name (--generator-name / -g) is required.");
|
LOGGER.error("[error] A generator name (--generator-name / -g) is required.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
@@ -73,20 +77,34 @@ public class ConfigHelp implements Runnable {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
CodegenConfig config = CodegenConfigLoader.forName(generatorName);
|
CodegenConfig config = CodegenConfigLoader.forName(generatorName);
|
||||||
|
|
||||||
if (StringUtils.isEmpty(format) || "text".equalsIgnoreCase(format)) {
|
String desiredFormat = StringUtils.defaultIfBlank(format, FORMAT_TEXT);
|
||||||
generatePlainTextHelp(sb, config);
|
|
||||||
} else if ("markdown".equalsIgnoreCase(format)) {
|
switch (desiredFormat) {
|
||||||
generateMarkdownHelp(sb, config);
|
case FORMAT_MARKDOWN:
|
||||||
} else {
|
generateMarkdownHelp(sb, config);
|
||||||
LOGGER.warn("[warning] Unrecognized format option: %s.%n", format);
|
break;
|
||||||
|
case FORMAT_YAMLSAMPLE:
|
||||||
|
generateYamlSample(sb, config);
|
||||||
|
break;
|
||||||
|
case FORMAT_TEXT:
|
||||||
|
generatePlainTextHelp(sb, config);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LOGGER.warn("[warning] Unrecognized format option: {}", format);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!isEmpty(outputFile)) {
|
if (!isEmpty(outputFile)) {
|
||||||
File out = Paths.get(outputFile).toFile();
|
File out = Paths.get(outputFile).toFile();
|
||||||
//noinspection ResultOfMethodCallIgnored
|
//noinspection ResultOfMethodCallIgnored
|
||||||
out.getParentFile().mkdirs();
|
File parentFolder = out.getParentFile();
|
||||||
|
if (parentFolder != null && parentFolder.isDirectory()) {
|
||||||
|
parentFolder.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out), StandardCharsets.UTF_8))) {
|
try (Writer writer = new BufferedWriter(
|
||||||
|
new OutputStreamWriter(new FileOutputStream(out), StandardCharsets.UTF_8))) {
|
||||||
writer.write(sb.toString());
|
writer.write(sb.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -101,12 +119,41 @@ public class ConfigHelp implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void generateYamlSample(StringBuilder sb, CodegenConfig config) {
|
||||||
|
|
||||||
|
for (CliOption langCliOption : config.cliOptions()) {
|
||||||
|
|
||||||
|
sb.append("# Description: ").append(langCliOption.getDescription()).append(newline);
|
||||||
|
|
||||||
|
Map<String, String> enums = langCliOption.getEnum();
|
||||||
|
if (enums != null) {
|
||||||
|
sb.append("# Available Values:").append(newline);
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> entry : enums.entrySet()) {
|
||||||
|
sb.append("# ").append(entry.getKey()).append(newline);
|
||||||
|
sb.append("# ").append(entry.getValue()).append(newline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String defaultValue = langCliOption.getDefault();
|
||||||
|
|
||||||
|
if (defaultValue != null) {
|
||||||
|
sb.append(langCliOption.getOpt()).append(": ").append(defaultValue).append(newline);
|
||||||
|
} else {
|
||||||
|
sb.append("# ").append(langCliOption.getOpt()).append(": ").append(newline);
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(newline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void generateMarkdownHelp(StringBuilder sb, CodegenConfig config) {
|
private void generateMarkdownHelp(StringBuilder sb, CodegenConfig config) {
|
||||||
sb.append(newline);
|
sb.append(newline);
|
||||||
|
|
||||||
if (Boolean.TRUE.equals(markdownHeader)) {
|
if (Boolean.TRUE.equals(markdownHeader)) {
|
||||||
sb.append("---").append(newline);
|
sb.append("---").append(newline);
|
||||||
sb.append("id: generator-opts-").append(config.getTag().toValue()).append("-").append(config.getName()).append(newline);
|
sb.append("id: generator-opts-").append(config.getTag().toValue()).append("-")
|
||||||
|
.append(config.getName()).append(newline);
|
||||||
sb.append("title: Config Options for ").append(generatorName).append(newline);
|
sb.append("title: Config Options for ").append(generatorName).append(newline);
|
||||||
sb.append("sidebar_label: ").append(generatorName).append(newline);
|
sb.append("sidebar_label: ").append(generatorName).append(newline);
|
||||||
sb.append("---").append(newline);
|
sb.append("---").append(newline);
|
||||||
@@ -167,7 +214,8 @@ public class ConfigHelp implements Runnable {
|
|||||||
for (CliOption langCliOption : config.cliOptions()) {
|
for (CliOption langCliOption : config.cliOptions()) {
|
||||||
sb.append("\t").append(langCliOption.getOpt());
|
sb.append("\t").append(langCliOption.getOpt());
|
||||||
sb.append(newline);
|
sb.append(newline);
|
||||||
sb.append("\t ").append(langCliOption.getOptionHelp().replaceAll("\n", System.lineSeparator() + "\t "));
|
sb.append("\t ").append(langCliOption.getOptionHelp()
|
||||||
|
.replaceAll("\n", System.lineSeparator() + "\t "));
|
||||||
sb.append(newline);
|
sb.append(newline);
|
||||||
sb.append(newline);
|
sb.append(newline);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,6 +217,11 @@ public class Generate implements Runnable {
|
|||||||
@Option(name = {"--generate-alias-as-model"}, title = "generate alias (array, map) as model", description = CodegenConstants.GENERATE_ALIAS_AS_MODEL_DESC)
|
@Option(name = {"--generate-alias-as-model"}, title = "generate alias (array, map) as model", description = CodegenConstants.GENERATE_ALIAS_AS_MODEL_DESC)
|
||||||
private Boolean generateAliasAsModel;
|
private Boolean generateAliasAsModel;
|
||||||
|
|
||||||
|
@Option(name = {"--minimal-update"},
|
||||||
|
title = "Minimal update",
|
||||||
|
description = "Only write output files that have changed.")
|
||||||
|
private Boolean minimalUpdate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (logToStderr != null) {
|
if (logToStderr != null) {
|
||||||
@@ -346,6 +351,9 @@ public class Generate implements Runnable {
|
|||||||
if (generateAliasAsModel != null) {
|
if (generateAliasAsModel != null) {
|
||||||
configurator.setGenerateAliasAsModel(generateAliasAsModel);
|
configurator.setGenerateAliasAsModel(generateAliasAsModel);
|
||||||
}
|
}
|
||||||
|
if (minimalUpdate != null) {
|
||||||
|
configurator.setEnableMinimalUpdate(minimalUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
applySystemPropertiesKvpList(systemProperties, configurator);
|
applySystemPropertiesKvpList(systemProperties, configurator);
|
||||||
applyInstantiationTypesKvpList(instantiationTypes, configurator);
|
applyInstantiationTypesKvpList(instantiationTypes, configurator);
|
||||||
|
|||||||
@@ -0,0 +1,142 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>org.openapitools</groupId>
|
||||||
|
<artifactId>multi-parent</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>java-client</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>java-client</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<!-- activate the plugin -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.openapitools</groupId>
|
||||||
|
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||||
|
<version>4.0.0-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>sample-schema</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>generate</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<!-- specify the OpenAPI spec -->
|
||||||
|
<inputSpec>openapi.yaml</inputSpec>
|
||||||
|
|
||||||
|
<!-- target to generate java client code -->
|
||||||
|
<generatorName>java</generatorName>
|
||||||
|
|
||||||
|
<!-- hint: if you want to generate java server code, e.g. based on Spring Boot,
|
||||||
|
you can use the following target: <generatorName>spring</generatorName> -->
|
||||||
|
|
||||||
|
<!-- pass any necessary config options -->
|
||||||
|
<configOptions>
|
||||||
|
<dateLibrary>joda</dateLibrary>
|
||||||
|
</configOptions>
|
||||||
|
|
||||||
|
<!-- override the default library to jersey2 -->
|
||||||
|
<library>jersey2</library>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.7</source>
|
||||||
|
<target>1.7</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<!-- dependencies are needed for the client being generated -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-annotations</artifactId>
|
||||||
|
<version>${swagger-annotations-version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- You can find the dependencies for the library configuation you chose by looking in JavaClientCodegen.
|
||||||
|
Then find the corresponding dependency on Maven Central, and set the versions in the property section below -->
|
||||||
|
|
||||||
|
<!-- HTTP client: jersey-client -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.core</groupId>
|
||||||
|
<artifactId>jersey-client</artifactId>
|
||||||
|
<version>${jersey-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
|
<artifactId>jersey-media-multipart</artifactId>
|
||||||
|
<version>${jersey-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
|
<artifactId>jersey-media-json-jackson</artifactId>
|
||||||
|
<version>${jersey-version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JSON processing: jackson -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||||
|
<artifactId>jackson-jaxrs-base</artifactId>
|
||||||
|
<version>${jackson-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>${jackson-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-annotations</artifactId>
|
||||||
|
<version>${jackson-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>${jackson-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||||
|
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||||
|
<version>${jackson-version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Joda time: if you use it -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-joda</artifactId>
|
||||||
|
<version>${jackson-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>joda-time</groupId>
|
||||||
|
<artifactId>joda-time</artifactId>
|
||||||
|
<version>${jodatime-version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Base64 encoding that works in both JVM and Android -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.brsanthu</groupId>
|
||||||
|
<artifactId>migbase64</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.openapitools</groupId>
|
||||||
|
<artifactId>multi-parent</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>parent-project</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>sample-schema</module>
|
||||||
|
<module>java-client</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<swagger-annotations-version>1.5.8</swagger-annotations-version>
|
||||||
|
<jersey-version>2.27</jersey-version>
|
||||||
|
<jackson-version>2.8.9</jackson-version>
|
||||||
|
<jodatime-version>2.7</jodatime-version>
|
||||||
|
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||||
|
<junit-version>4.8.1</junit-version>
|
||||||
|
</properties>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>org.openapitools</groupId>
|
||||||
|
<artifactId>multi-parent</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.openapitools</groupId>
|
||||||
|
<artifactId>sample-schema</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>sample-schema</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,702 @@
|
|||||||
|
---
|
||||||
|
swagger: "2.0"
|
||||||
|
info:
|
||||||
|
description: "This is a sample server Petstore server. You can find out more about\
|
||||||
|
\ Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\
|
||||||
|
\ For this sample, you can use the api key `special-key` to test the authorization\
|
||||||
|
\ filters."
|
||||||
|
version: "1.0.0"
|
||||||
|
title: "Swagger Petstore"
|
||||||
|
termsOfService: "http://swagger.io/terms/"
|
||||||
|
contact:
|
||||||
|
email: "apiteam@swagger.io"
|
||||||
|
license:
|
||||||
|
name: "Apache 2.0"
|
||||||
|
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||||
|
host: "petstore.swagger.io"
|
||||||
|
basePath: "/v2"
|
||||||
|
tags:
|
||||||
|
- name: "pet"
|
||||||
|
description: "Everything about your Pets"
|
||||||
|
externalDocs:
|
||||||
|
description: "Find out more"
|
||||||
|
url: "http://swagger.io"
|
||||||
|
- name: "store"
|
||||||
|
description: "Access to Petstore orders"
|
||||||
|
- name: "user"
|
||||||
|
description: "Operations about user"
|
||||||
|
externalDocs:
|
||||||
|
description: "Find out more about our store"
|
||||||
|
url: "http://swagger.io"
|
||||||
|
schemes:
|
||||||
|
- "http"
|
||||||
|
paths:
|
||||||
|
/pet:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- "pet"
|
||||||
|
summary: "Add a new pet to the store"
|
||||||
|
description: ""
|
||||||
|
operationId: "addPet"
|
||||||
|
consumes:
|
||||||
|
- "application/json"
|
||||||
|
- "application/xml"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- in: "body"
|
||||||
|
name: "body"
|
||||||
|
description: "Pet object that needs to be added to the store"
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/Pet"
|
||||||
|
responses:
|
||||||
|
405:
|
||||||
|
description: "Invalid input"
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- "write:pets"
|
||||||
|
- "read:pets"
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- "pet"
|
||||||
|
summary: "Update an existing pet"
|
||||||
|
description: ""
|
||||||
|
operationId: "updatePet"
|
||||||
|
consumes:
|
||||||
|
- "application/json"
|
||||||
|
- "application/xml"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- in: "body"
|
||||||
|
name: "body"
|
||||||
|
description: "Pet object that needs to be added to the store"
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/Pet"
|
||||||
|
responses:
|
||||||
|
400:
|
||||||
|
description: "Invalid ID supplied"
|
||||||
|
404:
|
||||||
|
description: "Pet not found"
|
||||||
|
405:
|
||||||
|
description: "Validation exception"
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- "write:pets"
|
||||||
|
- "read:pets"
|
||||||
|
/pet/findByStatus:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- "pet"
|
||||||
|
summary: "Finds Pets by status"
|
||||||
|
description: "Multiple status values can be provided with comma separated strings"
|
||||||
|
operationId: "findPetsByStatus"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "status"
|
||||||
|
in: "query"
|
||||||
|
description: "Status values that need to be considered for filter"
|
||||||
|
required: true
|
||||||
|
type: "array"
|
||||||
|
items:
|
||||||
|
type: "string"
|
||||||
|
enum:
|
||||||
|
- "available"
|
||||||
|
- "pending"
|
||||||
|
- "sold"
|
||||||
|
default: "available"
|
||||||
|
collectionFormat: "csv"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "successful operation"
|
||||||
|
schema:
|
||||||
|
type: "array"
|
||||||
|
items:
|
||||||
|
$ref: "#/definitions/Pet"
|
||||||
|
400:
|
||||||
|
description: "Invalid status value"
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- "write:pets"
|
||||||
|
- "read:pets"
|
||||||
|
/pet/findByTags:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- "pet"
|
||||||
|
summary: "Finds Pets by tags"
|
||||||
|
description: "Multiple tags can be provided with comma separated strings. Use\
|
||||||
|
\ tag1, tag2, tag3 for testing."
|
||||||
|
operationId: "findPetsByTags"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "tags"
|
||||||
|
in: "query"
|
||||||
|
description: "Tags to filter by"
|
||||||
|
required: true
|
||||||
|
type: "array"
|
||||||
|
items:
|
||||||
|
type: "string"
|
||||||
|
collectionFormat: "csv"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "successful operation"
|
||||||
|
schema:
|
||||||
|
type: "array"
|
||||||
|
items:
|
||||||
|
$ref: "#/definitions/Pet"
|
||||||
|
400:
|
||||||
|
description: "Invalid tag value"
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- "write:pets"
|
||||||
|
- "read:pets"
|
||||||
|
/pet/{petId}:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- "pet"
|
||||||
|
summary: "Find pet by ID"
|
||||||
|
description: "Returns a single pet"
|
||||||
|
operationId: "getPetById"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "petId"
|
||||||
|
in: "path"
|
||||||
|
description: "ID of pet to return"
|
||||||
|
required: true
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "successful operation"
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/Pet"
|
||||||
|
400:
|
||||||
|
description: "Invalid ID supplied"
|
||||||
|
404:
|
||||||
|
description: "Pet not found"
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- "pet"
|
||||||
|
summary: "Updates a pet in the store with form data"
|
||||||
|
description: ""
|
||||||
|
operationId: "updatePetWithForm"
|
||||||
|
consumes:
|
||||||
|
- "application/x-www-form-urlencoded"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "petId"
|
||||||
|
in: "path"
|
||||||
|
description: "ID of pet that needs to be updated"
|
||||||
|
required: true
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
- name: "name"
|
||||||
|
in: "formData"
|
||||||
|
description: "Updated name of the pet"
|
||||||
|
required: false
|
||||||
|
type: "string"
|
||||||
|
- name: "status"
|
||||||
|
in: "formData"
|
||||||
|
description: "Updated status of the pet"
|
||||||
|
required: false
|
||||||
|
type: "string"
|
||||||
|
responses:
|
||||||
|
405:
|
||||||
|
description: "Invalid input"
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- "write:pets"
|
||||||
|
- "read:pets"
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- "pet"
|
||||||
|
summary: "Deletes a pet"
|
||||||
|
description: ""
|
||||||
|
operationId: "deletePet"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "api_key"
|
||||||
|
in: "header"
|
||||||
|
required: false
|
||||||
|
type: "string"
|
||||||
|
- name: "petId"
|
||||||
|
in: "path"
|
||||||
|
description: "Pet id to delete"
|
||||||
|
required: true
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
responses:
|
||||||
|
400:
|
||||||
|
description: "Invalid pet value"
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- "write:pets"
|
||||||
|
- "read:pets"
|
||||||
|
/pet/{petId}/uploadImage:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- "pet"
|
||||||
|
summary: "uploads an image"
|
||||||
|
description: ""
|
||||||
|
operationId: "uploadFile"
|
||||||
|
consumes:
|
||||||
|
- "multipart/form-data"
|
||||||
|
produces:
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "petId"
|
||||||
|
in: "path"
|
||||||
|
description: "ID of pet to update"
|
||||||
|
required: true
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
- name: "additionalMetadata"
|
||||||
|
in: "formData"
|
||||||
|
description: "Additional data to pass to server"
|
||||||
|
required: false
|
||||||
|
type: "string"
|
||||||
|
- name: "file"
|
||||||
|
in: "formData"
|
||||||
|
description: "file to upload"
|
||||||
|
required: false
|
||||||
|
type: "file"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "successful operation"
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/ApiResponse"
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- "write:pets"
|
||||||
|
- "read:pets"
|
||||||
|
/store/inventory:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- "store"
|
||||||
|
summary: "Returns pet inventories by status"
|
||||||
|
description: "Returns a map of status codes to quantities"
|
||||||
|
operationId: "getInventory"
|
||||||
|
produces:
|
||||||
|
- "application/json"
|
||||||
|
parameters: []
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "successful operation"
|
||||||
|
schema:
|
||||||
|
type: "object"
|
||||||
|
additionalProperties:
|
||||||
|
type: "integer"
|
||||||
|
format: "int32"
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
/store/order:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- "store"
|
||||||
|
summary: "Place an order for a pet"
|
||||||
|
description: ""
|
||||||
|
operationId: "placeOrder"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- in: "body"
|
||||||
|
name: "body"
|
||||||
|
description: "order placed for purchasing the pet"
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/Order"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "successful operation"
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/Order"
|
||||||
|
400:
|
||||||
|
description: "Invalid Order"
|
||||||
|
/store/order/{orderId}:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- "store"
|
||||||
|
summary: "Find purchase order by ID"
|
||||||
|
description: "For valid response try integer IDs with value <= 5 or > 10. Other\
|
||||||
|
\ values will generated exceptions"
|
||||||
|
operationId: "getOrderById"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "orderId"
|
||||||
|
in: "path"
|
||||||
|
description: "ID of pet that needs to be fetched"
|
||||||
|
required: true
|
||||||
|
type: "integer"
|
||||||
|
maximum: 5.0
|
||||||
|
minimum: 1.0
|
||||||
|
format: "int64"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "successful operation"
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/Order"
|
||||||
|
400:
|
||||||
|
description: "Invalid ID supplied"
|
||||||
|
404:
|
||||||
|
description: "Order not found"
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- "store"
|
||||||
|
summary: "Delete purchase order by ID"
|
||||||
|
description: "For valid response try integer IDs with value < 1000. Anything\
|
||||||
|
\ above 1000 or nonintegers will generate API errors"
|
||||||
|
operationId: "deleteOrder"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "orderId"
|
||||||
|
in: "path"
|
||||||
|
description: "ID of the order that needs to be deleted"
|
||||||
|
required: true
|
||||||
|
type: "string"
|
||||||
|
minimum: 1.0
|
||||||
|
responses:
|
||||||
|
400:
|
||||||
|
description: "Invalid ID supplied"
|
||||||
|
404:
|
||||||
|
description: "Order not found"
|
||||||
|
/user:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- "user"
|
||||||
|
summary: "Create user"
|
||||||
|
description: "This can only be done by the logged in user."
|
||||||
|
operationId: "createUser"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- in: "body"
|
||||||
|
name: "body"
|
||||||
|
description: "Created user object"
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/User"
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: "successful operation"
|
||||||
|
/user/createWithArray:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- "user"
|
||||||
|
summary: "Creates list of users with given input array"
|
||||||
|
description: ""
|
||||||
|
operationId: "createUsersWithArrayInput"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- in: "body"
|
||||||
|
name: "body"
|
||||||
|
description: "List of user object"
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: "array"
|
||||||
|
items:
|
||||||
|
$ref: "#/definitions/User"
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: "successful operation"
|
||||||
|
/user/createWithList:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- "user"
|
||||||
|
summary: "Creates list of users with given input array"
|
||||||
|
description: ""
|
||||||
|
operationId: "createUsersWithListInput"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- in: "body"
|
||||||
|
name: "body"
|
||||||
|
description: "List of user object"
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: "array"
|
||||||
|
items:
|
||||||
|
$ref: "#/definitions/User"
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: "successful operation"
|
||||||
|
/user/login:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- "user"
|
||||||
|
summary: "Logs user into the system"
|
||||||
|
description: ""
|
||||||
|
operationId: "loginUser"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "username"
|
||||||
|
in: "query"
|
||||||
|
description: "The user name for login"
|
||||||
|
required: true
|
||||||
|
type: "string"
|
||||||
|
- name: "password"
|
||||||
|
in: "query"
|
||||||
|
description: "The password for login in clear text"
|
||||||
|
required: true
|
||||||
|
type: "string"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "successful operation"
|
||||||
|
schema:
|
||||||
|
type: "string"
|
||||||
|
headers:
|
||||||
|
X-Rate-Limit:
|
||||||
|
type: "integer"
|
||||||
|
format: "int32"
|
||||||
|
description: "calls per hour allowed by the user"
|
||||||
|
X-Expires-After:
|
||||||
|
type: "string"
|
||||||
|
format: "date-time"
|
||||||
|
description: "date in UTC when toekn expires"
|
||||||
|
400:
|
||||||
|
description: "Invalid username/password supplied"
|
||||||
|
/user/logout:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- "user"
|
||||||
|
summary: "Logs out current logged in user session"
|
||||||
|
description: ""
|
||||||
|
operationId: "logoutUser"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters: []
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: "successful operation"
|
||||||
|
/user/{username}:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- "user"
|
||||||
|
summary: "Get user by user name"
|
||||||
|
description: ""
|
||||||
|
operationId: "getUserByName"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "username"
|
||||||
|
in: "path"
|
||||||
|
description: "The name that needs to be fetched. Use user1 for testing. "
|
||||||
|
required: true
|
||||||
|
type: "string"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "successful operation"
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/User"
|
||||||
|
400:
|
||||||
|
description: "Invalid username supplied"
|
||||||
|
404:
|
||||||
|
description: "User not found"
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- "user"
|
||||||
|
summary: "Updated user"
|
||||||
|
description: "This can only be done by the logged in user."
|
||||||
|
operationId: "updateUser"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "username"
|
||||||
|
in: "path"
|
||||||
|
description: "name that need to be deleted"
|
||||||
|
required: true
|
||||||
|
type: "string"
|
||||||
|
- in: "body"
|
||||||
|
name: "body"
|
||||||
|
description: "Updated user object"
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/User"
|
||||||
|
responses:
|
||||||
|
400:
|
||||||
|
description: "Invalid user supplied"
|
||||||
|
404:
|
||||||
|
description: "User not found"
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- "user"
|
||||||
|
summary: "Delete user"
|
||||||
|
description: "This can only be done by the logged in user."
|
||||||
|
operationId: "deleteUser"
|
||||||
|
produces:
|
||||||
|
- "application/xml"
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- name: "username"
|
||||||
|
in: "path"
|
||||||
|
description: "The name that needs to be deleted"
|
||||||
|
required: true
|
||||||
|
type: "string"
|
||||||
|
responses:
|
||||||
|
400:
|
||||||
|
description: "Invalid username supplied"
|
||||||
|
404:
|
||||||
|
description: "User not found"
|
||||||
|
securityDefinitions:
|
||||||
|
petstore_auth:
|
||||||
|
type: "oauth2"
|
||||||
|
authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog"
|
||||||
|
flow: "implicit"
|
||||||
|
scopes:
|
||||||
|
write:pets: "modify pets in your account"
|
||||||
|
read:pets: "read your pets"
|
||||||
|
api_key:
|
||||||
|
type: "apiKey"
|
||||||
|
name: "api_key"
|
||||||
|
in: "header"
|
||||||
|
definitions:
|
||||||
|
Order:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
petId:
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
quantity:
|
||||||
|
type: "integer"
|
||||||
|
format: "int32"
|
||||||
|
shipDate:
|
||||||
|
type: "string"
|
||||||
|
format: "date-time"
|
||||||
|
status:
|
||||||
|
type: "string"
|
||||||
|
description: "Order Status"
|
||||||
|
enum:
|
||||||
|
- "placed"
|
||||||
|
- "approved"
|
||||||
|
- "delivered"
|
||||||
|
complete:
|
||||||
|
type: "boolean"
|
||||||
|
default: false
|
||||||
|
xml:
|
||||||
|
name: "Order"
|
||||||
|
Category:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
name:
|
||||||
|
type: "string"
|
||||||
|
xml:
|
||||||
|
name: "Category"
|
||||||
|
User:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
username:
|
||||||
|
type: "string"
|
||||||
|
firstName:
|
||||||
|
type: "string"
|
||||||
|
lastName:
|
||||||
|
type: "string"
|
||||||
|
email:
|
||||||
|
type: "string"
|
||||||
|
password:
|
||||||
|
type: "string"
|
||||||
|
phone:
|
||||||
|
type: "string"
|
||||||
|
userStatus:
|
||||||
|
type: "integer"
|
||||||
|
format: "int32"
|
||||||
|
description: "User Status"
|
||||||
|
xml:
|
||||||
|
name: "User"
|
||||||
|
Tag:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
name:
|
||||||
|
type: "string"
|
||||||
|
xml:
|
||||||
|
name: "Tag"
|
||||||
|
Pet:
|
||||||
|
type: "object"
|
||||||
|
required:
|
||||||
|
- "name"
|
||||||
|
- "photoUrls"
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
category:
|
||||||
|
$ref: "#/definitions/Category"
|
||||||
|
name:
|
||||||
|
type: "string"
|
||||||
|
example: "doggie"
|
||||||
|
photoUrls:
|
||||||
|
type: "array"
|
||||||
|
xml:
|
||||||
|
name: "photoUrl"
|
||||||
|
wrapped: true
|
||||||
|
items:
|
||||||
|
type: "string"
|
||||||
|
tags:
|
||||||
|
type: "array"
|
||||||
|
xml:
|
||||||
|
name: "tag"
|
||||||
|
wrapped: true
|
||||||
|
items:
|
||||||
|
$ref: "#/definitions/Tag"
|
||||||
|
status:
|
||||||
|
type: "string"
|
||||||
|
description: "pet status in the store"
|
||||||
|
enum:
|
||||||
|
- "available"
|
||||||
|
- "pending"
|
||||||
|
- "sold"
|
||||||
|
xml:
|
||||||
|
name: "Pet"
|
||||||
|
ApiResponse:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
code:
|
||||||
|
type: "integer"
|
||||||
|
format: "int32"
|
||||||
|
type:
|
||||||
|
type: "string"
|
||||||
|
message:
|
||||||
|
type: "string"
|
||||||
|
externalDocs:
|
||||||
|
description: "Find out more about Swagger"
|
||||||
|
url: "http://swagger.io"
|
||||||
@@ -37,6 +37,9 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteSource;
|
||||||
|
import com.google.common.io.CharSource;
|
||||||
|
import io.swagger.v3.parser.util.ClasspathHelper;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
@@ -163,6 +166,12 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
@Parameter(name = "invokerPackage")
|
@Parameter(name = "invokerPackage")
|
||||||
private String invokerPackage;
|
private String invokerPackage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default package to use for the generated objects
|
||||||
|
*/
|
||||||
|
@Parameter(name = "packageName")
|
||||||
|
private String packageName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* groupId in generated pom.xml
|
* groupId in generated pom.xml
|
||||||
*/
|
*/
|
||||||
@@ -507,6 +516,10 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
configurator.setInvokerPackage(invokerPackage);
|
configurator.setInvokerPackage(invokerPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(packageName)) {
|
||||||
|
configurator.setPackageName(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
if (isNotEmpty(groupId)) {
|
if (isNotEmpty(groupId)) {
|
||||||
configurator.setGroupId(groupId);
|
configurator.setGroupId(groupId);
|
||||||
}
|
}
|
||||||
@@ -672,7 +685,12 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
|
|
||||||
// Store a checksum of the input spec
|
// Store a checksum of the input spec
|
||||||
File storedInputSpecHashFile = getHashFile(inputSpecFile);
|
File storedInputSpecHashFile = getHashFile(inputSpecFile);
|
||||||
String inputSpecHash = Files.asByteSource(inputSpecFile).hash(Hashing.sha256()).toString();
|
ByteSource inputSpecByteSource =
|
||||||
|
inputSpecFile.exists()
|
||||||
|
? Files.asByteSource(inputSpecFile)
|
||||||
|
: CharSource.wrap(ClasspathHelper.loadFileFromClasspath(inputSpecFile.toString().replaceAll("\\\\","/")))
|
||||||
|
.asByteSource(Charsets.UTF_8);
|
||||||
|
String inputSpecHash =inputSpecByteSource.hash(Hashing.sha256()).toString();
|
||||||
|
|
||||||
if (storedInputSpecHashFile.getParent() != null && !new File(storedInputSpecHashFile.getParent()).exists()) {
|
if (storedInputSpecHashFile.getParent() != null && !new File(storedInputSpecHashFile.getParent()).exists()) {
|
||||||
File parent = new File(storedInputSpecHashFile.getParent());
|
File parent = new File(storedInputSpecHashFile.getParent());
|
||||||
|
|||||||
@@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen;
|
package org.openapitools.codegen;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.Arrays;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -28,23 +32,78 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public abstract class AbstractGenerator {
|
public abstract class AbstractGenerator {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGenerator.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGenerator.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the minimal-file-update option enabled?
|
||||||
|
*
|
||||||
|
* @return Option value
|
||||||
|
*/
|
||||||
|
public abstract boolean getEnableMinimalUpdate();
|
||||||
|
|
||||||
@SuppressWarnings("static-method")
|
/**
|
||||||
|
* Write String to a file, formatting as UTF-8
|
||||||
|
*
|
||||||
|
* @param filename The name of file to write
|
||||||
|
* @param contents The contents string.
|
||||||
|
* @return File representing the written file.
|
||||||
|
* @throws IOException If file cannot be written.
|
||||||
|
*/
|
||||||
public File writeToFile(String filename, String contents) throws IOException {
|
public File writeToFile(String filename, String contents) throws IOException {
|
||||||
LOGGER.info("writing file " + filename);
|
return writeToFile(filename, contents.getBytes(Charset.forName("UTF-8")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write bytes to a file
|
||||||
|
*
|
||||||
|
* @param filename The name of file to write
|
||||||
|
* @param contents The contents bytes. Typically this is a UTF-8 formatted string.
|
||||||
|
* @return File representing the written file.
|
||||||
|
* @throws IOException If file cannot be written.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("static-method")
|
||||||
|
public File writeToFile(String filename, byte contents[]) throws IOException {
|
||||||
|
if (getEnableMinimalUpdate()) {
|
||||||
|
String tempFilename = filename + ".tmp";
|
||||||
|
// Use Paths.get here to normalize path (for Windows file separator, space escaping on Linux/Mac, etc)
|
||||||
|
File outputFile = Paths.get(filename).toFile();
|
||||||
|
File tempFile = null;
|
||||||
|
try {
|
||||||
|
tempFile = writeToFileRaw(tempFilename, contents);
|
||||||
|
if (!filesEqual(tempFile, outputFile)) {
|
||||||
|
LOGGER.info("writing file " + filename);
|
||||||
|
Files.move(tempFile.toPath(), outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
tempFile = null;
|
||||||
|
} else {
|
||||||
|
LOGGER.info("skipping unchanged file " + filename);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (tempFile != null && tempFile.exists()) {
|
||||||
|
try {
|
||||||
|
tempFile.delete();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOGGER.error("Error removing temporary file " + tempFile, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outputFile;
|
||||||
|
} else {
|
||||||
|
LOGGER.info("writing file " + filename);
|
||||||
|
return writeToFileRaw(filename, contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean filesEqual(File file1, File file2) throws IOException {
|
||||||
|
return file1.exists() && file2.exists() && Arrays.equals(Files.readAllBytes(file1.toPath()), Files.readAllBytes(file2.toPath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private File writeToFileRaw(String filename, byte[] contents) throws IOException {
|
||||||
// Use Paths.get here to normalize path (for Windows file separator, space escaping on Linux/Mac, etc)
|
// Use Paths.get here to normalize path (for Windows file separator, space escaping on Linux/Mac, etc)
|
||||||
File output = Paths.get(filename).toFile();
|
File output = Paths.get(filename).toFile();
|
||||||
|
|
||||||
if (output.getParent() != null && !new File(output.getParent()).exists()) {
|
if (output.getParent() != null && !new File(output.getParent()).exists()) {
|
||||||
File parent = new File(output.getParent());
|
File parent = Paths.get(output.getParent()).toFile();
|
||||||
parent.mkdirs();
|
parent.mkdirs();
|
||||||
}
|
}
|
||||||
|
Files.write(output.toPath(), contents);
|
||||||
try (Writer out = new BufferedWriter(new OutputStreamWriter(
|
|
||||||
new FileOutputStream(output), "UTF-8"))) {
|
|
||||||
out.write(contents);
|
|
||||||
}
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -260,4 +260,8 @@ public interface CodegenConfig {
|
|||||||
*/
|
*/
|
||||||
void setOpenAPI(OpenAPI openAPI);
|
void setOpenAPI(OpenAPI openAPI);
|
||||||
|
|
||||||
|
public boolean isEnableMinimalUpdate();
|
||||||
|
|
||||||
|
public void setEnableMinimalUpdate(boolean isEnableMinimalUpdate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ package org.openapitools.codegen;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class CodegenProperty implements Cloneable {
|
public class CodegenProperty implements Cloneable {
|
||||||
public String baseName, complexType, getter, setter, description, dataType,
|
public String openApiType, baseName, complexType, getter, setter, description, dataType,
|
||||||
datatypeWithEnum, dataFormat, name, min, max, defaultValue, defaultValueWithParam,
|
datatypeWithEnum, dataFormat, name, min, max, defaultValue, defaultValueWithParam,
|
||||||
baseType, containerType, title;
|
baseType, containerType, title;
|
||||||
|
|
||||||
@@ -415,6 +415,7 @@ public class CodegenProperty implements Cloneable {
|
|||||||
return Objects.hash(
|
return Objects.hash(
|
||||||
_enum,
|
_enum,
|
||||||
allowableValues,
|
allowableValues,
|
||||||
|
openApiType,
|
||||||
baseName,
|
baseName,
|
||||||
baseType,
|
baseType,
|
||||||
complexType,
|
complexType,
|
||||||
@@ -501,6 +502,7 @@ public class CodegenProperty implements Cloneable {
|
|||||||
final CodegenProperty other = (CodegenProperty) obj;
|
final CodegenProperty other = (CodegenProperty) obj;
|
||||||
|
|
||||||
return Objects.equals(baseName, other.baseName) &&
|
return Objects.equals(baseName, other.baseName) &&
|
||||||
|
Objects.equals(openApiType, other.openApiType) &&
|
||||||
Objects.equals(complexType, other.complexType) &&
|
Objects.equals(complexType, other.complexType) &&
|
||||||
Objects.equals(getter, other.getter) &&
|
Objects.equals(getter, other.getter) &&
|
||||||
Objects.equals(setter, other.setter) &&
|
Objects.equals(setter, other.setter) &&
|
||||||
@@ -600,6 +602,7 @@ public class CodegenProperty implements Cloneable {
|
|||||||
public java.lang.String toString() {
|
public java.lang.String toString() {
|
||||||
return "CodegenProperty{" +
|
return "CodegenProperty{" +
|
||||||
"baseName='" + baseName + '\'' +
|
"baseName='" + baseName + '\'' +
|
||||||
|
", openApiType='" + openApiType + '\'' +
|
||||||
", complexType='" + complexType + '\'' +
|
", complexType='" + complexType + '\'' +
|
||||||
", getter='" + getter + '\'' +
|
", getter='" + getter + '\'' +
|
||||||
", setter='" + setter + '\'' +
|
", setter='" + setter + '\'' +
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
protected String ignoreFilePathOverride;
|
protected String ignoreFilePathOverride;
|
||||||
// flag to indicate whether to use environment variable to post process file
|
// flag to indicate whether to use environment variable to post process file
|
||||||
protected boolean enablePostProcessFile = false;
|
protected boolean enablePostProcessFile = false;
|
||||||
|
// flag to indicate whether to only update files whose contents have changed
|
||||||
|
protected boolean enableMinimalUpdate = false;
|
||||||
|
|
||||||
// make openapi available to all methods
|
// make openapi available to all methods
|
||||||
protected OpenAPI openAPI;
|
protected OpenAPI openAPI;
|
||||||
@@ -778,7 +780,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
* @return the file name of the model
|
* @return the file name of the model
|
||||||
*/
|
*/
|
||||||
public String toModelFilename(String name) {
|
public String toModelFilename(String name) {
|
||||||
return initialCaps(name);
|
return camelize(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -788,7 +790,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
* @return the file name of the model
|
* @return the file name of the model
|
||||||
*/
|
*/
|
||||||
public String toModelTestFilename(String name) {
|
public String toModelTestFilename(String name) {
|
||||||
return initialCaps(name) + "Test";
|
return camelize(name) + "Test";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -798,7 +800,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
* @return the file name of the model
|
* @return the file name of the model
|
||||||
*/
|
*/
|
||||||
public String toModelDocFilename(String name) {
|
public String toModelDocFilename(String name) {
|
||||||
return initialCaps(name);
|
return camelize(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1474,17 +1476,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
return (name.length() > 0) ? (Character.toLowerCase(name.charAt(0)) + name.substring(1)) : "";
|
return (name.length() > 0) ? (Character.toLowerCase(name.charAt(0)) + name.substring(1)) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Capitalize the string. Please use org.openapitools.codegen.utils.StringUtils.camelize instead as this method will be deprecated.
|
|
||||||
*
|
|
||||||
* @param name string to be capitalized
|
|
||||||
* @return capitalized string
|
|
||||||
* @deprecated use {@link org.openapitools.codegen.utils.StringUtils#camelize(String)} instead
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("static-method")
|
|
||||||
public String initialCaps(String name) {
|
|
||||||
return camelize(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output the type declaration of a given name
|
* Output the type declaration of a given name
|
||||||
@@ -1574,7 +1565,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return "DefaultApi";
|
return "DefaultApi";
|
||||||
}
|
}
|
||||||
return initialCaps(name) + "Api";
|
return camelize(name) + "Api";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1585,7 +1576,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
* @return capitalized model name
|
* @return capitalized model name
|
||||||
*/
|
*/
|
||||||
public String toModelName(final String name) {
|
public String toModelName(final String name) {
|
||||||
return initialCaps(modelNamePrefix + "_" + name + "_" + modelNameSuffix);
|
return camelize(modelNamePrefix + "_" + name + "_" + modelNameSuffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1898,6 +1889,11 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
|
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
|
||||||
property.name = toVarName(name);
|
property.name = toVarName(name);
|
||||||
property.baseName = name;
|
property.baseName = name;
|
||||||
|
if (p.getType() == null) {
|
||||||
|
property.openApiType = getSchemaType(p);
|
||||||
|
} else {
|
||||||
|
property.openApiType = p.getType();
|
||||||
|
}
|
||||||
property.nameInCamelCase = camelize(property.name, false);
|
property.nameInCamelCase = camelize(property.name, false);
|
||||||
property.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, property.nameInCamelCase);
|
property.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, property.nameInCamelCase);
|
||||||
property.description = escapeText(p.getDescription());
|
property.description = escapeText(p.getDescription());
|
||||||
@@ -3257,7 +3253,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
if (builder.toString().length() == 0) {
|
if (builder.toString().length() == 0) {
|
||||||
part = Character.toLowerCase(part.charAt(0)) + part.substring(1);
|
part = Character.toLowerCase(part.charAt(0)) + part.substring(1);
|
||||||
} else {
|
} else {
|
||||||
part = initialCaps(part);
|
part = camelize(part);
|
||||||
}
|
}
|
||||||
builder.append(part);
|
builder.append(part);
|
||||||
}
|
}
|
||||||
@@ -3854,6 +3850,11 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
// input name and age => input_name_and_age
|
// input name and age => input_name_and_age
|
||||||
name = name.replaceAll(" ", "_");
|
name = name.replaceAll(" ", "_");
|
||||||
|
|
||||||
|
// /api/films/get => _api_films_get
|
||||||
|
// \api\films\get => _api_films_get
|
||||||
|
name = name.replaceAll("/", "_");
|
||||||
|
name = name.replaceAll("\\\\", "_");
|
||||||
|
|
||||||
// remove everything else other than word, number and _
|
// remove everything else other than word, number and _
|
||||||
// $php_variable => php_variable
|
// $php_variable => php_variable
|
||||||
if (allowUnicodeIdentifiers) { //could be converted to a single line with ?: operator
|
if (allowUnicodeIdentifiers) { //could be converted to a single line with ?: operator
|
||||||
@@ -4834,4 +4835,22 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
this.enablePostProcessFile = enablePostProcessFile;
|
this.enablePostProcessFile = enablePostProcessFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the boolean value indicating the state of the option for updating only changed files
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isEnableMinimalUpdate() {
|
||||||
|
return enableMinimalUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the boolean value indicating the state of the option for updating only changed files
|
||||||
|
*
|
||||||
|
* @param enableMinimalUpdate true to enable minimal update
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setEnableMinimalUpdate(boolean enableMinimalUpdate) {
|
||||||
|
this.enableMinimalUpdate = enableMinimalUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
private String contextPath;
|
private String contextPath;
|
||||||
private Map<String, String> generatorPropertyDefaults = new HashMap<>();
|
private Map<String, String> generatorPropertyDefaults = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getEnableMinimalUpdate() {
|
||||||
|
return config.isEnableMinimalUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Generator opts(ClientOptInput opts) {
|
public Generator opts(ClientOptInput opts) {
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
@@ -797,16 +802,13 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected File writeInputStreamToFile(String filename, InputStream in, String templateFile) throws FileNotFoundException, IOException {
|
protected File writeInputStreamToFile(String filename, InputStream in, String templateFile) throws FileNotFoundException, IOException {
|
||||||
File outputFile = java.nio.file.Paths.get(filename).toFile();
|
|
||||||
if (in != null) {
|
if (in != null) {
|
||||||
OutputStream out = new FileOutputStream(outputFile, false);
|
byte bytes[] = IOUtils.toByteArray(in);
|
||||||
LOGGER.info("writing file " + outputFile);
|
return writeToFile(filename, bytes);
|
||||||
IOUtils.copy(in, out);
|
|
||||||
out.close();
|
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("can't open '" + templateFile + "' for input; cannot write '" + filename + "'");
|
LOGGER.error("can't open '" + templateFile + "' for input; cannot write '" + filename + "'");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return outputFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> buildSupportFileBundle(List<Object> allOperations, List<Object> allModels) {
|
private Map<String, Object> buildSupportFileBundle(List<Object> allOperations, List<Object> allModels) {
|
||||||
|
|||||||
@@ -101,11 +101,13 @@ public class CodegenConfigurator implements Serializable {
|
|||||||
private boolean logToStderr;
|
private boolean logToStderr;
|
||||||
private boolean validateSpec;
|
private boolean validateSpec;
|
||||||
private boolean enablePostProcessFile;
|
private boolean enablePostProcessFile;
|
||||||
|
private boolean enableMinimalUpdate;
|
||||||
private String templateDir;
|
private String templateDir;
|
||||||
private String auth;
|
private String auth;
|
||||||
private String apiPackage;
|
private String apiPackage;
|
||||||
private String modelPackage;
|
private String modelPackage;
|
||||||
private String invokerPackage;
|
private String invokerPackage;
|
||||||
|
private String packageName;
|
||||||
private String modelNamePrefix;
|
private String modelNamePrefix;
|
||||||
private String modelNameSuffix;
|
private String modelNameSuffix;
|
||||||
private String groupId;
|
private String groupId;
|
||||||
@@ -239,6 +241,15 @@ public class CodegenConfigurator implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getEnableMinimalUpdate() {
|
||||||
|
return enableMinimalUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CodegenConfigurator setEnableMinimalUpdate(boolean enableMinimalUpdate) {
|
||||||
|
this.enableMinimalUpdate = enableMinimalUpdate;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isGenerateAliasAsModel() {
|
public boolean isGenerateAliasAsModel() {
|
||||||
return ModelUtils.isGenerateAliasAsModel();
|
return ModelUtils.isGenerateAliasAsModel();
|
||||||
}
|
}
|
||||||
@@ -349,6 +360,15 @@ public class CodegenConfigurator implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPackageName() {
|
||||||
|
return packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CodegenConfigurator setPackageName(String packageName) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public String getGroupId() {
|
public String getGroupId() {
|
||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
@@ -545,6 +565,7 @@ public class CodegenConfigurator implements Serializable {
|
|||||||
config.setIgnoreFilePathOverride(ignoreFileOverride);
|
config.setIgnoreFilePathOverride(ignoreFileOverride);
|
||||||
config.setRemoveOperationIdPrefix(removeOperationIdPrefix);
|
config.setRemoveOperationIdPrefix(removeOperationIdPrefix);
|
||||||
config.setEnablePostProcessFile(enablePostProcessFile);
|
config.setEnablePostProcessFile(enablePostProcessFile);
|
||||||
|
config.setEnableMinimalUpdate(enableMinimalUpdate);
|
||||||
|
|
||||||
config.instantiationTypes().putAll(instantiationTypes);
|
config.instantiationTypes().putAll(instantiationTypes);
|
||||||
config.typeMapping().putAll(typeMappings);
|
config.typeMapping().putAll(typeMappings);
|
||||||
@@ -555,6 +576,7 @@ public class CodegenConfigurator implements Serializable {
|
|||||||
checkAndSetAdditionalProperty(apiPackage, CodegenConstants.API_PACKAGE);
|
checkAndSetAdditionalProperty(apiPackage, CodegenConstants.API_PACKAGE);
|
||||||
checkAndSetAdditionalProperty(modelPackage, CodegenConstants.MODEL_PACKAGE);
|
checkAndSetAdditionalProperty(modelPackage, CodegenConstants.MODEL_PACKAGE);
|
||||||
checkAndSetAdditionalProperty(invokerPackage, CodegenConstants.INVOKER_PACKAGE);
|
checkAndSetAdditionalProperty(invokerPackage, CodegenConstants.INVOKER_PACKAGE);
|
||||||
|
checkAndSetAdditionalProperty(packageName, CodegenConstants.PACKAGE_NAME);
|
||||||
checkAndSetAdditionalProperty(groupId, CodegenConstants.GROUP_ID);
|
checkAndSetAdditionalProperty(groupId, CodegenConstants.GROUP_ID);
|
||||||
checkAndSetAdditionalProperty(artifactId, CodegenConstants.ARTIFACT_ID);
|
checkAndSetAdditionalProperty(artifactId, CodegenConstants.ARTIFACT_ID);
|
||||||
checkAndSetAdditionalProperty(artifactVersion, CodegenConstants.ARTIFACT_VERSION);
|
checkAndSetAdditionalProperty(artifactVersion, CodegenConstants.ARTIFACT_VERSION);
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
cliOptions.clear();
|
cliOptions.clear();
|
||||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).")
|
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).")
|
||||||
.defaultValue("openapi"));
|
.defaultValue("openapi"));
|
||||||
|
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Go package version.")
|
||||||
|
.defaultValue("1.0.0"));
|
||||||
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
|
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
|
||||||
.defaultValue(Boolean.TRUE.toString()));
|
.defaultValue(Boolean.TRUE.toString()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(CodegenConstants.PARCELIZE_MODELS)) {
|
if (additionalProperties.containsKey(CodegenConstants.PARCELIZE_MODELS)) {
|
||||||
this.setParcelizeModels(Boolean.valueOf((String)additionalProperties.get(CodegenConstants.PARCELIZE_MODELS)));
|
this.setParcelizeModels(Boolean.valueOf((String) additionalProperties.get(CodegenConstants.PARCELIZE_MODELS)));
|
||||||
LOGGER.info(CodegenConstants.PARCELIZE_MODELS + " depends on the android framework and " +
|
LOGGER.info(CodegenConstants.PARCELIZE_MODELS + " depends on the android framework and " +
|
||||||
"experimental parcelize feature. Make sure your build applies the android plugin:\n" +
|
"experimental parcelize feature. Make sure your build applies the android plugin:\n" +
|
||||||
"apply plugin: 'com.android.library' OR apply plugin: 'com.android.application'.\n" +
|
"apply plugin: 'com.android.library' OR apply plugin: 'com.android.application'.\n" +
|
||||||
@@ -597,10 +597,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
private String sanitizeKotlinSpecificNames(final String name) {
|
private String sanitizeKotlinSpecificNames(final String name) {
|
||||||
String word = name;
|
String word = name;
|
||||||
for (Map.Entry<String, String> specialCharacters : specialCharReplacements.entrySet()) {
|
for (Map.Entry<String, String> specialCharacters : specialCharReplacements.entrySet()) {
|
||||||
// Underscore is the only special character we'll allow
|
word = replaceSpecialCharacters(word, specialCharacters);
|
||||||
if (!specialCharacters.getKey().equals("_")) {
|
|
||||||
word = word.replaceAll("\\Q" + specialCharacters.getKey() + "\\E", specialCharacters.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback, replace unknowns with underscore.
|
// Fallback, replace unknowns with underscore.
|
||||||
@@ -617,6 +614,38 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
return word;
|
return word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String replaceSpecialCharacters(String word, Map.Entry<String, String> specialCharacters) {
|
||||||
|
String specialChar = specialCharacters.getKey();
|
||||||
|
String replacementChar = specialCharacters.getValue();
|
||||||
|
// Underscore is the only special character we'll allow
|
||||||
|
if (!specialChar.equals("_") && word.contains(specialChar)) {
|
||||||
|
return replaceCharacters(word, specialChar, replacementChar);
|
||||||
|
}
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String replaceCharacters(String word, String oldValue, String newValue) {
|
||||||
|
if (!word.contains(oldValue)) {
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
if (word.equals(oldValue)) {
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
int i = word.indexOf(oldValue);
|
||||||
|
String start = word.substring(0, i);
|
||||||
|
String end = recurseOnEndOfWord(word, oldValue, newValue, i);
|
||||||
|
return start + newValue + end;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String recurseOnEndOfWord(String word, String oldValue, String newValue, int lastReplacedValue) {
|
||||||
|
String end = word.substring(lastReplacedValue + 1);
|
||||||
|
if (!end.isEmpty()) {
|
||||||
|
end = titleCase(end);
|
||||||
|
end = replaceCharacters(end, oldValue, newValue);
|
||||||
|
}
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
private String titleCase(final String input) {
|
private String titleCase(final String input) {
|
||||||
return input.substring(0, 1).toUpperCase(Locale.ROOT) + input.substring(1);
|
return input.substring(0, 1).toUpperCase(Locale.ROOT) + input.substring(1);
|
||||||
}
|
}
|
||||||
@@ -676,6 +705,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
@Override
|
@Override
|
||||||
public String toVarName(String name) {
|
public String toVarName(String name) {
|
||||||
// sanitize name
|
// sanitize name
|
||||||
|
name = sanitizeKotlinSpecificNames(name);
|
||||||
name = sanitizeName(name, "\\W-[\\$]");
|
name = sanitizeName(name, "\\W-[\\$]");
|
||||||
|
|
||||||
if (name.toLowerCase(Locale.ROOT).matches("^_*class$")) {
|
if (name.toLowerCase(Locale.ROOT).matches("^_*class$")) {
|
||||||
@@ -756,4 +786,31 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toDefaultValue(Schema p) {
|
||||||
|
if (ModelUtils.isBooleanSchema(p)) {
|
||||||
|
if (p.getDefault() != null) {
|
||||||
|
return p.getDefault().toString();
|
||||||
|
}
|
||||||
|
} else if (ModelUtils.isDateSchema(p)) {
|
||||||
|
// TODO
|
||||||
|
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||||
|
// TODO
|
||||||
|
} else if (ModelUtils.isNumberSchema(p)) {
|
||||||
|
if (p.getDefault() != null) {
|
||||||
|
return p.getDefault().toString();
|
||||||
|
}
|
||||||
|
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||||
|
if (p.getDefault() != null) {
|
||||||
|
return p.getDefault().toString();
|
||||||
|
}
|
||||||
|
} else if (ModelUtils.isStringSchema(p)) {
|
||||||
|
if (p.getDefault() != null) {
|
||||||
|
return "'" + p.getDefault() + "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -333,4 +333,29 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toOperationId(String operationId) {
|
||||||
|
// throw exception if method name is empty
|
||||||
|
if (StringUtils.isEmpty(operationId)) {
|
||||||
|
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||||
|
}
|
||||||
|
|
||||||
|
operationId = camelize(sanitizeName(operationId), true);
|
||||||
|
|
||||||
|
// method name cannot use reserved keyword, e.g. return
|
||||||
|
if (isReservedWord(operationId)) {
|
||||||
|
String newOperationId = camelize("call_" + operationId, true);
|
||||||
|
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||||
|
return newOperationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// operationId starts with a number
|
||||||
|
if (operationId.matches("^\\d.*")) {
|
||||||
|
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
|
||||||
|
operationId = camelize("call_" + operationId, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return operationId;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.openapitools.codegen.languages;
|
|||||||
|
|
||||||
import com.samskivert.mustache.Mustache;
|
import com.samskivert.mustache.Mustache;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
import org.openapitools.codegen.CodegenConstants;
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
import org.openapitools.codegen.CodegenOperation;
|
import org.openapitools.codegen.CodegenOperation;
|
||||||
import org.openapitools.codegen.CodegenType;
|
import org.openapitools.codegen.CodegenType;
|
||||||
@@ -82,6 +83,18 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
|||||||
|
|
||||||
cliOptions.clear();
|
cliOptions.clear();
|
||||||
|
|
||||||
|
typeMapping.put("boolean", "bool");
|
||||||
|
typeMapping.put("integer", "int");
|
||||||
|
typeMapping.put("float", "float");
|
||||||
|
typeMapping.put("long", "long");
|
||||||
|
typeMapping.put("double", "double");
|
||||||
|
typeMapping.put("number", "decimal");
|
||||||
|
typeMapping.put("DateTime", "DateTime");
|
||||||
|
typeMapping.put("date", "DateTime");
|
||||||
|
typeMapping.put("UUID", "Guid");
|
||||||
|
|
||||||
|
setSupportNullable(Boolean.TRUE);
|
||||||
|
|
||||||
// CLI options
|
// CLI options
|
||||||
addOption(CodegenConstants.LICENSE_URL,
|
addOption(CodegenConstants.LICENSE_URL,
|
||||||
CodegenConstants.LICENSE_URL_DESC,
|
CodegenConstants.LICENSE_URL_DESC,
|
||||||
@@ -375,4 +388,17 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
|||||||
public String toRegularExpression(String pattern) {
|
public String toRegularExpression(String pattern) {
|
||||||
return escapeText(pattern);
|
return escapeText(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNullableType(Schema p, String type) {
|
||||||
|
boolean isNullableExpected = p.getNullable() == null || (p.getNullable() != null && p.getNullable());
|
||||||
|
|
||||||
|
if (isNullableExpected && languageSpecificPrimitives.contains(type + "?")) {
|
||||||
|
return type + "?";
|
||||||
|
} else if (languageSpecificPrimitives.contains(type)) {
|
||||||
|
return type;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
|
|
||||||
public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(BashClientCodegen.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(BashClientCodegen.class);
|
||||||
|
|
||||||
@@ -743,7 +745,7 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelFilename(String name) {
|
public String toModelFilename(String name) {
|
||||||
return initialCaps(name);
|
return camelize(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,18 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
|
|
||||||
cliOptions.clear();
|
cliOptions.clear();
|
||||||
|
|
||||||
|
typeMapping.put("boolean", "bool");
|
||||||
|
typeMapping.put("integer", "int");
|
||||||
|
typeMapping.put("float", "float");
|
||||||
|
typeMapping.put("long", "long");
|
||||||
|
typeMapping.put("double", "double");
|
||||||
|
typeMapping.put("number", "decimal");
|
||||||
|
typeMapping.put("DateTime", "DateTime");
|
||||||
|
typeMapping.put("date", "DateTime");
|
||||||
|
typeMapping.put("UUID", "Guid");
|
||||||
|
|
||||||
|
setSupportNullable(Boolean.TRUE);
|
||||||
|
|
||||||
// CLI options
|
// CLI options
|
||||||
addOption(CodegenConstants.PACKAGE_NAME,
|
addOption(CodegenConstants.PACKAGE_NAME,
|
||||||
"C# package name (convention: Title.Case).",
|
"C# package name (convention: Title.Case).",
|
||||||
@@ -862,4 +874,18 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNullableType(Schema p, String type) {
|
||||||
|
boolean isNullableExpected = p.getNullable() == null || (p.getNullable() != null && p.getNullable());
|
||||||
|
|
||||||
|
if (isNullableExpected && languageSpecificPrimitives.contains(type + "?")) {
|
||||||
|
return type + "?";
|
||||||
|
} else if (languageSpecificPrimitives.contains(type)) {
|
||||||
|
return type;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import org.openapitools.codegen.utils.ModelUtils;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
|
|
||||||
public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||||
protected String implFolder = "impl";
|
protected String implFolder = "impl";
|
||||||
@@ -265,7 +265,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelFilename(String name) {
|
public String toModelFilename(String name) {
|
||||||
return initialCaps(toModelName(name));
|
return camelize(toModelName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -286,7 +286,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toApiFilename(String name) {
|
public String toApiFilename(String name) {
|
||||||
return modelNamePrefix + initialCaps(name) + "Api";
|
return modelNamePrefix + camelize(name) + "Api";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import io.swagger.v3.oas.models.media.Schema;
|
|||||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openapitools.codegen.CodegenConfig;
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.CodegenModel;
|
||||||
import org.openapitools.codegen.CodegenOperation;
|
import org.openapitools.codegen.CodegenOperation;
|
||||||
import org.openapitools.codegen.CodegenParameter;
|
import org.openapitools.codegen.CodegenParameter;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
@@ -280,7 +281,19 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||||
|
|
||||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||||
|
Map<String, CodegenModel> codegenModels = new HashMap<String, CodegenModel> ();
|
||||||
|
for(Object moObj : allModels) {
|
||||||
|
CodegenModel mo = ((Map<String, CodegenModel>) moObj).get("model");
|
||||||
|
if(mo.isEnum) {
|
||||||
|
codegenModels.put(mo.classname, mo);
|
||||||
|
}
|
||||||
|
}
|
||||||
for (CodegenOperation operation : operations) {
|
for (CodegenOperation operation : operations) {
|
||||||
|
if(operation.returnType != null) {
|
||||||
|
if(codegenModels.containsKey(operation.returnType)){
|
||||||
|
operation.vendorExtensions.put("returnsEnum", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Check all return parameter baseType if there is a necessity to include, include it if not
|
// Check all return parameter baseType if there is a necessity to include, include it if not
|
||||||
// already done
|
// already done
|
||||||
if (operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
if (operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
||||||
@@ -316,6 +329,21 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||||
|
return postProcessModelsEnum(objs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumValue(String value, String datatype) {
|
||||||
|
return escapeText(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDataTypeString(String dataType) {
|
||||||
|
return "QString".equals(dataType);
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, String> createMapping(String key, String value) {
|
private Map<String, String> createMapping(String key, String value) {
|
||||||
Map<String, String> customImport = new HashMap<String, String>();
|
Map<String, String> customImport = new HashMap<String, String>();
|
||||||
customImport.put(key, toModelImport(value));
|
customImport.put(key, toModelImport(value));
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import org.openapitools.codegen.SupportingFile;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
|
|
||||||
public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements CodegenConfig {
|
public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements CodegenConfig {
|
||||||
public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate client.pri.";
|
public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate client.pri.";
|
||||||
// source folder where to write the files
|
// source folder where to write the files
|
||||||
@@ -75,6 +77,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
|||||||
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, PREFIX + "HttpRequest.h"));
|
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, PREFIX + "HttpRequest.h"));
|
||||||
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, PREFIX + "HttpRequest.cpp"));
|
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, PREFIX + "HttpRequest.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, PREFIX + "Object.h"));
|
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, PREFIX + "Object.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, PREFIX + "Enum.h"));
|
||||||
if (optionalProjectFileFlag) {
|
if (optionalProjectFileFlag) {
|
||||||
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri"));
|
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri"));
|
||||||
}
|
}
|
||||||
@@ -100,6 +103,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
|||||||
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, modelNamePrefix + "HttpRequest.h"));
|
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, modelNamePrefix + "HttpRequest.h"));
|
||||||
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, modelNamePrefix + "HttpRequest.cpp"));
|
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, modelNamePrefix + "HttpRequest.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h"));
|
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h"));
|
||||||
|
|
||||||
typeMapping.put("file", modelNamePrefix + "HttpRequestInputFileElement");
|
typeMapping.put("file", modelNamePrefix + "HttpRequestInputFileElement");
|
||||||
typeMapping.put("binary", modelNamePrefix + "HttpRequestInputFileElement");
|
typeMapping.put("binary", modelNamePrefix + "HttpRequestInputFileElement");
|
||||||
@@ -163,7 +167,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toApiFilename(String name) {
|
public String toApiFilename(String name) {
|
||||||
return modelNamePrefix + sanitizeName(initialCaps(name)) + "Api";
|
return modelNamePrefix + sanitizeName(camelize(name)) + "Api";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOptionalProjectFileFlag(boolean flag) {
|
public void setOptionalProjectFileFlag(boolean flag) {
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import org.openapitools.codegen.SupportingFile;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
|
|
||||||
public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implements CodegenConfig {
|
public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implements CodegenConfig {
|
||||||
|
|
||||||
protected final String SRC_DIR = "/src";
|
protected final String SRC_DIR = "/src";
|
||||||
@@ -83,6 +85,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.h"));
|
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.h"));
|
||||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.cpp"));
|
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, PREFIX + "Object.h"));
|
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, PREFIX + "Object.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder + MODEL_DIR, PREFIX + "Enum.h"));
|
||||||
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.h"));
|
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.h"));
|
||||||
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.cpp"));
|
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.cpp"));
|
||||||
|
|
||||||
@@ -106,6 +109,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.h"));
|
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.h"));
|
||||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.cpp"));
|
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Object.h"));
|
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Object.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Enum.h"));
|
||||||
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.h"));
|
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.h"));
|
||||||
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.cpp"));
|
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.cpp"));
|
||||||
|
|
||||||
@@ -187,7 +191,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toApiFilename(String name) {
|
public String toApiFilename(String name) {
|
||||||
return modelNamePrefix + sanitizeName(initialCaps(name)) + "ApiHandler";
|
return modelNamePrefix + sanitizeName(camelize(name)) + "ApiHandler";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.openapitools.codegen.utils.ModelUtils;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
|
|
||||||
public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||||
|
|
||||||
@@ -288,12 +289,12 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelFilename(String name) {
|
public String toModelFilename(String name) {
|
||||||
return sanitizeName(initialCaps(name));
|
return sanitizeName(camelize(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toApiFilename(String name) {
|
public String toApiFilename(String name) {
|
||||||
return sanitizeName(initialCaps(name) + "Api");
|
return sanitizeName(camelize(name) + "Api");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
|
|
||||||
public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||||
|
|
||||||
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CppRestbedServerCodegen.class);
|
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CppRestbedServerCodegen.class);
|
||||||
@@ -191,12 +193,12 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelFilename(String name) {
|
public String toModelFilename(String name) {
|
||||||
return initialCaps(name);
|
return camelize(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toApiFilename(String name) {
|
public String toApiFilename(String name) {
|
||||||
return initialCaps(name) + "Api";
|
return camelize(name) + "Api";
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
@@ -247,17 +247,17 @@ public class CppTizenClientCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelFilename(String name) {
|
public String toModelFilename(String name) {
|
||||||
return initialCaps(name);
|
return camelize(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toApiName(String name) {
|
public String toApiName(String name) {
|
||||||
return initialCaps(name) + "Manager";
|
return camelize(name) + "Manager";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toApiFilename(String name) {
|
public String toApiFilename(String name) {
|
||||||
return initialCaps(name) + "Manager";
|
return camelize(name) + "Manager";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,10 +16,16 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen.languages;
|
package org.openapitools.codegen.languages;
|
||||||
|
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.openapitools.codegen.*;
|
||||||
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.media.*;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openapitools.codegen.*;
|
import org.openapitools.codegen.*;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
|
import org.openapitools.codegen.utils.ProcessUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -28,16 +34,25 @@ import static org.openapitools.codegen.utils.StringUtils.underscore;
|
|||||||
|
|
||||||
public class DartJaguarClientCodegen extends DartClientCodegen {
|
public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||||
private static final String NULLABLE_FIELDS = "nullableFields";
|
private static final String NULLABLE_FIELDS = "nullableFields";
|
||||||
|
private static final String SERIALIZATION_FORMAT = "serialization";
|
||||||
|
private static final String IS_FORMAT_JSON = "jsonFormat";
|
||||||
|
private static final String IS_FORMAT_PROTO = "protoFormat";
|
||||||
private static Set<String> modelToIgnore = new HashSet<>();
|
private static Set<String> modelToIgnore = new HashSet<>();
|
||||||
|
private HashMap<String, String> protoTypeMapping = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
modelToIgnore.add("datetime");
|
modelToIgnore.add("datetime");
|
||||||
modelToIgnore.add("map");
|
modelToIgnore.add("map");
|
||||||
modelToIgnore.add("list");
|
modelToIgnore.add("list");
|
||||||
modelToIgnore.add("file");
|
modelToIgnore.add("file");
|
||||||
|
modelToIgnore.add("uint8list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String SERIALIZATION_JSON = "json";
|
||||||
|
private static final String SERIALIZATION_PROTO = "proto";
|
||||||
|
|
||||||
private boolean nullableFields = true;
|
private boolean nullableFields = true;
|
||||||
|
private String serialization = SERIALIZATION_JSON;
|
||||||
|
|
||||||
public DartJaguarClientCodegen() {
|
public DartJaguarClientCodegen() {
|
||||||
super();
|
super();
|
||||||
@@ -46,6 +61,33 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
|||||||
embeddedTemplateDir = templateDir = "dart-jaguar";
|
embeddedTemplateDir = templateDir = "dart-jaguar";
|
||||||
|
|
||||||
cliOptions.add(new CliOption(NULLABLE_FIELDS, "Is the null fields should be in the JSON payload"));
|
cliOptions.add(new CliOption(NULLABLE_FIELDS, "Is the null fields should be in the JSON payload"));
|
||||||
|
cliOptions.add(new CliOption(SERIALIZATION_FORMAT, "Choose serialization format JSON or PROTO is supported"));
|
||||||
|
|
||||||
|
typeMapping.put("file", "Uint8List");
|
||||||
|
typeMapping.put("binary", "Uint8List");
|
||||||
|
|
||||||
|
protoTypeMapping.put("Array", "repeated");
|
||||||
|
protoTypeMapping.put("array", "repeated");
|
||||||
|
protoTypeMapping.put("List", "repeated");
|
||||||
|
protoTypeMapping.put("boolean", "bool");
|
||||||
|
protoTypeMapping.put("string", "string");
|
||||||
|
protoTypeMapping.put("char", "string");
|
||||||
|
protoTypeMapping.put("int", "int32");
|
||||||
|
protoTypeMapping.put("long", "int64");
|
||||||
|
protoTypeMapping.put("short", "int32");
|
||||||
|
protoTypeMapping.put("number", "double");
|
||||||
|
protoTypeMapping.put("float", "float");
|
||||||
|
protoTypeMapping.put("double", "double");
|
||||||
|
protoTypeMapping.put("object", "google.protobuf.Any");
|
||||||
|
protoTypeMapping.put("integer", "int32");
|
||||||
|
protoTypeMapping.put("Date", "google.protobuf.Timestamp");
|
||||||
|
protoTypeMapping.put("date", "google.protobuf.Timestamp");
|
||||||
|
protoTypeMapping.put("File", "bytes");
|
||||||
|
protoTypeMapping.put("file", "bytes");
|
||||||
|
protoTypeMapping.put("binary", "bytes");
|
||||||
|
protoTypeMapping.put("UUID", "string");
|
||||||
|
protoTypeMapping.put("ByteArray", "bytes");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,6 +119,20 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
|||||||
additionalProperties.put(NULLABLE_FIELDS, nullableFields);
|
additionalProperties.put(NULLABLE_FIELDS, nullableFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(SERIALIZATION_FORMAT)) {
|
||||||
|
serialization = ((String) additionalProperties.get(SERIALIZATION_FORMAT));
|
||||||
|
boolean isProto = serialization.equalsIgnoreCase(SERIALIZATION_PROTO);
|
||||||
|
additionalProperties.put(IS_FORMAT_JSON, serialization.equalsIgnoreCase(SERIALIZATION_JSON));
|
||||||
|
additionalProperties.put(IS_FORMAT_PROTO, isProto);
|
||||||
|
|
||||||
|
modelTemplateFiles.put("model.mustache", isProto ? ".proto" : ".dart");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//not set, use to be passed to template
|
||||||
|
additionalProperties.put(IS_FORMAT_JSON, true);
|
||||||
|
additionalProperties.put(IS_FORMAT_PROTO, false);
|
||||||
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(PUB_NAME)) {
|
if (additionalProperties.containsKey(PUB_NAME)) {
|
||||||
this.setPubName((String) additionalProperties.get(PUB_NAME));
|
this.setPubName((String) additionalProperties.get(PUB_NAME));
|
||||||
} else {
|
} else {
|
||||||
@@ -133,6 +189,7 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
|||||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||||
objs = super.postProcessModels(objs);
|
objs = super.postProcessModels(objs);
|
||||||
List<Object> models = (List<Object>) objs.get("models");
|
List<Object> models = (List<Object>) objs.get("models");
|
||||||
|
ProcessUtils.addIndexToProperties(models, 1);
|
||||||
for (Object _mo : models) {
|
for (Object _mo : models) {
|
||||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||||
Set<String> modelImports = new HashSet<>();
|
Set<String> modelImports = new HashSet<>();
|
||||||
@@ -142,6 +199,16 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
|||||||
modelImports.add(underscore(modelImport));
|
modelImports.add(underscore(modelImport));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (CodegenProperty p : cm.vars) {
|
||||||
|
String protoType = protoTypeMapping.get(p.openApiType);
|
||||||
|
if (p.isListContainer) {
|
||||||
|
String innerType = protoTypeMapping.get(p.mostInnerItems.openApiType);
|
||||||
|
protoType = protoType + " " + (innerType == null ? p.mostInnerItems.openApiType : innerType);
|
||||||
|
}
|
||||||
|
p.vendorExtensions.put("x-proto-type", protoType == null ? p.openApiType : protoType);
|
||||||
|
}
|
||||||
|
|
||||||
cm.imports = modelImports;
|
cm.imports = modelImports;
|
||||||
cm.vendorExtensions.put("hasVars", cm.vars.size() > 0);
|
cm.vendorExtensions.put("hasVars", cm.vars.size() > 0);
|
||||||
}
|
}
|
||||||
@@ -155,17 +222,20 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
|||||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||||
|
|
||||||
Set<String> modelImports = new HashSet<>();
|
Set<String> modelImports = new HashSet<>();
|
||||||
|
Set<String> fullImports = new HashSet<>();
|
||||||
|
|
||||||
for (CodegenOperation op : operationList) {
|
for (CodegenOperation op : operationList) {
|
||||||
op.httpMethod = StringUtils.capitalize(op.httpMethod.toLowerCase(Locale.ROOT));
|
op.httpMethod = StringUtils.capitalize(op.httpMethod.toLowerCase(Locale.ROOT));
|
||||||
boolean isJson = true; //default to JSON
|
boolean isJson = true; //default to JSON
|
||||||
boolean isForm = false;
|
boolean isForm = false;
|
||||||
|
boolean isProto = false;
|
||||||
boolean isMultipart = false;
|
boolean isMultipart = false;
|
||||||
if (op.consumes != null) {
|
if (op.consumes != null) {
|
||||||
for (Map<String, String> consume : op.consumes) {
|
for (Map<String, String> consume : op.consumes) {
|
||||||
if (consume.containsKey("mediaType")) {
|
if (consume.containsKey("mediaType")) {
|
||||||
String type = consume.get("mediaType");
|
String type = consume.get("mediaType");
|
||||||
isJson = type.equalsIgnoreCase("application/json");
|
isJson = type.equalsIgnoreCase("application/json");
|
||||||
|
isProto = type.equalsIgnoreCase("application/octet-stream");
|
||||||
isForm = type.equalsIgnoreCase("application/x-www-form-urlencoded");
|
isForm = type.equalsIgnoreCase("application/x-www-form-urlencoded");
|
||||||
isMultipart = type.equalsIgnoreCase("multipart/form-data");
|
isMultipart = type.equalsIgnoreCase("multipart/form-data");
|
||||||
break;
|
break;
|
||||||
@@ -173,7 +243,27 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (CodegenParameter param : op.allParams) {
|
||||||
|
if (param.baseType != null && param.baseType.equalsIgnoreCase("Uint8List") && isMultipart) {
|
||||||
|
param.baseType = "MultipartFile";
|
||||||
|
param.dataType = "MultipartFile";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (CodegenParameter param : op.formParams) {
|
||||||
|
if (param.baseType != null && param.baseType.equalsIgnoreCase("Uint8List") && isMultipart) {
|
||||||
|
param.baseType = "MultipartFile";
|
||||||
|
param.dataType = "MultipartFile";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (CodegenParameter param : op.bodyParams) {
|
||||||
|
if (param.baseType != null && param.baseType.equalsIgnoreCase("Uint8List") && isMultipart) {
|
||||||
|
param.baseType = "MultipartFile";
|
||||||
|
param.dataType = "MultipartFile";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
op.vendorExtensions.put("isJson", isJson);
|
op.vendorExtensions.put("isJson", isJson);
|
||||||
|
op.vendorExtensions.put("isProto", isProto);
|
||||||
op.vendorExtensions.put("isForm", isForm);
|
op.vendorExtensions.put("isForm", isForm);
|
||||||
op.vendorExtensions.put("isMultipart", isMultipart);
|
op.vendorExtensions.put("isMultipart", isMultipart);
|
||||||
|
|
||||||
@@ -181,6 +271,8 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
|||||||
for (String item : op.imports) {
|
for (String item : op.imports) {
|
||||||
if (!modelToIgnore.contains(item.toLowerCase(Locale.ROOT))) {
|
if (!modelToIgnore.contains(item.toLowerCase(Locale.ROOT))) {
|
||||||
imports.add(underscore(item));
|
imports.add(underscore(item));
|
||||||
|
} else if (item.equalsIgnoreCase("Uint8List")) {
|
||||||
|
fullImports.add("dart:typed_data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
modelImports.addAll(imports);
|
modelImports.addAll(imports);
|
||||||
@@ -205,6 +297,7 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
objs.put("modelImports", modelImports);
|
objs.put("modelImports", modelImports);
|
||||||
|
objs.put("fullImports", fullImports);
|
||||||
|
|
||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import io.swagger.v3.oas.models.OpenAPI;
|
|||||||
import io.swagger.v3.oas.models.info.Info;
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
|
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openapitools.codegen.*;
|
import org.openapitools.codegen.*;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
@@ -53,7 +54,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
List<String> extraApplications = Arrays.asList(":logger");
|
List<String> extraApplications = Arrays.asList(":logger");
|
||||||
List<String> deps = Arrays.asList(
|
List<String> deps = Arrays.asList(
|
||||||
"{:tesla, \"~> 1.0.0\"}",
|
"{:tesla, \"~> 1.0.0\"}",
|
||||||
"{:poison, \">= 1.0.0\"}"
|
"{:poison, \"~> 3.0.0\"}"
|
||||||
);
|
);
|
||||||
|
|
||||||
public ElixirClientCodegen() {
|
public ElixirClientCodegen() {
|
||||||
@@ -310,6 +311,11 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
return new ExtendedCodegenModel(cm);
|
return new ExtendedCodegenModel(cm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CodegenResponse fromResponse(String responseCode, ApiResponse resp) {
|
||||||
|
return new ExtendedCodegenResponse(super.fromResponse(responseCode, resp));
|
||||||
|
}
|
||||||
|
|
||||||
// We should use String.join if we can use Java8
|
// We should use String.join if we can use Java8
|
||||||
String join(CharSequence charSequence, Iterable<String> iterable) {
|
String join(CharSequence charSequence, Iterable<String> iterable) {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
@@ -515,6 +521,91 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
return toModelName(type);
|
return toModelName(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ExtendedCodegenResponse extends CodegenResponse {
|
||||||
|
public boolean isDefinedDefault;
|
||||||
|
|
||||||
|
public ExtendedCodegenResponse(CodegenResponse o) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.headers.addAll(o.headers);
|
||||||
|
this.code = o.code;
|
||||||
|
this.message = o.message;
|
||||||
|
this.hasMore = o.hasMore;
|
||||||
|
this.examples = o.examples;
|
||||||
|
this.dataType = o.dataType;
|
||||||
|
this.baseType = o.baseType;
|
||||||
|
this.containerType = o.containerType;
|
||||||
|
this.hasHeaders = o.hasHeaders;
|
||||||
|
this.isString = o.isString;
|
||||||
|
this.isNumeric = o.isNumeric;
|
||||||
|
this.isInteger = o.isInteger;
|
||||||
|
this.isLong = o.isLong;
|
||||||
|
this.isNumber = o.isNumber;
|
||||||
|
this.isFloat = o.isFloat;
|
||||||
|
this.isDouble = o.isDouble;
|
||||||
|
this.isByteArray = o.isByteArray;
|
||||||
|
this.isBoolean = o.isBoolean;
|
||||||
|
this.isDate = o.isDate;
|
||||||
|
this.isDateTime = o.isDateTime;
|
||||||
|
this.isUuid = o.isUuid;
|
||||||
|
this.isEmail = o.isEmail;
|
||||||
|
this.isModel = o.isModel;
|
||||||
|
this.isFreeFormObject = o.isFreeFormObject;
|
||||||
|
this.isDefault = o.isDefault;
|
||||||
|
this.simpleType = o.simpleType;
|
||||||
|
this.primitiveType = o.primitiveType;
|
||||||
|
this.isMapContainer = o.isMapContainer;
|
||||||
|
this.isListContainer = o.isListContainer;
|
||||||
|
this.isBinary = o.isBinary;
|
||||||
|
this.isFile = o.isFile;
|
||||||
|
this.schema = o.schema;
|
||||||
|
this.jsonSchema = o.jsonSchema;
|
||||||
|
this.vendorExtensions = o.vendorExtensions;
|
||||||
|
|
||||||
|
this.isDefinedDefault = (this.code.equals("0") || this.code.equals("default"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String codeMappingKey(){
|
||||||
|
if(this.isDefinedDefault) {
|
||||||
|
return ":default";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(code.matches("^\\d{3}$")){
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.warn("Unknown HTTP status code: " + this.code);
|
||||||
|
return "\"" + code + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String decodedStruct() {
|
||||||
|
// Let Poison decode the entire response into a generic blob
|
||||||
|
if (isMapContainer) {
|
||||||
|
return "%{}";
|
||||||
|
}
|
||||||
|
// Primitive return type, don't even try to decode
|
||||||
|
if (baseType == null || (simpleType && primitiveType)) {
|
||||||
|
return "false";
|
||||||
|
} else if (isListContainer && languageSpecificPrimitives().contains(baseType)) {
|
||||||
|
return "[]";
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (isListContainer) {
|
||||||
|
sb.append("[");
|
||||||
|
}
|
||||||
|
sb.append("%");
|
||||||
|
sb.append(moduleName);
|
||||||
|
sb.append(".Model.");
|
||||||
|
sb.append(baseType);
|
||||||
|
sb.append("{}");
|
||||||
|
if (isListContainer) {
|
||||||
|
sb.append("]");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class ExtendedCodegenOperation extends CodegenOperation {
|
class ExtendedCodegenOperation extends CodegenOperation {
|
||||||
private List<String> pathTemplateNames = new ArrayList<String>();
|
private List<String> pathTemplateNames = new ArrayList<String>();
|
||||||
private String replacedPathName;
|
private String replacedPathName;
|
||||||
@@ -688,32 +779,6 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
sb.append(".t");
|
sb.append(".t");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String decodedStruct() {
|
|
||||||
// Let Poison decode the entire response into a generic blob
|
|
||||||
if (isMapContainer) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
// Primitive return type, don't even try to decode
|
|
||||||
if (returnBaseType == null || (returnSimpleType && returnTypeIsPrimitive)) {
|
|
||||||
return "false";
|
|
||||||
} else if (isListContainer && languageSpecificPrimitives().contains(returnBaseType)) {
|
|
||||||
return "[]";
|
|
||||||
}
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
if (isListContainer) {
|
|
||||||
sb.append("[");
|
|
||||||
}
|
|
||||||
sb.append("%");
|
|
||||||
sb.append(moduleName);
|
|
||||||
sb.append(".Model.");
|
|
||||||
sb.append(returnBaseType);
|
|
||||||
sb.append("{}");
|
|
||||||
if (isListContainer) {
|
|
||||||
sb.append("]");
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExtendedCodegenModel extends CodegenModel {
|
class ExtendedCodegenModel extends CodegenModel {
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||||
|
|
||||||
@@ -234,7 +236,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return "Default";
|
return "Default";
|
||||||
}
|
}
|
||||||
return initialCaps(name);
|
return camelize(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -411,14 +413,26 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
return postProcessModelsEnum(objs);
|
return postProcessModelsEnum(objs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean anyOperationParam(final List<CodegenOperation> operations, final Predicate<CodegenParameter> predicate) {
|
||||||
|
return operations.stream()
|
||||||
|
.flatMap(operation -> Stream.of(
|
||||||
|
operation.bodyParams.stream(),
|
||||||
|
operation.queryParams.stream(),
|
||||||
|
operation.pathParams.stream(),
|
||||||
|
operation.headerParams.stream()
|
||||||
|
))
|
||||||
|
.flatMap(a -> a)
|
||||||
|
.filter(predicate)
|
||||||
|
.findAny()
|
||||||
|
.isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({"static-method", "unchecked"})
|
@SuppressWarnings({"static-method", "unchecked"})
|
||||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> operations, List<Object> allModels) {
|
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> operations, List<Object> allModels) {
|
||||||
Map<String, Object> objs = (Map<String, Object>) operations.get("operations");
|
Map<String, Object> objs = (Map<String, Object>) operations.get("operations");
|
||||||
List<CodegenOperation> ops = (List<CodegenOperation>) objs.get("operation");
|
List<CodegenOperation> ops = (List<CodegenOperation>) objs.get("operation");
|
||||||
|
|
||||||
boolean hasDateTime = false;
|
|
||||||
boolean hasDate = false;
|
|
||||||
final Map<String, Set<String>> dependencies = new HashMap<>();
|
final Map<String, Set<String>> dependencies = new HashMap<>();
|
||||||
|
|
||||||
for (CodegenOperation op : ops) {
|
for (CodegenOperation op : ops) {
|
||||||
@@ -427,8 +441,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
for (CodegenParameter param : op.pathParams) {
|
for (CodegenParameter param : op.pathParams) {
|
||||||
final String var = paramToString("params", param, false, null);
|
final String var = paramToString("params", param, false, null);
|
||||||
path = path.replace("{" + param.paramName + "}", "\" ++ " + var + " ++ \"");
|
path = path.replace("{" + param.paramName + "}", "\" ++ " + var + " ++ \"");
|
||||||
hasDateTime = hasDateTime || param.isDateTime;
|
|
||||||
hasDate = hasDate || param.isDate;
|
|
||||||
}
|
}
|
||||||
op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", "");
|
op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", "");
|
||||||
} else {
|
} else {
|
||||||
@@ -437,8 +449,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
for (CodegenParameter param : op.pathParams) {
|
for (CodegenParameter param : op.pathParams) {
|
||||||
String str = paramToString("params", param, false, null);
|
String str = paramToString("params", param, false, null);
|
||||||
path = path.replace("{" + param.paramName + "}", str);
|
path = path.replace("{" + param.paramName + "}", str);
|
||||||
hasDateTime = hasDateTime || param.isDateTime;
|
|
||||||
hasDate = hasDate || param.isDate;
|
|
||||||
}
|
}
|
||||||
op.path = path;
|
op.path = path;
|
||||||
|
|
||||||
@@ -487,6 +497,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
elmImport.hasExposures = true;
|
elmImport.hasExposures = true;
|
||||||
elmImports.add(elmImport);
|
elmImports.add(elmImport);
|
||||||
}
|
}
|
||||||
|
final boolean hasDate = anyOperationParam(ops, param -> param.isDate);
|
||||||
if (hasDate) {
|
if (hasDate) {
|
||||||
final ElmImport elmImport = new ElmImport();
|
final ElmImport elmImport = new ElmImport();
|
||||||
elmImport.moduleName = "DateOnly";
|
elmImport.moduleName = "DateOnly";
|
||||||
@@ -495,6 +506,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
elmImport.hasExposures = true;
|
elmImport.hasExposures = true;
|
||||||
elmImports.add(elmImport);
|
elmImports.add(elmImport);
|
||||||
}
|
}
|
||||||
|
final boolean hasDateTime = anyOperationParam(ops, param -> param.isDateTime);
|
||||||
if (hasDateTime) {
|
if (hasDateTime) {
|
||||||
final ElmImport elmImport = new ElmImport();
|
final ElmImport elmImport = new ElmImport();
|
||||||
elmImport.moduleName = "DateTime";
|
elmImport.moduleName = "DateTime";
|
||||||
@@ -503,6 +515,15 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
elmImport.hasExposures = true;
|
elmImport.hasExposures = true;
|
||||||
elmImports.add(elmImport);
|
elmImports.add(elmImport);
|
||||||
}
|
}
|
||||||
|
final boolean hasUuid = anyOperationParam(ops, param -> param.isUuid);
|
||||||
|
if (hasUuid) {
|
||||||
|
final ElmImport elmImport = new ElmImport();
|
||||||
|
elmImport.moduleName = "Uuid";
|
||||||
|
elmImport.exposures = new TreeSet<>();
|
||||||
|
elmImport.exposures.add("Uuid");
|
||||||
|
elmImport.hasExposures = true;
|
||||||
|
elmImports.add(elmImport);
|
||||||
|
}
|
||||||
operations.put("elmImports", elmImports);
|
operations.put("elmImports", elmImports);
|
||||||
|
|
||||||
return operations;
|
return operations;
|
||||||
@@ -553,7 +574,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String mapFn = null;
|
String mapFn = null;
|
||||||
if (param.isString || param.isUuid || param.isBinary || param.isByteArray) {
|
if (param.isString || param.isBinary || param.isByteArray) {
|
||||||
mapFn = "";
|
mapFn = "";
|
||||||
} else if (param.isBoolean) {
|
} else if (param.isBoolean) {
|
||||||
mapFn = "(\\val -> if val then \"true\" else \"false\")";
|
mapFn = "(\\val -> if val then \"true\" else \"false\")";
|
||||||
@@ -561,6 +582,8 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
mapFn = "DateTime.toString";
|
mapFn = "DateTime.toString";
|
||||||
} else if (param.isDate) {
|
} else if (param.isDate) {
|
||||||
mapFn = "DateOnly.toString";
|
mapFn = "DateOnly.toString";
|
||||||
|
} else if (param.isUuid) {
|
||||||
|
mapFn = "Uuid.toString";
|
||||||
} else if (ElmVersion.ELM_018.equals(elmVersion)) {
|
} else if (ElmVersion.ELM_018.equals(elmVersion)) {
|
||||||
mapFn = "toString";
|
mapFn = "toString";
|
||||||
} else if (param.isInteger || param.isLong) {
|
} else if (param.isInteger || param.isLong) {
|
||||||
|
|||||||
@@ -51,8 +51,6 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
// default HIDE_GENERATION_TIMESTAMP to true
|
// default HIDE_GENERATION_TIMESTAMP to true
|
||||||
hideGenerationTimestamp = Boolean.TRUE;
|
hideGenerationTimestamp = Boolean.TRUE;
|
||||||
|
|
||||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Go package version.")
|
|
||||||
.defaultValue("1.0.0"));
|
|
||||||
cliOptions.add(CliOption.newBoolean(WITH_GO_CODEGEN_COMMENT, "whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs"));
|
cliOptions.add(CliOption.newBoolean(WITH_GO_CODEGEN_COMMENT, "whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs"));
|
||||||
cliOptions.add(CliOption.newBoolean(WITH_XML, "whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)"));
|
cliOptions.add(CliOption.newBoolean(WITH_XML, "whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)"));
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen.languages;
|
package org.openapitools.codegen.languages;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.CliOption;
|
||||||
import org.openapitools.codegen.CodegenConstants;
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
import org.openapitools.codegen.CodegenType;
|
import org.openapitools.codegen.CodegenType;
|
||||||
import org.openapitools.codegen.SupportingFile;
|
import org.openapitools.codegen.SupportingFile;
|
||||||
@@ -30,16 +31,25 @@ public class GoServerCodegen extends AbstractGoCodegen {
|
|||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(GoServerCodegen.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(GoServerCodegen.class);
|
||||||
|
|
||||||
protected String apiVersion = "1.0.0";
|
protected String packageVersion = "1.0.0";
|
||||||
protected int serverPort = 8080;
|
protected int serverPort = 8080;
|
||||||
protected String projectName = "openapi-server";
|
protected String projectName = "openapi-server";
|
||||||
protected String apiPath = "go";
|
protected String sourceFolder = "go";
|
||||||
|
|
||||||
|
|
||||||
public GoServerCodegen() {
|
public GoServerCodegen() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// set the output folder here
|
// set the output folder here
|
||||||
outputFolder = "generated-code/go";
|
outputFolder = "generated-code/go";
|
||||||
|
|
||||||
|
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC)
|
||||||
|
.defaultValue(sourceFolder));
|
||||||
|
|
||||||
|
CliOption optServerPort = new CliOption("serverPort", "The network port the generated server binds to");
|
||||||
|
optServerPort.setType("int");
|
||||||
|
optServerPort.defaultValue(Integer.toString(serverPort));
|
||||||
|
cliOptions.add(optServerPort);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Models. You can write model files using the modelTemplateFiles map.
|
* Models. You can write model files using the modelTemplateFiles map.
|
||||||
@@ -88,21 +98,35 @@ public class GoServerCodegen extends AbstractGoCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public void processOpts() {
|
public void processOpts() {
|
||||||
super.processOpts();
|
super.processOpts();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Additional Properties. These values can be passed to the templates and
|
||||||
|
* are available in models, apis, and supporting files
|
||||||
|
*/
|
||||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||||
} else {
|
} else {
|
||||||
setPackageName("openapi");
|
setPackageName("openapi");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
|
||||||
* Additional Properties. These values can be passed to the templates and
|
this.setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
|
||||||
* are available in models, apis, and supporting files
|
} else {
|
||||||
*/
|
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||||
additionalProperties.put("apiVersion", apiVersion);
|
}
|
||||||
additionalProperties.put("serverPort", serverPort);
|
|
||||||
additionalProperties.put("apiPath", apiPath);
|
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
|
||||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
|
||||||
|
} else {
|
||||||
|
additionalProperties.put(CodegenConstants.SOURCE_FOLDER, sourceFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey("serverPort") && additionalProperties.get("serverPort") instanceof Integer) {
|
||||||
|
this.setServerPort((int) additionalProperties.get("serverPort"));
|
||||||
|
} else {
|
||||||
|
additionalProperties.put("serverPort", serverPort);
|
||||||
|
}
|
||||||
|
|
||||||
modelPackage = packageName;
|
modelPackage = packageName;
|
||||||
apiPackage = packageName;
|
apiPackage = packageName;
|
||||||
@@ -115,14 +139,14 @@ public class GoServerCodegen extends AbstractGoCodegen {
|
|||||||
supportingFiles.add(new SupportingFile("openapi.mustache", "api", "openapi.yaml"));
|
supportingFiles.add(new SupportingFile("openapi.mustache", "api", "openapi.yaml"));
|
||||||
supportingFiles.add(new SupportingFile("main.mustache", "", "main.go"));
|
supportingFiles.add(new SupportingFile("main.mustache", "", "main.go"));
|
||||||
supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile"));
|
supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile"));
|
||||||
supportingFiles.add(new SupportingFile("routers.mustache", apiPath, "routers.go"));
|
supportingFiles.add(new SupportingFile("routers.mustache", sourceFolder, "routers.go"));
|
||||||
supportingFiles.add(new SupportingFile("logger.mustache", apiPath, "logger.go"));
|
supportingFiles.add(new SupportingFile("logger.mustache", sourceFolder, "logger.go"));
|
||||||
writeOptional(outputFolder, new SupportingFile("README.mustache", apiPath, "README.md"));
|
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiPackage() {
|
public String apiPackage() {
|
||||||
return apiPath;
|
return sourceFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,5 +196,16 @@ public class GoServerCodegen extends AbstractGoCodegen {
|
|||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSourceFolder(String sourceFolder) {
|
||||||
|
this.sourceFolder = sourceFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPackageVersion(String packageVersion) {
|
||||||
|
this.packageVersion = packageVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerPort(int serverPort) {
|
||||||
|
this.serverPort = serverPort;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,18 +116,18 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
cliOptions.add(CliOption.newBoolean(FEIGN_VERSION, "Version of OpenFeign: '10.x', '9.x' (default)"));
|
cliOptions.add(CliOption.newBoolean(FEIGN_VERSION, "Version of OpenFeign: '10.x', '9.x' (default)"));
|
||||||
cliOptions.add(CliOption.newBoolean(USE_REFLECTION_EQUALS_HASHCODE, "Use org.apache.commons.lang3.builder for equals and hashCode in the models. WARNING: This will fail under a security manager, unless the appropriate permissions are set up correctly and also there's potential performance impact."));
|
cliOptions.add(CliOption.newBoolean(USE_REFLECTION_EQUALS_HASHCODE, "Use org.apache.commons.lang3.builder for equals and hashCode in the models. WARNING: This will fail under a security manager, unless the appropriate permissions are set up correctly and also there's potential performance impact."));
|
||||||
|
|
||||||
supportedLibraries.put(JERSEY1, "HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.8.9. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
|
supportedLibraries.put(JERSEY1, "HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.8.x. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
|
||||||
supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.8.9. To enable OpenFeign 10.x, set the 'feignVersion' option to '10.x'");
|
supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 9.x or 10.x. JSON processing: Jackson 2.8.x. To enable OpenFeign 10.x, set the 'feignVersion' option to '10.x'");
|
||||||
supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.8.9");
|
supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.8.x");
|
||||||
supportedLibraries.put(OKHTTP_GSON, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.8.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
|
supportedLibraries.put(OKHTTP_GSON, "HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
|
||||||
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.");
|
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.x. JSON processing: Gson 2.x (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.");
|
||||||
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.8.0. JSON processing: Gson 2.6.1 (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)");
|
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)");
|
||||||
supportedLibraries.put(RESTTEMPLATE, "HTTP client: Spring RestTemplate 4.3.9-RELEASE. JSON processing: Jackson 2.8.9");
|
supportedLibraries.put(RESTTEMPLATE, "HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.8.x");
|
||||||
supportedLibraries.put(WEBCLIENT, "HTTP client: Spring WebClient 5.0.7-RELEASE. JSON processing: Jackson 2.9.5");
|
supportedLibraries.put(WEBCLIENT, "HTTP client: Spring WebClient 5.x. JSON processing: Jackson 2.9.x");
|
||||||
supportedLibraries.put(RESTEASY, "HTTP client: Resteasy client 3.1.3.Final. JSON processing: Jackson 2.8.9");
|
supportedLibraries.put(RESTEASY, "HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.8.x");
|
||||||
supportedLibraries.put(VERTX, "HTTP client: VertX client 3.2.4. JSON processing: Jackson 2.8.9");
|
supportedLibraries.put(VERTX, "HTTP client: VertX client 3.x. JSON processing: Jackson 2.8.x");
|
||||||
supportedLibraries.put(GOOGLE_API_CLIENT, "HTTP client: Google API client 1.23.0. JSON processing: Jackson 2.8.9");
|
supportedLibraries.put(GOOGLE_API_CLIENT, "HTTP client: Google API client 1.x. JSON processing: Jackson 2.8.x");
|
||||||
supportedLibraries.put(REST_ASSURED, "HTTP client: rest-assured : 3.1.0. JSON processing: Gson 2.6.1. Only for Java8");
|
supportedLibraries.put(REST_ASSURED, "HTTP client: rest-assured : 3.x. JSON processing: Gson 2.x. Only for Java8");
|
||||||
|
|
||||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||||
libraryOption.setEnum(supportedLibraries);
|
libraryOption.setEnum(supportedLibraries);
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
final String[][] JAVASCRIPT_SUPPORTING_FILES = new String[][]{
|
final String[][] JAVASCRIPT_SUPPORTING_FILES = new String[][]{
|
||||||
new String[]{"package.mustache", "package.json"},
|
new String[]{"package.mustache", "package.json"},
|
||||||
new String[]{"index.mustache", "src/index.js"},
|
// new String[]{"index.mustache", "src/index.js", },
|
||||||
new String[]{"ApiClient.mustache", "src/ApiClient.js"},
|
// new String[]{"ApiClient.mustache", "src/ApiClient.js"},
|
||||||
new String[]{"git_push.sh.mustache", "git_push.sh"},
|
new String[]{"git_push.sh.mustache", "git_push.sh"},
|
||||||
new String[]{"README.mustache", "README.md"},
|
new String[]{"README.mustache", "README.md"},
|
||||||
new String[]{"mocha.opts", "mocha.opts"},
|
new String[]{"mocha.opts", "mocha.opts"},
|
||||||
@@ -61,8 +61,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
final String[][] JAVASCRIPT_ES6_SUPPORTING_FILES = new String[][]{
|
final String[][] JAVASCRIPT_ES6_SUPPORTING_FILES = new String[][]{
|
||||||
new String[]{"package.mustache", "package.json"},
|
new String[]{"package.mustache", "package.json"},
|
||||||
new String[]{"index.mustache", "src/index.js"},
|
// new String[]{"index.mustache", "src/index.js"},
|
||||||
new String[]{"ApiClient.mustache", "src/ApiClient.js"},
|
// new String[]{"ApiClient.mustache", "src/ApiClient.js"},
|
||||||
new String[]{"git_push.sh.mustache", "git_push.sh"},
|
new String[]{"git_push.sh.mustache", "git_push.sh"},
|
||||||
new String[]{"README.mustache", "README.md"},
|
new String[]{"README.mustache", "README.md"},
|
||||||
new String[]{"mocha.opts", "mocha.opts"},
|
new String[]{"mocha.opts", "mocha.opts"},
|
||||||
@@ -85,7 +85,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
protected String modelDocPath = "docs/";
|
protected String modelDocPath = "docs/";
|
||||||
protected String apiTestPath = "api/";
|
protected String apiTestPath = "api/";
|
||||||
protected String modelTestPath = "model/";
|
protected String modelTestPath = "model/";
|
||||||
protected boolean useES6 = true; // default is ES5
|
protected boolean useES6 = true; // default is ES6
|
||||||
private String modelPropertyNaming = "camelCase";
|
private String modelPropertyNaming = "camelCase";
|
||||||
|
|
||||||
public JavascriptClientCodegen() {
|
public JavascriptClientCodegen() {
|
||||||
@@ -205,7 +205,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelp() {
|
public String getHelp() {
|
||||||
return "Generates a Javascript client library.";
|
return "Generates a JavaScript client library.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -337,6 +337,10 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
for (String[] supportingTemplateFile : supportingTemplateFiles) {
|
for (String[] supportingTemplateFile : supportingTemplateFiles) {
|
||||||
supportingFiles.add(new SupportingFile(supportingTemplateFile[0], "", supportingTemplateFile[1]));
|
supportingFiles.add(new SupportingFile(supportingTemplateFile[0], "", supportingTemplateFile[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("index.mustache", createPath(sourceFolder, invokerPackage), "index.js"));
|
||||||
|
supportingFiles.add(new SupportingFile("ApiClient.mustache", createPath(sourceFolder, invokerPackage), "ApiClient.js"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -373,12 +377,12 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiTestFileFolder() {
|
public String apiTestFileFolder() {
|
||||||
return (outputFolder + "/test/" + apiTestPath).replace('/', File.separatorChar);
|
return createPath(outputFolder, "test", invokerPackage, apiTestPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String modelTestFileFolder() {
|
public String modelTestFileFolder() {
|
||||||
return (outputFolder + "/test/" + modelTestPath).replace('/', File.separatorChar);
|
return createPath(outputFolder, "test", invokerPackage, modelTestPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -788,7 +792,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
* @param type Primitive type
|
* @param type Primitive type
|
||||||
* @return Normalized type
|
* @return Normalized type
|
||||||
*/
|
*/
|
||||||
public String normalizeType(String type) {
|
private String normalizeType(String type) {
|
||||||
return type.replaceAll("\\b(Boolean|Integer|Number|String|Date|Blob)\\b", "'$1'");
|
return type.replaceAll("\\b(Boolean|Integer|Number|String|Date|Blob)\\b", "'$1'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -867,10 +871,11 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
return codegenModel;
|
return codegenModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
private String sanitizePath(String p) {
|
private String sanitizePath(String p) {
|
||||||
//prefer replace a ', instead of a fuLL URL encode for readability
|
//prefer replace a ', instead of a fuLL URL encode for readability
|
||||||
return p.replaceAll("'", "%27");
|
return p.replaceAll("'", "%27");
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private String trimBrackets(String s) {
|
private String trimBrackets(String s) {
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
@@ -959,7 +964,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
if (operations != null) {
|
if (operations != null) {
|
||||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||||
for (CodegenOperation operation : ops) {
|
for (CodegenOperation operation : ops) {
|
||||||
List<String> argList = new ArrayList<String>();
|
List<String> argList = new ArrayList<>();
|
||||||
boolean hasOptionalParams = false;
|
boolean hasOptionalParams = false;
|
||||||
for (CodegenParameter p : operation.allParams) {
|
for (CodegenParameter p : operation.allParams) {
|
||||||
if (p.required) {
|
if (p.required) {
|
||||||
@@ -976,7 +981,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
if (hasOptionalParams) {
|
if (hasOptionalParams) {
|
||||||
argList.add("opts");
|
argList.add("opts");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!usePromises) {
|
if (!usePromises) {
|
||||||
argList.add("callback");
|
argList.add("callback");
|
||||||
@@ -1014,7 +1019,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
// NOTE: can't use 'mandatory' as it is built from ModelImpl.getRequired(), which sorts names
|
// NOTE: can't use 'mandatory' as it is built from ModelImpl.getRequired(), which sorts names
|
||||||
// alphabetically and in any case the document order of 'required' and 'properties' can differ.
|
// alphabetically and in any case the document order of 'required' and 'properties' can differ.
|
||||||
List<CodegenProperty> required = new ArrayList<>();
|
List<CodegenProperty> required = new ArrayList<>();
|
||||||
List<CodegenProperty> allRequired = supportsInheritance || supportsMixins ? new ArrayList<CodegenProperty>() : required;
|
List<CodegenProperty> allRequired = supportsInheritance || supportsMixins ? new ArrayList<>() : required;
|
||||||
cm.vendorExtensions.put("x-required", required);
|
cm.vendorExtensions.put("x-required", required);
|
||||||
cm.vendorExtensions.put("x-all-required", allRequired);
|
cm.vendorExtensions.put("x-all-required", allRequired);
|
||||||
|
|
||||||
@@ -1120,15 +1125,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
return codegenModel;
|
return codegenModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String sanitizePackageName(String packageName) { // FIXME parameter should not be assigned. Also declare it as "final"
|
|
||||||
packageName = packageName.trim();
|
|
||||||
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
|
|
||||||
if (Strings.isNullOrEmpty(packageName)) {
|
|
||||||
return "invalidPackageName";
|
|
||||||
}
|
|
||||||
return packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toEnumName(CodegenProperty property) {
|
public String toEnumName(CodegenProperty property) {
|
||||||
return sanitizeName(camelize(property.name)) + "Enum";
|
return sanitizeName(camelize(property.name)) + "Enum";
|
||||||
@@ -1160,12 +1156,18 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String escapeQuotationMark(String input) {
|
public String escapeQuotationMark(String input) {
|
||||||
|
if (input == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
// remove ', " to avoid code injection
|
// remove ', " to avoid code injection
|
||||||
return input.replace("\"", "").replace("'", "");
|
return input.replace("\"", "").replace("'", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String escapeUnsafeCharacters(String input) {
|
public String escapeUnsafeCharacters(String input) {
|
||||||
|
if (input == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,12 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||||
|
this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
|||||||
LoggerFactory.getLogger(KotlinSpringServerCodegen.class);
|
LoggerFactory.getLogger(KotlinSpringServerCodegen.class);
|
||||||
|
|
||||||
private static final HashSet<String> VARIABLE_RESERVED_WORDS =
|
private static final HashSet<String> VARIABLE_RESERVED_WORDS =
|
||||||
new HashSet<String>(Arrays.asList(
|
new HashSet<>(Arrays.asList(
|
||||||
"ApiClient",
|
"ApiClient",
|
||||||
"ApiException",
|
"ApiException",
|
||||||
"ApiResponse"
|
"ApiResponse"
|
||||||
@@ -109,6 +109,10 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
|||||||
importMapping.put("Date", "java.time.LocalDate");
|
importMapping.put("Date", "java.time.LocalDate");
|
||||||
importMapping.put("DateTime", "java.time.OffsetDateTime");
|
importMapping.put("DateTime", "java.time.OffsetDateTime");
|
||||||
|
|
||||||
|
// use resource for file handling
|
||||||
|
typeMapping.put("file", "org.springframework.core.io.Resource");
|
||||||
|
|
||||||
|
|
||||||
languageSpecificPrimitives.addAll(Arrays.asList(
|
languageSpecificPrimitives.addAll(Arrays.asList(
|
||||||
"Any",
|
"Any",
|
||||||
"Byte",
|
"Byte",
|
||||||
@@ -562,4 +566,33 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
|||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output the proper model name (capitalized).
|
||||||
|
* In case the name belongs to the TypeSystem it won't be renamed.
|
||||||
|
*
|
||||||
|
* @param name the name of the model
|
||||||
|
* @return capitalized model name
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toModelName(final String name) {
|
||||||
|
// Allow for explicitly configured spring.*
|
||||||
|
if (name.startsWith("org.springframework.") ) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
return super.toModelName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the type to see if it needs import the library/module/package
|
||||||
|
*
|
||||||
|
* @param type name of the type
|
||||||
|
* @return true if the library/module/package of the corresponding type needs to be imported
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean needToImport(String type) {
|
||||||
|
// provides extra protection against improperly trying to import language primitives and java types
|
||||||
|
boolean imports = !type.startsWith("org.springframework.") && super.needToImport(type);
|
||||||
|
return imports;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,153 @@
|
|||||||
|
/*
|
||||||
|
* 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 io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
|
import org.openapitools.codegen.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class NodeJSFastifyServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class);
|
||||||
|
|
||||||
|
protected String projectName = "openapi-server";
|
||||||
|
|
||||||
|
public NodeJSFastifyServerCodegen() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
outputFolder = "generated-code/nodejs-fastify";
|
||||||
|
|
||||||
|
modelTemplateFiles.clear();
|
||||||
|
apiTemplateFiles.clear();
|
||||||
|
|
||||||
|
embeddedTemplateDir = templateDir = "nodejs-fastify";
|
||||||
|
|
||||||
|
setReservedWordsLowerCase(
|
||||||
|
Arrays.asList(
|
||||||
|
"break", "case", "class", "catch", "const", "continue", "debugger",
|
||||||
|
"default", "delete", "do", "else", "export", "extends", "finally",
|
||||||
|
"for", "function", "if", "import", "in", "instanceof", "let", "new",
|
||||||
|
"return", "super", "switch", "this", "throw", "try", "typeof", "var",
|
||||||
|
"void", "while", "with", "yield")
|
||||||
|
);
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("index.mustache", "", "index.js"));
|
||||||
|
supportingFiles.add(new SupportingFile("readme.mustache", "", "README.md"));
|
||||||
|
supportingFiles.add(new SupportingFile("openapi.mustache", "", "openapi.json"));
|
||||||
|
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 "nodejs-fastify-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 NodeJS Fastify server library";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processOpts() {
|
||||||
|
super.processOpts();
|
||||||
|
|
||||||
|
writeOptional(outputFolder, new SupportingFile("service.mustache", "", "service.js"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||||
|
generateJSONSpecFile(objs);
|
||||||
|
|
||||||
|
return super.postProcessSupportingFileData(objs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||||
|
|
||||||
|
if (openAPI.getInfo() != null) {
|
||||||
|
Info info = openAPI.getInfo();
|
||||||
|
if (info.getTitle() != null) {
|
||||||
|
// when info.title is defined, use it for projectName
|
||||||
|
// used in package.json
|
||||||
|
projectName = info.getTitle()
|
||||||
|
.replaceAll("[^a-zA-Z0-9]", "-")
|
||||||
|
.replaceAll("^[-]*", "")
|
||||||
|
.replaceAll("[-]*$", "")
|
||||||
|
.replaceAll("[-]{2,}", "-")
|
||||||
|
.toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.additionalProperties.put("projectName", projectName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||||
|
* those terms here. This logic is only called if a variable matches the reserved words
|
||||||
|
*
|
||||||
|
* @return the escaped term
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String escapeReservedWord(String name) {
|
||||||
|
if (this.reservedWordsMappings().containsKey(name)) {
|
||||||
|
return this.reservedWordsMappings().get(name);
|
||||||
|
}
|
||||||
|
return "_" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeUnsafeCharacters(String input) {
|
||||||
|
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeQuotationMark(String input) {
|
||||||
|
// remove " to avoid code injection
|
||||||
|
return input.replace("\"", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -38,6 +38,8 @@ import java.util.*;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
|
|
||||||
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class);
|
||||||
@@ -160,7 +162,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return "DefaultController";
|
return "DefaultController";
|
||||||
}
|
}
|
||||||
return initialCaps(name);
|
return camelize(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
|
|
||||||
public class PhpSlimServerCodegen extends AbstractPhpCodegen {
|
public class PhpSlimServerCodegen extends AbstractPhpCodegen {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(PhpSlimServerCodegen.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(PhpSlimServerCodegen.class);
|
||||||
|
|
||||||
@@ -175,7 +177,7 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen {
|
|||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return toAbstractName("DefaultApi");
|
return toAbstractName("DefaultApi");
|
||||||
}
|
}
|
||||||
return toAbstractName(initialCaps(name) + "Api");
|
return toAbstractName(camelize(name) + "Api");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -183,7 +185,7 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen {
|
|||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return "DefaultApiTest";
|
return "DefaultApiTest";
|
||||||
}
|
}
|
||||||
return initialCaps(name) + "ApiTest";
|
return camelize(name) + "ApiTest";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -324,10 +324,10 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
// Fix path parameters to be in snake_case
|
// Fix path parameters to be in snake_case
|
||||||
if (pathname.contains("{")) {
|
if (pathname.contains("{")) {
|
||||||
String fixedPath = new String();
|
String fixedPath = new String();
|
||||||
for (String token: pathname.substring(1).split("/")) {
|
for (String token : pathname.substring(1).split("/")) {
|
||||||
if (token.startsWith("{")) {
|
if (token.startsWith("{")) {
|
||||||
String snake_case_token = "{" + this.toParamName(token.substring(1, token.length()-1)) + "}";
|
String snake_case_token = "{" + this.toParamName(token.substring(1, token.length() - 1)) + "}";
|
||||||
if(!token.equals(snake_case_token)) {
|
if (!token.equals(snake_case_token)) {
|
||||||
token = snake_case_token;
|
token = snake_case_token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -336,6 +336,7 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
if (!fixedPath.equals(pathname)) {
|
if (!fixedPath.equals(pathname)) {
|
||||||
LOGGER.warn("Path '" + pathname + "' is not consistant with Python variable names. It will be replaced by '" + fixedPath + "'");
|
LOGGER.warn("Path '" + pathname + "' is not consistant with Python variable names. It will be replaced by '" + fixedPath + "'");
|
||||||
paths.remove(pathname);
|
paths.remove(pathname);
|
||||||
|
path.addExtension("x-python-connexion-openapi-name", pathname);
|
||||||
paths.put(fixedPath, path);
|
paths.put(fixedPath, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,11 +360,12 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (operation.getParameters() != null) {
|
if (operation.getParameters() != null) {
|
||||||
for (Parameter parameter: operation.getParameters()) {
|
for (Parameter parameter : operation.getParameters()) {
|
||||||
String swaggerParameterName = parameter.getName();
|
String swaggerParameterName = parameter.getName();
|
||||||
String pythonParameterName = this.toParamName(swaggerParameterName);
|
String pythonParameterName = this.toParamName(swaggerParameterName);
|
||||||
if (!swaggerParameterName.equals(pythonParameterName)) {
|
if (!swaggerParameterName.equals(pythonParameterName)) {
|
||||||
LOGGER.warn("Parameter name '" + swaggerParameterName + "' is not consistant with Python variable names. It will be replaced by '" + pythonParameterName + "'");
|
LOGGER.warn("Parameter name '" + swaggerParameterName + "' is not consistant with Python variable names. It will be replaced by '" + pythonParameterName + "'");
|
||||||
|
parameter.addExtension("x-python-connexion-openapi-name", swaggerParameterName);
|
||||||
parameter.setName(pythonParameterName);
|
parameter.setName(pythonParameterName);
|
||||||
}
|
}
|
||||||
if (swaggerParameterName.isEmpty()) {
|
if (swaggerParameterName.isEmpty()) {
|
||||||
@@ -377,8 +379,7 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
String bodyParameterName = "body";
|
String bodyParameterName = "body";
|
||||||
if (operation.getExtensions() != null && operation.getExtensions().containsKey("x-codegen-request-body-name")) {
|
if (operation.getExtensions() != null && operation.getExtensions().containsKey("x-codegen-request-body-name")) {
|
||||||
bodyParameterName = (String) operation.getExtensions().get("x-codegen-request-body-name");
|
bodyParameterName = (String) operation.getExtensions().get("x-codegen-request-body-name");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Used by code generator
|
// Used by code generator
|
||||||
operation.addExtension("x-codegen-request-body-name", bodyParameterName);
|
operation.addExtension("x-codegen-request-body-name", bodyParameterName);
|
||||||
}
|
}
|
||||||
@@ -392,7 +393,7 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
// Sort path names after variable name fix
|
// Sort path names after variable name fix
|
||||||
List<String> fixedPathnames = new ArrayList(paths.keySet());
|
List<String> fixedPathnames = new ArrayList(paths.keySet());
|
||||||
Collections.sort(fixedPathnames);
|
Collections.sort(fixedPathnames);
|
||||||
for (String pathname: fixedPathnames) {
|
for (String pathname : fixedPathnames) {
|
||||||
PathItem pathItem = paths.remove(pathname);
|
PathItem pathItem = paths.remove(pathname);
|
||||||
paths.put(pathname, pathItem);
|
paths.put(pathname, pathItem);
|
||||||
}
|
}
|
||||||
@@ -401,7 +402,7 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addSecurityExtension(SecurityScheme securityScheme, String extensionName, String functionName) {
|
private void addSecurityExtension(SecurityScheme securityScheme, String extensionName, String functionName) {
|
||||||
if (securityScheme.getExtensions() == null || ! securityScheme.getExtensions().containsKey(extensionName)) {
|
if (securityScheme.getExtensions() == null || !securityScheme.getExtensions().containsKey(extensionName)) {
|
||||||
securityScheme.addExtension(extensionName, functionName);
|
securityScheme.addExtension(extensionName, functionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -410,18 +411,17 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
Components components = openAPI.getComponents();
|
Components components = openAPI.getComponents();
|
||||||
if (components != null && components.getSecuritySchemes() != null) {
|
if (components != null && components.getSecuritySchemes() != null) {
|
||||||
Map<String, SecurityScheme> securitySchemes = components.getSecuritySchemes();
|
Map<String, SecurityScheme> securitySchemes = components.getSecuritySchemes();
|
||||||
for(String securityName: securitySchemes.keySet()) {
|
for (String securityName : securitySchemes.keySet()) {
|
||||||
SecurityScheme securityScheme = securitySchemes.get(securityName);
|
SecurityScheme securityScheme = securitySchemes.get(securityName);
|
||||||
String baseFunctionName = controllerPackage + ".security_controller_.";
|
String baseFunctionName = controllerPackage + ".security_controller_.";
|
||||||
switch(securityScheme.getType()) {
|
switch (securityScheme.getType()) {
|
||||||
case APIKEY:
|
case APIKEY:
|
||||||
addSecurityExtension(securityScheme, "x-apikeyInfoFunc", baseFunctionName + "info_from_" + securityName);
|
addSecurityExtension(securityScheme, "x-apikeyInfoFunc", baseFunctionName + "info_from_" + securityName);
|
||||||
break;
|
break;
|
||||||
case HTTP:
|
case HTTP:
|
||||||
if ("basic".equals(securityScheme.getScheme())) {
|
if ("basic".equals(securityScheme.getScheme())) {
|
||||||
addSecurityExtension(securityScheme, "x-basicInfoFunc", baseFunctionName + "info_from_" + securityName);
|
addSecurityExtension(securityScheme, "x-basicInfoFunc", baseFunctionName + "info_from_" + securityName);
|
||||||
}
|
} else if ("bearer".equals(securityScheme.getScheme())) {
|
||||||
else if ("bearer".equals(securityScheme.getScheme())) {
|
|
||||||
addSecurityExtension(securityScheme, "x-bearerInfoFunc", baseFunctionName + "info_from_" + securityName);
|
addSecurityExtension(securityScheme, "x-bearerInfoFunc", baseFunctionName + "info_from_" + securityName);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -474,6 +474,68 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||||
|
// XXX - Revert the original parameter (and path) names to make sure we have
|
||||||
|
// a consistent REST interface across other server/client languages:
|
||||||
|
//
|
||||||
|
// XXX - Reverts `x-python-connexion-openapi-name` back to the original (query/path) parameter name.
|
||||||
|
// We do not want to have our REST API itself being converted to pythonic params.
|
||||||
|
// This would be incompatible with other server implementations.
|
||||||
|
OpenAPI openAPI = (OpenAPI) objs.get("openAPI");
|
||||||
|
Map<String, PathItem> paths = openAPI.getPaths();
|
||||||
|
if (paths != null) {
|
||||||
|
List<String> pathnames = new ArrayList(paths.keySet());
|
||||||
|
for (String pythonPathname : pathnames) {
|
||||||
|
PathItem path = paths.get(pythonPathname);
|
||||||
|
|
||||||
|
// Fix path parameters back to original casing
|
||||||
|
Map<String, Object> pathExtensions = path.getExtensions();
|
||||||
|
if (pathExtensions != null) {
|
||||||
|
// Get and remove the (temporary) vendor extension
|
||||||
|
String openapiPathname = (String) pathExtensions.remove("x-python-connexion-openapi-name");
|
||||||
|
if (openapiPathname != null && openapiPathname != pythonPathname) {
|
||||||
|
LOGGER.info("Path '" + pythonPathname + "' is not consistant with the original OpenAPI definition. It will be replaced back by '" + openapiPathname + "'");
|
||||||
|
paths.remove(pythonPathname);
|
||||||
|
paths.put(openapiPathname, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<HttpMethod, Operation> operationMap = path.readOperationsMap();
|
||||||
|
if (operationMap != null) {
|
||||||
|
for (HttpMethod method : operationMap.keySet()) {
|
||||||
|
Operation operation = operationMap.get(method);
|
||||||
|
if (operation.getParameters() != null) {
|
||||||
|
for (Parameter parameter : operation.getParameters()) {
|
||||||
|
Map<String, Object> parameterExtensions = parameter.getExtensions();
|
||||||
|
if (parameterExtensions != null) {
|
||||||
|
// Get and remove the (temporary) vendor extension
|
||||||
|
String swaggerParameterName = (String) parameterExtensions.remove("x-python-connexion-openapi-name");
|
||||||
|
if (swaggerParameterName != null) {
|
||||||
|
String pythonParameterName = parameter.getName();
|
||||||
|
if (swaggerParameterName != pythonParameterName) {
|
||||||
|
LOGGER.info("Reverting name of parameter '" + pythonParameterName + "' of operation '" + operation.getOperationId() + "' back to '" + swaggerParameterName + "'");
|
||||||
|
parameter.setName(swaggerParameterName);
|
||||||
|
} else {
|
||||||
|
LOGGER.debug("Name of parameter '" + pythonParameterName + "' of operation '" + operation.getOperationId() + "' was unchanged.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.debug("x-python-connexion-openapi-name was not set on parameter '" + parameter.getName() + "' of operation '" + operation.getOperationId() + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort path names after variable name fix
|
||||||
|
List<String> recoveredPathnames = new ArrayList(paths.keySet());
|
||||||
|
Collections.sort(recoveredPathnames);
|
||||||
|
for (String pathname : recoveredPathnames) {
|
||||||
|
PathItem pathItem = paths.remove(pathname);
|
||||||
|
paths.put(pathname, pathItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
generateYAMLSpecFile(objs);
|
generateYAMLSpecFile(objs);
|
||||||
|
|
||||||
for (Map<String, Object> operations : getOperations(objs)) {
|
for (Map<String, Object> operations : getOperations(objs)) {
|
||||||
@@ -581,6 +643,7 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the default value of the property
|
* Return the default value of the property
|
||||||
|
*
|
||||||
* @param p OpenAPI property object
|
* @param p OpenAPI property object
|
||||||
* @return string presentation of the default value of the property
|
* @return string presentation of the default value of the property
|
||||||
*/
|
*/
|
||||||
@@ -691,8 +754,7 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
if (example == null) {
|
if (example == null) {
|
||||||
if (Boolean.TRUE.equals(p.isListContainer)) {
|
if (Boolean.TRUE.equals(p.isListContainer)) {
|
||||||
example = "[]";
|
example = "[]";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
example = "None";
|
example = "None";
|
||||||
}
|
}
|
||||||
} else if (Boolean.TRUE.equals(p.isListContainer)) {
|
} else if (Boolean.TRUE.equals(p.isListContainer)) {
|
||||||
@@ -799,7 +861,7 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
for (CodegenOperation operation : operationList) {
|
for (CodegenOperation operation : operationList) {
|
||||||
Map<String, String> skipTests = new HashMap<>();
|
Map<String, String> skipTests = new HashMap<>();
|
||||||
// Set flag to deactivate tests due to connexion issue.
|
// Set flag to deactivate tests due to connexion issue.
|
||||||
if (operation.consumes != null ) {
|
if (operation.consumes != null) {
|
||||||
if (operation.consumes.size() == 1) {
|
if (operation.consumes.size() == 1) {
|
||||||
Map<String, String> consume = operation.consumes.get(0);
|
Map<String, String> consume = operation.consumes.get(0);
|
||||||
if (!("application/json".equals(consume.get(MEDIA_TYPE))
|
if (!("application/json".equals(consume.get(MEDIA_TYPE))
|
||||||
@@ -810,8 +872,7 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
operation.vendorExtensions.put("x-prefered-consume", consume);
|
operation.vendorExtensions.put("x-prefered-consume", consume);
|
||||||
}
|
} else if (operation.consumes.size() > 1) {
|
||||||
else if (operation.consumes.size() > 1) {
|
|
||||||
Map<String, String> consume = operation.consumes.get(0);
|
Map<String, String> consume = operation.consumes.get(0);
|
||||||
skipTests.put("reason", "Connexion does not support multiple consummes. See https://github.com/zalando/connexion/pull/760");
|
skipTests.put("reason", "Connexion does not support multiple consummes. See https://github.com/zalando/connexion/pull/760");
|
||||||
operation.vendorExtensions.put("x-prefered-consume", consume);
|
operation.vendorExtensions.put("x-prefered-consume", consume);
|
||||||
@@ -819,8 +880,7 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
operation.isMultipart = Boolean.TRUE;
|
operation.isMultipart = Boolean.TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// A body without consumes means '*/*' has been used instead of application/json
|
// A body without consumes means '*/*' has been used instead of application/json
|
||||||
if (operation.bodyParam != null) {
|
if (operation.bodyParam != null) {
|
||||||
Map<String, String> consume = new HashMap<>();
|
Map<String, String> consume = new HashMap<>();
|
||||||
@@ -830,19 +890,19 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Choose to consume 'application/json' if available, else choose the last one.
|
// Choose to consume 'application/json' if available, else choose the last one.
|
||||||
if (operation.produces != null ) {
|
if (operation.produces != null) {
|
||||||
for (Map<String, String> produce: operation.produces) {
|
for (Map<String, String> produce : operation.produces) {
|
||||||
operation.vendorExtensions.put("x-prefered-produce", produce);
|
operation.vendorExtensions.put("x-prefered-produce", produce);
|
||||||
if (produce.get(MEDIA_TYPE).equals("application/json")) {
|
if (produce.get(MEDIA_TYPE).equals("application/json")) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (! skipTests.isEmpty()) {
|
if (!skipTests.isEmpty()) {
|
||||||
operation.vendorExtensions.put("x-skip-test", skipTests);
|
operation.vendorExtensions.put("x-skip-test", skipTests);
|
||||||
}
|
}
|
||||||
if (operation.requestBodyExamples != null) {
|
if (operation.requestBodyExamples != null) {
|
||||||
for (Map<String, String> example: operation.requestBodyExamples) {
|
for (Map<String, String> example : operation.requestBodyExamples) {
|
||||||
if (example.get("contentType") != null && example.get("contentType").equals("application/json")) {
|
if (example.get("contentType") != null && example.get("contentType").equals("application/json")) {
|
||||||
operation.bodyParam.example = example.get("example");
|
operation.bodyParam.example = example.get("example");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,6 +238,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
supportingFiles.add(new SupportingFile("__init__package.mustache", packagePath(), "__init__.py"));
|
supportingFiles.add(new SupportingFile("__init__package.mustache", packagePath(), "__init__.py"));
|
||||||
supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + modelPackage, "__init__.py"));
|
supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + modelPackage, "__init__.py"));
|
||||||
supportingFiles.add(new SupportingFile("__init__api.mustache", packagePath() + File.separatorChar + apiPackage, "__init__.py"));
|
supportingFiles.add(new SupportingFile("__init__api.mustache", packagePath() + File.separatorChar + apiPackage, "__init__.py"));
|
||||||
|
supportingFiles.add(new SupportingFile("exceptions.mustache", packagePath(), "exceptions.py"));
|
||||||
|
|
||||||
if (Boolean.FALSE.equals(excludeTests)) {
|
if (Boolean.FALSE.equals(excludeTests)) {
|
||||||
supportingFiles.add(new SupportingFile("__init__test.mustache", testFolder, "__init__.py"));
|
supportingFiles.add(new SupportingFile("__init__test.mustache", testFolder, "__init__.py"));
|
||||||
|
|||||||
@@ -539,6 +539,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the default value of the property
|
* Return the default value of the property
|
||||||
|
*
|
||||||
* @param p OpenAPI property object
|
* @param p OpenAPI property object
|
||||||
* @return string presentation of the default value of the property
|
* @return string presentation of the default value of the property
|
||||||
*/
|
*/
|
||||||
@@ -581,7 +582,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiTestFileFolder() {
|
public String apiTestFileFolder() {
|
||||||
return outputFolder + File.separator + testFolder;
|
return outputFolder + File.separator + testFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -598,4 +599,88 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
public String toModelTestFilename(String name) {
|
public String toModelTestFilename(String name) {
|
||||||
return "test_" + toModelFilename(name);
|
return "test_" + toModelFilename(name);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||||
|
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||||
|
|
||||||
|
HashMap<String, CodegenModel> modelMaps = new HashMap<String, CodegenModel>();
|
||||||
|
for (Object o : allModels) {
|
||||||
|
HashMap<String, Object> h = (HashMap<String, Object>) o;
|
||||||
|
CodegenModel m = (CodegenModel) h.get("model");
|
||||||
|
modelMaps.put(m.classname, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||||
|
for (CodegenOperation operation : operations) {
|
||||||
|
for (CodegenParameter cp : operation.allParams) {
|
||||||
|
cp.vendorExtensions.put("x-r-example", constructExampleCode(cp, modelMaps));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return objs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String constructExampleCode(CodegenParameter codegenParameter, HashMap<String, CodegenModel> modelMaps) {
|
||||||
|
if (codegenParameter.isListContainer) { // array
|
||||||
|
return "list(" + constructExampleCode(codegenParameter.items, modelMaps) + ")";
|
||||||
|
} else if (codegenParameter.isMapContainer) { // TODO: map
|
||||||
|
return "TODO";
|
||||||
|
} else if (languageSpecificPrimitives.contains(codegenParameter.dataType)) { // primitive type
|
||||||
|
if ("character".equals(codegenParameter.dataType)) {
|
||||||
|
return codegenParameter.example;
|
||||||
|
} else {
|
||||||
|
return codegenParameter.example;
|
||||||
|
}
|
||||||
|
} else { // model
|
||||||
|
// look up the model
|
||||||
|
if (modelMaps.containsKey(codegenParameter.dataType)) {
|
||||||
|
return constructExampleCode(modelMaps.get(codegenParameter.dataType), modelMaps);
|
||||||
|
} else {
|
||||||
|
LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenParameter.dataType);
|
||||||
|
return "TODO";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String constructExampleCode(CodegenProperty codegenProperty, HashMap<String, CodegenModel> modelMaps) {
|
||||||
|
if (codegenProperty.isListContainer) { // array
|
||||||
|
return "list(" + constructExampleCode(codegenProperty.items, modelMaps) + ")";
|
||||||
|
} else if (codegenProperty.isMapContainer) { // TODO: map
|
||||||
|
return "TODO";
|
||||||
|
} else if (languageSpecificPrimitives.contains(codegenProperty.dataType)) { // primitive type
|
||||||
|
if ("character".equals(codegenProperty.dataType)) {
|
||||||
|
if (StringUtils.isEmpty(codegenProperty.example)) {
|
||||||
|
return "\"" + codegenProperty.example + "\"";
|
||||||
|
} else {
|
||||||
|
return "\"" + codegenProperty.name + "_example\"";
|
||||||
|
}
|
||||||
|
} else { // numeric
|
||||||
|
if (StringUtils.isEmpty(codegenProperty.example)) {
|
||||||
|
return codegenProperty.example;
|
||||||
|
} else {
|
||||||
|
return "123";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// look up the model
|
||||||
|
if (modelMaps.containsKey(codegenProperty.dataType)) {
|
||||||
|
return constructExampleCode(modelMaps.get(codegenProperty.dataType), modelMaps);
|
||||||
|
} else {
|
||||||
|
LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenProperty.dataType);
|
||||||
|
return "TODO";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String constructExampleCode(CodegenModel codegenModel, HashMap<String, CodegenModel> modelMaps) {
|
||||||
|
String example;
|
||||||
|
example = codegenModel.name + "$new(";
|
||||||
|
List<String> propertyExamples = new ArrayList<>();
|
||||||
|
for (CodegenProperty codegenProperty : codegenModel.vars) {
|
||||||
|
propertyExamples.add(constructExampleCode(codegenProperty, modelMaps));
|
||||||
|
}
|
||||||
|
example += StringUtils.join(propertyExamples, ", ");
|
||||||
|
example += ")";
|
||||||
|
return example;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -732,6 +732,14 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
header.nameInCamelCase = toModelName(header.baseName);
|
header.nameInCamelCase = toModelName(header.baseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (op.authMethods != null) {
|
||||||
|
for (CodegenSecurity s : op.authMethods) {
|
||||||
|
if (s.isApiKey && s.isKeyInHeader) {
|
||||||
|
s.vendorExtensions.put("x-apiKeyName", toModelName(s.keyParamName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return objs;
|
return objs;
|
||||||
|
|||||||
@@ -49,13 +49,7 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
|
|||||||
protected boolean registerNonStandardStatusCodes = true;
|
protected boolean registerNonStandardStatusCodes = true;
|
||||||
protected boolean renderJavadoc = true;
|
protected boolean renderJavadoc = true;
|
||||||
protected boolean removeOAuthSecurities = true;
|
protected boolean removeOAuthSecurities = true;
|
||||||
/**
|
|
||||||
* If set to true, only the default response (the one with le lowest 2XX code) will be considered as a success, and all
|
|
||||||
* others as ApiErrors.
|
|
||||||
* If set to false, all responses defined in the model will be considered as a success upon reception. Only http errors,
|
|
||||||
* unmarshalling problems and any other RuntimeException will be considered as ApiErrors.
|
|
||||||
*/
|
|
||||||
protected boolean onlyOneSuccess = true;
|
|
||||||
|
|
||||||
@SuppressWarnings("hiding")
|
@SuppressWarnings("hiding")
|
||||||
protected Logger LOGGER = LoggerFactory.getLogger(ScalaAkkaClientCodegen.class);
|
protected Logger LOGGER = LoggerFactory.getLogger(ScalaAkkaClientCodegen.class);
|
||||||
@@ -92,7 +86,6 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
|
|||||||
additionalProperties.put("fnCapitalize", new CapitalizeLambda());
|
additionalProperties.put("fnCapitalize", new CapitalizeLambda());
|
||||||
additionalProperties.put("fnCamelize", new CamelizeLambda(false));
|
additionalProperties.put("fnCamelize", new CamelizeLambda(false));
|
||||||
additionalProperties.put("fnEnumEntry", new EnumEntryLambda());
|
additionalProperties.put("fnEnumEntry", new EnumEntryLambda());
|
||||||
additionalProperties.put("onlyOneSuccess", onlyOneSuccess);
|
|
||||||
additionalProperties.put("mainPackage", mainPackage);
|
additionalProperties.put("mainPackage", mainPackage);
|
||||||
|
|
||||||
importMapping.remove("Seq");
|
importMapping.remove("Seq");
|
||||||
@@ -235,16 +228,6 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
|
|||||||
return codegenSecurities;
|
return codegenSecurities;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toOperationId(String operationId) {
|
|
||||||
// throw exception if method name is empty
|
|
||||||
if (StringUtils.isEmpty(operationId)) {
|
|
||||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.toOperationId(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, operationId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toParamName(String name) {
|
public String toParamName(String name) {
|
||||||
return formatIdentifier(name, false);
|
return formatIdentifier(name, false);
|
||||||
|
|||||||
@@ -0,0 +1,417 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.google.common.collect.ImmutableMap;
|
||||||
|
import com.samskivert.mustache.Mustache;
|
||||||
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
|
import org.openapitools.codegen.*;
|
||||||
|
import org.openapitools.codegen.mustache.*;
|
||||||
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.StringUtils.rightPad;
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||||
|
|
||||||
|
public class ScalaPlayFrameworkServerCodegen extends AbstractScalaCodegen implements CodegenConfig {
|
||||||
|
public static final String TITLE = "title";
|
||||||
|
public static final String SKIP_STUBS = "skipStubs";
|
||||||
|
public static final String SUPPORT_ASYNC = "supportAsync";
|
||||||
|
public static final String GENERATE_CUSTOM_EXCEPTIONS = "generateCustomExceptions";
|
||||||
|
public static final String USE_SWAGGER_UI = "useSwaggerUI";
|
||||||
|
public static final String ROUTES_FILE_NAME = "routesFileName";
|
||||||
|
public static final String BASE_PACKAGE = "basePackage";
|
||||||
|
|
||||||
|
static Logger LOGGER = LoggerFactory.getLogger(ScalaPlayFrameworkServerCodegen.class);
|
||||||
|
|
||||||
|
protected boolean skipStubs = false;
|
||||||
|
protected boolean supportAsync = false;
|
||||||
|
protected boolean generateCustomExceptions = true;
|
||||||
|
protected boolean useSwaggerUI = true;
|
||||||
|
protected String routesFileName = "routes";
|
||||||
|
protected String basePackage = "org.openapitools";
|
||||||
|
|
||||||
|
public ScalaPlayFrameworkServerCodegen() {
|
||||||
|
super();
|
||||||
|
outputFolder = "generated-code" + File.separator + "scala-play-server";
|
||||||
|
modelTemplateFiles.put("model.mustache", ".scala");
|
||||||
|
apiTemplateFiles.put("api.mustache", ".scala");
|
||||||
|
embeddedTemplateDir = templateDir = "scala-play-server";
|
||||||
|
hideGenerationTimestamp = false;
|
||||||
|
sourceFolder = "app";
|
||||||
|
apiPackage = "api";
|
||||||
|
modelPackage = "model";
|
||||||
|
|
||||||
|
instantiationTypes.put("map", "Map");
|
||||||
|
instantiationTypes.put("array", "List");
|
||||||
|
|
||||||
|
typeMapping.put("DateTime", "OffsetDateTime");
|
||||||
|
typeMapping.put("Date", "LocalDate");
|
||||||
|
typeMapping.put("Integer", "Int");
|
||||||
|
typeMapping.put("binary", "Array[Byte]");
|
||||||
|
typeMapping.put("ByteArray", "Array[Byte]");
|
||||||
|
typeMapping.put("object", "JsObject");
|
||||||
|
typeMapping.put("file", "TemporaryFile");
|
||||||
|
|
||||||
|
importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
|
||||||
|
importMapping.put("LocalDate", "java.time.LocalDate");
|
||||||
|
importMapping.remove("BigDecimal");
|
||||||
|
importMapping.put("TemporaryFile", "play.api.libs.Files.TemporaryFile");
|
||||||
|
|
||||||
|
cliOptions.add(new CliOption(ROUTES_FILE_NAME, "Name of the routes file to generate.").defaultValue(routesFileName));
|
||||||
|
cliOptions.add(new CliOption(ROUTES_FILE_NAME, "Base package in which supporting classes are generated.").defaultValue(basePackage));
|
||||||
|
|
||||||
|
addCliOptionWithDefault(SKIP_STUBS, "If set, skips generation of stub classes.", skipStubs);
|
||||||
|
addCliOptionWithDefault(SUPPORT_ASYNC, "If set, wraps API return types with Futures and generates async actions.", supportAsync);
|
||||||
|
addCliOptionWithDefault(GENERATE_CUSTOM_EXCEPTIONS, "If set, generates custom exception types.", generateCustomExceptions);
|
||||||
|
addCliOptionWithDefault(USE_SWAGGER_UI, "Add a route to /api which show your documentation in swagger-ui. Will also import needed dependencies", useSwaggerUI);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CodegenType getTag() {
|
||||||
|
return CodegenType.SERVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "scala-play-server";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHelp() {
|
||||||
|
return "Generates a Scala server application (beta) with Play Framework.";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSupportAsync(boolean supportAsync) {
|
||||||
|
this.supportAsync = supportAsync;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSkipStubs(boolean skipStubs) {
|
||||||
|
this.skipStubs = skipStubs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGenerateCustomExceptions(boolean generateCustomExceptions) {
|
||||||
|
this.generateCustomExceptions = generateCustomExceptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoutesFileName(String routesFileName) {
|
||||||
|
this.routesFileName = routesFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBasePackage(String basePackage) {
|
||||||
|
this.basePackage = basePackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseSwaggerUI(boolean useSwaggerUI) {
|
||||||
|
this.useSwaggerUI = useSwaggerUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processOpts() {
|
||||||
|
super.processOpts();
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(SKIP_STUBS)) {
|
||||||
|
this.setSkipStubs(convertPropertyToBoolean(SKIP_STUBS));
|
||||||
|
}
|
||||||
|
writePropertyBack(SKIP_STUBS, skipStubs);
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(SUPPORT_ASYNC)) {
|
||||||
|
this.setSupportAsync(convertPropertyToBoolean(SUPPORT_ASYNC));
|
||||||
|
}
|
||||||
|
writePropertyBack(SUPPORT_ASYNC, supportAsync);
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(GENERATE_CUSTOM_EXCEPTIONS)) {
|
||||||
|
this.setGenerateCustomExceptions(convertPropertyToBoolean(GENERATE_CUSTOM_EXCEPTIONS));
|
||||||
|
}
|
||||||
|
writePropertyBack(GENERATE_CUSTOM_EXCEPTIONS, generateCustomExceptions);
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(USE_SWAGGER_UI)) {
|
||||||
|
this.setUseSwaggerUI(convertPropertyToBoolean(USE_SWAGGER_UI));
|
||||||
|
}
|
||||||
|
writePropertyBack(USE_SWAGGER_UI, useSwaggerUI);
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(ROUTES_FILE_NAME)) {
|
||||||
|
this.setRoutesFileName((String) additionalProperties.get(ROUTES_FILE_NAME));
|
||||||
|
} else {
|
||||||
|
additionalProperties.put(ROUTES_FILE_NAME, routesFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(BASE_PACKAGE)) {
|
||||||
|
this.setBasePackage((String) additionalProperties.get(BASE_PACKAGE));
|
||||||
|
} else {
|
||||||
|
additionalProperties.put(BASE_PACKAGE, basePackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
apiTemplateFiles.remove("api.mustache");
|
||||||
|
|
||||||
|
if (!skipStubs) {
|
||||||
|
apiTemplateFiles.put("app/apiImplStubs.scala.mustache", "Impl.scala");
|
||||||
|
}
|
||||||
|
|
||||||
|
apiTemplateFiles.put("app/apiTrait.scala.mustache", ".scala");
|
||||||
|
apiTemplateFiles.put("app/apiController.scala.mustache", "Controller.scala");
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("README.md.mustache", "", "README.md"));
|
||||||
|
supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt"));
|
||||||
|
supportingFiles.add(new SupportingFile("conf/application.conf.mustache", "conf", "application.conf"));
|
||||||
|
supportingFiles.add(new SupportingFile("conf/logback.xml.mustache", "conf", "logback.xml"));
|
||||||
|
supportingFiles.add(new SupportingFile("project/build.properties.mustache", "project", "build.properties"));
|
||||||
|
supportingFiles.add(new SupportingFile("project/plugins.sbt.mustache", "project", "plugins.sbt"));
|
||||||
|
supportingFiles.add(new SupportingFile("conf/routes.mustache", "conf", routesFileName));
|
||||||
|
supportingFiles.add(new SupportingFile("app/module.scala.mustache", getBasePackagePath(), "Module.scala"));
|
||||||
|
supportingFiles.add(new SupportingFile("app/errorHandler.scala.mustache", getBasePackagePath(), "ErrorHandler.scala"));
|
||||||
|
|
||||||
|
if (generateCustomExceptions) {
|
||||||
|
supportingFiles.add(new SupportingFile("app/exceptions.scala.mustache", getBasePackagePath(), "OpenApiExceptions.scala"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.useSwaggerUI) {
|
||||||
|
//App/Controllers
|
||||||
|
supportingFiles.add(new SupportingFile("public/openapi.json.mustache", "public", "openapi.json"));
|
||||||
|
supportingFiles.add(new SupportingFile("app/apiDocController.scala.mustache", String.format(Locale.ROOT, "app/%s", apiPackage.replace(".", File.separator)), "ApiDocController.scala"));
|
||||||
|
}
|
||||||
|
addMustacheLambdas(additionalProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMustacheLambdas(Map<String, Object> objs) {
|
||||||
|
Map<String, Mustache.Lambda> lambdas = new ImmutableMap.Builder<String, Mustache.Lambda>()
|
||||||
|
.put("indented_4", new IndentedLambda(4, " "))
|
||||||
|
.put("indented_8", new IndentedLambda(8, " "))
|
||||||
|
.build();
|
||||||
|
objs.put("lambda", lambdas);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||||
|
Map<String, CodegenModel> models = new HashMap<>();
|
||||||
|
|
||||||
|
for (Object _mo : allModels) {
|
||||||
|
CodegenModel model = (CodegenModel) ((Map<String, Object>) _mo).get("model");
|
||||||
|
models.put(model.classname, model);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||||
|
if (operations != null) {
|
||||||
|
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||||
|
for (CodegenOperation operation : ops) {
|
||||||
|
Pattern pathVariableMatcher = Pattern.compile("\\{([^}]+)}");
|
||||||
|
Matcher match = pathVariableMatcher.matcher(operation.path);
|
||||||
|
while (match.find()) {
|
||||||
|
String completeMatch = match.group();
|
||||||
|
String replacement = ":" + camelize(match.group(1), true);
|
||||||
|
operation.path = operation.path.replace(completeMatch, replacement);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("null".equals(operation.defaultResponse) && models.containsKey(operation.returnType)) {
|
||||||
|
operation.defaultResponse = models.get(operation.returnType).defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return objs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
|
||||||
|
objs = super.postProcessAllModels(objs);
|
||||||
|
Map<String, CodegenModel> modelsByClassName = new HashMap<>();
|
||||||
|
|
||||||
|
for (Object _outer : objs.values()) {
|
||||||
|
Map<String, Object> outer = (Map<String, Object>) _outer;
|
||||||
|
List<Map<String, Object>> models = (List<Map<String, Object>>) outer.get("models");
|
||||||
|
|
||||||
|
for (Map<String, Object> mo : models) {
|
||||||
|
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||||
|
postProcessModelsEnum(outer);
|
||||||
|
cm.classVarName = camelize(cm.classVarName, true);
|
||||||
|
modelsByClassName.put(cm.classname, cm);
|
||||||
|
boolean hasFiles = cm.vars.stream().anyMatch(var -> var.isFile);
|
||||||
|
cm.vendorExtensions.put("hasFiles", hasFiles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CodegenModel model : modelsByClassName.values()) {
|
||||||
|
model.defaultValue = generateModelDefaultValue(model, modelsByClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return objs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||||
|
objs = super.postProcessSupportingFileData(objs);
|
||||||
|
generateJSONSpecFile(objs);
|
||||||
|
|
||||||
|
// Prettify routes file
|
||||||
|
Map<String, Object> apiInfo = (Map<String, Object>) objs.get("apiInfo");
|
||||||
|
List<Map<String, Object>> apis = (List<Map<String, Object>>) apiInfo.get("apis");
|
||||||
|
List<CodegenOperation> ops = apis.stream()
|
||||||
|
.map(api -> (Map<String, Object>) api.get("operations"))
|
||||||
|
.flatMap(operations -> ((List<CodegenOperation>) operations.get("operation")).stream())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
int maxPathLength = ops.stream()
|
||||||
|
.mapToInt(op -> op.httpMethod.length() + op.path.length())
|
||||||
|
.reduce(0, Integer::max);
|
||||||
|
ops.forEach(op -> op.vendorExtensions.put("paddedPath", rightPad(op.path, maxPathLength - op.httpMethod.length())));
|
||||||
|
ops.forEach(op -> op.vendorExtensions.put("hasPathParams", op.getHasPathParams()));
|
||||||
|
|
||||||
|
return objs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSchemaType(Schema p) {
|
||||||
|
String openAPIType = super.getSchemaType(p);
|
||||||
|
openAPIType = getAlias(openAPIType);
|
||||||
|
|
||||||
|
// don't apply renaming on types from the typeMapping
|
||||||
|
if (typeMapping.containsKey(openAPIType)) {
|
||||||
|
return typeMapping.get(openAPIType);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == openAPIType) {
|
||||||
|
LOGGER.error("No Type defined for Schema " + p);
|
||||||
|
}
|
||||||
|
return toModelName(openAPIType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toDefaultValue(Schema p) {
|
||||||
|
if (p.getRequired() != null && p.getRequired().contains(p.getName())) {
|
||||||
|
return "None";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p.getDefault() != null) {
|
||||||
|
return p.getDefault().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelUtils.isBooleanSchema(p)) {
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelUtils.isDateSchema(p)) {
|
||||||
|
return "LocalDate.now";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelUtils.isDateTimeSchema(p)) {
|
||||||
|
return "OffsetDateTime.now";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelUtils.isDoubleSchema(p)) {
|
||||||
|
return "0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelUtils.isFloatSchema(p)) {
|
||||||
|
return "0.0F";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelUtils.isIntegerSchema(p)) {
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelUtils.isLongSchema(p)) {
|
||||||
|
return "0L";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelUtils.isStringSchema(p)) {
|
||||||
|
return "\"\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelUtils.isMapSchema(p)) {
|
||||||
|
Schema ap = ModelUtils.getAdditionalProperties(p);
|
||||||
|
String inner = getSchemaType(ap);
|
||||||
|
return "Map.empty[String, " + inner + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelUtils.isArraySchema(p)) {
|
||||||
|
Schema items = ((ArraySchema) p).getItems();
|
||||||
|
String inner = getSchemaType(items);
|
||||||
|
return "List.empty[" + inner + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumName(CodegenProperty property) {
|
||||||
|
return camelize(property.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumVarName(String value, String datatype) {
|
||||||
|
if (value.length() == 0) {
|
||||||
|
return "EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
String var = camelize(value.replaceAll("\\W+", "_"));
|
||||||
|
if (var.matches("\\d.*")) {
|
||||||
|
return "_" + var;
|
||||||
|
} else {
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addCliOptionWithDefault(String name, String description, boolean defaultValue) {
|
||||||
|
cliOptions.add(CliOption.newBoolean(name, description).defaultValue(Boolean.toString(defaultValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getBasePackagePath() {
|
||||||
|
return String.format(Locale.ROOT, "%s/%s", sourceFolder, basePackage.replace(".", File.separator));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateModelDefaultValue(CodegenModel cm, Map<String, CodegenModel> models) {
|
||||||
|
StringBuilder defaultValue = new StringBuilder();
|
||||||
|
defaultValue.append(cm.classname).append('(');
|
||||||
|
|
||||||
|
for (CodegenProperty var : cm.vars) {
|
||||||
|
if (!var.required) {
|
||||||
|
defaultValue.append("None");
|
||||||
|
} else if (models.containsKey(var.dataType)) {
|
||||||
|
defaultValue.append(generateModelDefaultValue(models.get(var.dataType), models));
|
||||||
|
} else if (var.defaultValue != null) {
|
||||||
|
defaultValue.append(var.defaultValue);
|
||||||
|
} else if (var.isEnum) {
|
||||||
|
defaultValue.append(cm.classname).append('.').append(var.enumName).append(".values.head");
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("Unknown default value for var {0} in class {1}", var.name, cm.classname);
|
||||||
|
defaultValue.append("null");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (var.hasMore) {
|
||||||
|
defaultValue.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cm.isMapModel) {
|
||||||
|
defaultValue.append(", Map.empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultValue.append(')');
|
||||||
|
|
||||||
|
return defaultValue.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -443,7 +443,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
public String toApiName(String name) {
|
public String toApiName(String name) {
|
||||||
if (name.length() == 0)
|
if (name.length() == 0)
|
||||||
return "DefaultAPI";
|
return "DefaultAPI";
|
||||||
return initialCaps(name) + "API";
|
return camelize(name) + "API";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -552,7 +552,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return "DefaultAPI";
|
return "DefaultAPI";
|
||||||
}
|
}
|
||||||
return initialCaps(name) + "API";
|
return camelize(name) + "API";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -434,7 +434,7 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
public String toApiName(String name) {
|
public String toApiName(String name) {
|
||||||
if (name.length() == 0)
|
if (name.length() == 0)
|
||||||
return "DefaultAPI";
|
return "DefaultAPI";
|
||||||
return initialCaps(name) + "API";
|
return camelize(name) + "API";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ import io.swagger.v3.parser.util.SchemaTypeUtil;
|
|||||||
import org.openapitools.codegen.*;
|
import org.openapitools.codegen.*;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
import org.openapitools.codegen.utils.SemVer;
|
import org.openapitools.codegen.utils.SemVer;
|
||||||
|
import org.openapitools.codegen.utils.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
@@ -208,9 +208,13 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
this.setNpmVersion(this.getVersionFromApi());
|
this.setNpmVersion(this.getVersionFromApi());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT)
|
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||||
&& Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
@@ -445,9 +449,9 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
/**
|
/**
|
||||||
* Finds and returns a path parameter of an operation by its name
|
* Finds and returns a path parameter of an operation by its name
|
||||||
*
|
*
|
||||||
* @param operation
|
* @param operation the operation
|
||||||
* @param parameterName
|
* @param parameterName the name of the parameter
|
||||||
* @return
|
* @return param
|
||||||
*/
|
*/
|
||||||
private CodegenParameter findPathParameterByName(CodegenOperation operation, String parameterName) {
|
private CodegenParameter findPathParameterByName(CodegenOperation operation, String parameterName) {
|
||||||
for (CodegenParameter param : operation.pathParams) {
|
for (CodegenParameter param : operation.pathParams) {
|
||||||
@@ -509,7 +513,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return "DefaultService";
|
return "DefaultService";
|
||||||
}
|
}
|
||||||
return initialCaps(name) + serviceSuffix;
|
return camelize(name) + serviceSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -564,6 +568,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
return toApiFilename(name);
|
return toApiFilename(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
private String getModelnameFromModelFilename(String filename) {
|
private String getModelnameFromModelFilename(String filename) {
|
||||||
String name = filename.substring((modelPackage() + "/").length());
|
String name = filename.substring((modelPackage() + "/").length());
|
||||||
// Remove the file suffix and add the class suffix.
|
// Remove the file suffix and add the class suffix.
|
||||||
@@ -574,6 +579,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
}
|
}
|
||||||
return camelize(name) + modelSuffix;
|
return camelize(name) + modelSuffix;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelName(String name) {
|
public String toModelName(String name) {
|
||||||
@@ -654,7 +660,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
/**
|
/**
|
||||||
* Returns version from OpenAPI info.
|
* Returns version from OpenAPI info.
|
||||||
*
|
*
|
||||||
* @return
|
* @return version
|
||||||
*/
|
*/
|
||||||
private String getVersionFromApi() {
|
private String getVersionFromApi() {
|
||||||
if (this.openAPI != null && this.openAPI.getInfo() != null) {
|
if (this.openAPI != null && this.openAPI.getInfo() != null) {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class TypeScriptAngularJsClientCodegen extends AbstractTypeScriptClientCo
|
|||||||
@Override
|
@Override
|
||||||
public void postProcessParameter(CodegenParameter parameter) {
|
public void postProcessParameter(CodegenParameter parameter) {
|
||||||
super.postProcessParameter(parameter);
|
super.postProcessParameter(parameter);
|
||||||
parameter.dataType = addModelPrefix(parameter.dataType);
|
// parameter.dataType = addModelPrefix(parameter.dataType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIndexDirectory() {
|
private String getIndexDirectory() {
|
||||||
|
|||||||
@@ -18,9 +18,12 @@
|
|||||||
package org.openapitools.codegen.languages;
|
package org.openapitools.codegen.languages;
|
||||||
|
|
||||||
import org.openapitools.codegen.*;
|
import org.openapitools.codegen.*;
|
||||||
|
import org.openapitools.codegen.utils.StringUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
|
|
||||||
public class TypeScriptAureliaClientCodegen extends AbstractTypeScriptClientCodegen {
|
public class TypeScriptAureliaClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||||
|
|
||||||
public static final String NPM_NAME = "npmName";
|
public static final String NPM_NAME = "npmName";
|
||||||
@@ -104,7 +107,7 @@ public class TypeScriptAureliaClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||||
for (CodegenOperation op : operationList) {
|
for (CodegenOperation op : operationList) {
|
||||||
// Aurelia uses "asGet", "asPost", ... methods; change the method format
|
// Aurelia uses "asGet", "asPost", ... methods; change the method format
|
||||||
op.httpMethod = initialCaps(op.httpMethod.toLowerCase(Locale.ROOT));
|
op.httpMethod = camelize(op.httpMethod.toLowerCase(Locale.ROOT));
|
||||||
|
|
||||||
// Collect models to be imported
|
// Collect models to be imported
|
||||||
for (CodegenParameter param : op.allParams) {
|
for (CodegenParameter param : op.allParams) {
|
||||||
|
|||||||
@@ -231,7 +231,12 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||||
|
this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,12 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||||
|
this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import io.swagger.v3.oas.models.media.Schema;
|
|||||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||||
import org.openapitools.codegen.*;
|
import org.openapitools.codegen.*;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
|
import org.openapitools.codegen.utils.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@@ -129,9 +130,13 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo
|
|||||||
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
|
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT)
|
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||||
&& Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
@@ -317,7 +322,7 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo
|
|||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return "DefaultService";
|
return "DefaultService";
|
||||||
}
|
}
|
||||||
return initialCaps(name) + "Service";
|
return camelize(name) + "Service";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -181,7 +181,12 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||||
|
this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import io.swagger.v3.oas.models.media.Schema;
|
|||||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||||
import org.openapitools.codegen.*;
|
import org.openapitools.codegen.*;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
|
import org.openapitools.codegen.utils.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -98,7 +99,7 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
|||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return "Default" + apiSuffix;
|
return "Default" + apiSuffix;
|
||||||
}
|
}
|
||||||
return initialCaps(name) + apiSuffix;
|
return camelize(name) + apiSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -232,7 +233,12 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||||
|
this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,12 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||||
|
this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||||
|
|
||||||
|
|||||||
@@ -14,19 +14,20 @@ public class ProcessUtils {
|
|||||||
* Add x-index extension to the model's properties
|
* Add x-index extension to the model's properties
|
||||||
*
|
*
|
||||||
* @param models List of models
|
* @param models List of models
|
||||||
|
* @param initialIndex starting index to use
|
||||||
*/
|
*/
|
||||||
public static void addIndexToProperties(List<Object> models) {
|
public static void addIndexToProperties(List<Object> models, int initialIndex) {
|
||||||
for (Object _mo : models) {
|
for (Object _mo : models) {
|
||||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||||
|
|
||||||
int i = 0;
|
int i = initialIndex;
|
||||||
for (CodegenProperty var : cm.vars) {
|
for (CodegenProperty var : cm.vars) {
|
||||||
var.vendorExtensions.put("x-index", i);
|
var.vendorExtensions.put("x-index", i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int j = 0;
|
int j = initialIndex;
|
||||||
for (CodegenProperty var : cm.allVars) {
|
for (CodegenProperty var : cm.allVars) {
|
||||||
var.vendorExtensions.put("x-index", j);
|
var.vendorExtensions.put("x-index", j);
|
||||||
j++;
|
j++;
|
||||||
@@ -36,6 +37,15 @@ public class ProcessUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add x-index extension to the model's properties
|
||||||
|
*
|
||||||
|
* @param models List of models
|
||||||
|
*/
|
||||||
|
public static void addIndexToProperties(List<Object> models) {
|
||||||
|
addIndexToProperties(models, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if at least one operation has OAuth security schema defined
|
* Returns true if at least one operation has OAuth security schema defined
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -15,22 +15,22 @@ public class StringUtils {
|
|||||||
* @param word The word
|
* @param word The word
|
||||||
* @return The underscored version of the word
|
* @return The underscored version of the word
|
||||||
*/
|
*/
|
||||||
public static String underscore(String word) {
|
public static String underscore(final String word) {
|
||||||
String firstPattern = "([A-Z]+)([A-Z][a-z])";
|
String firstPattern = "([A-Z]+)([A-Z][a-z])";
|
||||||
String secondPattern = "([a-z\\d])([A-Z])";
|
String secondPattern = "([a-z\\d])([A-Z])";
|
||||||
String replacementPattern = "$1_$2";
|
String replacementPattern = "$1_$2";
|
||||||
// Replace package separator with slash.
|
// Replace package separator with slash.
|
||||||
word = word.replaceAll("\\.", "/"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
String result = word.replaceAll("\\.", "/");
|
||||||
// Replace $ with two underscores for inner classes.
|
// Replace $ with two underscores for inner classes.
|
||||||
word = word.replaceAll("\\$", "__");
|
result = result.replaceAll("\\$", "__");
|
||||||
// Replace capital letter with _ plus lowercase letter.
|
// Replace capital letter with _ plus lowercase letter.
|
||||||
word = word.replaceAll(firstPattern, replacementPattern);
|
result = result.replaceAll(firstPattern, replacementPattern);
|
||||||
word = word.replaceAll(secondPattern, replacementPattern);
|
result = result.replaceAll(secondPattern, replacementPattern);
|
||||||
word = word.replace('-', '_');
|
result = result.replace('-', '_');
|
||||||
// replace space with underscore
|
// replace space with underscore
|
||||||
word = word.replace(' ', '_');
|
result = result.replace(' ', '_');
|
||||||
word = word.toLowerCase(Locale.ROOT);
|
result = result.toLowerCase(Locale.ROOT);
|
||||||
return word;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,13 +14,14 @@ the [Swagger Ada library](https://github.com/stcarrez/swagger-ada).
|
|||||||
When the GNAT Ada compiler and Swagger Ada libraries are installed,
|
When the GNAT Ada compiler and Swagger Ada libraries are installed,
|
||||||
run the following command:
|
run the following command:
|
||||||
|
|
||||||
```
|
```shell
|
||||||
gprbuild -p -P{{projectName}}
|
gprbuild -p -P{{projectName}}
|
||||||
```
|
```
|
||||||
|
|
||||||
After the build is successful, you will get the server binary
|
After the build is successful, you will get the server binary
|
||||||
in bin/{{packageName}}-server and you can start it as follows:
|
in bin/{{packageName}}-server and you can start it as follows:
|
||||||
```
|
|
||||||
|
```shell
|
||||||
./bin/{{packageName}}-server
|
./bin/{{packageName}}-server
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -51,8 +52,8 @@ The server instance is represented by the **{{package}}.Servers.Server_Type** Ad
|
|||||||
The REST API will need an instance of it to make the operation call. Two server model
|
The REST API will need an instance of it to make the operation call. Two server model
|
||||||
exists:
|
exists:
|
||||||
|
|
||||||
* The instance per request model creates an instance of the server type for each request.
|
- The instance per request model creates an instance of the server type for each request.
|
||||||
* The shared instance model shares the same instance across all concurrent REST requests. This instance is protected using an Ada protected object which holds the server instance.
|
- The shared instance model shares the same instance across all concurrent REST requests. This instance is protected using an Ada protected object which holds the server instance.
|
||||||
|
|
||||||
The choice of the server model is made at the compilation time by instantiating either
|
The choice of the server model is made at the compilation time by instantiating either
|
||||||
the **{{package}}.Skeletons.Skeleton** package or the **{{package}}.Skeletons.Shared_Instance**
|
the **{{package}}.Skeletons.Skeleton** package or the **{{package}}.Skeletons.Shared_Instance**
|
||||||
@@ -65,9 +66,9 @@ All you have to do is implement the server operation in the **src/{{packageName}
|
|||||||
The package already contains the operation with its parameters and you only have to replace
|
The package already contains the operation with its parameters and you only have to replace
|
||||||
the **null** instruction by real code.
|
the **null** instruction by real code.
|
||||||
|
|
||||||
# Documentation
|
## Documentation
|
||||||
|
|
||||||
## API Documentation
|
### API Documentation
|
||||||
|
|
||||||
All URIs are relative to *{{basePath}}*
|
All URIs are relative to *{{basePath}}*
|
||||||
|
|
||||||
@@ -76,22 +77,30 @@ Method | HTTP request | Description
|
|||||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}[**{{nickname}}**]({{apiDocPath}}{{classname}}.md#{{nickname}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
|
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}[**{{nickname}}**]({{apiDocPath}}{{classname}}.md#{{nickname}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
|
||||||
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
|
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
|
||||||
|
|
||||||
## Models
|
### Models
|
||||||
|
|
||||||
{{#models}}{{#model}} - [{{package}}.Models.{{classname}}]({{modelDocPath}}{{classname}}.md)
|
{{#models}}{{#model}} - [{{package}}.Models.{{classname}}]({{modelDocPath}}{{classname}}.md)
|
||||||
{{/model}}{{/models}}
|
{{/model}}{{/models}}
|
||||||
|
|
||||||
## Authorization
|
### Authorization
|
||||||
|
|
||||||
{{^authMethods}} All endpoints do not require authorization.
|
{{^authMethods}} All endpoints do not require authorization.
|
||||||
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
|
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
|
||||||
{{#authMethods}}## {{{name}}}
|
{{#authMethods}}## {{{name}}}
|
||||||
|
|
||||||
{{#isApiKey}}- **Type**: API key
|
{{#isApiKey}}
|
||||||
|
|
||||||
|
- **Type**: API key
|
||||||
- **API key parameter name**: {{{keyParamName}}}
|
- **API key parameter name**: {{{keyParamName}}}
|
||||||
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
|
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
|
||||||
{{/isApiKey}}
|
{{/isApiKey}}
|
||||||
{{#isBasic}}- **Type**: HTTP basic authentication
|
{{#isBasic}}
|
||||||
|
|
||||||
|
- **Type**: HTTP basic authentication
|
||||||
{{/isBasic}}
|
{{/isBasic}}
|
||||||
{{#isOAuth}}- **Type**: OAuth
|
{{#isOAuth}}
|
||||||
|
|
||||||
|
- **Type**: OAuth
|
||||||
- **Flow**: {{{flow}}}
|
- **Flow**: {{{flow}}}
|
||||||
- **Authorization URL**: {{{authorizationUrl}}}
|
- **Authorization URL**: {{{authorizationUrl}}}
|
||||||
- **Scopes**: {{^scopes}}N/A{{/scopes}}
|
- **Scopes**: {{^scopes}}N/A{{/scopes}}
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{{/hasOAuthMethods}}
|
{{/hasOAuthMethods}}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to set access token for the first Bearer authentication.
|
* Helper method to set access token for the first Bearer authentication.
|
||||||
* @param bearerToken Bearer token
|
* @param bearerToken Bearer token
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
# {{artifactId}}
|
# {{artifactId}}
|
||||||
|
|
||||||
{{appName}}
|
{{appName}}
|
||||||
|
|
||||||
- API version: {{appVersion}}
|
- API version: {{appVersion}}
|
||||||
{{^hideGenerationTimestamp}}
|
{{^hideGenerationTimestamp}}
|
||||||
- Build date: {{generatedDate}}
|
|
||||||
|
- Build date: {{generatedDate}}
|
||||||
{{/hideGenerationTimestamp}}
|
{{/hideGenerationTimestamp}}
|
||||||
|
|
||||||
{{#appDescription}}{{{appDescription}}}{{/appDescription}}
|
{{#appDescription}}{{{appDescription}}}{{/appDescription}}
|
||||||
@@ -14,10 +16,10 @@
|
|||||||
|
|
||||||
*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)*
|
*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)*
|
||||||
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
Building the API client library requires:
|
Building the API client library requires:
|
||||||
|
|
||||||
1. Java {{#supportJava6}}1.6{{/supportJava6}}{{^supportJava6}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/supportJava6}}+
|
1. Java {{#supportJava6}}1.6{{/supportJava6}}{{^supportJava6}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/supportJava6}}+
|
||||||
2. Maven/Gradle
|
2. Maven/Gradle
|
||||||
|
|
||||||
@@ -68,8 +70,8 @@ mvn clean package
|
|||||||
|
|
||||||
Then manually install the following JARs:
|
Then manually install the following JARs:
|
||||||
|
|
||||||
* `target/{{{artifactId}}}-{{{artifactVersion}}}.jar`
|
- `target/{{{artifactId}}}-{{{artifactVersion}}}.jar`
|
||||||
* `target/lib/*.jar`
|
- `target/lib/*.jar`
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
@@ -141,13 +143,19 @@ Class | Method | HTTP request | Description
|
|||||||
{{/authMethods}}Authentication schemes defined for the API:
|
{{/authMethods}}Authentication schemes defined for the API:
|
||||||
{{#authMethods}}### {{name}}
|
{{#authMethods}}### {{name}}
|
||||||
|
|
||||||
{{#isApiKey}}- **Type**: API key
|
{{#isApiKey}}
|
||||||
|
|
||||||
|
- **Type**: API key
|
||||||
- **API key parameter name**: {{keyParamName}}
|
- **API key parameter name**: {{keyParamName}}
|
||||||
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
|
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
|
||||||
{{/isApiKey}}
|
{{/isApiKey}}
|
||||||
{{#isBasic}}- **Type**: HTTP basic authentication
|
{{#isBasic}}
|
||||||
|
|
||||||
|
- **Type**: HTTP basic authentication
|
||||||
{{/isBasic}}
|
{{/isBasic}}
|
||||||
{{#isOAuth}}- **Type**: OAuth
|
{{#isOAuth}}
|
||||||
|
|
||||||
|
- **Type**: OAuth
|
||||||
- **Flow**: {{flow}}
|
- **Flow**: {{flow}}
|
||||||
- **Authorization URL**: {{authorizationUrl}}
|
- **Authorization URL**: {{authorizationUrl}}
|
||||||
- **Scopes**: {{^scopes}}N/A{{/scopes}}
|
- **Scopes**: {{^scopes}}N/A{{/scopes}}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# {{classname}}{{#description}}
|
# {{classname}}{{#description}}
|
||||||
|
|
||||||
{{description}}{{/description}}
|
{{description}}{{/description}}
|
||||||
|
|
||||||
All URIs are relative to *{{basePath}}*
|
All URIs are relative to *{{basePath}}*
|
||||||
@@ -10,8 +11,9 @@ Method | HTTP request | Description
|
|||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
<a name="{{operationId}}"></a>
|
|
||||||
# **{{operationId}}**
|
## {{operationId}}
|
||||||
|
|
||||||
> {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
> {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
||||||
|
|
||||||
{{summary}}{{#notes}}
|
{{summary}}{{#notes}}
|
||||||
@@ -19,6 +21,7 @@ Method | HTTP request | Description
|
|||||||
{{notes}}{{/notes}}
|
{{notes}}{{/notes}}
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Import classes:{{#hasAuthMethods}}
|
// Import classes:{{#hasAuthMethods}}
|
||||||
//import {{{invokerPackage}}}.ApiClient;{{/hasAuthMethods}}
|
//import {{{invokerPackage}}}.ApiClient;{{/hasAuthMethods}}
|
||||||
@@ -59,6 +62,7 @@ try {
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
|
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
|
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
|
||||||
@@ -75,8 +79,8 @@ Name | Type | Description | Notes
|
|||||||
|
|
||||||
### HTTP request headers
|
### HTTP request headers
|
||||||
|
|
||||||
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
|
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
|
||||||
- **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}}
|
- **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}}
|
||||||
|
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
|
|||||||
@@ -58,7 +58,12 @@ public class ApiClient {
|
|||||||
RequestInterceptor auth;
|
RequestInterceptor auth;
|
||||||
{{#authMethods}}if ("{{name}}".equals(authName)) {
|
{{#authMethods}}if ("{{name}}".equals(authName)) {
|
||||||
{{#isBasic}}
|
{{#isBasic}}
|
||||||
|
{{#isBasicBasic}}
|
||||||
auth = new HttpBasicAuth();
|
auth = new HttpBasicAuth();
|
||||||
|
{{/isBasicBasic}}
|
||||||
|
{{^isBasicBasic}}
|
||||||
|
auth = new HttpBearerAuth("{{scheme}}");
|
||||||
|
{{/isBasicBasic}}
|
||||||
{{/isBasic}}
|
{{/isBasic}}
|
||||||
{{#isApiKey}}
|
{{#isApiKey}}
|
||||||
auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");
|
auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");
|
||||||
@@ -225,6 +230,21 @@ public class ApiClient {
|
|||||||
return contentTypes[0];
|
return contentTypes[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to configure the bearer token.
|
||||||
|
* @param bearerToken the bearer token.
|
||||||
|
*/
|
||||||
|
public void setBearerToken(String bearerToken) {
|
||||||
|
for(RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
|
||||||
|
if (apiAuthorization instanceof HttpBearerAuth) {
|
||||||
|
((HttpBearerAuth) apiAuthorization).setBearerToken(bearerToken);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("No Bearer authentication configured!");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to configure the first api key found
|
* Helper method to configure the first api key found
|
||||||
* @param apiKey API key
|
* @param apiKey API key
|
||||||
|
|||||||
@@ -194,7 +194,6 @@ public class ApiClient {
|
|||||||
throw new RuntimeException("No API key authentication configured!");
|
throw new RuntimeException("No API key authentication configured!");
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#hasOAuthMethods}}
|
|
||||||
/**
|
/**
|
||||||
* Helper method to set bearer token for the first Bearer authentication.
|
* Helper method to set bearer token for the first Bearer authentication.
|
||||||
* @param bearerToken Bearer token
|
* @param bearerToken Bearer token
|
||||||
@@ -209,6 +208,7 @@ public class ApiClient {
|
|||||||
throw new RuntimeException("No Bearer authentication configured!");
|
throw new RuntimeException("No Bearer authentication configured!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{{#hasOAuthMethods}}
|
||||||
/**
|
/**
|
||||||
* Helper method to set access token for the first OAuth2 authentication.
|
* Helper method to set access token for the first OAuth2 authentication.
|
||||||
* @param accessToken Access token
|
* @param accessToken Access token
|
||||||
|
|||||||
@@ -289,14 +289,14 @@
|
|||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
<gson-fire-version>1.8.3</gson-fire-version>
|
<gson-fire-version>1.8.3</gson-fire-version>
|
||||||
<swagger-core-version>1.5.21</swagger-core-version>
|
<swagger-core-version>1.5.21</swagger-core-version>
|
||||||
<okhttp-version>3.13.1</okhttp-version>
|
<okhttp-version>3.14.0</okhttp-version>
|
||||||
<gson-version>2.8.5</gson-version>
|
<gson-version>2.8.5</gson-version>
|
||||||
<commons-lang3-version>3.8.1</commons-lang3-version>
|
<commons-lang3-version>3.8.1</commons-lang3-version>
|
||||||
{{#joda}}
|
{{#joda}}
|
||||||
<jodatime-version>2.9.9</jodatime-version>
|
<jodatime-version>2.9.9</jodatime-version>
|
||||||
{{/joda}}
|
{{/joda}}
|
||||||
{{#threetenbp}}
|
{{#threetenbp}}
|
||||||
<threetenbp-version>1.3.5</threetenbp-version>
|
<threetenbp-version>1.3.8</threetenbp-version>
|
||||||
{{/threetenbp}}
|
{{/threetenbp}}
|
||||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||||
<junit-version>4.12</junit-version>
|
<junit-version>4.12</junit-version>
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ import java.util.TimeZone;
|
|||||||
|
|
||||||
import {{invokerPackage}}.auth.Authentication;
|
import {{invokerPackage}}.auth.Authentication;
|
||||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||||
|
import {{invokerPackage}}.auth.HttpBearerAuth;
|
||||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||||
{{#hasOAuthMethods}}
|
{{#hasOAuthMethods}}
|
||||||
import {{invokerPackage}}.auth.OAuth;
|
import {{invokerPackage}}.auth.OAuth;
|
||||||
@@ -125,8 +126,9 @@ public class ApiClient {
|
|||||||
setUserAgent("Java-SDK");
|
setUserAgent("Java-SDK");
|
||||||
|
|
||||||
// Setup authentications (key: authentication name, value: authentication).
|
// Setup authentications (key: authentication name, value: authentication).
|
||||||
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}
|
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
|
||||||
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
|
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasicBasic}}{{^isBasicBasic}}
|
||||||
|
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}");{{/isBasicBasic}}{{/isBasic}}{{#isApiKey}}
|
||||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
||||||
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||||
// Prevent the authentications from being modified.
|
// Prevent the authentications from being modified.
|
||||||
@@ -185,6 +187,20 @@ public class ApiClient {
|
|||||||
return authentications.get(authName);
|
return authentications.get(authName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to set token for HTTP bearer authentication.
|
||||||
|
* @param bearerToken the token
|
||||||
|
*/
|
||||||
|
public void setBearerToken(String bearerToken) {
|
||||||
|
for (Authentication auth : authentications.values()) {
|
||||||
|
if (auth instanceof HttpBearerAuth) {
|
||||||
|
((HttpBearerAuth) auth).setBearerToken(bearerToken);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("No Bearer authentication configured!");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to set username for the first HTTP basic authentication.
|
* Helper method to set username for the first HTTP basic authentication.
|
||||||
* @param username the username
|
* @param username the username
|
||||||
@@ -342,6 +358,8 @@ public class ApiClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the given string into Date object.
|
* Parse the given string into Date object.
|
||||||
|
* @param str the string to parse
|
||||||
|
* @return the Date parsed from the string
|
||||||
*/
|
*/
|
||||||
public Date parseDate(String str) {
|
public Date parseDate(String str) {
|
||||||
try {
|
try {
|
||||||
@@ -353,6 +371,8 @@ public class ApiClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Format the given Date object into string.
|
* Format the given Date object into string.
|
||||||
|
* @param date the date to format
|
||||||
|
* @return the formatted date as string
|
||||||
*/
|
*/
|
||||||
public String formatDate(Date date) {
|
public String formatDate(Date date) {
|
||||||
return dateFormat.format(date);
|
return dateFormat.format(date);
|
||||||
@@ -386,7 +406,7 @@ public class ApiClient {
|
|||||||
* Formats the specified collection path parameter to a string value.
|
* Formats the specified collection path parameter to a string value.
|
||||||
*
|
*
|
||||||
* @param collectionFormat The collection format of the parameter.
|
* @param collectionFormat The collection format of the parameter.
|
||||||
* @param value The value of the parameter.
|
* @param values The values of the parameter.
|
||||||
* @return String representation of the parameter
|
* @return String representation of the parameter
|
||||||
*/
|
*/
|
||||||
public String collectionPathParameterToString(CollectionFormat collectionFormat, Collection<? extends CharSequence> values) {
|
public String collectionPathParameterToString(CollectionFormat collectionFormat, Collection<? extends CharSequence> values) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import com.squareup.okhttp.Interceptor;
|
|||||||
import com.squareup.okhttp.OkHttpClient;
|
import com.squareup.okhttp.OkHttpClient;
|
||||||
|
|
||||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||||
|
import {{invokerPackage}}.auth.HttpBearerAuth;
|
||||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||||
{{#hasOAuthMethods}}
|
{{#hasOAuthMethods}}
|
||||||
import {{invokerPackage}}.auth.OAuth;
|
import {{invokerPackage}}.auth.OAuth;
|
||||||
@@ -58,10 +59,16 @@ public class ApiClient {
|
|||||||
Interceptor auth;
|
Interceptor auth;
|
||||||
{{#authMethods}}if ("{{name}}".equals(authName)) {
|
{{#authMethods}}if ("{{name}}".equals(authName)) {
|
||||||
{{#isBasic}}
|
{{#isBasic}}
|
||||||
|
{{#isBasicBasic}}
|
||||||
auth = new HttpBasicAuth();
|
auth = new HttpBasicAuth();
|
||||||
|
{{/isBasicBasic}}
|
||||||
|
{{^isBasicBasic}}
|
||||||
|
auth = new HttpBearerAuth("{{scheme}}");
|
||||||
|
{{/isBasicBasic}}
|
||||||
{{/isBasic}}
|
{{/isBasic}}
|
||||||
{{#isApiKey}}
|
{{#isApiKey}}
|
||||||
auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}
|
auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");
|
||||||
|
{{/isApiKey}}
|
||||||
{{#isOAuth}}
|
{{#isOAuth}}
|
||||||
auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}");
|
auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}");
|
||||||
{{/isOAuth}}
|
{{/isOAuth}}
|
||||||
@@ -159,6 +166,19 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to set token for the first Http Bearer authentication found.
|
||||||
|
* @param bearerToken Bearer token
|
||||||
|
*/
|
||||||
|
public void setBearerToken(String bearerToken) {
|
||||||
|
for (Interceptor apiAuthorization : apiAuthorizations.values()) {
|
||||||
|
if (apiAuthorization instanceof HttpBearerAuth) {
|
||||||
|
((HttpBearerAuth) apiAuthorization).setBearerToken(bearerToken);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to configure the username/password for basic auth or password oauth
|
* Helper method to configure the username/password for basic auth or password oauth
|
||||||
* @param username Username
|
* @param username Username
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
|||||||
import retrofit2.converter.gson.GsonConverterFactory;
|
import retrofit2.converter.gson.GsonConverterFactory;
|
||||||
import retrofit2.converter.scalars.ScalarsConverterFactory;
|
import retrofit2.converter.scalars.ScalarsConverterFactory;
|
||||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||||
|
import {{invokerPackage}}.auth.HttpBearerAuth;
|
||||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||||
{{#hasOAuthMethods}}
|
{{#hasOAuthMethods}}
|
||||||
import {{invokerPackage}}.auth.OAuth;
|
import {{invokerPackage}}.auth.OAuth;
|
||||||
@@ -62,9 +63,11 @@ public class ApiClient {
|
|||||||
{{#hasAuthMethods}}
|
{{#hasAuthMethods}}
|
||||||
Interceptor auth;
|
Interceptor auth;
|
||||||
{{#authMethods}}if ("{{name}}".equals(authName)) {
|
{{#authMethods}}if ("{{name}}".equals(authName)) {
|
||||||
{{#isBasic}}
|
{{#isBasic}}{{#isBasicBasic}}
|
||||||
auth = new HttpBasicAuth();
|
auth = new HttpBasicAuth();
|
||||||
{{/isBasic}}
|
{{/isBasicBasic}}{{^isBasicBasic}}
|
||||||
|
auth = new HttpBearerAuth("{{scheme}}");
|
||||||
|
{{/isBasicBasic}}{{/isBasic}}
|
||||||
{{#isApiKey}}
|
{{#isApiKey}}
|
||||||
auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");
|
auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");
|
||||||
{{/isApiKey}}
|
{{/isApiKey}}
|
||||||
@@ -209,6 +212,21 @@ public class ApiClient {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to set token for the first Http Bearer authentication found.
|
||||||
|
* @param bearerToken Bearer token
|
||||||
|
* @return ApiClient
|
||||||
|
*/
|
||||||
|
public ApiClient setBearerToken(String bearerToken) {
|
||||||
|
for (Interceptor apiAuthorization : apiAuthorizations.values()) {
|
||||||
|
if (apiAuthorization instanceof HttpBearerAuth) {
|
||||||
|
((HttpBearerAuth) apiAuthorization).setBearerToken(bearerToken);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to configure the username/password for basic auth or password oauth
|
* Helper method to configure the username/password for basic auth or password oauth
|
||||||
* @param username Username
|
* @param username Username
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ public class ApiClient {
|
|||||||
|
|
||||||
public ApiClient() {
|
public ApiClient() {
|
||||||
// Setup authentications (key: authentication name, value: authentication).
|
// Setup authentications (key: authentication name, value: authentication).
|
||||||
authentications = new HashMap<{{#supportJava6}}String, Authentication{{/supportJava6}}>();{{#authMethods}}{{#isBasic}}
|
authentications = new HashMap<{{#supportJava6}}String, Authentication{{/supportJava6}}>();{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
|
||||||
// authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
|
// authentications.put("{{name}}", new HttpBasicAuth());{{/isBasicBasic}}{{^isBasicBasic}}
|
||||||
|
// authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}");{{/isBasicBasic}}{{/isBasic}}{{#isApiKey}}
|
||||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
||||||
// authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
// authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||||
// Prevent the authentications from being modified.
|
// Prevent the authentications from being modified.
|
||||||
|
|||||||
@@ -351,7 +351,7 @@
|
|||||||
<java.version>{{#supportJava6}}1.6{{/supportJava6}}{{^supportJava6}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/supportJava6}}</java.version>
|
<java.version>{{#supportJava6}}1.6{{/supportJava6}}{{^supportJava6}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/supportJava6}}</java.version>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
<gson-fire-version>1.8.0</gson-fire-version>
|
<gson-fire-version>1.8.3</gson-fire-version>
|
||||||
<swagger-annotations-version>1.5.21</swagger-annotations-version>
|
<swagger-annotations-version>1.5.21</swagger-annotations-version>
|
||||||
{{#usePlayWS}}
|
{{#usePlayWS}}
|
||||||
<jackson-databind-version>2.8.11.3</jackson-databind-version>
|
<jackson-databind-version>2.8.11.3</jackson-databind-version>
|
||||||
@@ -379,7 +379,7 @@
|
|||||||
<jodatime-version>2.9.9</jodatime-version>
|
<jodatime-version>2.9.9</jodatime-version>
|
||||||
{{/joda}}
|
{{/joda}}
|
||||||
{{#threetenbp}}
|
{{#threetenbp}}
|
||||||
<threetenbp-version>1.3.5</threetenbp-version>
|
<threetenbp-version>1.3.8</threetenbp-version>
|
||||||
{{/threetenbp}}
|
{{/threetenbp}}
|
||||||
<oltu-version>1.0.1</oltu-version>
|
<oltu-version>1.0.1</oltu-version>
|
||||||
<junit-version>4.12</junit-version>
|
<junit-version>4.12</junit-version>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package {{invokerPackage}};
|
|||||||
|
|
||||||
import {{invokerPackage}}.auth.Authentication;
|
import {{invokerPackage}}.auth.Authentication;
|
||||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||||
|
import {{invokerPackage}}.auth.HttpBearerAuth;
|
||||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||||
{{#hasOAuthMethods}}
|
{{#hasOAuthMethods}}
|
||||||
import {{invokerPackage}}.auth.OAuth;
|
import {{invokerPackage}}.auth.OAuth;
|
||||||
@@ -78,8 +79,9 @@ public class ApiClient {
|
|||||||
this.objectMapper.setDateFormat(dateFormat);
|
this.objectMapper.setDateFormat(dateFormat);
|
||||||
|
|
||||||
// Setup authentications (key: authentication name, value: authentication).
|
// Setup authentications (key: authentication name, value: authentication).
|
||||||
this.authentications = new HashMap<>();{{#authMethods}}{{#isBasic}}
|
this.authentications = new HashMap<>();{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
|
||||||
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
|
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasicBasic}}{{^isBasicBasic}}
|
||||||
|
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}");{{/isBasicBasic}}{{/isBasic}}{{#isApiKey}}
|
||||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
||||||
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||||
// Prevent the authentications from being modified.
|
// Prevent the authentications from being modified.
|
||||||
@@ -161,6 +163,20 @@ public class ApiClient {
|
|||||||
return authentications.get(authName);
|
return authentications.get(authName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to set access token for the first Bearer authentication.
|
||||||
|
* @param bearerToken Bearer token
|
||||||
|
*/
|
||||||
|
public ApiClient setBearerToken(String bearerToken) {
|
||||||
|
for (Authentication auth : authentications.values()) {
|
||||||
|
if (auth instanceof HttpBearerAuth) {
|
||||||
|
((HttpBearerAuth) auth).setBearerToken(bearerToken);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("No Bearer authentication configured!");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to set username for the first HTTP basic authentication.
|
* Helper method to set username for the first HTTP basic authentication.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ task execute(type:JavaExec) {
|
|||||||
ext {
|
ext {
|
||||||
swagger_annotations_version = "1.5.21"
|
swagger_annotations_version = "1.5.21"
|
||||||
jackson_version = "{{^threetenbp}}2.8.9{{/threetenbp}}{{#threetenbp}}2.6.4{{/threetenbp}}"
|
jackson_version = "{{^threetenbp}}2.8.9{{/threetenbp}}{{#threetenbp}}2.6.4{{/threetenbp}}"
|
||||||
|
jackson_databind_version = "{{^threetenbp}}2.8.11.3{{/threetenbp}}{{#threetenbp}}2.6.4{{/threetenbp}}"
|
||||||
vertx_version = "3.4.2"
|
vertx_version = "3.4.2"
|
||||||
junit_version = "4.12"
|
junit_version = "4.12"
|
||||||
}
|
}
|
||||||
@@ -39,7 +40,7 @@ dependencies {
|
|||||||
compile "io.vertx:vertx-rx-java:$vertx_version"
|
compile "io.vertx:vertx-rx-java:$vertx_version"
|
||||||
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version"
|
||||||
{{#joda}}
|
{{#joda}}
|
||||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
|
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
|
||||||
{{/joda}}
|
{{/joda}}
|
||||||
|
|||||||
@@ -234,7 +234,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson-version}</version>
|
<version>${jackson-databind}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
{{#joda}}
|
{{#joda}}
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -278,6 +278,7 @@
|
|||||||
<vertx-version>3.4.2</vertx-version>
|
<vertx-version>3.4.2</vertx-version>
|
||||||
<swagger-annotations-version>1.5.21</swagger-annotations-version>
|
<swagger-annotations-version>1.5.21</swagger-annotations-version>
|
||||||
<jackson-version>{{^threetenbp}}2.8.11{{/threetenbp}}{{#threetenbp}}2.6.4{{/threetenbp}}</jackson-version>
|
<jackson-version>{{^threetenbp}}2.8.11{{/threetenbp}}{{#threetenbp}}2.6.4{{/threetenbp}}</jackson-version>
|
||||||
|
<jackson-databind>{{^threetenbp}}2.8.11.3{{/threetenbp}}{{#threetenbp}}2.6.4{{/threetenbp}}</jackson-databind>
|
||||||
<junit-version>4.12</junit-version>
|
<junit-version>4.12</junit-version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ import java.util.TimeZone;
|
|||||||
|
|
||||||
import {{invokerPackage}}.auth.Authentication;
|
import {{invokerPackage}}.auth.Authentication;
|
||||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||||
|
import {{invokerPackage}}.auth.HttpBearerAuth;
|
||||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||||
{{#hasOAuthMethods}}
|
{{#hasOAuthMethods}}
|
||||||
import {{invokerPackage}}.auth.OAuth;
|
import {{invokerPackage}}.auth.OAuth;
|
||||||
@@ -122,8 +123,9 @@ public class ApiClient {
|
|||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
// Setup authentications (key: authentication name, value: authentication).
|
// Setup authentications (key: authentication name, value: authentication).
|
||||||
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}
|
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
|
||||||
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
|
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasicBasic}}{{^isBasicBasic}}
|
||||||
|
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}");{{/isBasicBasic}}{{/isBasic}}{{#isApiKey}}
|
||||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
||||||
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||||
// Prevent the authentications from being modified.
|
// Prevent the authentications from being modified.
|
||||||
@@ -182,6 +184,20 @@ public class ApiClient {
|
|||||||
return authentications.get(authName);
|
return authentications.get(authName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to set access token for the first Bearer authentication.
|
||||||
|
* @param bearerToken Bearer token
|
||||||
|
*/
|
||||||
|
public void setBearerToken(String bearerToken) {
|
||||||
|
for (Authentication auth : authentications.values()) {
|
||||||
|
if (auth instanceof HttpBearerAuth) {
|
||||||
|
((HttpBearerAuth) auth).setBearerToken(bearerToken);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("No Bearer authentication configured!");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to set username for the first HTTP basic authentication.
|
* Helper method to set username for the first HTTP basic authentication.
|
||||||
* @param username the username
|
* @param username the username
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
{{#jackson}}
|
{{#jackson}}
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
{{/jackson}}
|
{{/jackson}}
|
||||||
public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue(String text) {
|
public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
|
||||||
for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||||
if (String.valueOf(b.value).equals(text)) {
|
if (b.value.equals(value)) {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
||||||
}
|
}
|
||||||
{{#gson}}
|
{{#gson}}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
@Override
|
@Override
|
||||||
public {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
|
public {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
|
||||||
{{{dataType}}} value = jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}next{{{dataType}}}(){{/isInteger}};
|
{{{dataType}}} value = jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}next{{{dataType}}}(){{/isInteger}};
|
||||||
return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.fromValue(String.valueOf(value));
|
return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.fromValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/gson}}
|
{{/gson}}
|
||||||
|
|||||||
@@ -38,13 +38,13 @@
|
|||||||
{{#jackson}}
|
{{#jackson}}
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
{{/jackson}}
|
{{/jackson}}
|
||||||
public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue(String text) {
|
public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
|
||||||
for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||||
if (String.valueOf(b.value).equals(text)) {
|
if (b.value.equals(value)) {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
||||||
}
|
}
|
||||||
{{#gson}}
|
{{#gson}}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
@Override
|
@Override
|
||||||
public {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
|
public {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
|
||||||
{{{dataType}}} value = jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}next{{{dataType}}}(){{/isInteger}};
|
{{{dataType}}} value = jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}next{{{dataType}}}(){{/isInteger}};
|
||||||
return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.fromValue(String.valueOf(value));
|
return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.fromValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/gson}}
|
{{/gson}}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
{{#models}}{{#model}}
|
{{#models}}{{#model}}
|
||||||
|
|
||||||
{{#isEnum}}{{>enum_outer_doc}}{{/isEnum}}{{^isEnum}}{{>pojo_doc}}{{/isEnum}}
|
{{#isEnum}}{{>enum_outer_doc}}{{/isEnum}}{{^isEnum}}{{>pojo_doc}}{{/isEnum}}
|
||||||
{{/model}}{{/models}}
|
{{/model}}{{/models}}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
# {{classname}}
|
# {{classname}}
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------ | ------------- | ------------- | -------------
|
------------ | ------------- | ------------- | -------------
|
||||||
{{#vars}}**{{name}}** | {{#isEnum}}[**{{datatypeWithEnum}}**](#{{datatypeWithEnum}}){{/isEnum}}{{^isEnum}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}}{{/isEnum}} | {{description}} | {{^required}} [optional]{{/required}}{{#readOnly}} [readonly]{{/readOnly}}
|
{{#vars}}**{{name}}** | {{#isEnum}}[**{{datatypeWithEnum}}**](#{{datatypeWithEnum}}){{/isEnum}}{{^isEnum}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}}{{/isEnum}} | {{description}} | {{^required}} [optional]{{/required}}{{#readOnly}} [readonly]{{/readOnly}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
{{#vars}}{{#isEnum}}
|
{{#vars}}{{#isEnum}}
|
||||||
|
|
||||||
<a name="{{{datatypeWithEnum}}}"></a>
|
|
||||||
## Enum: {{datatypeWithEnum}}
|
## Enum: {{datatypeWithEnum}}
|
||||||
|
|
||||||
Name | Value
|
Name | Value
|
||||||
---- | -----{{#allowableValues}}{{#enumVars}}
|
---- | -----{{#allowableValues}}{{#enumVars}}
|
||||||
{{name}} | {{value}}{{/enumVars}}{{/allowableValues}}
|
{{name}} | {{value}}{{/enumVars}}{{/allowableValues}}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user