forked from loafle/openapi-generator-original
commit
ce821a5100
23
.gitignore
vendored
23
.gitignore
vendored
@ -91,13 +91,19 @@ samples/client/petstore/swift/SwaggerClientTests/Pods/Pods.xcodeproj/xcshareddat
|
||||
samples/client/petstore/csharp/SwaggerClientTest/.vs
|
||||
samples/client/petstore/csharp/SwaggerClientTest/obj
|
||||
samples/client/petstore/csharp/SwaggerClientTest/bin
|
||||
samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/vendor/
|
||||
samples/client/petstore/csharp/SwaggerClientTest/packages
|
||||
samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/
|
||||
samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/
|
||||
samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/nuget.exe
|
||||
samples/client/petstore/csharp/SwaggerClientTest/TestResult.xml
|
||||
samples/client/petstore/csharp/SwaggerClientTest/nuget.exe
|
||||
samples/client/petstore/csharp/SwaggerClientTest/testrunner/
|
||||
samples/client/petstore/csharp/SwaggerClient/.vs
|
||||
samples/client/petstore/csharp/SwaggerClient/nuget.exe
|
||||
samples/client/petstore/csharp/SwaggerClient/obj
|
||||
samples/client/petstore/csharp/SwaggerClient/bin
|
||||
samples/client/petstore/csharp/SwaggerClient/obj/Debug/
|
||||
samples/client/petstore/csharp/SwaggerClient/bin/Debug/
|
||||
samples/client/petstore/csharp/SwaggerClient/packages
|
||||
|
||||
# Python
|
||||
*.pyc
|
||||
@ -107,3 +113,16 @@ samples/client/petstore/python/swagger_client.egg-info/SOURCES.txt
|
||||
samples/client/petstore/python/.coverage
|
||||
samples/client/petstore/python/.projectile
|
||||
samples/client/petstore/python/.venv/
|
||||
|
||||
# ts
|
||||
samples/client/petstore/typescript-node/npm/node_modules
|
||||
samples/client/petstore/typescript-fetch/with-package-metadata/node_modules
|
||||
samples/client/petstore/typescript-fetch/with-package-metadata/dist
|
||||
samples/client/petstore/typescript-fetch/with-package-metadata/typings
|
||||
samples/client/petstore/typescript-fetch/default/node_modules
|
||||
samples/client/petstore/typescript-fetch/default/dist
|
||||
samples/client/petstore/typescript-fetch/default/typings
|
||||
samples/client/petstore/typescript-fetch/default-es6/node_modules
|
||||
samples/client/petstore/typescript-fetch/default-es6/dist
|
||||
samples/client/petstore/typescript-fetch/default-es6/typings
|
||||
|
||||
|
117
README.md
117
README.md
@ -51,6 +51,7 @@ Check out [Swagger-Spec](https://github.com/OAI/OpenAPI-Specification) for addit
|
||||
- [Java JAX-RS (Apache CXF 2 / 3)](#java-jax-rs-apache-cxf-2--3)
|
||||
- [Java JAX-RS (Resteasy)](#java-jax-rs-resteasy)
|
||||
- [Java Spring MVC](#java-spring-mvc)
|
||||
- [Java SpringBoot](#java-springboot)
|
||||
- [Haskell Servant](#haskell-servant)
|
||||
- [ASP.NET 5 Web API](#aspnet-5-web-api)
|
||||
- [To build the codegen library](#to-build-the-codegen-library)
|
||||
@ -59,6 +60,7 @@ Check out [Swagger-Spec](https://github.com/OAI/OpenAPI-Specification) for addit
|
||||
- [Online Generators](#online-generators)
|
||||
- [Guidelines for Contribution](https://github.com/swagger-api/swagger-codegen/wiki/Guidelines-for-Contribution)
|
||||
- [Companies/Projects using Swagger Codegen](#companiesprojects-using-swagger-codegen)
|
||||
- [Swagger Codegen Core Team](#swagger-codegen-core-team)
|
||||
- [License](#license)
|
||||
|
||||
|
||||
@ -688,6 +690,31 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-o samples/server/petstore/spring-mvc
|
||||
```
|
||||
|
||||
### Java SpringBoot
|
||||
|
||||
```
|
||||
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l springboot \
|
||||
-o samples/server/petstore/springboot
|
||||
```
|
||||
|
||||
You can also set a Json file with basePackage & configPackage properties :
|
||||
Example :
|
||||
```
|
||||
{
|
||||
"basePackage":"io.swagger",
|
||||
"configPackage":"io.swagger.config"
|
||||
}
|
||||
```
|
||||
For use it add option ```-c myOptions.json``` to the generation command
|
||||
|
||||
To Use-it :
|
||||
in the generated folder try ``` mvn package ``` for build jar.
|
||||
Start your server ``` java -jar target/swagger-springboot-server-1.0.0.jar ```
|
||||
SpringBoot listening on default port 8080
|
||||
|
||||
|
||||
### Haskell Servant
|
||||
|
||||
```
|
||||
@ -763,6 +790,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you
|
||||
- [Acunetix](https://www.acunetix.com/)
|
||||
- [Atlassian](https://www.atlassian.com/)
|
||||
- [beemo](http://www.beemo.eu)
|
||||
- [bitly](https://bitly.com)
|
||||
- [Cachet Financial](http://www.cachetfinancial.com/)
|
||||
- [CloudBoost](https://www.CloudBoost.io/)
|
||||
- [Cupix](http://www.cupix.com)
|
||||
@ -779,9 +807,12 @@ Here are some companies/projects using Swagger Codegen in production. To add you
|
||||
- [nViso](http://www.nviso.ch/)
|
||||
- [Okiok](https://www.okiok.com)
|
||||
- [OSDN](https://osdn.jp)
|
||||
- [PagerDuty](https://www.pagerduty.com)
|
||||
- [Pepipost](https://www.pepipost.com)
|
||||
- [Pixoneye](http://www.pixoneye.com/)
|
||||
- [PostAffiliatePro](https://www.postaffiliatepro.com/)
|
||||
- [Reload! A/S](https://reload.dk/)
|
||||
- [REstore](https://www.restore.eu)
|
||||
- [Royal Bank of Canada (RBC)](http://www.rbc.com/canada.html)
|
||||
- [SmartRecruiters](https://www.smartrecruiters.com/)
|
||||
- [StyleRecipe](http://stylerecipe.co.jp)
|
||||
@ -791,6 +822,92 @@ Here are some companies/projects using Swagger Codegen in production. To add you
|
||||
- [Zalando](https://tech.zalando.com)
|
||||
- [ZEEF.com](https://zeef.com/)
|
||||
|
||||
# Swagger Codegen Core Team
|
||||
|
||||
Swaagger Codegen core team members are contributors who have been making signficiant contributions (review issues, fix bugs, make enhancements, etc) to the project on a regular basis.
|
||||
|
||||
## API Clients
|
||||
| Langauges | Core Team (join date) |
|
||||
|:-------------|:-------------|
|
||||
| ActionScript | |
|
||||
| C++ | |
|
||||
| C# | @jimschubert (2016/05/01) | |
|
||||
| Clojure | @xhh (2016/05/01) |
|
||||
| Dart | |
|
||||
| Groovy | |
|
||||
| Go | @guohuang (2016/05/01) @neilotoole (2016/05/01) |
|
||||
| Java | @cbornet (2016/05/01) @xhh (2016/05/01) |
|
||||
| NodeJS/Javascript | @xhh (2016/05/01) |
|
||||
| ObjC | @mateuszmackowiak (2016/05/09) |
|
||||
| Perl | @wing328 (2016/05/01) |
|
||||
| PHP | @arnested (2016/05/01) |
|
||||
| Python | @scottrw93 (2016/05/01) |
|
||||
| Ruby | @wing328 (2016/05/01) |
|
||||
| Scala | |
|
||||
| Swift | @jaz-ah (2016/05/01) @Edubits (2016/05/01) |
|
||||
| TypeScript (Node) | @Vrolijkx (2016/05/01) |
|
||||
| TypeScript (Angular1) | @Vrolijkx (2016/05/01) |
|
||||
| TypeScript (Angular2) | @Vrolijkx (2016/05/01) |
|
||||
| TypeScript (Fetch) | |
|
||||
## Server Stubs
|
||||
| Langauges | Core Team (date joined) |
|
||||
|:------------- |:-------------|
|
||||
| C# ASP.NET5 | @jimschubert (2016/05/01) |
|
||||
| Haskell Servant | |
|
||||
| Java Spring Boot | |
|
||||
| Java SpringMVC | @kolyjjj (2016/05/01) |
|
||||
| Java JAX-RS | |
|
||||
| NodeJS | @kolyjjj (2016/05/01) |
|
||||
| PHP Lumen | @abcsum (2016/05/01) |
|
||||
| PHP Silex | |
|
||||
| PHP Slim | |
|
||||
| Python Flask | |
|
||||
| Ruby Sinatra | @wing328 (2016/05/01) | |
|
||||
| Scala Scalatra | | |
|
||||
|
||||
## Template Creator
|
||||
Here is a list of template creators:
|
||||
* API Clients:
|
||||
* Akka-Scala: @cchafer
|
||||
* C# (.NET 2.0): @who
|
||||
* Clojure: @xhh
|
||||
* Dart: @yissachar
|
||||
* Groovy: @victorgit
|
||||
* Go: @wing328
|
||||
* Java (Retrofit): @0legg
|
||||
* Java (Retrofi2): @emilianobonassi
|
||||
* Java (Jersey2): @xhh
|
||||
* Java (okhttp-gson): @xhh
|
||||
* Javascript/NodeJS: @jfiala
|
||||
* Javascript (Closure-annotated Angular) @achew22
|
||||
* Perl: @wing328
|
||||
* Swift: @tkqubo
|
||||
* TypeScript (Node): @mhardorf
|
||||
* TypeScript (Angular1): @mhardorf
|
||||
* TypeScript (Fetch): @leonyu
|
||||
* TypeScript (Angular2): @roni-frantchi
|
||||
* Server Stubs
|
||||
* C# ASP.NET5: @jimschubert
|
||||
* Haskell Servant: @algas
|
||||
* Java Spring Boot: @diyfr
|
||||
* JAX-RS RestEasy: @chameleon82
|
||||
* JAX-RS CXF: @hiveship
|
||||
* PHP Lumen: @abcsum
|
||||
* PHP Slim: @jfastnacht
|
||||
|
||||
## How to join the core team
|
||||
|
||||
Here are the requirements to become a core team member:
|
||||
- rank within top 50 in https://github.com/swagger-api/swagger-codegen/graphs/contributors
|
||||
- to contribute, here are some good [starting points](https://github.com/swagger-api/swagger-codegen/issues?q=is%3Aopen+is%3Aissue+label%3A%22Need+community+contribution%22)
|
||||
- regular contributions to the project
|
||||
- about 3 hours per week
|
||||
- for contribution, it can be addressing issues, reviewing PRs submitted by others, submitting PR to fix bugs or make enhancements, etc
|
||||
|
||||
To join the core team, please reach out to wing328hk@gmail.com (@wing328) for more information.
|
||||
|
||||
To become a Template Creator, simply submit a PR for new API client (e.g. Rust, Elixir) or server stub (e.g. Ruby Grape) generator.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
|
@ -29,7 +29,7 @@ cd $APP_DIR
|
||||
./bin/java-petstore-jersey2.sh
|
||||
./bin/java-petstore-okhttp-gson.sh
|
||||
./bin/java-petstore-retrofit.sh
|
||||
+./bin/java-petstore-retrofit2.sh
|
||||
./bin/java-petstore-retrofit2.sh
|
||||
./bin/jaxrs-petstore-server.sh
|
||||
./bin/nodejs-petstore-server.sh
|
||||
./bin/objc-petstore.sh
|
||||
@ -49,5 +49,6 @@ cd $APP_DIR
|
||||
./bin/tizen-petstore.sh
|
||||
./bin/typescript-angular-petstore.sh
|
||||
./bin/typescript-angular2-petstore.sh
|
||||
./bin/typescript-angular2-petstore-with-npm.sh
|
||||
./bin/typescript-node-petstore.sh
|
||||
./bin/lumen-petstore-server.sh
|
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l csharp -o samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l csharp -o samples/client/petstore/csharp/SwaggerClient"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/go -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l go -o samples/client/petstore/go/go-petstore"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/go -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l go -o samples/client/petstore/go/go-petstore -DpackageName=petstore "
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
30
bin/groovy-petstore.sh
Executable file
30
bin/groovy-petstore.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
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/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l groovy -o samples/client/petstore/groovy -DhideGenerationTimestamp=true"
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/haskell-servant -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l haskell-servant -o samples/server/petstore/haskell-servant"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/haskell-servant -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l haskell -o samples/server/petstore/haskell-servant"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/Javascript -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l javascript -o samples/client/petstore/javascript"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/Javascript -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l javascript -o samples/client/petstore/javascript"
|
||||
|
||||
java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -27,7 +27,7 @@ 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/swagger-codegen/src/main/resources/Javascript \
|
||||
-i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l javascript \
|
||||
-i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l javascript \
|
||||
-o samples/client/petstore/javascript-promise \
|
||||
--additional-properties usePromises=true"
|
||||
|
||||
|
31
bin/springboot-petstore-server.sh
Executable file
31
bin/springboot-petstore-server.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
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/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpringBoot -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l springboot -o samples/server/petstore/springboot"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular2 -c bin/typescript-angular2-petstore-with-npm.json -o samples/client/petstore/typescript-angular2-with-npm"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular2 -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular2/npm"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular2 -o samples/client/petstore/typescript-angular2"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular2 -o samples/client/petstore/typescript-angular2/default"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
5
bin/typescript-fetch-petstore-all.sh
Executable file
5
bin/typescript-fetch-petstore-all.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
./bin/typescript-fetch-petstore-target-es6.sh
|
||||
./bin/typescript-fetch-petstore-target-with-package-metadata.sh
|
||||
./bin/typescript-fetch-petstore.sh
|
3
bin/typescript-fetch-petstore-target-es6.json
Normal file
3
bin/typescript-fetch-petstore-target-es6.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"supportsES6": true
|
||||
}
|
31
bin/typescript-fetch-petstore-target-es6.sh
Executable file
31
bin/typescript-fetch-petstore-target-es6.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
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/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -c bin/typescript-fetch-petstore-target-es6.json -o samples/client/petstore/typescript-fetch/default-es6"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"npmName": "@swagger/typescript-fetch-petstore",
|
||||
"npmVersion": "0.0.1"
|
||||
}
|
31
bin/typescript-fetch-petstore-target-with-package-metadata.sh
Executable file
31
bin/typescript-fetch-petstore-target-with-package-metadata.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
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/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -c bin/typescript-fetch-petstore-target-with-package-metadata.json -o samples/client/petstore/typescript-fetch/with-package-metadata"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
31
bin/typescript-fetch-petstore.sh
Executable file
31
bin/typescript-fetch-petstore.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
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/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -o samples/client/petstore/typescript-fetch/default"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
31
bin/typescript-node-petstore-with-npm.sh
Executable file
31
bin/typescript-node-petstore-with-npm.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
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/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-node -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-node/npm"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-node -o samples/client/petstore/typescript-node"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-node -o samples/client/petstore/typescript-node/default"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\csharp -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l csharp -o samples\client\petstore\csharp\SwaggerClientTest\Lib\SwaggerClient
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\csharp -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l csharp -o samples\client\petstore\csharp\SwaggerClient
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
10
bin/windows/spring-mvc-petstore-j8-async-server.bat
Normal file
10
bin/windows/spring-mvc-petstore-j8-async-server.bat
Normal file
@ -0,0 +1,10 @@
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\JavaSpringMVC -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l spring-mvc -o samples/server/petstore/spring-mvc-j8-async -c bin/spring-mvc-petstore-j8-async.json
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
10
bin/windows/spring-mvc-petstore-server.bat
Normal file
10
bin/windows/spring-mvc-petstore-server.bat
Normal file
@ -0,0 +1,10 @@
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\JavaSpringMVC -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l spring-mvc -o samples\server\petstore\spring-mvc
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
10
bin/windows/springboot-petstore-server.bat
Normal file
10
bin/windows/springboot-petstore-server.bat
Normal file
@ -0,0 +1,10 @@
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\JavaSpringBoot -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l springboot -o samples\server\petstore\springboot
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
10
bin/windows/typescript-angular2-with-npm.bat
Normal file
10
bin/windows/typescript-angular2-with-npm.bat
Normal file
@ -0,0 +1,10 @@
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\typescript-angular -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -c bin/typescript-petstore-npm.json -l typescript-angular2 -o samples\client\petstore\typescript-angular2\npm
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\typescript-angular -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l typescript-angular2 -o samples\client\petstore\typescript-angular
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\typescript-angular -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l typescript-angular2 -o samples\client\petstore\typescript-angular2\default
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
10
bin/windows/typescript-fetch.bat
Executable file
10
bin/windows/typescript-fetch.bat
Executable file
@ -0,0 +1,10 @@
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\typescript-fetch -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l typescript-fetch -o samples\client\petstore\typescript-fetch
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
10
bin/windows/typescript-node-with-npm.bat
Executable file
10
bin/windows/typescript-node-with-npm.bat
Executable file
@ -0,0 +1,10 @@
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\typescript-node -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -c bin/typescript-petstore-npm.json -l typescript-node -o samples\client\petstore\typescript-node\npm
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\typescript-node -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l typescript-node -o samples\client\petstore\typescript-node
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\typescript-node -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l typescript-node -o samples\client\petstore\typescript-node\default
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
@ -252,8 +252,8 @@
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -89,7 +89,7 @@ public class CodegenConstants {
|
||||
public static final String MODEL_NAME_SUFFIX_DESC = "Suffix that will be appended to all model names. Default is the empty string.";
|
||||
|
||||
public static final String OPTIONAL_EMIT_DEFAULT_VALUES = "optionalEmitDefaultValues";
|
||||
public static final String OPTIONAL_EMIT_DEFAULT_VALUES_DESC = "Set DataMember's EmitDefaultValue, default false.";
|
||||
public static final String OPTIONAL_EMIT_DEFAULT_VALUES_DESC = "Set DataMember's EmitDefaultValue.";
|
||||
|
||||
public static final String GIT_USER_ID = "gitUserId";
|
||||
public static final String GIT_USER_ID_DESC = "Git user ID, e.g. swagger-api.";
|
||||
@ -103,4 +103,6 @@ public class CodegenConstants {
|
||||
public static final String HTTP_USER_AGENT = "httpUserAgent";
|
||||
public static final String HTTP_USER_AGENT_DESC = "HTTP user agent, e.g. codegen_csharp_api_client, default to 'Swagger-Codegen/{packageVersion}}/{language}'";
|
||||
|
||||
public static final String SUPPORTS_ES6 = "supportsES6";
|
||||
public static final String SUPPORTS_ES6_DESC = "Generate code that conforms to ES6.";
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class CodegenModel {
|
||||
public List<CodegenProperty> requiredVars = new ArrayList<CodegenProperty>(); // a list of required properties
|
||||
public List<CodegenProperty> optionalVars = new ArrayList<CodegenProperty>(); // a list of optional properties
|
||||
public List<CodegenProperty> allVars;
|
||||
public List<String> allowableValues;
|
||||
public Map<String, Object> allowableValues;
|
||||
|
||||
// Sorted sets of required parameters.
|
||||
public Set<String> mandatory = new TreeSet<String>();
|
||||
|
@ -9,8 +9,8 @@ import io.swagger.models.parameters.*;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.models.properties.PropertyBuilder.PropertyId;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -55,6 +55,10 @@ public class DefaultCodegen {
|
||||
protected Boolean ensureUniqueParams = true;
|
||||
protected String gitUserId, gitRepoId, releaseNote;
|
||||
protected String httpUserAgent;
|
||||
// How to encode special characters like $
|
||||
// They are translated to words like "Dollar" and prefixed with '
|
||||
// Then translated back during JSON encoding and decoding
|
||||
protected Map<Character, String> specialCharReplacements = new HashMap<Character, String>();
|
||||
|
||||
public List<CliOption> cliOptions() {
|
||||
return cliOptions;
|
||||
@ -97,10 +101,10 @@ public class DefaultCodegen {
|
||||
@SuppressWarnings({ "static-method", "unchecked" })
|
||||
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
|
||||
if (supportsInheritance) {
|
||||
// Index all CodegenModels by name.
|
||||
// Index all CodegenModels by model name.
|
||||
Map<String, CodegenModel> allModels = new HashMap<String, CodegenModel>();
|
||||
for (Entry<String, Object> entry : objs.entrySet()) {
|
||||
String modelName = entry.getKey();
|
||||
String modelName = toModelName(entry.getKey());
|
||||
Map<String, Object> inner = (Map<String, Object>) entry.getValue();
|
||||
List<Map<String, Object>> models = (List<Map<String, Object>>) inner.get("models");
|
||||
for (Map<String, Object> mo : models) {
|
||||
@ -133,6 +137,161 @@ public class DefaultCodegen {
|
||||
return objs;
|
||||
}
|
||||
|
||||
/**
|
||||
* post process enum defined in model's properties
|
||||
*
|
||||
* @param objs Map of models
|
||||
* @return maps of models with better enum support
|
||||
*/
|
||||
public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
|
||||
// for enum model
|
||||
if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) {
|
||||
Map<String, Object> allowableValues = cm.allowableValues;
|
||||
|
||||
List<Object> values = (List<Object>) allowableValues.get("values");
|
||||
List<Map<String, String>> enumVars = new ArrayList<Map<String, String>>();
|
||||
String commonPrefix = findCommonPrefixOfVars(values);
|
||||
int truncateIdx = commonPrefix.length();
|
||||
for (Object value : values) {
|
||||
Map<String, String> enumVar = new HashMap<String, String>();
|
||||
String enumName;
|
||||
if (truncateIdx == 0) {
|
||||
enumName = value.toString();
|
||||
} else {
|
||||
enumName = value.toString().substring(truncateIdx);
|
||||
if ("".equals(enumName)) {
|
||||
enumName = value.toString();
|
||||
}
|
||||
}
|
||||
enumVar.put("name", toEnumVarName(enumName, cm.dataType));
|
||||
enumVar.put("value", toEnumValue(value.toString(), cm.dataType));
|
||||
enumVars.add(enumVar);
|
||||
}
|
||||
cm.allowableValues.put("enumVars", enumVars);
|
||||
}
|
||||
|
||||
// for enum model's properties
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
Map<String, Object> allowableValues = var.allowableValues;
|
||||
|
||||
// handle ArrayProperty
|
||||
if (var.items != null) {
|
||||
allowableValues = var.items.allowableValues;
|
||||
}
|
||||
|
||||
if (allowableValues == null) {
|
||||
continue;
|
||||
}
|
||||
//List<String> values = (List<String>) allowableValues.get("values");
|
||||
List<Object> values = (List<Object>) allowableValues.get("values");
|
||||
if (values == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// put "enumVars" map into `allowableValues", including `name` and `value`
|
||||
List<Map<String, String>> enumVars = new ArrayList<Map<String, String>>();
|
||||
String commonPrefix = findCommonPrefixOfVars(values);
|
||||
int truncateIdx = commonPrefix.length();
|
||||
for (Object value : values) {
|
||||
Map<String, String> enumVar = new HashMap<String, String>();
|
||||
String enumName;
|
||||
if (truncateIdx == 0) {
|
||||
enumName = value.toString();
|
||||
} else {
|
||||
enumName = value.toString().substring(truncateIdx);
|
||||
if ("".equals(enumName)) {
|
||||
enumName = value.toString();
|
||||
}
|
||||
}
|
||||
enumVar.put("name", toEnumVarName(enumName, var.datatype));
|
||||
enumVar.put("value", toEnumValue(value.toString(), var.datatype));
|
||||
enumVars.add(enumVar);
|
||||
}
|
||||
allowableValues.put("enumVars", enumVars);
|
||||
// handle default value for enum, e.g. available => StatusEnum.AVAILABLE
|
||||
if (var.defaultValue != null) {
|
||||
String enumName = null;
|
||||
for (Map<String, String> enumVar : enumVars) {
|
||||
if (toEnumValue(var.defaultValue, var.datatype).equals(enumVar.get("value"))) {
|
||||
enumName = enumVar.get("name");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (enumName != null) {
|
||||
var.defaultValue = toEnumDefaultValue(enumName, var.datatypeWithEnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the common prefix of variables for enum naming
|
||||
*
|
||||
* @param vars List of variable names
|
||||
* @return the common prefix for naming
|
||||
*/
|
||||
public String findCommonPrefixOfVars(List<Object> vars) {
|
||||
try {
|
||||
String[] listStr = vars.toArray(new String[vars.size()]);
|
||||
|
||||
String prefix = StringUtils.getCommonPrefix(listStr);
|
||||
// exclude trailing characters that should be part of a valid variable
|
||||
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
|
||||
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
|
||||
} catch (ArrayStoreException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enum default value in the language specifed format
|
||||
*
|
||||
* @param value enum variable name
|
||||
* @param datatype data type
|
||||
* @return the default value for the enum
|
||||
*/
|
||||
public String toEnumDefaultValue(String value, String datatype) {
|
||||
return datatype + "." + value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enum value in the language specifed format
|
||||
* e.g. status becomes "status"
|
||||
*
|
||||
* @param value enum variable name
|
||||
* @param datatype data type
|
||||
* @return the sanitized value for enum
|
||||
*/
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
if ("number".equalsIgnoreCase(datatype)) {
|
||||
return value;
|
||||
} else {
|
||||
return "\"" + escapeText(value) + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sanitized variable name for enum
|
||||
*
|
||||
* @param value enum variable name
|
||||
* @param datatype data type
|
||||
* @return the sanitized variable name for enum
|
||||
*/
|
||||
public String toEnumVarName(String value, String datatype) {
|
||||
String var = value.replaceAll("\\W+", "_").toUpperCase();
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
} else {
|
||||
return var;
|
||||
}
|
||||
}
|
||||
|
||||
// override with any special post-processing
|
||||
@SuppressWarnings("static-method")
|
||||
@ -170,7 +329,11 @@ public class DefaultCodegen {
|
||||
@SuppressWarnings("static-method")
|
||||
public String escapeText(String input) {
|
||||
if (input != null) {
|
||||
return StringEscapeUtils.escapeJava(input).replace("\\/", "/");
|
||||
// remove \t, \n, \r
|
||||
// repalce \ with \\
|
||||
// repalce " with \"
|
||||
// outter unescape to retain the original multi-byte characters
|
||||
return StringEscapeUtils.unescapeJava(StringEscapeUtils.escapeJava(input).replace("\\/", "/")).replaceAll("[\\t\\n\\r]"," ").replace("\\", "\\\\").replace("\"", "\\\"");
|
||||
}
|
||||
return input;
|
||||
}
|
||||
@ -456,7 +619,7 @@ public class DefaultCodegen {
|
||||
/**
|
||||
* Return the Enum name (e.g. StatusEnum given 'status')
|
||||
*
|
||||
* @param property Codegen property object
|
||||
* @param property Codegen property
|
||||
* @return the Enum name
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
@ -573,6 +736,31 @@ public class DefaultCodegen {
|
||||
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC).defaultValue(Boolean.TRUE.toString()));
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants
|
||||
.ENSURE_UNIQUE_PARAMS_DESC).defaultValue(Boolean.TRUE.toString()));
|
||||
|
||||
// initalize special character mapping
|
||||
initalizeSpecialCharacterMapping();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initalize special character mapping
|
||||
*/
|
||||
protected void initalizeSpecialCharacterMapping() {
|
||||
// Initialize special characters
|
||||
specialCharReplacements.put('$', "Dollar");
|
||||
specialCharReplacements.put('^', "Caret");
|
||||
specialCharReplacements.put('|', "Pipe");
|
||||
specialCharReplacements.put('=', "Equal");
|
||||
specialCharReplacements.put('*', "Star");
|
||||
specialCharReplacements.put('-', "Minus");
|
||||
specialCharReplacements.put('&', "Ampersand");
|
||||
specialCharReplacements.put('%', "Percent");
|
||||
specialCharReplacements.put('#', "Hash");
|
||||
specialCharReplacements.put('@', "At");
|
||||
specialCharReplacements.put('!', "Exclamation");
|
||||
specialCharReplacements.put('+', "Plus");
|
||||
specialCharReplacements.put(':', "Colon");
|
||||
specialCharReplacements.put('>', "GreaterThan");
|
||||
specialCharReplacements.put('<', "LessThan");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -986,7 +1174,7 @@ public class DefaultCodegen {
|
||||
m.interfaces.add(interfaceRef);
|
||||
addImport(m, interfaceRef);
|
||||
if (allDefinitions != null) {
|
||||
final Model interfaceModel = allDefinitions.get(interfaceRef);
|
||||
final Model interfaceModel = allDefinitions.get(_interface.getSimpleRef());
|
||||
if (supportsInheritance) {
|
||||
addProperties(allProperties, allRequired, interfaceModel, allDefinitions);
|
||||
} else {
|
||||
@ -1012,7 +1200,9 @@ public class DefaultCodegen {
|
||||
ModelImpl impl = (ModelImpl) model;
|
||||
if(impl.getEnum() != null && impl.getEnum().size() > 0) {
|
||||
m.isEnum = true;
|
||||
m.allowableValues = impl.getEnum();
|
||||
// comment out below as allowableValues is not set in post processing model enum
|
||||
m.allowableValues = new HashMap<String, Object>();
|
||||
m.allowableValues.put("values", impl.getEnum());
|
||||
Property p = PropertyBuilder.build(impl.getType(), impl.getFormat(), null);
|
||||
m.dataType = getSwaggerType(p);
|
||||
}
|
||||
@ -1043,7 +1233,7 @@ public class DefaultCodegen {
|
||||
required.addAll(mi.getRequired());
|
||||
}
|
||||
} else if (model instanceof RefModel) {
|
||||
String interfaceRef = toModelName(((RefModel) model).getSimpleRef());
|
||||
String interfaceRef = ((RefModel) model).getSimpleRef();
|
||||
Model interfaceModel = allDefinitions.get(interfaceRef);
|
||||
addProperties(properties, required, interfaceModel, allDefinitions);
|
||||
} else if (model instanceof ComposedModel) {
|
||||
@ -1144,7 +1334,8 @@ public class DefaultCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
if (p instanceof BaseIntegerProperty) {
|
||||
// type is integer and without format
|
||||
if (p instanceof BaseIntegerProperty && !(p instanceof IntegerProperty) && !(p instanceof LongProperty)) {
|
||||
BaseIntegerProperty sp = (BaseIntegerProperty) p;
|
||||
property.isInteger = true;
|
||||
/*if (sp.getEnum() != null) {
|
||||
@ -1210,7 +1401,8 @@ public class DefaultCodegen {
|
||||
property.isByteArray = true;
|
||||
}
|
||||
|
||||
if (p instanceof DecimalProperty) {
|
||||
// type is number and without format
|
||||
if (p instanceof DecimalProperty && !(p instanceof DoubleProperty) && !(p instanceof FloatProperty)) {
|
||||
DecimalProperty sp = (DecimalProperty) p;
|
||||
property.isFloat = true;
|
||||
/*if (sp.getEnum() != null) {
|
||||
|
@ -264,6 +264,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
String suffix = config.modelTemplateFiles().get(templateName);
|
||||
String filename = config.modelFileFolder() + File.separator + config.toModelFilename(name) + suffix;
|
||||
if (!config.shouldOverwrite(filename)) {
|
||||
LOGGER.info("Skipped overwriting " + filename);
|
||||
continue;
|
||||
}
|
||||
String templateFile = getFullTemplateFile(config, templateName);
|
||||
@ -285,7 +286,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
for (String templateName : config.modelTestTemplateFiles().keySet()) {
|
||||
String suffix = config.modelTestTemplateFiles().get(templateName);
|
||||
String filename = config.modelTestFileFolder() + File.separator + config.toModelTestFilename(name) + suffix;
|
||||
if (!config.shouldOverwrite(filename)) {
|
||||
// do not overwrite test file that already exists
|
||||
if (new File(filename).exists()) {
|
||||
LOGGER.info("File exists. Skipped overwriting " + filename);
|
||||
continue;
|
||||
}
|
||||
String templateFile = getFullTemplateFile(config, templateName);
|
||||
@ -308,6 +311,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
String suffix = config.modelDocTemplateFiles().get(templateName);
|
||||
String filename = config.modelDocFileFolder() + File.separator + config.toModelDocFilename(name) + suffix;
|
||||
if (!config.shouldOverwrite(filename)) {
|
||||
LOGGER.info("Skipped overwriting " + filename);
|
||||
continue;
|
||||
}
|
||||
String templateFile = getFullTemplateFile(config, templateName);
|
||||
@ -393,6 +397,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
for (String templateName : config.apiTemplateFiles().keySet()) {
|
||||
String filename = config.apiFilename(templateName, tag);
|
||||
if (!config.shouldOverwrite(filename) && new File(filename).exists()) {
|
||||
LOGGER.info("Skipped overwriting " + filename);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -415,10 +420,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
// to generate api test files
|
||||
for (String templateName : config.apiTestTemplateFiles().keySet()) {
|
||||
String filename = config.apiTestFilename(templateName, tag);
|
||||
if (!config.shouldOverwrite(filename) && new File(filename).exists()) {
|
||||
// do not overwrite test file that already exists
|
||||
if (new File(filename).exists()) {
|
||||
LOGGER.info("File exists. Skipped overwriting " + filename);
|
||||
continue;
|
||||
}
|
||||
|
||||
String templateFile = getFullTemplateFile(config, templateName);
|
||||
String template = readTemplate(templateFile);
|
||||
Template tmpl = Mustache.compiler()
|
||||
@ -439,6 +445,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
for (String templateName : config.apiDocTemplateFiles().keySet()) {
|
||||
String filename = config.apiDocFilename(templateName, tag);
|
||||
if (!config.shouldOverwrite(filename) && new File(filename).exists()) {
|
||||
LOGGER.info("Skipped overwriting " + filename);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -521,6 +528,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
String outputFilename = outputFolder + File.separator + support.destinationFilename;
|
||||
if (!config.shouldOverwrite(outputFilename)) {
|
||||
LOGGER.info("Skipped overwriting " + outputFilename);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,8 @@ public class CodegenConfigurator {
|
||||
private Map<String, String> additionalProperties = new HashMap<String, String>();
|
||||
private Map<String, String> importMappings = new HashMap<String, String>();
|
||||
private Set<String> languageSpecificPrimitives = new HashSet<String>();
|
||||
private String gitUserId="YOUR_GIT_USR_ID";
|
||||
private String gitRepoId="YOUR_GIT_REPO_ID";
|
||||
private String gitUserId="GIT_USER_ID";
|
||||
private String gitRepoId="GIT_REPO_ID";
|
||||
private String releaseNote="Minor update";
|
||||
private String httpUserAgent;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -12,7 +12,7 @@ import java.util.*;
|
||||
public abstract class AbstractCSharpCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
protected boolean optionalAssemblyInfoFlag = true;
|
||||
protected boolean optionalProjectFileFlag = false;
|
||||
protected boolean optionalProjectFileFlag = true;
|
||||
protected boolean optionalEmitDefaultValue = false;
|
||||
protected boolean optionalMethodArgumentFlag = true;
|
||||
protected boolean useDateTimeOffsetFlag = false;
|
||||
@ -21,7 +21,12 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String packageName = "IO.Swagger";
|
||||
protected String sourceFolder = "src" + File.separator + packageName;
|
||||
|
||||
protected String sourceFolder = "src";
|
||||
|
||||
// TODO: Add option for test folder output location. Nice to allow e.g. ./test instead of ./src.
|
||||
// This would require updating relative paths (e.g. path to main project file in test project file)
|
||||
protected String testFolder = sourceFolder;
|
||||
|
||||
protected Set<String> collectionTypes;
|
||||
protected Set<String> mapTypes;
|
||||
@ -88,7 +93,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
"Int32",
|
||||
"Int64",
|
||||
"Float",
|
||||
"Guid",
|
||||
"Guid?",
|
||||
"System.IO.Stream", // not really a primitive, we include it to avoid model import
|
||||
"Object")
|
||||
);
|
||||
@ -115,7 +120,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
typeMapping.put("list", "List");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("uuid", "Guid");
|
||||
typeMapping.put("uuid", "Guid?");
|
||||
}
|
||||
|
||||
public void setReturnICollection(boolean returnICollection) {
|
||||
@ -203,11 +208,6 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return StringUtils.capitalize(property.name) + "Enum?";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
@ -223,7 +223,8 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
// process enum in models
|
||||
return postProcessModelsEnum(objs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -277,12 +278,12 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + packageName + File.separator + apiPackage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar);
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + packageName + File.separator + modelPackage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -532,7 +533,6 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
return toModelName(name) + "Tests";
|
||||
}
|
||||
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
@ -544,4 +544,57 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
this.sourceFolder = sourceFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String name, String datatype) {
|
||||
String enumName = sanitizeName(name);
|
||||
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
enumName = enumName.replaceFirst("_$", "");
|
||||
|
||||
enumName = camelize(enumName) + "Enum";
|
||||
|
||||
LOGGER.info("toEnumVarName = " + enumName);
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return sanitizeName(camelize(property.name)) + "Enum";
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String enumName = sanitizeName(property.name);
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
enumName = modelNamePrefix + "_" + enumName;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
enumName = enumName + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(enumName)) {
|
||||
LOGGER.warn(enumName + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + enumName));
|
||||
enumName = "model_" + enumName; // e.g. return => ModelReturn (after camelize)
|
||||
}
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public String testPackageName() {
|
||||
return this.packageName + ".Test";
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,12 @@ import io.swagger.models.properties.*;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
protected String modelPropertyNaming= "camelCase";
|
||||
protected Boolean supportsES6 = true;
|
||||
|
||||
public AbstractTypeScriptClientCodegen() {
|
||||
super();
|
||||
@ -60,18 +61,25 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
typeMapping.put("ByteArray", "string");
|
||||
typeMapping.put("UUID", "string");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PROPERTY_NAMING, CodegenConstants.MODEL_PROPERTY_NAMING_DESC).defaultValue("camelCase"));
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.SUPPORTS_ES6, CodegenConstants.SUPPORTS_ES6_DESC).defaultValue("false"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) {
|
||||
setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SUPPORTS_ES6)) {
|
||||
setSupportsES6(Boolean.valueOf((String)additionalProperties.get(CodegenConstants.SUPPORTS_ES6)));
|
||||
additionalProperties.put("supportsES6", getSupportsES6());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -230,4 +238,66 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||
return value;
|
||||
} else {
|
||||
return "\'" + escapeText(value) + "\'";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumDefaultValue(String value, String datatype) {
|
||||
return datatype + "_" + value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String name, String datatype) {
|
||||
// number
|
||||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||
String varName = new String(name);
|
||||
varName = varName.replaceAll("-", "MINUS_");
|
||||
varName = varName.replaceAll("\\+", "PLUS_");
|
||||
varName = varName.replaceAll("\\.", "_DOT_");
|
||||
return varName;
|
||||
}
|
||||
|
||||
// string
|
||||
String enumName = sanitizeName(underscore(name).toUpperCase());
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
enumName = enumName.replaceFirst("_$", "");
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String enumName = toModelName(property.name) + "Enum";
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
// process enum in models
|
||||
return postProcessModelsEnum(objs);
|
||||
}
|
||||
|
||||
public void setSupportsES6(Boolean value) {
|
||||
supportsES6 = value;
|
||||
}
|
||||
|
||||
public Boolean getSupportsES6() {
|
||||
return supportsES6;
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -3,6 +3,7 @@ package io.swagger.codegen.languages;
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
@ -14,7 +15,7 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -32,6 +33,8 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
// requestPackage and authPackage are used by the "volley" template/library
|
||||
protected String requestPackage = "io.swagger.client.request";
|
||||
protected String authPackage = "io.swagger.client.auth";
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
|
||||
public AndroidClientCodegen() {
|
||||
super();
|
||||
@ -123,6 +126,26 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
return (outputFolder + "/" + apiDocPath).replace( '/', File.separatorChar );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
return ( outputFolder + "/" + modelDocPath ).replace( '/', File.separatorChar );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiDocFilename( String name ) {
|
||||
return toApiName( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelDocFilename( String name ) {
|
||||
return toModelName( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
@ -224,6 +247,70 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParameterExampleValue(CodegenParameter p) {
|
||||
String example;
|
||||
|
||||
if (p.defaultValue == null) {
|
||||
example = p.example;
|
||||
} else {
|
||||
example = p.defaultValue;
|
||||
}
|
||||
|
||||
String type = p.baseType;
|
||||
if (type == null) {
|
||||
type = p.dataType;
|
||||
}
|
||||
|
||||
if ("String".equals(type)) {
|
||||
if (example == null) {
|
||||
example = p.paramName + "_example";
|
||||
}
|
||||
example = "\"" + escapeText(example) + "\"";
|
||||
} else if ("Integer".equals(type) || "Short".equals(type)) {
|
||||
if (example == null) {
|
||||
example = "56";
|
||||
}
|
||||
} else if ("Long".equals(type)) {
|
||||
if (example == null) {
|
||||
example = "56";
|
||||
}
|
||||
example = example + "L";
|
||||
} else if ("Float".equals(type)) {
|
||||
if (example == null) {
|
||||
example = "3.4";
|
||||
}
|
||||
example = example + "F";
|
||||
} else if ("Double".equals(type)) {
|
||||
example = "3.4";
|
||||
example = example + "D";
|
||||
} else if ("Boolean".equals(type)) {
|
||||
if (example == null) {
|
||||
example = "true";
|
||||
}
|
||||
} else if ("File".equals(type)) {
|
||||
if (example == null) {
|
||||
example = "/path/to/file";
|
||||
}
|
||||
example = "new File(\"" + escapeText(example) + "\")";
|
||||
} else if ("Date".equals(type)) {
|
||||
example = "new Date()";
|
||||
} else if (!languageSpecificPrimitives.contains(type)) {
|
||||
// type is a model class, e.g. User
|
||||
example = "new " + type + "()";
|
||||
}
|
||||
|
||||
if (example == null) {
|
||||
example = "null";
|
||||
} else if (Boolean.TRUE.equals(p.isListContainer)) {
|
||||
example = "Arrays.asList(" + example + ")";
|
||||
} else if (Boolean.TRUE.equals(p.isMapContainer)) {
|
||||
example = "new HashMap()";
|
||||
}
|
||||
|
||||
p.example = example;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
@ -290,9 +377,23 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
this.setLibrary((String) additionalProperties.get(CodegenConstants.LIBRARY));
|
||||
}
|
||||
|
||||
//make api and model doc path available in mustache template
|
||||
additionalProperties.put( "apiDocPath", apiDocPath );
|
||||
additionalProperties.put( "modelDocPath", modelDocPath );
|
||||
|
||||
if (StringUtils.isEmpty(getLibrary())) {
|
||||
modelDocTemplateFiles.put( "model_doc.mustache", ".md" );
|
||||
apiDocTemplateFiles.put( "api_doc.mustache", ".md" );
|
||||
//supportingFiles.add(new SupportingFile("api_doc.mustache", apiDocPath, "api.md"));
|
||||
//supportingFiles.add(new SupportingFile("model_doc.mustache", modelDocPath, "model.md"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
addSupportingFilesForDefault();
|
||||
} else if ("volley".equals(getLibrary())) {
|
||||
modelDocTemplateFiles.put( "model_doc.mustache", ".md" );
|
||||
apiDocTemplateFiles.put( "api_doc.mustache", ".md" );
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
//supportingFiles.add(new SupportingFile("api_doc.mustache", apiDocPath, "api.md"));
|
||||
//supportingFiles.add(new SupportingFile("model_doc.mustache", modelDocPath, "model.md"));
|
||||
addSupportingFilesForVolley();
|
||||
}
|
||||
}
|
||||
@ -317,7 +418,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
}
|
||||
|
||||
private void addSupportingFilesForVolley() {
|
||||
// supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
// supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
supportingFiles.add(new SupportingFile("build.mustache", "", "build.gradle"));
|
||||
supportingFiles.add(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
|
||||
|
@ -2,7 +2,7 @@ package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -11,6 +11,8 @@ import java.util.*;
|
||||
|
||||
public class AspNet5ServerCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
protected String sourceFolder = "src" + File.separator + packageName;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
protected Logger LOGGER = LoggerFactory.getLogger(AspNet5ServerCodegen.class);
|
||||
|
||||
|
@ -25,8 +25,8 @@ import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -68,9 +68,6 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||
|
||||
// C# client default
|
||||
setSourceFolder("src" + File.separator + "main" + File.separator + "csharp");
|
||||
|
||||
cliOptions.clear();
|
||||
|
||||
// CLI options
|
||||
@ -141,9 +138,9 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
apiPackage = packageName + ".Api";
|
||||
modelPackage = packageName + ".Model";
|
||||
clientPackage = packageName + ".Client";
|
||||
apiPackage = "Api";
|
||||
modelPackage = "Model";
|
||||
clientPackage = "Client";
|
||||
|
||||
additionalProperties.put("clientPackage", clientPackage);
|
||||
|
||||
@ -157,6 +154,10 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.DOTNET_FRAMEWORK)) {
|
||||
setTargetFramework((String) additionalProperties.get(CodegenConstants.DOTNET_FRAMEWORK));
|
||||
} else {
|
||||
// Ensure default is set.
|
||||
setTargetFramework(NET45);
|
||||
additionalProperties.put("targetFramework", this.targetFramework);
|
||||
}
|
||||
|
||||
if (NET35.equals(this.targetFramework)) {
|
||||
@ -201,8 +202,12 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
.get(CodegenConstants.OPTIONAL_ASSEMBLY_INFO).toString()));
|
||||
}
|
||||
|
||||
String packageFolder = sourceFolder + File.separator + packageName.replace(".", java.io.File.separator);
|
||||
String clientPackageDir = sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator);
|
||||
final String testPackageName = testPackageName();
|
||||
String packageFolder = sourceFolder + File.separator + packageName;
|
||||
String clientPackageDir = packageFolder + File.separator + clientPackage;
|
||||
String testPackageFolder = testFolder + File.separator + testPackageName;
|
||||
|
||||
additionalProperties.put("testPackageName", testPackageName);
|
||||
|
||||
//Compute the relative path to the bin directory where the external assemblies live
|
||||
//This is necessary to properly generate the project file
|
||||
@ -210,7 +215,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
String binRelativePath = "..\\";
|
||||
for (int i = 0; i < packageDepth; i = i + 1)
|
||||
binRelativePath += "..\\";
|
||||
binRelativePath += "vendor\\";
|
||||
binRelativePath += "vendor";
|
||||
additionalProperties.put("binRelativePath", binRelativePath);
|
||||
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache",
|
||||
@ -222,9 +227,13 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
supportingFiles.add(new SupportingFile("ApiResponse.mustache",
|
||||
clientPackageDir, "ApiResponse.cs"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
|
||||
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "compile-mono.sh"));
|
||||
supportingFiles.add(new SupportingFile("packages.config.mustache", "vendor" + java.io.File.separator, "packages.config"));
|
||||
supportingFiles.add(new SupportingFile("compile.mustache", "", "build.bat"));
|
||||
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "build.sh"));
|
||||
|
||||
// copy package.config to nuget's standard location for project-level installs
|
||||
supportingFiles.add(new SupportingFile("packages.config.mustache", packageFolder + File.separator, "packages.config"));
|
||||
supportingFiles.add(new SupportingFile("packages_test.config.mustache", testPackageFolder + File.separator, "packages.config"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
@ -233,7 +242,14 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
supportingFiles.add(new SupportingFile("AssemblyInfo.mustache", packageFolder + File.separator + "Properties", "AssemblyInfo.cs"));
|
||||
}
|
||||
if (optionalProjectFileFlag) {
|
||||
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, clientPackage + ".csproj"));
|
||||
supportingFiles.add(new SupportingFile("Solution.mustache", "", packageName + ".sln"));
|
||||
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, packageName + ".csproj"));
|
||||
|
||||
// TODO: Check if test project output is enabled, partially related to #2506. Should have options for:
|
||||
// 1) No test project
|
||||
// 2) No model tests
|
||||
// 3) No api tests
|
||||
supportingFiles.add(new SupportingFile("TestProject.mustache", testPackageFolder, testPackageName + ".csproj"));
|
||||
}
|
||||
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
@ -308,75 +324,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objMap) {
|
||||
Map<String, Object> objs = super.postProcessModels(objMap);
|
||||
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
Map<String, Object> allowableValues = var.allowableValues;
|
||||
|
||||
// handle ArrayProperty
|
||||
if (var.items != null) {
|
||||
allowableValues = var.items.allowableValues;
|
||||
}
|
||||
|
||||
if (allowableValues == null) {
|
||||
continue;
|
||||
}
|
||||
List<String> values = (List<String>) allowableValues.get("values");
|
||||
if (values == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// put "enumVars" map into `allowableValues", including `name` and `value`
|
||||
List<Map<String, String>> enumVars = new ArrayList<Map<String, String>>();
|
||||
String commonPrefix = findCommonPrefixOfVars(values);
|
||||
int truncateIdx = commonPrefix.length();
|
||||
for (String value : values) {
|
||||
Map<String, String> enumVar = new HashMap<String, String>();
|
||||
String enumName;
|
||||
if (truncateIdx == 0) {
|
||||
enumName = value;
|
||||
} else {
|
||||
enumName = value.substring(truncateIdx);
|
||||
if ("".equals(enumName)) {
|
||||
enumName = value;
|
||||
}
|
||||
}
|
||||
enumVar.put("name", toEnumVarName(enumName));
|
||||
enumVar.put("jsonname", value);
|
||||
enumVar.put("value", value);
|
||||
enumVars.add(enumVar);
|
||||
}
|
||||
allowableValues.put("enumVars", enumVars);
|
||||
// handle default value for enum, e.g. available => StatusEnum.AVAILABLE
|
||||
|
||||
// HACK: strip ? from enum
|
||||
if (var.datatypeWithEnum != null) {
|
||||
var.vendorExtensions.put(DATA_TYPE_WITH_ENUM_EXTENSION, var.datatypeWithEnum.substring(0, var.datatypeWithEnum.length() - 1));
|
||||
}
|
||||
|
||||
if (var.defaultValue != null) {
|
||||
String enumName = null;
|
||||
|
||||
for (Map<String, String> enumVar : enumVars) {
|
||||
|
||||
if (var.defaultValue.replace("\"", "").equals(enumVar.get("value"))) {
|
||||
enumName = enumVar.get("name");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (enumName != null && var.vendorExtensions.containsKey(DATA_TYPE_WITH_ENUM_EXTENSION)) {
|
||||
var.defaultValue = var.vendorExtensions.get(DATA_TYPE_WITH_ENUM_EXTENSION) + "." + enumName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
return super.postProcessModels(objMap);
|
||||
}
|
||||
|
||||
public void setTargetFramework(String dotnetFramework) {
|
||||
@ -436,18 +384,34 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
private String findCommonPrefixOfVars(List<String> vars) {
|
||||
String prefix = StringUtils.getCommonPrefix(vars.toArray(new String[vars.size()]));
|
||||
// exclude trailing characters that should be part of a valid variable
|
||||
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
|
||||
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
|
||||
@Override
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
if ("int?".equalsIgnoreCase(datatype) || "long?".equalsIgnoreCase(datatype) ||
|
||||
"double?".equalsIgnoreCase(datatype) || "float?".equalsIgnoreCase(datatype)) {
|
||||
return value;
|
||||
} else {
|
||||
return "\"" + escapeText(value) + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
private String toEnumVarName(String value) {
|
||||
@Override
|
||||
public String toEnumVarName(String value, String datatype) {
|
||||
// number
|
||||
if ("int?".equals(datatype) || "long?".equals(datatype) ||
|
||||
"double?".equals(datatype) || "float?".equals(datatype)) {
|
||||
String varName = "NUMBER_" + value;
|
||||
varName = varName.replaceAll("-", "MINUS_");
|
||||
varName = varName.replaceAll("\\+", "PLUS_");
|
||||
varName = varName.replaceAll("\\.", "_DOT_");
|
||||
return varName;
|
||||
}
|
||||
|
||||
// string
|
||||
String var = value.replaceAll("_", " ");
|
||||
var = WordUtils.capitalizeFully(var);
|
||||
var = var.replaceAll("\\W+", "");
|
||||
|
||||
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
} else {
|
||||
@ -491,4 +455,13 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return outputFolder + File.separator + testFolder + File.separator + testPackageName() + File.separator + apiPackage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return outputFolder + File.separator + testFolder + File.separator + testPackageName() + File.separator + modelPackage();
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import io.swagger.models.Contact;
|
||||
import io.swagger.models.Info;
|
||||
import io.swagger.models.License;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
@ -17,7 +17,7 @@ import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
@ -9,7 +9,7 @@ import io.swagger.models.parameters.Parameter;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -375,6 +375,15 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (_import.startsWith(apiPackage()))
|
||||
iterator.remove();
|
||||
}
|
||||
// if the return type is not primitive, import encoding/json
|
||||
for (CodegenOperation operation : operations) {
|
||||
if(operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
||||
Map<String, String> customImport = new HashMap<String, String>();
|
||||
customImport.put("import", "encoding/json");
|
||||
imports.add(customImport);
|
||||
break; //just need to import once
|
||||
}
|
||||
}
|
||||
|
||||
// recursivly add import for mapping one type to multipe imports
|
||||
List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports");
|
||||
|
@ -18,12 +18,6 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
protected String sourceFolder = "src";
|
||||
protected String apiVersion = "0.0.1";
|
||||
|
||||
|
||||
// How to encode special characters like $
|
||||
// They are translated to words like "Dollar" and prefixed with '
|
||||
// Then translated back during JSON encoding and decoding
|
||||
private Map<Character, String> specialCharReplacements = new HashMap<Character, String>();
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
@ -57,20 +51,8 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
public HaskellServantCodegen() {
|
||||
super();
|
||||
|
||||
// Initialize special characters
|
||||
specialCharReplacements.put('$', "Dollar");
|
||||
specialCharReplacements.put('^', "Caret");
|
||||
specialCharReplacements.put('|', "Pipe");
|
||||
specialCharReplacements.put('=', "Equal");
|
||||
specialCharReplacements.put('*', "Star");
|
||||
// override the mapping for "-" (Minus) to keep the original mapping in Haskell
|
||||
specialCharReplacements.put('-', "Dash");
|
||||
specialCharReplacements.put('&', "Ampersand");
|
||||
specialCharReplacements.put('%', "Percent");
|
||||
specialCharReplacements.put('#', "Hash");
|
||||
specialCharReplacements.put('@', "At");
|
||||
specialCharReplacements.put('!', "Exclamation");
|
||||
specialCharReplacements.put('+', "Plus");
|
||||
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/haskell-servant";
|
||||
|
@ -9,8 +9,9 @@ import io.swagger.models.Swagger;
|
||||
import io.swagger.models.parameters.FormParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
//import org.apache.commons.lang3.WordUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -89,6 +90,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
instantiationTypes.put("map", "HashMap");
|
||||
typeMapping.put("date", "Date");
|
||||
typeMapping.put("file", "File");
|
||||
typeMapping.put("UUID", "String");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
@ -651,6 +653,28 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
|
||||
objs = super.postProcessModelsEnum(objs);
|
||||
String lib = getLibrary();
|
||||
if (StringUtils.isEmpty(lib) || "feign".equals(lib) || "jersey2".equals(lib)) {
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>)objs.get("imports");
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
// for enum model
|
||||
if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) {
|
||||
cm.imports.add(importMapping.get("JsonValue"));
|
||||
Map<String, String> item = new HashMap<String, String>();
|
||||
item.put("import", importMapping.get("JsonValue"));
|
||||
imports.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
if(serializeBigDecimalAsString) {
|
||||
@ -696,63 +720,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
Map<String, Object> allowableValues = var.allowableValues;
|
||||
|
||||
// handle ArrayProperty
|
||||
if (var.items != null) {
|
||||
allowableValues = var.items.allowableValues;
|
||||
}
|
||||
|
||||
if (allowableValues == null) {
|
||||
continue;
|
||||
}
|
||||
List<String> values = (List<String>) allowableValues.get("values");
|
||||
if (values == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// put "enumVars" map into `allowableValues", including `name` and `value`
|
||||
List<Map<String, String>> enumVars = new ArrayList<Map<String, String>>();
|
||||
String commonPrefix = findCommonPrefixOfVars(values);
|
||||
int truncateIdx = commonPrefix.length();
|
||||
for (String value : values) {
|
||||
Map<String, String> enumVar = new HashMap<String, String>();
|
||||
String enumName;
|
||||
if (truncateIdx == 0) {
|
||||
enumName = value;
|
||||
} else {
|
||||
enumName = value.substring(truncateIdx);
|
||||
if ("".equals(enumName)) {
|
||||
enumName = value;
|
||||
}
|
||||
}
|
||||
enumVar.put("name", toEnumVarName(enumName));
|
||||
enumVar.put("value", value);
|
||||
enumVars.add(enumVar);
|
||||
}
|
||||
allowableValues.put("enumVars", enumVars);
|
||||
// handle default value for enum, e.g. available => StatusEnum.AVAILABLE
|
||||
if (var.defaultValue != null) {
|
||||
String enumName = null;
|
||||
for (Map<String, String> enumVar : enumVars) {
|
||||
if (var.defaultValue.equals(enumVar.get("value"))) {
|
||||
enumName = enumVar.get("name");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (enumName != null) {
|
||||
var.defaultValue = var.datatypeWithEnum + "." + enumName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
return postProcessModelsEnum(objs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -848,16 +816,35 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected boolean needToImport(String type) {
|
||||
return super.needToImport(type) && type.indexOf(".") < 0;
|
||||
}
|
||||
|
||||
private static String findCommonPrefixOfVars(List<String> vars) {
|
||||
/*
|
||||
@Override
|
||||
public String findCommonPrefixOfVars(List<String> vars) {
|
||||
String prefix = StringUtils.getCommonPrefix(vars.toArray(new String[vars.size()]));
|
||||
// exclude trailing characters that should be part of a valid variable
|
||||
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
|
||||
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
|
||||
}
|
||||
*/
|
||||
|
||||
private static String toEnumVarName(String value) {
|
||||
String var = value.replaceAll("\\W+", "_").toUpperCase();
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return sanitizeName(camelize(property.name)) + "Enum";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String value, String datatype) {
|
||||
// number
|
||||
if ("Integer".equals(datatype) || "Long".equals(datatype) ||
|
||||
"Float".equals(datatype) || "Double".equals(datatype)) {
|
||||
String varName = "NUMBER_" + value;
|
||||
varName = varName.replaceAll("-", "MINUS_");
|
||||
varName = varName.replaceAll("\\+", "PLUS_");
|
||||
varName = varName.replaceAll("\\.", "_DOT_");
|
||||
return varName;
|
||||
}
|
||||
|
||||
// string
|
||||
String var = value.replaceAll("\\W+", "_").replaceAll("_+", "_").toUpperCase();
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
} else {
|
||||
@ -865,6 +852,16 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
if ("Integer".equals(datatype) || "Long".equals(datatype) ||
|
||||
"Float".equals(datatype) || "Double".equals(datatype)) {
|
||||
return value;
|
||||
} else {
|
||||
return "\"" + escapeText(value) + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
// This generator uses inline classes to define enums, which breaks when
|
||||
// dealing with models that have subTypes. To clean this up, we will analyze
|
||||
|
@ -4,7 +4,7 @@ import io.swagger.codegen.*;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
@ -12,9 +12,12 @@ import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.models.ArrayModel;
|
||||
import io.swagger.models.ComposedModel;
|
||||
import io.swagger.models.Info;
|
||||
import io.swagger.models.License;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
@ -30,7 +33,7 @@ import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.RefProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -63,6 +66,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
protected String projectVersion;
|
||||
protected String projectLicenseName;
|
||||
|
||||
protected String invokerPackage;
|
||||
protected String sourceFolder = "src";
|
||||
protected String localVariablePrefix = "";
|
||||
protected boolean usePromises;
|
||||
@ -132,11 +136,13 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
// binary not supported in JavaScript client right now, using String as a workaround
|
||||
typeMapping.put("ByteArray", "String"); // I don't see ByteArray defined in the Swagger docs.
|
||||
typeMapping.put("binary", "String");
|
||||
typeMapping.put("UUID", "String");
|
||||
|
||||
importMapping.clear();
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC).defaultValue("src"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.LOCAL_VARIABLE_PREFIX, CodegenConstants.LOCAL_VARIABLE_PREFIX_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(PROJECT_NAME,
|
||||
@ -203,6 +209,9 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
|
||||
setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
|
||||
}
|
||||
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||
setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||
}
|
||||
if (additionalProperties.containsKey(USE_PROMISES)) {
|
||||
setUsePromises(Boolean.parseBoolean((String)additionalProperties.get(USE_PROMISES)));
|
||||
}
|
||||
@ -265,6 +274,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
additionalProperties.put(PROJECT_DESCRIPTION, escapeText(projectDescription));
|
||||
additionalProperties.put(PROJECT_VERSION, projectVersion);
|
||||
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||
additionalProperties.put(CodegenConstants.LOCAL_VARIABLE_PREFIX, localVariablePrefix);
|
||||
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
additionalProperties.put(CodegenConstants.SOURCE_FOLDER, sourceFolder);
|
||||
@ -278,8 +288,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
|
||||
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", sourceFolder, "index.js"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", sourceFolder, "ApiClient.js"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", createPath(sourceFolder, invokerPackage), "index.js"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", createPath(sourceFolder, invokerPackage), "ApiClient.js"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
}
|
||||
@ -289,14 +299,41 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates an array of path segments into a path string.
|
||||
* @param segments The path segments to concatenate. A segment may contain either of the file separator characters '\' or '/'.
|
||||
* A segment is ignored if it is <code>null</code>, empty or ".".
|
||||
* @return A path string using the correct platform-specific file separator character.
|
||||
*/
|
||||
private String createPath(String... segments) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (String segment : segments) {
|
||||
if (!StringUtils.isEmpty(segment) && !segment.equals(".")) {
|
||||
if (buf.length() != 0)
|
||||
buf.append(File.separatorChar);
|
||||
buf.append(segment);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < buf.length(); i++) {
|
||||
char c = buf.charAt(i);
|
||||
if ((c == '/' || c == '\\') && c != File.separatorChar)
|
||||
buf.setCharAt(i, File.separatorChar);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + '/' + sourceFolder + '/' + apiPackage().replace('.', '/');
|
||||
return createPath(outputFolder, sourceFolder, invokerPackage, apiPackage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + '/' + sourceFolder + '/' + modelPackage().replace('.', '/');
|
||||
return createPath(outputFolder, sourceFolder, invokerPackage, modelPackage());
|
||||
}
|
||||
|
||||
public void setInvokerPackage(String invokerPackage) {
|
||||
this.invokerPackage = invokerPackage;
|
||||
}
|
||||
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
@ -345,12 +382,12 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
return (outputFolder + "/" + apiDocPath).replace('/', File.separatorChar);
|
||||
return createPath(outputFolder, apiDocPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
|
||||
return createPath(outputFolder, modelDocPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -654,10 +691,23 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
|
||||
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||
final Model parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||
final Model parentModel = allDefinitions.get(codegenModel.parentSchema);
|
||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel, allDefinitions);
|
||||
codegenModel = JavascriptClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
}
|
||||
if (model instanceof ArrayModel) {
|
||||
ArrayModel am = (ArrayModel) model;
|
||||
if (am.getItems() != null) {
|
||||
codegenModel.vendorExtensions.put("x-isArray", true);
|
||||
codegenModel.vendorExtensions.put("x-itemType", getSwaggerType(am.getItems()));
|
||||
}
|
||||
} else if (model instanceof ModelImpl) {
|
||||
ModelImpl mm = (ModelImpl)model;
|
||||
if (mm.getAdditionalProperties() != null) {
|
||||
codegenModel.vendorExtensions.put("x-isMap", true);
|
||||
codegenModel.vendorExtensions.put("x-itemType", getSwaggerType(mm.getAdditionalProperties()));
|
||||
}
|
||||
}
|
||||
|
||||
return codegenModel;
|
||||
}
|
||||
@ -674,7 +724,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
|
||||
private String getModelledType(String dataType) {
|
||||
return "module:" + (StringUtils.isEmpty(modelPackage) ? "" : (modelPackage + "/")) + dataType;
|
||||
return "module:" + (StringUtils.isEmpty(invokerPackage) ? "" : (invokerPackage + "/"))
|
||||
+ (StringUtils.isEmpty(modelPackage) ? "" : (modelPackage + "/")) + dataType;
|
||||
}
|
||||
|
||||
private String getJSDocTypeWithBraces(CodegenModel cm, CodegenProperty cp) {
|
||||
@ -788,6 +839,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
objs = super.postProcessModelsEnum(objs);
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
@ -802,8 +854,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
cm.vendorExtensions.put("x-all-required", allRequired);
|
||||
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
Map<String, Object> allowableValues = var.allowableValues;
|
||||
|
||||
// Add JSDoc @type value for this property.
|
||||
String jsDocType = getJSDocTypeWithBraces(cm, var);
|
||||
var.vendorExtensions.put("x-jsdoc-type", jsDocType);
|
||||
@ -811,40 +861,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
if (Boolean.TRUE.equals(var.required)) {
|
||||
required.add(var.name);
|
||||
}
|
||||
|
||||
// handle ArrayProperty
|
||||
if (var.items != null) {
|
||||
allowableValues = var.items.allowableValues;
|
||||
}
|
||||
|
||||
if (allowableValues == null) {
|
||||
continue;
|
||||
}
|
||||
List<String> values = (List<String>) allowableValues.get("values");
|
||||
if (values == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// put "enumVars" map into `allowableValues", including `name` and `value`
|
||||
List<Map<String, String>> enumVars = new ArrayList<Map<String, String>>();
|
||||
String commonPrefix = findCommonPrefixOfVars(values);
|
||||
int truncateIdx = commonPrefix.length();
|
||||
for (String value : values) {
|
||||
Map<String, String> enumVar = new HashMap<String, String>();
|
||||
String enumName;
|
||||
if (truncateIdx == 0) {
|
||||
enumName = value;
|
||||
} else {
|
||||
enumName = value.substring(truncateIdx);
|
||||
if ("".equals(enumName)) {
|
||||
enumName = value;
|
||||
}
|
||||
}
|
||||
enumVar.put("name", toEnumVarName(enumName));
|
||||
enumVar.put("value", value);
|
||||
enumVars.add(enumVar);
|
||||
}
|
||||
allowableValues.put("enumVars", enumVars);
|
||||
}
|
||||
|
||||
if (supportsInheritance) {
|
||||
@ -878,22 +894,15 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return !defaultIncludes.contains(type)
|
||||
&& !languageSpecificPrimitives.contains(type);
|
||||
}
|
||||
|
||||
private static String findCommonPrefixOfVars(List<String> vars) {
|
||||
/*
|
||||
@Override
|
||||
public String findCommonPrefixOfVars(List<String> vars) {
|
||||
String prefix = StringUtils.getCommonPrefix(vars.toArray(new String[vars.size()]));
|
||||
// exclude trailing characters that should be part of a valid variable
|
||||
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
|
||||
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
|
||||
}
|
||||
|
||||
private static String toEnumVarName(String value) {
|
||||
String var = value.replaceAll("\\W+", "_").toUpperCase();
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
} else {
|
||||
return var;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
// This generator uses inline classes to define enums, which breaks when
|
||||
@ -952,4 +961,41 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return packageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return sanitizeName(camelize(property.name)) + "Enum";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String value, String datatype) {
|
||||
return value;
|
||||
/*
|
||||
// number
|
||||
if ("Integer".equals(datatype) || "Number".equals(datatype)) {
|
||||
String varName = "NUMBER_" + value;
|
||||
varName = varName.replaceAll("-", "MINUS_");
|
||||
varName = varName.replaceAll("\\+", "PLUS_");
|
||||
varName = varName.replaceAll("\\.", "_DOT_");
|
||||
return varName;
|
||||
}
|
||||
|
||||
// string
|
||||
String var = value.replaceAll("\\W+", "_").replaceAll("_+", "_").toUpperCase();
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
} else {
|
||||
return var;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
if ("Integer".equals(datatype) || "Number".equals(datatype)) {
|
||||
return value;
|
||||
} else {
|
||||
return "\"" + escapeText(value) + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public JavascriptClosureAngularClientCodegen() {
|
||||
|
@ -19,7 +19,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public static final String CLASS_PREFIX = "classPrefix";
|
||||
@ -28,6 +28,9 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public static final String AUTHOR_EMAIL = "authorEmail";
|
||||
public static final String GIT_REPO_URL = "gitRepoURL";
|
||||
public static final String LICENSE = "license";
|
||||
|
||||
public static final String BinaryDataType = "ObjcClientCodegenBinaryData";
|
||||
|
||||
protected Set<String> foundationClasses = new HashSet<String>();
|
||||
protected String podName = "SwaggerClient";
|
||||
protected String podVersion = "1.0.0";
|
||||
@ -40,6 +43,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
|
||||
protected Set<String> advancedMapingTypes = new HashSet<String>();
|
||||
|
||||
public ObjcClientCodegen() {
|
||||
super();
|
||||
|
||||
@ -66,6 +71,18 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
defaultIncludes.add("NSMutableArray");
|
||||
defaultIncludes.add("NSMutableDictionary");
|
||||
|
||||
defaultIncludes.add(BinaryDataType);
|
||||
|
||||
advancedMapingTypes.add("NSDictionary");
|
||||
advancedMapingTypes.add("NSArray");
|
||||
advancedMapingTypes.add("NSMutableArray");
|
||||
advancedMapingTypes.add("NSMutableDictionary");
|
||||
advancedMapingTypes.add("NSObject");
|
||||
advancedMapingTypes.add("NSNumber");
|
||||
advancedMapingTypes.add("NSURL");
|
||||
advancedMapingTypes.add("NSString");
|
||||
advancedMapingTypes.add("NSDate");
|
||||
|
||||
languageSpecificPrimitives.clear();
|
||||
languageSpecificPrimitives.add("NSNumber");
|
||||
languageSpecificPrimitives.add("NSString");
|
||||
@ -92,10 +109,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("List", "NSArray");
|
||||
typeMapping.put("object", "NSObject");
|
||||
typeMapping.put("file", "NSURL");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "NSString");
|
||||
typeMapping.put("ByteArray", "NSString");
|
||||
typeMapping.put("binary", BinaryDataType);
|
||||
typeMapping.put("ByteArray", BinaryDataType);
|
||||
|
||||
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
|
||||
setReservedWordsLowerCase(
|
||||
@ -223,6 +238,10 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("JSONResponseSerializer-body.mustache", swaggerFolder, classPrefix + "JSONResponseSerializer.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONRequestSerializer-body.mustache", swaggerFolder, classPrefix + "JSONRequestSerializer.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONRequestSerializer-header.mustache", swaggerFolder, classPrefix + "JSONRequestSerializer.h"));
|
||||
supportingFiles.add(new SupportingFile("ResponseDeserializer-body.mustache", swaggerFolder, classPrefix + "ResponseDeserializer.m"));
|
||||
supportingFiles.add(new SupportingFile("ResponseDeserializer-header.mustache", swaggerFolder, classPrefix + "ResponseDeserializer.h"));
|
||||
supportingFiles.add(new SupportingFile("Sanitizer-body.mustache", swaggerFolder, classPrefix + "Sanitizer.m"));
|
||||
supportingFiles.add(new SupportingFile("Sanitizer-header.mustache", swaggerFolder, classPrefix + "Sanitizer.h"));
|
||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", swaggerFolder, "JSONValueTransformer+ISO8601.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.h", swaggerFolder, "JSONValueTransformer+ISO8601.h"));
|
||||
supportingFiles.add(new SupportingFile("Configuration-body.mustache", swaggerFolder, classPrefix + "Configuration.m"));
|
||||
@ -278,19 +297,26 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
String innerType = getSwaggerType(inner);
|
||||
|
||||
String innerTypeDeclaration = getTypeDeclaration(inner);
|
||||
|
||||
if (innerTypeDeclaration.endsWith("*")) {
|
||||
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
|
||||
}
|
||||
|
||||
if(innerTypeDeclaration.equalsIgnoreCase(BinaryDataType)) {
|
||||
return "NSData*";
|
||||
}
|
||||
// In this codition, type of property p is array of primitive,
|
||||
// return container type with pointer, e.g. `NSArray* /* NSString */'
|
||||
if (languageSpecificPrimitives.contains(innerType)) {
|
||||
return getSwaggerType(p) + "*" + " /* " + innerTypeDeclaration + " */";
|
||||
// return container type with pointer, e.g. `NSArray*<NSString*>*'
|
||||
if (languageSpecificPrimitives.contains(innerTypeDeclaration)) {
|
||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + "*>*";
|
||||
}
|
||||
// In this codition, type of property p is array of model,
|
||||
// return container type combine inner type with pointer, e.g. `NSArray<SWGTag>*'
|
||||
else {
|
||||
for (String sd : advancedMapingTypes) {
|
||||
if(innerTypeDeclaration.startsWith(sd)) {
|
||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + "*>*";
|
||||
}
|
||||
}
|
||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*";
|
||||
}
|
||||
} else if (p instanceof MapProperty) {
|
||||
@ -302,7 +328,16 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (innerTypeDeclaration.endsWith("*")) {
|
||||
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
|
||||
}
|
||||
return getSwaggerType(p) + "* /* NSString, " + innerTypeDeclaration + " */";
|
||||
if (languageSpecificPrimitives.contains(innerTypeDeclaration)) {
|
||||
return getSwaggerType(p) + "<NSString*, " + innerTypeDeclaration + "*>*";
|
||||
} else {
|
||||
for (String s : advancedMapingTypes) {
|
||||
if(innerTypeDeclaration.startsWith(s)) {
|
||||
return getSwaggerType(p) + "<NSString*, " + innerTypeDeclaration + "*>*";
|
||||
}
|
||||
}
|
||||
return getSwaggerType(p) + "<NSString*, " + innerTypeDeclaration + ">*";
|
||||
}
|
||||
} else {
|
||||
String swaggerType = getSwaggerType(p);
|
||||
|
||||
|
@ -27,7 +27,7 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public static final String MODULE_NAME = "moduleName";
|
||||
|
@ -4,6 +4,7 @@ import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
@ -12,6 +13,7 @@ import io.swagger.models.properties.*;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.HashSet;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
@ -35,9 +37,13 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String packagePath = "SwaggerClient-php";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String srcBasePath = "lib";
|
||||
protected String testBasePath = "test";
|
||||
protected String docsBasePath = "docs";
|
||||
protected String apiDirName = "Api";
|
||||
protected String modelDirName = "Model";
|
||||
protected String variableNamingConvention= "snake_case";
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
protected String apiDocPath = docsBasePath + "/" + apiDirName;
|
||||
protected String modelDocPath = docsBasePath + "/" + modelDirName;
|
||||
|
||||
public PhpClientCodegen() {
|
||||
super();
|
||||
@ -49,9 +55,8 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
modelTestTemplateFiles.put("model_test.mustache", ".php");
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".php");
|
||||
embeddedTemplateDir = templateDir = "php";
|
||||
apiPackage = invokerPackage + "\\Api";
|
||||
modelPackage = invokerPackage + "\\Model";
|
||||
testPackage = invokerPackage + "\\Tests";
|
||||
apiPackage = invokerPackage + "\\" + apiDirName;
|
||||
modelPackage = invokerPackage + "\\" + modelDirName;
|
||||
|
||||
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||
@ -111,6 +116,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("object", "object");
|
||||
typeMapping.put("binary", "string");
|
||||
typeMapping.put("ByteArray", "string");
|
||||
typeMapping.put("UUID", "string");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
@ -230,6 +236,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
|
||||
// make test path available in mustache template
|
||||
additionalProperties.put("testBasePath", testBasePath);
|
||||
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", toPackagePath(invokerPackage, srcBasePath), "Configuration.php"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", toPackagePath(invokerPackage, srcBasePath), "ApiClient.php"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", toPackagePath(invokerPackage, srcBasePath), "ApiException.php"));
|
||||
@ -259,23 +268,21 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return (outputFolder + "/" + toPackagePath(testPackage, srcBasePath));
|
||||
return (outputFolder + "/" + getPackagePath() + "/" + testBasePath + "/" + apiDirName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return (outputFolder + "/" + toPackagePath(testPackage, srcBasePath));
|
||||
return (outputFolder + "/" + getPackagePath() + "/" + testBasePath + "/" + modelDirName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
//return (outputFolder + "/" + apiDocPath).replace('/', File.separatorChar);
|
||||
return (outputFolder + "/" + getPackagePath() + "/" + apiDocPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
//return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
|
||||
return (outputFolder + "/" + getPackagePath() + "/" + modelDocPath);
|
||||
}
|
||||
|
||||
@ -566,4 +573,57 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
p.example = example;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||
return value;
|
||||
} else {
|
||||
return "\'" + escapeText(value) + "\'";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumDefaultValue(String value, String datatype) {
|
||||
return datatype + "_" + value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String name, String datatype) {
|
||||
// number
|
||||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||
String varName = new String(name);
|
||||
varName = varName.replaceAll("-", "MINUS_");
|
||||
varName = varName.replaceAll("\\+", "PLUS_");
|
||||
varName = varName.replaceAll("\\.", "_DOT_");
|
||||
return varName;
|
||||
}
|
||||
|
||||
// string
|
||||
String enumName = sanitizeName(underscore(name).toUpperCase());
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
enumName = enumName.replaceFirst("_$", "");
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String enumName = underscore(toModelName(property.name)).toUpperCase();
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
// process enum in models
|
||||
return postProcessModelsEnum(objs);
|
||||
}
|
||||
}
|
||||
|
@ -3,17 +3,23 @@ package io.swagger.codegen.languages;
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String packageName;
|
||||
@ -21,6 +27,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
|
||||
protected Map<Character, String> regexModifiers;
|
||||
|
||||
private String testFolder;
|
||||
|
||||
public PythonClientCodegen() {
|
||||
@ -88,6 +96,14 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"print", "class", "exec", "in", "raise", "continue", "finally", "is",
|
||||
"return", "def", "for", "lambda", "try", "self"));
|
||||
|
||||
regexModifiers = new HashMap<Character, String>();
|
||||
regexModifiers.put('i', "IGNORECASE");
|
||||
regexModifiers.put('l', "LOCALE");
|
||||
regexModifiers.put('m', "MULTILINE");
|
||||
regexModifiers.put('s', "DOTALL");
|
||||
regexModifiers.put('u', "UNICODE");
|
||||
regexModifiers.put('x', "VERBOSE");
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "python package name (convention: snake_case).")
|
||||
.defaultValue("swagger_client"));
|
||||
@ -144,6 +160,46 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return str.replaceAll("\\.", "_");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter){
|
||||
postProcessPattern(parameter.pattern, parameter.vendorExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
postProcessPattern(property.pattern, property.vendorExtensions);
|
||||
}
|
||||
|
||||
/*
|
||||
* The swagger pattern spec follows the Perl convention and style of modifiers. Python
|
||||
* does not support this in as natural a way so it needs to convert it. See
|
||||
* https://docs.python.org/2/howto/regex.html#compilation-flags for details.
|
||||
*/
|
||||
public void postProcessPattern(String pattern, Map<String, Object> vendorExtensions){
|
||||
if(pattern != null) {
|
||||
int i = pattern.lastIndexOf('/');
|
||||
|
||||
//Must follow Perl /pattern/modifiers convention
|
||||
if(pattern.charAt(0) != '/' || i < 2) {
|
||||
throw new IllegalArgumentException("Pattern must follow the Perl "
|
||||
+ "/pattern/modifiers convention. "+pattern+" is not valid.");
|
||||
}
|
||||
|
||||
String regex = pattern.substring(1, i).replace("'", "\'");
|
||||
List<String> modifiers = new ArrayList<String>();
|
||||
|
||||
for(char c : pattern.substring(i).toCharArray()) {
|
||||
if(regexModifiers.containsKey(c)) {
|
||||
String modifier = regexModifiers.get(c);
|
||||
modifiers.add(modifier);
|
||||
}
|
||||
}
|
||||
|
||||
vendorExtensions.put("x-regex", regex);
|
||||
vendorExtensions.put("x-modifiers", modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
|
@ -19,7 +19,7 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -117,6 +117,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("file", "File");
|
||||
typeMapping.put("binary", "String");
|
||||
typeMapping.put("ByteArray", "String");
|
||||
typeMapping.put("UUID", "String");
|
||||
|
||||
// remove modelPackage and apiPackage added by default
|
||||
Iterator<CliOption> itr = cliOptions.iterator();
|
||||
@ -223,6 +224,12 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
writeOptional(outputFolder, new SupportingFile("rspec.mustache", "", ".rspec"));
|
||||
writeOptional(outputFolder, new SupportingFile("spec_helper.mustache", specFolder, "spec_helper.rb"));
|
||||
writeOptional(outputFolder, new SupportingFile("configuration_spec.mustache", specFolder, "configuration_spec.rb"));
|
||||
writeOptional(outputFolder, new SupportingFile("api_client_spec.mustache", specFolder, "api_client_spec.rb"));
|
||||
// not including base object test as the moment as not all API has model
|
||||
//writeOptional(outputFolder, new SupportingFile("base_object_spec.mustache", specFolder, "base_object_spec.rb"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -642,4 +649,12 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setGemAuthorEmail(String gemAuthorEmail) {
|
||||
this.gemAuthorEmail = gemAuthorEmail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
// skip spec file as the file might have been updated with new test cases
|
||||
return !(skipOverwrite && new File(filename).exists());
|
||||
//
|
||||
//return super.shouldOverwrite(filename) && !filename.endsWith("_spec.rb");
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
|
@ -17,7 +17,7 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -0,0 +1,281 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class SpringBootServerCodegen extends JavaClientCodegen implements CodegenConfig{
|
||||
public static final String CONFIG_PACKAGE = "configPackage";
|
||||
public static final String BASE_PACKAGE = "basePackage";
|
||||
protected String title = "Petstore Server";
|
||||
protected String configPackage = "";
|
||||
protected String basePackage = "";
|
||||
protected String templateFileName = "api.mustache";
|
||||
|
||||
public SpringBootServerCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/javaSpringBoot";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put(templateFileName, ".java");
|
||||
embeddedTemplateDir = templateDir = "JavaSpringBoot";
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.model";
|
||||
configPackage = "io.swagger.configuration";
|
||||
invokerPackage = "io.swagger.api";
|
||||
basePackage = "io.swagger";
|
||||
artifactId = "swagger-springboot-server";
|
||||
|
||||
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||
additionalProperties.put("title", title);
|
||||
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
additionalProperties.put(CONFIG_PACKAGE, configPackage);
|
||||
additionalProperties.put(BASE_PACKAGE, basePackage);
|
||||
|
||||
cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code"));
|
||||
cliOptions.add(new CliOption(BASE_PACKAGE, "base package for generated code"));
|
||||
|
||||
supportedLibraries.clear();
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "Default Spring Boot server stub.");
|
||||
supportedLibraries.put("j8-async", "Use async servlet feature and Java 8's default interface. Generating interface with service " +
|
||||
"declaration is useful when using Maven plugin. Just provide a implementation with @Controller to instantiate service.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "springboot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Java SpringBoot Server application using the SpringFox integration.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
// clear model and api doc template as this codegen
|
||||
// does not support auto-generated markdown doc at the moment
|
||||
modelDocTemplateFiles.remove("model_doc.mustache");
|
||||
apiDocTemplateFiles.remove("api_doc.mustache");
|
||||
|
||||
if (additionalProperties.containsKey(CONFIG_PACKAGE)) {
|
||||
this.setConfigPackage((String) additionalProperties.get(CONFIG_PACKAGE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(BASE_PACKAGE)) {
|
||||
this.setBasePackage((String) additionalProperties.get(BASE_PACKAGE));
|
||||
}
|
||||
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("apiOriginFilter.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiOriginFilter.java"));
|
||||
supportingFiles.add(new SupportingFile("apiResponseMessage.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiResponseMessage.java"));
|
||||
supportingFiles.add(new SupportingFile("notFoundException.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "NotFoundException.java"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("swaggerDocumentationConfig.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "SwaggerDocumentationConfig.java"));
|
||||
supportingFiles.add(new SupportingFile("homeController.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("swagger2SpringBoot.mustache",
|
||||
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), "Swagger2SpringBoot.java"));
|
||||
|
||||
|
||||
supportingFiles.add(new SupportingFile("application.properties",
|
||||
("src.main.resources").replace(".", java.io.File.separator), "application.properties"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
String basePath = resourcePath;
|
||||
if (basePath.startsWith("/")) {
|
||||
basePath = basePath.substring(1);
|
||||
}
|
||||
int pos = basePath.indexOf("/");
|
||||
if (pos > 0) {
|
||||
basePath = basePath.substring(0, pos);
|
||||
}
|
||||
|
||||
if (basePath == "") {
|
||||
basePath = "default";
|
||||
} else {
|
||||
if (co.path.startsWith("/" + basePath)) {
|
||||
co.path = co.path.substring(("/" + basePath).length());
|
||||
}
|
||||
co.subresourceOperation = !co.path.isEmpty();
|
||||
}
|
||||
List<CodegenOperation> opList = operations.get(basePath);
|
||||
if (opList == null) {
|
||||
opList = new ArrayList<CodegenOperation>();
|
||||
operations.put(basePath, opList);
|
||||
}
|
||||
opList.add(co);
|
||||
co.baseName = basePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
System.out.println("preprocessSwagger");
|
||||
if ("/".equals(swagger.getBasePath())) {
|
||||
swagger.setBasePath("");
|
||||
}
|
||||
|
||||
String host = swagger.getHost();
|
||||
String port = "8080";
|
||||
if (host != null) {
|
||||
String[] parts = host.split(":");
|
||||
if (parts.length > 1) {
|
||||
port = parts[1];
|
||||
}
|
||||
}
|
||||
|
||||
this.additionalProperties.put("serverPort", port);
|
||||
if (swagger != null && swagger.getPaths() != null) {
|
||||
for (String pathname : swagger.getPaths().keySet()) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if (path.getOperations() != null) {
|
||||
for (Operation operation : path.getOperations()) {
|
||||
if (operation.getTags() != null) {
|
||||
List<Map<String, String>> tags = new ArrayList<Map<String, String>>();
|
||||
for (String tag : operation.getTags()) {
|
||||
Map<String, String> value = new HashMap<String, String>();
|
||||
value.put("tag", tag);
|
||||
value.put("hasMore", "true");
|
||||
tags.add(value);
|
||||
}
|
||||
if (tags.size() > 0) {
|
||||
tags.get(tags.size() - 1).remove("hasMore");
|
||||
}
|
||||
if (operation.getTags().size() > 0) {
|
||||
String tag = operation.getTags().get(0);
|
||||
operation.setTags(Arrays.asList(tag));
|
||||
}
|
||||
operation.setVendorExtension("x-tags", tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
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) {
|
||||
List<CodegenResponse> responses = operation.responses;
|
||||
if (responses != null) {
|
||||
for (CodegenResponse resp : responses) {
|
||||
if ("0".equals(resp.code)) {
|
||||
resp.code = "200";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (operation.returnType == null) {
|
||||
operation.returnType = "Void";
|
||||
} else if (operation.returnType.startsWith("List")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("List<".length(), end).trim();
|
||||
operation.returnContainer = "List";
|
||||
}
|
||||
} else if (operation.returnType.startsWith("Map")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("Map<".length(), end).split(",")[1].trim();
|
||||
operation.returnContainer = "Map";
|
||||
}
|
||||
} else if (operation.returnType.startsWith("Set")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("Set<".length(), end).trim();
|
||||
operation.returnContainer = "Set";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if("j8-async".equals(getLibrary())) {
|
||||
apiTemplateFiles.remove(this.templateFileName);
|
||||
this.templateFileName = "api-j8-async.mustache";
|
||||
apiTemplateFiles.put(this.templateFileName, ".java");
|
||||
|
||||
int originalPomFileIdx = -1;
|
||||
for (int i = 0; i < supportingFiles.size(); i++) {
|
||||
if ("pom.xml".equals(supportingFiles.get(i).destinationFilename)) {
|
||||
originalPomFileIdx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (originalPomFileIdx > -1) {
|
||||
supportingFiles.remove(originalPomFileIdx);
|
||||
}
|
||||
supportingFiles.add(new SupportingFile("pom-j8-async.mustache", "", "pom.xml"));
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
name = sanitizeName(name);
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
public void setConfigPackage(String configPackage) {
|
||||
this.configPackage = configPackage;
|
||||
}
|
||||
|
||||
public void setBasePackage(String configPackage) {
|
||||
this.basePackage = configPackage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
// remove the import of "Object" to avoid compilation error
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||
Iterator<Map<String, String>> iterator = imports.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String _import = iterator.next().get("import");
|
||||
if (_import.endsWith(".Object")) iterator.remove();
|
||||
}
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
// handle default value for enum, e.g. available => StatusEnum.available
|
||||
if (var.isEnum && var.defaultValue != null && !"null".equals(var.defaultValue)) {
|
||||
var.defaultValue = var.datatypeWithEnum + "." + var.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
}
|
@ -2,11 +2,12 @@ package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class SpringMVCServerCodegen extends JavaClientCodegen {
|
||||
public class SpringMVCServerCodegen extends JavaClientCodegen implements CodegenConfig{
|
||||
public static final String CONFIG_PACKAGE = "configPackage";
|
||||
protected String title = "Petstore Server";
|
||||
protected String configPackage = "";
|
||||
@ -121,6 +122,51 @@ public class SpringMVCServerCodegen extends JavaClientCodegen {
|
||||
co.baseName = basePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
System.out.println("preprocessSwagger");
|
||||
if ("/".equals(swagger.getBasePath())) {
|
||||
swagger.setBasePath("");
|
||||
}
|
||||
|
||||
String host = swagger.getHost();
|
||||
String port = "8080";
|
||||
if (host != null) {
|
||||
String[] parts = host.split(":");
|
||||
if (parts.length > 1) {
|
||||
port = parts[1];
|
||||
}
|
||||
}
|
||||
|
||||
this.additionalProperties.put("serverPort", port);
|
||||
if (swagger != null && swagger.getPaths() != null) {
|
||||
for (String pathname : swagger.getPaths().keySet()) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if (path.getOperations() != null) {
|
||||
for (Operation operation : path.getOperations()) {
|
||||
if (operation.getTags() != null) {
|
||||
List<Map<String, String>> tags = new ArrayList<Map<String, String>>();
|
||||
for (String tag : operation.getTags()) {
|
||||
Map<String, String> value = new HashMap<String, String>();
|
||||
value.put("tag", tag);
|
||||
value.put("hasMore", "true");
|
||||
tags.add(value);
|
||||
}
|
||||
if (tags.size() > 0) {
|
||||
tags.get(tags.size() - 1).remove("hasMore");
|
||||
}
|
||||
if (operation.getTags().size() > 0) {
|
||||
String tag = operation.getTags().get(0);
|
||||
operation.setTags(Arrays.asList(tag));
|
||||
}
|
||||
operation.setVendorExtension("x-tags", tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
|
@ -13,9 +13,9 @@ import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
@ -335,8 +335,10 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
swiftEnums.add(map);
|
||||
}
|
||||
codegenProperty.allowableValues.put("values", swiftEnums);
|
||||
codegenProperty.datatypeWithEnum =
|
||||
StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length());
|
||||
codegenProperty.datatypeWithEnum = toEnumName(codegenProperty);
|
||||
//codegenProperty.datatypeWithEnum =
|
||||
// StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length());
|
||||
|
||||
// Ensure that the enum type doesn't match a reserved word or
|
||||
// the variable name doesn't match the generated enum type or the
|
||||
// Swift compiler will generate an error
|
||||
@ -483,4 +485,59 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setResponseAs(String[] responseAs) {
|
||||
this.responseAs = responseAs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||
return value;
|
||||
} else {
|
||||
return "\'" + escapeText(value) + "\'";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumDefaultValue(String value, String datatype) {
|
||||
return datatype + "_" + value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String name, String datatype) {
|
||||
// number
|
||||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||
String varName = new String(name);
|
||||
varName = varName.replaceAll("-", "MINUS_");
|
||||
varName = varName.replaceAll("\\+", "PLUS_");
|
||||
varName = varName.replaceAll("\\.", "_DOT_");
|
||||
return varName;
|
||||
}
|
||||
|
||||
// string
|
||||
String enumName = sanitizeName(underscore(name).toUpperCase());
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
enumName = enumName.replaceFirst("_$", "");
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String enumName = underscore(toModelName(property.name)).toUpperCase();
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
// process enum in models
|
||||
return postProcessModelsEnum(objs);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class TizenClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected static String PREFIX = "Sami";
|
||||
|
@ -30,7 +30,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
outputFolder = "generated-code/typescript-angular";
|
||||
modelTemplateFiles.put("model.mustache", ".ts");
|
||||
apiTemplateFiles.put("api.mustache", ".ts");
|
||||
embeddedTemplateDir = templateDir = "TypeScript-Angular";
|
||||
embeddedTemplateDir = templateDir = "typescript-angular";
|
||||
apiPackage = "API.Client";
|
||||
modelPackage = "API.Client";
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
|
||||
public static final String NPM_NAME = "npmName";
|
||||
public static final String NPM_VERSION = "npmVersion";
|
||||
|
||||
protected String npmName = null;
|
||||
protected String npmVersion = "1.0.0";
|
||||
|
||||
public TypeScriptFetchClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/typescript-fetch";
|
||||
embeddedTemplateDir = templateDir = "TypeScript-Fetch";
|
||||
this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package"));
|
||||
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
supportingFiles.add(new SupportingFile("api.mustache", "", "api.ts"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("assign.ts", "", "assign.ts"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("package.json.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("typings.json.mustache", "", "typings.json"));
|
||||
supportingFiles.add(new SupportingFile("tsconfig.json.mustache", "", "tsconfig.json"));
|
||||
|
||||
if(additionalProperties.containsKey(NPM_NAME)) {
|
||||
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(NPM_VERSION)) {
|
||||
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "typescript-fetch";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a TypeScript client library using Fetch API (beta).";
|
||||
}
|
||||
|
||||
public String getNpmName() {
|
||||
return npmName;
|
||||
}
|
||||
|
||||
public void setNpmName(String npmName) {
|
||||
this.npmName = npmName;
|
||||
}
|
||||
|
||||
public String getNpmVersion() {
|
||||
return npmVersion;
|
||||
}
|
||||
|
||||
public void setNpmVersion(String npmVersion) {
|
||||
this.npmVersion = npmVersion;
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,81 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
|
||||
public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TypeScriptNodeClientCodegen.class);
|
||||
private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
|
||||
|
||||
public static final String NPM_NAME = "npmName";
|
||||
public static final String NPM_VERSION = "npmVersion";
|
||||
public static final String NPM_REPOSITORY = "npmRepository";
|
||||
public static final String SNAPSHOT = "snapshot";
|
||||
|
||||
protected String npmName = null;
|
||||
protected String npmVersion = "1.0.0";
|
||||
protected String npmRepository = null;
|
||||
|
||||
public TypeScriptNodeClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/typescript-node";
|
||||
embeddedTemplateDir = templateDir = "typescript-node";
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package"));
|
||||
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package"));
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
|
||||
LOGGER.warn("check additionals: " + additionalProperties.get(NPM_NAME));
|
||||
if(additionalProperties.containsKey(NPM_NAME)) {
|
||||
addNpmPackageGeneration();
|
||||
}
|
||||
}
|
||||
|
||||
private void addNpmPackageGeneration() {
|
||||
if(additionalProperties.containsKey(NPM_NAME)) {
|
||||
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(NPM_VERSION)) {
|
||||
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||
}
|
||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||
|
||||
if (additionalProperties.containsKey(NPM_REPOSITORY)) {
|
||||
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
|
||||
}
|
||||
|
||||
//Files for building our lib
|
||||
supportingFiles.add(new SupportingFile("package.mustache", getPackageRootDirectory(), "package.json"));
|
||||
supportingFiles.add(new SupportingFile("typings.mustache", getPackageRootDirectory(), "typings.json"));
|
||||
supportingFiles.add(new SupportingFile("tsconfig.mustache", getPackageRootDirectory(), "tsconfig.json"));
|
||||
}
|
||||
|
||||
private String getPackageRootDirectory() {
|
||||
String indexPackage = modelPackage.substring(0, Math.max(0, modelPackage.lastIndexOf('.')));
|
||||
return indexPackage.replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@ -14,18 +87,24 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
return "Generates a TypeScript nodejs client library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
//supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
|
||||
public void setNpmName(String npmName) {
|
||||
this.npmName = npmName;
|
||||
}
|
||||
|
||||
public TypeScriptNodeClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/typescript-node";
|
||||
embeddedTemplateDir = templateDir = "TypeScript-node";
|
||||
public void setNpmVersion(String npmVersion) {
|
||||
this.npmVersion = npmVersion;
|
||||
}
|
||||
|
||||
public String getNpmVersion() {
|
||||
return npmVersion;
|
||||
}
|
||||
|
||||
public String getNpmRepository() {
|
||||
return npmRepository;
|
||||
}
|
||||
|
||||
public void setNpmRepository(String npmRepository) {
|
||||
this.npmRepository = npmRepository;
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,13 @@ import com.sun.jersey.api.client.GenericType;
|
||||
import {{invokerPackage}}.ApiException;
|
||||
import {{invokerPackage}}.ApiClient;
|
||||
import {{invokerPackage}}.Configuration;
|
||||
import {{modelPackage}}.*;
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
|
||||
{{^fullJavaUtil}}
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -1,17 +0,0 @@
|
||||
|
||||
public enum {{{datatypeWithEnum}}} {
|
||||
{{#allowableValues}}{{#enumVars}}{{{name}}}("{{{value}}}"){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
|
||||
private String value;
|
||||
|
||||
{{{datatypeWithEnum}}}(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
public enum {{classname}} {
|
||||
{{#allowableValues}}{{.}}{{^-last}}, {{/-last}}{{/allowableValues}}
|
||||
}
|
@ -2,6 +2,6 @@
|
||||
|
||||
## Enum
|
||||
|
||||
{{#allowableValues}}
|
||||
* `{{.}}`
|
||||
{{/allowableValues}}
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
* `{{name}}` (value: `{{{value}}}`)
|
||||
{{/enumVars}}{{/allowableValues}}
|
||||
|
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||
*/
|
||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#enumVars}}@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
|
||||
private {{datatype}} value;
|
||||
|
||||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
public enum {{{datatypeWithEnum}}} {
|
||||
{{#allowableValues}}{{#enumVars}}@SerializedName("{{{value}}}")
|
||||
{{{name}}}("{{{value}}}"){{^-last}},
|
||||
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
|
||||
private String value;
|
||||
|
||||
{{{datatypeWithEnum}}}(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -3,5 +3,5 @@
|
||||
## Enum
|
||||
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
* `{{name}}` (value: `{{value}}`)
|
||||
{{#enumVars}}{{/allowableValues}}
|
||||
* `{{name}}` (value: `{{{value}}}`)
|
||||
{{/enumVars}}{{/allowableValues}}
|
||||
|
@ -8,78 +8,7 @@ import com.google.gson.annotations.SerializedName;
|
||||
|
||||
{{#serializableModel}}import java.io.Serializable;{{/serializableModel}}
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
{{#description}}@ApiModel(description = "{{{description}}}"){{/description}}
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
|
||||
{{>libraries/okhttp-gson/enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
||||
|
||||
{{>libraries/okhttp-gson/enumClass}}{{/items}}{{/items.isEnum}}
|
||||
@SerializedName("{{baseName}}")
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
|
||||
{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}{{^isReadOnly}}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}{{/isReadOnly}}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}{{#hasVars}}
|
||||
{{classname}} {{classVarName}} = ({{classname}}) o;
|
||||
return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
|
||||
{{/hasMore}}{{/vars}}{{#parent}} &&
|
||||
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
|
||||
return true;{{/hasVars}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n");
|
||||
{{/vars}}sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
||||
{{#model}}
|
||||
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>pojo}}{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* {{^description}}Gets or Sets {{name}}{{/description}}{{#description}}{{description}}{{/description}}
|
||||
*/
|
||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#enumVars}}@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
|
||||
private {{dataType}} value;
|
||||
|
||||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{dataType}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||
*/
|
||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#enumVars}}@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
|
||||
private {{datatype}} value;
|
||||
|
||||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* {{#description}}{{description}}{{/description}}{{^description}}{{classname}}{{/description}}
|
||||
*/{{#description}}
|
||||
@ApiModel(description = "{{{description}}}"){{/description}}
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
|
||||
{{>libraries/common/modelInnerEnum}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
||||
|
||||
{{>libraries/common/modelInnerEnum}}{{/items}}{{/items.isEnum}}
|
||||
@SerializedName("{{baseName}}")
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
|
||||
{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}{{^isReadOnly}}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}{{/isReadOnly}}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}{{#hasVars}}
|
||||
{{classname}} {{classVarName}} = ({{classname}}) o;
|
||||
return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
|
||||
{{/hasMore}}{{/vars}}{{#parent}} &&
|
||||
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
|
||||
return true;{{/hasVars}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n");
|
||||
{{/vars}}sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
@ -17,9 +17,9 @@ import com.google.gson.annotations.SerializedName;
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
|
||||
{{>libraries/okhttp-gson/enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
||||
{{>libraries/common/modelInnerEnum}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
||||
|
||||
{{>libraries/okhttp-gson/enumClass}}{{/items}}{{/items.isEnum}}
|
||||
{{>libraries/common/modelInnerEnum}}{{/items}}{{/items.isEnum}}
|
||||
@SerializedName("{{baseName}}")
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
|
||||
{{/vars}}
|
||||
|
@ -17,9 +17,9 @@ import com.google.gson.annotations.SerializedName;
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
|
||||
{{>libraries/okhttp-gson/enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
||||
{{>libraries/common/modelInnerEnum}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
||||
|
||||
{{>libraries/okhttp-gson/enumClass}}{{/items}}{{/items.isEnum}}
|
||||
{{>libraries/common/modelInnerEnum}}{{/items}}{{/items.isEnum}}
|
||||
@SerializedName("{{baseName}}")
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
|
||||
{{/vars}}
|
||||
|
@ -1,16 +1,13 @@
|
||||
package {{package}};
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import java.util.Objects;
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
{{#serializableModel}}import java.io.Serializable;{{/serializableModel}}
|
||||
{{#models}}
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
{{#isEnum}}{{>enumOuterClass}}{{/isEnum}}
|
||||
{{^isEnum}}{{>pojo}}{{/isEnum}}
|
||||
{{#model}}
|
||||
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>pojo}}{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||
*/
|
||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#enumVars}}{{{name}}}({{{value}}}){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
|
||||
private {{dataType}} value;
|
||||
|
||||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{dataType}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||
*/
|
||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#enumVars}}{{{name}}}({{{value}}}){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
|
||||
private {{datatype}} value;
|
||||
|
||||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
{{#description}}@ApiModel(description = "{{{description}}}"){{/description}}
|
||||
/**
|
||||
* {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
|
||||
*/{{#description}}
|
||||
@ApiModel(description = "{{{description}}}"){{/description}}
|
||||
{{>generatedAnnotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
|
||||
{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
||||
{{>modelInnerEnum}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
||||
|
||||
{{>enumClass}}{{/items}}{{/items.isEnum}}
|
||||
{{>modelInnerEnum}}{{/items}}{{/items.isEnum}}
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}}
|
||||
|
||||
{{#vars}}{{^isReadOnly}}
|
||||
|
@ -1,17 +1,24 @@
|
||||
/**
|
||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||
*/
|
||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
|
||||
public enum {{{datatypeWithEnum}}} {
|
||||
{{#allowableValues}}{{#enumVars}}{{{name}}}("{{{value}}}"){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
{{/-last}}{{#-last}};
|
||||
{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
private {{datatype}} value;
|
||||
|
||||
private String value;
|
||||
|
||||
{{{datatypeWithEnum}}}(String value) {
|
||||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return value;
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,24 @@
|
||||
/**
|
||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||
*/
|
||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
|
||||
public enum {{{datatypeWithEnum}}} {
|
||||
{{#allowableValues}}{{#enumVars}}{{{name}}}("{{{value}}}"){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
{{/-last}}{{#-last}};
|
||||
{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
private {{datatype}} value;
|
||||
|
||||
private String value;
|
||||
|
||||
{{{datatypeWithEnum}}}(String value) {
|
||||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return value;
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
# Swagger generated server
|
||||
|
||||
Spring Boot Server
|
||||
|
||||
|
||||
## Overview
|
||||
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project.
|
||||
By using the [OpenAPI-Spec](https://github.com/swagger-api/swagger-core), you can easily generate a server stub.
|
||||
This is an example of building a swagger-enabled server in Java using the SpringBoot framework.
|
||||
|
||||
The underlying library integrating swagger to SpringBoot is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
Start your server as an simple java application
|
||||
|
||||
You can view the api documentation in swagger-ui by pointing to
|
||||
http://localhost:8080/
|
||||
|
||||
Change default port value in application.properties
|
@ -0,0 +1,56 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import {{modelPackage}}.*;
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.http.MediaType.*;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/{{{baseName}}}", produces = {APPLICATION_JSON_VALUE})
|
||||
@Api(value = "/{{{baseName}}}", description = "the {{{baseName}}} API")
|
||||
{{>generatedAnnotation}}
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
{{#operation}}
|
||||
|
||||
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
|
||||
{{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
|
||||
{{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
|
||||
{{/hasMore}}{{/scopes}}
|
||||
}{{/isOAuth}}){{#hasMore}},
|
||||
{{/hasMore}}{{/authMethods}}
|
||||
}{{/hasAuthMethods}})
|
||||
@ApiResponses(value = { {{#responses}}
|
||||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{returnType}}}.class){{#hasMore}},{{/hasMore}}{{/responses}} })
|
||||
@RequestMapping(value = "{{{path}}}",
|
||||
{{#hasProduces}}produces = { {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}
|
||||
{{#hasConsumes}}consumes = { {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}
|
||||
method = RequestMethod.{{httpMethod}})
|
||||
public ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
|
||||
{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException {
|
||||
// do some magic!
|
||||
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
@ -0,0 +1,10 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
#server.port=8090
|
@ -0,0 +1 @@
|
||||
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @RequestBody {{{dataType}}} {{paramName}}{{/isBodyParam}}
|
@ -0,0 +1,2 @@
|
||||
{{#isFormParam}}{{#notFile}}
|
||||
@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @RequestPart(value="{{paramName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@ApiParam(value = "file detail") @RequestPart("file") MultipartFile {{baseName}}{{/isFile}}{{/isFormParam}}
|
@ -0,0 +1 @@
|
||||
@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}")
|
@ -0,0 +1 @@
|
||||
{{#isHeaderParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @RequestHeader(value="{{baseName}}", required={{#required}}true{{/required}}{{^required}}false{{/required}}) {{{dataType}}} {{paramName}}{{/isHeaderParam}}
|
@ -0,0 +1,16 @@
|
||||
package {{configPackage}};
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
* Home redirection to swagger api documentation
|
||||
*/
|
||||
@Controller
|
||||
public class HomeController {
|
||||
@RequestMapping(value = "/")
|
||||
public String index() {
|
||||
System.out.println("swagger-ui.html");
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Objects;
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
{{>generatedAnnotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
{{/isEnum}}{{#items}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
{{/isEnum}}{{/items}}
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
@JsonProperty("{{baseName}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
{{classname}} {{classVarName}} = ({{classname}}) o;{{#hasVars}}
|
||||
return {{#vars}}Objects.equals({{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
|
||||
{{/hasMore}}{{^hasMore}};{{/hasMore}}{{/vars}}{{/hasVars}}{{^hasVars}}
|
||||
return true;{{/hasVars}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
@ -0,0 +1,10 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
{{#isPathParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}} {{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathVariable("{{paramName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}
|
@ -0,0 +1,54 @@
|
||||
<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>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<properties>
|
||||
<springfox-version>2.4.0</springfox-version>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.3.3.RELEASE</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--SpringFox dependencies -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
sbt.version=0.12.0
|
@ -0,0 +1,9 @@
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.4")
|
||||
|
||||
libraryDependencies <+= sbtVersion(v => v match {
|
||||
case "0.11.0" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.0-0.2.8"
|
||||
case "0.11.1" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.1-0.2.10"
|
||||
case "0.11.2" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.2-0.2.11"
|
||||
case "0.11.3" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.3-0.2.11.1"
|
||||
case x if (x.startsWith("0.12")) => "com.github.siasia" %% "xsbt-web-plugin" % "0.12.0-0.2.11.1"
|
||||
})
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user