forked from loafle/openapi-generator-original
Compare commits
100 Commits
v3.3.4
...
duke_scrip
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb627dedfd | ||
|
|
774013c7e1 | ||
|
|
c0634ac213 | ||
|
|
92d60b684a | ||
|
|
d40cbf9dbd | ||
|
|
d57009d14d | ||
|
|
ced6e0502e | ||
|
|
314b4cc54f | ||
|
|
21b2b20c2d | ||
|
|
1e023f3b6e | ||
|
|
df19c13347 | ||
|
|
32d228c33a | ||
|
|
fcd37a6006 | ||
|
|
4be605bcb7 | ||
|
|
01ac429954 | ||
|
|
10ea00066a | ||
|
|
4930f75dc7 | ||
|
|
8795bff35e | ||
|
|
6976a8c775 | ||
|
|
110d057384 | ||
|
|
d75392e056 | ||
|
|
e84c59f4cc | ||
|
|
0a33ad465f | ||
|
|
8ee1553654 | ||
|
|
001f89f1d9 | ||
|
|
cd61442387 | ||
|
|
e3ab059530 | ||
|
|
dfa7e616c0 | ||
|
|
b226f52d13 | ||
|
|
308515bbc1 | ||
|
|
5b4a19849e | ||
|
|
172448fa28 | ||
|
|
34abedeb8a | ||
|
|
2146081ffb | ||
|
|
7db12aa4af | ||
|
|
5f1362daad | ||
|
|
65a86eee3b | ||
|
|
334415dec2 | ||
|
|
736e8348b6 | ||
|
|
2bcf5b2263 | ||
|
|
a87a544bf5 | ||
|
|
8ba4b3a276 | ||
|
|
d59230fd27 | ||
|
|
75b1403c1e | ||
|
|
a023a0d0ca | ||
|
|
e6c97a1bc1 | ||
|
|
a186efed35 | ||
|
|
ceffdde2c0 | ||
|
|
71ecee02e9 | ||
|
|
ed2f6ea72e | ||
|
|
ef98971746 | ||
|
|
3482a0a993 | ||
|
|
4a47acce19 | ||
|
|
9422dea149 | ||
|
|
30062afc7c | ||
|
|
bbfaa90242 | ||
|
|
eccab2c025 | ||
|
|
40e90b5883 | ||
|
|
a3dc5ecc20 | ||
|
|
649d5a97b4 | ||
|
|
83c55ec016 | ||
|
|
e42cac636a | ||
|
|
cfbc72f444 | ||
|
|
9e3c7781bb | ||
|
|
257a97b6cd | ||
|
|
5490bb8e9c | ||
|
|
0f7557ca9d | ||
|
|
5357791337 | ||
|
|
c9625f3fd5 | ||
|
|
94eb1c3c63 | ||
|
|
a08f8d13e0 | ||
|
|
adbe478e0b | ||
|
|
780ba49da1 | ||
|
|
e5b6d525c7 | ||
|
|
d1f7e16daa | ||
|
|
74d70121d1 | ||
|
|
aed8e38584 | ||
|
|
3746fae2ca | ||
|
|
c44d91c673 | ||
|
|
be2a0170b7 | ||
|
|
2f85867963 | ||
|
|
3b1029ada4 | ||
|
|
8cbd57d829 | ||
|
|
75e5ed2f68 | ||
|
|
6460bb2897 | ||
|
|
22c79cf470 | ||
|
|
024dde11d7 | ||
|
|
d2db799a93 | ||
|
|
07b8040122 | ||
|
|
eb09731a65 | ||
|
|
f98000753d | ||
|
|
deb5dcaad1 | ||
|
|
7f4fc4de93 | ||
|
|
7938677efa | ||
|
|
b0c02d8ea6 | ||
|
|
05f177b6d6 | ||
|
|
b1921ce484 | ||
|
|
4a4fb77081 | ||
|
|
f5f744ad2c | ||
|
|
b887efdc1c |
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -2,7 +2,7 @@
|
||||
|
||||
- [ ] Read the [contribution guidelines](https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md).
|
||||
- [ ] Ran the shell script under `./bin/` to update Petstore sample so that CIs can verify the change. (For instance, only need to run `./bin/{LANG}-petstore.sh` and `./bin/security/{LANG}-petstore.sh` if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in `.\bin\windows\`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`, `3.4.x`, `4.0.x`. Default: `master`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`~~, `3.4.x`, `4.0.x`~~. Default: `master`.
|
||||
- [ ] Copied the [technical committee](https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee) to review the pull request if your PR is targeting a particular programming language.
|
||||
|
||||
### Description of the PR
|
||||
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -184,6 +184,9 @@ samples/server/petstore/kotlin-server/ktor/build
|
||||
.stack-work
|
||||
.cabal-sandbox
|
||||
cabal.project.local
|
||||
samples/client/petstore/haskell-http-client/docs/haddock-bundle.min.js
|
||||
samples/client/petstore/haskell-http-client/docs/meta.json
|
||||
samples/client/petstore/haskell-http-client/docs/quick-jump.css
|
||||
|
||||
# R
|
||||
.Rproj.user
|
||||
@@ -212,3 +215,7 @@ samples/client/petstore/javascript/package-lock.json
|
||||
|
||||
# elm
|
||||
samples/client/petstore/elm/index.html
|
||||
|
||||
# C
|
||||
samples/client/petstore/c/build
|
||||
samples/client/petstore/c/*.so
|
||||
|
||||
@@ -51,9 +51,9 @@ addons:
|
||||
|
||||
before_install:
|
||||
# install haskell
|
||||
#- curl -sSL https://get.haskellstack.org/ | sh
|
||||
#- stack upgrade
|
||||
#- stack --version
|
||||
- curl -sSL https://get.haskellstack.org/ | sh
|
||||
- stack upgrade
|
||||
- stack --version
|
||||
# install rust
|
||||
- curl https://sh.rustup.rs -sSf | sh -s -- -y -v
|
||||
# required when sudo: required for the Ruby petstore tests
|
||||
@@ -80,6 +80,9 @@ before_install:
|
||||
#- sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
|
||||
#- sudo apt-get update
|
||||
#- sudo apt-get install dart
|
||||
# switch to php7
|
||||
- phpenv global 7.1
|
||||
- php -v
|
||||
# install perl module
|
||||
#- cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
|
||||
#- cpanm Test::Exception Test::More Log::Any LWP::UserAgent JSON URI:Query Module::Runtime DateTime Module::Find Moose::Role
|
||||
|
||||
@@ -15,7 +15,7 @@ elif [ "$NODE_INDEX" = "2" ]; then
|
||||
java -version
|
||||
#export GO_POST_PROCESS_FILE="/usr/local/bin/gofmt -w"
|
||||
# not formatting the code as different go versions may format the code a bit different
|
||||
#./bin/utils/ensure-up-to-date
|
||||
./bin/utils/ensure-up-to-date
|
||||
else
|
||||
echo "Running node $NODE_INDEX to test 'samples.circleci.jdk7' defined in pom.xml ..."
|
||||
sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>TypeScriptAngularBuildPestoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>TS Fetch Default Petstore Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,59 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>TypeScriptAngularBuildES6PestoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>TS Fetch ES6 Petstore Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>npm-install</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,73 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>TypeScriptAngularBuildWithNPMVersionPestoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>TS Fetch Petstore Client (with npm)</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>npm-install</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-build</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>run</argument>
|
||||
<argument>build</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,59 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>TypeScriptFetchPestoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>TS Fetch Petstore Test Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>npm-install</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1 @@
|
||||
c2fcc2ae9693a8e8d02b25e286844aad88188fcb
|
||||
Binary file not shown.
15
README.md
15
README.md
@@ -2,15 +2,11 @@
|
||||
|
||||
<div align="center">
|
||||
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`3.3.4`): [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`4.0.0`): [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
|
||||
|
||||
[`4.0.x`](https://github.com/OpenAPITools/openapi-generator/tree/4.0.x) branch: [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
@@ -46,7 +42,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
|
||||
**Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go** (net/http, Gin), **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples)), **Kotlin** (Spring Boot), **PHP** (Laravel, Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** (rust-server), **Scala** ([Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), Scalatra)
|
||||
**API documentation generators** | **HTML**, **Confluence Wiki**
|
||||
**Configuration files** | [**Apache2**](https://httpd.apache.org/)
|
||||
**Others** | **JMeter**, **MySQL Schema**
|
||||
**Others** | **GraphQL**, **JMeter**, **MySQL Schema**
|
||||
|
||||
## Table of contents
|
||||
|
||||
@@ -83,7 +79,7 @@ The OpenAPI Specification has undergone 3 revisions since initial creation in 20
|
||||
|
||||
OpenAPI Generator Version | Release Date | Notes
|
||||
---------------------------- | ------------ | -----
|
||||
4.0.0 (upcoming major release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/)| 20.12.2018 | Major release with breaking changes (with or without fallback)
|
||||
4.0.0 (upcoming release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/)| 20.12.2018 | Major release with breaking changes (with or without fallback)
|
||||
[3.3.4](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.3.4) (latest stable release) | 30.11.2018 | Bugfix release
|
||||
|
||||
OpenAPI Spec compatibility: 1.0, 1.1, 1.2, 2.0, 3.0
|
||||
@@ -621,6 +617,7 @@ Here is a list of template creators:
|
||||
* Erlang Server: @galaxie
|
||||
* Go Server: @guohuang
|
||||
* Go (Gin) Server: @kemokemo
|
||||
* GraphQL Express Server: @renepardon
|
||||
* Haskell Servant: @algas
|
||||
* Java MSF4J: @sanjeewa-malalgoda
|
||||
* Java Spring Boot: @diyfr
|
||||
@@ -648,6 +645,7 @@ Here is a list of template creators:
|
||||
* Configuration
|
||||
* Apache2: @stkrwork
|
||||
* Schema
|
||||
* GraphQL: @wing328
|
||||
* MySQL: @ybelenko
|
||||
|
||||
#### How to join the core team
|
||||
@@ -696,6 +694,7 @@ If you want to join the committee, please kindly apply by sending an email to te
|
||||
| Elm | @trenneman (2018/09) |
|
||||
| Erlang | @tsloughter (2017/11) @jfacorro (2018/10) @robertoaloi (2018/10) |
|
||||
| Go | @antihax (2017/11) @bvwells (2017/12) @grokify (2018/07) @kemokemo (2018/09 |
|
||||
| GraphQL | @renepardon (2018/12) |
|
||||
| Groovy | |
|
||||
| Haskell | |
|
||||
| Java | @bbdouglas (2017/07) @JFCote (2017/08) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) |
|
||||
@@ -704,7 +703,7 @@ If you want to join the committee, please kindly apply by sending an email to te
|
||||
| NodeJS/Javascript | @CodeNinjai (2017/07) @frol (2017/07) @cliffano (2017/07) |
|
||||
| ObjC | |
|
||||
| Perl | @wing328 (2017/07) |
|
||||
| PHP | @jebentier (2017/07) @dkarlovi (2017/07) @mandrean (2017/08) @jfastnacht (2017/09) @ackintosh (2017/09) @ybelenko (2018/07) |
|
||||
| PHP | @jebentier (2017/07) @dkarlovi (2017/07) @mandrean (2017/08) @jfastnacht (2017/09) @ackintosh (2017/09) @ybelenko (2018/07) @renepardon (2018/12) |
|
||||
| PowerShell | |
|
||||
| Python | @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) |
|
||||
| R | |
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-qt5 -o samples/client/petstore/cpp-qt5 $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-qt5-client -o samples/client/petstore/cpp-qt5 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
32
bin/dukescript-petstore.sh
Normal file
32
bin/dukescript-petstore.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/dukescript -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dukescript -o samples/client/petstore/dukescript $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
32
bin/graphql-schema-petstore.sh
Executable file
32
bin/graphql-schema-petstore.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/graphql-schema -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g graphql-schema -o samples/config/petstore/graphql-schema -DpackageName=petstore $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
32
bin/graphql-server-petstore.sh
Executable file
32
bin/graphql-server-petstore.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/graphql-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g graphql-server -o samples/server/petstore/graphql-server -DpackageName=petstore $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-client -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-qt5 -o samples/client/petstore/cpp-qt5 $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-client -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-qt5-client -o samples/client/petstore/cpp-qt5 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
42
bin/openapi3/graphql-petstore-server.sh
Executable file
42
bin/openapi3/graphql-petstore-server.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
# Make sure that the working directory is the root dir
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "${SCRIPT_DIR}/../"
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
# Make sure that we are regenerating the sample by removing any existing target directory
|
||||
TARGET_DIR="$SCRIPT_DIR/../../samples/server/petstore/graphql-server"
|
||||
if [ -d "$TARGET_DIR" ]; then
|
||||
rm -rf $TARGET_DIR
|
||||
fi
|
||||
|
||||
executable="$SCRIPT_DIR/../../modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t $SCRIPT_DIR/../../modules/openapi-generator/src/main/resources/graphql-server -i $SCRIPT_DIR/../../modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g graphql-server -o $TARGET_DIR $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-client -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g cpp-qt5 -o samples/client/petstore-security-test/cpp-qt5 $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-client -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g cpp-qt5-client -o samples/client/petstore-security-test/cpp-qt5 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -9,3 +9,7 @@
|
||||
./bin/typescript-angular-v6-petstore-not-provided-in-root-with-npm.sh
|
||||
./bin/typescript-angular-v6-petstore-provided-in-root.sh
|
||||
./bin/typescript-angular-v6-petstore-provided-in-root-with-npm.sh
|
||||
./bin/typescript-angular-v7-petstore-not-provided-in-root.sh
|
||||
./bin/typescript-angular-v7-petstore-not-provided-in-root-with-npm.sh
|
||||
./bin/typescript-angular-v7-petstore-provided-in-root.sh
|
||||
./bin/typescript-angular-v7-petstore-provided-in-root-with-npm.sh
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"npmName": "@swagger/typescript-angular-petstore",
|
||||
"npmVersion": "1.0.0",
|
||||
"npmRepository" : "https://skimdb.npmjs.com/registry",
|
||||
"snapshot" : false
|
||||
}
|
||||
32
bin/typescript-angular-v7-petstore-not-provided-in-root-with-npm.sh
Executable file
32
bin/typescript-angular-v7-petstore-not-provided-in-root-with-npm.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-angular -c bin/typescript-angular-v7-petstore-not-provided-in-root-with-npm.json -o samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm -D providedInRoot=false --additional-properties ngVersion=7.0.0 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
32
bin/typescript-angular-v7-petstore-not-provided-in-root.sh
Executable file
32
bin/typescript-angular-v7-petstore-not-provided-in-root.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-angular -o samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default -D providedInRoot=false --additional-properties ngVersion=7.0.0 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"npmName": "@swagger/typescript-angular-petstore",
|
||||
"npmVersion": "1.0.0",
|
||||
"npmRepository" : "https://skimdb.npmjs.com/registry",
|
||||
"snapshot" : false
|
||||
}
|
||||
32
bin/typescript-angular-v7-petstore-provided-in-root-with-npm.sh
Executable file
32
bin/typescript-angular-v7-petstore-provided-in-root-with-npm.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-angular -c bin/typescript-angular-v7-petstore-provided-in-root-with-npm.json -o samples/client/petstore/typescript-angular-v7-provided-in-root/builds/with-npm --additional-properties ngVersion=7.0.0 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
32
bin/typescript-angular-v7-petstore-provided-in-root.sh
Executable file
32
bin/typescript-angular-v7-petstore-provided-in-root.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-angular -o samples/client/petstore/typescript-angular-v7-provided-in-root/builds/default --additional-properties ngVersion=7.0.0 $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -30,3 +30,5 @@ export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-fetch -c bin/typescript-fetch-petstore-target-es6.json -o samples/client/petstore/typescript-fetch/builds/es6-target $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/builds/es6-target/pom.xml samples/client/petstore/typescript-fetch/builds/es6-target/pom.xml
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/tests/default/pom.xml samples/client/petstore/typescript-fetch/tests/default/pom.xml
|
||||
@@ -30,3 +30,5 @@ export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-fetch -c bin/typescript-fetch-petstore-with-npm-version.json -o samples/client/petstore/typescript-fetch/builds/with-npm-version $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/builds/with-npm-version/pom.xml samples/client/petstore/typescript-fetch/builds/with-npm-version/pom.xml
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/tests/default/pom.xml samples/client/petstore/typescript-fetch/tests/default/pom.xml
|
||||
@@ -30,3 +30,5 @@ export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-fetch -o samples/client/petstore/typescript-fetch/builds/default $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/builds/default/pom.xml samples/client/petstore/typescript-fetch/builds/default/pom.xml
|
||||
cp CI/samples.ci/client/petstore/typescript-fetch/tests/default/pom.xml samples/client/petstore/typescript-fetch/tests/default/pom.xml
|
||||
@@ -1,8 +1,26 @@
|
||||
#release_chekcout.rb
|
||||
#!/usr/bin/env ruby
|
||||
#
|
||||
# release_chekcout.rb
|
||||
#
|
||||
require 'rubygems'
|
||||
require 'open-uri'
|
||||
require 'net/http'
|
||||
|
||||
def check_npmjs
|
||||
print "Checking npmjs... "
|
||||
|
||||
url = "https://www.npmjs.com/package/@openapitools/openapi-generator-cli?activeTab=versions"
|
||||
open(url) do |f|
|
||||
content = f.read
|
||||
if !content.nil? && content.include?($version)
|
||||
puts "[OK]"
|
||||
else
|
||||
puts "[ERROR]"
|
||||
puts "> #{url} not yet updated with #{$version}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_homebrew
|
||||
print "Checking homebrew forumla ... "
|
||||
|
||||
@@ -184,6 +202,7 @@ $version = ARGV[0]
|
||||
|
||||
puts "Running checkout on OpenAPI Generator release #{$version}"
|
||||
|
||||
check_npmjs
|
||||
check_homebrew
|
||||
check_openapi_generator_jar
|
||||
check_openapi_generator_cli_jar
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-qt5 -o samples\client\petstore\cpp-qt5
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-qt5-client -o samples\client\petstore\cpp-qt5
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
10
bin/windows/dukescript-petstore.bat
Normal file
10
bin/windows/dukescript-petstore.bat
Normal file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g dukescript -o samples\client\petstore\dukescript
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
10
bin/windows/graphql-petstore-server.bat
Executable file
10
bin/windows/graphql-petstore-server.bat
Executable file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -t modules\openapi-generator\src\main\resources\graphql-server -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g graphql-server -o samples\server\petstore\graphql-server
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
10
bin/windows/graphql-schema-petstore.bat
Executable file
10
bin/windows/graphql-schema-petstore.bat
Executable file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -t modules\openapi-generator\src\main\resources\graphql-schema -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g graphql-schema -o samples\config\petstore\graphql-schema
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -7,5 +7,8 @@ call .\bin\windows\typescript-angular-v6-provided-in-root.bat
|
||||
call .\bin\windows\typescript-angular-v6-provided-in-root-with-npm.bat
|
||||
call .\bin\windows\typescript-angular-v6-not-provided-in-root.bat
|
||||
call .\bin\windows\typescript-angular-v6-not-provided-in-root-with-npm.bat
|
||||
|
||||
call .\bin\windows\typescript-angular-v7-provided-in-root.bat
|
||||
call .\bin\windows\typescript-angular-v7-provided-in-root-with-npm.bat
|
||||
call .\bin\windows\typescript-angular-v7-not-provided-in-root.bat
|
||||
call .\bin\windows\typescript-angular-v7-not-provided-in-root-with-npm.bat
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l typescript-angular -c bin\typescript-angular-v7-petstore-not-provided-in-root-with-npm.json -o samples\client\petstore\typescript-angular-v7-not-provided-in-root\builds\with-npm -D providedInRoot=false --additional-properties ngVersion=7.0.0
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
10
bin/windows/typescript-angular-v7-not-provided-in-root.bat
Normal file
10
bin/windows/typescript-angular-v7-not-provided-in-root.bat
Normal file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l typescript-angular -o samples\client\petstore\typescript-angular-v7-not-provided-in-root\builds\default -D providedInRoot=false --additional-properties ngVersion=7.0.0
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -0,0 +1,9 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l typescript-angular -c bin/typescript-angular-v7-petstore-provided-in-root-with-npm.json -o samples\client\petstore\typescript-angular-v7-provided-in-root\builds\with-npm --additional-properties ngVersion=7.0.0
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
9
bin/windows/typescript-angular-v7-provided-in-root.bat
Normal file
9
bin/windows/typescript-angular-v7-provided-in-root.bat
Normal file
@@ -0,0 +1,9 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l typescript-angular -o samples\client\petstore\typescript-angular-v7-provided-in-root\builds\default --additional-properties ngVersion=7.0.0
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -17,7 +17,7 @@ CONFIG OPTIONS for clojure
|
||||
name of the project (Default: generated from info.title or "openapi-clj-client")
|
||||
|
||||
projectDescription
|
||||
description of the project (Default: using info.description or "Client library of <projectNname>")
|
||||
description of the project (Default: using info.description or "Client library of <projectName>")
|
||||
|
||||
projectVersion
|
||||
version of the project (Default: using info.version or "1.0.0")
|
||||
|
||||
@@ -16,4 +16,7 @@ CONFIG OPTIONS for cpp-qt5-qhttpengine-server
|
||||
cppNamespace
|
||||
C++ namespace (convention: name::space::for::api). (Default: OpenAPI)
|
||||
|
||||
cppNamespace
|
||||
C++ namespace (convention: name::space::for::api). (Default: OpenAPI)
|
||||
|
||||
Back to the [generators list](README.md)
|
||||
|
||||
@@ -34,4 +34,7 @@ CONFIG OPTIONS for dart-jaguar
|
||||
supportDart2
|
||||
support dart2 (Default: true)
|
||||
|
||||
nullableFields
|
||||
Is the null fields should be in the JSON payload
|
||||
|
||||
Back to the [generators list](README.md)
|
||||
|
||||
@@ -9,4 +9,10 @@ CONFIG OPTIONS for elm
|
||||
elmPrefixCustomTypeVariants
|
||||
Prefix custom type variants (Default: false)
|
||||
|
||||
elmEnableCustomBasePaths
|
||||
Enable setting the base path for each request (Default: false)
|
||||
|
||||
elmEnableHttpRequestTrackers
|
||||
Enable adding a tracker to each http request (Default: false)
|
||||
|
||||
Back to the [generators list](README.md)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.3.4</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.invoke
|
||||
import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorGenerateExtension
|
||||
import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorMetaExtension
|
||||
import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorValidateExtension
|
||||
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
|
||||
import org.openapitools.generator.gradle.plugin.tasks.GeneratorsTask
|
||||
import org.openapitools.generator.gradle.plugin.tasks.MetaTask
|
||||
import org.openapitools.generator.gradle.plugin.tasks.ValidateTask
|
||||
|
||||
/**
|
||||
* A plugin providing common Open API Generator use cases.
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
@Suppress("unused")
|
||||
class OpenApiGeneratorPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
project.run {
|
||||
val meta = extensions.create(
|
||||
"openApiMeta",
|
||||
OpenApiGeneratorMetaExtension::class.java,
|
||||
project
|
||||
)
|
||||
|
||||
val validate = extensions.create(
|
||||
"openApiValidate",
|
||||
OpenApiGeneratorValidateExtension::class.java,
|
||||
project
|
||||
)
|
||||
|
||||
val generate = extensions.create(
|
||||
"openApiGenerate",
|
||||
OpenApiGeneratorGenerateExtension::class.java,
|
||||
project
|
||||
)
|
||||
|
||||
generate.outputDir.set("$buildDir/generate-resources/main")
|
||||
|
||||
tasks {
|
||||
"openApiGenerators"(GeneratorsTask::class) {
|
||||
group = pluginGroup
|
||||
description = "Lists generators available via Open API Generators."
|
||||
}
|
||||
"openApiMeta"(MetaTask::class) {
|
||||
group = pluginGroup
|
||||
description = "Generates a new generator to be consumed via Open API Generator."
|
||||
|
||||
generatorName.set(meta.generatorName)
|
||||
packageName.set(meta.packageName)
|
||||
outputFolder.set(meta.outputFolder)
|
||||
}
|
||||
"openApiValidate"(ValidateTask::class) {
|
||||
group = pluginGroup
|
||||
description = "Validates an Open API 2.0 or 3.x specification document."
|
||||
|
||||
inputSpec.set(validate.inputSpec)
|
||||
}
|
||||
"openApiGenerate"(GenerateTask::class) {
|
||||
group = pluginGroup
|
||||
description = "Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents."
|
||||
|
||||
verbose.set(generate.verbose)
|
||||
validateSpec.set(generate.validateSpec)
|
||||
generatorName.set(generate.generatorName)
|
||||
outputDir.set(generate.outputDir)
|
||||
inputSpec.set(generate.inputSpec)
|
||||
templateDir.set(generate.templateDir)
|
||||
auth.set(generate.auth)
|
||||
systemProperties.set(generate.systemProperties)
|
||||
configFile.set(generate.configFile)
|
||||
skipOverwrite.set(generate.skipOverwrite)
|
||||
apiPackage.set(generate.apiPackage)
|
||||
modelPackage.set(generate.modelPackage)
|
||||
modelNamePrefix.set(generate.modelNamePrefix)
|
||||
modelNameSuffix.set(generate.modelNameSuffix)
|
||||
instantiationTypes.set(generate.instantiationTypes)
|
||||
typeMappings.set(generate.typeMappings)
|
||||
additionalProperties.set(generate.additionalProperties)
|
||||
languageSpecificPrimitives.set(generate.languageSpecificPrimitives)
|
||||
importMappings.set(generate.importMappings)
|
||||
invokerPackage.set(generate.invokerPackage)
|
||||
groupId.set(generate.groupId)
|
||||
id.set(generate.id)
|
||||
version.set(generate.version)
|
||||
library.set(generate.library)
|
||||
gitUserId.set(generate.gitUserId)
|
||||
gitRepoId.set(generate.gitRepoId)
|
||||
releaseNote.set(generate.releaseNote)
|
||||
httpUserAgent.set(generate.httpUserAgent)
|
||||
reservedWordsMappings.set(generate.reservedWordsMappings)
|
||||
ignoreFileOverride.set(generate.ignoreFileOverride)
|
||||
removeOperationIdPrefix.set(generate.removeOperationIdPrefix)
|
||||
apiFilesConstrainedTo.set(generate.apiFilesConstrainedTo)
|
||||
modelFilesConstrainedTo.set(generate.modelFilesConstrainedTo)
|
||||
supportingFilesConstrainedTo.set(generate.supportingFilesConstrainedTo)
|
||||
generateModelTests.set(generate.generateModelTests)
|
||||
generateModelDocumentation.set(generate.generateModelDocumentation)
|
||||
generateApiTests.set(generate.generateApiTests)
|
||||
generateApiDocumentation.set(generate.generateApiDocumentation)
|
||||
withXml.set(generate.withXml)
|
||||
configOptions.set(generate.configOptions)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val pluginGroup = "OpenAPI Tools"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.extensions
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.listProperty
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
/**
|
||||
* Gradle project level extension object definition for the generate task
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
|
||||
/**
|
||||
* The verbosity of generation
|
||||
*/
|
||||
val verbose = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Whether or not an input specification should be validated upon generation.
|
||||
*/
|
||||
val validateSpec = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* The name of the generator which will handle codegen. (see "openApiGenerators" task)
|
||||
*/
|
||||
val generatorName = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The output target directory into which code will be generated.
|
||||
*/
|
||||
val outputDir = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The Open API 2.0/3.x specification location.
|
||||
*/
|
||||
val inputSpec = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The template directory holding a custom template.
|
||||
*/
|
||||
val templateDir = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Adds authorization headers when fetching the OpenAPI definitions remotely.
|
||||
* Pass in a URL-encoded string of name:header with a comma separating multiple values
|
||||
*/
|
||||
val auth = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Sets specified system properties.
|
||||
*/
|
||||
val systemProperties = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Path to json configuration file.
|
||||
* File content should be in a json format { "optionKey":"optionValue", "optionKey1":"optionValue1"...}
|
||||
* Supported options can be different for each language. Run config-help -g {generator name} command for language specific config options.
|
||||
*/
|
||||
val configFile = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Specifies if the existing files should be overwritten during the generation.
|
||||
*/
|
||||
val skipOverwrite = project.objects.property<Boolean?>()
|
||||
|
||||
/**
|
||||
* Package for generated api classes
|
||||
*/
|
||||
val apiPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Package for generated models
|
||||
*/
|
||||
val modelPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Prefix that will be prepended to all model names. Default is the empty string.
|
||||
*/
|
||||
val modelNamePrefix = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Suffix that will be appended to all model names. Default is the empty string.
|
||||
*/
|
||||
val modelNameSuffix = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Sets instantiation type mappings.
|
||||
*/
|
||||
val instantiationTypes = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Sets mappings between OpenAPI spec types and generated code types.
|
||||
*/
|
||||
val typeMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Sets additional properties that can be referenced by the mustache templates.
|
||||
*/
|
||||
val additionalProperties = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double.
|
||||
*/
|
||||
val languageSpecificPrimitives = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Specifies mappings between a given class and the import that should be used for that class.
|
||||
*/
|
||||
val importMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Root package for generated code.
|
||||
*/
|
||||
val invokerPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* GroupId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
val groupId = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* ArtifactId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
val id = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Artifact version in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
val version = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Reference the library template (sub-template) of a generator.
|
||||
*/
|
||||
val library = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Git user ID, e.g. openapitools.
|
||||
*/
|
||||
val gitUserId = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Git repo ID, e.g. openapi-generator.
|
||||
*/
|
||||
val gitRepoId = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Release note, default to 'Minor update'.
|
||||
*/
|
||||
val releaseNote = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}}/{language}'
|
||||
*/
|
||||
val httpUserAgent = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Specifies how a reserved name should be escaped to. Otherwise, the default _<name> is used.
|
||||
*/
|
||||
val reservedWordsMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Specifies an override location for the .openapi-generator-ignore file. Most useful on initial generation.
|
||||
*/
|
||||
val ignoreFileOverride = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Remove prefix of operationId, e.g. config_getId => getId
|
||||
*/
|
||||
val removeOperationIdPrefix = project.objects.property<Boolean?>()
|
||||
|
||||
/**
|
||||
* Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val apiFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines which model-related files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val modelFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines which supporting files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* Supporting files are those related to projects/frameworks which may be modified
|
||||
* by consumers.
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val supportingFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines whether or not model-related _test_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL model-related _test_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val generateModelTests = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not model-related _documentation_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL model-related _documentation_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val generateModelDocumentation = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not api-related _test_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL api-related _test_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val generateApiTests = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not api-related _documentation_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL api-related _documentation_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
val generateApiDocumentation = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* A special-case setting which configures some generators with XML support. In some cases,
|
||||
* this forces json OR xml, so the default here is false.
|
||||
*/
|
||||
val withXml = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* A map of options specific to a generator.
|
||||
*/
|
||||
val configOptions = project.objects.property<Map<String, String>>()
|
||||
|
||||
init {
|
||||
applyDefaults()
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
fun applyDefaults(){
|
||||
releaseNote.set("Minor update")
|
||||
modelNamePrefix.set("")
|
||||
modelNameSuffix.set("")
|
||||
generateModelTests.set(true)
|
||||
generateModelDocumentation.set(true)
|
||||
generateApiTests.set(true)
|
||||
generateApiDocumentation.set(true)
|
||||
withXml.set(false)
|
||||
configOptions.set(mapOf())
|
||||
validateSpec.set(true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.extensions
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
/**
|
||||
* Gradle project level extension object definition for the meta-generator task
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class OpenApiGeneratorMetaExtension(project: Project) {
|
||||
/**
|
||||
* The human-readable generator name of the newly created template generator.
|
||||
*/
|
||||
val generatorName = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The packageName generatorName to put the main class into (defaults to org.openapitools.codegen)
|
||||
*/
|
||||
val packageName = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Where to write the generated files (current dir by default).
|
||||
*/
|
||||
val outputFolder = project.objects.property<String>()
|
||||
|
||||
init {
|
||||
generatorName.set("default")
|
||||
packageName.set("org.openapitools.codegen")
|
||||
outputFolder.set("")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.extensions
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
/**
|
||||
* Gradle project level extension object definition for the generators task
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class OpenApiGeneratorValidateExtension(project: Project) {
|
||||
/**
|
||||
* The input specification to validate. Supports all formats supported by the Parser.
|
||||
*/
|
||||
val inputSpec = project.objects.property<String>()
|
||||
}
|
||||
@@ -0,0 +1,554 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.internal.logging.text.StyledTextOutput
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
import org.gradle.kotlin.dsl.listProperty
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import org.openapitools.codegen.CodegenConstants
|
||||
import org.openapitools.codegen.DefaultGenerator
|
||||
import org.openapitools.codegen.config.CodegenConfigurator
|
||||
|
||||
|
||||
/**
|
||||
* A task which generates the desired code.
|
||||
*
|
||||
* Example (CLI):
|
||||
*
|
||||
* ./gradlew -q openApiGenerate
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class GenerateTask : DefaultTask() {
|
||||
|
||||
/**
|
||||
* The verbosity of generation
|
||||
*/
|
||||
@get:Internal
|
||||
val verbose = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Whether or not an input specification should be validated upon generation.
|
||||
*/
|
||||
@get:Internal
|
||||
val validateSpec = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* The name of the generator which will handle codegen. (see "openApiGenerators" task)
|
||||
*/
|
||||
@get:Internal
|
||||
val generatorName = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The output target directory into which code will be generated.
|
||||
*/
|
||||
@get:Internal
|
||||
val outputDir = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The Open API 2.0/3.x specification location.
|
||||
*/
|
||||
@get:Internal
|
||||
val inputSpec = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* The template directory holding a custom template.
|
||||
*/
|
||||
@get:Internal
|
||||
val templateDir = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Adds authorization headers when fetching the OpenAPI definitions remotely.
|
||||
* Pass in a URL-encoded string of name:header with a comma separating multiple values
|
||||
*/
|
||||
@get:Internal
|
||||
val auth = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Sets specified system properties.
|
||||
*/
|
||||
@get:Internal
|
||||
val systemProperties = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Path to json configuration file.
|
||||
* File content should be in a json format { "optionKey":"optionValue", "optionKey1":"optionValue1"...}
|
||||
* Supported options can be different for each language. Run config-help -g {generator name} command for language specific config options.
|
||||
*/
|
||||
@get:Internal
|
||||
val configFile = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Specifies if the existing files should be overwritten during the generation.
|
||||
*/
|
||||
@get:Internal
|
||||
val skipOverwrite = project.objects.property<Boolean?>()
|
||||
|
||||
/**
|
||||
* Package for generated api classes
|
||||
*/
|
||||
@get:Internal
|
||||
val apiPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Package for generated models
|
||||
*/
|
||||
@get:Internal
|
||||
val modelPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Prefix that will be prepended to all model names. Default is the empty string.
|
||||
*/
|
||||
@get:Internal
|
||||
val modelNamePrefix = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Suffix that will be appended to all model names. Default is the empty string.
|
||||
*/
|
||||
@get:Internal
|
||||
val modelNameSuffix = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Sets instantiation type mappings.
|
||||
*/
|
||||
@get:Internal
|
||||
val instantiationTypes = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Sets mappings between OpenAPI spec types and generated code types.
|
||||
*/
|
||||
@get:Internal
|
||||
val typeMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value.
|
||||
* You can also have multiple occurrences of this option.
|
||||
*/
|
||||
@get:Internal
|
||||
val additionalProperties = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double.
|
||||
*/
|
||||
@get:Internal
|
||||
val languageSpecificPrimitives = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Specifies mappings between a given class and the import that should be used for that class.
|
||||
*/
|
||||
@get:Internal
|
||||
val importMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Root package for generated code.
|
||||
*/
|
||||
@get:Internal
|
||||
val invokerPackage = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* GroupId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
@get:Internal
|
||||
val groupId = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* ArtifactId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
@get:Internal
|
||||
val id = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Artifact version in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators.
|
||||
*/
|
||||
@get:Internal
|
||||
val version = project.objects.property<String>()
|
||||
|
||||
/**
|
||||
* Reference the library template (sub-template) of a generator.
|
||||
*/
|
||||
@get:Internal
|
||||
val library = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Git user ID, e.g. openapitools.
|
||||
*/
|
||||
@get:Internal
|
||||
val gitUserId = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Git repo ID, e.g. openapi-generator.
|
||||
*/
|
||||
@get:Internal
|
||||
val gitRepoId = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Release note, default to 'Minor update'.
|
||||
*/
|
||||
@get:Internal
|
||||
val releaseNote = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}}/{language}'
|
||||
*/
|
||||
@get:Internal
|
||||
val httpUserAgent = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Specifies how a reserved name should be escaped to.
|
||||
*/
|
||||
@get:Internal
|
||||
val reservedWordsMappings = project.objects.property<Map<String, String>>()
|
||||
|
||||
/**
|
||||
* Specifies an override location for the .openapi-generator-ignore file. Most useful on initial generation.
|
||||
*/
|
||||
@get:Internal
|
||||
val ignoreFileOverride = project.objects.property<String?>()
|
||||
|
||||
/**
|
||||
* Remove prefix of operationId, e.g. config_getId => getId
|
||||
*/
|
||||
@get:Internal
|
||||
val removeOperationIdPrefix = project.objects.property<Boolean?>()
|
||||
|
||||
/**
|
||||
* Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* This option enables/disables generation of ALL api-related files.
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val apiFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines which model-related files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val modelFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines which supporting files should be generated. This allows you to create a subset of generated files (or none at all).
|
||||
*
|
||||
* Supporting files are those related to projects/frameworks which may be modified
|
||||
* by consumers.
|
||||
*
|
||||
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
|
||||
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
|
||||
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val supportingFilesConstrainedTo = project.objects.listProperty<String>()
|
||||
|
||||
/**
|
||||
* Defines whether or not model-related _test_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL model-related _test_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val generateModelTests = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not model-related _documentation_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL model-related _documentation_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val generateModelDocumentation = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not api-related _test_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL api-related _test_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val generateApiTests = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Defines whether or not api-related _documentation_ files should be generated.
|
||||
*
|
||||
* This option enables/disables generation of ALL api-related _documentation_ files.
|
||||
*
|
||||
* For more control over generation of individual files, configure an ignore file and
|
||||
* refer to it via [ignoreFileOverride].
|
||||
*/
|
||||
@get:Internal
|
||||
val generateApiDocumentation = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* A special-case setting which configures some generators with XML support. In some cases,
|
||||
* this forces json OR xml, so the default here is false.
|
||||
*/
|
||||
@get:Internal
|
||||
val withXml = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* A dynamic map of options specific to a generator.
|
||||
*/
|
||||
@get:Internal
|
||||
val configOptions = project.objects.property<Map<String, String>>()
|
||||
|
||||
private val originalEnvironmentVariables = mutableMapOf<String, String?>()
|
||||
|
||||
private fun <T : Any?> Property<T>.ifNotEmpty(block: Property<T>.(T) -> Unit) {
|
||||
if (isPresent) {
|
||||
val item: T? = get()
|
||||
if (item != null) {
|
||||
when (get()) {
|
||||
is String -> if ((get() as String).isNotEmpty()) {
|
||||
block(get())
|
||||
}
|
||||
is String? -> if (true == (get() as String?)?.isNotEmpty()) {
|
||||
block(get())
|
||||
}
|
||||
else -> block(get())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
@TaskAction
|
||||
fun doWork() {
|
||||
val configurator: CodegenConfigurator = if (configFile.isPresent) {
|
||||
CodegenConfigurator.fromFile(configFile.get())
|
||||
} else CodegenConfigurator()
|
||||
|
||||
try {
|
||||
if (systemProperties.isPresent) {
|
||||
systemProperties.get().forEach { (key, value) ->
|
||||
// System.setProperty returns the original value for a key, or null.
|
||||
// Cache the original value or null…we will late put the properties back in their original state.
|
||||
originalEnvironmentVariables[key] = System.setProperty(key, value)
|
||||
configurator.addSystemProperty(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
if (supportingFilesConstrainedTo.isPresent && supportingFilesConstrainedTo.get().isNotEmpty()) {
|
||||
System.setProperty(CodegenConstants.SUPPORTING_FILES, supportingFilesConstrainedTo.get().joinToString(","))
|
||||
} else {
|
||||
System.clearProperty(CodegenConstants.SUPPORTING_FILES)
|
||||
}
|
||||
|
||||
if (modelFilesConstrainedTo.isPresent && modelFilesConstrainedTo.get().isNotEmpty()) {
|
||||
System.setProperty(CodegenConstants.MODELS, modelFilesConstrainedTo.get().joinToString(","))
|
||||
} else {
|
||||
System.clearProperty(CodegenConstants.MODELS)
|
||||
}
|
||||
|
||||
if (apiFilesConstrainedTo.isPresent && apiFilesConstrainedTo.get().isNotEmpty()) {
|
||||
System.setProperty(CodegenConstants.APIS, apiFilesConstrainedTo.get().joinToString(","))
|
||||
} else {
|
||||
System.clearProperty(CodegenConstants.APIS)
|
||||
}
|
||||
|
||||
System.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.get().toString())
|
||||
System.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.get().toString())
|
||||
System.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.get().toString())
|
||||
System.setProperty(CodegenConstants.API_TESTS, generateApiTests.get().toString())
|
||||
System.setProperty(CodegenConstants.WITH_XML, withXml.get().toString())
|
||||
|
||||
// now override with any specified parameters
|
||||
verbose.ifNotEmpty { value ->
|
||||
configurator.isVerbose = value
|
||||
}
|
||||
|
||||
validateSpec.ifNotEmpty { value ->
|
||||
configurator.isValidateSpec = value
|
||||
}
|
||||
|
||||
skipOverwrite.ifNotEmpty { value ->
|
||||
configurator.isSkipOverwrite = value ?: false
|
||||
}
|
||||
|
||||
inputSpec.ifNotEmpty { value ->
|
||||
configurator.inputSpec = value
|
||||
}
|
||||
|
||||
generatorName.ifNotEmpty { value ->
|
||||
configurator.generatorName = value
|
||||
}
|
||||
|
||||
outputDir.ifNotEmpty { value ->
|
||||
configurator.outputDir = value
|
||||
}
|
||||
|
||||
auth.ifNotEmpty { value ->
|
||||
configurator.auth = value
|
||||
}
|
||||
|
||||
templateDir.ifNotEmpty { value ->
|
||||
configurator.templateDir = value
|
||||
}
|
||||
|
||||
apiPackage.ifNotEmpty { value ->
|
||||
configurator.apiPackage = value
|
||||
}
|
||||
|
||||
modelPackage.ifNotEmpty { value ->
|
||||
configurator.modelPackage = value
|
||||
}
|
||||
|
||||
modelNamePrefix.ifNotEmpty { value ->
|
||||
configurator.modelNamePrefix = value
|
||||
}
|
||||
|
||||
modelNameSuffix.ifNotEmpty { value ->
|
||||
configurator.modelNameSuffix = value
|
||||
}
|
||||
|
||||
invokerPackage.ifNotEmpty { value ->
|
||||
configurator.invokerPackage = value
|
||||
}
|
||||
|
||||
groupId.ifNotEmpty { value ->
|
||||
configurator.groupId = value
|
||||
}
|
||||
|
||||
id.ifNotEmpty { value ->
|
||||
configurator.artifactId = value
|
||||
}
|
||||
|
||||
version.ifNotEmpty { value ->
|
||||
configurator.artifactVersion = value
|
||||
}
|
||||
|
||||
library.ifNotEmpty { value ->
|
||||
configurator.library = value
|
||||
}
|
||||
|
||||
gitUserId.ifNotEmpty { value ->
|
||||
configurator.gitUserId = value
|
||||
}
|
||||
|
||||
gitRepoId.ifNotEmpty { value ->
|
||||
configurator.gitRepoId = value
|
||||
}
|
||||
|
||||
releaseNote.ifNotEmpty { value ->
|
||||
configurator.releaseNote = value
|
||||
}
|
||||
|
||||
httpUserAgent.ifNotEmpty { value ->
|
||||
configurator.httpUserAgent = value
|
||||
}
|
||||
|
||||
ignoreFileOverride.ifNotEmpty { value ->
|
||||
configurator.ignoreFileOverride = value
|
||||
}
|
||||
|
||||
removeOperationIdPrefix.ifNotEmpty { value ->
|
||||
configurator.removeOperationIdPrefix = value!!
|
||||
}
|
||||
|
||||
if (systemProperties.isPresent) {
|
||||
systemProperties.get().forEach { entry ->
|
||||
configurator.addSystemProperty(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (instantiationTypes.isPresent) {
|
||||
instantiationTypes.get().forEach { entry ->
|
||||
configurator.addInstantiationType(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (importMappings.isPresent) {
|
||||
importMappings.get().forEach { entry ->
|
||||
configurator.addImportMapping(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (typeMappings.isPresent) {
|
||||
typeMappings.get().forEach { entry ->
|
||||
configurator.addTypeMapping(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalProperties.isPresent) {
|
||||
additionalProperties.get().forEach { entry ->
|
||||
configurator.addAdditionalProperty(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (languageSpecificPrimitives.isPresent) {
|
||||
languageSpecificPrimitives.get().forEach {
|
||||
configurator.addLanguageSpecificPrimitive(it)
|
||||
}
|
||||
}
|
||||
|
||||
if (reservedWordsMappings.isPresent) {
|
||||
reservedWordsMappings.get().forEach { entry ->
|
||||
configurator.addAdditionalReservedWordMapping(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
val clientOptInput = configurator.toClientOptInput()
|
||||
val codgenConfig = clientOptInput.config
|
||||
|
||||
if (configOptions.isPresent) {
|
||||
val userSpecifiedConfigOptions = configOptions.get()
|
||||
codgenConfig.cliOptions().forEach {
|
||||
if (userSpecifiedConfigOptions.containsKey(it.opt)) {
|
||||
clientOptInput.config.additionalProperties()[it.opt] = userSpecifiedConfigOptions[it.opt]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
val out = services.get(StyledTextOutputFactory::class.java).create("openapi")
|
||||
out.withStyle(StyledTextOutput.Style.Success)
|
||||
|
||||
DefaultGenerator().opts(clientOptInput).generate()
|
||||
|
||||
out.println("Successfully generated code to ${configurator.outputDir}")
|
||||
} catch (e: RuntimeException) {
|
||||
throw GradleException("Code generation failed.", e)
|
||||
}
|
||||
} finally {
|
||||
// Reset all modified system properties back to their original state
|
||||
originalEnvironmentVariables.forEach {
|
||||
when {
|
||||
it.value == null -> System.clearProperty(it.key)
|
||||
else -> System.setProperty(it.key, it.value)
|
||||
}
|
||||
}
|
||||
originalEnvironmentVariables.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.internal.logging.text.StyledTextOutput
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
import org.openapitools.codegen.CodegenConfigLoader
|
||||
import org.openapitools.codegen.CodegenType
|
||||
|
||||
/**
|
||||
* A task which lists out the generators available in OpenAPI Generator
|
||||
*
|
||||
* Example (CLI):
|
||||
*
|
||||
* ./gradlew -q openApiGenerators
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class GeneratorsTask : DefaultTask() {
|
||||
@Suppress("unused")
|
||||
@TaskAction
|
||||
fun doWork() {
|
||||
val generators = CodegenConfigLoader.getAll()
|
||||
|
||||
val out = services.get(StyledTextOutputFactory::class.java).create("openapi")
|
||||
|
||||
StringBuilder().apply {
|
||||
val types = CodegenType.values()
|
||||
|
||||
append("The following generators are available:")
|
||||
|
||||
append(System.lineSeparator())
|
||||
append(System.lineSeparator())
|
||||
|
||||
for (type in types) {
|
||||
append(type.name).append(" generators:")
|
||||
append(System.lineSeparator())
|
||||
|
||||
generators.filter { it.tag == type }
|
||||
.sortedBy { it.name }
|
||||
.forEach({ generator ->
|
||||
append(" - ")
|
||||
append(generator.name)
|
||||
append(System.lineSeparator())
|
||||
})
|
||||
|
||||
append(System.lineSeparator())
|
||||
append(System.lineSeparator())
|
||||
}
|
||||
|
||||
out.withStyle(StyledTextOutput.Style.Success)
|
||||
out.formatln("%s%n", toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.tasks
|
||||
|
||||
import com.samskivert.mustache.Mustache
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.internal.logging.text.StyledTextOutput
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import org.openapitools.codegen.CodegenConfig
|
||||
import org.openapitools.codegen.CodegenConstants
|
||||
import org.openapitools.codegen.DefaultGenerator
|
||||
import org.openapitools.codegen.SupportingFile
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.charset.Charset
|
||||
|
||||
/**
|
||||
* A task which generates a new generator (meta). Useful for redistributable generator packages.
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class MetaTask : DefaultTask() {
|
||||
|
||||
@get:Internal
|
||||
val generatorName = project.objects.property<String>()
|
||||
|
||||
@get:Internal
|
||||
val packageName = project.objects.property<String>()
|
||||
|
||||
@get:Internal
|
||||
val outputFolder = project.objects.property<String>()
|
||||
|
||||
@Suppress("unused")
|
||||
@TaskAction
|
||||
fun doWork() {
|
||||
|
||||
val packageToPath = packageName.get().replace(".", File.separator)
|
||||
val dir = File(outputFolder.get())
|
||||
val klass = "${generatorName.get().titleCasedTextOnly()}Generator"
|
||||
|
||||
val templateResourceDir = generatorName.get().hyphenatedTextOnly()
|
||||
|
||||
val out = services.get(StyledTextOutputFactory::class.java).create("openapi")
|
||||
|
||||
out.withStyle(StyledTextOutput.Style.Info)
|
||||
|
||||
logger.debug("package: {}", packageName.get())
|
||||
logger.debug("dir: {}", dir.absolutePath)
|
||||
logger.debug("generator class: {}", klass)
|
||||
|
||||
val supportingFiles = listOf(
|
||||
SupportingFile("pom.mustache", "", "pom.xml"),
|
||||
SupportingFile("generatorClass.mustache", dir("src", "main", "java", packageToPath), "$klass.java"),
|
||||
SupportingFile("README.mustache", "", "README.md"),
|
||||
SupportingFile("api.template", dir("src", "main", "resources", templateResourceDir), "api.mustache"),
|
||||
SupportingFile("model.template", dir("src", "main", "resources", templateResourceDir), "model.mustache"),
|
||||
SupportingFile("myFile.template", dir("src", "main", "resources", templateResourceDir), "myFile.mustache"),
|
||||
SupportingFile("services.mustache", dir("src", "main", "resources", "META-INF", "services"), CodegenConfig::class.java.canonicalName))
|
||||
|
||||
val currentVersion = CodegenConstants::class.java.`package`.implementationVersion
|
||||
|
||||
val data = mapOf("generatorPackage" to packageToPath,
|
||||
"generatorClass" to klass,
|
||||
"name" to templateResourceDir,
|
||||
"fullyQualifiedGeneratorClass" to "${packageName.get()}.$klass",
|
||||
"openapiGeneratorVersion" to currentVersion)
|
||||
|
||||
val generator = DefaultGenerator()
|
||||
supportingFiles.map {
|
||||
try {
|
||||
val destinationFolder = File(File(dir.absolutePath), it.folder)
|
||||
destinationFolder.mkdirs()
|
||||
val outputFile = File(destinationFolder, it.destinationFilename)
|
||||
|
||||
val template = generator.readTemplate(File("codegen", it.templateFile).path)
|
||||
var formatted = template
|
||||
|
||||
if (it.templateFile.endsWith(".mustache")) {
|
||||
formatted = Mustache.compiler()
|
||||
.withLoader(loader(generator))
|
||||
.defaultValue("")
|
||||
.compile(template).execute(data)
|
||||
}
|
||||
|
||||
outputFile.writeText(formatted, Charset.forName("UTF8"))
|
||||
|
||||
out.formatln("Wrote file to %s", outputFile.absolutePath)
|
||||
|
||||
// TODO: register outputs
|
||||
// return outputFile
|
||||
} catch (e: IOException) {
|
||||
logger.error(e.message)
|
||||
throw GradleException("Can't generate project", e)
|
||||
}
|
||||
}
|
||||
out.withStyle(StyledTextOutput.Style.Success)
|
||||
out.formatln("Created generator %s", klass)
|
||||
}
|
||||
|
||||
private fun loader(generator: DefaultGenerator): Mustache.TemplateLoader {
|
||||
return Mustache.TemplateLoader { name ->
|
||||
generator.getTemplateReader("codegen${File.separator}$name.mustache")
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.titleCasedTextOnly(): String =
|
||||
this.split(Regex("[^a-zA-Z0-9]")).joinToString(separator = "", transform = String::capitalize)
|
||||
|
||||
private fun String.hyphenatedTextOnly(): String =
|
||||
this.split(Regex("[^a-zA-Z0-9]")).joinToString(separator = "-", transform = String::toLowerCase)
|
||||
|
||||
private fun dir(vararg parts: String): String =
|
||||
parts.joinToString(separator = File.separator)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.generator.gradle.plugin.tasks
|
||||
|
||||
import io.swagger.parser.OpenAPIParser
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.options.Option
|
||||
import org.gradle.internal.logging.text.StyledTextOutput
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
/**
|
||||
* A generator which validates an Open API spec. This task outputs a list of validation issues and errors.
|
||||
*
|
||||
* Example:
|
||||
* cli:
|
||||
*
|
||||
* ./gradlew openApiValidate --input=/path/to/file
|
||||
*
|
||||
* build.gradle:
|
||||
*
|
||||
* openApiMeta {
|
||||
* inputSpec = "path/to/spec.yaml"
|
||||
* }
|
||||
*
|
||||
* @author Jim Schubert
|
||||
*/
|
||||
open class ValidateTask : DefaultTask() {
|
||||
@get:Internal
|
||||
var inputSpec = project.objects.property<String>()
|
||||
|
||||
@Suppress("unused")
|
||||
@get:Internal
|
||||
@set:Option(option = "input", description = "The input specification.")
|
||||
var input: String? = null
|
||||
set(value) {
|
||||
inputSpec.set(value)
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
@TaskAction
|
||||
fun doWork() {
|
||||
val spec = inputSpec.get()
|
||||
logger.quiet("Validating spec $spec")
|
||||
val result = OpenAPIParser().readLocation(spec, null, null)
|
||||
val messages = result.messages.toSet()
|
||||
val out = services.get(StyledTextOutputFactory::class.java).create("openapi")
|
||||
|
||||
if (messages.isNotEmpty()) {
|
||||
|
||||
out.withStyle(StyledTextOutput.Style.Error)
|
||||
out.println("\nSpec is invalid.\nIssues:\n")
|
||||
|
||||
messages.forEach {
|
||||
out.withStyle(StyledTextOutput.Style.Error)
|
||||
out.println("\t$it\n")
|
||||
}
|
||||
|
||||
throw GradleException("Validation failed.")
|
||||
} else {
|
||||
out.withStyle(StyledTextOutput.Style.Success)
|
||||
out.println("Spec is valid.")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class GenerateTaskDslTest : TestBase() {
|
||||
override var temp: File = createTempDir(javaClass.simpleName)
|
||||
|
||||
private val defaultBuildGradle = """
|
||||
plugins {
|
||||
id 'org.openapi.generator'
|
||||
}
|
||||
openApiGenerate {
|
||||
generatorName = "kotlin"
|
||||
inputSpec = file("spec.yaml").absolutePath
|
||||
outputDir = file("build/kotlin").absolutePath
|
||||
apiPackage = "org.openapitools.example.api"
|
||||
invokerPackage = "org.openapitools.example.invoker"
|
||||
modelPackage = "org.openapitools.example.model"
|
||||
configOptions = [
|
||||
dateLibrary: "java8"
|
||||
]
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@Test
|
||||
fun `openApiGenerate should create an expected file structure from DSL config`() {
|
||||
// Arrange
|
||||
val projectFiles = mapOf(
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml")
|
||||
)
|
||||
withProject(defaultBuildGradle, projectFiles)
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiGenerate")
|
||||
.withPluginClasspath()
|
||||
.build()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("Successfully generated code to"), "User friendly generate notice is missing.")
|
||||
|
||||
listOf(
|
||||
"build/kotlin/.openapi-generator-ignore",
|
||||
"build/kotlin/docs/PetsApi.md",
|
||||
"build/kotlin/docs/Pets.md",
|
||||
"build/kotlin/docs/Error.md",
|
||||
"build/kotlin/docs/Pet.md",
|
||||
"build/kotlin/README.md",
|
||||
"build/kotlin/build.gradle",
|
||||
"build/kotlin/.openapi-generator/VERSION",
|
||||
"build/kotlin/settings.gradle",
|
||||
"build/kotlin/src/main/kotlin/org/openapitools/example/model/Pets.kt",
|
||||
"build/kotlin/src/main/kotlin/org/openapitools/example/model/Pet.kt",
|
||||
"build/kotlin/src/main/kotlin/org/openapitools/example/model/Error.kt",
|
||||
"build/kotlin/src/main/kotlin/org/openapitools/example/api/PetsApi.kt",
|
||||
"build/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt"
|
||||
).map {
|
||||
val f = File(temp, it)
|
||||
assertTrue(f.exists() && f.isFile, "An expected file was not generated when invoking the generation.")
|
||||
}
|
||||
|
||||
assertEquals(TaskOutcome.SUCCESS, result.task(":openApiGenerate")?.outcome,
|
||||
"Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class GeneratorsTaskDslTest : TestBase() {
|
||||
override var temp: File = createTempDir(javaClass.simpleName)
|
||||
|
||||
@Test
|
||||
fun `openApiGenerators should list generators available to the user`() {
|
||||
// Arrange
|
||||
withProject("""
|
||||
| plugins {
|
||||
| id 'org.openapi.generator'
|
||||
| }
|
||||
""".trimMargin())
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiGenerators")
|
||||
.withPluginClasspath()
|
||||
.build()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("The following generators are available:"), "User friendly generator notice is missing.")
|
||||
assertTrue(result.output.contains("CLIENT generators:"), "Expected client generator header is missing.")
|
||||
assertTrue(result.output.contains("android"), "Spot-checking listed client generators is missing a client generator.")
|
||||
assertTrue(result.output.contains("SERVER generators:"), "Expected server generator header is missing.")
|
||||
assertTrue(result.output.contains("kotlin-server"), "Spot-checking listed server generators is missing a server generator.")
|
||||
assertEquals(TaskOutcome.SUCCESS, result.task(":openApiGenerators")?.outcome,
|
||||
"Expected a successful run, but found ${result.task(":openApiGenerators")?.outcome}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class MetaTaskDslTest : TestBase() {
|
||||
override var temp: File = createTempDir(javaClass.simpleName)
|
||||
|
||||
@Test
|
||||
fun `openApiMeta should generate desired project contents`() {
|
||||
// Arrange
|
||||
val buildDirReplacement = "\$buildDir/meta"
|
||||
withProject("""
|
||||
| plugins {
|
||||
| id 'org.openapi.generator'
|
||||
| }
|
||||
|
|
||||
| openApiMeta {
|
||||
| generatorName = "Sample"
|
||||
| packageName = "org.openapitools.example"
|
||||
| outputFolder = "$buildDirReplacement".toString()
|
||||
| }
|
||||
""".trimMargin())
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiMeta")
|
||||
.withPluginClasspath()
|
||||
.build()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("Wrote file to"), "User friendly write notice is missing.")
|
||||
|
||||
// To avoid any OS-specific output causing issues with our stdout comparisons, only compare on expected filenames.
|
||||
listOf(
|
||||
"SampleGenerator.java",
|
||||
"README.md",
|
||||
"api.mustache",
|
||||
"model.mustache",
|
||||
"myFile.mustache",
|
||||
"org.openapitools.codegen.CodegenConfig",
|
||||
"pom.xml"
|
||||
).map {
|
||||
assertTrue(result.output.contains(it), "Expected $it to be listed in gradle stdout.")
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
TaskOutcome.SUCCESS,
|
||||
result.task(":openApiMeta")?.outcome,
|
||||
"Expected a successful run, but found ${result.task(":openApiMeta")?.outcome}"
|
||||
)
|
||||
}
|
||||
}
|
||||
34
modules/openapi-generator-gradle-plugin/bin/test/TestBase.kt
Normal file
34
modules/openapi-generator-gradle-plugin/bin/test/TestBase.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.testng.annotations.AfterMethod
|
||||
import org.testng.annotations.BeforeMethod
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
abstract class TestBase {
|
||||
protected open lateinit var temp: File
|
||||
|
||||
@BeforeMethod
|
||||
protected fun before() {
|
||||
temp = createTempDir(javaClass.simpleName)
|
||||
temp.deleteOnExit()
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
protected fun after(){
|
||||
temp.deleteRecursively()
|
||||
}
|
||||
|
||||
protected fun withProject(
|
||||
buildContents: String,
|
||||
projectFiles: Map<String, InputStream> = mapOf()
|
||||
) {
|
||||
val buildFile = File(temp,"build.gradle")
|
||||
buildFile.writeText(buildContents)
|
||||
|
||||
projectFiles.forEach { entry ->
|
||||
val target = File(temp, entry.key)
|
||||
entry.value.copyTo(target.outputStream())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package org.openapitools.generator.gradle.plugin
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.testkit.runner.TaskOutcome.FAILED
|
||||
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class ValidateTaskDslTest : TestBase() {
|
||||
override var temp: File = createTempDir(javaClass.simpleName)
|
||||
|
||||
@Test
|
||||
fun `openApiValidate should fail on non-file spec`() {
|
||||
// Arrange
|
||||
withProject("""
|
||||
| plugins {
|
||||
| id 'org.openapi.generator'
|
||||
| }
|
||||
|
|
||||
| openApiValidate {
|
||||
| inputSpec = "some_location"
|
||||
| }
|
||||
""".trimMargin())
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiValidate")
|
||||
.withPluginClasspath()
|
||||
.buildAndFail()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("unable to read location `some_location`"), "Unexpected/no message presented to the user for a spec pointing to an invalid URI.")
|
||||
assertEquals(FAILED, result.task(":openApiValidate")?.outcome,
|
||||
"Expected a failed run, but found ${result.task(":openApiValidate")?.outcome}")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `openApiValidate should succeed on valid spec`() {
|
||||
// Arrange
|
||||
val projectFiles = mapOf(
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml")
|
||||
)
|
||||
|
||||
withProject("""
|
||||
| plugins {
|
||||
| id 'org.openapi.generator'
|
||||
| }
|
||||
|
|
||||
| openApiValidate {
|
||||
| inputSpec = file("spec.yaml").absolutePath
|
||||
| }
|
||||
""".trimMargin(), projectFiles)
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiValidate")
|
||||
.withPluginClasspath()
|
||||
.build()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("Spec is valid."), "Unexpected/no message presented to the user for a valid spec.")
|
||||
assertEquals(SUCCESS, result.task(":openApiValidate")?.outcome,
|
||||
"Expected a successful run, but found ${result.task(":openApiValidate")?.outcome}")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `openApiValidate should fail on invalid spec`() {
|
||||
// Arrange
|
||||
val projectFiles = mapOf(
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0-invalid.yaml")
|
||||
)
|
||||
withProject("""
|
||||
| plugins {
|
||||
| id 'org.openapi.generator'
|
||||
| }
|
||||
|
|
||||
| openApiValidate {
|
||||
| inputSpec = file('spec.yaml').absolutePath
|
||||
| }
|
||||
""".trimMargin(), projectFiles)
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiValidate")
|
||||
.withPluginClasspath()
|
||||
.buildAndFail()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.output.contains("Spec is invalid."), "Unexpected/no message presented to the user for an invalid spec.")
|
||||
assertEquals(FAILED, result.task(":openApiValidate")?.outcome,
|
||||
"Expected a failed run, but found ${result.task(":openApiValidate")?.outcome}")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
openapi: "3.0.0"
|
||||
servers:
|
||||
- url: http://petstore.swagger.io/v1
|
||||
paths:
|
||||
/pets:
|
||||
get:
|
||||
summary: List all pets
|
||||
operationId: listPets
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
description: How many items to return at one time (max 100)
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: A paged array of pets
|
||||
headers:
|
||||
x-next:
|
||||
description: A link to the next page of responses
|
||||
schema:
|
||||
type: string
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
summary: Create a pet
|
||||
tags:
|
||||
- pets
|
||||
responses:
|
||||
'201':
|
||||
description: Null response
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/pets/{petId}:
|
||||
get:
|
||||
summary: Info for a specific pet
|
||||
operationId: showPetById
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
required: true
|
||||
description: The id of the pet to retrieve
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: Expected response to a valid request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
Pet:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
Pets:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Pet"
|
||||
Error:
|
||||
required:
|
||||
- code
|
||||
- message
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
@@ -0,0 +1,109 @@
|
||||
openapi: "3.0.0"
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: Swagger Petstore
|
||||
license:
|
||||
name: MIT
|
||||
servers:
|
||||
- url: http://petstore.swagger.io/v1
|
||||
paths:
|
||||
/pets:
|
||||
get:
|
||||
summary: List all pets
|
||||
operationId: listPets
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
description: How many items to return at one time (max 100)
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: A paged array of pets
|
||||
headers:
|
||||
x-next:
|
||||
description: A link to the next page of responses
|
||||
schema:
|
||||
type: string
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
summary: Create a pet
|
||||
operationId: createPets
|
||||
tags:
|
||||
- pets
|
||||
responses:
|
||||
'201':
|
||||
description: Null response
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/pets/{petId}:
|
||||
get:
|
||||
summary: Info for a specific pet
|
||||
operationId: showPetById
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
required: true
|
||||
description: The id of the pet to retrieve
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: Expected response to a valid request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
Pet:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
Pets:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Pet"
|
||||
Error:
|
||||
required:
|
||||
- code
|
||||
- message
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
@@ -1,4 +1,4 @@
|
||||
openApiGeneratorVersion=3.3.4
|
||||
openApiGeneratorVersion=4.0.0-SNAPSHOT
|
||||
|
||||
# BEGIN placeholders
|
||||
# these are just placeholders to allow contributors to build directly
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.3.4</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.3.4</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.3.4</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-online</artifactId>
|
||||
@@ -13,7 +13,9 @@
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<spring-boot-version>2.0.7.RELEASE</spring-boot-version>
|
||||
<springfox-version>2.8.0</springfox-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@@ -85,5 +87,23 @@
|
||||
<artifactId>openapi-generator</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>2.0.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -69,12 +69,8 @@ public class GenApiService implements GenApiDelegate {
|
||||
servers.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
}
|
||||
|
||||
private final NativeWebRequest request;
|
||||
|
||||
@Autowired
|
||||
public GenApiService(NativeWebRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
private NativeWebRequest request;
|
||||
|
||||
@Override
|
||||
public Optional<NativeWebRequest> getRequest() {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Generator {
|
||||
try {
|
||||
config = CodegenConfigLoader.forName(language);
|
||||
} catch (Exception e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format(Locale.ROOT,"Unsupported target %s supplied. %s",
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, String.format(Locale.ROOT,"Unsupported target %s supplied. %s",
|
||||
language, e));
|
||||
}
|
||||
Map<String, CliOption> map = new LinkedHashMap<>();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.3.4</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenDiscriminator {
|
||||
@@ -85,4 +87,13 @@ public class CodegenDiscriminator {
|
||||
public int hashCode() {
|
||||
return Objects.hash(propertyName, mapping, mappedModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("propertyName", propertyName)
|
||||
.append("mapping", mapping)
|
||||
.append("mappedModels", mappedModels)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,7 @@ package org.openapitools.codegen;
|
||||
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
@@ -40,6 +33,11 @@ public class CodegenModel {
|
||||
public List<CodegenModel> interfaceModels;
|
||||
public List<CodegenModel> children;
|
||||
|
||||
// anyOf, oneOf, allOf
|
||||
public Set<String> anyOf = new TreeSet<String>();
|
||||
public Set<String> oneOf = new TreeSet<String>();
|
||||
public Set<String> allOf = new TreeSet<String>();
|
||||
|
||||
public String name, classname, title, description, classVarName, modelJson, dataType, xmlPrefix, xmlNamespace, xmlName;
|
||||
public String classFilename; // store the class file name, mainly used for import
|
||||
public String unescapedDescription;
|
||||
@@ -53,8 +51,8 @@ public class CodegenModel {
|
||||
public List<CodegenProperty> optionalVars = new ArrayList<CodegenProperty>(); // a list of optional properties
|
||||
public List<CodegenProperty> readOnlyVars = new ArrayList<CodegenProperty>(); // a list of read-only properties
|
||||
public List<CodegenProperty> readWriteVars = new ArrayList<CodegenProperty>(); // a list of properties for read, write
|
||||
public List<CodegenProperty> allVars;
|
||||
public List<CodegenProperty> parentVars = new ArrayList<>();
|
||||
public List<CodegenProperty> allVars = new ArrayList<CodegenProperty>();
|
||||
public List<CodegenProperty> parentVars = new ArrayList<CodegenProperty>();
|
||||
public Map<String, Object> allowableValues;
|
||||
|
||||
// Sorted sets of required parameters.
|
||||
@@ -195,11 +193,11 @@ public class CodegenModel {
|
||||
result = 31 * result + (mandatory != null ? mandatory.hashCode() : 0);
|
||||
result = 31 * result + (allMandatory != null ? allMandatory.hashCode() : 0);
|
||||
result = 31 * result + (imports != null ? imports.hashCode() : 0);
|
||||
result = 31 * result + (hasVars ? 13:31);
|
||||
result = 31 * result + (emptyVars ? 13:31);
|
||||
result = 31 * result + (hasMoreModels ? 13:31);
|
||||
result = 31 * result + (hasEnums ? 13:31);
|
||||
result = 31 * result + (isEnum ? 13:31);
|
||||
result = 31 * result + (hasVars ? 13 : 31);
|
||||
result = 31 * result + (emptyVars ? 13 : 31);
|
||||
result = 31 * result + (hasMoreModels ? 13 : 31);
|
||||
result = 31 * result + (hasEnums ? 13 : 31);
|
||||
result = 31 * result + (isEnum ? 13 : 31);
|
||||
result = 31 * result + (externalDocumentation != null ? externalDocumentation.hashCode() : 0);
|
||||
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);
|
||||
result = 31 * result + Objects.hash(hasOnlyReadOnly);
|
||||
@@ -499,4 +497,67 @@ public class CodegenModel {
|
||||
public void setAdditionalPropertiesType(String additionalPropertiesType) {
|
||||
this.additionalPropertiesType = additionalPropertiesType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove duplicated properties in all variable list and update "hasMore"
|
||||
*/
|
||||
public void removeAllDuplicatedProperty() {
|
||||
// remove duplicated properties
|
||||
vars = removeDuplicatedProperty(vars);
|
||||
optionalVars = removeDuplicatedProperty(optionalVars);
|
||||
requiredVars = removeDuplicatedProperty(requiredVars);
|
||||
parentVars = removeDuplicatedProperty(parentVars);
|
||||
allVars = removeDuplicatedProperty(allVars);
|
||||
readOnlyVars = removeDuplicatedProperty(readOnlyVars);
|
||||
readWriteVars = removeDuplicatedProperty(readWriteVars);
|
||||
|
||||
// update property list's "hasMore"
|
||||
updatePropertyListHasMore(vars);
|
||||
updatePropertyListHasMore(optionalVars);
|
||||
updatePropertyListHasMore(requiredVars);
|
||||
updatePropertyListHasMore(parentVars);
|
||||
updatePropertyListHasMore(allVars);
|
||||
updatePropertyListHasMore(readOnlyVars);
|
||||
updatePropertyListHasMore(readWriteVars);
|
||||
}
|
||||
|
||||
private List<CodegenProperty> removeDuplicatedProperty(List<CodegenProperty> vars) {
|
||||
// clone the list first
|
||||
List<CodegenProperty> newList = new ArrayList<CodegenProperty>();
|
||||
for (CodegenProperty cp : vars) {
|
||||
newList.add(cp.clone());
|
||||
}
|
||||
|
||||
Set<String> propertyNames = new TreeSet<String>();
|
||||
Set<String> duplicatedNames = new TreeSet<String>();
|
||||
|
||||
ListIterator<CodegenProperty> iterator = newList.listIterator();
|
||||
while (iterator.hasNext()) {
|
||||
CodegenProperty element = iterator.next();
|
||||
|
||||
if (propertyNames.contains(element.baseName)) {
|
||||
duplicatedNames.add(element.baseName);
|
||||
iterator.remove();
|
||||
} else {
|
||||
propertyNames.add(element.baseName);
|
||||
}
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the element and update "hasMore" in the list of codegen properties
|
||||
*/
|
||||
private void updatePropertyListHasMore(List<CodegenProperty> vars) {
|
||||
if (vars != null) {
|
||||
for (int i = 0; i < vars.size(); i++) {
|
||||
if (i < vars.size() - 1) {
|
||||
vars.get(i).hasMore = true;
|
||||
} else { // last element
|
||||
vars.get(i).hasMore = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,7 @@
|
||||
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenProperty implements Cloneable {
|
||||
public String baseName, complexType, getter, setter, description, dataType,
|
||||
@@ -733,6 +729,7 @@ public class CodegenProperty implements Cloneable {
|
||||
if (this.vendorExtensions != null) {
|
||||
cp.vendorExtensions = new HashMap<String, Object>(this.vendorExtensions);
|
||||
}
|
||||
|
||||
return cp;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new IllegalStateException(e);
|
||||
@@ -817,4 +814,6 @@ public class CodegenProperty implements Cloneable {
|
||||
", isXmlWrapped=" + isXmlWrapped +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -875,23 +876,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
throw new RuntimeException("reserved word " + name + " not allowed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name with escaped characters.
|
||||
*
|
||||
* @param name the name to be escaped
|
||||
* @param charactersToAllow characters that are not escaped
|
||||
* @param appdendixToReplacement String to append to replaced characters.
|
||||
* @return the escaped word
|
||||
* <p>
|
||||
* throws Runtime exception as word is not escaped properly.
|
||||
* @see org.openapitools.codegen.utils.StringUtils#escape directly instead
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public String escapeSpecialCharacters(String name, List<String> charactersToAllow, String appdendixToReplacement) {
|
||||
return escape(name, specialCharReplacements, charactersToAllow, appdendixToReplacement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fully-qualified "Model" name for import
|
||||
*
|
||||
@@ -1329,16 +1313,53 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
**/
|
||||
@SuppressWarnings("static-method")
|
||||
public String getSchemaType(Schema schema) {
|
||||
// TODO better logic to handle compose schema
|
||||
if (schema instanceof ComposedSchema) { // composed schema
|
||||
ComposedSchema cs = (ComposedSchema) schema;
|
||||
List<Schema> schemas = ModelUtils.getInterfaces(cs);
|
||||
if (cs.getAllOf() != null) {
|
||||
for (Schema s : cs.getAllOf()) {
|
||||
if (s != null) {
|
||||
// using the first schema defined in allOf
|
||||
schema = s;
|
||||
break;
|
||||
//schema = s;
|
||||
}
|
||||
//LOGGER.info("ALL OF SCHEMA: {}", s);
|
||||
}
|
||||
|
||||
LOGGER.info("Composed schema not yet supported: {}", cs);
|
||||
// get the model (allOf)
|
||||
return getAlias("UNKNOWN_COMPOSED_SCHMEA");
|
||||
} else if (cs.getAnyOf() != null) { // anyOf
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (Schema s : schemas) {
|
||||
if (StringUtils.isNotBlank(s.get$ref())) { // reference to another definition/schema
|
||||
String schemaName = ModelUtils.getSimpleRef(s.get$ref());
|
||||
if (StringUtils.isNotEmpty(schemaName)) {
|
||||
names.add(getAlias(schemaName));
|
||||
} else {
|
||||
LOGGER.warn("Error obtaining the datatype from ref:" + schema.get$ref() + ". Default to 'object'");
|
||||
return "object";
|
||||
}
|
||||
} else {
|
||||
// primitive type or model
|
||||
names.add(getAlias(getPrimitiveType(s)));
|
||||
}
|
||||
return "anyOf<" + String.join(",", names) + ">";
|
||||
}
|
||||
} else if (cs.getOneOf() != null) { // oneOf
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (Schema s : schemas) {
|
||||
if (StringUtils.isNotBlank(s.get$ref())) { // reference to another definition/schema
|
||||
String schemaName = ModelUtils.getSimpleRef(s.get$ref());
|
||||
if (StringUtils.isNotEmpty(schemaName)) {
|
||||
names.add(getAlias(schemaName));
|
||||
} else {
|
||||
LOGGER.warn("Error obtaining the datatype from ref:" + schema.get$ref() + ". Default to 'object'");
|
||||
return "object";
|
||||
}
|
||||
} else {
|
||||
// primitive type or model
|
||||
names.add(getAlias(getPrimitiveType(s)));
|
||||
}
|
||||
return "oneOf<" + String.join(",", names) + ">";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1592,42 +1613,43 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
final ComposedSchema composed = (ComposedSchema) schema;
|
||||
Map<String, Schema> properties = new LinkedHashMap<String, Schema>();
|
||||
List<String> required = new ArrayList<String>();
|
||||
Map<String, Schema> allProperties;
|
||||
List<String> allRequired;
|
||||
Map<String, Schema> allProperties = new LinkedHashMap<String, Schema>();
|
||||
List<String> allRequired = new ArrayList<String>();
|
||||
|
||||
// parent model
|
||||
final String parentName = ModelUtils.getParentName(composed, allDefinitions);
|
||||
final Schema parent = StringUtils.isBlank(parentName) || allDefinitions == null ? null : allDefinitions.get(parentName);
|
||||
final boolean hasParent = StringUtils.isNotBlank(parentName);
|
||||
|
||||
// TODO revise the logic below to set dicriminator, xml attributes
|
||||
if (supportsInheritance || supportsMixins) {
|
||||
allProperties = new LinkedHashMap<String, Schema>();
|
||||
allRequired = new ArrayList<String>();
|
||||
m.allVars = new ArrayList<CodegenProperty>();
|
||||
if (composed.getAllOf() != null) {
|
||||
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
|
||||
for (Schema innerModel : composed.getAllOf()) {
|
||||
for (Schema innerSchema : composed.getAllOf()) { // TOOD need to work with anyOf, oneOf as well
|
||||
if (m.discriminator == null) {
|
||||
LOGGER.debug("discriminator is set to null (not correctly set earlier): {}", name);
|
||||
m.discriminator = createDiscriminator(name, schema, allDefinitions);
|
||||
}
|
||||
if (innerModel.getXml() != null) {
|
||||
m.xmlPrefix = innerModel.getXml().getPrefix();
|
||||
m.xmlNamespace = innerModel.getXml().getNamespace();
|
||||
m.xmlName = innerModel.getXml().getName();
|
||||
|
||||
if (innerSchema.getXml() != null) {
|
||||
m.xmlPrefix = innerSchema.getXml().getPrefix();
|
||||
m.xmlNamespace = innerSchema.getXml().getNamespace();
|
||||
m.xmlName = innerSchema.getXml().getName();
|
||||
}
|
||||
|
||||
if (modelImplCnt++ > 1) {
|
||||
LOGGER.warn("More than one inline schema specified in allOf:. Only the first one is recognized. All others are ignored.");
|
||||
break; // only one ModelImpl with discriminator allowed in allOf
|
||||
break; // only one schema with discriminator allowed in allOf
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
allProperties = null;
|
||||
allRequired = null;
|
||||
}
|
||||
// parent model
|
||||
final String parentName = getParentName(composed, allDefinitions);
|
||||
final Schema parent = StringUtils.isBlank(parentName) || allDefinitions == null ? null : allDefinitions.get(parentName);
|
||||
|
||||
List<Schema> interfaces = getInterfaces(composed);
|
||||
|
||||
// interfaces (intermediate models)
|
||||
if (interfaces != null) {
|
||||
// interfaces (schemas defined in allOf, anyOf, oneOf)
|
||||
List<Schema> interfaces = ModelUtils.getInterfaces(composed);
|
||||
if (!interfaces.isEmpty()) {
|
||||
// m.interfaces is for backward compatibility
|
||||
if (m.interfaces == null)
|
||||
m.interfaces = new ArrayList<String>();
|
||||
|
||||
@@ -1644,12 +1666,29 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
m.interfaces.add(modelName);
|
||||
addImport(m, modelName);
|
||||
if (allDefinitions != null && refSchema != null) {
|
||||
if (!supportsMixins && !supportsInheritance) {
|
||||
if (hasParent || supportsInheritance) {
|
||||
if (supportsInheritance || parentName.equals(modelName)) {
|
||||
// inheritance
|
||||
addProperties(allProperties, allRequired, refSchema, allDefinitions);
|
||||
} else {
|
||||
// composition
|
||||
//LOGGER.debug("Parent {} not set to model name {}", parentName, modelName);
|
||||
addProperties(properties, required, refSchema, allDefinitions);
|
||||
}
|
||||
} else if (!supportsMixins && !supportsInheritance) {
|
||||
addProperties(properties, required, refSchema, allDefinitions);
|
||||
}
|
||||
if (supportsInheritance) {
|
||||
addProperties(allProperties, allRequired, refSchema, allDefinitions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (composed.getAnyOf() != null) {
|
||||
m.anyOf.add(modelName);
|
||||
} else if (composed.getOneOf() != null) {
|
||||
m.oneOf.add(modelName);
|
||||
} else if (composed.getAllOf() != null) {
|
||||
m.allOf.add(modelName);
|
||||
} else {
|
||||
LOGGER.error("Composed schema has incorrect anyOf, allOf, oneOf defined: {}", composed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1659,7 +1698,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
m.parent = toModelName(parentName);
|
||||
addImport(m, m.parent);
|
||||
if (allDefinitions != null && !allDefinitions.isEmpty()) {
|
||||
if (supportsInheritance) {
|
||||
if (hasParent || supportsInheritance) {
|
||||
addProperties(allProperties, allRequired, parent, allDefinitions);
|
||||
} else {
|
||||
addProperties(properties, required, parent, allDefinitions);
|
||||
@@ -1667,23 +1706,24 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// child model (properties owned by the model itself)
|
||||
Schema child = null;
|
||||
if (composed.getAllOf() != null && !composed.getAllOf().isEmpty()) {
|
||||
for (Schema component : composed.getAllOf()) {
|
||||
if (component.get$ref() == null) {
|
||||
child = component;
|
||||
// child schema (properties owned by the schema itself)
|
||||
for (Schema component : interfaces) {
|
||||
if (component.get$ref() == null) {
|
||||
if (component != null) {
|
||||
// component is the child schema
|
||||
addProperties(properties, required, component, allDefinitions);
|
||||
|
||||
if (hasParent || supportsInheritance) {
|
||||
addProperties(allProperties, allRequired, component, allDefinitions);
|
||||
}
|
||||
}
|
||||
break; // at most one schema not using $ref
|
||||
}
|
||||
}
|
||||
if (child != null) {
|
||||
addProperties(properties, required, child, allDefinitions);
|
||||
if (supportsInheritance) {
|
||||
addProperties(allProperties, allRequired, child, allDefinitions);
|
||||
}
|
||||
}
|
||||
|
||||
addVars(m, unaliasPropertySchema(allDefinitions, properties), required, allProperties, allRequired);
|
||||
|
||||
// end of code block for composed schema
|
||||
} else {
|
||||
m.dataType = getSchemaType(schema);
|
||||
if (schema.getEnum() != null && !schema.getEnum().isEmpty()) {
|
||||
@@ -1708,12 +1748,15 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
addVars(m, unaliasPropertySchema(allDefinitions, schema.getProperties()), schema.getRequired());
|
||||
}
|
||||
|
||||
// remove duplicated properties
|
||||
m.removeAllDuplicatedProperty();
|
||||
|
||||
// post process model properties
|
||||
if (m.vars != null) {
|
||||
for (CodegenProperty prop : m.vars) {
|
||||
postProcessModelProperty(m, prop);
|
||||
}
|
||||
}
|
||||
LOGGER.debug("debugging fromModel return: " + m);
|
||||
|
||||
return m;
|
||||
}
|
||||
@@ -1728,7 +1771,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
discriminator.setMapping(schema.getDiscriminator().getMapping());
|
||||
if (schema.getDiscriminator().getMapping() != null && !schema.getDiscriminator().getMapping().isEmpty()) {
|
||||
for (Entry<String, String> e : schema.getDiscriminator().getMapping().entrySet()) {
|
||||
String name = ModelUtils.getSimpleRef(e.getValue());
|
||||
String name = toModelName(ModelUtils.getSimpleRef(e.getValue())); // e.g e.getValue => #/components/schemas/Dog
|
||||
if (allDefinitions.get(name) == null) {
|
||||
LOGGER.warn("Discriminator's mapping: model {} (mapped to {}) couldn't be found", name, e.getKey());
|
||||
}
|
||||
discriminator.getMappedModels().add(new MappedModel(e.getKey(), name));
|
||||
}
|
||||
} else {
|
||||
@@ -1788,7 +1834,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
if (name == null || name.length() == 0) {
|
||||
return name;
|
||||
}
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(toVarName(name));
|
||||
return camelize(toVarName(name));
|
||||
}
|
||||
|
||||
|
||||
@@ -1812,7 +1858,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
|
||||
property.name = toVarName(name);
|
||||
property.baseName = name;
|
||||
property.nameInCamelCase = org.openapitools.codegen.utils.StringUtils.camelize(property.name, false);
|
||||
property.nameInCamelCase = camelize(property.name, false);
|
||||
property.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, property.nameInCamelCase);
|
||||
property.description = escapeText(p.getDescription());
|
||||
property.unescapedDescription = p.getDescription();
|
||||
@@ -2231,7 +2277,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* Override with any special handling of response codes
|
||||
*
|
||||
* @param responses OAS Operation's responses
|
||||
* @return default method response or <tt>null</tt> if not found
|
||||
* @return default method response or <code>null</code> if not found
|
||||
*/
|
||||
protected ApiResponse findMethodResponse(ApiResponses responses) {
|
||||
String code = null;
|
||||
@@ -3309,8 +3355,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
co.operationId = uniqueName;
|
||||
co.operationIdLowerCase = uniqueName.toLowerCase(Locale.ROOT);
|
||||
co.operationIdCamelCase = org.openapitools.codegen.utils.StringUtils.camelize(uniqueName);
|
||||
co.operationIdSnakeCase = org.openapitools.codegen.utils.StringUtils.underscore(uniqueName);
|
||||
co.operationIdCamelCase = camelize(uniqueName);
|
||||
co.operationIdSnakeCase = underscore(uniqueName);
|
||||
opList.add(co);
|
||||
co.baseName = tag;
|
||||
}
|
||||
@@ -3332,35 +3378,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Underscore the given word.
|
||||
* Copied from Twitter elephant bird
|
||||
* https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/util/Strings.java
|
||||
*
|
||||
* @param word The word
|
||||
* @return The underscored version of the word
|
||||
* @see org.openapitools.codegen.utils.StringUtils#underscore
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public static String underscore(String word) {
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(word);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashize the given word.
|
||||
*
|
||||
* @param word The word
|
||||
* @return The dashized version of the word, e.g. "my-name"
|
||||
* @see org.openapitools.codegen.utils.StringUtils#dashize
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
@Deprecated
|
||||
protected String dashize(String word) {
|
||||
return org.openapitools.codegen.utils.StringUtils.dashize(word);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the next name for the given name, i.e. append "2" to the base name if not ending with a number,
|
||||
* otherwise increase the number by 1. For example:
|
||||
@@ -3560,37 +3577,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Camelize name (parameter, property, method, etc) with upper case for first letter
|
||||
* copied from Twitter elephant bird
|
||||
* https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/util/Strings.java
|
||||
*
|
||||
* @param word string to be camelize
|
||||
* @return camelized string
|
||||
* @see org.openapitools.codegen.utils.StringUtils#camelize(String)
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public static String camelize(String word) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(word);
|
||||
}
|
||||
|
||||
/**
|
||||
* Camelize name (parameter, property, method, etc)
|
||||
*
|
||||
* @param word string to be camelize
|
||||
* @param lowercaseFirstLetter lower case for first letter if set to true
|
||||
* @return camelized string
|
||||
* @see org.openapitools.codegen.utils.StringUtils#camelize(String, boolean)
|
||||
* @deprecated since version 3.2.3, may be removed with the next major release (4.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public static String camelize(String word, boolean lowercaseFirstLetter) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(word, lowercaseFirstLetter);
|
||||
}
|
||||
|
||||
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String suffix = apiTemplateFiles().get(templateName);
|
||||
return apiFileFolder() + File.separator + toApiFilename(tag) + suffix;
|
||||
@@ -4147,19 +4133,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private List<Schema> getInterfaces(ComposedSchema composed) {
|
||||
List<Schema> interfaces;
|
||||
if (composed.getAllOf() != null && !composed.getAllOf().isEmpty()) {
|
||||
return composed.getAllOf();
|
||||
} else if (composed.getAnyOf() != null && !composed.getAnyOf().isEmpty()) {
|
||||
return composed.getAnyOf();
|
||||
} else if (composed.getOneOf() != null && !composed.getOneOf().isEmpty()) {
|
||||
return composed.getOneOf();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void addConsumesInfo(OpenAPI openAPI, Operation operation, CodegenOperation codegenOperation) {
|
||||
RequestBody requestBody = ModelUtils.getReferencedRequestBody(openAPI, operation.getRequestBody());
|
||||
if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) {
|
||||
@@ -4296,18 +4269,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return produces;
|
||||
}
|
||||
|
||||
protected String getParentName(ComposedSchema composedSchema, Map<String, Schema> allSchemas) {
|
||||
if (composedSchema.getAllOf() != null && !composedSchema.getAllOf().isEmpty()) {
|
||||
for (Schema schema : composedSchema.getAllOf()) {
|
||||
String ref = schema.get$ref();
|
||||
if (!StringUtils.isBlank(ref)) {
|
||||
return ModelUtils.getSimpleRef(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getCollectionFormat(Parameter parameter) {
|
||||
if (Parameter.StyleEnum.FORM.equals(parameter.getStyle())) {
|
||||
// Ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#style-values
|
||||
|
||||
@@ -34,7 +34,7 @@ public class GeneratorNotFoundException extends RuntimeException {
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
* by the {@link #getMessage()} method).
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* {@link #getCause()} method). (A <code>null</code> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
@@ -45,13 +45,13 @@ public class GeneratorNotFoundException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified cause and a
|
||||
* detail message of <tt>(cause==null ? null : cause.toString())</tt>
|
||||
* detail message of <code>(cause==null ? null : cause.toString())</code>
|
||||
* (which typically contains the class and detail message of
|
||||
* <tt>cause</tt>). This constructor is useful for runtime exceptions
|
||||
* <code>cause</code>). This constructor is useful for runtime exceptions
|
||||
* that are little more than wrappers for other throwables.
|
||||
*
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* {@link #getCause()} method). (A <code>null</code> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SpecValidationException extends RuntimeException {
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
* by the {@link #getMessage()} method).
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* {@link #getCause()} method). (A <code>null</code> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
@@ -47,13 +47,13 @@ public class SpecValidationException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified cause and a
|
||||
* detail message of <tt>(cause==null ? null : cause.toString())</tt>
|
||||
* detail message of <code>(cause==null ? null : cause.toString())</code>
|
||||
* (which typically contains the class and detail message of
|
||||
* <tt>cause</tt>). This constructor is useful for runtime exceptions
|
||||
* <code>cause</code>). This constructor is useful for runtime exceptions
|
||||
* that are little more than wrappers for other throwables.
|
||||
*
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* {@link #getCause()} method). (A <code>null</code> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
abstract public class AbstractAdaCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractAdaCodegen.class);
|
||||
@@ -666,7 +667,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
// method with only the scope that it requires. We have to create a new auth method
|
||||
// instance because the original object must not be modified.
|
||||
List<String> opScopes = (scopes == null) ? null : scopes.get(authMethod.name);
|
||||
authMethod.name = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(authMethod.name), true);
|
||||
authMethod.name = camelize(sanitizeName(authMethod.name), true);
|
||||
if (opScopes != null) {
|
||||
CodegenSecurity opSecurity = new CodegenSecurity();
|
||||
opSecurity.name = authMethod.name;
|
||||
|
||||
@@ -36,6 +36,8 @@ import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public abstract class AbstractApexCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractApexCodegen.class);
|
||||
|
||||
@@ -112,7 +114,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(name, true);
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@@ -159,7 +161,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
final String camelizedName = org.openapitools.codegen.utils.StringUtils.camelize(nameWithPrefixSuffix);
|
||||
final String camelizedName = camelize(nameWithPrefixSuffix);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(camelizedName)) {
|
||||
@@ -422,11 +424,11 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
@@ -515,7 +517,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum";
|
||||
return sanitizeName(camelize(property.name)) + "Enum";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -669,7 +671,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String sanitizeTag(String tag) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(tag));
|
||||
return camelize(sanitizeName(tag));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public abstract class AbstractCSharpCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@@ -206,8 +207,12 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
public void useDateTimeOffset(boolean flag) {
|
||||
this.useDateTimeOffsetFlag = flag;
|
||||
if (flag) typeMapping.put("datetime", "DateTimeOffset?");
|
||||
else typeMapping.put("datetime", "DateTime?");
|
||||
if (flag) {
|
||||
typeMapping.put("DateTime", "DateTimeOffset?");
|
||||
}
|
||||
else {
|
||||
typeMapping.put("DateTime", "DateTime?");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -568,6 +573,32 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
}
|
||||
}
|
||||
|
||||
for (CodegenParameter parameter: operation.allParams) {
|
||||
CodegenModel model = null;
|
||||
for(Object modelHashMap: allModels) {
|
||||
CodegenModel codegenModel = ((HashMap<String, CodegenModel>) modelHashMap).get("model");
|
||||
if (codegenModel.getClassname().equals(parameter.dataType)) {
|
||||
model = codegenModel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (model == null) {
|
||||
// Primitive data types all come already marked
|
||||
parameter.isNullable = true;
|
||||
} else {
|
||||
// Effectively mark enum models as enums and non-nullable
|
||||
if (model.isEnum) {
|
||||
parameter.isEnum = true;
|
||||
parameter.allowableValues = model.allowableValues;
|
||||
parameter.isPrimitiveType = true;
|
||||
parameter.isNullable = false;
|
||||
} else {
|
||||
parameter.isNullable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processOperation(operation);
|
||||
}
|
||||
}
|
||||
@@ -605,17 +636,17 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId)));
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId)));
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId));
|
||||
return camelize(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -630,7 +661,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
// camelize the variable name
|
||||
// pet_id => PetId
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(name);
|
||||
name = camelize(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@@ -653,9 +684,9 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
return name;
|
||||
}
|
||||
|
||||
// org.openapitools.codegen.utils.StringUtils.camelize(lower) the variable name
|
||||
// camelize(lower) the variable name
|
||||
// pet_id => petId
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(name, true);
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@@ -840,19 +871,19 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name));
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name));
|
||||
name = "model_" + name; // e.g. return => ModelReturn (after camelize)
|
||||
}
|
||||
|
||||
// model name starts with number
|
||||
if (name.matches("^\\d.*")) {
|
||||
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name));
|
||||
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name));
|
||||
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name);
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -940,7 +971,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
// for symbol, e.g. $, #
|
||||
if (getSymbolName(name) != null) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(getSymbolName(name));
|
||||
return camelize(getSymbolName(name));
|
||||
}
|
||||
|
||||
String enumName = sanitizeName(name);
|
||||
@@ -948,7 +979,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
enumName = enumName.replaceFirst("_$", "");
|
||||
|
||||
enumName = org.openapitools.codegen.utils.StringUtils.camelize(enumName) + "Enum";
|
||||
enumName = camelize(enumName) + "Enum";
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
@@ -959,7 +990,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum";
|
||||
return sanitizeName(camelize(property.name)) + "Enum";
|
||||
}
|
||||
|
||||
public String testPackageName() {
|
||||
|
||||
@@ -49,6 +49,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public abstract class AbstractEiffelCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractEiffelCodegen.class);
|
||||
@@ -206,7 +208,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
// (after camelize)
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
return underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,7 +219,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
// methods parameters as 'final'.
|
||||
|
||||
// e.g. PetApi.go => pet_api.go
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(name) + "_api";
|
||||
return underscore(name) + "_api";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -335,7 +337,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(sanitizedOperationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to "
|
||||
+ org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId));
|
||||
+ camelize("call_" + operationId));
|
||||
sanitizedOperationId = "call_" + sanitizedOperationId;
|
||||
}
|
||||
// method name from updateSomething to update_Something.
|
||||
@@ -353,7 +355,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
for (CodegenOperation operation : operations) {
|
||||
// http method verb conversion (e.g. PUT => Put)
|
||||
|
||||
operation.httpMethod = org.openapitools.codegen.utils.StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT));
|
||||
operation.httpMethod = camelize(operation.httpMethod.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
// remove model imports to avoid error
|
||||
|
||||
@@ -30,6 +30,9 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public abstract class AbstractGoCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGoCodegen.class);
|
||||
@@ -147,7 +150,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
if (this.reservedWordsMappings().containsKey(name)) {
|
||||
return this.reservedWordsMappings().get(name);
|
||||
}
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name) + '_';
|
||||
return camelize(name) + '_';
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,7 +165,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => PetId
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(name);
|
||||
name = camelize(name);
|
||||
|
||||
// for reserved word append _
|
||||
if (isReservedWord(name)) {
|
||||
@@ -187,7 +190,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
// params should be lowerCamelCase. E.g. "person Person", instead of
|
||||
// "Person Person".
|
||||
//
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(toVarName(name), true);
|
||||
name = camelize(toVarName(name), true);
|
||||
|
||||
// REVISIT: Actually, for idiomatic go, the param name should
|
||||
// really should just be a letter, e.g. "p Person"), but we'll get
|
||||
@@ -204,7 +207,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
public String toModelName(String name) {
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(toModel(name));
|
||||
return camelize(toModel(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -241,7 +244,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
return underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,7 +253,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// e.g. PetApi.go => pet_api.go
|
||||
name = "api_" + org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
name = "api_" + underscore(name);
|
||||
if (name.endsWith("_test")) {
|
||||
LOGGER.warn(name + ".go with `_test.go` suffix (reserved word) cannot be used as filename. Renamed to " + name + "_.go");
|
||||
name += "_";
|
||||
@@ -321,17 +324,17 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(sanitizedOperationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to "
|
||||
+ org.openapitools.codegen.utils.StringUtils.camelize("call_" + sanitizedOperationId));
|
||||
+ camelize("call_" + sanitizedOperationId));
|
||||
sanitizedOperationId = "call_" + sanitizedOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (sanitizedOperationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("call_" + sanitizedOperationId));
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize("call_" + sanitizedOperationId));
|
||||
sanitizedOperationId = "call_" + sanitizedOperationId;
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(sanitizedOperationId);
|
||||
return camelize(sanitizedOperationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -342,7 +345,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
for (CodegenOperation operation : operations) {
|
||||
// http method verb conversion (e.g. PUT => Put)
|
||||
operation.httpMethod = org.openapitools.codegen.utils.StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT));
|
||||
operation.httpMethod = camelize(operation.httpMethod.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
// remove model imports to avoid error
|
||||
@@ -573,7 +576,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
}
|
||||
|
||||
// string
|
||||
String enumName = sanitizeName(org.openapitools.codegen.utils.StringUtils.underscore(name).toUpperCase(Locale.ROOT));
|
||||
String enumName = sanitizeName(underscore(name).toUpperCase(Locale.ROOT));
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
enumName = enumName.replaceFirst("_$", "");
|
||||
|
||||
@@ -588,7 +591,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String enumName = org.openapitools.codegen.utils.StringUtils.underscore(toModelName(property.name)).toUpperCase(Locale.ROOT);
|
||||
String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT);
|
||||
|
||||
// remove [] for array or map of enum
|
||||
enumName = enumName.replace("[]", "");
|
||||
|
||||
@@ -0,0 +1,466 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public abstract class AbstractGraphQLCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGraphQLCodegen.class);
|
||||
|
||||
protected String specFolder = "spec";
|
||||
protected String packageName = "openapi2graphql";
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
|
||||
protected String graphQlInputsPackage = "";
|
||||
|
||||
public AbstractGraphQLCodegen() {
|
||||
super();
|
||||
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// data type
|
||||
"null", "Int", "Float", "String", "Boolean", "ID",
|
||||
|
||||
// reserved words: TODO
|
||||
"type", "implements", "query", "union", "interface"
|
||||
)
|
||||
);
|
||||
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"map",
|
||||
"array")
|
||||
);
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"null",
|
||||
"ID",
|
||||
"Int",
|
||||
"String",
|
||||
"Float",
|
||||
"Boolean")
|
||||
);
|
||||
|
||||
instantiationTypes.clear();
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("long", "Int");
|
||||
typeMapping.put("number", "Float");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("double", "Float");
|
||||
typeMapping.put("boolean", "Boolean");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("UUID", "ID");
|
||||
typeMapping.put("date", "String");
|
||||
typeMapping.put("DateTime", "String");
|
||||
typeMapping.put("password", "String");
|
||||
// TODO fix mapping
|
||||
typeMapping.put("file", "String");
|
||||
typeMapping.put("binary", "String");
|
||||
typeMapping.put("ByteArray", "String");
|
||||
typeMapping.put("object", "TODO_OBJECT_MAPPING");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
|
||||
setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
|
||||
}
|
||||
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public void setPackageVersion(String packageVersion) {
|
||||
this.packageVersion = packageVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
// Can't start with an underscore, as our fields need to start with an
|
||||
|
||||
// Options?
|
||||
// - MyName
|
||||
// - AName
|
||||
// - TheName
|
||||
// - XName
|
||||
// - X_Name
|
||||
// ... or maybe a suffix?
|
||||
// - Name_ ... think this will work.
|
||||
if (this.reservedWordsMappings().containsKey(name)) {
|
||||
return this.reservedWordsMappings().get(name);
|
||||
}
|
||||
return camelize(name) + '_';
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + packageName + File.separator + "api" + File.separator;
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + packageName + File.separator + "model" + File.separator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = sanitizeName(name.replaceAll("-", "_"));
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$"))
|
||||
return name;
|
||||
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name))
|
||||
name = escapeReservedWord(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (name.matches("^\\d.*"))
|
||||
name = camelize("var_" + name);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
return camelize(toModelFilename(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
name = modelNamePrefix + "_" + name;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
name = name + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
name = sanitizeName(name);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + ("model_" + name));
|
||||
name = "model_" + name; // e.g. return => ModelReturn (after camelize)
|
||||
}
|
||||
|
||||
// model name starts with number
|
||||
if (name.matches("^\\d.*")) {
|
||||
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + ("model_" + name));
|
||||
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
|
||||
}
|
||||
|
||||
return underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// e.g. PetApi.graphql => pet_api.graphql
|
||||
return underscore(name) + "_api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiTestFilename(String name) {
|
||||
return toApiFilename(name) + "_spec";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelTestFilename(String name) {
|
||||
return toModelFilename(name) + "_spec";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return outputFolder + File.separator + specFolder.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return outputFolder + File.separator + specFolder.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
return (outputFolder + "/" + apiDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelDocFilename(String name) {
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiDocFilename(String name) {
|
||||
return toApiName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
return underscore(super.toApiName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
return getTypeDeclaration(inner);
|
||||
}
|
||||
|
||||
// Not using the supertype invocation, because we want to UpperCamelize
|
||||
// the type.
|
||||
String schemaType = getSchemaType(p);
|
||||
String nullable = ModelUtils.isNullable(p) ? "" : "!";
|
||||
/*
|
||||
if (p != null && Boolean.TRUE.equals(p.getNullable())) {
|
||||
nullable = "";
|
||||
} else {
|
||||
nullable = "!";
|
||||
}*/
|
||||
|
||||
if (typeMapping.containsKey(schemaType)) {
|
||||
return typeMapping.get(schemaType) + nullable;
|
||||
}
|
||||
|
||||
if (languageSpecificPrimitives.contains(schemaType)) {
|
||||
return schemaType + nullable;
|
||||
}
|
||||
|
||||
return toModelName(schemaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchemaType(Schema p) {
|
||||
String schemaType = super.getSchemaType(p);
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(schemaType)) {
|
||||
type = typeMapping.get(schemaType);
|
||||
if (languageSpecificPrimitives.contains(type))
|
||||
return (type);
|
||||
} else {
|
||||
type = schemaType;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
String sanitizedOperationId = sanitizeName(operationId);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(sanitizedOperationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore("call_" + operationId));
|
||||
sanitizedOperationId = "call_" + sanitizedOperationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizedOperationId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needToImport(String type) {
|
||||
return !defaultIncludes.contains(type)
|
||||
&& !languageSpecificPrimitives.contains(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("]]", "] ]");
|
||||
}
|
||||
|
||||
public Map<String, String> createMapping(String key, String value) {
|
||||
Map<String, String> customImport = new HashMap<String, String>();
|
||||
customImport.put(key, value);
|
||||
|
||||
return customImport;
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (name.length() == 0) {
|
||||
return "EMPTY";
|
||||
}
|
||||
|
||||
// number
|
||||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||
String varName = name;
|
||||
varName = varName.replaceAll("-", "MINUS_");
|
||||
varName = varName.replaceAll("\\+", "PLUS_");
|
||||
varName = varName.replaceAll("\\.", "_DOT_");
|
||||
return varName;
|
||||
}
|
||||
|
||||
// for symbol, e.g. $, #
|
||||
if (getSymbolName(name) != null) {
|
||||
return getSymbolName(name).toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
// string
|
||||
String enumName = sanitizeName(underscore(name).toUpperCase(Locale.ROOT));
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
enumName = enumName.replaceFirst("_$", "");
|
||||
|
||||
if (isReservedWord(enumName) || enumName.matches("\\d.*")) { // reserved word or starts with number
|
||||
return escapeReservedWord(enumName);
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String enumName = toModelName(property.name);
|
||||
|
||||
// remove [] for array or map of enum
|
||||
enumName = enumName.replace("[]", "");
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
return enumName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if (needToImport(toModelName(name))) {
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> operations) {
|
||||
Map<String, Object> objs = (Map<String, Object>) operations.get("operations");
|
||||
|
||||
for (CodegenOperation op : (List<CodegenOperation>) objs.get("operation")) {
|
||||
// non GET/HEAD methods are mutation
|
||||
if (!"GET".equals(op.httpMethod.toUpperCase(Locale.ROOT)) && !"HEAD".equals(op.httpMethod.toUpperCase(Locale.ROOT))) {
|
||||
op.vendorExtensions.put("x-is-mutation", Boolean.TRUE);
|
||||
}
|
||||
for (CodegenParameter p : op.allParams) {
|
||||
// TODO check and adjust!
|
||||
// {{#vendorExtensions.x-graphql-nullable}}?{{/vendorExtensions.x-graphql-nullable}}
|
||||
if (p.required) {
|
||||
op.vendorExtensions.put("x-graphql-nullable", Boolean.FALSE);
|
||||
} else {
|
||||
op.vendorExtensions.put("x-graphql-nullable", Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
public String graphQlInputsPackage() {
|
||||
return graphQlInputsPackage;
|
||||
}
|
||||
|
||||
public String graphQlInputsFileFolder() {
|
||||
return outputFolder + File.separator + graphQlInputsPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String graphQlInputsFilename(String templateName, String tag) {
|
||||
String suffix = apiTemplateFiles().get(templateName);
|
||||
return graphQlInputsFileFolder() + File.separator + tographQlInputsFilename(tag) + suffix;
|
||||
}
|
||||
|
||||
public String tographQlInputsFilename(String name) {
|
||||
return tographQlInputsName(name);
|
||||
}
|
||||
|
||||
public String tographQlInputsName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "EmptyInput";
|
||||
}
|
||||
|
||||
return camelize(name) + "Input";
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,8 @@ import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.escape;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public abstract class AbstractJavaCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@@ -584,7 +585,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api";
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -624,7 +625,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(name, true);
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@@ -676,7 +677,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
final String camelizedName = org.openapitools.codegen.utils.StringUtils.camelize(nameWithPrefixSuffix);
|
||||
final String camelizedName = camelize(nameWithPrefixSuffix);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(camelizedName)) {
|
||||
@@ -919,19 +920,19 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId), true);
|
||||
operationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
|
||||
operationId = camelize("call_" + operationId, true);
|
||||
}
|
||||
|
||||
return operationId;
|
||||
@@ -1082,7 +1083,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum";
|
||||
return sanitizeName(camelize(property.name)) + "Enum";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1378,7 +1379,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String sanitizeTag(String tag) {
|
||||
tag = org.openapitools.codegen.utils.StringUtils.camelize(org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(tag)));
|
||||
tag = camelize(underscore(sanitizeName(tag)));
|
||||
|
||||
// tag starts with numbers
|
||||
if (tag.matches("^\\d.*")) {
|
||||
|
||||
@@ -40,6 +40,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen implements BeanValidationFeatures {
|
||||
public static final String SERVER_PORT = "serverPort";
|
||||
@@ -251,7 +252,7 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
|
||||
return "DefaultApi";
|
||||
}
|
||||
computed = sanitizeName(computed);
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(computed) + "Api";
|
||||
return camelize(computed) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,6 +32,9 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.escape;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public abstract class AbstractKotlinCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractKotlinCodegen.class);
|
||||
@@ -431,16 +434,16 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
break;
|
||||
case camelCase:
|
||||
// NOTE: Removes hyphens and underscores
|
||||
modified = org.openapitools.codegen.utils.StringUtils.camelize(modified, true);
|
||||
modified = camelize(modified, true);
|
||||
break;
|
||||
case PascalCase:
|
||||
// NOTE: Removes hyphens and underscores
|
||||
String result = org.openapitools.codegen.utils.StringUtils.camelize(modified);
|
||||
String result = camelize(modified);
|
||||
modified = titleCase(result);
|
||||
break;
|
||||
case snake_case:
|
||||
// NOTE: Removes hyphens
|
||||
modified = org.openapitools.codegen.utils.StringUtils.underscore(modified);
|
||||
modified = underscore(modified);
|
||||
break;
|
||||
case UPPERCASE:
|
||||
modified = modified.toUpperCase(Locale.ROOT);
|
||||
@@ -502,7 +505,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
modifiedName = sanitizeKotlinSpecificNames(modifiedName);
|
||||
|
||||
// Camelize name of nested properties
|
||||
modifiedName = org.openapitools.codegen.utils.StringUtils.camelize(modifiedName);
|
||||
modifiedName = camelize(modifiedName);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(modifiedName)) {
|
||||
@@ -687,7 +690,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
List<String> allowedCharacters = new ArrayList<>();
|
||||
allowedCharacters.add("_");
|
||||
allowedCharacters.add("$");
|
||||
name = escapeSpecialCharacters(name, allowedCharacters, "_");
|
||||
name = escape(name, specialCharReplacements, allowedCharacters, "_");
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
|
||||
@@ -41,6 +41,13 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public abstract class AbstractPhpCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPhpCodegen.class);
|
||||
@@ -425,11 +432,11 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
if ("camelCase".equals(variableNamingConvention)) {
|
||||
// return the name in camelCase style
|
||||
// phone_number => phoneNumber
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(name, true);
|
||||
name = camelize(name, true);
|
||||
} else { // default to snake case
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
name = org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
name = underscore(name);
|
||||
}
|
||||
|
||||
// parameter name starting with number won't compile
|
||||
@@ -460,13 +467,13 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
// model name cannot use reserved keyword
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name));
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name));
|
||||
name = "model_" + name; // e.g. return => ModelReturn (after camelize)
|
||||
}
|
||||
|
||||
// model name starts with number
|
||||
if (name.matches("^\\d.*")) {
|
||||
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name));
|
||||
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name));
|
||||
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
|
||||
}
|
||||
|
||||
@@ -483,7 +490,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name);
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -505,7 +512,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
* @return capitalized model name
|
||||
*/
|
||||
public String toInterfaceName(final String name) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(interfaceNamePrefix + name + interfaceNameSuffix);
|
||||
return camelize(interfaceNamePrefix + name + interfaceNameSuffix);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -515,7 +522,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
* @return capitalized abstract class name
|
||||
*/
|
||||
public String toAbstractName(final String name) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(abstractNamePrefix + name + abstractNameSuffix);
|
||||
return camelize(abstractNamePrefix + name + abstractNameSuffix);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -525,7 +532,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
* @return capitalized trait name
|
||||
*/
|
||||
public String toTraitName(final String name) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(traitNamePrefix + name + traitNameSuffix);
|
||||
return camelize(traitNamePrefix + name + traitNameSuffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -537,17 +544,17 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true));
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true));
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true);
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -685,7 +692,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
}
|
||||
|
||||
// string
|
||||
String enumName = sanitizeName(org.openapitools.codegen.utils.StringUtils.underscore(name).toUpperCase(Locale.ROOT));
|
||||
String enumName = sanitizeName(underscore(name).toUpperCase(Locale.ROOT));
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
enumName = enumName.replaceFirst("_$", "");
|
||||
|
||||
@@ -698,7 +705,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String enumName = org.openapitools.codegen.utils.StringUtils.underscore(toModelName(property.name)).toUpperCase(Locale.ROOT);
|
||||
String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT);
|
||||
|
||||
// remove [] for array or map of enum
|
||||
enumName = enumName.replace("[]", "");
|
||||
@@ -723,7 +730,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
for (CodegenOperation op : operationList) {
|
||||
// for API test method name
|
||||
// e.g. public function test{{vendorExtensions.x-testOperationId}}()
|
||||
op.vendorExtensions.put("x-testOperationId", org.openapitools.codegen.utils.StringUtils.camelize(op.operationId));
|
||||
op.vendorExtensions.put("x-testOperationId", camelize(op.operationId));
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRubyCodegen.class);
|
||||
@@ -136,7 +137,7 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// petId => pet_id
|
||||
name = org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
name = underscore(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@@ -160,12 +161,12 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = org.openapitools.codegen.utils.StringUtils.underscore("call_" + operationId);
|
||||
String newOperationId = underscore("call_" + operationId);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(operationId);
|
||||
return underscore(operationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractScalaCodegen.class);
|
||||
@@ -280,7 +281,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
}
|
||||
|
||||
protected String formatIdentifier(String name, boolean capitalized) {
|
||||
String identifier = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(name), true);
|
||||
String identifier = camelize(sanitizeName(name), true);
|
||||
if (capitalized) {
|
||||
identifier = StringUtils.capitalize(identifier);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTypeScriptClientCodegen.class);
|
||||
@@ -159,7 +161,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name, "\\W-[\\$]");
|
||||
name = sanitizeName(name, "[^\\w$]");
|
||||
|
||||
if ("_".equals(name)) {
|
||||
name = "_u";
|
||||
@@ -221,27 +223,27 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
String modelName = org.openapitools.codegen.utils.StringUtils.camelize("model_" + name);
|
||||
String modelName = camelize("model_" + name);
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
// model name starts with number
|
||||
if (name.matches("^\\d.*")) {
|
||||
String modelName = org.openapitools.codegen.utils.StringUtils.camelize("model_" + name); // e.g. 200Response => Model200Response (after camelize)
|
||||
String modelName = camelize("model_" + name); // e.g. 200Response => Model200Response (after camelize)
|
||||
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
if (languageSpecificPrimitives.contains(name)) {
|
||||
String modelName = org.openapitools.codegen.utils.StringUtils.camelize("model_" + name);
|
||||
String modelName = camelize("model_" + name);
|
||||
LOGGER.warn(name + " (model name matches existing language type) cannot be used as a model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name);
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -405,10 +407,10 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
// append _ at the beginning, e.g. _return
|
||||
if (isReservedWord(operationId)) {
|
||||
return escapeReservedWord(org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true));
|
||||
return escapeReservedWord(camelize(sanitizeName(operationId), true));
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true);
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
}
|
||||
|
||||
public void setModelPropertyNaming(String naming) {
|
||||
@@ -431,11 +433,11 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name, true);
|
||||
return camelize(name, true);
|
||||
case PascalCase:
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name);
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
return underscore(name);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid model property naming '" +
|
||||
name + "'. Must be 'original', 'camelCase', " +
|
||||
@@ -466,7 +468,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
|
||||
// for symbol, e.g. $, #
|
||||
if (getSymbolName(name) != null) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(getSymbolName(name));
|
||||
return camelize(getSymbolName(name));
|
||||
}
|
||||
|
||||
// number
|
||||
@@ -486,7 +488,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
|
||||
// camelize the enum variable name
|
||||
// ref: https://basarat.gitbooks.io/typescript/content/docs/enums.html
|
||||
enumName = org.openapitools.codegen.utils.StringUtils.camelize(enumName);
|
||||
enumName = camelize(enumName);
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AndroidClientCodegen.class);
|
||||
@@ -229,7 +230,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(name, true);
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@@ -258,7 +259,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(name));
|
||||
name = camelize(sanitizeName(name));
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
@@ -355,11 +356,11 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class ApexClientCodegen extends AbstractApexCodegen {
|
||||
|
||||
@@ -193,7 +194,7 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(classPrefix + super.toApiName(name));
|
||||
return camelize(classPrefix + super.toApiName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -35,10 +35,16 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CLibcurlClientCodegen.class);
|
||||
|
||||
public static final String PROJECT_NAME = "projectName";
|
||||
protected String moduleName;
|
||||
protected String projectName;
|
||||
protected static final String defaultProjectName = "openapi_client";
|
||||
protected String specFolder = "spec";
|
||||
protected String libFolder = "lib";
|
||||
protected String apiDocPath = "docs/";
|
||||
@@ -93,6 +99,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
"int",
|
||||
"long",
|
||||
"register",
|
||||
"remove",
|
||||
"restrict",
|
||||
"return",
|
||||
"short",
|
||||
@@ -135,6 +142,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
languageSpecificPrimitives.add("FILE");
|
||||
languageSpecificPrimitives.add("Object");
|
||||
languageSpecificPrimitives.add("list_t*");
|
||||
languageSpecificPrimitives.add("list");
|
||||
|
||||
typeMapping.put("string", "char");
|
||||
typeMapping.put("char", "char");
|
||||
@@ -200,8 +208,8 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
supportingFiles.add(new SupportingFile("list.h.mustache", "include", "list.h"));
|
||||
// external folder
|
||||
supportingFiles.add(new SupportingFile("cJSON.licence.mustache", "external", "cJSON.licence"));
|
||||
supportingFiles.add(new SupportingFile("cJSON.c.mustache", "external" + File.separator + "src", "cJSON.c"));
|
||||
supportingFiles.add(new SupportingFile("cJSON.h.mustache", "external" + File.separator + "include", "cJSON.h"));
|
||||
supportingFiles.add(new SupportingFile("cJSON.c.mustache", "external", "cJSON.c"));
|
||||
supportingFiles.add(new SupportingFile("cJSON.h.mustache", "external", "cJSON.h"));
|
||||
|
||||
}
|
||||
|
||||
@@ -500,7 +508,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
return "#include \"" + name + ".h\"";
|
||||
return "#include \"" +"../model/" + name + ".h\"";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -567,6 +575,21 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
p.example = example;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
if (openAPI.getInfo() != null) {
|
||||
Info info = openAPI.getInfo();
|
||||
setProjectName((escapeText(info.getTitle())));
|
||||
} else {
|
||||
setProjectName(defaultProjectName);
|
||||
}
|
||||
additionalProperties.put(PROJECT_NAME, projectName);
|
||||
}
|
||||
|
||||
public void setProjectName(String projectName) {
|
||||
this.projectName = underscore(projectName.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
// skip spec file as the file might have been updated with new test cases
|
||||
|
||||
@@ -42,6 +42,8 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
@SuppressWarnings({"hiding"})
|
||||
@@ -704,7 +706,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
// for symbol, e.g. $, #
|
||||
if (getSymbolName(value) != null) {
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(getSymbolName(value));
|
||||
return camelize(getSymbolName(value));
|
||||
}
|
||||
|
||||
// number
|
||||
@@ -720,7 +722,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
// string
|
||||
String var = value.replaceAll("_", " ");
|
||||
//var = WordUtils.capitalizeFully(var);
|
||||
var = org.openapitools.codegen.utils.StringUtils.camelize(var);
|
||||
var = camelize(var);
|
||||
var = var.replaceAll("\\W+", "");
|
||||
|
||||
if (var.matches("\\d.*")) {
|
||||
@@ -755,11 +757,11 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name, true);
|
||||
return camelize(name, true);
|
||||
case PascalCase:
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name);
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
return underscore(name);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid model property naming '" +
|
||||
name + "'. Must be 'original', 'camelCase', " +
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.openapitools.codegen.utils.URLPathUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@@ -72,6 +71,7 @@ import static org.openapitools.codegen.CodegenConstants.USE_COLLECTION_DESC;
|
||||
import static org.openapitools.codegen.CodegenConstants.USE_DATETIME_OFFSET;
|
||||
import static org.openapitools.codegen.CodegenConstants.USE_DATETIME_OFFSET_DESC;
|
||||
import static org.openapitools.codegen.CodegenType.SERVER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpNancyFXServerCodegen.class);
|
||||
@@ -335,7 +335,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
return "Empty";
|
||||
}
|
||||
|
||||
final String enumName = org.openapitools.codegen.utils.StringUtils.camelize(
|
||||
final String enumName = camelize(
|
||||
sanitizeName(name)
|
||||
.replaceFirst("^_", "")
|
||||
.replaceFirst("_$", "")
|
||||
@@ -402,7 +402,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@Override
|
||||
public String toEnumName(final CodegenProperty property) {
|
||||
return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum";
|
||||
return sanitizeName(camelize(property.name)) + "Enum";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,6 +43,9 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class CSharpRefactorClientCodegen extends AbstractCSharpCodegen {
|
||||
@SuppressWarnings({"hiding"})
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
|
||||
|
||||
@@ -17,24 +17,19 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import org.openapitools.codegen.*;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.oas.models.info.*;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.DefaultCodegen;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.dashize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final String PROJECT_NAME = "projectName";
|
||||
@@ -45,23 +40,29 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
private static final String PROJECT_LICENSE_URL = "projectLicenseUrl";
|
||||
private static final String BASE_NAMESPACE = "baseNamespace";
|
||||
|
||||
static final String X_BASE_SPEC = "x-baseSpec";
|
||||
static final String X_MODELS = "x-models";
|
||||
|
||||
protected String projectName;
|
||||
protected String projectDescription;
|
||||
protected String projectVersion;
|
||||
protected String baseNamespace;
|
||||
protected Set<String> baseSpecs;
|
||||
protected Set<String> models = new HashSet<>();
|
||||
|
||||
protected String sourceFolder = "src";
|
||||
|
||||
public ClojureClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code" + File.separator + "clojure";
|
||||
modelTemplateFiles.put("spec.mustache", ".clj");
|
||||
apiTemplateFiles.put("api.mustache", ".clj");
|
||||
embeddedTemplateDir = templateDir = "clojure";
|
||||
|
||||
cliOptions.add(new CliOption(PROJECT_NAME,
|
||||
"name of the project (Default: generated from info.title or \"openapi-clj-client\")"));
|
||||
cliOptions.add(new CliOption(PROJECT_DESCRIPTION,
|
||||
"description of the project (Default: using info.description or \"Client library of <projectNname>\")"));
|
||||
"description of the project (Default: using info.description or \"Client library of <projectName>\")"));
|
||||
cliOptions.add(new CliOption(PROJECT_VERSION,
|
||||
"version of the project (Default: using info.version or \"1.0.0\")"));
|
||||
cliOptions.add(new CliOption(PROJECT_URL,
|
||||
@@ -72,6 +73,49 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
"URL of the license the project uses (Default: using info.license.url or not included in project.clj)"));
|
||||
cliOptions.add(new CliOption(BASE_NAMESPACE,
|
||||
"the base/top namespace (Default: generated from projectName)"));
|
||||
|
||||
typeMapping.clear();
|
||||
|
||||
// We have specs for most of the types:
|
||||
typeMapping.put("integer", "int?");
|
||||
typeMapping.put("long", "int?");
|
||||
typeMapping.put("short", "int?");
|
||||
typeMapping.put("number", "float?");
|
||||
typeMapping.put("float", "float?");
|
||||
typeMapping.put("double", "float?");
|
||||
typeMapping.put("array", "list?");
|
||||
typeMapping.put("map", "map?");
|
||||
typeMapping.put("boolean", "boolean?");
|
||||
typeMapping.put("string", "string?");
|
||||
typeMapping.put("char", "char?");
|
||||
typeMapping.put("date", "inst?");
|
||||
typeMapping.put("DateTime", "inst?");
|
||||
typeMapping.put("UUID", "uuid?");
|
||||
|
||||
// But some type mappings are not really worth/meaningful to check for:
|
||||
typeMapping.put("object", "any?"); // Like, everything is an object.
|
||||
typeMapping.put("file", "any?"); // We don't really have specs for files,
|
||||
typeMapping.put("binary", "any?"); // nor binary.
|
||||
// And while there is a way to easily check if something is a bytearray,
|
||||
// (https://stackoverflow.com/questions/14796964/), it's not possible
|
||||
// to conform it yet, so we leave it as is.
|
||||
typeMapping.put("ByteArray", "any?");
|
||||
|
||||
// Set of base specs that don't need to be imported
|
||||
baseSpecs = new HashSet<>(
|
||||
Arrays.asList(
|
||||
"int?",
|
||||
"float?",
|
||||
"list?",
|
||||
"map?",
|
||||
"boolean?",
|
||||
"string?",
|
||||
"char?",
|
||||
"inst?",
|
||||
"uuid?",
|
||||
"any?"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,6 +133,69 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return "Generates a Clojure client library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (p instanceof ArraySchema) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
|
||||
return "(s/coll-of " + getTypeDeclaration(inner) + ")";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
|
||||
return "(s/map-of string? " + getTypeDeclaration(inner) + ")";
|
||||
}
|
||||
|
||||
// If it's a type we defined, we want to append the spec suffix
|
||||
if (!typeMapping.containsKey(super.getSchemaType(p))) {
|
||||
return super.getTypeDeclaration(p) + "-spec";
|
||||
} else {
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
|
||||
if (typeMapping.containsKey(openAPIType)) {
|
||||
return typeMapping.get(openAPIType);
|
||||
} else {
|
||||
return toModelName(openAPIType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
return dashize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Schema mod, Map<String, Schema> allDefinitions) {
|
||||
CodegenModel model = super.fromModel(name, mod, allDefinitions);
|
||||
|
||||
// If a var is a base spec we won't need to import it
|
||||
for (CodegenProperty var : model.vars) {
|
||||
if (baseSpecs.contains(var.complexType)) {
|
||||
var.vendorExtensions.put(X_BASE_SPEC, true);
|
||||
} else {
|
||||
var.vendorExtensions.put(X_BASE_SPEC, false);
|
||||
}
|
||||
if (var.items != null) {
|
||||
if (baseSpecs.contains(var.items.complexType)) {
|
||||
var.items.vendorExtensions.put(X_BASE_SPEC, true);
|
||||
} else {
|
||||
var.items.vendorExtensions.put(X_BASE_SPEC, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We also add all models to our model list so we can import them e.g. in operations
|
||||
models.add(model.classname);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
@@ -110,7 +217,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
Info info = openAPI.getInfo();
|
||||
if (projectName == null && info.getTitle() != null) {
|
||||
// when projectName is not specified, generate it from info.title
|
||||
projectName = org.openapitools.codegen.utils.StringUtils.dashize(info.getTitle());
|
||||
projectName = dashize(info.getTitle());
|
||||
}
|
||||
if (projectVersion == null) {
|
||||
// when projectVersion is not specified, use info.version
|
||||
@@ -149,15 +256,17 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
projectDescription = "Client library of " + projectName;
|
||||
}
|
||||
if (baseNamespace == null) {
|
||||
baseNamespace = org.openapitools.codegen.utils.StringUtils.dashize(projectName);
|
||||
baseNamespace = dashize(projectName);
|
||||
}
|
||||
apiPackage = baseNamespace + ".api";
|
||||
modelPackage = baseNamespace + ".specs";
|
||||
|
||||
additionalProperties.put(PROJECT_NAME, projectName);
|
||||
additionalProperties.put(PROJECT_DESCRIPTION, escapeText(projectDescription));
|
||||
additionalProperties.put(PROJECT_VERSION, projectVersion);
|
||||
additionalProperties.put(BASE_NAMESPACE, baseNamespace);
|
||||
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
|
||||
final String baseNamespaceFolder = sourceFolder + File.separator + namespaceToFolder(baseNamespace);
|
||||
supportingFiles.add(new SupportingFile("project.mustache", "", "project.clj"));
|
||||
@@ -176,6 +285,11 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + namespaceToFolder(apiPackage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + namespaceToFolder(modelPackage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
@@ -183,17 +297,22 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.dashize(sanitizeName(operationId));
|
||||
return dashize(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(toApiName(name));
|
||||
return underscore(toApiName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return underscore(toModelName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
return org.openapitools.codegen.utils.StringUtils.dashize(name);
|
||||
return dashize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -204,7 +323,6 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
name = name.replaceAll("[^a-zA-Z0-9_-]+", ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
name = org.openapitools.codegen.utils.StringUtils.dashize(name);
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -223,6 +341,9 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
for (CodegenOperation op : ops) {
|
||||
// Convert httpMethod to lower case, e.g. "get", "post"
|
||||
op.httpMethod = op.httpMethod.toLowerCase(Locale.ROOT);
|
||||
|
||||
op.vendorExtensions.put(X_MODELS, models);
|
||||
op.httpMethod = op.httpMethod.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
protected String implFolder = "impl";
|
||||
@@ -214,8 +215,8 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
String classname = (String) operations.get("classname");
|
||||
operations.put("classnameSnakeUpperCase", org.openapitools.codegen.utils.StringUtils.underscore(classname).toUpperCase(Locale.ROOT));
|
||||
operations.put("classnameSnakeLowerCase", org.openapitools.codegen.utils.StringUtils.underscore(classname).toLowerCase(Locale.ROOT));
|
||||
operations.put("classnameSnakeUpperCase", underscore(classname).toUpperCase(Locale.ROOT));
|
||||
operations.put("classnameSnakeLowerCase", underscore(classname).toLowerCase(Locale.ROOT));
|
||||
|
||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation op : operationList) {
|
||||
|
||||
@@ -0,0 +1,344 @@
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
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.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
|
||||
public class CppQt5AbstractCodegen extends AbstractCppCodegen implements CodegenConfig {
|
||||
|
||||
protected final String PREFIX = "OAI";
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected static final String CPP_NAMESPACE = "cppNamespace";
|
||||
protected static final String CPP_NAMESPACE_DESC = "C++ namespace (convention: name::space::for::api).";
|
||||
protected Set<String> foundationClasses = new HashSet<String>();
|
||||
protected String cppNamespace = "OpenAPI";
|
||||
protected Map<String, String> namespaces = new HashMap<String, String>();
|
||||
protected Set<String> systemIncludes = new HashSet<String>();
|
||||
|
||||
protected Set<String> nonFrameworkPrimitives = new HashSet<String>();
|
||||
|
||||
public CppQt5AbstractCodegen() {
|
||||
super();
|
||||
// set modelNamePrefix as default for QHttpEngine Server
|
||||
if (StringUtils.isEmpty(modelNamePrefix)) {
|
||||
modelNamePrefix = PREFIX;
|
||||
}
|
||||
// CLI options
|
||||
addOption(CPP_NAMESPACE, CPP_NAMESPACE_DESC, this.cppNamespace);
|
||||
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
additionalProperties().put("prefix", PREFIX);
|
||||
|
||||
// Write defaults namespace in properties so that it can be accessible in templates.
|
||||
// At this point command line has not been parsed so if value is given
|
||||
// in command line it will supersede this content
|
||||
additionalProperties.put("cppNamespace", cppNamespace);
|
||||
// CLI options
|
||||
addOption(CPP_NAMESPACE, CPP_NAMESPACE_DESC, this.cppNamespace);
|
||||
/*
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"bool",
|
||||
"qint32",
|
||||
"qint64",
|
||||
"float",
|
||||
"double")
|
||||
);
|
||||
nonFrameworkPrimitives.addAll(languageSpecificPrimitives);
|
||||
|
||||
foundationClasses.addAll(
|
||||
Arrays.asList(
|
||||
"QString",
|
||||
"QDate",
|
||||
"QDateTime",
|
||||
"QByteArray")
|
||||
);
|
||||
languageSpecificPrimitives.addAll(foundationClasses);
|
||||
super.typeMapping = new HashMap<String, String>();
|
||||
|
||||
typeMapping.put("date", "QDate");
|
||||
typeMapping.put("DateTime", "QDateTime");
|
||||
typeMapping.put("string", "QString");
|
||||
typeMapping.put("integer", "qint32");
|
||||
typeMapping.put("long", "qint64");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("array", "QList");
|
||||
typeMapping.put("map", "QMap");
|
||||
typeMapping.put("object", PREFIX + "Object");
|
||||
// mapped as "file" type for OAS 3.0
|
||||
typeMapping.put("ByteArray", "QByteArray");
|
||||
// UUID support - possible enhancement : use QUuid instead of QString.
|
||||
// beware though that Serialization/de-serialization of QUuid does not
|
||||
// come out of the box and will need to be sorted out (at least imply
|
||||
// modifications on multiple templates)
|
||||
typeMapping.put("UUID", "QString");
|
||||
typeMapping.put("file", "QIODevice");
|
||||
typeMapping.put("binary", "QIODevice");
|
||||
importMapping = new HashMap<String, String>();
|
||||
namespaces = new HashMap<String, String>();
|
||||
|
||||
systemIncludes.add("QString");
|
||||
systemIncludes.add("QList");
|
||||
systemIncludes.add("QMap");
|
||||
systemIncludes.add("QDate");
|
||||
systemIncludes.add("QDateTime");
|
||||
systemIncludes.add("QByteArray");
|
||||
systemIncludes.add("QIODevice");
|
||||
}
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("cppNamespace")) {
|
||||
cppNamespace = (String) additionalProperties.get("cppNamespace");
|
||||
}
|
||||
|
||||
additionalProperties.put("cppNamespaceDeclarations", cppNamespace.split("\\::"));
|
||||
if (additionalProperties.containsKey("modelNamePrefix")) {
|
||||
typeMapping.put("object", modelNamePrefix + "Object");
|
||||
additionalProperties().put("prefix", modelNamePrefix);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if( name.isEmpty() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (namespaces.containsKey(name)) {
|
||||
return "using " + namespaces.get(name) + ";";
|
||||
} else if (systemIncludes.contains(name)) {
|
||||
return "#include <" + name + ">";
|
||||
} else if(importMapping.containsKey(name)){
|
||||
return importMapping.get(name);
|
||||
}
|
||||
|
||||
String folder = modelPackage().replace("::", File.separator);
|
||||
if (!folder.isEmpty())
|
||||
folder += File.separator;
|
||||
|
||||
return "#include \"" + folder + name + ".h\"";
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||
* types. There is typically special handling for different property types
|
||||
*
|
||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
String openAPIType = getSchemaType(p);
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return getSchemaType(p) + "*";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return getSchemaType(p) + "*";
|
||||
}
|
||||
if (foundationClasses.contains(openAPIType)) {
|
||||
return openAPIType;
|
||||
} else if (languageSpecificPrimitives.contains(openAPIType)) {
|
||||
return toModelName(openAPIType);
|
||||
} else {
|
||||
return openAPIType;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
return "NULL";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return "NULL";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
||||
return "0.0f";
|
||||
}
|
||||
return "0.0";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
||||
return "0L";
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "QList<" + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
return "QString(\"\")";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
}
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return modelNamePrefix + sanitizeName(initialCaps(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - OpenAPI type conversion. This is used to map OpenAPI types in a `Schema` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(openAPIType)) {
|
||||
type = typeMapping.get(openAPIType);
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
return toModelName(type);
|
||||
}
|
||||
if (foundationClasses.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
type = openAPIType;
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
String varName = name;
|
||||
varName = sanitizeName(name);
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (varName.matches("^[A-Z_]*$")) {
|
||||
varName = varName.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// petId => pet_id
|
||||
varName = org.openapitools.codegen.utils.StringUtils.underscore(varName);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(varName) || varName.matches("^\\d.*")) {
|
||||
varName = escapeReservedWord(varName);
|
||||
}
|
||||
|
||||
return varName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(String str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needToImport(String type) {
|
||||
return StringUtils.isNotBlank(type) && !defaultIncludes.contains(type)
|
||||
&& !nonFrameworkPrimitives.contains(type);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||
for (CodegenOperation operation : operations) {
|
||||
// Check all return parameter baseType if there is a necessity to include, include it if not
|
||||
// already done
|
||||
if (operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
||||
if(!isIncluded(operation.returnBaseType, imports)) {
|
||||
imports.add(createMapping("import", operation.returnBaseType));
|
||||
}
|
||||
}
|
||||
List<CodegenParameter> params = new ArrayList<CodegenParameter>();
|
||||
if (operation.allParams != null)params.addAll(operation.allParams);
|
||||
|
||||
// Check all parameter baseType if there is a necessity to include, include it if not
|
||||
// already done
|
||||
for(CodegenParameter param : params) {
|
||||
if(param.isPrimitiveType && needToImport(param.baseType)) {
|
||||
if(!isIncluded(param.baseType, imports)) {
|
||||
imports.add(createMapping("import", param.baseType));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation.pathParams != null) {
|
||||
// We use QString to pass path params, add it to include
|
||||
if(!isIncluded("QString", imports)) {
|
||||
imports.add(createMapping("import", "QString"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isIncluded("QMap", imports)) {
|
||||
// Maps uses QString as key
|
||||
if(!isIncluded("QString", imports)) {
|
||||
imports.add(createMapping("import", "QString"));
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
private Map<String, String> createMapping(String key, String value) {
|
||||
Map<String, String> customImport = new HashMap<String, String>();
|
||||
customImport.put(key, toModelImport(value));
|
||||
return customImport;
|
||||
}
|
||||
|
||||
private boolean isIncluded(String type, List<Map<String, String>> imports) {
|
||||
boolean included = false;
|
||||
String inclStr = toModelImport(type);
|
||||
for (Map<String, String> importItem : imports) {
|
||||
if(importItem.containsValue(inclStr)) {
|
||||
included = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return included;
|
||||
}
|
||||
}
|
||||
@@ -17,19 +17,12 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -37,22 +30,12 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CppQt5ClientCodegen.class);
|
||||
|
||||
public static final String CPP_NAMESPACE = "cppNamespace";
|
||||
public static final String CPP_NAMESPACE_DESC = "C++ namespace (convention: name::space::for::api).";
|
||||
public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements CodegenConfig {
|
||||
public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate client.pri.";
|
||||
|
||||
protected final String PREFIX = "OAI";
|
||||
protected Set<String> foundationClasses = new HashSet<String>();
|
||||
// source folder where to write the files
|
||||
protected String sourceFolder = "client";
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected Map<String, String> namespaces = new HashMap<String, String>();
|
||||
protected Set<String> systemIncludes = new HashSet<String>();
|
||||
protected String cppNamespace = "OpenAPI";
|
||||
protected boolean optionalProjectFileFlag = true;
|
||||
|
||||
public CppQt5ClientCodegen() {
|
||||
@@ -61,11 +44,6 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/qt5cpp";
|
||||
|
||||
// set modelNamePrefix as default for QT5CPP
|
||||
if (StringUtils.isEmpty(modelNamePrefix)) {
|
||||
modelNamePrefix = PREFIX;
|
||||
}
|
||||
|
||||
/*
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
@@ -99,106 +77,35 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
*/
|
||||
embeddedTemplateDir = templateDir = "cpp-qt5-client";
|
||||
|
||||
// CLI options
|
||||
addOption(CPP_NAMESPACE, CPP_NAMESPACE_DESC, this.cppNamespace);
|
||||
addSwitch(CodegenConstants.OPTIONAL_PROJECT_FILE, OPTIONAL_PROJECT_FILE_DESC, this.optionalProjectFileFlag);
|
||||
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
additionalProperties().put("prefix", PREFIX);
|
||||
|
||||
// Write defaults namespace in properties so that it can be accessible in templates.
|
||||
// At this point command line has not been parsed so if value is given
|
||||
// in command line it will superseed this content
|
||||
additionalProperties.put("cppNamespace", cppNamespace);
|
||||
|
||||
/*
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"bool",
|
||||
"qint32",
|
||||
"qint64",
|
||||
"float",
|
||||
"double")
|
||||
);
|
||||
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder, PREFIX + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder, PREFIX + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, PREFIX + "HttpRequest.h"));
|
||||
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, PREFIX + "HttpRequest.cpp"));
|
||||
supportingFiles.add(new SupportingFile("modelFactory.mustache", sourceFolder, PREFIX + "ModelFactory.h"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, PREFIX + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("QObjectWrapper.h.mustache", sourceFolder, PREFIX + "QObjectWrapper.h"));
|
||||
if (optionalProjectFileFlag) {
|
||||
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri"));
|
||||
}
|
||||
|
||||
super.typeMapping = new HashMap<String, String>();
|
||||
|
||||
typeMapping.put("date", "QDate");
|
||||
typeMapping.put("DateTime", "QDateTime");
|
||||
typeMapping.put("string", "QString");
|
||||
typeMapping.put("integer", "qint32");
|
||||
typeMapping.put("long", "qint64");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("array", "QList");
|
||||
typeMapping.put("map", "QMap");
|
||||
typeMapping.put("file", "OAIHttpRequestInputFileElement");
|
||||
typeMapping.put("object", PREFIX + "Object");
|
||||
// mapped as "file" type for OAS 3.0
|
||||
typeMapping.put("binary", "OAIHttpRequestInputFileElement");
|
||||
typeMapping.put("ByteArray", "QByteArray");
|
||||
// UUID support - possible enhancement : use QUuid instead of QString.
|
||||
// beware though that Serialisation/deserialisation of QUuid does not
|
||||
// come out of the box and will need to be sorted out (at least imply
|
||||
// modifications on multiple templates)
|
||||
typeMapping.put("UUID", "QString");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
|
||||
importMapping.put("OAIHttpRequestInputFileElement", "#include \"" + PREFIX + "HttpRequest.h\"");
|
||||
|
||||
namespaces = new HashMap<String, String>();
|
||||
|
||||
foundationClasses.add("QString");
|
||||
|
||||
systemIncludes.add("QString");
|
||||
systemIncludes.add("QList");
|
||||
systemIncludes.add("QMap");
|
||||
systemIncludes.add("QDate");
|
||||
systemIncludes.add("QDateTime");
|
||||
systemIncludes.add("QByteArray");
|
||||
typeMapping.put("file", PREFIX + "HttpRequestInputFileElement");
|
||||
typeMapping.put("binary", PREFIX +"HttpRequestInputFileElement");
|
||||
importMapping.put(PREFIX + "HttpRequestInputFileElement", "#include \"" + PREFIX + "HttpRequest.h\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("cppNamespace")) {
|
||||
cppNamespace = (String) additionalProperties.get("cppNamespace");
|
||||
}
|
||||
|
||||
additionalProperties.put("cppNamespaceDeclarations", cppNamespace.split("\\::"));
|
||||
if (additionalProperties.containsKey("modelNamePrefix")) {
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder, modelNamePrefix + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder, modelNamePrefix + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, modelNamePrefix + "HttpRequest.h"));
|
||||
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, modelNamePrefix + "HttpRequest.cpp"));
|
||||
supportingFiles.add(new SupportingFile("modelFactory.mustache", sourceFolder, modelNamePrefix + "ModelFactory.h"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("QObjectWrapper.h.mustache", sourceFolder, modelNamePrefix + "QObjectWrapper.h"));
|
||||
|
||||
typeMapping.put("object", modelNamePrefix + "Object");
|
||||
typeMapping.put("file", modelNamePrefix + "HttpRequestInputFileElement");
|
||||
importMapping.put("SWGHttpRequestInputFileElement", "#include \"" + modelNamePrefix + "HttpRequest.h\"");
|
||||
additionalProperties().put("prefix", modelNamePrefix);
|
||||
typeMapping.put("binary", modelNamePrefix + "HttpRequestInputFileElement");
|
||||
importMapping.put(modelNamePrefix + "HttpRequestInputFileElement", "#include \"" + modelNamePrefix + "HttpRequest.h\"");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_FILE)) {
|
||||
@@ -227,7 +134,7 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "cpp-qt5";
|
||||
return "cpp-qt5-client";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,21 +148,6 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
return "Generates a Qt5 C++ client library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if (namespaces.containsKey(name)) {
|
||||
return "using " + namespaces.get(name) + ";";
|
||||
} else if (systemIncludes.contains(name)) {
|
||||
return "#include <" + name + ">";
|
||||
}
|
||||
|
||||
String folder = modelPackage().replace("::", File.separator);
|
||||
if (!folder.isEmpty())
|
||||
folder += File.separator;
|
||||
|
||||
return "#include \"" + folder + sanitizeName(name) + ".h\"";
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
@@ -274,134 +166,12 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace("::", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return sanitizeName(initialCaps(toModelName(name)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return modelNamePrefix + sanitizeName(initialCaps(name)) + "Api";
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||
* types. There is typically special handling for different property types
|
||||
*
|
||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
String openAPIType = getSchemaType(p);
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">*";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">*";
|
||||
}
|
||||
if (foundationClasses.contains(openAPIType)) {
|
||||
return openAPIType + "*";
|
||||
} else if (languageSpecificPrimitives.contains(openAPIType)) {
|
||||
return toModelName(openAPIType);
|
||||
} else {
|
||||
return openAPIType + "*";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
return "NULL";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return "NULL";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
||||
return "0.0f";
|
||||
}
|
||||
return "0.0";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
||||
return "0L";
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "new QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "new QList<" + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
return "new QString(\"\")";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
}
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - OpenAPI type conversion. This is used to map OpenAPI types in a `Schema` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
*/
|
||||
@Override
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(openAPIType)) {
|
||||
type = typeMapping.get(openAPIType);
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
return toModelName(type);
|
||||
}
|
||||
if (foundationClasses.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
type = openAPIType;
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
String varName = sanitizeName(name);
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (varName.matches("^[A-Z_]*$")) {
|
||||
varName = varName.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// petId => pet_id
|
||||
varName = org.openapitools.codegen.utils.StringUtils.underscore(varName);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(varName) || varName.matches("^\\d.*")) {
|
||||
varName = escapeReservedWord(varName);
|
||||
}
|
||||
|
||||
return varName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
public void setOptionalProjectFileFlag(boolean flag) {
|
||||
this.optionalProjectFileFlag = flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(String str) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,20 +17,11 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -40,38 +31,24 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implements CodegenConfig {
|
||||
@SuppressWarnings("unused")
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CppQt5QHttpEngineServerCodegen.class);
|
||||
public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implements CodegenConfig {
|
||||
|
||||
public static final String CPP_NAMESPACE = "cppNamespace";
|
||||
public static final String CPP_NAMESPACE_DESC = "C++ namespace (convention: name::space::for::api).";
|
||||
|
||||
protected final String PREFIX = "OAI";
|
||||
protected final String SRC_DIR = "/src";
|
||||
protected final String MODEL_DIR = "/src/models";
|
||||
protected final String APIHANDLER_DIR = "/src/handlers";
|
||||
protected final String APIREQUEST_DIR = "/src/requests";
|
||||
protected Set<String> foundationClasses = new HashSet<String>();
|
||||
|
||||
// source folder where to write the files
|
||||
protected String sourceFolder = "server";
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected Map<String, String> namespaces = new HashMap<String, String>();
|
||||
protected Set<String> systemIncludes = new HashSet<String>();
|
||||
protected String cppNamespace = "OpenAPI";
|
||||
protected Set<String> nonFrameworkPrimitives = new HashSet<String>();
|
||||
|
||||
public CppQt5QHttpEngineServerCodegen() {
|
||||
super();
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/cpp-qt5-qhttpengine-server";
|
||||
|
||||
// set modelNamePrefix as default for QHttpEngine Server
|
||||
if (StringUtils.isEmpty(modelNamePrefix)) {
|
||||
modelNamePrefix = PREFIX;
|
||||
}
|
||||
|
||||
/*
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
@@ -112,45 +89,7 @@ public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implement
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
embeddedTemplateDir = templateDir = "cpp-qt5-qhttpengine-server";
|
||||
|
||||
// CLI options
|
||||
addOption(CPP_NAMESPACE, CPP_NAMESPACE_DESC, this.cppNamespace);
|
||||
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
additionalProperties().put("prefix", PREFIX);
|
||||
|
||||
// Write defaults namespace in properties so that it can be accessible in templates.
|
||||
// At this point command line has not been parsed so if value is given
|
||||
// in command line it will supersede this content
|
||||
additionalProperties.put("cppNamespace", cppNamespace);
|
||||
|
||||
/*
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"bool",
|
||||
"qint32",
|
||||
"qint64",
|
||||
"float",
|
||||
"double")
|
||||
);
|
||||
nonFrameworkPrimitives.addAll(languageSpecificPrimitives);
|
||||
|
||||
foundationClasses.addAll(
|
||||
Arrays.asList(
|
||||
"QString",
|
||||
"QDate",
|
||||
"QDateTime",
|
||||
"QByteArray")
|
||||
);
|
||||
languageSpecificPrimitives.addAll(foundationClasses);
|
||||
|
||||
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, PREFIX + "Object.h"));
|
||||
@@ -166,49 +105,12 @@ public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implement
|
||||
supportingFiles.add(new SupportingFile("Dockerfile.mustache", sourceFolder, "Dockerfile"));
|
||||
supportingFiles.add(new SupportingFile("LICENSE.txt.mustache", sourceFolder, "LICENSE.txt"));
|
||||
|
||||
super.typeMapping = new HashMap<String, String>();
|
||||
|
||||
typeMapping.put("date", "QDate");
|
||||
typeMapping.put("DateTime", "QDateTime");
|
||||
typeMapping.put("string", "QString");
|
||||
typeMapping.put("integer", "qint32");
|
||||
typeMapping.put("long", "qint64");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("array", "QList");
|
||||
typeMapping.put("map", "QMap");
|
||||
typeMapping.put("object", PREFIX + "Object");
|
||||
// mapped as "file" type for OAS 3.0
|
||||
typeMapping.put("ByteArray", "QByteArray");
|
||||
// UUID support - possible enhancement : use QUuid instead of QString.
|
||||
// beware though that Serialization/deserialization of QUuid does not
|
||||
// come out of the box and will need to be sorted out (at least imply
|
||||
// modifications on multiple templates)
|
||||
typeMapping.put("UUID", "QString");
|
||||
typeMapping.put("file", "QIODevice");
|
||||
typeMapping.put("binary", "QIODevice");
|
||||
importMapping = new HashMap<String, String>();
|
||||
namespaces = new HashMap<String, String>();
|
||||
|
||||
|
||||
|
||||
systemIncludes.add("QString");
|
||||
systemIncludes.add("QList");
|
||||
systemIncludes.add("QMap");
|
||||
systemIncludes.add("QDate");
|
||||
systemIncludes.add("QDateTime");
|
||||
systemIncludes.add("QByteArray");
|
||||
systemIncludes.add("QIODevice");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("cppNamespace")) {
|
||||
cppNamespace = (String) additionalProperties.get("cppNamespace");
|
||||
}
|
||||
|
||||
additionalProperties.put("cppNamespaceDeclarations", cppNamespace.split("\\::"));
|
||||
if (additionalProperties.containsKey("modelNamePrefix")) {
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.h"));
|
||||
@@ -224,9 +126,6 @@ public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implement
|
||||
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
||||
supportingFiles.add(new SupportingFile("Dockerfile.mustache", sourceFolder, "Dockerfile"));
|
||||
supportingFiles.add(new SupportingFile("LICENSE.txt.mustache", sourceFolder, "LICENSE.txt"));
|
||||
|
||||
typeMapping.put("object", modelNamePrefix + "Object");
|
||||
additionalProperties().put("prefix", modelNamePrefix);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,25 +161,6 @@ public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implement
|
||||
public String getHelp() {
|
||||
return "Generates a Qt5 C++ Server using the QHTTPEngine HTTP Library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if( name.isEmpty() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (namespaces.containsKey(name)) {
|
||||
return "using " + namespaces.get(name) + ";";
|
||||
} else if (systemIncludes.contains(name)) {
|
||||
return "#include <" + name + ">";
|
||||
}
|
||||
|
||||
String folder = modelPackage().replace("::", File.separator);
|
||||
if (!folder.isEmpty())
|
||||
folder += File.separator;
|
||||
|
||||
return "#include \"" + folder + name + ".h\"";
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
@@ -304,11 +184,6 @@ public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implement
|
||||
return outputFolder + "/" + sourceFolder + APIREQUEST_DIR + "/" + apiPackage().replace("::", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return modelNamePrefix + sanitizeName(initialCaps(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
@@ -325,195 +200,4 @@ public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implement
|
||||
return modelNamePrefix + sanitizeName(initialCaps(name)) + "ApiHandler";
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||
* types. There is typically special handling for different property types
|
||||
*
|
||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
String openAPIType = getSchemaType(p);
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return getSchemaType(p) + "*";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return getSchemaType(p) + "*";
|
||||
}
|
||||
if (foundationClasses.contains(openAPIType)) {
|
||||
return openAPIType;
|
||||
} else if (languageSpecificPrimitives.contains(openAPIType)) {
|
||||
return toModelName(openAPIType);
|
||||
} else {
|
||||
return openAPIType;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
return "NULL";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return "NULL";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
||||
return "0.0f";
|
||||
}
|
||||
return "0.0";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
||||
return "0L";
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "QList<" + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
return "QString(\"\")";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
}
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - OpenAPI type conversion. This is used to map OpenAPI types in a `Schema` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(openAPIType)) {
|
||||
type = typeMapping.get(openAPIType);
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
return toModelName(type);
|
||||
}
|
||||
if (foundationClasses.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
type = openAPIType;
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
String varName = name;
|
||||
varName = sanitizeName(name);
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (varName.matches("^[A-Z_]*$")) {
|
||||
varName = varName.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// petId => pet_id
|
||||
varName = org.openapitools.codegen.utils.StringUtils.underscore(varName);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(varName) || varName.matches("^\\d.*")) {
|
||||
varName = escapeReservedWord(varName);
|
||||
}
|
||||
|
||||
return varName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(String str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needToImport(String type) {
|
||||
return StringUtils.isNotBlank(type) && !defaultIncludes.contains(type)
|
||||
&& !nonFrameworkPrimitives.contains(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||
for (CodegenOperation operation : operations) {
|
||||
// Check all return parameter baseType if there is a necessity to include, include it if not
|
||||
// already done
|
||||
if (operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
||||
if(!isIncluded(operation.returnBaseType, imports)) {
|
||||
imports.add(createMapping("import", operation.returnBaseType));
|
||||
}
|
||||
}
|
||||
List<CodegenParameter> params = new ArrayList<CodegenParameter>();
|
||||
if (operation.allParams != null)params.addAll(operation.allParams);
|
||||
|
||||
// Check all parameter baseType if there is a necessity to include, include it if not
|
||||
// already done
|
||||
for(CodegenParameter param : params) {
|
||||
if(param.isPrimitiveType && needToImport(param.baseType)) {
|
||||
if(!isIncluded(param.baseType, imports)) {
|
||||
imports.add(createMapping("import", param.baseType));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation.pathParams != null) {
|
||||
// We use QString to pass path params, add it to include
|
||||
if(!isIncluded("QString", imports)) {
|
||||
imports.add(createMapping("import", "QString"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isIncluded("QMap", imports)) {
|
||||
// Maps uses QString as key
|
||||
if(!isIncluded("QString", imports)) {
|
||||
imports.add(createMapping("import", "QString"));
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
public Map<String, String> createMapping(String key, String value) {
|
||||
Map<String, String> customImport = new HashMap<String, String>();
|
||||
customImport.put(key, toModelImport(value));
|
||||
return customImport;
|
||||
}
|
||||
|
||||
private boolean isIncluded(String type, List<Map<String, String>> imports) {
|
||||
boolean included = false;
|
||||
String inclStr = toModelImport(type);
|
||||
for (Map<String, String> importItem : imports) {
|
||||
if(importItem.containsValue(inclStr)) {
|
||||
included = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return included;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class CppTizenClientCodegen extends AbstractCppCodegen implements CodegenConfig {
|
||||
protected static String PREFIX = "ArtikCloud";
|
||||
@@ -284,7 +285,7 @@ public class CppTizenClientCodegen extends AbstractCppCodegen implements Codegen
|
||||
}
|
||||
|
||||
// add_pet_by_id => addPetById
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(operationId, true);
|
||||
return camelize(operationId, true);
|
||||
}
|
||||
/**
|
||||
* Output the Getter name for boolean property, e.g. getActive
|
||||
|
||||
@@ -42,6 +42,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DartClientCodegen.class);
|
||||
|
||||
@@ -263,7 +266,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = org.openapitools.codegen.utils.StringUtils.camelize(name, true);
|
||||
name = camelize(name, true);
|
||||
|
||||
if (name.matches("^\\d.*")) {
|
||||
name = "n" + name;
|
||||
@@ -286,23 +289,23 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name));
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + camelize("model_" + name));
|
||||
name = "model_" + name; // e.g. return => ModelReturn (after camelize)
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name);
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(toModelName(name));
|
||||
return underscore(toModelName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(toApiName(name));
|
||||
return underscore(toApiName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -424,7 +427,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
new ArrayList<Map<String, String>>();
|
||||
for (Map<String, Object> value : values) {
|
||||
Map<String, String> enumVar = new HashMap<String, String>();
|
||||
String name = org.openapitools.codegen.utils.StringUtils.camelize((String) value.get("identifier"), true);
|
||||
String name = camelize((String) value.get("identifier"), true);
|
||||
if (isReservedWord(name)) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
@@ -450,7 +453,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
"int".equalsIgnoreCase(datatype)) {
|
||||
var = "Number" + var;
|
||||
}
|
||||
return escapeReservedWord(org.openapitools.codegen.utils.StringUtils.camelize(var, true));
|
||||
return escapeReservedWord(camelize(var, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -467,12 +470,12 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(operationId, true);
|
||||
return camelize(operationId, true);
|
||||
}
|
||||
|
||||
public void setBrowserClient(boolean browserClient) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
@@ -33,7 +34,10 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||
private static final String NULLABLE_FIELDS = "nullableFields";
|
||||
private static Set<String> modelToIgnore = new HashSet<>();
|
||||
|
||||
static {
|
||||
@@ -43,11 +47,15 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||
modelToIgnore.add("file");
|
||||
}
|
||||
|
||||
private boolean nullableFields = true;
|
||||
|
||||
public DartJaguarClientCodegen() {
|
||||
super();
|
||||
browserClient = false;
|
||||
outputFolder = "generated-code/dart-jaguar";
|
||||
embeddedTemplateDir = templateDir = "dart-jaguar";
|
||||
|
||||
cliOptions.add(new CliOption(NULLABLE_FIELDS, "Is the null fields should be in the JSON payload"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,6 +80,13 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
if (additionalProperties.containsKey(NULLABLE_FIELDS)) {
|
||||
nullableFields = convertPropertyToBooleanAndWriteBack(NULLABLE_FIELDS);
|
||||
} else {
|
||||
//not set, use to be passed to template
|
||||
additionalProperties.put(NULLABLE_FIELDS, nullableFields);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(PUB_NAME)) {
|
||||
this.setPubName((String) additionalProperties.get(PUB_NAME));
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.openapitools.codegen.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DukeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String sourceFolder = "src";
|
||||
protected String apiVersion = "1.0.0";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "dukescript";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a DukeScript @Model client library (beta).";
|
||||
}
|
||||
|
||||
public DukeScriptClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/dukescript";
|
||||
modelTemplateFiles.put(
|
||||
"model.mustache",
|
||||
"VMD.java");
|
||||
apiTemplateFiles.put(
|
||||
"api.mustache",
|
||||
"Connector.java");
|
||||
templateDir = "dukescript";
|
||||
apiPackage = "org.openapitools.client.api";
|
||||
modelPackage = "org.openapitools.client.model";
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("integer", "int");
|
||||
typeMapping.put("long", "long");
|
||||
typeMapping.put("short", "short");
|
||||
typeMapping.put("short", "short");
|
||||
typeMapping.put("Boolean", "boolean");
|
||||
typeMapping.put("boolean", "boolean");
|
||||
typeMapping.put("Date", "long");
|
||||
typeMapping.put("DateTime", "long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name; // add an underscore to the name
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(openAPIType)) {
|
||||
type = typeMapping.get(openAPIType);
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
type = openAPIType;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,6 +37,8 @@ import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ElixirClientCodegen.class);
|
||||
@@ -276,7 +278,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String pathTemplateName = matcher.group(1);
|
||||
matcher.appendReplacement(buffer, "#{" + org.openapitools.codegen.utils.StringUtils.underscore(pathTemplateName) + "}" + "$2");
|
||||
matcher.appendReplacement(buffer, "#{" + underscore(pathTemplateName) + "}" + "$2");
|
||||
pathTemplateNames.add(pathTemplateName);
|
||||
}
|
||||
ExtendedCodegenOperation eco = new ExtendedCodegenOperation(o);
|
||||
@@ -324,7 +326,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
String underscored(String words) {
|
||||
ArrayList<String> underscoredWords = new ArrayList<String>();
|
||||
for (String word : words.split(" ")) {
|
||||
underscoredWords.add(org.openapitools.codegen.utils.StringUtils.underscore(word));
|
||||
underscoredWords.add(underscore(word));
|
||||
}
|
||||
return join("_", underscoredWords);
|
||||
}
|
||||
@@ -332,7 +334,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
String modulized(String words) {
|
||||
ArrayList<String> modulizedWords = new ArrayList<String>();
|
||||
for (String word : words.split(" ")) {
|
||||
modulizedWords.add(org.openapitools.codegen.utils.StringUtils.camelize(word));
|
||||
modulizedWords.add(camelize(word));
|
||||
}
|
||||
return join("", modulizedWords);
|
||||
}
|
||||
@@ -351,7 +353,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
private String sourceFolder() {
|
||||
ArrayList<String> underscoredWords = new ArrayList<String>();
|
||||
for (String word : moduleName.split("\\.")) {
|
||||
underscoredWords.add(org.openapitools.codegen.utils.StringUtils.underscore(word));
|
||||
underscoredWords.add(underscore(word));
|
||||
}
|
||||
return ("lib/" + join("/", underscoredWords)).replace('/', File.separatorChar);
|
||||
}
|
||||
@@ -378,7 +380,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
if (name.length() == 0) {
|
||||
return "Default";
|
||||
}
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(name);
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -387,14 +389,14 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// e.g. PetApi.go => pet_api.go
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
return underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(toModelFilename(name));
|
||||
return camelize(toModelFilename(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -421,7 +423,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
return underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -433,17 +435,17 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId)));
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId));
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
|
||||
return underscore(sanitizeName("call_" + operationId));
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId)));
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(operationId));
|
||||
return underscore(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -596,7 +598,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
public String typespec() {
|
||||
StringBuilder sb = new StringBuilder("@spec ");
|
||||
sb.append(org.openapitools.codegen.utils.StringUtils.underscore(operationId));
|
||||
sb.append(underscore(operationId));
|
||||
sb.append("(Tesla.Env.client, ");
|
||||
|
||||
for (CodegenParameter param : allParams) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user