forked from loafle/openapi-generator-original
Compare commits
93 Commits
cpp-oatpp-
...
refactor_m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2e2b30f23 | ||
|
|
37cec1695c | ||
|
|
4a275b24f7 | ||
|
|
8c06f96529 | ||
|
|
36d366b19b | ||
|
|
751ffad8db | ||
|
|
ed72843668 | ||
|
|
e732804a68 | ||
|
|
a3aa19927e | ||
|
|
cbe1fd9728 | ||
|
|
c0c2f2b804 | ||
|
|
3195338c47 | ||
|
|
43fa47a51d | ||
|
|
b54dade079 | ||
|
|
13f1c610d9 | ||
|
|
3de537062d | ||
|
|
adcf54bc09 | ||
|
|
38dbcdd752 | ||
|
|
bac913f384 | ||
|
|
5e4d0978dc | ||
|
|
a4f1d1b5b1 | ||
|
|
25c7ccf30c | ||
|
|
64c57e3f52 | ||
|
|
bcf4f8ade6 | ||
|
|
b0ecaab8fb | ||
|
|
7644f3ee83 | ||
|
|
ebac0a8ed4 | ||
|
|
033d985cf7 | ||
|
|
82c5021df2 | ||
|
|
634c4c09e4 | ||
|
|
64ade2ce8f | ||
|
|
e040a5fdde | ||
|
|
adcf9ffa20 | ||
|
|
a8fbcb0db2 | ||
|
|
16e9011d5b | ||
|
|
cb1a620628 | ||
|
|
045d05fa72 | ||
|
|
2801c0cb88 | ||
|
|
3f75691da2 | ||
|
|
9334909bcd | ||
|
|
c950384a5d | ||
|
|
616b44f3b1 | ||
|
|
157ad1ce73 | ||
|
|
cf185d559b | ||
|
|
4dc8d2a351 | ||
|
|
2b6b7746f3 | ||
|
|
ca6c63f7e5 | ||
|
|
8cfc9b015a | ||
|
|
596d9a1d1d | ||
|
|
be07bd13af | ||
|
|
9c0850f2d7 | ||
|
|
d64586c223 | ||
|
|
4f0e75b32d | ||
|
|
2e3cfe7695 | ||
|
|
522faf835a | ||
|
|
6f6822a1b7 | ||
|
|
33f4827a06 | ||
|
|
4984f9c3d5 | ||
|
|
14ff8e0ffd | ||
|
|
70bc472b86 | ||
|
|
1c1e4f4476 | ||
|
|
91e64f47fc | ||
|
|
08c8296e33 | ||
|
|
aed8086d0e | ||
|
|
67271b72f2 | ||
|
|
2578ef5e63 | ||
|
|
2715f1371a | ||
|
|
dd26e406b5 | ||
|
|
cf8ea9120a | ||
|
|
c02fc812fe | ||
|
|
5e02a5bd45 | ||
|
|
b5ce7cec8b | ||
|
|
78611b3e38 | ||
|
|
3bf8ca7484 | ||
|
|
c08f14500e | ||
|
|
057647cf1e | ||
|
|
36aba267a0 | ||
|
|
54d6257865 | ||
|
|
aca6927ce0 | ||
|
|
023e6dd9ed | ||
|
|
88dc21959d | ||
|
|
a3a0af7c84 | ||
|
|
e725c4e56f | ||
|
|
920eafc9c1 | ||
|
|
405aa24737 | ||
|
|
777031f24f | ||
|
|
3b84e8bb55 | ||
|
|
ec13288c02 | ||
|
|
13673962cb | ||
|
|
eab26d493b | ||
|
|
f8766d591c | ||
|
|
b1b64cb356 | ||
|
|
81e0e8dfa8 |
14
.gitignore
vendored
14
.gitignore
vendored
@@ -234,11 +234,15 @@ samples/client/petstore/erlang-proper/rebar.lock
|
|||||||
samples/server/petstore/erlang-server/_build/
|
samples/server/petstore/erlang-server/_build/
|
||||||
samples/server/petstore/erlang-server/rebar.lock
|
samples/server/petstore/erlang-server/rebar.lock
|
||||||
|
|
||||||
# dart
|
# Dart
|
||||||
samples/client/petstore/dart/petstore/packages
|
**/dart*/**/.dart_tool
|
||||||
samples/client/petstore/dart/flutter_petstore/test/packages
|
**/dart*/**/.packages
|
||||||
samples/client/petstore/dart/petstore/test/packages
|
**/dart*/**/pubspec.lock
|
||||||
**/.dart_tool
|
# Dart dio
|
||||||
|
**/dart*/**/*.g.dart
|
||||||
|
# Dart jaguar
|
||||||
|
**/dart*/**/*.jser.dart
|
||||||
|
**/dart*/**/*.jretro.dart
|
||||||
|
|
||||||
# JS
|
# JS
|
||||||
samples/client/petstore/javascript-es6/package-lock.json
|
samples/client/petstore/javascript-es6/package-lock.json
|
||||||
|
|||||||
@@ -140,6 +140,8 @@ install:
|
|||||||
script:
|
script:
|
||||||
# fail fast
|
# fail fast
|
||||||
- set -e
|
- set -e
|
||||||
|
# fail if the test files have changes
|
||||||
|
- bin/utils/detect_test_file_changes.rb bin/utils/test_file_list.yaml
|
||||||
# fail if templates/generators contain carriage return '\r'
|
# fail if templates/generators contain carriage return '\r'
|
||||||
- /bin/bash ./bin/utils/detect_carriage_return.sh
|
- /bin/bash ./bin/utils/detect_carriage_return.sh
|
||||||
# fail if generators contain merge conflicts
|
# fail if generators contain merge conflicts
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ steps:
|
|||||||
# test java native client
|
# test java native client
|
||||||
- ./mvnw clean test -f samples/client/petstore/java/native/pom.xml
|
- ./mvnw clean test -f samples/client/petstore/java/native/pom.xml
|
||||||
- ./mvnw clean test -f samples/client/petstore/java/native-async/pom.xml
|
- ./mvnw clean test -f samples/client/petstore/java/native-async/pom.xml
|
||||||
|
- ./mvnw clean test -f samples/openapi3/client/petstore/java/native/pom.xml
|
||||||
# test all generators with fake petstore spec (2.0, 3.0)
|
# test all generators with fake petstore spec (2.0, 3.0)
|
||||||
- /bin/bash bin/utils/test-fake-petstore-for-all.sh
|
- /bin/bash bin/utils/test-fake-petstore-for-all.sh
|
||||||
# generate test scripts
|
# generate test scripts
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
:notebook_with_decorative_cover: The eBook [A Beginner's Guide to Code Generation for REST APIs](https://gum.co/openapi_generator_ebook) is a good starting point for beginners :notebook_with_decorative_cover:
|
:notebook_with_decorative_cover: The eBook [A Beginner's Guide to Code Generation for REST APIs](https://gum.co/openapi_generator_ebook) is a good starting point for beginners :notebook_with_decorative_cover:
|
||||||
|
|
||||||
:warning: If the OpenAPI spec, templates or any input (e.g. options, environment variables) is obtained from an untrusted source or environment, please make sure you've reviewed these inputs before using OpenAPI Generator to generate the API client, server stub or documentation to avoid potential security issues (e.g. [code injection](https://en.wikipedia.org/wiki/Code_injection)) :warning:
|
:warning: If the OpenAPI spec, templates or any input (e.g. options, environment variables) is obtained from an untrusted source or environment, please make sure you've reviewed these inputs before using OpenAPI Generator to generate the API client, server stub or documentation to avoid potential security issues (e.g. [code injection](https://en.wikipedia.org/wiki/Code_injection)). For security vulnerabilities, please contact [team@openapitools.org](mailto:team@openapitools.org). :warning:
|
||||||
|
|
||||||
:bangbang: Both "OpenAPI Tools" (https://OpenAPITools.org - the parent organization of OpenAPI Generator) and "OpenAPI Generator" are not affiliated with OpenAPI Initiative (OAI) :bangbang:
|
:bangbang: Both "OpenAPI Tools" (https://OpenAPITools.org - the parent organization of OpenAPI Generator) and "OpenAPI Generator" are not affiliated with OpenAPI Initiative (OAI) :bangbang:
|
||||||
|
|
||||||
@@ -103,9 +103,7 @@ The OpenAPI Specification has undergone 3 revisions since initial creation in 20
|
|||||||
| OpenAPI Generator Version | Release Date | Notes |
|
| OpenAPI Generator Version | Release Date | Notes |
|
||||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------------------------------------------- |
|
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------------------------------------------- |
|
||||||
| 5.0.0 (upcoming major release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.0.0-SNAPSHOT/) | TBD | Major release with breaking changes (no fallback) |
|
| 5.0.0 (upcoming major release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.0.0-SNAPSHOT/) | TBD | Major release with breaking changes (no fallback) |
|
||||||
| 5.0.0-beta3 (upcoming beta release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.0.0-SNAPSHOT/) | 01.11.2020 | Major beta release with breaking changes (no fallback) |
|
| [5.0.0-beta3](https://github.com/OpenAPITools/openapi-generator/releases/tag/v5.0.0-beta3) (latest beta release) | 20.11.2020 | Major beta release with breaking changes (no fallback) |
|
||||||
| [5.0.0-beta2](https://github.com/OpenAPITools/openapi-generator/releases/tag/v5.0.0-beta2) (latest beta release) | 04.09.2020 | Major beta release with breaking changes (no fallback) |
|
|
||||||
| [5.0.0-beta](https://github.com/OpenAPITools/openapi-generator/releases/tag/v5.0.0-beta) (latest beta release) | 30.06.2020 | Major beta release with breaking changes (no fallback) |
|
|
||||||
| [4.3.1](https://github.com/OpenAPITools/openapi-generator/releases/tag/v4.3.1) (latest stable release) | 06.05.2020 | Patch release (enhancements, bug fixes, etc) |
|
| [4.3.1](https://github.com/OpenAPITools/openapi-generator/releases/tag/v4.3.1) (latest stable release) | 06.05.2020 | Patch release (enhancements, bug fixes, etc) |
|
||||||
|
|
||||||
OpenAPI Spec compatibility: 1.0, 1.1, 1.2, 2.0, 3.0
|
OpenAPI Spec compatibility: 1.0, 1.1, 1.2, 2.0, 3.0
|
||||||
@@ -162,16 +160,16 @@ See the different versions of the [openapi-generator-cli](https://mvnrepository.
|
|||||||
<!-- RELEASE_VERSION -->
|
<!-- RELEASE_VERSION -->
|
||||||
If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum):
|
If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum):
|
||||||
|
|
||||||
JAR location: `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta2/openapi-generator-cli-5.0.0-beta2.jar`
|
JAR location: `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta3/openapi-generator-cli-5.0.0-beta3.jar`
|
||||||
|
|
||||||
For **Mac/Linux** users:
|
For **Mac/Linux** users:
|
||||||
```sh
|
```sh
|
||||||
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta2/openapi-generator-cli-5.0.0-beta2.jar -O openapi-generator-cli.jar
|
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta3/openapi-generator-cli-5.0.0-beta3.jar -O openapi-generator-cli.jar
|
||||||
```
|
```
|
||||||
|
|
||||||
For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.
|
For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.
|
||||||
```
|
```
|
||||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta2/openapi-generator-cli-5.0.0-beta2.jar
|
Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta3/openapi-generator-cli-5.0.0-beta3.jar
|
||||||
```
|
```
|
||||||
|
|
||||||
After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage.
|
After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage.
|
||||||
@@ -420,7 +418,7 @@ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generat
|
|||||||
(if you're on Windows, replace the last command with `java -jar modules\openapi-generator-cli\target\openapi-generator-cli.jar generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php -o c:\temp\php_api_client`)
|
(if you're on Windows, replace the last command with `java -jar modules\openapi-generator-cli\target\openapi-generator-cli.jar generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php -o c:\temp\php_api_client`)
|
||||||
|
|
||||||
<!-- RELEASE_VERSION -->
|
<!-- RELEASE_VERSION -->
|
||||||
You can also download the JAR (latest release) directly from [maven.org](https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta2/openapi-generator-cli-5.0.0-beta2.jar)
|
You can also download the JAR (latest release) directly from [maven.org](https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta3/openapi-generator-cli-5.0.0-beta3.jar)
|
||||||
<!-- /RELEASE_VERSION -->
|
<!-- /RELEASE_VERSION -->
|
||||||
|
|
||||||
To get a list of **general** options available, please run `java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar help generate`
|
To get a list of **general** options available, please run `java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar help generate`
|
||||||
@@ -612,6 +610,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
|||||||
- [Kubernetes](https://kubernetes.io)
|
- [Kubernetes](https://kubernetes.io)
|
||||||
- [Linode](https://www.linode.com/)
|
- [Linode](https://www.linode.com/)
|
||||||
- [Logicdrop](https://www.logicdrop.com)
|
- [Logicdrop](https://www.logicdrop.com)
|
||||||
|
- [LVM Versicherungen](https://www.lvm.de)
|
||||||
- [MailSlurp](https://www.mailslurp.com)
|
- [MailSlurp](https://www.mailslurp.com)
|
||||||
- [Médiavision](https://www.mediavision.fr/)
|
- [Médiavision](https://www.mediavision.fr/)
|
||||||
- [Metaswitch](https://www.metaswitch.com/)
|
- [Metaswitch](https://www.metaswitch.com/)
|
||||||
@@ -785,6 +784,8 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
|||||||
- 2020-09-25 - [Generate OpenAPI Angular Client](https://medium.com/@pguso/generate-openapi-angular-client-8c9288e8bbd4) by [Patric](https://medium.com/@pguso)
|
- 2020-09-25 - [Generate OpenAPI Angular Client](https://medium.com/@pguso/generate-openapi-angular-client-8c9288e8bbd4) by [Patric](https://medium.com/@pguso)
|
||||||
- 2020-10-24 - [Working with Microsoft Identity - React Native Client](https://www.josephguadagno.net/2020/10/24/working-with-microsoft-identity-react-native-client) by [Joseph Guadagno](https://www.josephguadagno.net/)
|
- 2020-10-24 - [Working with Microsoft Identity - React Native Client](https://www.josephguadagno.net/2020/10/24/working-with-microsoft-identity-react-native-client) by [Joseph Guadagno](https://www.josephguadagno.net/)
|
||||||
- 2020-10-31 - [[B2] OpenAPI Specification으로 타입-세이프하게 API 개발하기: 희망편 VS 절망편](https://www.youtube.com/watch?v=J4JHLESAiFk) by 최태건 at [FEConf 2020](https://2020.feconf.kr/)
|
- 2020-10-31 - [[B2] OpenAPI Specification으로 타입-세이프하게 API 개발하기: 희망편 VS 절망편](https://www.youtube.com/watch?v=J4JHLESAiFk) by 최태건 at [FEConf 2020](https://2020.feconf.kr/)
|
||||||
|
- 2020-11-05 - [Automated REST-Api Code Generation: Wie IT-Systeme miteinander sprechen](https://www.massiveart.com/blog/automated-rest-api-code-generation-wie-it-systeme-miteinander-sprechen) by Stefan Rottensteiner at [MASSIVE ART Blog](https://www.massiveart.com/blog)
|
||||||
|
- 2020-12-01 - [OpenAPI GeneratorでGoのAPIサーバー/クライアントコードを自動生成する](https://qiita.com/saki-engineering/items/b20d8b6074c4da9664a5) by [@saki-engineering](https://qiita.com/saki-engineering)
|
||||||
|
|
||||||
## [6 - About Us](#table-of-contents)
|
## [6 - About Us](#table-of-contents)
|
||||||
|
|
||||||
@@ -859,7 +860,7 @@ Here is a list of template creators:
|
|||||||
* PHP (Guzzle): @baartosz
|
* PHP (Guzzle): @baartosz
|
||||||
* PowerShell: @beatcracker
|
* PowerShell: @beatcracker
|
||||||
* PowerShell (refactored in 5.0.0): @wing328
|
* PowerShell (refactored in 5.0.0): @wing328
|
||||||
* Python-experimental: @spacether
|
* Python: @spacether
|
||||||
* R: @ramnov
|
* R: @ramnov
|
||||||
* Ruby (Faraday): @meganemura @dkliban
|
* Ruby (Faraday): @meganemura @dkliban
|
||||||
* Rust: @farcaller
|
* Rust: @farcaller
|
||||||
|
|||||||
6
bin/configs/dart-dio-petstore-client-lib-fake.yaml
Normal file
6
bin/configs/dart-dio-petstore-client-lib-fake.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
generatorName: dart-dio
|
||||||
|
outputDir: samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/dart-dio
|
||||||
|
additionalProperties:
|
||||||
|
hideGenerationTimestamp: "true"
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
generatorName: dart-dio
|
generatorName: dart-dio
|
||||||
outputDir: samples/client/petstore/dart-dio
|
outputDir: samples/client/petstore/dart-dio/petstore_client_lib
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
|
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
|
||||||
templateDir: modules/openapi-generator/src/main/resources/dart-dio
|
templateDir: modules/openapi-generator/src/main/resources/dart-dio
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
6
bin/configs/dart-dio-petstore-client-lib.yaml
Normal file
6
bin/configs/dart-dio-petstore-client-lib.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
generatorName: dart-dio
|
||||||
|
outputDir: samples/openapi3/client/petstore/dart-dio/petstore_client_lib
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/dart-dio
|
||||||
|
additionalProperties:
|
||||||
|
hideGenerationTimestamp: "true"
|
||||||
6
bin/configs/dart-petstore-client-lib-fake.yaml
Normal file
6
bin/configs/dart-petstore-client-lib-fake.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
generatorName: dart
|
||||||
|
outputDir: samples/openapi3/client/petstore/dart2/petstore_client_lib_fake
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/dart2
|
||||||
|
additionalProperties:
|
||||||
|
hideGenerationTimestamp: "true"
|
||||||
6
bin/configs/dart-petstore-client-lib.yaml
Normal file
6
bin/configs/dart-petstore-client-lib.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
generatorName: dart
|
||||||
|
outputDir: samples/openapi3/client/petstore/dart2/petstore_client_lib
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/dart2
|
||||||
|
additionalProperties:
|
||||||
|
hideGenerationTimestamp: "true"
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
generatorName: cpp-oatpp-server
|
|
||||||
outputDir: samples/server/petstore/cpp-oatpp
|
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
|
||||||
templateDir: modules/openapi-generator/src/main/resources/cpp-oatpp-server
|
|
||||||
7
bin/configs/other/jaxrs-cxf-client-jackson.yaml
Normal file
7
bin/configs/other/jaxrs-cxf-client-jackson.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
generatorName: jaxrs-cxf-client
|
||||||
|
outputDir: samples/client/petstore/jaxrs-cxf-client-jackson
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/JavaJaxRS/cxf
|
||||||
|
additionalProperties:
|
||||||
|
artifactId: jaxrs-cxf-jackson-petstore-client
|
||||||
|
jackson: "true"
|
||||||
@@ -10,3 +10,7 @@ additionalProperties:
|
|||||||
powershellGalleryUrl: https://www.powershellgallery.com/packages/PSPetstore
|
powershellGalleryUrl: https://www.powershellgallery.com/packages/PSPetstore
|
||||||
apiNamePrefix: PS
|
apiNamePrefix: PS
|
||||||
powershellVersion: "5.0"
|
powershellVersion: "5.0"
|
||||||
|
licenseUri: https://www.apache.org/licenses/LICENSE-2.0.txt
|
||||||
|
projectUri: https://github.com/OpenAPITools/openapi-generator
|
||||||
|
releaseNotes: 'This is a sample project'
|
||||||
|
tags: 'PetStore,powershell,sdk'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
generatorName: python
|
generatorName: python-legacy
|
||||||
outputDir: samples/client/petstore/python-asyncio
|
outputDir: samples/client/petstore/python-asyncio
|
||||||
library: asyncio
|
library: asyncio
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||||
templateDir: modules/openapi-generator/src/main/resources/python
|
templateDir: modules/openapi-generator/src/main/resources/python-legacy
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
packageName: petstore_api
|
packageName: petstore_api
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
generatorName: python-experimental
|
|
||||||
outputDir: samples/client/petstore/python-experimental
|
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/python-client-experimental/petstore-with-fake-endpoints-models-for-testing.yaml
|
|
||||||
templateDir: modules/openapi-generator/src/main/resources/python
|
|
||||||
additionalProperties:
|
|
||||||
disallowAdditionalPropertiesIfNotPresent: "true"
|
|
||||||
packageName: petstore_api
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
generatorName: python-experimental
|
|
||||||
outputDir: samples/openapi3/client/petstore/python-experimental
|
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
|
||||||
templateDir: modules/openapi-generator/src/main/resources/python
|
|
||||||
additionalProperties:
|
|
||||||
packageName: petstore_api
|
|
||||||
recursionLimit: "1234"
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
generatorName: python-experimental
|
generatorName: python
|
||||||
outputDir: samples/openapi3/client/extensions/x-auth-id-alias/python-experimental/
|
outputDir: samples/openapi3/client/extensions/x-auth-id-alias/python/
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/extensions/x-auth-id-alias.yaml
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/extensions/x-auth-id-alias.yaml
|
||||||
templateDir: modules/openapi-generator/src/main/resources/python
|
templateDir: modules/openapi-generator/src/main/resources/python
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
generatorName: python-experimental
|
generatorName: python
|
||||||
outputDir: samples/openapi3/client/features/dynamic-servers/python-experimental/
|
outputDir: samples/openapi3/client/features/dynamic-servers/python/
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/features/dynamic-servers.yaml
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/features/dynamic-servers.yaml
|
||||||
templateDir: modules/openapi-generator/src/main/resources/python
|
templateDir: modules/openapi-generator/src/main/resources/python
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
6
bin/configs/python-legacy-oas2.yaml
Normal file
6
bin/configs/python-legacy-oas2.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
generatorName: python-legacy
|
||||||
|
outputDir: samples/client/petstore/python-legacy
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/python-legacy
|
||||||
|
additionalProperties:
|
||||||
|
packageName: petstore_api
|
||||||
6
bin/configs/python-legacy.yaml
Normal file
6
bin/configs/python-legacy.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
generatorName: python-legacy
|
||||||
|
outputDir: samples/openapi3/client/petstore/python-legacy
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/python-legacy
|
||||||
|
additionalProperties:
|
||||||
|
packageName: petstore_api
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
generatorName: python
|
generatorName: python
|
||||||
outputDir: samples/client/petstore/python
|
outputDir: samples/client/petstore/python
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
inputSpec: modules/openapi-generator/src/test/resources/2_0/python-client-experimental/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||||
templateDir: modules/openapi-generator/src/main/resources/python
|
templateDir: modules/openapi-generator/src/main/resources/python
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
|
disallowAdditionalPropertiesIfNotPresent: "true"
|
||||||
packageName: petstore_api
|
packageName: petstore_api
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
generatorName: python
|
generatorName: python-legacy
|
||||||
outputDir: samples/client/petstore/python-tornado
|
outputDir: samples/client/petstore/python-tornado
|
||||||
library: tornado
|
library: tornado
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||||
templateDir: modules/openapi-generator/src/main/resources/python
|
templateDir: modules/openapi-generator/src/main/resources/python-legacy
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
packageName: petstore_api
|
packageName: petstore_api
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
generatorName: python
|
generatorName: python
|
||||||
outputDir: samples/openapi3/client/petstore/python
|
outputDir: samples/openapi3/client/petstore/python
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||||
templateDir: modules/openapi-generator/src/main/resources/python
|
templateDir: modules/openapi-generator/src/main/resources/python
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
packageName: petstore_api
|
packageName: petstore_api
|
||||||
|
recursionLimit: "1234"
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
generatorName: typescript-angular
|
||||||
|
outputDir: samples/client/petstore/typescript-angular-v11-provided-in-root/builds/with-npm
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
|
||||||
|
additionalProperties:
|
||||||
|
ngVersion: 11.0.0
|
||||||
|
npmVersion: 1.0.0
|
||||||
|
npmName: '@openapitools/typescript-angular-petstore'
|
||||||
|
npmRepository: https://skimdb.npmjs.com/registry
|
||||||
|
snapshot: false
|
||||||
5
bin/configs/typescript-angular-v11-provided-in-root.yaml
Normal file
5
bin/configs/typescript-angular-v11-provided-in-root.yaml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
generatorName: typescript-angular
|
||||||
|
outputDir: samples/client/petstore/typescript-angular-v11-provided-in-root/builds/default
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
|
||||||
|
additionalProperties:
|
||||||
|
ngVersion: 11.0.0
|
||||||
3
bin/configs/typescript-fetch-default-v3.0.yaml
Normal file
3
bin/configs/typescript-fetch-default-v3.0.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
generatorName: typescript-fetch
|
||||||
|
outputDir: samples/client/petstore/typescript-fetch/builds/default-v3.0
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||||
3
bin/configs/typescript-fetch-enum.yaml
Normal file
3
bin/configs/typescript-fetch-enum.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
generatorName: typescript-fetch
|
||||||
|
outputDir: samples/client/petstore/typescript-fetch/builds/enum
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-fetch/enum.yaml
|
||||||
9
bin/configs/typescript-fetch-without-runtime-checks.yaml
Normal file
9
bin/configs/typescript-fetch-without-runtime-checks.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
generatorName: typescript-fetch
|
||||||
|
outputDir: samples/client/petstore/typescript-fetch/builds/without-runtime-checks
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
|
||||||
|
additionalProperties:
|
||||||
|
npmVersion: 1.0.0
|
||||||
|
npmName: '@openapitools/typescript-fetch-petstore'
|
||||||
|
npmRepository: https://skimdb.npmjs.com/registry
|
||||||
|
withoutRuntimeChecks: true
|
||||||
|
snapshot: false
|
||||||
57
bin/utils/detect_test_file_changes.rb
Executable file
57
bin/utils/detect_test_file_changes.rb
Executable file
@@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
# ruby script to detect changes in test-related files
|
||||||
|
require 'yaml'
|
||||||
|
require 'digest'
|
||||||
|
|
||||||
|
hash = Digest::SHA256.hexdigest("xyz")
|
||||||
|
|
||||||
|
filename= ARGV[0]
|
||||||
|
|
||||||
|
if !filename
|
||||||
|
puts "Usage: #{$0} filename"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if !File.file? filename
|
||||||
|
warn "Error. #{filename} doesn't exist."
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
mismatch = 0
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
test_files = YAML.load_file(filename)
|
||||||
|
test_files.each do |test_file|
|
||||||
|
count = count + 1
|
||||||
|
# file still exists?
|
||||||
|
if !File.file? test_file['filename']
|
||||||
|
warn "Error. Provided test file `#{test_file['filename']}` doesn't exist."
|
||||||
|
mismatch = mismatch + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# check sha256 hash
|
||||||
|
sha256 = Digest::SHA256.hexdigest(File.read(test_file['filename']))
|
||||||
|
if test_file['sha256'] != sha256
|
||||||
|
warn "Looks like #{test_file['filename']} has been modified as its SHA256 `#{sha256}` is not the same as the one in the record: #{test_file['sha256']}"
|
||||||
|
mismatch = mismatch + 1
|
||||||
|
else
|
||||||
|
# no change to the test file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if mismatch > 0
|
||||||
|
warn "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
warn "There are #{mismatch} mismatch. Please review the test files to ensure it has not been deleted/regenerated."
|
||||||
|
warn "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
puts "OK. All matched!"
|
||||||
|
end
|
||||||
|
|
||||||
|
if count == 0
|
||||||
|
warn "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
warn "Looks like the test file list in #{filename} is empty! Please check!"
|
||||||
|
warn "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
6
bin/utils/test_file_list.yaml
Normal file
6
bin/utils/test_file_list.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
# csharp-netcore test files and image for upload
|
||||||
|
- filename: "samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/Api/PetApiTests.cs"
|
||||||
|
sha256: b74ef9eefa4b41fd3233e083fe2355babf25a77f9073d28e1aa81ae2e0a5f1d0
|
||||||
|
- filename: "samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/linux-logo.png"
|
||||||
|
sha256: 0a67c32728197e942b13bdda064b73793f12f5c795f1e5cf35a3adf69c973230
|
||||||
@@ -48,8 +48,8 @@ The following generators are available:
|
|||||||
* [perl](generators/perl.md)
|
* [perl](generators/perl.md)
|
||||||
* [php](generators/php.md)
|
* [php](generators/php.md)
|
||||||
* [powershell (beta)](generators/powershell.md)
|
* [powershell (beta)](generators/powershell.md)
|
||||||
* [python](generators/python.md)
|
* [python (experimental)](generators/python.md)
|
||||||
* [python-experimental (experimental)](generators/python-experimental.md)
|
* [python-legacy](generators/python-legacy.md)
|
||||||
* [r](generators/r.md)
|
* [r](generators/r.md)
|
||||||
* [ruby](generators/ruby.md)
|
* [ruby](generators/ruby.md)
|
||||||
* [rust](generators/rust.md)
|
* [rust](generators/rust.md)
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ The following generators are available:
|
|||||||
* [perl](perl.md)
|
* [perl](perl.md)
|
||||||
* [php](php.md)
|
* [php](php.md)
|
||||||
* [powershell](powershell.md)
|
* [powershell](powershell.md)
|
||||||
* [python](python.md)
|
* [python](python.md)
|
||||||
* [python-experimental (experimental)](python-experimental.md)
|
* [python-legacy](python-legacy.md)
|
||||||
* [r](r.md)
|
* [r](r.md)
|
||||||
* [ruby](ruby.md)
|
* [ruby](ruby.md)
|
||||||
* [rust](rust.md)
|
* [rust](rust.md)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
| ---------- | ------- |
|
| ---------- | ------- |
|
||||||
|BuiltList|package:built_collection/built_collection.dart|
|
|BuiltList|package:built_collection/built_collection.dart|
|
||||||
|BuiltMap|package:built_collection/built_collection.dart|
|
|BuiltMap|package:built_collection/built_collection.dart|
|
||||||
|
|BuiltSet|package:built_collection/built_collection.dart|
|
||||||
|JsonObject|package:built_value/json_object.dart|
|
|JsonObject|package:built_value/json_object.dart|
|
||||||
|Uint8List|dart:typed_data|
|
|Uint8List|dart:typed_data|
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|
|
||||||
| Type/Alias | Imports |
|
| Type/Alias | Imports |
|
||||||
| ---------- | ------- |
|
| ---------- | ------- |
|
||||||
|
|File|FILE|
|
||||||
|
|List|LIST|
|
||||||
|
|Map|STRING_TABLE|
|
||||||
|
|Set|SET|
|
||||||
|
|file|FILE|
|
||||||
|
|
||||||
|
|
||||||
## INSTANTIATION TYPES
|
## INSTANTIATION TYPES
|
||||||
@@ -52,6 +57,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
<li>and</li>
|
<li>and</li>
|
||||||
<li>as</li>
|
<li>as</li>
|
||||||
<li>assign</li>
|
<li>assign</li>
|
||||||
|
<li>attached</li>
|
||||||
<li>attribute</li>
|
<li>attribute</li>
|
||||||
<li>check</li>
|
<li>check</li>
|
||||||
<li>class</li>
|
<li>class</li>
|
||||||
@@ -60,6 +66,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
<li>current</li>
|
<li>current</li>
|
||||||
<li>debug</li>
|
<li>debug</li>
|
||||||
<li>deferred</li>
|
<li>deferred</li>
|
||||||
|
<li>detachable</li>
|
||||||
<li>do</li>
|
<li>do</li>
|
||||||
<li>else</li>
|
<li>else</li>
|
||||||
<li>elseif</li>
|
<li>elseif</li>
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
||||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||||
|sourceFolder|source folder for generated code| |/app|
|
|sourceFolder|source folder for generated code| |/app|
|
||||||
|
|supportAsync|Support Async operations| |false|
|
||||||
|title|server title name or client service name| |openapi-java-playframework|
|
|title|server title name or client service name| |openapi-java-playframework|
|
||||||
|useBeanValidation|Use BeanValidation API annotations| |true|
|
|useBeanValidation|Use BeanValidation API annotations| |true|
|
||||||
|useInterfaces|Makes the controllerImp implements an interface to facilitate automatic completion when updating from version x to y of your spec| |true|
|
|useInterfaces|Makes the controllerImp implements an interface to facilitate automatic completion when updating from version x to y of your spec| |true|
|
||||||
|
|||||||
@@ -11,10 +11,15 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|commonVerbs|PS common verb mappings. e.g. Delete=Remove:Patch=Update to map Delete with Remove and Patch with Update accordingly.| |null|
|
|commonVerbs|PS common verb mappings. e.g. Delete=Remove:Patch=Update to map Delete with Remove and Patch with Update accordingly.| |null|
|
||||||
|disallowAdditionalPropertiesIfNotPresent|Specify the behavior when the 'additionalProperties' keyword is not present in the OAS document. If false: the 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications. If true: when the 'additionalProperties' keyword is not present in a schema, the value of 'additionalProperties' is set to false, i.e. no additional properties are allowed. Note: this mode is not compliant with the JSON schema specification. This is the original openapi-generator behavior.This setting is currently ignored for OAS 2.0 documents: 1) When the 'additionalProperties' keyword is not present in a 2.0 schema, additional properties are NOT allowed. 2) Boolean values of the 'additionalProperties' keyword are ignored. It's as if additional properties are NOT allowed.Note: the root cause are issues #1369 and #1371, which must be resolved in the swagger-parser project.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>when the 'additionalProperties' keyword is not present in a schema, the value of 'additionalProperties' is automatically set to false, i.e. no additional properties are allowed. Note: this mode is not compliant with the JSON schema specification. This is the original openapi-generator behavior.</dd></dl>|true|
|
|disallowAdditionalPropertiesIfNotPresent|Specify the behavior when the 'additionalProperties' keyword is not present in the OAS document. If false: the 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications. If true: when the 'additionalProperties' keyword is not present in a schema, the value of 'additionalProperties' is set to false, i.e. no additional properties are allowed. Note: this mode is not compliant with the JSON schema specification. This is the original openapi-generator behavior.This setting is currently ignored for OAS 2.0 documents: 1) When the 'additionalProperties' keyword is not present in a 2.0 schema, additional properties are NOT allowed. 2) Boolean values of the 'additionalProperties' keyword are ignored. It's as if additional properties are NOT allowed.Note: the root cause are issues #1369 and #1371, which must be resolved in the swagger-parser project.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>when the 'additionalProperties' keyword is not present in a schema, the value of 'additionalProperties' is automatically set to false, i.e. no additional properties are allowed. Note: this mode is not compliant with the JSON schema specification. This is the original openapi-generator behavior.</dd></dl>|true|
|
||||||
|discardReadOnly|Set discardReadonly to true to generate the Initialize cmdlet without readonly parameters| |null|
|
|discardReadOnly|Set discardReadonly to true to generate the Initialize cmdlet without readonly parameters| |null|
|
||||||
|
|iconUri|A URL to an icon representing the generated PowerShell module| |null|
|
||||||
|
|licenseUri|A URL to the license for the generated PowerShell module| |null|
|
||||||
|packageGuid|GUID for PowerShell module (e.g. a27b908d-2a20-467f-bc32-af6f3a654ac5). A random GUID will be generated by default.| |null|
|
|packageGuid|GUID for PowerShell module (e.g. a27b908d-2a20-467f-bc32-af6f3a654ac5). A random GUID will be generated by default.| |null|
|
||||||
|packageName|Client package name (e.g. PSTwitter).| |PSOpenAPITools|
|
|packageName|Client package name (e.g. PSTwitter).| |PSOpenAPITools|
|
||||||
|packageVersion|Package version (e.g. 0.1.2).| |0.1.2|
|
|packageVersion|Package version (e.g. 0.1.2).| |0.1.2|
|
||||||
|powershellGalleryUrl|URL to the module in PowerShell Gallery (e.g. https://www.powershellgallery.com/packages/PSTwitter/).| |null|
|
|powershellGalleryUrl|URL to the module in PowerShell Gallery (e.g. https://www.powershellgallery.com/packages/PSTwitter/).| |null|
|
||||||
|
|projectUri|A URL to the main website for this project| |null|
|
||||||
|
|releaseNotes|Release notes of the generated PowerShell module| |null|
|
||||||
|
|tags|Tags applied to the generated PowerShell module. These help with module discovery in online galleries| |null|
|
||||||
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and onlye one match in oneOf's schemas) will be skipped.| |null|
|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and onlye one match in oneOf's schemas) will be skipped.| |null|
|
||||||
|
|
||||||
## IMPORT MAPPING
|
## IMPORT MAPPING
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: Config Options for python-experimental
|
title: Config Options for python-legacy
|
||||||
sidebar_label: python-experimental
|
sidebar_label: python-legacy
|
||||||
---
|
---
|
||||||
|
|
||||||
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
|
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
|
||||||
@@ -14,8 +14,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|packageUrl|python package URL.| |null|
|
|packageUrl|python package URL.| |null|
|
||||||
|packageVersion|python package version.| |1.0.0|
|
|packageVersion|python package version.| |1.0.0|
|
||||||
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|
||||||
|pythonAttrNoneIfUnset|when accessing unset attribute, return `None` instead of raising `ApiAttributeError`| |false|
|
|
||||||
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|
||||||
|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||||
|useNose|use the nose test framework| |false|
|
|useNose|use the nose test framework| |false|
|
||||||
|
|
||||||
## IMPORT MAPPING
|
## IMPORT MAPPING
|
||||||
@@ -28,7 +28,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|
|
||||||
| Type/Alias | Instantiated By |
|
| Type/Alias | Instantiated By |
|
||||||
| ---------- | --------------- |
|
| ---------- | --------------- |
|
||||||
|map|dict|
|
|
||||||
|
|
||||||
|
|
||||||
## LANGUAGE PRIMITIVES
|
## LANGUAGE PRIMITIVES
|
||||||
@@ -40,11 +39,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
<li>datetime</li>
|
<li>datetime</li>
|
||||||
<li>dict</li>
|
<li>dict</li>
|
||||||
<li>file</li>
|
<li>file</li>
|
||||||
<li>file_type</li>
|
|
||||||
<li>float</li>
|
<li>float</li>
|
||||||
<li>int</li>
|
<li>int</li>
|
||||||
<li>list</li>
|
<li>list</li>
|
||||||
<li>none_type</li>
|
|
||||||
<li>object</li>
|
<li>object</li>
|
||||||
<li>str</li>
|
<li>str</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -167,7 +164,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|Examples|✓|OAS2,OAS3
|
|Examples|✓|OAS2,OAS3
|
||||||
|XMLStructureDefinitions|✗|OAS2,OAS3
|
|XMLStructureDefinitions|✗|OAS2,OAS3
|
||||||
|MultiServer|✗|OAS3
|
|MultiServer|✗|OAS3
|
||||||
|ParameterizedServer|✓|OAS3
|
|ParameterizedServer|✗|OAS3
|
||||||
|ParameterStyling|✗|OAS3
|
|ParameterStyling|✗|OAS3
|
||||||
|Callbacks|✗|OAS3
|
|Callbacks|✗|OAS3
|
||||||
|LinkObjects|✗|OAS3
|
|LinkObjects|✗|OAS3
|
||||||
@@ -14,8 +14,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|packageUrl|python package URL.| |null|
|
|packageUrl|python package URL.| |null|
|
||||||
|packageVersion|python package version.| |1.0.0|
|
|packageVersion|python package version.| |1.0.0|
|
||||||
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|
||||||
|
|pythonAttrNoneIfUnset|when accessing unset attribute, return `None` instead of raising `ApiAttributeError`| |false|
|
||||||
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|
||||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
|
||||||
|useNose|use the nose test framework| |false|
|
|useNose|use the nose test framework| |false|
|
||||||
|
|
||||||
## IMPORT MAPPING
|
## IMPORT MAPPING
|
||||||
@@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|
|
||||||
| Type/Alias | Instantiated By |
|
| Type/Alias | Instantiated By |
|
||||||
| ---------- | --------------- |
|
| ---------- | --------------- |
|
||||||
|
|map|dict|
|
||||||
|
|
||||||
|
|
||||||
## LANGUAGE PRIMITIVES
|
## LANGUAGE PRIMITIVES
|
||||||
@@ -39,9 +40,11 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
<li>datetime</li>
|
<li>datetime</li>
|
||||||
<li>dict</li>
|
<li>dict</li>
|
||||||
<li>file</li>
|
<li>file</li>
|
||||||
|
<li>file_type</li>
|
||||||
<li>float</li>
|
<li>float</li>
|
||||||
<li>int</li>
|
<li>int</li>
|
||||||
<li>list</li>
|
<li>list</li>
|
||||||
|
<li>none_type</li>
|
||||||
<li>object</li>
|
<li>object</li>
|
||||||
<li>str</li>
|
<li>str</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -164,7 +167,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|Examples|✓|OAS2,OAS3
|
|Examples|✓|OAS2,OAS3
|
||||||
|XMLStructureDefinitions|✗|OAS2,OAS3
|
|XMLStructureDefinitions|✗|OAS2,OAS3
|
||||||
|MultiServer|✗|OAS3
|
|MultiServer|✗|OAS3
|
||||||
|ParameterizedServer|✗|OAS3
|
|ParameterizedServer|✓|OAS3
|
||||||
|ParameterStyling|✗|OAS3
|
|ParameterStyling|✗|OAS3
|
||||||
|Callbacks|✗|OAS3
|
|Callbacks|✗|OAS3
|
||||||
|LinkObjects|✗|OAS3
|
|LinkObjects|✗|OAS3
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
| Type/Alias | Imports |
|
| Type/Alias | Imports |
|
||||||
| ---------- | ------- |
|
| ---------- | ------- |
|
||||||
|ArrayBuffer|scala.collection.mutable.ArrayBuffer|
|
|ArrayBuffer|scala.collection.mutable.ArrayBuffer|
|
||||||
|BigDecimal|java.math.BigDecimal|
|
|
||||||
|Date|java.util.Date|
|
|Date|java.util.Date|
|
||||||
|DateTime|java.time.LocalDateTime|
|
|DateTime|java.time.LocalDateTime|
|
||||||
|File|java.io.File|
|
|File|java.io.File|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
| ---------- | ------- |
|
| ---------- | ------- |
|
||||||
|Array|java.util.List|
|
|Array|java.util.List|
|
||||||
|ArrayList|java.util.ArrayList|
|
|ArrayList|java.util.ArrayList|
|
||||||
|BigDecimal|java.math.BigDecimal|
|
|
||||||
|Date|java.util.Date|
|
|Date|java.util.Date|
|
||||||
|DateTime|org.joda.time.DateTime|
|
|DateTime|org.joda.time.DateTime|
|
||||||
|File|java.io.File|
|
|File|java.io.File|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|modelFileSuffix|The suffix of the file of the generated model (model<suffix>.ts).| |null|
|
|modelFileSuffix|The suffix of the file of the generated model (model<suffix>.ts).| |null|
|
||||||
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original|
|
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original|
|
||||||
|modelSuffix|The suffix of the generated model.| |null|
|
|modelSuffix|The suffix of the generated model.| |null|
|
||||||
|ngVersion|The version of Angular. (At least 6.0.0)| |10.0.0|
|
|ngVersion|The version of Angular. (At least 6.0.0)| |11.0.0|
|
||||||
|npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null|
|
|npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null|
|
||||||
|npmRepository|Use this property to set an url your private npmRepo in the package.json| |null|
|
|npmRepository|Use this property to set an url your private npmRepo in the package.json| |null|
|
||||||
|npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0|
|
|npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|typescriptThreePlus|Setting this property to true will generate TypeScript 3.6+ compatible code.| |false|
|
|typescriptThreePlus|Setting this property to true will generate TypeScript 3.6+ compatible code.| |false|
|
||||||
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |true|
|
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |true|
|
||||||
|withInterfaces|Setting this property to true will generate interfaces next to the default class implementations.| |false|
|
|withInterfaces|Setting this property to true will generate interfaces next to the default class implementations.| |false|
|
||||||
|
|withoutRuntimeChecks|Setting this property to true will remove any runtime checks on the request and response payloads. Payloads will be casted to their expected types.| |false|
|
||||||
|
|
||||||
## IMPORT MAPPING
|
## IMPORT MAPPING
|
||||||
|
|
||||||
|
|||||||
@@ -150,9 +150,9 @@ public interface CodegenConfig {
|
|||||||
|
|
||||||
Map<String, String> reservedWordsMappings();
|
Map<String, String> reservedWordsMappings();
|
||||||
|
|
||||||
void preprocessOpenAPI(OpenAPI openAPI);
|
void preprocessOpenAPI();
|
||||||
|
|
||||||
void processOpenAPI(OpenAPI openAPI);
|
void processOpenAPI();
|
||||||
|
|
||||||
Compiler processCompiler(Compiler compiler);
|
Compiler processCompiler(Compiler compiler);
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.openapitools.codegen;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.TreeSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -25,14 +25,14 @@ public class CodegenDiscriminator {
|
|||||||
private String propertyType;
|
private String propertyType;
|
||||||
private Map<String, String> mapping;
|
private Map<String, String> mapping;
|
||||||
|
|
||||||
// mappedModels is populated differently if discriminatorExplicitMappingVerbose is
|
// mappedModels is populated differently if legacyDiscriminatorBehavior is
|
||||||
// True or False. When:
|
// True or False. When:
|
||||||
//
|
//
|
||||||
// discriminatorExplicitMappingVerbose == False, this contains:
|
// legacyDiscriminatorBehavior == False, this contains:
|
||||||
// - the name to schema map info in the discriminator mapping entry in your openapi spec OR
|
// - the name to schema map info in the discriminator mapping entry in your openapi spec OR
|
||||||
// - child schemas that allOf inherit self schema
|
// - child schemas that allOf inherit self schema
|
||||||
//
|
//
|
||||||
// discriminatorExplicitMappingVerbose == True, this contains:
|
// legacyDiscriminatorBehavior == True, this contains:
|
||||||
// - the name to schema map info in the discriminMappedModelator mapping entry in your openapi spec AND
|
// - the name to schema map info in the discriminMappedModelator mapping entry in your openapi spec AND
|
||||||
// - x-discriminator-value mappings in child oneOf + anyOf schemas + descendant schemas that allOf inherit self schema AND
|
// - x-discriminator-value mappings in child oneOf + anyOf schemas + descendant schemas that allOf inherit self schema AND
|
||||||
// - descendant schemas that allOf inherit self schema AND
|
// - descendant schemas that allOf inherit self schema AND
|
||||||
@@ -40,7 +40,7 @@ public class CodegenDiscriminator {
|
|||||||
//
|
//
|
||||||
// see the method createDiscriminator in DefaultCodegen.java
|
// see the method createDiscriminator in DefaultCodegen.java
|
||||||
|
|
||||||
private Set<MappedModel> mappedModels = new LinkedHashSet<>();
|
private Set<MappedModel> mappedModels = new TreeSet<>();
|
||||||
|
|
||||||
public String getPropertyName() {
|
public String getPropertyName() {
|
||||||
return propertyName;
|
return propertyName;
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
|||||||
/**
|
/**
|
||||||
* True if this property is an array of items or a map container.
|
* True if this property is an array of items or a map container.
|
||||||
* See:
|
* See:
|
||||||
* - ModelUtils.isArraySchema()
|
* - modelUtils.isArraySchema()
|
||||||
* - ModelUtils.isMapSchema()
|
* - modelUtils.isMapSchema()
|
||||||
*/
|
*/
|
||||||
public boolean isContainer;
|
public boolean isContainer;
|
||||||
public boolean isString;
|
public boolean isString;
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
|||||||
isMap, isArray, isBinary, isFile, schema, jsonSchema, vendorExtensions, items, additionalProperties,
|
isMap, isArray, isBinary, isFile, schema, jsonSchema, vendorExtensions, items, additionalProperties,
|
||||||
vars, requiredVars,
|
vars, requiredVars,
|
||||||
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
|
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
|
||||||
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern());
|
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern(),
|
||||||
|
is1xx, is2xx, is3xx, is4xx, is5xx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -121,6 +122,11 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
|||||||
isFile == that.isFile &&
|
isFile == that.isFile &&
|
||||||
items == that.items &&
|
items == that.items &&
|
||||||
additionalProperties == that.additionalProperties &&
|
additionalProperties == that.additionalProperties &&
|
||||||
|
is1xx == that.is1xx &&
|
||||||
|
is2xx == that.is2xx &&
|
||||||
|
is3xx == that.is3xx &&
|
||||||
|
is4xx == that.is4xx &&
|
||||||
|
is5xx == that.is5xx &&
|
||||||
Objects.equals(vars, that.vars) &&
|
Objects.equals(vars, that.vars) &&
|
||||||
Objects.equals(requiredVars, that.requiredVars) &&
|
Objects.equals(requiredVars, that.requiredVars) &&
|
||||||
Objects.equals(headers, that.headers) &&
|
Objects.equals(headers, that.headers) &&
|
||||||
@@ -362,6 +368,11 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
|||||||
final StringBuilder sb = new StringBuilder("CodegenResponse{");
|
final StringBuilder sb = new StringBuilder("CodegenResponse{");
|
||||||
sb.append("headers=").append(headers);
|
sb.append("headers=").append(headers);
|
||||||
sb.append(", code='").append(code).append('\'');
|
sb.append(", code='").append(code).append('\'');
|
||||||
|
sb.append(", is1xx='").append(is1xx).append('\'');
|
||||||
|
sb.append(", is2xx='").append(is2xx).append('\'');
|
||||||
|
sb.append(", is3xx='").append(is3xx).append('\'');
|
||||||
|
sb.append(", is4xx='").append(is4xx).append('\'');
|
||||||
|
sb.append(", is5xx='").append(is5xx).append('\'');
|
||||||
sb.append(", message='").append(message).append('\'');
|
sb.append(", message='").append(message).append('\'');
|
||||||
sb.append(", examples=").append(examples);
|
sb.append(", examples=").append(examples);
|
||||||
sb.append(", dataType='").append(dataType).append('\'');
|
sb.append(", dataType='").append(dataType).append('\'');
|
||||||
@@ -421,4 +432,15 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
|||||||
public boolean isWildcard() {
|
public boolean isWildcard() {
|
||||||
return "0".equals(code) || "default".equals(code);
|
return "0".equals(code) || "default".equals(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Boolean value indicating whether the status code is a range
|
||||||
|
*
|
||||||
|
* @return True if the status code is a range (e.g. 2XX)
|
||||||
|
*/
|
||||||
|
public boolean isRange() {
|
||||||
|
if (code != null && code.length() == 3 && "XX".equalsIgnoreCase(code.substring(1)))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@
|
|||||||
package org.openapitools.codegen;
|
package org.openapitools.codegen;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import io.swagger.models.Model;
|
||||||
import io.swagger.v3.core.util.Json;
|
import io.swagger.v3.core.util.Json;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.Operation;
|
import io.swagger.v3.oas.models.Operation;
|
||||||
@@ -41,7 +42,7 @@ import org.openapitools.codegen.config.GlobalSettings;
|
|||||||
import org.openapitools.codegen.api.TemplatingEngineAdapter;
|
import org.openapitools.codegen.api.TemplatingEngineAdapter;
|
||||||
import org.openapitools.codegen.api.TemplateFileType;
|
import org.openapitools.codegen.api.TemplateFileType;
|
||||||
import org.openapitools.codegen.ignore.CodegenIgnoreProcessor;
|
import org.openapitools.codegen.ignore.CodegenIgnoreProcessor;
|
||||||
import org.openapitools.codegen.languages.PythonClientExperimentalCodegen;
|
import org.openapitools.codegen.languages.PythonClientCodegen;
|
||||||
import org.openapitools.codegen.meta.GeneratorMetadata;
|
import org.openapitools.codegen.meta.GeneratorMetadata;
|
||||||
import org.openapitools.codegen.meta.Stability;
|
import org.openapitools.codegen.meta.Stability;
|
||||||
import org.openapitools.codegen.serializer.SerializerUtils;
|
import org.openapitools.codegen.serializer.SerializerUtils;
|
||||||
@@ -76,6 +77,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
protected CodegenConfig config;
|
protected CodegenConfig config;
|
||||||
protected ClientOptInput opts;
|
protected ClientOptInput opts;
|
||||||
protected OpenAPI openAPI;
|
protected OpenAPI openAPI;
|
||||||
|
protected ModelUtils modelUtils;
|
||||||
protected CodegenIgnoreProcessor ignoreProcessor;
|
protected CodegenIgnoreProcessor ignoreProcessor;
|
||||||
private Boolean generateApis = null;
|
private Boolean generateApis = null;
|
||||||
private Boolean generateModels = null;
|
private Boolean generateModels = null;
|
||||||
@@ -108,7 +110,10 @@ public class DefaultGenerator implements Generator {
|
|||||||
public Generator opts(ClientOptInput opts) {
|
public Generator opts(ClientOptInput opts) {
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
this.openAPI = opts.getOpenAPI();
|
this.openAPI = opts.getOpenAPI();
|
||||||
|
this.modelUtils = new ModelUtils(openAPI);
|
||||||
this.config = opts.getConfig();
|
this.config = opts.getConfig();
|
||||||
|
this.config.setOpenAPI(this.openAPI);
|
||||||
|
|
||||||
List<TemplateDefinition> userFiles = opts.getUserDefinedTemplates();
|
List<TemplateDefinition> userFiles = opts.getUserDefinedTemplates();
|
||||||
if (userFiles != null) {
|
if (userFiles != null) {
|
||||||
this.userDefinedTemplates = ImmutableList.copyOf(userFiles);
|
this.userDefinedTemplates = ImmutableList.copyOf(userFiles);
|
||||||
@@ -152,6 +157,10 @@ public class DefaultGenerator implements Generator {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModelUtils getModelUtils() {
|
||||||
|
return modelUtils;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an instance to the configured template processor, available after user-defined options are
|
* Retrieves an instance to the configured template processor, available after user-defined options are
|
||||||
* applied via {@link DefaultGenerator#opts(ClientOptInput)}.
|
* applied via {@link DefaultGenerator#opts(ClientOptInput)}.
|
||||||
@@ -248,10 +257,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
config.processOpts();
|
config.processOpts();
|
||||||
config.preprocessOpenAPI(openAPI);
|
config.preprocessOpenAPI();
|
||||||
|
|
||||||
// set OpenAPI to make these available to all methods
|
|
||||||
config.setOpenAPI(openAPI);
|
|
||||||
|
|
||||||
config.additionalProperties().put("generatorVersion", ImplementationVersion.read());
|
config.additionalProperties().put("generatorVersion", ImplementationVersion.read());
|
||||||
config.additionalProperties().put("generatedDate", ZonedDateTime.now().toString());
|
config.additionalProperties().put("generatedDate", ZonedDateTime.now().toString());
|
||||||
@@ -397,7 +403,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<String, Schema> schemas = ModelUtils.getSchemas(this.openAPI);
|
final Map<String, Schema> schemas = modelUtils.getSchemas();
|
||||||
if (schemas == null) {
|
if (schemas == null) {
|
||||||
LOGGER.warn("Skipping generation of models because specification document has no schemas.");
|
LOGGER.warn("Skipping generation of models because specification document has no schemas.");
|
||||||
return;
|
return;
|
||||||
@@ -458,7 +464,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
|
|
||||||
Schema schema = schemas.get(name);
|
Schema schema = schemas.get(name);
|
||||||
|
|
||||||
if (ModelUtils.isFreeFormObject(this.openAPI, schema)) { // check to see if it'a a free-form object
|
if (modelUtils.isFreeFormObject(schema)) { // check to see if it'a a free-form object
|
||||||
// there are 3 free form use cases
|
// there are 3 free form use cases
|
||||||
// 1. free form with no validation that is not allOf included in any composed schemas
|
// 1. free form with no validation that is not allOf included in any composed schemas
|
||||||
// 2. free form with validation
|
// 2. free form with validation
|
||||||
@@ -472,17 +478,17 @@ public class DefaultGenerator implements Generator {
|
|||||||
LOGGER.info("Model {} not generated since it's a free-form object", name);
|
LOGGER.info("Model {} not generated since it's a free-form object", name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isMapSchema(schema)) { // check to see if it's a "map" model
|
} else if (modelUtils.isMapSchema(schema)) { // check to see if it's a "map" model
|
||||||
// A composed schema (allOf, oneOf, anyOf) is considered a Map schema if the additionalproperties attribute is set
|
// A composed schema (allOf, oneOf, anyOf) is considered a Map schema if the additionalproperties attribute is set
|
||||||
// for that composed schema. However, in the case of a composed schema, the properties are defined or referenced
|
// for that composed schema. However, in the case of a composed schema, the properties are defined or referenced
|
||||||
// in the inner schemas, and the outer schema does not have properties.
|
// in the inner schemas, and the outer schema does not have properties.
|
||||||
if (!ModelUtils.isGenerateAliasAsModel(schema) && !ModelUtils.isComposedSchema(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
|
if (!modelUtils.isGenerateAliasAsModel(schema) && !modelUtils.isComposedSchema(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
|
||||||
// schema without property, i.e. alias to map
|
// schema without property, i.e. alias to map
|
||||||
LOGGER.info("Model {} not generated since it's an alias to map (without property) and `generateAliasAsModel` is set to false (default)", name);
|
LOGGER.info("Model {} not generated since it's an alias to map (without property) and `generateAliasAsModel` is set to false (default)", name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isArraySchema(schema)) { // check to see if it's an "array" model
|
} else if (modelUtils.isArraySchema(schema)) { // check to see if it's an "array" model
|
||||||
if (!ModelUtils.isGenerateAliasAsModel(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
|
if (!modelUtils.isGenerateAliasAsModel(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
|
||||||
// schema without property, i.e. alias to array
|
// schema without property, i.e. alias to array
|
||||||
LOGGER.info("Model {} not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)", name);
|
LOGGER.info("Model {} not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)", name);
|
||||||
continue;
|
continue;
|
||||||
@@ -520,9 +526,9 @@ public class DefaultGenerator implements Generator {
|
|||||||
Map<String, Object> modelTemplate = (Map<String, Object>) ((List<Object>) models.get("models")).get(0);
|
Map<String, Object> modelTemplate = (Map<String, Object>) ((List<Object>) models.get("models")).get(0);
|
||||||
if (modelTemplate != null && modelTemplate.containsKey("model")) {
|
if (modelTemplate != null && modelTemplate.containsKey("model")) {
|
||||||
CodegenModel m = (CodegenModel) modelTemplate.get("model");
|
CodegenModel m = (CodegenModel) modelTemplate.get("model");
|
||||||
if (m.isAlias && !(config instanceof PythonClientExperimentalCodegen)) {
|
if (m.isAlias && !(config instanceof PythonClientCodegen)) {
|
||||||
// alias to number, string, enum, etc, which should not be generated as model
|
// alias to number, string, enum, etc, which should not be generated as model
|
||||||
// for PythonClientExperimentalCodegen, all aliases are generated as models
|
// for PythonClientCodegen, all aliases are generated as models
|
||||||
continue; // Don't create user-defined classes for aliases
|
continue; // Don't create user-defined classes for aliases
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -769,7 +775,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
bundle.put("basePathWithoutHost", basePathWithoutHost);
|
bundle.put("basePathWithoutHost", basePathWithoutHost);
|
||||||
bundle.put("scheme", URLPathUtils.getScheme(url, config));
|
bundle.put("scheme", URLPathUtils.getScheme(url, config));
|
||||||
bundle.put("host", url.getHost());
|
bundle.put("host", url.getHost());
|
||||||
if (url.getPort() != 80 && url.getPort() != 443 ) {
|
if (url.getPort() != 80 && url.getPort() != 443 && url.getPort() != -1) {
|
||||||
bundle.put("port", url.getPort());
|
bundle.put("port", url.getPort());
|
||||||
}
|
}
|
||||||
bundle.put("contextPath", contextPath);
|
bundle.put("contextPath", contextPath);
|
||||||
@@ -856,19 +862,19 @@ public class DefaultGenerator implements Generator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// resolve inline models
|
// resolve inline models
|
||||||
InlineModelResolver inlineModelResolver = new InlineModelResolver();
|
InlineModelResolver inlineModelResolver = new InlineModelResolver(openAPI);
|
||||||
inlineModelResolver.flatten(openAPI);
|
inlineModelResolver.flatten();
|
||||||
|
|
||||||
configureGeneratorProperties();
|
configureGeneratorProperties();
|
||||||
configureOpenAPIInfo();
|
configureOpenAPIInfo();
|
||||||
|
|
||||||
config.processOpenAPI(openAPI);
|
config.processOpenAPI();
|
||||||
|
|
||||||
processUserDefinedTemplates();
|
processUserDefinedTemplates();
|
||||||
|
|
||||||
List<File> files = new ArrayList<>();
|
List<File> files = new ArrayList<>();
|
||||||
// models
|
// models
|
||||||
List<String> filteredSchemas = ModelUtils.getSchemasUsedOnlyInFormParam(openAPI);
|
List<String> filteredSchemas = modelUtils.getSchemasUsedOnlyInFormParam();
|
||||||
List<Object> allModels = new ArrayList<>();
|
List<Object> allModels = new ArrayList<>();
|
||||||
generateModels(files, allModels, filteredSchemas);
|
generateModels(files, allModels, filteredSchemas);
|
||||||
// apis
|
// apis
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ import java.util.*;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class InlineModelResolver {
|
public class InlineModelResolver {
|
||||||
private OpenAPI openapi;
|
private OpenAPI openAPI;
|
||||||
|
private ModelUtils modelUtils;
|
||||||
private Map<String, Schema> addedModels = new HashMap<String, Schema>();
|
private Map<String, Schema> addedModels = new HashMap<String, Schema>();
|
||||||
private Map<String, String> generatedSignature = new HashMap<String, String>();
|
private Map<String, String> generatedSignature = new HashMap<String, String>();
|
||||||
|
|
||||||
@@ -54,27 +55,36 @@ public class InlineModelResolver {
|
|||||||
|
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(InlineModelResolver.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(InlineModelResolver.class);
|
||||||
|
|
||||||
void flatten(OpenAPI openapi) {
|
public InlineModelResolver(OpenAPI openAPI) {
|
||||||
this.openapi = openapi;
|
this.openAPI = openAPI;
|
||||||
|
this.modelUtils = new ModelUtils(openAPI);
|
||||||
|
}
|
||||||
|
|
||||||
if (openapi.getComponents() == null) {
|
public OpenAPI getOpenAPI() {
|
||||||
openapi.setComponents(new Components());
|
return this.openAPI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModelUtils getModelUtils() {
|
||||||
|
return this.modelUtils;
|
||||||
|
}
|
||||||
|
|
||||||
|
void flatten() {
|
||||||
|
if (openAPI.getComponents() == null) {
|
||||||
|
openAPI.setComponents(new Components());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openapi.getComponents().getSchemas() == null) {
|
if (openAPI.getComponents().getSchemas() == null) {
|
||||||
openapi.getComponents().setSchemas(new HashMap<String, Schema>());
|
openAPI.getComponents().setSchemas(new HashMap<String, Schema>());
|
||||||
}
|
}
|
||||||
|
|
||||||
flattenPaths(openapi);
|
flattenPaths();
|
||||||
flattenComponents(openapi);
|
flattenComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flatten inline models in Paths
|
* Flatten inline models in Paths
|
||||||
*
|
|
||||||
* @param openAPI target spec
|
|
||||||
*/
|
*/
|
||||||
private void flattenPaths(OpenAPI openAPI) {
|
private void flattenPaths() {
|
||||||
Paths paths = openAPI.getPaths();
|
Paths paths = openAPI.getPaths();
|
||||||
if (paths == null) {
|
if (paths == null) {
|
||||||
return;
|
return;
|
||||||
@@ -96,9 +106,9 @@ public class InlineModelResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Operation operation : operations) {
|
for (Operation operation : operations) {
|
||||||
flattenRequestBody(openAPI, pathname, operation);
|
flattenRequestBody(pathname, operation);
|
||||||
flattenParameters(openAPI, pathname, operation);
|
flattenParameters(pathname, operation);
|
||||||
flattenResponses(openAPI, pathname, operation);
|
flattenResponses(pathname, operation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,22 +116,21 @@ public class InlineModelResolver {
|
|||||||
/**
|
/**
|
||||||
* Flatten inline models in RequestBody
|
* Flatten inline models in RequestBody
|
||||||
*
|
*
|
||||||
* @param openAPI target spec
|
* @param pathname target pathname
|
||||||
* @param pathname target pathname
|
|
||||||
* @param operation target operation
|
* @param operation target operation
|
||||||
*/
|
*/
|
||||||
private void flattenRequestBody(OpenAPI openAPI, String pathname, Operation operation) {
|
private void flattenRequestBody(String pathname, Operation operation) {
|
||||||
RequestBody requestBody = operation.getRequestBody();
|
RequestBody requestBody = operation.getRequestBody();
|
||||||
if (requestBody == null) {
|
if (requestBody == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Schema model = ModelUtils.getSchemaFromRequestBody(requestBody);
|
Schema model = modelUtils.getSchemaFromRequestBody(requestBody);
|
||||||
if (model instanceof ObjectSchema) {
|
if (model instanceof ObjectSchema) {
|
||||||
Schema obj = (Schema) model;
|
Schema obj = (Schema) model;
|
||||||
if (obj.getType() == null || "object".equals(obj.getType())) {
|
if (obj.getType() == null || "object".equals(obj.getType())) {
|
||||||
if (obj.getProperties() != null && obj.getProperties().size() > 0) {
|
if (obj.getProperties() != null && obj.getProperties().size() > 0) {
|
||||||
flattenProperties(openAPI, obj.getProperties(), pathname);
|
flattenProperties(obj.getProperties(), pathname);
|
||||||
// for model name, use "title" if defined, otherwise default to 'inline_object'
|
// for model name, use "title" if defined, otherwise default to 'inline_object'
|
||||||
String modelName = resolveModelName(obj.getTitle(), "inline_object");
|
String modelName = resolveModelName(obj.getTitle(), "inline_object");
|
||||||
addGenerated(modelName, model);
|
addGenerated(modelName, model);
|
||||||
@@ -163,7 +172,6 @@ public class InlineModelResolver {
|
|||||||
|
|
||||||
// update requestBody to use $ref instead of inline def
|
// update requestBody to use $ref instead of inline def
|
||||||
requestBody.set$ref(modelName);
|
requestBody.set$ref(modelName);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (model instanceof ArraySchema) {
|
} else if (model instanceof ArraySchema) {
|
||||||
@@ -172,10 +180,10 @@ public class InlineModelResolver {
|
|||||||
if (inner instanceof ObjectSchema) {
|
if (inner instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) inner;
|
ObjectSchema op = (ObjectSchema) inner;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
flattenProperties(openAPI, op.getProperties(), pathname);
|
flattenProperties(op.getProperties(), pathname);
|
||||||
// Generate a unique model name based on the title.
|
// Generate a unique model name based on the title.
|
||||||
String modelName = resolveModelName(op.getTitle(), null);
|
String modelName = resolveModelName(op.getTitle(), null);
|
||||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
Schema innerModel = modelFromProperty(op, modelName);
|
||||||
String existing = matchGenerated(innerModel);
|
String existing = matchGenerated(innerModel);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
Schema schema = new Schema().$ref(existing);
|
Schema schema = new Schema().$ref(existing);
|
||||||
@@ -196,11 +204,10 @@ public class InlineModelResolver {
|
|||||||
/**
|
/**
|
||||||
* Flatten inline models in parameters
|
* Flatten inline models in parameters
|
||||||
*
|
*
|
||||||
* @param openAPI target spec
|
* @param pathname target pathname
|
||||||
* @param pathname target pathname
|
|
||||||
* @param operation target operation
|
* @param operation target operation
|
||||||
*/
|
*/
|
||||||
private void flattenParameters(OpenAPI openAPI, String pathname, Operation operation) {
|
private void flattenParameters(String pathname, Operation operation) {
|
||||||
List<Parameter> parameters = operation.getParameters();
|
List<Parameter> parameters = operation.getParameters();
|
||||||
if (parameters == null) {
|
if (parameters == null) {
|
||||||
return;
|
return;
|
||||||
@@ -216,7 +223,7 @@ public class InlineModelResolver {
|
|||||||
Schema obj = (Schema) model;
|
Schema obj = (Schema) model;
|
||||||
if (obj.getType() == null || "object".equals(obj.getType())) {
|
if (obj.getType() == null || "object".equals(obj.getType())) {
|
||||||
if (obj.getProperties() != null && obj.getProperties().size() > 0) {
|
if (obj.getProperties() != null && obj.getProperties().size() > 0) {
|
||||||
flattenProperties(openAPI, obj.getProperties(), pathname);
|
flattenProperties(obj.getProperties(), pathname);
|
||||||
String modelName = resolveModelName(obj.getTitle(), parameter.getName());
|
String modelName = resolveModelName(obj.getTitle(), parameter.getName());
|
||||||
|
|
||||||
parameter.$ref(modelName);
|
parameter.$ref(modelName);
|
||||||
@@ -230,9 +237,9 @@ public class InlineModelResolver {
|
|||||||
if (inner instanceof ObjectSchema) {
|
if (inner instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) inner;
|
ObjectSchema op = (ObjectSchema) inner;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
flattenProperties(openAPI, op.getProperties(), pathname);
|
flattenProperties(op.getProperties(), pathname);
|
||||||
String modelName = resolveModelName(op.getTitle(), parameter.getName());
|
String modelName = resolveModelName(op.getTitle(), parameter.getName());
|
||||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
Schema innerModel = modelFromProperty(op, modelName);
|
||||||
String existing = matchGenerated(innerModel);
|
String existing = matchGenerated(innerModel);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
Schema schema = new Schema().$ref(existing);
|
Schema schema = new Schema().$ref(existing);
|
||||||
@@ -254,11 +261,10 @@ public class InlineModelResolver {
|
|||||||
/**
|
/**
|
||||||
* Flatten inline models in ApiResponses
|
* Flatten inline models in ApiResponses
|
||||||
*
|
*
|
||||||
* @param openAPI target spec
|
* @param pathname target pathname
|
||||||
* @param pathname target pathname
|
|
||||||
* @param operation target operation
|
* @param operation target operation
|
||||||
*/
|
*/
|
||||||
private void flattenResponses(OpenAPI openAPI, String pathname, Operation operation) {
|
private void flattenResponses(String pathname, Operation operation) {
|
||||||
ApiResponses responses = operation.getResponses();
|
ApiResponses responses = operation.getResponses();
|
||||||
if (responses == null) {
|
if (responses == null) {
|
||||||
return;
|
return;
|
||||||
@@ -266,16 +272,16 @@ public class InlineModelResolver {
|
|||||||
|
|
||||||
for (String key : responses.keySet()) {
|
for (String key : responses.keySet()) {
|
||||||
ApiResponse response = responses.get(key);
|
ApiResponse response = responses.get(key);
|
||||||
if (ModelUtils.getSchemaFromResponse(response) == null) {
|
if (modelUtils.getSchemaFromResponse(response) == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Schema property = ModelUtils.getSchemaFromResponse(response);
|
Schema property = modelUtils.getSchemaFromResponse(response);
|
||||||
if (property instanceof ObjectSchema) {
|
if (property instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) property;
|
ObjectSchema op = (ObjectSchema) property;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
String modelName = resolveModelName(op.getTitle(), "inline_response_" + key);
|
String modelName = resolveModelName(op.getTitle(), "inline_response_" + key);
|
||||||
Schema model = modelFromProperty(openAPI, op, modelName);
|
Schema model = modelFromProperty(op, modelName);
|
||||||
String existing = matchGenerated(model);
|
String existing = matchGenerated(model);
|
||||||
Content content = response.getContent();
|
Content content = response.getContent();
|
||||||
for (MediaType mediaType : content.values()) {
|
for (MediaType mediaType : content.values()) {
|
||||||
@@ -298,10 +304,10 @@ public class InlineModelResolver {
|
|||||||
if (inner instanceof ObjectSchema) {
|
if (inner instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) inner;
|
ObjectSchema op = (ObjectSchema) inner;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
flattenProperties(openAPI, op.getProperties(), pathname);
|
flattenProperties(op.getProperties(), pathname);
|
||||||
String modelName = resolveModelName(op.getTitle(),
|
String modelName = resolveModelName(op.getTitle(),
|
||||||
"inline_response_" + key);
|
"inline_response_" + key);
|
||||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
Schema innerModel = modelFromProperty(op, modelName);
|
||||||
String existing = matchGenerated(innerModel);
|
String existing = matchGenerated(innerModel);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
Schema schema = this.makeSchema(existing, op);
|
Schema schema = this.makeSchema(existing, op);
|
||||||
@@ -318,14 +324,14 @@ public class InlineModelResolver {
|
|||||||
}
|
}
|
||||||
} else if (property instanceof MapSchema) {
|
} else if (property instanceof MapSchema) {
|
||||||
MapSchema mp = (MapSchema) property;
|
MapSchema mp = (MapSchema) property;
|
||||||
Schema innerProperty = ModelUtils.getAdditionalProperties(openAPI, mp);
|
Schema innerProperty = modelUtils.getAdditionalProperties(mp);
|
||||||
if (innerProperty instanceof ObjectSchema) {
|
if (innerProperty instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) innerProperty;
|
ObjectSchema op = (ObjectSchema) innerProperty;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
flattenProperties(openAPI, op.getProperties(), pathname);
|
flattenProperties(op.getProperties(), pathname);
|
||||||
String modelName = resolveModelName(op.getTitle(),
|
String modelName = resolveModelName(op.getTitle(),
|
||||||
"inline_response_" + key);
|
"inline_response_" + key);
|
||||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
Schema innerModel = modelFromProperty(op, modelName);
|
||||||
String existing = matchGenerated(innerModel);
|
String existing = matchGenerated(innerModel);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
Schema schema = new Schema().$ref(existing);
|
Schema schema = new Schema().$ref(existing);
|
||||||
@@ -348,30 +354,29 @@ public class InlineModelResolver {
|
|||||||
* Flattens properties of inline object schemas that belong to a composed schema into a
|
* Flattens properties of inline object schemas that belong to a composed schema into a
|
||||||
* single flat list of properties. This is useful to generate a single or multiple
|
* single flat list of properties. This is useful to generate a single or multiple
|
||||||
* inheritance model.
|
* inheritance model.
|
||||||
*
|
* <p>
|
||||||
* In the example below, codegen may generate a 'Dog' class that extends from the
|
* In the example below, codegen may generate a 'Dog' class that extends from the
|
||||||
* generated 'Animal' class. 'Dog' has additional properties 'name', 'age' and 'breed' that
|
* generated 'Animal' class. 'Dog' has additional properties 'name', 'age' and 'breed' that
|
||||||
* are flattened as a single list of properties.
|
* are flattened as a single list of properties.
|
||||||
*
|
* <p>
|
||||||
* Dog:
|
* Dog:
|
||||||
* allOf:
|
* allOf:
|
||||||
* - $ref: '#/components/schemas/Animal'
|
* - $ref: '#/components/schemas/Animal'
|
||||||
* - type: object
|
* - type: object
|
||||||
* properties:
|
* properties:
|
||||||
* name:
|
* name:
|
||||||
* type: string
|
* type: string
|
||||||
* age:
|
* age:
|
||||||
* type: string
|
* type: string
|
||||||
* - type: object
|
* - type: object
|
||||||
* properties:
|
* properties:
|
||||||
* breed:
|
* breed:
|
||||||
* type: string
|
* type: string
|
||||||
*
|
*
|
||||||
* @param openAPI the OpenAPI document
|
* @param key a unique name ofr the composed schema.
|
||||||
* @param key a unique name ofr the composed schema.
|
|
||||||
* @param children the list of nested schemas within a composed schema (allOf, anyOf, oneOf).
|
* @param children the list of nested schemas within a composed schema (allOf, anyOf, oneOf).
|
||||||
*/
|
*/
|
||||||
private void flattenComposedChildren(OpenAPI openAPI, String key, List<Schema> children) {
|
private void flattenComposedChildren(String key, List<Schema> children) {
|
||||||
if (children == null || children.isEmpty()) {
|
if (children == null || children.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -394,7 +399,7 @@ public class InlineModelResolver {
|
|||||||
// To have complete control of the model naming, one can define the model separately
|
// To have complete control of the model naming, one can define the model separately
|
||||||
// instead of inline.
|
// instead of inline.
|
||||||
String innerModelName = resolveModelName(op.getTitle(), key);
|
String innerModelName = resolveModelName(op.getTitle(), key);
|
||||||
Schema innerModel = modelFromProperty(openAPI, op, innerModelName);
|
Schema innerModel = modelFromProperty(op, innerModelName);
|
||||||
String existing = matchGenerated(innerModel);
|
String existing = matchGenerated(innerModel);
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
openAPI.getComponents().addSchemas(innerModelName, innerModel);
|
openAPI.getComponents().addSchemas(innerModelName, innerModel);
|
||||||
@@ -416,10 +421,8 @@ public class InlineModelResolver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Flatten inline models in components
|
* Flatten inline models in components
|
||||||
*
|
|
||||||
* @param openAPI target spec
|
|
||||||
*/
|
*/
|
||||||
private void flattenComponents(OpenAPI openAPI) {
|
private void flattenComponents() {
|
||||||
Map<String, Schema> models = openAPI.getComponents().getSchemas();
|
Map<String, Schema> models = openAPI.getComponents().getSchemas();
|
||||||
if (models == null) {
|
if (models == null) {
|
||||||
return;
|
return;
|
||||||
@@ -428,25 +431,25 @@ public class InlineModelResolver {
|
|||||||
List<String> modelNames = new ArrayList<String>(models.keySet());
|
List<String> modelNames = new ArrayList<String>(models.keySet());
|
||||||
for (String modelName : modelNames) {
|
for (String modelName : modelNames) {
|
||||||
Schema model = models.get(modelName);
|
Schema model = models.get(modelName);
|
||||||
if (ModelUtils.isComposedSchema(model)) {
|
if (modelUtils.isComposedSchema(model)) {
|
||||||
ComposedSchema m = (ComposedSchema) model;
|
ComposedSchema m = (ComposedSchema) model;
|
||||||
// inline child schemas
|
// inline child schemas
|
||||||
flattenComposedChildren(openAPI, modelName + "_allOf", m.getAllOf());
|
flattenComposedChildren(modelName + "_allOf", m.getAllOf());
|
||||||
flattenComposedChildren(openAPI, modelName + "_anyOf", m.getAnyOf());
|
flattenComposedChildren(modelName + "_anyOf", m.getAnyOf());
|
||||||
flattenComposedChildren(openAPI, modelName + "_oneOf", m.getOneOf());
|
flattenComposedChildren(modelName + "_oneOf", m.getOneOf());
|
||||||
} else if (model instanceof Schema) {
|
} else if (model instanceof Schema) {
|
||||||
Schema m = (Schema) model;
|
Schema m = (Schema) model;
|
||||||
Map<String, Schema> properties = m.getProperties();
|
Map<String, Schema> properties = m.getProperties();
|
||||||
flattenProperties(openAPI, properties, modelName);
|
flattenProperties(properties, modelName);
|
||||||
fixStringModel(m);
|
fixStringModel(m);
|
||||||
} else if (ModelUtils.isArraySchema(model)) {
|
} else if (modelUtils.isArraySchema(model)) {
|
||||||
ArraySchema m = (ArraySchema) model;
|
ArraySchema m = (ArraySchema) model;
|
||||||
Schema inner = m.getItems();
|
Schema inner = m.getItems();
|
||||||
if (inner instanceof ObjectSchema) {
|
if (inner instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) inner;
|
ObjectSchema op = (ObjectSchema) inner;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
String innerModelName = resolveModelName(op.getTitle(), modelName + "_inner");
|
String innerModelName = resolveModelName(op.getTitle(), modelName + "_inner");
|
||||||
Schema innerModel = modelFromProperty(openAPI, op, innerModelName);
|
Schema innerModel = modelFromProperty(op, innerModelName);
|
||||||
String existing = matchGenerated(innerModel);
|
String existing = matchGenerated(innerModel);
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
openAPI.getComponents().addSchemas(innerModelName, innerModel);
|
openAPI.getComponents().addSchemas(innerModelName, innerModel);
|
||||||
@@ -483,12 +486,11 @@ public class InlineModelResolver {
|
|||||||
/**
|
/**
|
||||||
* Generates a unique model name. Non-alphanumeric characters will be replaced
|
* Generates a unique model name. Non-alphanumeric characters will be replaced
|
||||||
* with underscores
|
* with underscores
|
||||||
*
|
* <p>
|
||||||
* e.g. io.schema.User_name => io_schema_User_name
|
* e.g. io.schema.User_name => io_schema_User_name
|
||||||
*
|
*
|
||||||
* @param title String title field in the schema if present
|
* @param title String title field in the schema if present
|
||||||
* @param key String model name
|
* @param key String model name
|
||||||
*
|
|
||||||
* @return if provided the sanitized {@code title}, else the sanitized {@code key}
|
* @return if provided the sanitized {@code title}, else the sanitized {@code key}
|
||||||
*/
|
*/
|
||||||
private String resolveModelName(String title, String key) {
|
private String resolveModelName(String title, String key) {
|
||||||
@@ -527,24 +529,24 @@ public class InlineModelResolver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitizes the input so that it's valid name for a class or interface
|
* Sanitizes the input so that it's valid name for a class or interface
|
||||||
*
|
* <p>
|
||||||
* e.g. 12.schema.User name => _2_schema_User_name
|
* e.g. 12.schema.User name => _2_schema_User_name
|
||||||
*/
|
*/
|
||||||
private String sanitizeName(final String name) {
|
private String sanitizeName(final String name) {
|
||||||
return name
|
return name
|
||||||
.replaceAll("^[0-9]", "_") // e.g. 12object => _2object
|
.replaceAll("^[0-9]", "_") // e.g. 12object => _2object
|
||||||
.replaceAll("[^A-Za-z0-9]", "_"); // e.g. io.schema.User name => io_schema_User_name
|
.replaceAll("[^A-Za-z0-9]", "_"); // e.g. io.schema.User name => io_schema_User_name
|
||||||
}
|
}
|
||||||
|
|
||||||
private String uniqueName(final String name) {
|
private String uniqueName(final String name) {
|
||||||
if (openapi.getComponents().getSchemas() == null) {
|
if (openAPI.getComponents().getSchemas() == null) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
String uniqueName = name;
|
String uniqueName = name;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!openapi.getComponents().getSchemas().containsKey(uniqueName)) {
|
if (!openAPI.getComponents().getSchemas().containsKey(uniqueName)) {
|
||||||
return uniqueName;
|
return uniqueName;
|
||||||
}
|
}
|
||||||
uniqueName = name + "_" + ++count;
|
uniqueName = name + "_" + ++count;
|
||||||
@@ -552,7 +554,7 @@ public class InlineModelResolver {
|
|||||||
// TODO it would probably be a good idea to check against a list of used uniqueNames to make sure there are no collisions
|
// TODO it would probably be a good idea to check against a list of used uniqueNames to make sure there are no collisions
|
||||||
}
|
}
|
||||||
|
|
||||||
private void flattenProperties(OpenAPI openAPI, Map<String, Schema> properties, String path) {
|
private void flattenProperties(Map<String, Schema> properties, String path) {
|
||||||
if (properties == null) {
|
if (properties == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -564,7 +566,7 @@ public class InlineModelResolver {
|
|||||||
&& ((ObjectSchema) property).getProperties().size() > 0) {
|
&& ((ObjectSchema) property).getProperties().size() > 0) {
|
||||||
ObjectSchema op = (ObjectSchema) property;
|
ObjectSchema op = (ObjectSchema) property;
|
||||||
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
||||||
Schema model = modelFromProperty(openAPI, op, modelName);
|
Schema model = modelFromProperty(op, modelName);
|
||||||
String existing = matchGenerated(model);
|
String existing = matchGenerated(model);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
Schema schema = new Schema().$ref(existing);
|
Schema schema = new Schema().$ref(existing);
|
||||||
@@ -576,7 +578,7 @@ public class InlineModelResolver {
|
|||||||
propsToUpdate.put(key, schema);
|
propsToUpdate.put(key, schema);
|
||||||
modelsToAdd.put(modelName, model);
|
modelsToAdd.put(modelName, model);
|
||||||
addGenerated(modelName, model);
|
addGenerated(modelName, model);
|
||||||
openapi.getComponents().addSchemas(modelName, model);
|
openAPI.getComponents().addSchemas(modelName, model);
|
||||||
}
|
}
|
||||||
} else if (property instanceof ArraySchema) {
|
} else if (property instanceof ArraySchema) {
|
||||||
ArraySchema ap = (ArraySchema) property;
|
ArraySchema ap = (ArraySchema) property;
|
||||||
@@ -584,9 +586,9 @@ public class InlineModelResolver {
|
|||||||
if (inner instanceof ObjectSchema) {
|
if (inner instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) inner;
|
ObjectSchema op = (ObjectSchema) inner;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
flattenProperties(openAPI, op.getProperties(), path);
|
flattenProperties(op.getProperties(), path);
|
||||||
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
||||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
Schema innerModel = modelFromProperty(op, modelName);
|
||||||
String existing = matchGenerated(innerModel);
|
String existing = matchGenerated(innerModel);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
Schema schema = new Schema().$ref(existing);
|
Schema schema = new Schema().$ref(existing);
|
||||||
@@ -597,19 +599,19 @@ public class InlineModelResolver {
|
|||||||
schema.setRequired(op.getRequired());
|
schema.setRequired(op.getRequired());
|
||||||
ap.setItems(schema);
|
ap.setItems(schema);
|
||||||
addGenerated(modelName, innerModel);
|
addGenerated(modelName, innerModel);
|
||||||
openapi.getComponents().addSchemas(modelName, innerModel);
|
openAPI.getComponents().addSchemas(modelName, innerModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelUtils.isMapSchema(property)) {
|
if (modelUtils.isMapSchema(property)) {
|
||||||
Schema inner = ModelUtils.getAdditionalProperties(openAPI, property);
|
Schema inner = modelUtils.getAdditionalProperties(property);
|
||||||
if (inner instanceof ObjectSchema) {
|
if (inner instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) inner;
|
ObjectSchema op = (ObjectSchema) inner;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
flattenProperties(openAPI, op.getProperties(), path);
|
flattenProperties(op.getProperties(), path);
|
||||||
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
||||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
Schema innerModel = modelFromProperty(op, modelName);
|
||||||
String existing = matchGenerated(innerModel);
|
String existing = matchGenerated(innerModel);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
Schema schema = new Schema().$ref(existing);
|
Schema schema = new Schema().$ref(existing);
|
||||||
@@ -620,7 +622,7 @@ public class InlineModelResolver {
|
|||||||
schema.setRequired(op.getRequired());
|
schema.setRequired(op.getRequired());
|
||||||
property.setAdditionalProperties(schema);
|
property.setAdditionalProperties(schema);
|
||||||
addGenerated(modelName, innerModel);
|
addGenerated(modelName, innerModel);
|
||||||
openapi.getComponents().addSchemas(modelName, innerModel);
|
openAPI.getComponents().addSchemas(modelName, innerModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -632,12 +634,12 @@ public class InlineModelResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String key : modelsToAdd.keySet()) {
|
for (String key : modelsToAdd.keySet()) {
|
||||||
openapi.getComponents().addSchemas(key, modelsToAdd.get(key));
|
openAPI.getComponents().addSchemas(key, modelsToAdd.get(key));
|
||||||
this.addedModels.put(key, modelsToAdd.get(key));
|
this.addedModels.put(key, modelsToAdd.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Schema modelFromProperty(OpenAPI openAPI, Schema object, String path) {
|
private Schema modelFromProperty(Schema object, String path) {
|
||||||
String description = object.getDescription();
|
String description = object.getDescription();
|
||||||
String example = null;
|
String example = null;
|
||||||
Object obj = object.getExample();
|
Object obj = object.getExample();
|
||||||
@@ -686,7 +688,7 @@ public class InlineModelResolver {
|
|||||||
model.setDeprecated(object.getDeprecated());
|
model.setDeprecated(object.getDeprecated());
|
||||||
|
|
||||||
if (properties != null) {
|
if (properties != null) {
|
||||||
flattenProperties(openAPI, properties, path);
|
flattenProperties(properties, path);
|
||||||
model.setProperties(properties);
|
model.setProperties(properties);
|
||||||
}
|
}
|
||||||
return model;
|
return model;
|
||||||
@@ -715,7 +717,7 @@ public class InlineModelResolver {
|
|||||||
private void copyVendorExtensions(Schema source, Schema target) {
|
private void copyVendorExtensions(Schema source, Schema target) {
|
||||||
Map<String, Object> vendorExtensions = source.getExtensions();
|
Map<String, Object> vendorExtensions = source.getExtensions();
|
||||||
if (vendorExtensions == null) {
|
if (vendorExtensions == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (String extName : vendorExtensions.keySet()) {
|
for (String extName : vendorExtensions.keySet()) {
|
||||||
target.addExtension(extName, vendorExtensions.get(extName));
|
target.addExtension(extName, vendorExtensions.get(extName));
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ public class CodegenConfigurator {
|
|||||||
|
|
||||||
public CodegenConfigurator setGenerateAliasAsModel(boolean generateAliasAsModel) {
|
public CodegenConfigurator setGenerateAliasAsModel(boolean generateAliasAsModel) {
|
||||||
workflowSettingsBuilder.withGenerateAliasAsModel(generateAliasAsModel);
|
workflowSettingsBuilder.withGenerateAliasAsModel(generateAliasAsModel);
|
||||||
ModelUtils.setGenerateAliasAsModel(generateAliasAsModel);
|
GlobalSettings.setProperty("generateAliasAsModelKey", String.valueOf(generateAliasAsModel));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,9 +508,6 @@ public class CodegenConfigurator {
|
|||||||
GlobalSettings.setProperty(entry.getKey(), entry.getValue());
|
GlobalSettings.setProperty(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if caller resets GlobalSettings, we'll need to reset generateAliasAsModel. As noted in this method, this should be moved.
|
|
||||||
ModelUtils.setGenerateAliasAsModel(workflowSettings.isGenerateAliasAsModel());
|
|
||||||
|
|
||||||
// TODO: Support custom spec loader implementations (https://github.com/OpenAPITools/openapi-generator/issues/844)
|
// TODO: Support custom spec loader implementations (https://github.com/OpenAPITools/openapi-generator/issues/844)
|
||||||
final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth);
|
final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth);
|
||||||
ParseOptions options = new ParseOptions();
|
ParseOptions options = new ParseOptions();
|
||||||
@@ -523,13 +520,18 @@ public class CodegenConfigurator {
|
|||||||
// TODO: The line below could be removed when at least one of the issue below has been resolved.
|
// TODO: The line below could be removed when at least one of the issue below has been resolved.
|
||||||
// https://github.com/swagger-api/swagger-parser/issues/1369
|
// https://github.com/swagger-api/swagger-parser/issues/1369
|
||||||
// https://github.com/swagger-api/swagger-parser/pull/1374
|
// https://github.com/swagger-api/swagger-parser/pull/1374
|
||||||
//ModelUtils.getOpenApiVersion(specification, inputSpec, authorizationValues);
|
//modelUtils.getOpenApiVersion(specification, inputSpec, authorizationValues);
|
||||||
|
|
||||||
|
ModelUtils modelUtils = new ModelUtils(specification);
|
||||||
|
|
||||||
|
// if caller resets GlobalSettings, we'll need to reset generateAliasAsModel. As noted in this method, this should be moved.
|
||||||
|
modelUtils.setGenerateAliasAsModel(workflowSettings.isGenerateAliasAsModel());
|
||||||
|
|
||||||
// NOTE: We will only expose errors+warnings if there are already errors in the spec.
|
// NOTE: We will only expose errors+warnings if there are already errors in the spec.
|
||||||
if (validationMessages.size() > 0) {
|
if (validationMessages.size() > 0) {
|
||||||
Set<String> warnings = new HashSet<>();
|
Set<String> warnings = new HashSet<>();
|
||||||
if (specification != null) {
|
if (specification != null) {
|
||||||
List<String> unusedModels = ModelUtils.getUnusedSchemas(specification);
|
List<String> unusedModels = modelUtils.getUnusedSchemas();
|
||||||
if (unusedModels != null) {
|
if (unusedModels != null) {
|
||||||
unusedModels.forEach(name -> warnings.add("Unused model: " + name));
|
unusedModels.forEach(name -> warnings.add("Unused model: " + name));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen.examples;
|
package org.openapitools.codegen.examples;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xpath.internal.operations.Mod;
|
||||||
import io.swagger.v3.core.util.Json;
|
import io.swagger.v3.core.util.Json;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
@@ -46,11 +47,13 @@ public class ExampleGenerator {
|
|||||||
|
|
||||||
protected Map<String, Schema> examples;
|
protected Map<String, Schema> examples;
|
||||||
private OpenAPI openAPI;
|
private OpenAPI openAPI;
|
||||||
|
private ModelUtils modelUtils;
|
||||||
private Random random;
|
private Random random;
|
||||||
|
|
||||||
public ExampleGenerator(Map<String, Schema> examples, OpenAPI openAPI) {
|
public ExampleGenerator(Map<String, Schema> examples, OpenAPI openAPI) {
|
||||||
this.examples = examples;
|
this.examples = examples;
|
||||||
this.openAPI = openAPI;
|
this.openAPI = openAPI;
|
||||||
|
this.modelUtils = new ModelUtils(openAPI);
|
||||||
// use a fixed seed to make the "random" numbers reproducible.
|
// use a fixed seed to make the "random" numbers reproducible.
|
||||||
this.random = new Random("ExampleGenerator".hashCode());
|
this.random = new Random("ExampleGenerator".hashCode());
|
||||||
}
|
}
|
||||||
@@ -69,7 +72,7 @@ public class ExampleGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<Map<String, String>> generateFromResponseSchema(Schema responseSchema, Set<String> producesInfo) {
|
private List<Map<String, String>> generateFromResponseSchema(Schema responseSchema, Set<String> producesInfo) {
|
||||||
if (responseSchema.getExample() == null && StringUtils.isEmpty(responseSchema.get$ref()) && !ModelUtils.isArraySchema(responseSchema)) {
|
if (responseSchema.getExample() == null && StringUtils.isEmpty(responseSchema.get$ref()) && !modelUtils.isArraySchema(responseSchema)) {
|
||||||
// no example provided
|
// no example provided
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -78,14 +81,14 @@ public class ExampleGenerator {
|
|||||||
return generate(responseSchema.getExample(), new ArrayList<>(producesInfo));
|
return generate(responseSchema.getExample(), new ArrayList<>(producesInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(responseSchema)) { // array of schema
|
if (modelUtils.isArraySchema(responseSchema)) { // array of schema
|
||||||
ArraySchema as = (ArraySchema) responseSchema;
|
ArraySchema as = (ArraySchema) responseSchema;
|
||||||
if (as.getItems() != null && StringUtils.isEmpty(as.getItems().get$ref())) { // arary of primtive types
|
if (as.getItems() != null && StringUtils.isEmpty(as.getItems().get$ref())) { // arary of primtive types
|
||||||
return generate((Map<String, Object>) responseSchema.getExample(),
|
return generate((Map<String, Object>) responseSchema.getExample(),
|
||||||
new ArrayList<String>(producesInfo), as.getItems());
|
new ArrayList<String>(producesInfo), as.getItems());
|
||||||
} else if (as.getItems() != null && !StringUtils.isEmpty(as.getItems().get$ref())) { // array of model
|
} else if (as.getItems() != null && !StringUtils.isEmpty(as.getItems().get$ref())) { // array of model
|
||||||
return generate((Map<String, Object>) responseSchema.getExample(),
|
return generate((Map<String, Object>) responseSchema.getExample(),
|
||||||
new ArrayList<String>(producesInfo), ModelUtils.getSimpleRef(as.getItems().get$ref()));
|
new ArrayList<String>(producesInfo), modelUtils.getSimpleRef(as.getItems().get$ref()));
|
||||||
} else {
|
} else {
|
||||||
// TODO log warning message as such case is not handled at the moment
|
// TODO log warning message as such case is not handled at the moment
|
||||||
return null;
|
return null;
|
||||||
@@ -95,7 +98,7 @@ public class ExampleGenerator {
|
|||||||
new ArrayList<String>(producesInfo), responseSchema);
|
new ArrayList<String>(producesInfo), responseSchema);
|
||||||
} else { // model
|
} else { // model
|
||||||
return generate((Map<String, Object>) responseSchema.getExample(),
|
return generate((Map<String, Object>) responseSchema.getExample(),
|
||||||
new ArrayList<String>(producesInfo), ModelUtils.getSimpleRef(responseSchema.get$ref()));
|
new ArrayList<String>(producesInfo), modelUtils.getSimpleRef(responseSchema.get$ref()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +121,7 @@ public class ExampleGenerator {
|
|||||||
output.add(kv);
|
output.add(kv);
|
||||||
}
|
}
|
||||||
} else if (property != null && mediaType.startsWith(MIME_TYPE_XML)) {
|
} else if (property != null && mediaType.startsWith(MIME_TYPE_XML)) {
|
||||||
String example = new XmlExampleGenerator(this.examples).toXml(property);
|
String example = new XmlExampleGenerator(this.examples, openAPI).toXml(property);
|
||||||
if (example != null) {
|
if (example != null) {
|
||||||
kv.put(EXAMPLE, example);
|
kv.put(EXAMPLE, example);
|
||||||
output.add(kv);
|
output.add(kv);
|
||||||
@@ -165,7 +168,7 @@ public class ExampleGenerator {
|
|||||||
}
|
}
|
||||||
} else if (modelName != null && mediaType.startsWith(MIME_TYPE_XML)) {
|
} else if (modelName != null && mediaType.startsWith(MIME_TYPE_XML)) {
|
||||||
final Schema schema = this.examples.get(modelName);
|
final Schema schema = this.examples.get(modelName);
|
||||||
String example = new XmlExampleGenerator(this.examples).toXml(schema, 0, Collections.<String>emptySet());
|
String example = new XmlExampleGenerator(this.examples, openAPI).toXml(schema, 0, Collections.<String>emptySet());
|
||||||
if (example != null) {
|
if (example != null) {
|
||||||
kv.put(EXAMPLE, example);
|
kv.put(EXAMPLE, example);
|
||||||
output.add(kv);
|
output.add(kv);
|
||||||
@@ -222,13 +225,13 @@ public class ExampleGenerator {
|
|||||||
if (property.getExample() != null) {
|
if (property.getExample() != null) {
|
||||||
LOGGER.debug("Example set in openapi spec, returning example: '{}'", property.getExample().toString());
|
LOGGER.debug("Example set in openapi spec, returning example: '{}'", property.getExample().toString());
|
||||||
return property.getExample();
|
return property.getExample();
|
||||||
} else if (ModelUtils.isBooleanSchema(property)) {
|
} else if (modelUtils.isBooleanSchema(property)) {
|
||||||
Object defaultValue = property.getDefault();
|
Object defaultValue = property.getDefault();
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
} else if (ModelUtils.isArraySchema(property)) {
|
} else if (modelUtils.isArraySchema(property)) {
|
||||||
Schema innerType = ((ArraySchema) property).getItems();
|
Schema innerType = ((ArraySchema) property).getItems();
|
||||||
if (innerType != null) {
|
if (innerType != null) {
|
||||||
int arrayLength = null == ((ArraySchema) property).getMaxItems() ? 2 : ((ArraySchema) property).getMaxItems();
|
int arrayLength = null == ((ArraySchema) property).getMaxItems() ? 2 : ((ArraySchema) property).getMaxItems();
|
||||||
@@ -241,45 +244,45 @@ public class ExampleGenerator {
|
|||||||
}
|
}
|
||||||
return objectProperties;
|
return objectProperties;
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(property)) {
|
} else if (modelUtils.isDateSchema(property)) {
|
||||||
return "2000-01-23";
|
return "2000-01-23";
|
||||||
} else if (ModelUtils.isDateTimeSchema(property)) {
|
} else if (modelUtils.isDateTimeSchema(property)) {
|
||||||
return "2000-01-23T04:56:07.000+00:00";
|
return "2000-01-23T04:56:07.000+00:00";
|
||||||
} else if (ModelUtils.isNumberSchema(property)) {
|
} else if (modelUtils.isNumberSchema(property)) {
|
||||||
Double min = getPropertyValue(property.getMinimum());
|
Double min = getPropertyValue(property.getMinimum());
|
||||||
Double max = getPropertyValue(property.getMaximum());
|
Double max = getPropertyValue(property.getMaximum());
|
||||||
if (ModelUtils.isFloatSchema(property)) { // float
|
if (modelUtils.isFloatSchema(property)) { // float
|
||||||
return (float) randomNumber(min, max);
|
return (float) randomNumber(min, max);
|
||||||
} else if (ModelUtils.isDoubleSchema(property)) { // decimal/double
|
} else if (modelUtils.isDoubleSchema(property)) { // decimal/double
|
||||||
return BigDecimal.valueOf(randomNumber(min, max));
|
return BigDecimal.valueOf(randomNumber(min, max));
|
||||||
} else { // no format defined
|
} else { // no format defined
|
||||||
return randomNumber(min, max);
|
return randomNumber(min, max);
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isFileSchema(property)) {
|
} else if (modelUtils.isFileSchema(property)) {
|
||||||
return ""; // TODO
|
return ""; // TODO
|
||||||
|
|
||||||
} else if (ModelUtils.isIntegerSchema(property)) {
|
} else if (modelUtils.isIntegerSchema(property)) {
|
||||||
Double min = getPropertyValue(property.getMinimum());
|
Double min = getPropertyValue(property.getMinimum());
|
||||||
Double max = getPropertyValue(property.getMaximum());
|
Double max = getPropertyValue(property.getMaximum());
|
||||||
if (ModelUtils.isLongSchema(property)) {
|
if (modelUtils.isLongSchema(property)) {
|
||||||
return (long) randomNumber(min, max);
|
return (long) randomNumber(min, max);
|
||||||
}
|
}
|
||||||
return (int) randomNumber(min, max);
|
return (int) randomNumber(min, max);
|
||||||
} else if (ModelUtils.isMapSchema(property)) {
|
} else if (modelUtils.isMapSchema(property)) {
|
||||||
Map<String, Object> mp = new HashMap<String, Object>();
|
Map<String, Object> mp = new HashMap<String, Object>();
|
||||||
if (property.getName() != null) {
|
if (property.getName() != null) {
|
||||||
mp.put(property.getName(),
|
mp.put(property.getName(),
|
||||||
resolvePropertyToExample(propertyName, mediaType, ModelUtils.getAdditionalProperties(openAPI, property), processedModels));
|
resolvePropertyToExample(propertyName, mediaType, modelUtils.getAdditionalProperties(property), processedModels));
|
||||||
} else {
|
} else {
|
||||||
mp.put("key",
|
mp.put("key",
|
||||||
resolvePropertyToExample(propertyName, mediaType, ModelUtils.getAdditionalProperties(openAPI, property), processedModels));
|
resolvePropertyToExample(propertyName, mediaType, modelUtils.getAdditionalProperties(property), processedModels));
|
||||||
}
|
}
|
||||||
return mp;
|
return mp;
|
||||||
} else if (ModelUtils.isUUIDSchema(property)) {
|
} else if (modelUtils.isUUIDSchema(property)) {
|
||||||
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
||||||
} else if (ModelUtils.isURISchema(property)) {
|
} else if (modelUtils.isURISchema(property)) {
|
||||||
return "https://openapi-generator.tech";
|
return "https://openapi-generator.tech";
|
||||||
} else if (ModelUtils.isStringSchema(property)) {
|
} else if (modelUtils.isStringSchema(property)) {
|
||||||
LOGGER.debug("String property");
|
LOGGER.debug("String property");
|
||||||
String defaultValue = (String) property.getDefault();
|
String defaultValue = (String) property.getDefault();
|
||||||
if (defaultValue != null && !defaultValue.isEmpty()) {
|
if (defaultValue != null && !defaultValue.isEmpty()) {
|
||||||
@@ -299,14 +302,14 @@ public class ExampleGenerator {
|
|||||||
LOGGER.debug("No values found, using property name " + propertyName + " as example");
|
LOGGER.debug("No values found, using property name " + propertyName + " as example");
|
||||||
return propertyName;
|
return propertyName;
|
||||||
} else if (!StringUtils.isEmpty(property.get$ref())) { // model
|
} else if (!StringUtils.isEmpty(property.get$ref())) { // model
|
||||||
String simpleName = ModelUtils.getSimpleRef(property.get$ref());
|
String simpleName = modelUtils.getSimpleRef(property.get$ref());
|
||||||
Schema schema = ModelUtils.getSchema(openAPI, simpleName);
|
Schema schema = modelUtils.getSchema(simpleName);
|
||||||
if (schema == null) { // couldn't find the model/schema
|
if (schema == null) { // couldn't find the model/schema
|
||||||
return "{}";
|
return "{}";
|
||||||
}
|
}
|
||||||
return resolveModelToExample(simpleName, mediaType, schema, processedModels);
|
return resolveModelToExample(simpleName, mediaType, schema, processedModels);
|
||||||
|
|
||||||
} else if (ModelUtils.isObjectSchema(property)) {
|
} else if (modelUtils.isObjectSchema(property)) {
|
||||||
return "{}";
|
return "{}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen.examples;
|
package org.openapitools.codegen.examples;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
import io.swagger.v3.oas.models.media.XML;
|
import io.swagger.v3.oas.models.media.XML;
|
||||||
@@ -35,8 +36,12 @@ public class XmlExampleGenerator {
|
|||||||
public static String TAG_END = "</";
|
public static String TAG_END = "</";
|
||||||
private static String EMPTY = "";
|
private static String EMPTY = "";
|
||||||
protected Map<String, Schema> examples;
|
protected Map<String, Schema> examples;
|
||||||
|
protected OpenAPI openAPI;
|
||||||
|
protected ModelUtils modelUtils;
|
||||||
|
|
||||||
public XmlExampleGenerator(Map<String, Schema> examples) {
|
public XmlExampleGenerator(Map<String, Schema> examples, OpenAPI openAPI) {
|
||||||
|
this.openAPI = openAPI;
|
||||||
|
this.modelUtils = new ModelUtils(openAPI);
|
||||||
this.examples = examples;
|
this.examples = examples;
|
||||||
if (examples == null) {
|
if (examples == null) {
|
||||||
this.examples = new HashMap<String, Schema>();
|
this.examples = new HashMap<String, Schema>();
|
||||||
@@ -124,7 +129,7 @@ public class XmlExampleGenerator {
|
|||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema as = (ArraySchema) schema;
|
ArraySchema as = (ArraySchema) schema;
|
||||||
Schema inner = as.getItems();
|
Schema inner = as.getItems();
|
||||||
boolean wrapped = false;
|
boolean wrapped = false;
|
||||||
@@ -177,29 +182,29 @@ public class XmlExampleGenerator {
|
|||||||
protected String getExample(Schema schema) {
|
protected String getExample(Schema schema) {
|
||||||
if (schema.getExample() != null) {
|
if (schema.getExample() != null) {
|
||||||
return schema.getExample().toString();
|
return schema.getExample().toString();
|
||||||
} else if (ModelUtils.isDateTimeSchema(schema)) {
|
} else if (modelUtils.isDateTimeSchema(schema)) {
|
||||||
return "2000-01-23T04:56:07.000Z";
|
return "2000-01-23T04:56:07.000Z";
|
||||||
} else if (ModelUtils.isDateSchema(schema)) {
|
} else if (modelUtils.isDateSchema(schema)) {
|
||||||
return "2000-01-23";
|
return "2000-01-23";
|
||||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||||
return "true";
|
return "true";
|
||||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
} else if (modelUtils.isNumberSchema(schema)) {
|
||||||
if (ModelUtils.isFloatSchema(schema)) { // float
|
if (modelUtils.isFloatSchema(schema)) { // float
|
||||||
return "1.3579";
|
return "1.3579";
|
||||||
} else { // double
|
} else { // double
|
||||||
return "3.149";
|
return "3.149";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isPasswordSchema(schema)) {
|
} else if (modelUtils.isPasswordSchema(schema)) {
|
||||||
return "********";
|
return "********";
|
||||||
} else if (ModelUtils.isUUIDSchema(schema)) {
|
} else if (modelUtils.isUUIDSchema(schema)) {
|
||||||
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
||||||
} else if (ModelUtils.isURISchema(schema)) {
|
} else if (modelUtils.isURISchema(schema)) {
|
||||||
return "https://openapi-generator.tech";
|
return "https://openapi-generator.tech";
|
||||||
// do these last in case the specific types above are derived from these classes
|
// do these last in case the specific types above are derived from these classes
|
||||||
} else if (ModelUtils.isStringSchema(schema)) {
|
} else if (modelUtils.isStringSchema(schema)) {
|
||||||
return "aeiou";
|
return "aeiou";
|
||||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||||
if (ModelUtils.isLongSchema(schema)) { // long
|
if (modelUtils.isLongSchema(schema)) { // long
|
||||||
return "123456789";
|
return "123456789";
|
||||||
} else { //integer
|
} else { //integer
|
||||||
return "123";
|
return "123";
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public class CodegenIgnoreProcessor {
|
|||||||
public boolean allowsFile(final File targetFile) {
|
public boolean allowsFile(final File targetFile) {
|
||||||
if(this.ignoreFile == null) return true;
|
if(this.ignoreFile == null) return true;
|
||||||
|
|
||||||
File file = new File(this.ignoreFile.getParentFile().toURI().relativize(targetFile.toURI()).getPath());
|
File file = new File(this.ignoreFile.getAbsoluteFile().getParentFile().toURI().relativize(targetFile.toURI()).getPath());
|
||||||
Boolean directoryExcluded = false;
|
Boolean directoryExcluded = false;
|
||||||
Boolean exclude = false;
|
Boolean exclude = false;
|
||||||
if(exclusionRules.size() == 0 && inclusionRules.size() == 0) {
|
if(exclusionRules.size() == 0 && inclusionRules.size() == 0) {
|
||||||
|
|||||||
@@ -410,12 +410,12 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
|||||||
schemaType = schemaType.replace("-", "_");
|
schemaType = schemaType.replace("-", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getTypeDeclaration(inner) + "_Vectors.Vector";
|
return getTypeDeclaration(inner) + "_Vectors.Vector";
|
||||||
}
|
}
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
String name = getTypeDeclaration(inner) + "_Map";
|
String name = getTypeDeclaration(inner) + "_Map";
|
||||||
if (name.startsWith("Swagger.")) {
|
if (name.startsWith("Swagger.")) {
|
||||||
@@ -432,7 +432,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
|||||||
return schemaType;
|
return schemaType;
|
||||||
}
|
}
|
||||||
String modelType = toModelName(schemaType).replace("-", "_");
|
String modelType = toModelName(schemaType).replace("-", "_");
|
||||||
if (ModelUtils.isStringSchema(p) || ModelUtils.isFileSchema(p)
|
if (modelUtils.isStringSchema(p) || modelUtils.isFileSchema(p)
|
||||||
|| languageSpecificPrimitives.contains(modelType)) {
|
|| languageSpecificPrimitives.contains(modelType)) {
|
||||||
return modelType;
|
return modelType;
|
||||||
}
|
}
|
||||||
@@ -526,8 +526,8 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
|||||||
|
|
||||||
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
||||||
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
||||||
if (methodResponse != null && ModelUtils.getSchemaFromResponse(methodResponse) != null) {
|
if (methodResponse != null && modelUtils.getSchemaFromResponse(methodResponse) != null) {
|
||||||
CodegenProperty cm = fromProperty("response", ModelUtils.getSchemaFromResponse(methodResponse));
|
CodegenProperty cm = fromProperty("response", modelUtils.getSchemaFromResponse(methodResponse));
|
||||||
op.vendorExtensions.put("x-codegen-response", cm);
|
op.vendorExtensions.put("x-codegen-response", cm);
|
||||||
op.vendorExtensions.put("x-is-model-type", isModelType(cm));
|
op.vendorExtensions.put("x-is-model-type", isModelType(cm));
|
||||||
op.vendorExtensions.put("x-is-stream-type", isStreamType(cm));
|
op.vendorExtensions.put("x-is-stream-type", isStreamType(cm));
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@@ -194,7 +194,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@@ -217,7 +217,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
final ArraySchema ap = (ArraySchema) p;
|
final ArraySchema ap = (ArraySchema) p;
|
||||||
final String pattern = "new ArrayList<%s>()";
|
final String pattern = "new ArrayList<%s>()";
|
||||||
if (ap.getItems() == null) {
|
if (ap.getItems() == null) {
|
||||||
@@ -225,7 +225,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
return String.format(Locale.ROOT, pattern, getTypeDeclaration(ap.getItems()));
|
return String.format(Locale.ROOT, pattern, getTypeDeclaration(ap.getItems()));
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
final MapSchema ap = (MapSchema) p;
|
final MapSchema ap = (MapSchema) p;
|
||||||
final String pattern = "new HashMap<%s>()";
|
final String pattern = "new HashMap<%s>()";
|
||||||
if (getAdditionalProperties(ap) == null) {
|
if (getAdditionalProperties(ap) == null) {
|
||||||
@@ -233,32 +233,32 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
return String.format(Locale.ROOT, pattern, String.format(Locale.ROOT, "String, %s", getTypeDeclaration(getAdditionalProperties(ap))));
|
return String.format(Locale.ROOT, pattern, String.format(Locale.ROOT, "String, %s", getTypeDeclaration(getAdditionalProperties(ap))));
|
||||||
} else if (ModelUtils.isLongSchema(p)) {
|
} else if (modelUtils.isLongSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString() + "l";
|
return p.getDefault().toString() + "l";
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isFloatSchema(p)) {
|
} else if (modelUtils.isFloatSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString() + "f";
|
return p.getDefault().toString() + "f";
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isDoubleSchema(p)) {
|
} else if (modelUtils.isDoubleSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString() + "d";
|
return p.getDefault().toString() + "d";
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
String _default = (String) p.getDefault();
|
String _default = (String) p.getDefault();
|
||||||
if (p.getEnum() == null) {
|
if (p.getEnum() == null) {
|
||||||
@@ -314,18 +314,18 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
Object obj = p.getExample();
|
Object obj = p.getExample();
|
||||||
String example = obj == null ? "" : obj.toString();
|
String example = obj == null ? "" : obj.toString();
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
example = "new " + getTypeDeclaration(p) + "{" + toExampleValue(
|
example = "new " + getTypeDeclaration(p) + "{" + toExampleValue(
|
||||||
((ArraySchema) p).getItems()) + "}";
|
((ArraySchema) p).getItems()) + "}";
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
example = String.valueOf(!"false".equals(example));
|
example = String.valueOf(!"false".equals(example));
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
if (example.isEmpty()) {
|
if (example.isEmpty()) {
|
||||||
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
||||||
}
|
}
|
||||||
p.setExample(example);
|
p.setExample(example);
|
||||||
example = "EncodingUtil.base64Decode('" + example + "')";
|
example = "EncodingUtil.base64Decode('" + example + "')";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
if (example.matches("^\\d{4}(-\\d{2}){2}")) {
|
if (example.matches("^\\d{4}(-\\d{2}){2}")) {
|
||||||
example = example.substring(0, 10).replaceAll("-0?", ", ");
|
example = example.substring(0, 10).replaceAll("-0?", ", ");
|
||||||
} else if (example.isEmpty()) {
|
} else if (example.isEmpty()) {
|
||||||
@@ -336,7 +336,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
example = "2000, 1, 23";
|
example = "2000, 1, 23";
|
||||||
}
|
}
|
||||||
example = "Date.newInstance(" + example + ")";
|
example = "Date.newInstance(" + example + ")";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
if (example.matches("^\\d{4}([-T:]\\d{2}){5}.+")) {
|
if (example.matches("^\\d{4}([-T:]\\d{2}){5}.+")) {
|
||||||
example = example.substring(0, 19).replaceAll("[-T:]0?", ", ");
|
example = example.substring(0, 19).replaceAll("[-T:]0?", ", ");
|
||||||
} else if (example.isEmpty()) {
|
} else if (example.isEmpty()) {
|
||||||
@@ -347,31 +347,31 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
example = "2000, 1, 23, 4, 56, 7";
|
example = "2000, 1, 23, 4, 56, 7";
|
||||||
}
|
}
|
||||||
example = "Datetime.newInstanceGmt(" + example + ")";
|
example = "Datetime.newInstanceGmt(" + example + ")";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
example = example.replaceAll("[^-0-9.]", "");
|
example = example.replaceAll("[^-0-9.]", "");
|
||||||
example = example.isEmpty() ? "1.3579" : example;
|
example = example.isEmpty() ? "1.3579" : example;
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isFileSchema(p)) {
|
||||||
if (example.isEmpty()) {
|
if (example.isEmpty()) {
|
||||||
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
||||||
p.setExample(example);
|
p.setExample(example);
|
||||||
}
|
}
|
||||||
example = "EncodingUtil.base64Decode(" + example + ")";
|
example = "EncodingUtil.base64Decode(" + example + ")";
|
||||||
} else if (ModelUtils.isEmailSchema(p)) {
|
} else if (modelUtils.isEmailSchema(p)) {
|
||||||
if (example.isEmpty()) {
|
if (example.isEmpty()) {
|
||||||
example = "example@example.com";
|
example = "example@example.com";
|
||||||
p.setExample(example);
|
p.setExample(example);
|
||||||
}
|
}
|
||||||
example = "'" + example + "'";
|
example = "'" + example + "'";
|
||||||
} else if (ModelUtils.isLongSchema(p)) {
|
} else if (modelUtils.isLongSchema(p)) {
|
||||||
example = example.isEmpty() ? "123456789L" : example + "L";
|
example = example.isEmpty() ? "123456789L" : example + "L";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
example = "new " + getTypeDeclaration(p) + "{'key'=>" + toExampleValue(getAdditionalProperties(p)) + "}";
|
example = "new " + getTypeDeclaration(p) + "{'key'=>" + toExampleValue(getAdditionalProperties(p)) + "}";
|
||||||
|
|
||||||
} else if (ModelUtils.isPasswordSchema(p)) {
|
} else if (modelUtils.isPasswordSchema(p)) {
|
||||||
example = example.isEmpty() ? "password123" : escapeText(example);
|
example = example.isEmpty() ? "password123" : escapeText(example);
|
||||||
p.setExample(example);
|
p.setExample(example);
|
||||||
example = "'" + example + "'";
|
example = "'" + example + "'";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
List<String> enums = p.getEnum();
|
List<String> enums = p.getEnum();
|
||||||
if (enums != null && example.isEmpty()) {
|
if (enums != null && example.isEmpty()) {
|
||||||
example = enums.get(0);
|
example = enums.get(0);
|
||||||
@@ -383,13 +383,13 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
p.setExample(example);
|
p.setExample(example);
|
||||||
}
|
}
|
||||||
example = "'" + example + "'";
|
example = "'" + example + "'";
|
||||||
} else if (ModelUtils.isUUIDSchema(p)) {
|
} else if (modelUtils.isUUIDSchema(p)) {
|
||||||
example = example.isEmpty()
|
example = example.isEmpty()
|
||||||
? "'046b6c7f-0b8a-43b9-b35d-6489e6daee91'"
|
? "'046b6c7f-0b8a-43b9-b35d-6489e6daee91'"
|
||||||
: "'" + escapeText(example) + "'";
|
: "'" + escapeText(example) + "'";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
example = example.matches("^-?\\d+$") ? example : "0";
|
example = example.matches("^-?\\d+$") ? example : "0";
|
||||||
} else if (ModelUtils.isObjectSchema(p)) {
|
} else if (modelUtils.isObjectSchema(p)) {
|
||||||
example = example.isEmpty() ? "null" : example;
|
example = example.isEmpty() ? "null" : example;
|
||||||
} else {
|
} else {
|
||||||
example = getTypeDeclaration(p) + ".getExample()";
|
example = getTypeDeclaration(p) + ".getExample()";
|
||||||
@@ -571,7 +571,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
if (op.getHasExamples()) {
|
if (op.getHasExamples()) {
|
||||||
// prepare examples for Apex test classes
|
// prepare examples for Apex test classes
|
||||||
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
||||||
final Schema responseSchema = ModelUtils.getSchemaFromResponse(apiResponse);
|
final Schema responseSchema = modelUtils.getSchemaFromResponse(apiResponse);
|
||||||
String deserializedExample = toExampleValue(responseSchema);
|
String deserializedExample = toExampleValue(responseSchema);
|
||||||
for (Map<String, String> example : op.examples) {
|
for (Map<String, String> example : op.examples) {
|
||||||
example.put("example", escapeText(example.get("example")));
|
example.put("example", escapeText(example.get("example")));
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
private void postProcessEnumRefs(final Map<String, Object> models) {
|
private void postProcessEnumRefs(final Map<String, Object> models) {
|
||||||
Map<String, CodegenModel> enumRefs = new HashMap<String, CodegenModel>();
|
Map<String, CodegenModel> enumRefs = new HashMap<String, CodegenModel>();
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
CodegenModel model = ModelUtils.getModelByName(entry.getKey(), models);
|
CodegenModel model = modelUtils.getModelByName(entry.getKey(), models);
|
||||||
if (model.isEnum) {
|
if (model.isEnum) {
|
||||||
enumRefs.put(entry.getKey(), model);
|
enumRefs.put(entry.getKey(), model);
|
||||||
}
|
}
|
||||||
@@ -445,7 +445,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
String openAPIName = entry.getKey();
|
String openAPIName = entry.getKey();
|
||||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
for (CodegenProperty var : model.allVars) {
|
for (CodegenProperty var : model.allVars) {
|
||||||
if (enumRefs.containsKey(var.dataType)) {
|
if (enumRefs.containsKey(var.dataType)) {
|
||||||
@@ -594,7 +594,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
protected void updateValueTypeProperty(Map<String, Object> models) {
|
protected void updateValueTypeProperty(Map<String, Object> models) {
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
String openAPIName = entry.getKey();
|
String openAPIName = entry.getKey();
|
||||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
for (CodegenProperty var : model.vars) {
|
for (CodegenProperty var : model.vars) {
|
||||||
var.vendorExtensions.put("x-is-value-type", isValueType(var));
|
var.vendorExtensions.put("x-is-value-type", isValueType(var));
|
||||||
@@ -611,7 +611,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
protected void updateNullableTypeProperty(Map<String, Object> models) {
|
protected void updateNullableTypeProperty(Map<String, Object> models) {
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
String openAPIName = entry.getKey();
|
String openAPIName = entry.getKey();
|
||||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
for (CodegenProperty var : model.vars) {
|
for (CodegenProperty var : model.vars) {
|
||||||
if (!var.isContainer && (nullableType.contains(var.dataType) || var.isEnum)) {
|
if (!var.isContainer && (nullableType.contains(var.dataType) || var.isEnum)) {
|
||||||
@@ -859,23 +859,23 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toExampleValue(Schema p) {
|
public String toExampleValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return "\"" + p.getExample().toString() + "\"";
|
return "\"" + p.getExample().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
@@ -891,33 +891,33 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (ModelUtils.isFloatSchema(p)) { // float
|
if (modelUtils.isFloatSchema(p)) { // float
|
||||||
return p.getDefault().toString() + "F";
|
return p.getDefault().toString() + "F";
|
||||||
} else if (ModelUtils.isDoubleSchema(p)) { // double
|
} else if (modelUtils.isDoubleSchema(p)) { // double
|
||||||
return p.getDefault().toString() + "D";
|
return p.getDefault().toString() + "D";
|
||||||
} else { // decimal
|
} else { // decimal
|
||||||
return p.getDefault().toString() + "M";
|
return p.getDefault().toString() + "M";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
String _default = (String) p.getDefault();
|
String _default = (String) p.getDefault();
|
||||||
if (p.getEnum() == null) {
|
if (p.getEnum() == null) {
|
||||||
@@ -989,7 +989,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
return getArrayTypeDeclaration((ArraySchema) p);
|
return getArrayTypeDeclaration((ArraySchema) p);
|
||||||
}
|
}
|
||||||
return super.toInstantiationType(p);
|
return super.toInstantiationType(p);
|
||||||
@@ -997,9 +997,9 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
return getArrayTypeDeclaration((ArraySchema) p);
|
return getArrayTypeDeclaration((ArraySchema) p);
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
// Should we also support maps of maps?
|
// Should we also support maps of maps?
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
||||||
String port = URLPathUtils.getPort(url, "");
|
String port = URLPathUtils.getPort(url, "");
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
@@ -362,7 +362,7 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
|||||||
public Map<String, Object> postProcessAllModels(Map<String, Object> objs){
|
public Map<String, Object> postProcessAllModels(Map<String, Object> objs){
|
||||||
Map<String, Object> models = super.postProcessAllModels(objs);
|
Map<String, Object> models = super.postProcessAllModels(objs);
|
||||||
for (final Entry<String, Object> model : models.entrySet()) {
|
for (final Entry<String, Object> model : models.entrySet()) {
|
||||||
CodegenModel mo = ModelUtils.getModelByName(model.getKey(), models);
|
CodegenModel mo = modelUtils.getModelByName(model.getKey(), models);
|
||||||
addForwardDeclarations(mo, models);
|
addForwardDeclarations(mo, models);
|
||||||
}
|
}
|
||||||
return models;
|
return models;
|
||||||
@@ -379,7 +379,7 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
|||||||
}
|
}
|
||||||
String childPropertyType = property.isContainer? property.mostInnerItems.baseType : property.baseType;
|
String childPropertyType = property.isContainer? property.mostInnerItems.baseType : property.baseType;
|
||||||
for(final Entry<String, Object> mo : objs.entrySet()) {
|
for(final Entry<String, Object> mo : objs.entrySet()) {
|
||||||
CodegenModel childModel = ModelUtils.getModelByName(mo.getKey(), objs);
|
CodegenModel childModel = modelUtils.getModelByName(mo.getKey(), objs);
|
||||||
if( !childPropertyType.equals(childModel.classname) || childPropertyType.equals(parentModel.classname) || !childModel.hasVars ){
|
if( !childPropertyType.equals(childModel.classname) || childPropertyType.equals(parentModel.classname) || !childModel.hasVars ){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
setReservedWordsLowerCase(Arrays.asList(
|
setReservedWordsLowerCase(Arrays.asList(
|
||||||
// language reserved words
|
// language reserved words
|
||||||
"across", "agent", "alias", "all", "and", "as", "assign", "attribute", "check", "class", "convert",
|
"across", "agent", "alias", "all", "and", "as", "assign", "attached", "attribute", "check", "class", "convert",
|
||||||
"create", "Current", "debug", "deferred", "do", "else", "elseif", "end", "ensure", "expanded", "export",
|
"create", "Current", "debug", "deferred", "detachable", "do", "else", "elseif", "end", "ensure", "expanded", "export",
|
||||||
"external", "False", "feature", "from", "frozen", "if", "implies", "inherit", "inspect", "invariant",
|
"external", "False", "feature", "from", "frozen", "if", "implies", "inherit", "inspect", "invariant",
|
||||||
"like", "local", "loop", "not", "note", "obsolete", "old", "once", "only", "or", "Precursor",
|
"like", "local", "loop", "not", "note", "obsolete", "old", "once", "only", "or", "Precursor",
|
||||||
"redefine", "rename", "require", "rescue", "Result", "retry", "select", "separate", "then", "True",
|
"redefine", "rename", "require", "rescue", "Result", "retry", "select", "separate", "then", "True",
|
||||||
@@ -68,6 +68,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
typeMapping.put("long", "INTEGER_64");
|
typeMapping.put("long", "INTEGER_64");
|
||||||
typeMapping.put("number", "REAL_32");
|
typeMapping.put("number", "REAL_32");
|
||||||
typeMapping.put("float", "REAL_32");
|
typeMapping.put("float", "REAL_32");
|
||||||
|
typeMapping.put("decimal", "REAL_64");
|
||||||
typeMapping.put("double", "REAL_64");
|
typeMapping.put("double", "REAL_64");
|
||||||
typeMapping.put("boolean", "BOOLEAN");
|
typeMapping.put("boolean", "BOOLEAN");
|
||||||
typeMapping.put("string", "STRING_32");
|
typeMapping.put("string", "STRING_32");
|
||||||
@@ -85,10 +86,17 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
typeMapping.put("map", "STRING_TABLE");
|
typeMapping.put("map", "STRING_TABLE");
|
||||||
typeMapping.put("array", "LIST");
|
typeMapping.put("array", "LIST");
|
||||||
typeMapping.put("list", "LIST");
|
typeMapping.put("list", "LIST");
|
||||||
|
typeMapping.put("AnyType", "ANY");
|
||||||
|
|
||||||
instantiationTypes.put("array", "ARRAYED_LIST");
|
instantiationTypes.put("array", "ARRAYED_LIST");
|
||||||
instantiationTypes.put("list", "ARRAYED_LIST");
|
instantiationTypes.put("list", "ARRAYED_LIST");
|
||||||
instantiationTypes.put("map", "STRING_TABLE");
|
instantiationTypes.put("map", "STRING_TABLE");
|
||||||
|
|
||||||
|
importMapping.put("List", "LIST");
|
||||||
|
importMapping.put("Set", "SET");
|
||||||
|
importMapping.put("file", "FILE");
|
||||||
|
importMapping.put("File", "FILE");
|
||||||
|
importMapping.put("Map", "STRING_TABLE");
|
||||||
|
|
||||||
|
|
||||||
cliOptions.clear();
|
cliOptions.clear();
|
||||||
@@ -167,6 +175,12 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelFilename(String name) {
|
public String toModelFilename(String name) {
|
||||||
|
// We need to check if import-mapping has a different model for this class, so we use it
|
||||||
|
// instead of the auto-generated one.
|
||||||
|
if (importMapping.containsKey(name)) {
|
||||||
|
return importMapping.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||||
name = modelNamePrefix + "_" + name;
|
name = modelNamePrefix + "_" + name;
|
||||||
}
|
}
|
||||||
@@ -191,6 +205,13 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
name = "model_" + name; // e.g. 200Response => Model200Response
|
name = "model_" + name; // e.g. 200Response => Model200Response
|
||||||
// (after camelize)
|
// (after camelize)
|
||||||
}
|
}
|
||||||
|
// model name starts with _
|
||||||
|
if (name.startsWith("_")) {
|
||||||
|
LOGGER.warn(name + " (model name starts with _) cannot be used as model name. Renamed to "
|
||||||
|
+ ("model" + name));
|
||||||
|
name = "model" + name; // e.g. 200Response => Model200Response
|
||||||
|
// (after camelize)
|
||||||
|
}
|
||||||
|
|
||||||
return underscore(name);
|
return underscore(name);
|
||||||
}
|
}
|
||||||
@@ -271,14 +292,14 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "LIST [" + getTypeDeclaration(inner) + "]";
|
return "LIST [" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + " [" + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
// return super.getTypeDeclaration(p);
|
// return super.getTypeDeclaration(p);
|
||||||
|
|
||||||
@@ -315,7 +336,12 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toOperationId(String operationId) {
|
public String toOperationId(String operationId) {
|
||||||
String sanitizedOperationId = sanitizeName(operationId);
|
// throw exception if method name is empty
|
||||||
|
if (StringUtils.isEmpty(operationId)) {
|
||||||
|
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||||
|
}
|
||||||
|
|
||||||
|
String sanitizedOperationId = camelize(sanitizeName(operationId), true);
|
||||||
|
|
||||||
// method name cannot use reserved keyword, e.g. return
|
// method name cannot use reserved keyword, e.g. return
|
||||||
if (isReservedWord(sanitizedOperationId)) {
|
if (isReservedWord(sanitizedOperationId)) {
|
||||||
@@ -323,6 +349,13 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
+ camelize("call_" + operationId));
|
+ camelize("call_" + operationId));
|
||||||
sanitizedOperationId = "call_" + sanitizedOperationId;
|
sanitizedOperationId = "call_" + sanitizedOperationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// operationId starts with a number
|
||||||
|
if (operationId.matches("^\\d.*")) {
|
||||||
|
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
|
||||||
|
sanitizedOperationId = camelize("call_" + sanitizedOperationId, true);
|
||||||
|
}
|
||||||
|
|
||||||
// method name from updateSomething to update_Something.
|
// method name from updateSomething to update_Something.
|
||||||
sanitizedOperationId = unCamelize(sanitizedOperationId);
|
sanitizedOperationId = unCamelize(sanitizedOperationId);
|
||||||
|
|
||||||
@@ -430,7 +463,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
private void postProcessParentModels(final Map<String, Object> models) {
|
private void postProcessParentModels(final Map<String, Object> models) {
|
||||||
for (final String parent : parentModels) {
|
for (final String parent : parentModels) {
|
||||||
final CodegenModel parentModel = ModelUtils.getModelByName(parent, models);
|
final CodegenModel parentModel = modelUtils.getModelByName(parent, models);
|
||||||
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
||||||
for (final CodegenModel child : childrenModels) {
|
for (final CodegenModel child : childrenModels) {
|
||||||
processParentPropertiesInChildModel(parentModel, child);
|
processParentPropertiesInChildModel(parentModel, child);
|
||||||
@@ -459,7 +492,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
if (allDefinitions != null && codegenModel.parentSchema != null && codegenModel.hasEnums) {
|
if (allDefinitions != null && codegenModel.parentSchema != null && codegenModel.hasEnums) {
|
||||||
final Schema parentModel = allDefinitions.get(codegenModel.parentSchema);
|
final Schema parentModel = allDefinitions.get(codegenModel.parentSchema);
|
||||||
@@ -537,22 +570,23 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
return getTypeDeclaration(p);
|
||||||
Schema additionalProperties2 = getAdditionalProperties(p);
|
// if (modelUtils.isMapSchema(p)) {
|
||||||
String type = additionalProperties2.getType();
|
// Schema additionalProperties2 = getAdditionalProperties(p);
|
||||||
if (null == type) {
|
// String type = additionalProperties2.getType();
|
||||||
LOGGER.error("No Type defined for Additional Schema " + additionalProperties2 + "\n" //
|
// if (null == type) {
|
||||||
+ "\tIn Schema: " + p);
|
// LOGGER.error("No Type defined for Additional Schema " + additionalProperties2 + "\n" //
|
||||||
}
|
// + "\tIn Schema: " + p);
|
||||||
String inner = toModelName(getSchemaType(additionalProperties2));
|
// }
|
||||||
return instantiationTypes.get("map") + " [" + inner + "]";
|
// String inner = toModelName(getSchemaType(additionalProperties2));
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
// return instantiationTypes.get("map") + " [" + inner + "]";
|
||||||
ArraySchema ap = (ArraySchema) p;
|
// } else if (modelUtils.isArraySchema(p)) {
|
||||||
String inner = toModelName(getSchemaType(ap.getItems()));
|
// ArraySchema ap = (ArraySchema) p;
|
||||||
return instantiationTypes.get("array") + " [" + inner + "]";
|
// String inner = toModelName(getSchemaType(ap.getItems()));
|
||||||
} else {
|
// return instantiationTypes.get("array") + " [" + inner + "]";
|
||||||
return null;
|
// } else {
|
||||||
}
|
// return null;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public String unCamelize(String name) {
|
public String unCamelize(String name) {
|
||||||
|
|||||||
@@ -358,7 +358,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
List<String> classNames = new ArrayList<String>();
|
List<String> classNames = new ArrayList<String>();
|
||||||
|
|
||||||
for (String k : objs.keySet()) {
|
for (String k : objs.keySet()) {
|
||||||
CodegenModel model = ModelUtils.getModelByName(k, objs);
|
CodegenModel model = modelUtils.getModelByName(k, objs);
|
||||||
if (model == null || model.classname == null) {
|
if (model == null || model.classname == null) {
|
||||||
throw new RuntimeException("Null model encountered");
|
throw new RuntimeException("Null model encountered");
|
||||||
}
|
}
|
||||||
@@ -405,7 +405,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
private void postProcessEnumRefs(final Map<String, Object> models) {
|
private void postProcessEnumRefs(final Map<String, Object> models) {
|
||||||
Map<String, CodegenModel> enumRefs = new HashMap<String, CodegenModel>();
|
Map<String, CodegenModel> enumRefs = new HashMap<String, CodegenModel>();
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
CodegenModel model = ModelUtils.getModelByName(entry.getKey(), models);
|
CodegenModel model = modelUtils.getModelByName(entry.getKey(), models);
|
||||||
if (model.isEnum) {
|
if (model.isEnum) {
|
||||||
enumRefs.put(entry.getKey(), model);
|
enumRefs.put(entry.getKey(), model);
|
||||||
}
|
}
|
||||||
@@ -413,7 +413,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
String openAPIName = entry.getKey();
|
String openAPIName = entry.getKey();
|
||||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
for (CodegenProperty var : model.allVars) {
|
for (CodegenProperty var : model.allVars) {
|
||||||
if (enumRefs.containsKey(var.dataType)) {
|
if (enumRefs.containsKey(var.dataType)) {
|
||||||
@@ -735,23 +735,23 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toExampleValue(Schema p) {
|
public String toExampleValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return "\"" + p.getExample().toString() + "\"";
|
return "\"" + p.getExample().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
@@ -768,33 +768,33 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (ModelUtils.isFloatSchema(p)) { // float
|
if (modelUtils.isFloatSchema(p)) { // float
|
||||||
return p.getDefault().toString() + "F";
|
return p.getDefault().toString() + "F";
|
||||||
} else if (ModelUtils.isDoubleSchema(p)) { // double
|
} else if (modelUtils.isDoubleSchema(p)) { // double
|
||||||
return p.getDefault().toString() + "D";
|
return p.getDefault().toString() + "D";
|
||||||
} else { // decimal
|
} else { // decimal
|
||||||
return p.getDefault().toString() + "M";
|
return p.getDefault().toString() + "M";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
String _default = (String) p.getDefault();
|
String _default = (String) p.getDefault();
|
||||||
if (p.getEnum() == null) {
|
if (p.getEnum() == null) {
|
||||||
@@ -817,7 +817,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
public String getNullableType(Schema p, String type) {
|
public String getNullableType(Schema p, String type) {
|
||||||
if (languageSpecificPrimitives.contains(type)) {
|
if (languageSpecificPrimitives.contains(type)) {
|
||||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||||
return type + " option";
|
return type + " option";
|
||||||
} else {
|
} else {
|
||||||
return type;
|
return type;
|
||||||
@@ -869,7 +869,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
return getArrayTypeDeclaration((ArraySchema) p);
|
return getArrayTypeDeclaration((ArraySchema) p);
|
||||||
}
|
}
|
||||||
return super.toInstantiationType(p);
|
return super.toInstantiationType(p);
|
||||||
@@ -877,9 +877,9 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
return getArrayTypeDeclaration((ArraySchema) p);
|
return getArrayTypeDeclaration((ArraySchema) p);
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
// Should we also support maps of maps?
|
// Should we also support maps of maps?
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen.languages;
|
package org.openapitools.codegen.languages;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xpath.internal.operations.Mod;
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
@@ -330,7 +331,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
// In OAS 3.0.x, the array "items" attribute is required.
|
// In OAS 3.0.x, the array "items" attribute is required.
|
||||||
@@ -338,7 +339,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
// specification is aligned with the JSON schema specification.
|
// specification is aligned with the JSON schema specification.
|
||||||
// When "items" is not specified, the elements of the array may be anything at all.
|
// When "items" is not specified, the elements of the array may be anything at all.
|
||||||
if (inner != null) {
|
if (inner != null) {
|
||||||
inner = ModelUtils.unaliasSchema(this.openAPI, inner);
|
inner = modelUtils.unaliasSchema(inner);
|
||||||
}
|
}
|
||||||
String typDecl;
|
String typDecl;
|
||||||
if (inner != null) {
|
if (inner != null) {
|
||||||
@@ -347,9 +348,9 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
typDecl = "interface{}";
|
typDecl = "interface{}";
|
||||||
}
|
}
|
||||||
return "[]" + typDecl;
|
return "[]" + typDecl;
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[string]" + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner));
|
return getSchemaType(p) + "[string]" + getTypeDeclaration(modelUtils.unaliasSchema(inner));
|
||||||
}
|
}
|
||||||
//return super.getTypeDeclaration(p);
|
//return super.getTypeDeclaration(p);
|
||||||
|
|
||||||
@@ -394,7 +395,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
|
|
||||||
if (ref != null && !ref.isEmpty()) {
|
if (ref != null && !ref.isEmpty()) {
|
||||||
type = openAPIType;
|
type = openAPIType;
|
||||||
} else if ("object".equals(openAPIType) && isAnyTypeSchema(p)) {
|
} else if ("object".equals(openAPIType) && modelUtils.isAnyTypeSchema(p)) {
|
||||||
// Arbitrary type. Note this is not the same thing as free-form object.
|
// Arbitrary type. Note this is not the same thing as free-form object.
|
||||||
type = "interface{}";
|
type = "interface{}";
|
||||||
} else if (typeMapping.containsKey(openAPIType)) {
|
} else if (typeMapping.containsKey(openAPIType)) {
|
||||||
@@ -425,9 +426,9 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema property) {
|
public String toInstantiationType(Schema property) {
|
||||||
if (ModelUtils.isMapSchema(property)) {
|
if (modelUtils.isMapSchema(property)) {
|
||||||
return getTypeDeclaration(property);
|
return getTypeDeclaration(property);
|
||||||
} else if (ModelUtils.isArraySchema(property)) {
|
} else if (modelUtils.isArraySchema(property)) {
|
||||||
return getTypeDeclaration(property);
|
return getTypeDeclaration(property);
|
||||||
}
|
}
|
||||||
return super.toInstantiationType(property);
|
return super.toInstantiationType(property);
|
||||||
|
|||||||
@@ -266,11 +266,11 @@ public abstract class AbstractGraphQLCodegen extends DefaultCodegen implements C
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = (Schema) p.getAdditionalProperties();
|
Schema inner = (Schema) p.getAdditionalProperties();
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
}
|
}
|
||||||
@@ -278,7 +278,7 @@ public abstract class AbstractGraphQLCodegen extends DefaultCodegen implements C
|
|||||||
// Not using the supertype invocation, because we want to UpperCamelize
|
// Not using the supertype invocation, because we want to UpperCamelize
|
||||||
// the type.
|
// the type.
|
||||||
String schemaType = getSchemaType(p);
|
String schemaType = getSchemaType(p);
|
||||||
String nullable = ModelUtils.isNullable(p) ? "" : "!";
|
String nullable = modelUtils.isNullable(p) ? "" : "!";
|
||||||
/*
|
/*
|
||||||
if (p != null && Boolean.TRUE.equals(p.getNullable())) {
|
if (p != null && Boolean.TRUE.equals(p.getNullable())) {
|
||||||
nullable = "";
|
nullable = "";
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ import com.google.common.base.Strings;
|
|||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.Operation;
|
import io.swagger.v3.oas.models.Operation;
|
||||||
import io.swagger.v3.oas.models.PathItem;
|
import io.swagger.v3.oas.models.PathItem;
|
||||||
|
import io.swagger.v3.oas.models.examples.Example;
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
import io.swagger.v3.oas.models.media.ComposedSchema;
|
import io.swagger.v3.oas.models.media.ComposedSchema;
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
import io.swagger.v3.oas.models.media.StringSchema;
|
import io.swagger.v3.oas.models.media.StringSchema;
|
||||||
|
import io.swagger.v3.oas.models.parameters.Parameter;
|
||||||
import io.swagger.v3.oas.models.servers.Server;
|
import io.swagger.v3.oas.models.servers.Server;
|
||||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
@@ -792,13 +794,13 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
Schema<?> schema = ModelUtils.unaliasSchema(this.openAPI, p, importMapping);
|
Schema<?> schema = modelUtils.unaliasSchema(p, importMapping);
|
||||||
Schema<?> target = ModelUtils.isGenerateAliasAsModel() ? p : schema;
|
Schema<?> target = modelUtils.isGenerateAliasAsModel() ? p : schema;
|
||||||
if (ModelUtils.isArraySchema(target)) {
|
if (modelUtils.isArraySchema(target)) {
|
||||||
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
||||||
return getSchemaType(target) + "<" + getTypeDeclaration(items) + ">";
|
return getSchemaType(target) + "<" + getTypeDeclaration(items) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(target)) {
|
} else if (modelUtils.isMapSchema(target)) {
|
||||||
// Note: ModelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
// Note: modelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
||||||
// additionalproperties: true
|
// additionalproperties: true
|
||||||
Schema<?> inner = getAdditionalProperties(target);
|
Schema<?> inner = getAdditionalProperties(target);
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@@ -821,10 +823,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema schema) {
|
public String toDefaultValue(Schema schema) {
|
||||||
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
|
schema = modelUtils.getReferencedSchema(schema);
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (modelUtils.isArraySchema(schema)) {
|
||||||
final String pattern;
|
final String pattern;
|
||||||
if (ModelUtils.isSet(schema)) {
|
if (modelUtils.isSet(schema)) {
|
||||||
String mapInstantiationType = instantiationTypes().getOrDefault("set", "LinkedHashSet");
|
String mapInstantiationType = instantiationTypes().getOrDefault("set", "LinkedHashSet");
|
||||||
pattern = "new " + mapInstantiationType + "<%s>()";
|
pattern = "new " + mapInstantiationType + "<%s>()";
|
||||||
} else {
|
} else {
|
||||||
@@ -834,7 +836,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
||||||
|
|
||||||
String typeDeclaration = getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, items));
|
String typeDeclaration = getTypeDeclaration(modelUtils.unaliasSchema(items));
|
||||||
Object java8obj = additionalProperties.get("java8");
|
Object java8obj = additionalProperties.get("java8");
|
||||||
if (java8obj != null) {
|
if (java8obj != null) {
|
||||||
Boolean java8 = Boolean.valueOf(java8obj.toString());
|
Boolean java8 = Boolean.valueOf(java8obj.toString());
|
||||||
@@ -844,7 +846,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
return String.format(Locale.ROOT, pattern, typeDeclaration);
|
return String.format(Locale.ROOT, pattern, typeDeclaration);
|
||||||
} else if (ModelUtils.isMapSchema(schema) && !(schema instanceof ComposedSchema)) {
|
} else if (modelUtils.isMapSchema(schema) && !(schema instanceof ComposedSchema)) {
|
||||||
if (schema.getProperties() != null && schema.getProperties().size() > 0) {
|
if (schema.getProperties() != null && schema.getProperties().size() > 0) {
|
||||||
// object is complex object with free-form additional properties
|
// object is complex object with free-form additional properties
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
@@ -870,7 +872,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
return String.format(Locale.ROOT, pattern, typeDeclaration);
|
return String.format(Locale.ROOT, pattern, typeDeclaration);
|
||||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(schema.getFormat())) {
|
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(schema.getFormat())) {
|
||||||
return schema.getDefault().toString() + "l";
|
return schema.getDefault().toString() + "l";
|
||||||
@@ -879,26 +881,28 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
} else if (modelUtils.isNumberSchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(schema.getFormat())) {
|
if (SchemaTypeUtil.FLOAT_FORMAT.equals(schema.getFormat())) {
|
||||||
return schema.getDefault().toString() + "f";
|
return schema.getDefault().toString() + "f";
|
||||||
} else {
|
} else if (SchemaTypeUtil.DOUBLE_FORMAT.equals(schema.getFormat())) {
|
||||||
return schema.getDefault().toString() + "d";
|
return schema.getDefault().toString() + "d";
|
||||||
|
} else {
|
||||||
|
return "new BigDecimal(\"" + schema.getDefault().toString() + "\")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
return schema.getDefault().toString();
|
return schema.getDefault().toString();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isURISchema(schema)) {
|
} else if (modelUtils.isURISchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
return "URI.create(\"" + escapeText((String) schema.getDefault()) + "\")";
|
return "URI.create(\"" + escapeText((String) schema.getDefault()) + "\")";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isStringSchema(schema)) {
|
} else if (modelUtils.isStringSchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
String _default;
|
String _default;
|
||||||
if (schema.getDefault() instanceof Date) {
|
if (schema.getDefault() instanceof Date) {
|
||||||
@@ -919,7 +923,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isObjectSchema(schema)) {
|
} else if (modelUtils.isObjectSchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
return super.toDefaultValue(schema);
|
return super.toDefaultValue(schema);
|
||||||
}
|
}
|
||||||
@@ -929,6 +933,37 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
return super.toDefaultValue(schema);
|
return super.toDefaultValue(schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the example value of the parameter. Overrides the
|
||||||
|
* setParameterExampleValue(CodegenParameter, Parameter) method in
|
||||||
|
* DefaultCodegen to always call setParameterExampleValue(CodegenParameter)
|
||||||
|
* in this class, which adds single quotes around strings from the
|
||||||
|
* x-example property.
|
||||||
|
*
|
||||||
|
* @param codegenParameter Codegen parameter
|
||||||
|
* @param parameter Parameter
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setParameterExampleValue(CodegenParameter codegenParameter, Parameter parameter) {
|
||||||
|
if (parameter.getExample() != null) {
|
||||||
|
codegenParameter.example = parameter.getExample().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parameter.getExamples() != null && !parameter.getExamples().isEmpty()) {
|
||||||
|
Example example = parameter.getExamples().values().iterator().next();
|
||||||
|
if (example.getValue() != null) {
|
||||||
|
codegenParameter.example = example.getValue().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Schema schema = parameter.getSchema();
|
||||||
|
if (schema != null && schema.getExample() != null) {
|
||||||
|
codegenParameter.example = schema.getExample().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
setParameterExampleValue(codegenParameter);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setParameterExampleValue(CodegenParameter p) {
|
public void setParameterExampleValue(CodegenParameter p) {
|
||||||
String example;
|
String example;
|
||||||
@@ -957,15 +992,17 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
if (example == null) {
|
if (example == null) {
|
||||||
example = "56";
|
example = "56";
|
||||||
}
|
}
|
||||||
example = example + "L";
|
example = StringUtils.appendIfMissingIgnoreCase(example, "L");
|
||||||
} else if ("Float".equals(type)) {
|
} else if ("Float".equals(type)) {
|
||||||
if (example == null) {
|
if (example == null) {
|
||||||
example = "3.4";
|
example = "3.4";
|
||||||
}
|
}
|
||||||
example = example + "F";
|
example = StringUtils.appendIfMissingIgnoreCase(example, "F");
|
||||||
} else if ("Double".equals(type)) {
|
} else if ("Double".equals(type)) {
|
||||||
example = "3.4";
|
if (example == null) {
|
||||||
example = example + "D";
|
example = "3.4";
|
||||||
|
}
|
||||||
|
example = StringUtils.appendIfMissingIgnoreCase(example, "D");
|
||||||
} else if ("Boolean".equals(type)) {
|
} else if ("Boolean".equals(type)) {
|
||||||
if (example == null) {
|
if (example == null) {
|
||||||
example = "true";
|
example = "true";
|
||||||
@@ -977,6 +1014,14 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
example = "new File(\"" + escapeText(example) + "\")";
|
example = "new File(\"" + escapeText(example) + "\")";
|
||||||
} else if ("Date".equals(type)) {
|
} else if ("Date".equals(type)) {
|
||||||
example = "new Date()";
|
example = "new Date()";
|
||||||
|
} else if ("OffsetDateTime".equals(type)) {
|
||||||
|
example = "OffsetDateTime.now()";
|
||||||
|
} else if ("BigDecimal".equals(type)) {
|
||||||
|
example = "new BigDecimal(78)";
|
||||||
|
} else if (p.allowableValues != null && !p.allowableValues.isEmpty()) {
|
||||||
|
Map<String, Object> allowableValues = p.allowableValues;
|
||||||
|
List<Object> values = (List<Object>) allowableValues.get("values");
|
||||||
|
example = type + ".fromValue(\"" + String.valueOf(values.get(0)) + "\")";
|
||||||
} else if (!languageSpecificPrimitives.contains(type)) {
|
} else if (!languageSpecificPrimitives.contains(type)) {
|
||||||
// type is a model class, e.g. User
|
// type is a model class, e.g. User
|
||||||
example = "new " + type + "()";
|
example = "new " + type + "()";
|
||||||
@@ -1055,7 +1100,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
if (codegenModel.description != null) {
|
if (codegenModel.description != null) {
|
||||||
codegenModel.imports.add("ApiModel");
|
codegenModel.imports.add("ApiModel");
|
||||||
@@ -1139,12 +1184,24 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
itr.remove();
|
itr.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||||
|
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||||
|
for (CodegenOperation op : operationList) {
|
||||||
|
Collection<String> operationImports = new TreeSet<String>();
|
||||||
|
for (CodegenParameter p : op.allParams) {
|
||||||
|
if (importMapping.containsKey(p.dataType)) {
|
||||||
|
operationImports.add(importMapping.get(p.dataType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
op.vendorExtensions.put("x-java-import", operationImports);
|
||||||
|
}
|
||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
super.preprocessOpenAPI(openAPI);
|
super.preprocessOpenAPI();
|
||||||
if (openAPI == null) {
|
if (openAPI == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1156,13 +1213,13 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
for (Operation operation : path.readOperations()) {
|
for (Operation operation : path.readOperations()) {
|
||||||
LOGGER.info("Processing operation " + operation.getOperationId());
|
LOGGER.info("Processing operation " + operation.getOperationId());
|
||||||
if (hasBodyParameter(openAPI, operation) || hasFormParameter(openAPI, operation)) {
|
if (hasBodyParameter(operation) || hasFormParameter(operation)) {
|
||||||
String defaultContentType = hasFormParameter(openAPI, operation) ? "application/x-www-form-urlencoded" : "application/json";
|
String defaultContentType = hasFormParameter(operation) ? "application/x-www-form-urlencoded" : "application/json";
|
||||||
List<String> consumes = new ArrayList<>(getConsumesInfo(openAPI, operation));
|
List<String> consumes = new ArrayList<>(getConsumesInfo(operation));
|
||||||
String contentType = consumes == null || consumes.isEmpty() ? defaultContentType : consumes.get(0);
|
String contentType = consumes == null || consumes.isEmpty() ? defaultContentType : consumes.get(0);
|
||||||
operation.addExtension("x-contentType", contentType);
|
operation.addExtension("x-contentType", contentType);
|
||||||
}
|
}
|
||||||
String accepts = getAccept(openAPI, operation);
|
String accepts = getAccept(operation);
|
||||||
operation.addExtension("x-accepts", accepts);
|
operation.addExtension("x-accepts", accepts);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1214,10 +1271,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getAccept(OpenAPI openAPI, Operation operation) {
|
private String getAccept(Operation operation) {
|
||||||
String accepts = null;
|
String accepts = null;
|
||||||
String defaultContentType = "application/json";
|
String defaultContentType = "application/json";
|
||||||
Set<String> producesInfo = getProducesInfo(openAPI, operation);
|
Set<String> producesInfo = getProducesInfo(operation);
|
||||||
if (producesInfo != null && !producesInfo.isEmpty()) {
|
if (producesInfo != null && !producesInfo.isEmpty()) {
|
||||||
ArrayList<String> produces = new ArrayList<>(producesInfo);
|
ArrayList<String> produces = new ArrayList<>(producesInfo);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
super.preprocessOpenAPI(openAPI);
|
super.preprocessOpenAPI();
|
||||||
/* TODO there should be no need for the following logic
|
/* TODO there should be no need for the following logic
|
||||||
if ("/".equals(swagger.getBasePath())) {
|
if ("/".equals(swagger.getBasePath())) {
|
||||||
swagger.setBasePath("");
|
swagger.setBasePath("");
|
||||||
|
|||||||
@@ -310,13 +310,13 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
Schema<?> schema = ModelUtils.unaliasSchema(this.openAPI, p, importMapping);
|
Schema<?> schema = modelUtils.unaliasSchema(p, importMapping);
|
||||||
Schema<?> target = ModelUtils.isGenerateAliasAsModel() ? p : schema;
|
Schema<?> target = modelUtils.isGenerateAliasAsModel() ? p : schema;
|
||||||
if (ModelUtils.isArraySchema(target)) {
|
if (modelUtils.isArraySchema(target)) {
|
||||||
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
||||||
return getSchemaType(target) + "<" + getTypeDeclaration(items) + ">";
|
return getSchemaType(target) + "<" + getTypeDeclaration(items) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(target)) {
|
} else if (modelUtils.isMapSchema(target)) {
|
||||||
// Note: ModelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
// Note: modelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
||||||
// additionalproperties: true
|
// additionalproperties: true
|
||||||
Schema<?> inner = getAdditionalProperties(target);
|
Schema<?> inner = getAdditionalProperties(target);
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@@ -899,27 +899,27 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isURISchema(p)) {
|
} else if (modelUtils.isURISchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "URI.create('" + p.getDefault() + "')";
|
return "URI.create('" + p.getDefault() + "')";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault() + "\"";
|
return "\"" + p.getDefault() + "\"";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@@ -301,7 +301,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
|||||||
inner = new StringSchema().description("TODO default missing array inner type to string");
|
inner = new StringSchema().description("TODO default missing array inner type to string");
|
||||||
}
|
}
|
||||||
return getTypeDeclaration(inner) + "[]";
|
return getTypeDeclaration(inner) + "[]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined. Default to string");
|
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined. Default to string");
|
||||||
@@ -514,23 +514,23 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + p.getDefault() + "'";
|
return "'" + p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -345,11 +345,11 @@ public abstract class AbstractPythonConnexionServerCodegen extends DefaultCodege
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[str, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[str, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
@@ -372,7 +372,7 @@ public abstract class AbstractPythonConnexionServerCodegen extends DefaultCodege
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
// need vendor extensions for x-openapi-router-controller
|
// need vendor extensions for x-openapi-router-controller
|
||||||
Map<String, PathItem> paths = openAPI.getPaths();
|
Map<String, PathItem> paths = openAPI.getPaths();
|
||||||
if (paths != null) {
|
if (paths != null) {
|
||||||
@@ -704,26 +704,26 @@ public abstract class AbstractPythonConnexionServerCodegen extends DefaultCodege
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
||||||
return "False";
|
return "False";
|
||||||
else
|
else
|
||||||
return "True";
|
return "True";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + (String) p.getDefault() + "'";
|
return "'" + (String) p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,10 +114,10 @@ abstract public class AbstractRubyCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema schema) {
|
public String getTypeDeclaration(Schema schema) {
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (modelUtils.isArraySchema(schema)) {
|
||||||
Schema inner = ((ArraySchema) schema).getItems();
|
Schema inner = ((ArraySchema) schema).getItems();
|
||||||
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(schema)) {
|
} else if (modelUtils.isMapSchema(schema)) {
|
||||||
Schema inner = getAdditionalProperties(schema);
|
Schema inner = getAdditionalProperties(schema);
|
||||||
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||||
}
|
}
|
||||||
@@ -127,11 +127,11 @@ abstract public class AbstractRubyCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema schema) {
|
public String toInstantiationType(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
return instantiationTypes.get("map");
|
return instantiationTypes.get("map");
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
String parentType;
|
String parentType;
|
||||||
if (ModelUtils.isSet(schema)) {
|
if (modelUtils.isSet(schema)) {
|
||||||
parentType = "set";
|
parentType = "set";
|
||||||
} else {
|
} else {
|
||||||
parentType = "array";
|
parentType = "array";
|
||||||
@@ -143,12 +143,12 @@ abstract public class AbstractRubyCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
p = ModelUtils.getReferencedSchema(this.openAPI, p);
|
p = modelUtils.getReferencedSchema(p);
|
||||||
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isIntegerSchema(p) || modelUtils.isNumberSchema(p) || modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (p.getDefault() instanceof Date) {
|
if (p.getDefault() instanceof Date) {
|
||||||
Date date = (Date) p.getDefault();
|
Date date = (Date) p.getDefault();
|
||||||
|
|||||||
@@ -320,11 +320,11 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
@@ -335,7 +335,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String getSchemaType(Schema p) {
|
public String getSchemaType(Schema p) {
|
||||||
String openAPIType = super.getSchemaType(p);
|
String openAPIType = super.getSchemaType(p);
|
||||||
if (ModelUtils.isSet(p)) {
|
if (modelUtils.isSet(p)) {
|
||||||
openAPIType = "set";
|
openAPIType = "set";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,13 +353,13 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return instantiationTypes.get("map") + "[String, " + inner + "]";
|
return instantiationTypes.get("map") + "[String, " + inner + "]";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
return ( ModelUtils.isSet(ap) ? instantiationTypes.get("set") : instantiationTypes.get("array") ) + "[" + inner + "]";
|
return ( modelUtils.isSet(ap) ? instantiationTypes.get("set") : instantiationTypes.get("array") ) + "[" + inner + "]";
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -372,24 +372,24 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// comment out the following as the default value is no handled differently
|
// comment out the following as the default value is no handled differently
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return "new HashMap[String, " + inner + "]() ";
|
return "new HashMap[String, " + inner + "]() ";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
String genericType;
|
String genericType;
|
||||||
if (ModelUtils.isSet(ap)) {
|
if (modelUtils.isSet(ap)) {
|
||||||
genericType = instantiationTypes.get("set");
|
genericType = instantiationTypes.get("set");
|
||||||
} else {
|
} else {
|
||||||
genericType = instantiationTypes.get("array");
|
genericType = instantiationTypes.get("array");
|
||||||
@@ -410,7 +410,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
|
|
||||||
// Assume that any other generic types can be new'd up.
|
// Assume that any other generic types can be new'd up.
|
||||||
return "new " + genericType + "[" + inner + "]() ";
|
return "new " + genericType + "[" + inner + "]() ";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@@ -427,9 +427,9 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public CodegenProperty fromProperty(String name, Schema p) {
|
public CodegenProperty fromProperty(String name, Schema p) {
|
||||||
CodegenProperty prop = super.fromProperty(name, p);
|
CodegenProperty prop = super.fromProperty(name, p);
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema as = (ArraySchema) p;
|
ArraySchema as = (ArraySchema) p;
|
||||||
if (ModelUtils.isSet(as)) {
|
if (modelUtils.isSet(as)) {
|
||||||
prop.containerType = "set";
|
prop.containerType = "set";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
|
|
||||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||||
|
|
||||||
@@ -413,16 +413,16 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
Schema<?> items = getSchemaItems((ArraySchema) p);
|
Schema<?> items = getSchemaItems((ArraySchema) p);
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, items)) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(modelUtils.unaliasSchema(items)) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema<?> inner = getSchemaAdditionalProperties(p);
|
Schema<?> inner = getSchemaAdditionalProperties(p);
|
||||||
String nullSafeSuffix = getNullSafeAdditionalProps() ? " | undefined" : "";
|
String nullSafeSuffix = getNullSafeAdditionalProps() ? " | undefined" : "";
|
||||||
return "{ [key: string]: " + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner)) + nullSafeSuffix + "; }";
|
return "{ [key: string]: " + getTypeDeclaration(modelUtils.unaliasSchema(inner)) + nullSafeSuffix + "; }";
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isFileSchema(p)) {
|
||||||
return "any";
|
return "any";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isBinarySchema(p)) {
|
||||||
return "any";
|
return "any";
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
@@ -432,37 +432,37 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
protected String getParameterDataType(Parameter parameter, Schema p) {
|
protected String getParameterDataType(Parameter parameter, Schema p) {
|
||||||
// handle enums of various data types
|
// handle enums of various data types
|
||||||
Schema inner;
|
Schema inner;
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema mp1 = (ArraySchema) p;
|
ArraySchema mp1 = (ArraySchema) p;
|
||||||
inner = mp1.getItems();
|
inner = mp1.getItems();
|
||||||
return this.getSchemaType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
|
return this.getSchemaType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
inner = getAdditionalProperties(p);
|
inner = getAdditionalProperties(p);
|
||||||
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
|
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
// Handle string enums
|
// Handle string enums
|
||||||
if (p.getEnum() != null) {
|
if (p.getEnum() != null) {
|
||||||
return enumValuesToEnumTypeUnion(p.getEnum(), "string");
|
return enumValuesToEnumTypeUnion(p.getEnum(), "string");
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
// Handle integer enums
|
// Handle integer enums
|
||||||
if (p.getEnum() != null) {
|
if (p.getEnum() != null) {
|
||||||
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
// Handle double enums
|
// Handle double enums
|
||||||
if (p.getEnum() != null) {
|
if (p.getEnum() != null) {
|
||||||
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* TODO revise the logic below
|
/* TODO revise the logic below
|
||||||
else if (ModelUtils.isDateSchema(p)) {
|
else if (modelUtils.isDateSchema(p)) {
|
||||||
// Handle date enums
|
// Handle date enums
|
||||||
DateSchema sp = (DateSchema) p;
|
DateSchema sp = (DateSchema) p;
|
||||||
if (sp.getEnum() != null) {
|
if (sp.getEnum() != null) {
|
||||||
return enumValuesToEnumTypeUnion(sp.getEnum(), "string");
|
return enumValuesToEnumTypeUnion(sp.getEnum(), "string");
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// Handle datetime enums
|
// Handle datetime enums
|
||||||
DateTimeSchema sp = (DateTimeSchema) p;
|
DateTimeSchema sp = (DateTimeSchema) p;
|
||||||
if (sp.getEnum() != null) {
|
if (sp.getEnum() != null) {
|
||||||
@@ -510,27 +510,27 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isNumberSchema(p) || ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p) || modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + (String) p.getDefault() + "'";
|
return "'" + (String) p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
@@ -551,7 +551,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
public String getSchemaType(Schema p) {
|
public String getSchemaType(Schema p) {
|
||||||
String openAPIType = super.getSchemaType(p);
|
String openAPIType = super.getSchemaType(p);
|
||||||
String type = null;
|
String type = null;
|
||||||
if (ModelUtils.isComposedSchema(p)) {
|
if (modelUtils.isComposedSchema(p)) {
|
||||||
return openAPIType;
|
return openAPIType;
|
||||||
} else if (typeMapping.containsKey(openAPIType)) {
|
} else if (typeMapping.containsKey(openAPIType)) {
|
||||||
type = typeMapping.get(openAPIType);
|
type = typeMapping.get(openAPIType);
|
||||||
@@ -898,7 +898,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
|
|
||||||
return filteredSchemas.stream().map(schema -> {
|
return filteredSchemas.stream().map(schema -> {
|
||||||
String schemaType = getSchemaType(schema);
|
String schemaType = getSchemaType(schema);
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema ap = (ArraySchema) schema;
|
ArraySchema ap = (ArraySchema) schema;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
schemaType = schemaType + "<" + getSchemaType(inner) + ">";
|
schemaType = schemaType + "<" + getSchemaType(inner) + ">";
|
||||||
|
|||||||
@@ -223,11 +223,11 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
String calloutLabel = openAPI.getInfo().getTitle();
|
String calloutLabel = openAPI.getInfo().getTitle();
|
||||||
if (StringUtils.isNotBlank(namedCredential)) {
|
if (StringUtils.isNotBlank(namedCredential)) {
|
||||||
calloutLabel = namedCredential;
|
calloutLabel = namedCredential;
|
||||||
@@ -221,24 +221,24 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
String out = null;
|
String out = null;
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
Schema inner = ((ArraySchema) p).getItems();
|
Schema inner = ((ArraySchema) p).getItems();
|
||||||
out = String.format(
|
out = String.format(
|
||||||
Locale.ROOT,
|
Locale.ROOT,
|
||||||
"new List<%s>()",
|
"new List<%s>()",
|
||||||
inner == null ? "Object" : getTypeDeclaration(inner)
|
inner == null ? "Object" : getTypeDeclaration(inner)
|
||||||
);
|
);
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
// true => "true", false => "false", null => "null"
|
// true => "true", false => "false", null => "null"
|
||||||
out = String.valueOf(p.getDefault());
|
out = String.valueOf(p.getDefault());
|
||||||
} else if (ModelUtils.isLongSchema(p)) {
|
} else if (modelUtils.isLongSchema(p)) {
|
||||||
Long def = (Long) p.getDefault();
|
Long def = (Long) p.getDefault();
|
||||||
out = def == null ? out : def.toString() + "L";
|
out = def == null ? out : def.toString() + "L";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
String s = inner == null ? "Object" : getTypeDeclaration(inner);
|
String s = inner == null ? "Object" : getTypeDeclaration(inner);
|
||||||
out = String.format(Locale.ROOT, "new Map<String, %s>()", s);
|
out = String.format(Locale.ROOT, "new Map<String, %s>()", s);
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
String def = p.getDefault().toString();
|
String def = p.getDefault().toString();
|
||||||
if (def != null) {
|
if (def != null) {
|
||||||
|
|||||||
@@ -359,14 +359,14 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processOpenAPI(OpenAPI openAPI) {
|
public void processOpenAPI() {
|
||||||
if (this.includeSpecMarkupLambda != null) {
|
if (this.includeSpecMarkupLambda != null) {
|
||||||
LOGGER.debug("specs: " + ": " + this.includeSpecMarkupLambda.resetCounter());
|
LOGGER.debug("specs: " + ": " + this.includeSpecMarkupLambda.resetCounter());
|
||||||
}
|
}
|
||||||
if (this.includeSnippetMarkupLambda != null) {
|
if (this.includeSnippetMarkupLambda != null) {
|
||||||
LOGGER.debug("snippets: " + ": " + this.includeSnippetMarkupLambda.resetCounter());
|
LOGGER.debug("snippets: " + ": " + this.includeSnippetMarkupLambda.resetCounter());
|
||||||
}
|
}
|
||||||
super.processOpenAPI(openAPI);
|
super.processOpenAPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -304,8 +304,8 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
super.preprocessOpenAPI(openAPI);
|
super.preprocessOpenAPI();
|
||||||
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
||||||
additionalProperties.put("serverHost", url.getHost());
|
additionalProperties.put("serverHost", url.getHost());
|
||||||
additionalProperties.put("serverPort", URLPathUtils.getPort(url, 8080));
|
additionalProperties.put("serverPort", URLPathUtils.getPort(url, 8080));
|
||||||
@@ -450,7 +450,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String getNullableType(Schema p, String type) {
|
public String getNullableType(Schema p, String type) {
|
||||||
if (languageSpecificPrimitives.contains(type)) {
|
if (languageSpecificPrimitives.contains(type)) {
|
||||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||||
return type + "?";
|
return type + "?";
|
||||||
} else {
|
} else {
|
||||||
return type;
|
return type;
|
||||||
|
|||||||
@@ -423,11 +423,11 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
@@ -619,7 +619,7 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
@Override
|
@Override
|
||||||
public CodegenOperation fromOperation(String path, String httpMethod,
|
public CodegenOperation fromOperation(String path, String httpMethod,
|
||||||
Operation operation, List<Server> servers) {
|
Operation operation, List<Server> servers) {
|
||||||
Map<String, Schema> definitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> definitions = modelUtils.getSchemas();
|
||||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -663,8 +663,8 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
* If the operation produces Json and has nonempty example
|
* If the operation produces Json and has nonempty example
|
||||||
* try to reformat it.
|
* try to reformat it.
|
||||||
*/
|
*/
|
||||||
if (getConsumesInfo(this.openAPI, operation) != null
|
if (getConsumesInfo(operation) != null
|
||||||
&& getConsumesInfo(this.openAPI, operation).contains("application/json")
|
&& getConsumesInfo(operation).contains("application/json")
|
||||||
&& definitions.get(p.dataType).getExample() != null) {
|
&& definitions.get(p.dataType).getExample() != null) {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
@@ -697,8 +697,8 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
* @param openAPI [description]
|
* @param openAPI [description]
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
super.preprocessOpenAPI(openAPI);
|
super.preprocessOpenAPI();
|
||||||
|
|
||||||
/* TODO need to revise the logic below
|
/* TODO need to revise the logic below
|
||||||
if ("/".equals(openAPI.getServers())) {
|
if ("/".equals(openAPI.getServers())) {
|
||||||
|
|||||||
@@ -296,10 +296,10 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema schema) {
|
public String getTypeDeclaration(Schema schema) {
|
||||||
/* comment out below as we'll do it in the template instead
|
/* comment out below as we'll do it in the template instead
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (modelUtils.isArraySchema(schema)) {
|
||||||
Schema inner = ((ArraySchema) schema).getItems();
|
Schema inner = ((ArraySchema) schema).getItems();
|
||||||
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(schema)) {
|
} else if (modelUtils.isMapSchema(schema)) {
|
||||||
Schema inner = (Schema) schema.getAdditionalProperties();
|
Schema inner = (Schema) schema.getAdditionalProperties();
|
||||||
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||||
}
|
}
|
||||||
@@ -310,11 +310,11 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isIntegerSchema(p) || modelUtils.isNumberSchema(p) || modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + escapeText((String) p.getDefault()) + "'";
|
return "'" + escapeText((String) p.getDefault()) + "'";
|
||||||
}
|
}
|
||||||
@@ -327,17 +327,17 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
public String toExampleValue(Schema schema) {
|
public String toExampleValue(Schema schema) {
|
||||||
String example = super.toExampleValue(schema);
|
String example = super.toExampleValue(schema);
|
||||||
|
|
||||||
if (ModelUtils.isNullType(schema) && null != example) {
|
if (modelUtils.isNullType(schema) && null != example) {
|
||||||
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
|
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
|
||||||
// though this tooling supports it.
|
// though this tooling supports it.
|
||||||
return "NULL";
|
return "NULL";
|
||||||
}
|
}
|
||||||
// correct "'"s into "'"s after toString()
|
// correct "'"s into "'"s after toString()
|
||||||
if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null) {
|
if (modelUtils.isStringSchema(schema) && schema.getDefault() != null) {
|
||||||
example = (String) schema.getDefault();
|
example = (String) schema.getDefault();
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(example) && !"null".equals(example)) {
|
if (StringUtils.isNotBlank(example) && !"null".equals(example)) {
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
example = "\"" + example + "\"";
|
example = "\"" + example + "\"";
|
||||||
}
|
}
|
||||||
return example;
|
return example;
|
||||||
@@ -346,7 +346,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
if (schema.getEnum() != null && !schema.getEnum().isEmpty()) {
|
if (schema.getEnum() != null && !schema.getEnum().isEmpty()) {
|
||||||
// Enum case:
|
// Enum case:
|
||||||
example = schema.getEnum().get(0).toString();
|
example = schema.getEnum().get(0).toString();
|
||||||
/* if (ModelUtils.isStringSchema(schema)) {
|
/* if (modelUtils.isStringSchema(schema)) {
|
||||||
example = "'" + escapeText(example) + "'";
|
example = "'" + escapeText(example) + "'";
|
||||||
}*/
|
}*/
|
||||||
if (null == example)
|
if (null == example)
|
||||||
@@ -355,8 +355,8 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
return example;
|
return example;
|
||||||
} else if (null != schema.get$ref()) {
|
} else if (null != schema.get$ref()) {
|
||||||
// $ref case:
|
// $ref case:
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
String ref = ModelUtils.getSimpleRef(schema.get$ref());
|
String ref = modelUtils.getSimpleRef(schema.get$ref());
|
||||||
if (allDefinitions != null) {
|
if (allDefinitions != null) {
|
||||||
Schema refSchema = allDefinitions.get(ref);
|
Schema refSchema = allDefinitions.get(ref);
|
||||||
if (null == refSchema) {
|
if (null == refSchema) {
|
||||||
@@ -372,18 +372,18 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
LOGGER.warn("allDefinitions not defined in toExampleValue!\n");
|
LOGGER.warn("allDefinitions not defined in toExampleValue!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelUtils.isDateSchema(schema)) {
|
if (modelUtils.isDateSchema(schema)) {
|
||||||
example = "\"2013-10-20\"";
|
example = "\"2013-10-20\"";
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isDateTimeSchema(schema)) {
|
} else if (modelUtils.isDateTimeSchema(schema)) {
|
||||||
example = "\"2013-10-20T19:20:30+01:00\"";
|
example = "\"2013-10-20T19:20:30+01:00\"";
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isBinarySchema(schema)) {
|
} else if (modelUtils.isBinarySchema(schema)) {
|
||||||
example = "instantiate_binary_t(\"blah\", 5)";
|
example = "instantiate_binary_t(\"blah\", 5)";
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isByteArraySchema(schema)) {
|
} else if (modelUtils.isByteArraySchema(schema)) {
|
||||||
example = "YQ==";
|
example = "YQ==";
|
||||||
} else if (ModelUtils.isStringSchema(schema)) {
|
} else if (modelUtils.isStringSchema(schema)) {
|
||||||
// decimal (type: string, format: decimal)
|
// decimal (type: string, format: decimal)
|
||||||
if ("number".equalsIgnoreCase(schema.getFormat())) {
|
if ("number".equalsIgnoreCase(schema.getFormat())) {
|
||||||
return "1";
|
return "1";
|
||||||
@@ -398,29 +398,29 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
example = "";
|
example = "";
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
example += i;
|
example += i;
|
||||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||||
if (schema.getMinimum() != null)
|
if (schema.getMinimum() != null)
|
||||||
example = schema.getMinimum().toString();
|
example = schema.getMinimum().toString();
|
||||||
else
|
else
|
||||||
example = "56";
|
example = "56";
|
||||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
} else if (modelUtils.isNumberSchema(schema)) {
|
||||||
if (schema.getMinimum() != null)
|
if (schema.getMinimum() != null)
|
||||||
example = schema.getMinimum().toString();
|
example = schema.getMinimum().toString();
|
||||||
else
|
else
|
||||||
example = "1.337";
|
example = "1.337";
|
||||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||||
example = "1";
|
example = "1";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
example = "list_create()";
|
example = "list_create()";
|
||||||
} else if (ModelUtils.isMapSchema(schema)) {
|
} else if (modelUtils.isMapSchema(schema)) {
|
||||||
example = "list_create()";
|
example = "list_create()";
|
||||||
} else if (ModelUtils.isObjectSchema(schema)) {
|
} else if (modelUtils.isObjectSchema(schema)) {
|
||||||
return null; // models are managed at moustache level
|
return null; // models are managed at moustache level
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("Type " + schema.getType() + " not handled properly in toExampleValue");
|
LOGGER.warn("Type " + schema.getType() + " not handled properly in toExampleValue");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
example = "\"" + escapeText(example) + "\"";
|
example = "\"" + escapeText(example) + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -716,7 +716,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
if (openAPI.getInfo() != null) {
|
if (openAPI.getInfo() != null) {
|
||||||
Info info = openAPI.getInfo();
|
Info info = openAPI.getInfo();
|
||||||
setProjectName((escapeText(info.getTitle())));
|
setProjectName((escapeText(info.getTitle())));
|
||||||
@@ -744,7 +744,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
@Override
|
@Override
|
||||||
public CodegenProperty fromProperty(String name, Schema p) {
|
public CodegenProperty fromProperty(String name, Schema p) {
|
||||||
CodegenProperty cm = super.fromProperty(name, p);
|
CodegenProperty cm = super.fromProperty(name, p);
|
||||||
Schema ref = ModelUtils.getReferencedSchema(openAPI, p);
|
Schema ref = modelUtils.getReferencedSchema(p);
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
if (ref.getEnum() != null) {
|
if (ref.getEnum() != null) {
|
||||||
cm.isEnum = true;
|
cm.isEnum = true;
|
||||||
|
|||||||
@@ -588,7 +588,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
||||||
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||||
@@ -965,14 +965,14 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema schema) {
|
public String toInstantiationType(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
Schema additionalProperties = getAdditionalProperties(schema);
|
Schema additionalProperties = getAdditionalProperties(schema);
|
||||||
String inner = getSchemaType(additionalProperties);
|
String inner = getSchemaType(additionalProperties);
|
||||||
if (ModelUtils.isMapSchema(additionalProperties)) {
|
if (modelUtils.isMapSchema(additionalProperties)) {
|
||||||
inner = toInstantiationType(additionalProperties);
|
inner = toInstantiationType(additionalProperties);
|
||||||
}
|
}
|
||||||
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema arraySchema = (ArraySchema) schema;
|
ArraySchema arraySchema = (ArraySchema) schema;
|
||||||
String inner = getSchemaType(arraySchema.getItems());
|
String inner = getSchemaType(arraySchema.getItems());
|
||||||
return instantiationTypes.get("array") + "<" + inner + ">";
|
return instantiationTypes.get("array") + "<" + inner + ">";
|
||||||
@@ -984,7 +984,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String getNullableType(Schema p, String type) {
|
public String getNullableType(Schema p, String type) {
|
||||||
if (languageSpecificPrimitives.contains(type)) {
|
if (languageSpecificPrimitives.contains(type)) {
|
||||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||||
return type + "?";
|
return type + "?";
|
||||||
} else {
|
} else {
|
||||||
return type;
|
return type;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
|||||||
private static final String PACKAGE_CONTEXT = "packageContext";
|
private static final String PACKAGE_CONTEXT = "packageContext";
|
||||||
private static final String ASYNC_SERVER = "asyncServer";
|
private static final String ASYNC_SERVER = "asyncServer";
|
||||||
|
|
||||||
private static final Map<String, Predicate<Schema>> propertyToOpenAPITypeMapping =
|
private final Map<String, Predicate<Schema>> propertyToOpenAPITypeMapping =
|
||||||
createPropertyToOpenAPITypeMapping();
|
createPropertyToOpenAPITypeMapping();
|
||||||
|
|
||||||
private String packageGuid = "{" + randomUUID().toString().toUpperCase(Locale.ROOT) + "}";
|
private String packageGuid = "{" + randomUUID().toString().toUpperCase(Locale.ROOT) + "}";
|
||||||
@@ -118,8 +118,6 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
|||||||
addSwitch(ASYNC_SERVER, "Set to true to enable the generation of async routes/endpoints.", this.asyncServer);
|
addSwitch(ASYNC_SERVER, "Set to true to enable the generation of async routes/endpoints.", this.asyncServer);
|
||||||
typeMapping.putAll(nodaTimeTypesMappings());
|
typeMapping.putAll(nodaTimeTypesMappings());
|
||||||
languageSpecificPrimitives.addAll(nodaTimePrimitiveTypes());
|
languageSpecificPrimitives.addAll(nodaTimePrimitiveTypes());
|
||||||
|
|
||||||
importMapping.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -272,7 +270,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
|||||||
private void postProcessParentModels(final Map<String, Object> models) {
|
private void postProcessParentModels(final Map<String, Object> models) {
|
||||||
LOGGER.debug("Processing parents: " + parentModels);
|
LOGGER.debug("Processing parents: " + parentModels);
|
||||||
for (final String parent : parentModels) {
|
for (final String parent : parentModels) {
|
||||||
final CodegenModel parentModel = ModelUtils.getModelByName(parent, models);
|
final CodegenModel parentModel = modelUtils.getModelByName(parent, models);
|
||||||
if (parentModel != null) {
|
if (parentModel != null) {
|
||||||
parentModel.hasChildren = true;
|
parentModel.hasChildren = true;
|
||||||
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
||||||
@@ -375,7 +373,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(final OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
||||||
String path = URLPathUtils.getPath(url, "/");
|
String path = URLPathUtils.getPath(url, "/");
|
||||||
final String packageContextOption = (String) additionalProperties.get(PACKAGE_CONTEXT);
|
final String packageContextOption = (String) additionalProperties.get(PACKAGE_CONTEXT);
|
||||||
@@ -399,17 +397,17 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
|||||||
return super.getSchemaType(property);
|
return super.getSchemaType(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, Predicate<Schema>> createPropertyToOpenAPITypeMapping() {
|
private Map<String, Predicate<Schema>> createPropertyToOpenAPITypeMapping() {
|
||||||
final ImmutableMap.Builder<String, Predicate<Schema>> mapping = ImmutableMap.builder();
|
final ImmutableMap.Builder<String, Predicate<Schema>> mapping = ImmutableMap.builder();
|
||||||
mapping.put("time", timeProperty());
|
mapping.put("time", timeProperty());
|
||||||
return mapping.build();
|
return mapping.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Predicate<Schema> timeProperty() {
|
private Predicate<Schema> timeProperty() {
|
||||||
return new Predicate<Schema>() {
|
return new Predicate<Schema>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Schema property) {
|
public boolean apply(Schema property) {
|
||||||
return ModelUtils.isStringSchema(property) && "time".equalsIgnoreCase(property.getFormat());
|
return modelUtils.isStringSchema(property) && "time".equalsIgnoreCase(property.getFormat());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import java.io.File;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||||
@@ -305,7 +306,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
||||||
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||||
@@ -400,7 +401,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String getNullableType(Schema p, String type) {
|
public String getNullableType(Schema p, String type) {
|
||||||
if (languageSpecificPrimitives.contains(type)) {
|
if (languageSpecificPrimitives.contains(type)) {
|
||||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||||
return type + "?";
|
return type + "?";
|
||||||
} else {
|
} else {
|
||||||
return type;
|
return type;
|
||||||
@@ -547,7 +548,6 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
additionalProperties.put(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES, optionalEmitDefaultValuesFlag);
|
additionalProperties.put(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES, optionalEmitDefaultValuesFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) {
|
if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) {
|
||||||
setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING));
|
setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING));
|
||||||
}
|
}
|
||||||
@@ -561,13 +561,24 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
clientPackage = "Client";
|
clientPackage = "Client";
|
||||||
|
|
||||||
String framework = (String) additionalProperties.getOrDefault(CodegenConstants.DOTNET_FRAMEWORK, defaultFramework.name);
|
String framework = (String) additionalProperties.getOrDefault(CodegenConstants.DOTNET_FRAMEWORK, defaultFramework.name);
|
||||||
|
boolean strategyMatched = false;
|
||||||
FrameworkStrategy strategy = defaultFramework;
|
FrameworkStrategy strategy = defaultFramework;
|
||||||
for (FrameworkStrategy frameworkStrategy : frameworkStrategies) {
|
for (FrameworkStrategy frameworkStrategy : frameworkStrategies) {
|
||||||
if (framework.equals(frameworkStrategy.name)) {
|
if (framework.equals(frameworkStrategy.name)) {
|
||||||
strategy = frameworkStrategy;
|
strategy = frameworkStrategy;
|
||||||
|
strategyMatched = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// throws exception if the input targetFramework is invalid
|
||||||
|
if (strategyMatched == false) {
|
||||||
|
throw new IllegalArgumentException("Invalid .NET framework version: " +
|
||||||
|
framework + ". List of supported versions: " +
|
||||||
|
frameworkStrategies.stream()
|
||||||
|
.map(p -> p.name)
|
||||||
|
.collect(Collectors.joining(", ")));
|
||||||
|
}
|
||||||
|
|
||||||
strategy.configureAdditionalProperties(additionalProperties);
|
strategy.configureAdditionalProperties(additionalProperties);
|
||||||
|
|
||||||
setTargetFrameworkNuget(strategy.getNugetFrameworkIdentifier());
|
setTargetFrameworkNuget(strategy.getNugetFrameworkIdentifier());
|
||||||
@@ -710,7 +721,11 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
|
|
||||||
public void setTargetFramework(String dotnetFramework) {
|
public void setTargetFramework(String dotnetFramework) {
|
||||||
if (!frameworks.containsKey(dotnetFramework)) {
|
if (!frameworks.containsKey(dotnetFramework)) {
|
||||||
LOGGER.warn("Invalid .NET framework version, defaulting to " + this.targetFramework);
|
throw new IllegalArgumentException("Invalid .NET framework version: " +
|
||||||
|
dotnetFramework + ". List of supported versions: " +
|
||||||
|
frameworkStrategies.stream()
|
||||||
|
.map(p -> p.name)
|
||||||
|
.collect(Collectors.joining(", ")));
|
||||||
} else {
|
} else {
|
||||||
this.targetFramework = dotnetFramework;
|
this.targetFramework = dotnetFramework;
|
||||||
}
|
}
|
||||||
@@ -953,14 +968,14 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema schema) {
|
public String toInstantiationType(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
Schema additionalProperties = getAdditionalProperties(schema);
|
Schema additionalProperties = getAdditionalProperties(schema);
|
||||||
String inner = getSchemaType(additionalProperties);
|
String inner = getSchemaType(additionalProperties);
|
||||||
if (ModelUtils.isMapSchema(additionalProperties)) {
|
if (modelUtils.isMapSchema(additionalProperties)) {
|
||||||
inner = toInstantiationType(additionalProperties);
|
inner = toInstantiationType(additionalProperties);
|
||||||
}
|
}
|
||||||
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema arraySchema = (ArraySchema) schema;
|
ArraySchema arraySchema = (ArraySchema) schema;
|
||||||
String inner = getSchemaType(arraySchema.getItems());
|
String inner = getSchemaType(arraySchema.getItems());
|
||||||
return instantiationTypes.get("array") + "<" + inner + ">";
|
return instantiationTypes.get("array") + "<" + inner + ">";
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
|||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
|
|
||||||
return "(s/coll-of " + getTypeDeclaration(inner) + ")";
|
return "(s/coll-of " + getTypeDeclaration(inner) + ")";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = (Schema) p.getAdditionalProperties();
|
Schema inner = (Schema) p.getAdditionalProperties();
|
||||||
|
|
||||||
return "(s/map-of string? " + getTypeDeclaration(inner) + ")";
|
return "(s/map-of string? " + getTypeDeclaration(inner) + ")";
|
||||||
@@ -216,8 +216,8 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
super.preprocessOpenAPI(openAPI);
|
super.preprocessOpenAPI();
|
||||||
|
|
||||||
if (additionalProperties.containsKey(PROJECT_NAME)) {
|
if (additionalProperties.containsKey(PROJECT_NAME)) {
|
||||||
projectName = ((String) additionalProperties.get(PROJECT_NAME));
|
projectName = ((String) additionalProperties.get(PROJECT_NAME));
|
||||||
|
|||||||
@@ -102,11 +102,11 @@ public class ConfluenceWikiCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,438 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* https://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.Operation;
|
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
|
||||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
|
||||||
import io.swagger.v3.oas.models.servers.Server;
|
|
||||||
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.underscore;
|
|
||||||
|
|
||||||
public class CppOatppServerCodegen extends AbstractCppCodegen {
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(CppOatppServerCodegen.class);
|
|
||||||
|
|
||||||
protected String implFolder = "impl";
|
|
||||||
protected boolean isAddExternalLibs = true;
|
|
||||||
protected boolean isUseStructModel = false;
|
|
||||||
public static final String OPTIONAL_EXTERNAL_LIB = "addExternalLibs";
|
|
||||||
public static final String OPTIONAL_EXTERNAL_LIB_DESC = "Add the Possibility to fetch and compile external Libraries needed by this Framework.";
|
|
||||||
public static final String OPTION_USE_STRUCT_MODEL = "useStructModel";
|
|
||||||
public static final String OPTION_USE_STRUCT_MODEL_DESC = "Use struct-based model template instead of get/set-based model template";
|
|
||||||
public static final String HELPERS_PACKAGE_NAME = "helpersPackage";
|
|
||||||
public static final String HELPERS_PACKAGE_NAME_DESC = "Specify the package name to be used for the helpers (e.g. org.openapitools.server.helpers).";
|
|
||||||
protected final String PREFIX = "";
|
|
||||||
protected String helpersPackage = "";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CodegenType getTag() {
|
|
||||||
return CodegenType.SERVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "cpp-oatpp-server";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
// Ref: https://github.com/oatpp/oatpp
|
|
||||||
return "Generates a C++ API server (based on Oat++)";
|
|
||||||
}
|
|
||||||
|
|
||||||
public CppOatppServerCodegen() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(modelNamePrefix)) {
|
|
||||||
modelNamePrefix = PREFIX;
|
|
||||||
}
|
|
||||||
|
|
||||||
helpersPackage = "org.openapitools.server.helpers";
|
|
||||||
apiPackage = "org.openapitools.server.api";
|
|
||||||
modelPackage = "org.openapitools.server.model";
|
|
||||||
|
|
||||||
apiTemplateFiles.put("api-header.mustache", ".h");
|
|
||||||
apiTemplateFiles.put("api-source.mustache", ".cpp");
|
|
||||||
apiTemplateFiles.put("api-impl-header.mustache", ".h");
|
|
||||||
apiTemplateFiles.put("api-impl-source.mustache", ".cpp");
|
|
||||||
|
|
||||||
embeddedTemplateDir = templateDir = "cpp-oatpp-server";
|
|
||||||
|
|
||||||
cliOptions.clear();
|
|
||||||
addSwitch(OPTIONAL_EXTERNAL_LIB, OPTIONAL_EXTERNAL_LIB_DESC, this.isAddExternalLibs);
|
|
||||||
addOption(HELPERS_PACKAGE_NAME, HELPERS_PACKAGE_NAME_DESC, this.helpersPackage);
|
|
||||||
addOption(RESERVED_WORD_PREFIX_OPTION, RESERVED_WORD_PREFIX_DESC, this.reservedWordPrefix);
|
|
||||||
addSwitch(OPTION_USE_STRUCT_MODEL, OPTION_USE_STRUCT_MODEL_DESC, this.isUseStructModel);
|
|
||||||
addOption(VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_OPTION,
|
|
||||||
VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_DESC,
|
|
||||||
Boolean.toString(this.variableNameFirstCharacterUppercase));
|
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
|
|
||||||
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
|
|
||||||
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
|
|
||||||
supportingFiles.add(new SupportingFile("cmake.mustache", "", "CMakeLists.txt"));
|
|
||||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
|
||||||
|
|
||||||
languageSpecificPrimitives = new HashSet<String>(
|
|
||||||
Arrays.asList("int", "char", "bool", "long", "float", "double", "int32_t", "int64_t"));
|
|
||||||
|
|
||||||
typeMapping = new HashMap<String, String>();
|
|
||||||
typeMapping.put("date", "std::string");
|
|
||||||
typeMapping.put("DateTime", "std::string");
|
|
||||||
typeMapping.put("string", "std::string");
|
|
||||||
typeMapping.put("integer", "int32_t");
|
|
||||||
typeMapping.put("long", "int64_t");
|
|
||||||
typeMapping.put("boolean", "bool");
|
|
||||||
typeMapping.put("array", "std::vector");
|
|
||||||
typeMapping.put("map", "std::map");
|
|
||||||
typeMapping.put("file", "std::string");
|
|
||||||
typeMapping.put("object", "Object");
|
|
||||||
typeMapping.put("binary", "std::string");
|
|
||||||
typeMapping.put("number", "double");
|
|
||||||
typeMapping.put("UUID", "std::string");
|
|
||||||
typeMapping.put("URI", "std::string");
|
|
||||||
typeMapping.put("ByteArray", "std::string");
|
|
||||||
|
|
||||||
importMapping = new HashMap<String, String>();
|
|
||||||
importMapping.put("std::vector", "#include <vector>");
|
|
||||||
importMapping.put("std::map", "#include <map>");
|
|
||||||
importMapping.put("std::string", "#include <string>");
|
|
||||||
importMapping.put("Object", "#include \"Object.h\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processOpts() {
|
|
||||||
super.processOpts();
|
|
||||||
if (additionalProperties.containsKey(HELPERS_PACKAGE_NAME)) {
|
|
||||||
helpersPackage = (String) additionalProperties.get(HELPERS_PACKAGE_NAME);
|
|
||||||
}
|
|
||||||
if (additionalProperties.containsKey("modelNamePrefix")) {
|
|
||||||
additionalProperties().put("prefix", modelNamePrefix);
|
|
||||||
supportingFiles.clear();
|
|
||||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
|
|
||||||
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
|
|
||||||
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
|
|
||||||
supportingFiles.add(new SupportingFile("cmake.mustache", "", "CMakeLists.txt"));
|
|
||||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
|
||||||
}
|
|
||||||
if (additionalProperties.containsKey(RESERVED_WORD_PREFIX_OPTION)) {
|
|
||||||
reservedWordPrefix = (String) additionalProperties.get(RESERVED_WORD_PREFIX_OPTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
additionalProperties.put("modelNamespaceDeclarations", modelPackage.split("\\."));
|
|
||||||
additionalProperties.put("modelNamespace", modelPackage.replaceAll("\\.", "::"));
|
|
||||||
additionalProperties.put("apiNamespaceDeclarations", apiPackage.split("\\."));
|
|
||||||
additionalProperties.put("apiNamespace", apiPackage.replaceAll("\\.", "::"));
|
|
||||||
additionalProperties.put("helpersNamespaceDeclarations", helpersPackage.split("\\."));
|
|
||||||
additionalProperties.put("helpersNamespace", helpersPackage.replaceAll("\\.", "::"));
|
|
||||||
additionalProperties.put(RESERVED_WORD_PREFIX_OPTION, reservedWordPrefix);
|
|
||||||
|
|
||||||
if (additionalProperties.containsKey(OPTIONAL_EXTERNAL_LIB)) {
|
|
||||||
setAddExternalLibs(convertPropertyToBooleanAndWriteBack(OPTIONAL_EXTERNAL_LIB));
|
|
||||||
} else {
|
|
||||||
additionalProperties.put(OPTIONAL_EXTERNAL_LIB, isAddExternalLibs);
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup model templates
|
|
||||||
if (additionalProperties.containsKey(OPTION_USE_STRUCT_MODEL))
|
|
||||||
isUseStructModel = convertPropertyToBooleanAndWriteBack(OPTION_USE_STRUCT_MODEL);
|
|
||||||
|
|
||||||
if (isUseStructModel) {
|
|
||||||
LOGGER.info("Using struct-based model template");
|
|
||||||
modelTemplateFiles.put("model-struct-header.mustache", ".h");
|
|
||||||
modelTemplateFiles.put("model-struct-source.mustache", ".cpp");
|
|
||||||
} else {
|
|
||||||
LOGGER.info("Using get/set-based model template");
|
|
||||||
modelTemplateFiles.put("model-header.mustache", ".h");
|
|
||||||
modelTemplateFiles.put("model-source.mustache", ".cpp");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toModelImport(String name) {
|
|
||||||
if (importMapping.containsKey(name)) {
|
|
||||||
return importMapping.get(name);
|
|
||||||
} else {
|
|
||||||
return "#include \"" + name + ".h\"";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
|
||||||
|
|
||||||
Set<String> oldImports = codegenModel.imports;
|
|
||||||
codegenModel.imports = new HashSet<>();
|
|
||||||
for (String imp : oldImports) {
|
|
||||||
String newImp = toModelImport(imp);
|
|
||||||
if (!newImp.isEmpty()) {
|
|
||||||
codegenModel.imports.add(newImp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return codegenModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
|
||||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
|
||||||
|
|
||||||
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
|
||||||
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
|
||||||
|
|
||||||
if (apiResponse != null) {
|
|
||||||
Schema response = ModelUtils.getSchemaFromResponse(apiResponse);
|
|
||||||
if (response != null) {
|
|
||||||
CodegenProperty cm = fromProperty("response", response);
|
|
||||||
op.vendorExtensions.put("x-codegen-response", cm);
|
|
||||||
if ("HttpContent".equals(cm.dataType)) {
|
|
||||||
op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String pathForOatpp = path.replaceAll("\\{(.*?)}", ":$1");
|
|
||||||
op.vendorExtensions.put("x-codegen-oatpp-path", pathForOatpp);
|
|
||||||
|
|
||||||
return op;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
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", 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) {
|
|
||||||
boolean consumeJson = false;
|
|
||||||
boolean isParsingSupported = true;
|
|
||||||
if (op.bodyParam != null) {
|
|
||||||
if (op.bodyParam.vendorExtensions == null) {
|
|
||||||
op.bodyParam.vendorExtensions = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isStringOrDate = op.bodyParam.isString || op.bodyParam.isDate;
|
|
||||||
op.bodyParam.vendorExtensions.put("x-codegen-oatpp-is-string-or-date", isStringOrDate);
|
|
||||||
}
|
|
||||||
if (op.consumes != null) {
|
|
||||||
for (Map<String, String> consume : op.consumes) {
|
|
||||||
if (consume.get("mediaType") != null && consume.get("mediaType").equals("application/json")) {
|
|
||||||
consumeJson = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
op.httpMethod = op.httpMethod.substring(0, 1).toUpperCase(Locale.ROOT) + op.httpMethod.substring(1).toLowerCase(Locale.ROOT);
|
|
||||||
|
|
||||||
for (CodegenParameter param : op.allParams) {
|
|
||||||
if (param.isFormParam) isParsingSupported = false;
|
|
||||||
if (param.isFile) isParsingSupported = false;
|
|
||||||
if (param.isCookieParam) isParsingSupported = false;
|
|
||||||
|
|
||||||
//TODO: This changes the info about the real type but it is needed to parse the header params
|
|
||||||
if (param.isHeaderParam) {
|
|
||||||
param.dataType = "Oatpp::Optional<Oatpp::Http::Header::Raw>";
|
|
||||||
param.baseType = "Oatpp::Optional<Oatpp::Http::Header::Raw>";
|
|
||||||
} else if (param.isQueryParam) {
|
|
||||||
if (param.isPrimitiveType) {
|
|
||||||
param.dataType = "Oatpp::Optional<" + param.dataType + ">";
|
|
||||||
} else {
|
|
||||||
param.dataType = "Oatpp::Optional<" + param.dataType + ">";
|
|
||||||
param.baseType = "Oatpp::Optional<" + param.baseType + ">";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (op.vendorExtensions == null) {
|
|
||||||
op.vendorExtensions = new HashMap<>();
|
|
||||||
}
|
|
||||||
op.vendorExtensions.put("x-codegen-oatpp-consumes-json", consumeJson);
|
|
||||||
op.vendorExtensions.put("x-codegen-oatpp-is-parsing-supported", isParsingSupported);
|
|
||||||
|
|
||||||
// Check if any one of the operations needs a model, then at API file level, at least one model has to be included.
|
|
||||||
for (String hdr : op.imports) {
|
|
||||||
if (importMapping.containsKey(hdr)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
operations.put("hasModelImport", true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return objs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toModelFilename(String name) {
|
|
||||||
return toModelName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String apiFilename(String templateName, String tag) {
|
|
||||||
String result = super.apiFilename(templateName, tag);
|
|
||||||
|
|
||||||
if (templateName.endsWith("impl-header.mustache")) {
|
|
||||||
int ix = result.lastIndexOf(File.separatorChar);
|
|
||||||
result = result.substring(0, ix) + result.substring(ix, result.length() - 2) + "Impl.h";
|
|
||||||
result = result.replace(apiFileFolder(), implFileFolder());
|
|
||||||
} else if (templateName.endsWith("impl-source.mustache")) {
|
|
||||||
int ix = result.lastIndexOf(File.separatorChar);
|
|
||||||
result = result.substring(0, ix) + result.substring(ix, result.length() - 4) + "Impl.cpp";
|
|
||||||
result = result.replace(apiFileFolder(), implFileFolder());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toApiFilename(String name) {
|
|
||||||
return toApiName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 = getAdditionalProperties(p);
|
|
||||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
|
||||||
return "std::string";
|
|
||||||
} else if (ModelUtils.isStringSchema(p)
|
|
||||||
|| ModelUtils.isDateSchema(p)
|
|
||||||
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|
|
||||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
|
||||||
return toModelName(openAPIType);
|
|
||||||
}
|
|
||||||
|
|
||||||
return openAPIType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toDefaultValue(Schema p) {
|
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
|
||||||
return "false";
|
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
|
||||||
return "\"\"";
|
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
|
||||||
return "\"\"";
|
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
|
||||||
if (ModelUtils.isFloatSchema(p)) {
|
|
||||||
return "0.0f";
|
|
||||||
}
|
|
||||||
return "0.0";
|
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
|
||||||
if (ModelUtils.isLongSchema(p)) {
|
|
||||||
return "0L";
|
|
||||||
}
|
|
||||||
return "0";
|
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
|
||||||
return "\"\"";
|
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
|
||||||
return "std::map<std::string, " + inner + ">()";
|
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
|
||||||
ArraySchema ap = (ArraySchema) p;
|
|
||||||
String inner = getSchemaType(ap.getItems());
|
|
||||||
return "std::vector<" + inner + ">()";
|
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
|
||||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
|
||||||
return "\"\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Location to write model files. You can use the modelPackage() as defined
|
|
||||||
* when the class is instantiated
|
|
||||||
*/
|
|
||||||
public String modelFileFolder() {
|
|
||||||
return (outputFolder + "/model").replace("/", File.separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Location to write api files. You can use the apiPackage() as defined when
|
|
||||||
* the class is instantiated
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String apiFileFolder() {
|
|
||||||
return (outputFolder + "/api").replace("/", File.separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String implFileFolder() {
|
|
||||||
return (outputFolder + "/" + implFolder).replace("/", File.separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
} else
|
|
||||||
type = openAPIType;
|
|
||||||
return toModelName(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTypeDeclaration(String str) {
|
|
||||||
return toModelName(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specify whether external libraries will be added during the generation
|
|
||||||
*
|
|
||||||
* @param value the value to be set
|
|
||||||
*/
|
|
||||||
public void setAddExternalLibs(boolean value) {
|
|
||||||
isAddExternalLibs = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -229,7 +229,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
||||||
|
|
||||||
if (apiResponse != null) {
|
if (apiResponse != null) {
|
||||||
Schema response = ModelUtils.getSchemaFromResponse(apiResponse);
|
Schema response = modelUtils.getSchemaFromResponse(apiResponse);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
CodegenProperty cm = fromProperty("response", response);
|
CodegenProperty cm = fromProperty("response", response);
|
||||||
op.vendorExtensions.put("x-codegen-response", cm);
|
op.vendorExtensions.put("x-codegen-response", cm);
|
||||||
@@ -350,20 +350,20 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
String openAPIType = getSchemaType(p);
|
String openAPIType = getSchemaType(p);
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
}
|
}
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
return "std::string";
|
return "std::string";
|
||||||
}
|
}
|
||||||
if (ModelUtils.isStringSchema(p)
|
if (modelUtils.isStringSchema(p)
|
||||||
|| ModelUtils.isDateSchema(p)
|
|| modelUtils.isDateSchema(p)
|
||||||
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|
|| modelUtils.isDateTimeSchema(p) || modelUtils.isFileSchema(p)
|
||||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||||
return toModelName(openAPIType);
|
return toModelName(openAPIType);
|
||||||
}
|
}
|
||||||
@@ -373,34 +373,34 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "false";
|
return "false";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (ModelUtils.isFloatSchema(p)) {
|
if (modelUtils.isFloatSchema(p)) {
|
||||||
return "0.0f";
|
return "0.0f";
|
||||||
}
|
}
|
||||||
return "0.0";
|
return "0.0";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (ModelUtils.isLongSchema(p)) {
|
if (modelUtils.isLongSchema(p)) {
|
||||||
return "0L";
|
return "0L";
|
||||||
}
|
}
|
||||||
return "0";
|
return "0";
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return "std::map<std::string, " + inner + ">()";
|
return "std::map<std::string, " + inner + ">()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
return "std::vector<" + inner + ">()";
|
return "std::vector<" + inner + ">()";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
||||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
return toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -181,16 +181,16 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
String openAPIType = getSchemaType(p);
|
String openAPIType = getSchemaType(p);
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isBinarySchema(p)) {
|
||||||
return getSchemaType(p);
|
return getSchemaType(p);
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isFileSchema(p)) {
|
||||||
return getSchemaType(p);
|
return getSchemaType(p);
|
||||||
}
|
}
|
||||||
if (foundationClasses.contains(openAPIType)) {
|
if (foundationClasses.contains(openAPIType)) {
|
||||||
@@ -205,33 +205,33 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "false";
|
return "false";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "NULL";
|
return "NULL";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "NULL";
|
return "NULL";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
||||||
return "0.0f";
|
return "0.0f";
|
||||||
}
|
}
|
||||||
return "0.0";
|
return "0.0";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
||||||
return "0L";
|
return "0L";
|
||||||
}
|
}
|
||||||
return "0";
|
return "0";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
return "QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "QList<" + getTypeDeclaration(inner) + ">()";
|
return "QList<" + getTypeDeclaration(inner) + ">()";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "QString(\"\")";
|
return "QString(\"\")";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
return toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||||
}
|
}
|
||||||
return "NULL";
|
return "NULL";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
|||||||
supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder, PREFIX + "HttpFileElement.cpp"));
|
supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder, PREFIX + "HttpFileElement.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, PREFIX + "Object.h"));
|
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, PREFIX + "Object.h"));
|
||||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, PREFIX + "Enum.h"));
|
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, PREFIX + "Enum.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("README.mustache", "","README.md"));
|
||||||
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
||||||
if (optionalProjectFileFlag) {
|
if (optionalProjectFileFlag) {
|
||||||
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri"));
|
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri"));
|
||||||
@@ -108,6 +109,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
|||||||
supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder, modelNamePrefix + "HttpFileElement.cpp"));
|
supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder, modelNamePrefix + "HttpFileElement.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h"));
|
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h"));
|
||||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h"));
|
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("README.mustache", "","README.md"));
|
||||||
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import io.swagger.v3.oas.models.servers.Server;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openapitools.codegen.*;
|
import org.openapitools.codegen.*;
|
||||||
import org.openapitools.codegen.meta.features.*;
|
import org.openapitools.codegen.meta.features.*;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -271,8 +270,8 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
||||||
|
|
||||||
if (methodResponse != null) {
|
if (methodResponse != null) {
|
||||||
Schema response = ModelUtils.getSchemaFromResponse(methodResponse);
|
Schema response = modelUtils.getSchemaFromResponse(methodResponse);
|
||||||
response = ModelUtils.unaliasSchema(this.openAPI, response, importMapping);
|
response = modelUtils.unaliasSchema(response, importMapping);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
CodegenProperty cm = fromProperty("response", response);
|
CodegenProperty cm = fromProperty("response", response);
|
||||||
op.vendorExtensions.put("x-codegen-response", cm);
|
op.vendorExtensions.put("x-codegen-response", cm);
|
||||||
@@ -344,18 +343,18 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
String openAPIType = getSchemaType(p);
|
String openAPIType = getSchemaType(p);
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isFileSchema(p) || ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isFileSchema(p) || modelUtils.isBinarySchema(p)) {
|
||||||
return "std::shared_ptr<" + openAPIType + ">";
|
return "std::shared_ptr<" + openAPIType + ">";
|
||||||
} else if (ModelUtils.isStringSchema(p)
|
} else if (modelUtils.isStringSchema(p)
|
||||||
|| ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)
|
|| modelUtils.isDateSchema(p) || modelUtils.isDateTimeSchema(p)
|
||||||
|| ModelUtils.isFileSchema(p) || ModelUtils.isUUIDSchema(p)
|
|| modelUtils.isFileSchema(p) || modelUtils.isUUIDSchema(p)
|
||||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||||
return toModelName(openAPIType);
|
return toModelName(openAPIType);
|
||||||
}
|
}
|
||||||
@@ -365,26 +364,26 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "false";
|
return "false";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "utility::datetime()";
|
return "utility::datetime()";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "utility::datetime()";
|
return "utility::datetime()";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (ModelUtils.isFloatSchema(p)) {
|
if (modelUtils.isFloatSchema(p)) {
|
||||||
return "0.0f";
|
return "0.0f";
|
||||||
}
|
}
|
||||||
return "0.0";
|
return "0.0";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (ModelUtils.isLongSchema(p)) {
|
if (modelUtils.isLongSchema(p)) {
|
||||||
return "0L";
|
return "0L";
|
||||||
}
|
}
|
||||||
return "0";
|
return "0";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return "std::map<utility::string_t, " + inner + ">()";
|
return "std::map<utility::string_t, " + inner + ">()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
if (!languageSpecificPrimitives.contains(inner)) {
|
if (!languageSpecificPrimitives.contains(inner)) {
|
||||||
@@ -392,10 +391,10 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
}
|
}
|
||||||
return "std::vector<" + inner + ">()";
|
return "std::vector<" + inner + ">()";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||||
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
return "new " + toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "utility::conversions::to_string_t(\"\")";
|
return "utility::conversions::to_string_t(\"\")";
|
||||||
} else if (isFreeFormObject(p)) {
|
} else if (modelUtils.isFreeFormObject(p)) {
|
||||||
return "new Object()";
|
return "new Object()";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,7 +445,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
private void postProcessParentModels(final Map<String, Object> models) {
|
private void postProcessParentModels(final Map<String, Object> models) {
|
||||||
for (final String parent : parentModels) {
|
for (final String parent : parentModels) {
|
||||||
final CodegenModel parentModel = ModelUtils.getModelByName(parent, models);
|
final CodegenModel parentModel = modelUtils.getModelByName(parent, models);
|
||||||
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
||||||
for (final CodegenModel child : childrenModels) {
|
for (final CodegenModel child : childrenModels) {
|
||||||
processParentPropertiesInChildModel(parentModel, child);
|
processParentPropertiesInChildModel(parentModel, child);
|
||||||
|
|||||||
@@ -345,18 +345,18 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
String openAPIType = getSchemaType(p);
|
String openAPIType = getSchemaType(p);
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
return "std::string";
|
return "std::string";
|
||||||
} else if (ModelUtils.isStringSchema(p)
|
} else if (modelUtils.isStringSchema(p)
|
||||||
|| ModelUtils.isDateSchema(p)
|
|| modelUtils.isDateSchema(p)
|
||||||
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|
|| modelUtils.isDateTimeSchema(p) || modelUtils.isFileSchema(p)
|
||||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||||
return toModelName(openAPIType);
|
return toModelName(openAPIType);
|
||||||
}
|
}
|
||||||
@@ -366,32 +366,32 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (ModelUtils.isFloatSchema(p)) { // float
|
if (modelUtils.isFloatSchema(p)) { // float
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString() + "f";
|
return p.getDefault().toString() + "f";
|
||||||
} else {
|
} else {
|
||||||
@@ -404,8 +404,8 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
return "0.0";
|
return "0.0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (ModelUtils.isLongSchema(p)) { // long
|
if (modelUtils.isLongSchema(p)) { // long
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString() + "L";
|
return p.getDefault().toString() + "L";
|
||||||
} else {
|
} else {
|
||||||
@@ -418,16 +418,16 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return "std::map<std::string, " + inner + ">()";
|
return "std::map<std::string, " + inner + ">()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
if (!languageSpecificPrimitives.contains(inner)) {
|
if (!languageSpecificPrimitives.contains(inner)) {
|
||||||
@@ -435,7 +435,7 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
}
|
}
|
||||||
return "std::vector<" + inner + ">()";
|
return "std::vector<" + inner + ">()";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||||
return "std::make_shared<" + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + ">()";
|
return "std::make_shared<" + toModelName(modelUtils.getSimpleRef(p.get$ref())) + ">()";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "nullptr";
|
return "nullptr";
|
||||||
|
|||||||
@@ -161,9 +161,9 @@ public class CppTizenClientCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
return instantiationTypes.get("map");
|
return instantiationTypes.get("map");
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
return instantiationTypes.get("array");
|
return instantiationTypes.get("array");
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@@ -232,28 +232,28 @@ public class CppTizenClientCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
//Might not be needed
|
//Might not be needed
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "bool(false)";
|
return "bool(false)";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
||||||
return "float(0)";
|
return "float(0)";
|
||||||
}
|
}
|
||||||
return "double(0)";
|
return "double(0)";
|
||||||
|
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
||||||
return "long(0)";
|
return "long(0)";
|
||||||
}
|
}
|
||||||
return "int(0)";
|
return "int(0)";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
return "new std::map()";
|
return "new std::map()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
return "new std::list()";
|
return "new std::list()";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||||
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
return "new " + toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||||
} else if (ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateSchema(p) || modelUtils.isDateTimeSchema(p)) {
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "std::string()";
|
return "std::string()";
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
|
|||||||
@@ -379,11 +379,11 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
|||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
String openAPIType = getSchemaType(p);
|
String openAPIType = getSchemaType(p);
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return getSchemaType(p) + "<FString, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<FString, " + getTypeDeclaration(inner) + ">";
|
||||||
}
|
}
|
||||||
@@ -404,41 +404,41 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "TEXT(\"" + p.getDefault().toString() + "\")";
|
return "TEXT(\"" + p.getDefault().toString() + "\")";
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "FDateTime(0)";
|
return "FDateTime(0)";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "FDateTime(0)";
|
return "FDateTime(0)";
|
||||||
} else if (ModelUtils.isDoubleSchema(p)) {
|
} else if (modelUtils.isDoubleSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
return "0.0";
|
return "0.0";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isFloatSchema(p)) {
|
} else if (modelUtils.isFloatSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
return "0.0f";
|
return "0.0f";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isLongSchema(p)) {
|
} else if (modelUtils.isLongSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -412,14 +412,14 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema schema) {
|
public String toDefaultValue(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
return "const {}";
|
return "const {}";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
return "const []";
|
return "const []";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
||||||
}
|
}
|
||||||
return schema.getDefault().toString();
|
return schema.getDefault().toString();
|
||||||
@@ -430,11 +430,11 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||||
@@ -617,7 +617,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
return; // skip if DART_POST_PROCESS_FILE env variable is not defined
|
return; // skip if DART_POST_PROCESS_FILE env variable is not defined
|
||||||
}
|
}
|
||||||
|
|
||||||
// only procees the following type (or we can simply rely on the file extension to check if it's a Dart file)
|
// only process the following type (or we can simply rely on the file extension to check if it's a Dart file)
|
||||||
Set<String> supportedFileType = Sets.newHashSet(
|
Set<String> supportedFileType = Sets.newHashSet(
|
||||||
"supporting-mustache",
|
"supporting-mustache",
|
||||||
"model-test",
|
"model-test",
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
|||||||
|
|
||||||
private static final String IS_FORMAT_JSON = "jsonFormat";
|
private static final String IS_FORMAT_JSON = "jsonFormat";
|
||||||
private static final String CLIENT_NAME = "clientName";
|
private static final String CLIENT_NAME = "clientName";
|
||||||
private static Set<String> modelToIgnore = new HashSet<>();
|
private static final Set<String> modelToIgnore = new HashSet<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
modelToIgnore.add("datetime");
|
modelToIgnore.add("datetime");
|
||||||
@@ -71,10 +71,6 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
|||||||
embeddedTemplateDir = "dart-dio";
|
embeddedTemplateDir = "dart-dio";
|
||||||
this.setTemplateDir(embeddedTemplateDir);
|
this.setTemplateDir(embeddedTemplateDir);
|
||||||
|
|
||||||
//no tests at this time
|
|
||||||
modelTestTemplateFiles.clear();
|
|
||||||
apiTestTemplateFiles.clear();
|
|
||||||
|
|
||||||
cliOptions.add(new CliOption(NULLABLE_FIELDS, "Is the null fields should be in the JSON payload"));
|
cliOptions.add(new CliOption(NULLABLE_FIELDS, "Is the null fields should be in the JSON payload"));
|
||||||
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use").defaultValue(this.getDateLibrary());
|
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use").defaultValue(this.getDateLibrary());
|
||||||
Map<String, String> dateOptions = new HashMap<>();
|
Map<String, String> dateOptions = new HashMap<>();
|
||||||
@@ -88,6 +84,7 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
|||||||
typeMapping.put("AnyType", "Object");
|
typeMapping.put("AnyType", "Object");
|
||||||
|
|
||||||
importMapping.put("BuiltList", "package:built_collection/built_collection.dart");
|
importMapping.put("BuiltList", "package:built_collection/built_collection.dart");
|
||||||
|
importMapping.put("BuiltSet", "package:built_collection/built_collection.dart");
|
||||||
importMapping.put("BuiltMap", "package:built_collection/built_collection.dart");
|
importMapping.put("BuiltMap", "package:built_collection/built_collection.dart");
|
||||||
importMapping.put("JsonObject", "package:built_value/json_object.dart");
|
importMapping.put("JsonObject", "package:built_value/json_object.dart");
|
||||||
importMapping.put("Uint8List", "dart:typed_data");
|
importMapping.put("Uint8List", "dart:typed_data");
|
||||||
@@ -109,7 +106,6 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
|||||||
this.nullableFields = nullableFields;
|
this.nullableFields = nullableFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "dart-dio";
|
return "dart-dio";
|
||||||
@@ -122,14 +118,14 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema schema) {
|
public String toDefaultValue(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
return "const {}";
|
return "const {}";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
return "const []";
|
return "const []";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
||||||
}
|
}
|
||||||
return schema.getDefault().toString();
|
return schema.getDefault().toString();
|
||||||
@@ -316,6 +312,11 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
|||||||
if (property.dataType.contains("JsonObject")) {
|
if (property.dataType.contains("JsonObject")) {
|
||||||
model.imports.add("JsonObject");
|
model.imports.add("JsonObject");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property.isEnum) {
|
||||||
|
// enums are generated with built_value and make use of BuiltSet
|
||||||
|
model.imports.add("BuiltSet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -378,5 +379,4 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
|||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,14 +132,14 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema schema) {
|
public String toDefaultValue(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
return "const {}";
|
return "const {}";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
return "const []";
|
return "const []";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
||||||
}
|
}
|
||||||
return schema.getDefault().toString();
|
return schema.getDefault().toString();
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
Info info = openAPI.getInfo();
|
Info info = openAPI.getInfo();
|
||||||
if (moduleName == null) {
|
if (moduleName == null) {
|
||||||
if (info.getTitle() != null) {
|
if (info.getTitle() != null) {
|
||||||
@@ -490,42 +490,42 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "%{optional(String.t) => " + getTypeDeclaration(inner) + "}";
|
return "%{optional(String.t) => " + getTypeDeclaration(inner) + "}";
|
||||||
} else if (ModelUtils.isPasswordSchema(p)) {
|
} else if (modelUtils.isPasswordSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
} else if (ModelUtils.isEmailSchema(p)) {
|
} else if (modelUtils.isEmailSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
return "binary()";
|
return "binary()";
|
||||||
} else if (ModelUtils.isUUIDSchema(p)) {
|
} else if (modelUtils.isUUIDSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "Date.t";
|
return "Date.t";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "DateTime.t";
|
return "DateTime.t";
|
||||||
} else if (ModelUtils.isObjectSchema(p)) {
|
} else if (modelUtils.isObjectSchema(p)) {
|
||||||
// TODO How to map it?
|
// TODO How to map it?
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
return "integer()";
|
return "integer()";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
return "float()";
|
return "float()";
|
||||||
} else if (ModelUtils.isBinarySchema(p) || ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isBinarySchema(p) || modelUtils.isFileSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "boolean()";
|
return "boolean()";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
||||||
// How to map it?
|
// How to map it?
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isFileSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.samskivert.mustache.Mustache.Lambda;
|
|||||||
import com.samskivert.mustache.Template;
|
import com.samskivert.mustache.Template;
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openapitools.codegen.*;
|
import org.openapitools.codegen.*;
|
||||||
import org.openapitools.codegen.meta.features.*;
|
import org.openapitools.codegen.meta.features.*;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
@@ -37,6 +38,7 @@ import java.util.function.Predicate;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
|
||||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||||
|
|
||||||
public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
@@ -174,6 +176,31 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
return input.replace("\"", "");
|
return input.replace("\"", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toOperationId(String operationId) {
|
||||||
|
// throw exception if method name is empty
|
||||||
|
if (StringUtils.isEmpty(operationId)) {
|
||||||
|
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||||
|
}
|
||||||
|
|
||||||
|
operationId = camelize(sanitizeName(operationId), true);
|
||||||
|
|
||||||
|
// method name cannot use reserved keyword, e.g. return
|
||||||
|
if (isReservedWord(operationId)) {
|
||||||
|
String newOperationId = camelize("call_" + operationId, true);
|
||||||
|
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||||
|
return newOperationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// operationId starts with a number
|
||||||
|
if (operationId.matches("^\\d.*")) {
|
||||||
|
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
|
||||||
|
operationId = camelize("call_" + operationId, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return operationId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toApiName(String name) {
|
public String toApiName(String name) {
|
||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
@@ -211,7 +238,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
return instantiationTypes.get("array") + " " + inner;
|
return instantiationTypes.get("array") + " " + inner;
|
||||||
@@ -387,19 +414,19 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return Boolean.valueOf(p.getDefault().toString()) ? "True" : "False";
|
return Boolean.valueOf(p.getDefault().toString()) ? "True" : "False";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
@@ -423,11 +450,11 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
CodegenModel cm = super.fromModel(name, model);
|
CodegenModel cm = super.fromModel(name, model);
|
||||||
if(ModelUtils.isArraySchema(model)) {
|
if(modelUtils.isArraySchema(model)) {
|
||||||
return new CodegenArrayModel(cm, (ArraySchema) model);
|
return new CodegenArrayModel(cm, (ArraySchema) model);
|
||||||
} else {
|
} else {
|
||||||
return cm;
|
return cm;
|
||||||
@@ -152,7 +152,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema schema) {
|
public String getTypeDeclaration(Schema schema) {
|
||||||
String typeDeclaration = super.getSchemaType(schema);
|
String typeDeclaration = super.getSchemaType(schema);
|
||||||
if(ModelUtils.isArraySchema(schema)) {
|
if(modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema arraySchema = (ArraySchema) schema;
|
ArraySchema arraySchema = (ArraySchema) schema;
|
||||||
String complexType = getSchemaType(arraySchema.getItems());
|
String complexType = getSchemaType(arraySchema.getItems());
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
@Override
|
@Override
|
||||||
public String getSchemaType(Schema schema) {
|
public String getSchemaType(Schema schema) {
|
||||||
String schemaType = super.getSchemaType(schema);
|
String schemaType = super.getSchemaType(schema);
|
||||||
if(ModelUtils.isArraySchema(schema)) {
|
if(modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema arraySchema = (ArraySchema) schema;
|
ArraySchema arraySchema = (ArraySchema) schema;
|
||||||
String complexType = getSchemaType(arraySchema.getItems());
|
String complexType = getSchemaType(arraySchema.getItems());
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
if(minItems != null && maxItems != null) sb.append(", ").append(maxItems);
|
if(minItems != null && maxItems != null) sb.append(", ").append(maxItems);
|
||||||
|
|
||||||
return sb.append(")").toString();
|
return sb.append(")").toString();
|
||||||
} else if(ModelUtils.isIntegerSchema(schema)) {
|
} else if(modelUtils.isIntegerSchema(schema)) {
|
||||||
StringBuilder sb = new StringBuilder("integer(");
|
StringBuilder sb = new StringBuilder("integer(");
|
||||||
|
|
||||||
BigDecimal min = schema.getMinimum();
|
BigDecimal min = schema.getMinimum();
|
||||||
@@ -192,9 +192,9 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
if(min != null && max != null) sb.append(", ").append(max);
|
if(min != null && max != null) sb.append(", ").append(max);
|
||||||
|
|
||||||
return sb.append(")").toString();
|
return sb.append(")").toString();
|
||||||
} else if(ModelUtils.isDateSchema(schema) || ModelUtils.isDateTimeSchema(schema)) {
|
} else if(modelUtils.isDateSchema(schema) || modelUtils.isDateTimeSchema(schema)) {
|
||||||
return typeMapping.get(schemaType);
|
return typeMapping.get(schemaType);
|
||||||
} else if(ModelUtils.isStringSchema(schema)) {
|
} else if(modelUtils.isStringSchema(schema)) {
|
||||||
StringBuilder sb = new StringBuilder("binary(");
|
StringBuilder sb = new StringBuilder("binary(");
|
||||||
Integer min = schema.getMinLength();
|
Integer min = schema.getMinLength();
|
||||||
Integer max = schema.getMaxLength();
|
Integer max = schema.getMaxLength();
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p) || ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isArraySchema(p) || modelUtils.isMapSchema(p)) {
|
||||||
return getSchemaType(p);
|
return getSchemaType(p);
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
@@ -258,27 +258,27 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "false";
|
return "false";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return "0.0";
|
return "0.0";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return "0";
|
return "0";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
return "new Dictionary()";
|
return "new Dictionary()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
return "new Array()";
|
return "new Array()";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "null";
|
return "null";
|
||||||
} else {
|
} else {
|
||||||
return "NaN";
|
return "NaN";
|
||||||
|
|||||||
@@ -166,8 +166,8 @@ public class FsharpGiraffeServerCodegen extends AbstractFSharpCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
super.preprocessOpenAPI(openAPI);
|
super.preprocessOpenAPI();
|
||||||
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
||||||
additionalProperties.put("serverHost", url.getHost());
|
additionalProperties.put("serverHost", url.getHost());
|
||||||
additionalProperties.put("serverPort", URLPathUtils.getPort(url, 8080));
|
additionalProperties.put("serverPort", URLPathUtils.getPort(url, 8080));
|
||||||
|
|||||||
@@ -349,8 +349,8 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
p = ModelUtils.getReferencedSchema(this.openAPI, p);
|
p = modelUtils.getReferencedSchema(p);
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
||||||
}
|
}
|
||||||
@@ -448,13 +448,17 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
for (CodegenParameter p : op.allParams) {
|
for (CodegenParameter p : op.allParams) {
|
||||||
p.vendorExtensions.put("x-go-example", constructExampleCode(p, modelMaps, processedModelMaps));
|
p.vendorExtensions.put("x-go-example", constructExampleCode(p, modelMaps, processedModelMaps));
|
||||||
}
|
}
|
||||||
|
processedModelMaps.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
processedModelMaps.clear();
|
|
||||||
for (CodegenOperation operation : operationList) {
|
for (CodegenOperation operation : operationList) {
|
||||||
for (CodegenParameter cp : operation.allParams) {
|
for (CodegenParameter cp : operation.allParams) {
|
||||||
cp.vendorExtensions.put("x-go-example", constructExampleCode(cp, modelMaps, processedModelMaps));
|
cp.vendorExtensions.put("x-go-example", constructExampleCode(cp, modelMaps, processedModelMaps));
|
||||||
}
|
}
|
||||||
|
if (processedModelMaps.containsKey("time.Time")) {
|
||||||
|
operation.vendorExtensions.put("x-go-import", " \"time\"");
|
||||||
|
}
|
||||||
|
processedModelMaps.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
return objs;
|
return objs;
|
||||||
@@ -462,12 +466,22 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
|
|
||||||
private String constructExampleCode(CodegenParameter codegenParameter, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
|
private String constructExampleCode(CodegenParameter codegenParameter, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
|
||||||
if (codegenParameter.isArray) { // array
|
if (codegenParameter.isArray) { // array
|
||||||
return codegenParameter.dataType + "{" + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
|
String prefix = codegenParameter.dataType;
|
||||||
|
String dataType = StringUtils.removeStart(codegenParameter.dataType, "[]");
|
||||||
|
if (modelMaps.containsKey(dataType)) {
|
||||||
|
prefix = "[]" + goImportAlias + "." + dataType;
|
||||||
|
}
|
||||||
|
return prefix + "{" + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
|
||||||
} else if (codegenParameter.isMap) {
|
} else if (codegenParameter.isMap) {
|
||||||
return codegenParameter.dataType + "{ \"key\": " + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
|
String prefix = codegenParameter.dataType;
|
||||||
|
String dataType = StringUtils.removeStart(codegenParameter.dataType, "map[string][]");
|
||||||
|
if (modelMaps.containsKey(dataType)) {
|
||||||
|
prefix = "map[string][]" + goImportAlias + "." + dataType;
|
||||||
|
}
|
||||||
|
return prefix + "{\"key\": " + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
|
||||||
} else if (codegenParameter.isPrimitiveType) { // primitive type
|
} else if (codegenParameter.isPrimitiveType) { // primitive type
|
||||||
if (codegenParameter.isString) {
|
if (codegenParameter.isString) {
|
||||||
if (StringUtils.isEmpty(codegenParameter.example)) {
|
if (!StringUtils.isEmpty(codegenParameter.example) && !"null".equals(codegenParameter.example)) {
|
||||||
return "\"" + codegenParameter.example + "\"";
|
return "\"" + codegenParameter.example + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"" + codegenParameter.paramName + "_example\"";
|
return "\"" + codegenParameter.paramName + "_example\"";
|
||||||
@@ -481,18 +495,30 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
} else if (codegenParameter.isUri) { // URL
|
} else if (codegenParameter.isUri) { // URL
|
||||||
return "\"https://example.com\"";
|
return "\"https://example.com\"";
|
||||||
} else if (codegenParameter.isDateTime || codegenParameter.isDate) { // datetime or date
|
} else if (codegenParameter.isDateTime || codegenParameter.isDate) { // datetime or date
|
||||||
|
processedModelMap.put("time.Time", 1);
|
||||||
return "time.Now()";
|
return "time.Now()";
|
||||||
|
} else if (codegenParameter.isFile) {
|
||||||
|
return "os.NewFile(1234, \"some_file\")";
|
||||||
} else { // numeric
|
} else { // numeric
|
||||||
if (StringUtils.isEmpty(codegenParameter.example)) {
|
if (!StringUtils.isEmpty(codegenParameter.example) && !"null".equals(codegenParameter.example)) {
|
||||||
return codegenParameter.example;
|
return codegenParameter.dataType + "(" + codegenParameter.example + ")";
|
||||||
} else {
|
} else {
|
||||||
return "987";
|
return codegenParameter.dataType + "(987)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // model
|
} else { // model
|
||||||
// look up the model
|
// look up the model
|
||||||
if (modelMaps.containsKey(codegenParameter.dataType)) {
|
if (modelMaps.containsKey(codegenParameter.dataType)) {
|
||||||
return constructExampleCode(modelMaps.get(codegenParameter.dataType), modelMaps, processedModelMap);
|
return constructExampleCode(modelMaps.get(codegenParameter.dataType), modelMaps, processedModelMap);
|
||||||
|
} else if (codegenParameter.isEmail) { // email
|
||||||
|
if (!StringUtils.isEmpty(codegenParameter.example) && !"null".equals(codegenParameter.example)) {
|
||||||
|
return "\"" + codegenParameter.example + "\"";
|
||||||
|
} else {
|
||||||
|
return "\"" + codegenParameter.paramName + "@example.com\"";
|
||||||
|
}
|
||||||
|
} else if (codegenParameter.isDateTime || codegenParameter.isDate) { // datetime or date
|
||||||
|
processedModelMap.put("time.Time", 1);
|
||||||
|
return "time.Now()";
|
||||||
} else {
|
} else {
|
||||||
//LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenParameter.dataType);
|
//LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenParameter.dataType);
|
||||||
return "TODO";
|
return "TODO";
|
||||||
@@ -502,12 +528,22 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
|
|
||||||
private String constructExampleCode(CodegenProperty codegenProperty, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
|
private String constructExampleCode(CodegenProperty codegenProperty, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
|
||||||
if (codegenProperty.isArray) { // array
|
if (codegenProperty.isArray) { // array
|
||||||
return codegenProperty.dataType + "{" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + ")";
|
String prefix = codegenProperty.dataType;
|
||||||
|
String dataType = StringUtils.removeStart(codegenProperty.dataType, "[]");
|
||||||
|
if (modelMaps.containsKey(dataType)) {
|
||||||
|
prefix = "[]" + goImportAlias + "." + dataType;
|
||||||
|
}
|
||||||
|
return prefix + "{" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
|
||||||
} else if (codegenProperty.isMap) { // map
|
} else if (codegenProperty.isMap) { // map
|
||||||
return codegenProperty.dataType + "{ \"key\": " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
|
String prefix = codegenProperty.dataType;
|
||||||
|
String dataType = StringUtils.removeStart(codegenProperty.dataType, "map[string][]");
|
||||||
|
if (modelMaps.containsKey(dataType)) {
|
||||||
|
prefix = "map[string][]" + goImportAlias + "." + dataType;
|
||||||
|
}
|
||||||
|
return prefix + "{\"key\": " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
|
||||||
} else if (codegenProperty.isPrimitiveType) { // primitive type
|
} else if (codegenProperty.isPrimitiveType) { // primitive type
|
||||||
if (codegenProperty.isString) {
|
if (codegenProperty.isString) {
|
||||||
if (StringUtils.isEmpty(codegenProperty.example)) {
|
if (!StringUtils.isEmpty(codegenProperty.example) && !"null".equals(codegenProperty.example)) {
|
||||||
return "\"" + codegenProperty.example + "\"";
|
return "\"" + codegenProperty.example + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"" + codegenProperty.name + "_example\"";
|
return "\"" + codegenProperty.name + "_example\"";
|
||||||
@@ -521,25 +557,31 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
} else if (codegenProperty.isUri) { // URL
|
} else if (codegenProperty.isUri) { // URL
|
||||||
return "\"https://example.com\"";
|
return "\"https://example.com\"";
|
||||||
} else if (codegenProperty.isDateTime || codegenProperty.isDate) { // datetime or date
|
} else if (codegenProperty.isDateTime || codegenProperty.isDate) { // datetime or date
|
||||||
|
processedModelMap.put("time.Time", 1);
|
||||||
return "time.Now()";
|
return "time.Now()";
|
||||||
} else { // numeric
|
} else { // numeric
|
||||||
String example;
|
String example;
|
||||||
if (StringUtils.isEmpty(codegenProperty.example)) {
|
if (!StringUtils.isEmpty(codegenProperty.example) && !"null".equals(codegenProperty.example)) {
|
||||||
example = codegenProperty.example;
|
example = codegenProperty.example;
|
||||||
} else {
|
} else {
|
||||||
example = "123";
|
example = "123";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codegenProperty.isLong) {
|
return codegenProperty.dataType + "(" + example + ")";
|
||||||
return "int64(" + example + ")";
|
|
||||||
} else {
|
|
||||||
return example;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// look up the model
|
// look up the model
|
||||||
if (modelMaps.containsKey(codegenProperty.dataType)) {
|
if (modelMaps.containsKey(codegenProperty.dataType)) {
|
||||||
return constructExampleCode(modelMaps.get(codegenProperty.dataType), modelMaps, processedModelMap);
|
return constructExampleCode(modelMaps.get(codegenProperty.dataType), modelMaps, processedModelMap);
|
||||||
|
} else if (codegenProperty.isEmail) { // email
|
||||||
|
if (!StringUtils.isEmpty(codegenProperty.example) && !"null".equals(codegenProperty.example)) {
|
||||||
|
return "\"" + codegenProperty.example + "\"";
|
||||||
|
} else {
|
||||||
|
return "\"" + codegenProperty.name + "@example.com\"";
|
||||||
|
}
|
||||||
|
} else if (codegenProperty.isDateTime || codegenProperty.isDate) { // datetime or date
|
||||||
|
processedModelMap.put("time.Time", 1);
|
||||||
|
return "time.Now()";
|
||||||
} else {
|
} else {
|
||||||
//LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenProperty.dataType);
|
//LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenProperty.dataType);
|
||||||
return "\"TODO\"";
|
return "\"TODO\"";
|
||||||
@@ -548,8 +590,6 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String constructExampleCode(CodegenModel codegenModel, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
|
private String constructExampleCode(CodegenModel codegenModel, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
|
||||||
String example;
|
|
||||||
|
|
||||||
// break infinite recursion. Return, in case a model is already processed in the current context.
|
// break infinite recursion. Return, in case a model is already processed in the current context.
|
||||||
String model = codegenModel.name;
|
String model = codegenModel.name;
|
||||||
if (processedModelMap.containsKey(model)) {
|
if (processedModelMap.containsKey(model)) {
|
||||||
@@ -561,6 +601,14 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Invalid count when constructing example: " + count);
|
throw new RuntimeException("Invalid count when constructing example: " + count);
|
||||||
}
|
}
|
||||||
|
} else if (codegenModel.isEnum) {
|
||||||
|
Map<String, Object> allowableValues = codegenModel.allowableValues;
|
||||||
|
List<Object> values = (List<Object>) allowableValues.get("values");
|
||||||
|
return goImportAlias + "." + model + "(\"" + String.valueOf(values.get(0)) + "\")";
|
||||||
|
} else if (codegenModel.oneOf != null && !codegenModel.oneOf.isEmpty()) {
|
||||||
|
String subModel = (String) codegenModel.oneOf.toArray()[0];
|
||||||
|
String oneOf = constructExampleCode(modelMaps.get(subModel), modelMaps, processedModelMap).substring(1);
|
||||||
|
return goImportAlias + "." + model + "{" + subModel + ": " + oneOf + "}";
|
||||||
} else {
|
} else {
|
||||||
processedModelMap.put(model, 1);
|
processedModelMap.put(model, 1);
|
||||||
}
|
}
|
||||||
@@ -569,6 +617,6 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
for (CodegenProperty codegenProperty : codegenModel.requiredVars) {
|
for (CodegenProperty codegenProperty : codegenModel.requiredVars) {
|
||||||
propertyExamples.add(constructExampleCode(codegenProperty, modelMaps, processedModelMap));
|
propertyExamples.add(constructExampleCode(codegenProperty, modelMaps, processedModelMap));
|
||||||
}
|
}
|
||||||
return "*" + goImportAlias + ".New" + codegenModel.name + "(" + StringUtils.join(propertyExamples, ", ") + ")";
|
return "*" + goImportAlias + ".New" + toModelName(model) + "(" + StringUtils.join(propertyExamples, ", ") + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class GraphQLNodeJSExpressServerCodegen extends AbstractGraphQLCodegen im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ public class GraphQLNodeJSExpressServerCodegen extends AbstractGraphQLCodegen im
|
|||||||
// between some specific types for GraphQL:
|
// between some specific types for GraphQL:
|
||||||
// return "[" + getTypeDeclaration(inner) + "]";
|
// return "[" + getTypeDeclaration(inner) + "]";
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = (Schema) p.getAdditionalProperties();
|
Schema inner = (Schema) p.getAdditionalProperties();
|
||||||
|
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
@@ -139,7 +139,7 @@ public class GraphQLNodeJSExpressServerCodegen extends AbstractGraphQLCodegen im
|
|||||||
|
|
||||||
// IMPORANT NOTE Not using the supertype invocation, because we want to UpperCamelize the type:
|
// IMPORANT NOTE Not using the supertype invocation, because we want to UpperCamelize the type:
|
||||||
String schemaType = getSchemaType(p);
|
String schemaType = getSchemaType(p);
|
||||||
String nullable = ModelUtils.isNullable(p) ? "" : "!";
|
String nullable = modelUtils.isNullable(p) ? "" : "!";
|
||||||
|
|
||||||
if (typeMapping.containsKey(schemaType)) {
|
if (typeMapping.containsKey(schemaType)) {
|
||||||
return typeMapping.get(schemaType) + nullable;
|
return typeMapping.get(schemaType) + nullable;
|
||||||
|
|||||||
@@ -519,7 +519,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
String baseTitle = openAPI.getInfo().getTitle();
|
String baseTitle = openAPI.getInfo().getTitle();
|
||||||
|
|
||||||
if (baseTitle == null) {
|
if (baseTitle == null) {
|
||||||
@@ -612,7 +612,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
|||||||
additionalProperties.put(X_HAS_IMPORT_MAPPINGS, true);
|
additionalProperties.put(X_HAS_IMPORT_MAPPINGS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
super.preprocessOpenAPI(openAPI);
|
super.preprocessOpenAPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -624,11 +624,11 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
||||||
}
|
}
|
||||||
@@ -650,7 +650,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
Schema additionalProperties2 = getAdditionalProperties(p);
|
Schema additionalProperties2 = getAdditionalProperties(p);
|
||||||
String type = additionalProperties2.getType();
|
String type = additionalProperties2.getType();
|
||||||
if (null == type) {
|
if (null == type) {
|
||||||
@@ -659,7 +659,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
|||||||
}
|
}
|
||||||
String inner = getSchemaType(additionalProperties2);
|
String inner = getSchemaType(additionalProperties2);
|
||||||
return "(Map.Map Text " + inner + ")";
|
return "(Map.Map Text " + inner + ")";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
return getSchemaType(ap.getItems());
|
return getSchemaType(ap.getItems());
|
||||||
} else {
|
} else {
|
||||||
@@ -1245,11 +1245,11 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
||||||
return "False";
|
return "False";
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
public void preprocessOpenAPI() {
|
||||||
// From the title, compute a reasonable name for the package and the API
|
// From the title, compute a reasonable name for the package and the API
|
||||||
String title = openAPI.getInfo().getTitle();
|
String title = openAPI.getInfo().getTitle();
|
||||||
|
|
||||||
@@ -325,7 +325,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
// See docstring for setGenerateToSchema for why we do this
|
// See docstring for setGenerateToSchema for why we do this
|
||||||
additionalProperties.put("generateToSchema", true);
|
additionalProperties.put("generateToSchema", true);
|
||||||
|
|
||||||
super.preprocessOpenAPI(openAPI);
|
super.preprocessOpenAPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -368,11 +368,11 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
||||||
}
|
}
|
||||||
@@ -407,7 +407,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
Schema additionalProperties2 = getAdditionalProperties(p);
|
Schema additionalProperties2 = getAdditionalProperties(p);
|
||||||
String type = additionalProperties2.getType();
|
String type = additionalProperties2.getType();
|
||||||
if (null == type) {
|
if (null == type) {
|
||||||
@@ -416,7 +416,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
}
|
}
|
||||||
String inner = getSchemaType(additionalProperties2);
|
String inner = getSchemaType(additionalProperties2);
|
||||||
return "(Map.Map Text " + inner + ")";
|
return "(Map.Map Text " + inner + ")";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
// Return only the inner type; the wrapping with QueryList is done
|
// Return only the inner type; the wrapping with QueryList is done
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user