forked from loafle/openapi-generator-original
Compare commits
66 Commits
v5.0.0-bet
...
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 |
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/rebar.lock
|
||||
|
||||
# dart
|
||||
samples/client/petstore/dart/petstore/packages
|
||||
samples/client/petstore/dart/flutter_petstore/test/packages
|
||||
samples/client/petstore/dart/petstore/test/packages
|
||||
**/.dart_tool
|
||||
# Dart
|
||||
**/dart*/**/.dart_tool
|
||||
**/dart*/**/.packages
|
||||
**/dart*/**/pubspec.lock
|
||||
# Dart dio
|
||||
**/dart*/**/*.g.dart
|
||||
# Dart jaguar
|
||||
**/dart*/**/*.jser.dart
|
||||
**/dart*/**/*.jretro.dart
|
||||
|
||||
# JS
|
||||
samples/client/petstore/javascript-es6/package-lock.json
|
||||
|
||||
@@ -140,6 +140,8 @@ install:
|
||||
script:
|
||||
# fail fast
|
||||
- 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'
|
||||
- /bin/bash ./bin/utils/detect_carriage_return.sh
|
||||
# fail if generators contain merge conflicts
|
||||
|
||||
@@ -42,6 +42,7 @@ steps:
|
||||
# test java native client
|
||||
- ./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/openapi3/client/petstore/java/native/pom.xml
|
||||
# test all generators with fake petstore spec (2.0, 3.0)
|
||||
- /bin/bash bin/utils/test-fake-petstore-for-all.sh
|
||||
# generate test scripts
|
||||
|
||||
@@ -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:
|
||||
|
||||
: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:
|
||||
|
||||
@@ -784,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-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-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
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
|
||||
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
|
||||
templateDir: modules/openapi-generator/src/main/resources/dart-dio
|
||||
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"
|
||||
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
|
||||
apiNamePrefix: PS
|
||||
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'
|
||||
|
||||
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
|
||||
@@ -32,6 +32,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
| ---------- | ------- |
|
||||
|BuiltList|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|
|
||||
|Uint8List|dart:typed_data|
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|
||||
| Type/Alias | Imports |
|
||||
| ---------- | ------- |
|
||||
|File|FILE|
|
||||
|List|LIST|
|
||||
|Map|STRING_TABLE|
|
||||
|Set|SET|
|
||||
|file|FILE|
|
||||
|
||||
|
||||
## INSTANTIATION TYPES
|
||||
@@ -52,6 +57,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
<li>and</li>
|
||||
<li>as</li>
|
||||
<li>assign</li>
|
||||
<li>attached</li>
|
||||
<li>attribute</li>
|
||||
<li>check</li>
|
||||
<li>class</li>
|
||||
@@ -60,6 +66,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
<li>current</li>
|
||||
<li>debug</li>
|
||||
<li>deferred</li>
|
||||
<li>detachable</li>
|
||||
<li>do</li>
|
||||
<li>else</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|
|
||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||
|sourceFolder|source folder for generated code| |/app|
|
||||
|supportAsync|Support Async operations| |false|
|
||||
|title|server title name or client service name| |openapi-java-playframework|
|
||||
|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|
|
||||
|
||||
@@ -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|
|
||||
|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|
|
||||
|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|
|
||||
|packageName|Client package name (e.g. PSTwitter).| |PSOpenAPITools|
|
||||
|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|
|
||||
|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|
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -97,7 +97,7 @@ task validateGoodSpec(type: org.openapitools.generator.gradle.plugin.tasks.Valid
|
||||
[source,group]
|
||||
----
|
||||
plugins {
|
||||
id "org.openapi.generator" version "5.0.0-beta3"
|
||||
id "org.openapi.generator" version "4.3.1"
|
||||
}
|
||||
----
|
||||
|
||||
@@ -113,7 +113,7 @@ buildscript {
|
||||
// url "https://plugins.gradle.org/m2/"
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:5.0.0-beta3"
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:4.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# RELEASE_VERSION
|
||||
openApiGeneratorVersion=5.0.0-beta3
|
||||
openApiGeneratorVersion=5.0.0-SNAPSHOT
|
||||
# /RELEASE_VERSION
|
||||
|
||||
# BEGIN placeholders
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -18,5 +18,5 @@ gradle generateGoWithInvalidSpec # expected outcome: BUILD FAILED
|
||||
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
|
||||
|
||||
```bash
|
||||
gradle -PopenApiGeneratorVersion=5.0.0-beta3 openApiValidate
|
||||
gradle -PopenApiGeneratorVersion=4.3.0 openApiValidate
|
||||
```
|
||||
|
||||
@@ -12,7 +12,7 @@ Add to your `build->plugins` section (default phase is `generate-sources` phase)
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>4.3.1</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>5.0.0-beta3</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -150,9 +150,9 @@ public interface CodegenConfig {
|
||||
|
||||
Map<String, String> reservedWordsMappings();
|
||||
|
||||
void preprocessOpenAPI(OpenAPI openAPI);
|
||||
void preprocessOpenAPI();
|
||||
|
||||
void processOpenAPI(OpenAPI openAPI);
|
||||
void processOpenAPI();
|
||||
|
||||
Compiler processCompiler(Compiler compiler);
|
||||
|
||||
|
||||
@@ -111,8 +111,8 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
||||
/**
|
||||
* True if this property is an array of items or a map container.
|
||||
* See:
|
||||
* - ModelUtils.isArraySchema()
|
||||
* - ModelUtils.isMapSchema()
|
||||
* - modelUtils.isArraySchema()
|
||||
* - modelUtils.isMapSchema()
|
||||
*/
|
||||
public boolean isContainer;
|
||||
public boolean isString;
|
||||
|
||||
@@ -86,7 +86,8 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
isMap, isArray, isBinary, isFile, schema, jsonSchema, vendorExtensions, items, additionalProperties,
|
||||
vars, requiredVars,
|
||||
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
|
||||
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern());
|
||||
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern(),
|
||||
is1xx, is2xx, is3xx, is4xx, is5xx);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,6 +122,11 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
isFile == that.isFile &&
|
||||
items == that.items &&
|
||||
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(requiredVars, that.requiredVars) &&
|
||||
Objects.equals(headers, that.headers) &&
|
||||
@@ -362,6 +368,11 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
final StringBuilder sb = new StringBuilder("CodegenResponse{");
|
||||
sb.append("headers=").append(headers);
|
||||
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(", examples=").append(examples);
|
||||
sb.append(", dataType='").append(dataType).append('\'');
|
||||
@@ -421,4 +432,15 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
public boolean isWildcard() {
|
||||
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;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.v3.core.util.Json;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
@@ -76,6 +77,7 @@ public class DefaultGenerator implements Generator {
|
||||
protected CodegenConfig config;
|
||||
protected ClientOptInput opts;
|
||||
protected OpenAPI openAPI;
|
||||
protected ModelUtils modelUtils;
|
||||
protected CodegenIgnoreProcessor ignoreProcessor;
|
||||
private Boolean generateApis = null;
|
||||
private Boolean generateModels = null;
|
||||
@@ -108,7 +110,10 @@ public class DefaultGenerator implements Generator {
|
||||
public Generator opts(ClientOptInput opts) {
|
||||
this.opts = opts;
|
||||
this.openAPI = opts.getOpenAPI();
|
||||
this.modelUtils = new ModelUtils(openAPI);
|
||||
this.config = opts.getConfig();
|
||||
this.config.setOpenAPI(this.openAPI);
|
||||
|
||||
List<TemplateDefinition> userFiles = opts.getUserDefinedTemplates();
|
||||
if (userFiles != null) {
|
||||
this.userDefinedTemplates = ImmutableList.copyOf(userFiles);
|
||||
@@ -152,6 +157,10 @@ public class DefaultGenerator implements Generator {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModelUtils getModelUtils() {
|
||||
return modelUtils;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an instance to the configured template processor, available after user-defined options are
|
||||
* applied via {@link DefaultGenerator#opts(ClientOptInput)}.
|
||||
@@ -248,10 +257,7 @@ public class DefaultGenerator implements Generator {
|
||||
}
|
||||
|
||||
config.processOpts();
|
||||
config.preprocessOpenAPI(openAPI);
|
||||
|
||||
// set OpenAPI to make these available to all methods
|
||||
config.setOpenAPI(openAPI);
|
||||
config.preprocessOpenAPI();
|
||||
|
||||
config.additionalProperties().put("generatorVersion", ImplementationVersion.read());
|
||||
config.additionalProperties().put("generatedDate", ZonedDateTime.now().toString());
|
||||
@@ -397,7 +403,7 @@ public class DefaultGenerator implements Generator {
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<String, Schema> schemas = ModelUtils.getSchemas(this.openAPI);
|
||||
final Map<String, Schema> schemas = modelUtils.getSchemas();
|
||||
if (schemas == null) {
|
||||
LOGGER.warn("Skipping generation of models because specification document has no schemas.");
|
||||
return;
|
||||
@@ -458,7 +464,7 @@ public class DefaultGenerator implements Generator {
|
||||
|
||||
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
|
||||
// 1. free form with no validation that is not allOf included in any composed schemas
|
||||
// 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);
|
||||
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
|
||||
// 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.
|
||||
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
|
||||
LOGGER.info("Model {} not generated since it's an alias to map (without property) and `generateAliasAsModel` is set to false (default)", name);
|
||||
continue;
|
||||
}
|
||||
} else if (ModelUtils.isArraySchema(schema)) { // check to see if it's an "array" model
|
||||
if (!ModelUtils.isGenerateAliasAsModel(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
|
||||
} else if (modelUtils.isArraySchema(schema)) { // check to see if it's an "array" model
|
||||
if (!modelUtils.isGenerateAliasAsModel(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
|
||||
// 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);
|
||||
continue;
|
||||
@@ -769,7 +775,7 @@ public class DefaultGenerator implements Generator {
|
||||
bundle.put("basePathWithoutHost", basePathWithoutHost);
|
||||
bundle.put("scheme", URLPathUtils.getScheme(url, config));
|
||||
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("contextPath", contextPath);
|
||||
@@ -856,19 +862,19 @@ public class DefaultGenerator implements Generator {
|
||||
}
|
||||
|
||||
// resolve inline models
|
||||
InlineModelResolver inlineModelResolver = new InlineModelResolver();
|
||||
inlineModelResolver.flatten(openAPI);
|
||||
InlineModelResolver inlineModelResolver = new InlineModelResolver(openAPI);
|
||||
inlineModelResolver.flatten();
|
||||
|
||||
configureGeneratorProperties();
|
||||
configureOpenAPIInfo();
|
||||
|
||||
config.processOpenAPI(openAPI);
|
||||
config.processOpenAPI();
|
||||
|
||||
processUserDefinedTemplates();
|
||||
|
||||
List<File> files = new ArrayList<>();
|
||||
// models
|
||||
List<String> filteredSchemas = ModelUtils.getSchemasUsedOnlyInFormParam(openAPI);
|
||||
List<String> filteredSchemas = modelUtils.getSchemasUsedOnlyInFormParam();
|
||||
List<Object> allModels = new ArrayList<>();
|
||||
generateModels(files, allModels, filteredSchemas);
|
||||
// apis
|
||||
|
||||
@@ -38,7 +38,8 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class InlineModelResolver {
|
||||
private OpenAPI openapi;
|
||||
private OpenAPI openAPI;
|
||||
private ModelUtils modelUtils;
|
||||
private Map<String, Schema> addedModels = new HashMap<String, Schema>();
|
||||
private Map<String, String> generatedSignature = new HashMap<String, String>();
|
||||
|
||||
@@ -54,27 +55,36 @@ public class InlineModelResolver {
|
||||
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(InlineModelResolver.class);
|
||||
|
||||
void flatten(OpenAPI openapi) {
|
||||
this.openapi = openapi;
|
||||
public InlineModelResolver(OpenAPI openAPI) {
|
||||
this.openAPI = openAPI;
|
||||
this.modelUtils = new ModelUtils(openAPI);
|
||||
}
|
||||
|
||||
if (openapi.getComponents() == null) {
|
||||
openapi.setComponents(new Components());
|
||||
public OpenAPI getOpenAPI() {
|
||||
return this.openAPI;
|
||||
}
|
||||
|
||||
public ModelUtils getModelUtils() {
|
||||
return this.modelUtils;
|
||||
}
|
||||
|
||||
void flatten() {
|
||||
if (openAPI.getComponents() == null) {
|
||||
openAPI.setComponents(new Components());
|
||||
}
|
||||
|
||||
if (openapi.getComponents().getSchemas() == null) {
|
||||
openapi.getComponents().setSchemas(new HashMap<String, Schema>());
|
||||
if (openAPI.getComponents().getSchemas() == null) {
|
||||
openAPI.getComponents().setSchemas(new HashMap<String, Schema>());
|
||||
}
|
||||
|
||||
flattenPaths(openapi);
|
||||
flattenComponents(openapi);
|
||||
flattenPaths();
|
||||
flattenComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten inline models in Paths
|
||||
*
|
||||
* @param openAPI target spec
|
||||
*/
|
||||
private void flattenPaths(OpenAPI openAPI) {
|
||||
private void flattenPaths() {
|
||||
Paths paths = openAPI.getPaths();
|
||||
if (paths == null) {
|
||||
return;
|
||||
@@ -96,9 +106,9 @@ public class InlineModelResolver {
|
||||
}
|
||||
|
||||
for (Operation operation : operations) {
|
||||
flattenRequestBody(openAPI, pathname, operation);
|
||||
flattenParameters(openAPI, pathname, operation);
|
||||
flattenResponses(openAPI, pathname, operation);
|
||||
flattenRequestBody(pathname, operation);
|
||||
flattenParameters(pathname, operation);
|
||||
flattenResponses(pathname, operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,22 +116,21 @@ public class InlineModelResolver {
|
||||
/**
|
||||
* Flatten inline models in RequestBody
|
||||
*
|
||||
* @param openAPI target spec
|
||||
* @param pathname target pathname
|
||||
* @param pathname target pathname
|
||||
* @param operation target operation
|
||||
*/
|
||||
private void flattenRequestBody(OpenAPI openAPI, String pathname, Operation operation) {
|
||||
private void flattenRequestBody(String pathname, Operation operation) {
|
||||
RequestBody requestBody = operation.getRequestBody();
|
||||
if (requestBody == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema model = ModelUtils.getSchemaFromRequestBody(requestBody);
|
||||
Schema model = modelUtils.getSchemaFromRequestBody(requestBody);
|
||||
if (model instanceof ObjectSchema) {
|
||||
Schema obj = (Schema) model;
|
||||
if (obj.getType() == null || "object".equals(obj.getType())) {
|
||||
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'
|
||||
String modelName = resolveModelName(obj.getTitle(), "inline_object");
|
||||
addGenerated(modelName, model);
|
||||
@@ -163,7 +172,6 @@ public class InlineModelResolver {
|
||||
|
||||
// update requestBody to use $ref instead of inline def
|
||||
requestBody.set$ref(modelName);
|
||||
|
||||
}
|
||||
}
|
||||
} else if (model instanceof ArraySchema) {
|
||||
@@ -172,10 +180,10 @@ public class InlineModelResolver {
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
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.
|
||||
String modelName = resolveModelName(op.getTitle(), null);
|
||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
@@ -196,11 +204,10 @@ public class InlineModelResolver {
|
||||
/**
|
||||
* Flatten inline models in parameters
|
||||
*
|
||||
* @param openAPI target spec
|
||||
* @param pathname target pathname
|
||||
* @param pathname target pathname
|
||||
* @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();
|
||||
if (parameters == null) {
|
||||
return;
|
||||
@@ -216,7 +223,7 @@ public class InlineModelResolver {
|
||||
Schema obj = (Schema) model;
|
||||
if (obj.getType() == null || "object".equals(obj.getType())) {
|
||||
if (obj.getProperties() != null && obj.getProperties().size() > 0) {
|
||||
flattenProperties(openAPI, obj.getProperties(), pathname);
|
||||
flattenProperties(obj.getProperties(), pathname);
|
||||
String modelName = resolveModelName(obj.getTitle(), parameter.getName());
|
||||
|
||||
parameter.$ref(modelName);
|
||||
@@ -230,9 +237,9 @@ public class InlineModelResolver {
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(openAPI, op.getProperties(), pathname);
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
String modelName = resolveModelName(op.getTitle(), parameter.getName());
|
||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
@@ -254,11 +261,10 @@ public class InlineModelResolver {
|
||||
/**
|
||||
* Flatten inline models in ApiResponses
|
||||
*
|
||||
* @param openAPI target spec
|
||||
* @param pathname target pathname
|
||||
* @param pathname target pathname
|
||||
* @param operation target operation
|
||||
*/
|
||||
private void flattenResponses(OpenAPI openAPI, String pathname, Operation operation) {
|
||||
private void flattenResponses(String pathname, Operation operation) {
|
||||
ApiResponses responses = operation.getResponses();
|
||||
if (responses == null) {
|
||||
return;
|
||||
@@ -266,16 +272,16 @@ public class InlineModelResolver {
|
||||
|
||||
for (String key : responses.keySet()) {
|
||||
ApiResponse response = responses.get(key);
|
||||
if (ModelUtils.getSchemaFromResponse(response) == null) {
|
||||
if (modelUtils.getSchemaFromResponse(response) == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Schema property = ModelUtils.getSchemaFromResponse(response);
|
||||
Schema property = modelUtils.getSchemaFromResponse(response);
|
||||
if (property instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) property;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
String modelName = resolveModelName(op.getTitle(), "inline_response_" + key);
|
||||
Schema model = modelFromProperty(openAPI, op, modelName);
|
||||
Schema model = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(model);
|
||||
Content content = response.getContent();
|
||||
for (MediaType mediaType : content.values()) {
|
||||
@@ -298,10 +304,10 @@ public class InlineModelResolver {
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(openAPI, op.getProperties(), pathname);
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
String modelName = resolveModelName(op.getTitle(),
|
||||
"inline_response_" + key);
|
||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = this.makeSchema(existing, op);
|
||||
@@ -318,14 +324,14 @@ public class InlineModelResolver {
|
||||
}
|
||||
} else if (property instanceof MapSchema) {
|
||||
MapSchema mp = (MapSchema) property;
|
||||
Schema innerProperty = ModelUtils.getAdditionalProperties(openAPI, mp);
|
||||
Schema innerProperty = modelUtils.getAdditionalProperties(mp);
|
||||
if (innerProperty instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) innerProperty;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(openAPI, op.getProperties(), pathname);
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
String modelName = resolveModelName(op.getTitle(),
|
||||
"inline_response_" + key);
|
||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
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
|
||||
* single flat list of properties. This is useful to generate a single or multiple
|
||||
* inheritance model.
|
||||
*
|
||||
* <p>
|
||||
* 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
|
||||
* are flattened as a single list of properties.
|
||||
*
|
||||
* <p>
|
||||
* Dog:
|
||||
* allOf:
|
||||
* - $ref: '#/components/schemas/Animal'
|
||||
* - type: object
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* age:
|
||||
* type: string
|
||||
* - type: object
|
||||
* properties:
|
||||
* breed:
|
||||
* type: string
|
||||
* allOf:
|
||||
* - $ref: '#/components/schemas/Animal'
|
||||
* - type: object
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* age:
|
||||
* type: string
|
||||
* - type: object
|
||||
* properties:
|
||||
* breed:
|
||||
* 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).
|
||||
*/
|
||||
private void flattenComposedChildren(OpenAPI openAPI, String key, List<Schema> children) {
|
||||
private void flattenComposedChildren(String key, List<Schema> children) {
|
||||
if (children == null || children.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -394,7 +399,7 @@ public class InlineModelResolver {
|
||||
// To have complete control of the model naming, one can define the model separately
|
||||
// instead of inline.
|
||||
String innerModelName = resolveModelName(op.getTitle(), key);
|
||||
Schema innerModel = modelFromProperty(openAPI, op, innerModelName);
|
||||
Schema innerModel = modelFromProperty(op, innerModelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing == null) {
|
||||
openAPI.getComponents().addSchemas(innerModelName, innerModel);
|
||||
@@ -416,10 +421,8 @@ public class InlineModelResolver {
|
||||
|
||||
/**
|
||||
* Flatten inline models in components
|
||||
*
|
||||
* @param openAPI target spec
|
||||
*/
|
||||
private void flattenComponents(OpenAPI openAPI) {
|
||||
private void flattenComponents() {
|
||||
Map<String, Schema> models = openAPI.getComponents().getSchemas();
|
||||
if (models == null) {
|
||||
return;
|
||||
@@ -428,25 +431,25 @@ public class InlineModelResolver {
|
||||
List<String> modelNames = new ArrayList<String>(models.keySet());
|
||||
for (String modelName : modelNames) {
|
||||
Schema model = models.get(modelName);
|
||||
if (ModelUtils.isComposedSchema(model)) {
|
||||
if (modelUtils.isComposedSchema(model)) {
|
||||
ComposedSchema m = (ComposedSchema) model;
|
||||
// inline child schemas
|
||||
flattenComposedChildren(openAPI, modelName + "_allOf", m.getAllOf());
|
||||
flattenComposedChildren(openAPI, modelName + "_anyOf", m.getAnyOf());
|
||||
flattenComposedChildren(openAPI, modelName + "_oneOf", m.getOneOf());
|
||||
flattenComposedChildren(modelName + "_allOf", m.getAllOf());
|
||||
flattenComposedChildren(modelName + "_anyOf", m.getAnyOf());
|
||||
flattenComposedChildren(modelName + "_oneOf", m.getOneOf());
|
||||
} else if (model instanceof Schema) {
|
||||
Schema m = (Schema) model;
|
||||
Map<String, Schema> properties = m.getProperties();
|
||||
flattenProperties(openAPI, properties, modelName);
|
||||
flattenProperties(properties, modelName);
|
||||
fixStringModel(m);
|
||||
} else if (ModelUtils.isArraySchema(model)) {
|
||||
} else if (modelUtils.isArraySchema(model)) {
|
||||
ArraySchema m = (ArraySchema) model;
|
||||
Schema inner = m.getItems();
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
String innerModelName = resolveModelName(op.getTitle(), modelName + "_inner");
|
||||
Schema innerModel = modelFromProperty(openAPI, op, innerModelName);
|
||||
Schema innerModel = modelFromProperty(op, innerModelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing == null) {
|
||||
openAPI.getComponents().addSchemas(innerModelName, innerModel);
|
||||
@@ -483,12 +486,11 @@ public class InlineModelResolver {
|
||||
/**
|
||||
* Generates a unique model name. Non-alphanumeric characters will be replaced
|
||||
* with underscores
|
||||
*
|
||||
* <p>
|
||||
* e.g. io.schema.User_name => io_schema_User_name
|
||||
*
|
||||
* @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}
|
||||
*/
|
||||
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
|
||||
*
|
||||
* <p>
|
||||
* e.g. 12.schema.User name => _2_schema_User_name
|
||||
*/
|
||||
private String sanitizeName(final String name) {
|
||||
return name
|
||||
.replaceAll("^[0-9]", "_") // e.g. 12object => _2object
|
||||
.replaceAll("[^A-Za-z0-9]", "_"); // e.g. io.schema.User name => io_schema_User_name
|
||||
.replaceAll("^[0-9]", "_") // e.g. 12object => _2object
|
||||
.replaceAll("[^A-Za-z0-9]", "_"); // e.g. io.schema.User name => io_schema_User_name
|
||||
}
|
||||
|
||||
private String uniqueName(final String name) {
|
||||
if (openapi.getComponents().getSchemas() == null) {
|
||||
if (openAPI.getComponents().getSchemas() == null) {
|
||||
return name;
|
||||
}
|
||||
|
||||
String uniqueName = name;
|
||||
int count = 0;
|
||||
while (true) {
|
||||
if (!openapi.getComponents().getSchemas().containsKey(uniqueName)) {
|
||||
if (!openAPI.getComponents().getSchemas().containsKey(uniqueName)) {
|
||||
return uniqueName;
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
private void flattenProperties(OpenAPI openAPI, Map<String, Schema> properties, String path) {
|
||||
private void flattenProperties(Map<String, Schema> properties, String path) {
|
||||
if (properties == null) {
|
||||
return;
|
||||
}
|
||||
@@ -564,7 +566,7 @@ public class InlineModelResolver {
|
||||
&& ((ObjectSchema) property).getProperties().size() > 0) {
|
||||
ObjectSchema op = (ObjectSchema) property;
|
||||
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
||||
Schema model = modelFromProperty(openAPI, op, modelName);
|
||||
Schema model = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(model);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
@@ -576,7 +578,7 @@ public class InlineModelResolver {
|
||||
propsToUpdate.put(key, schema);
|
||||
modelsToAdd.put(modelName, model);
|
||||
addGenerated(modelName, model);
|
||||
openapi.getComponents().addSchemas(modelName, model);
|
||||
openAPI.getComponents().addSchemas(modelName, model);
|
||||
}
|
||||
} else if (property instanceof ArraySchema) {
|
||||
ArraySchema ap = (ArraySchema) property;
|
||||
@@ -584,9 +586,9 @@ public class InlineModelResolver {
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(openAPI, op.getProperties(), path);
|
||||
flattenProperties(op.getProperties(), path);
|
||||
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
@@ -597,19 +599,19 @@ public class InlineModelResolver {
|
||||
schema.setRequired(op.getRequired());
|
||||
ap.setItems(schema);
|
||||
addGenerated(modelName, innerModel);
|
||||
openapi.getComponents().addSchemas(modelName, innerModel);
|
||||
openAPI.getComponents().addSchemas(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ModelUtils.isMapSchema(property)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(openAPI, property);
|
||||
if (modelUtils.isMapSchema(property)) {
|
||||
Schema inner = modelUtils.getAdditionalProperties(property);
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(openAPI, op.getProperties(), path);
|
||||
flattenProperties(op.getProperties(), path);
|
||||
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
||||
Schema innerModel = modelFromProperty(openAPI, op, modelName);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
@@ -620,7 +622,7 @@ public class InlineModelResolver {
|
||||
schema.setRequired(op.getRequired());
|
||||
property.setAdditionalProperties(schema);
|
||||
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()) {
|
||||
openapi.getComponents().addSchemas(key, modelsToAdd.get(key));
|
||||
openAPI.getComponents().addSchemas(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 example = null;
|
||||
Object obj = object.getExample();
|
||||
@@ -686,7 +688,7 @@ public class InlineModelResolver {
|
||||
model.setDeprecated(object.getDeprecated());
|
||||
|
||||
if (properties != null) {
|
||||
flattenProperties(openAPI, properties, path);
|
||||
flattenProperties(properties, path);
|
||||
model.setProperties(properties);
|
||||
}
|
||||
return model;
|
||||
@@ -715,7 +717,7 @@ public class InlineModelResolver {
|
||||
private void copyVendorExtensions(Schema source, Schema target) {
|
||||
Map<String, Object> vendorExtensions = source.getExtensions();
|
||||
if (vendorExtensions == null) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
for (String extName : vendorExtensions.keySet()) {
|
||||
target.addExtension(extName, vendorExtensions.get(extName));
|
||||
|
||||
@@ -264,7 +264,7 @@ public class CodegenConfigurator {
|
||||
|
||||
public CodegenConfigurator setGenerateAliasAsModel(boolean generateAliasAsModel) {
|
||||
workflowSettingsBuilder.withGenerateAliasAsModel(generateAliasAsModel);
|
||||
ModelUtils.setGenerateAliasAsModel(generateAliasAsModel);
|
||||
GlobalSettings.setProperty("generateAliasAsModelKey", String.valueOf(generateAliasAsModel));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -508,9 +508,6 @@ public class CodegenConfigurator {
|
||||
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)
|
||||
final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth);
|
||||
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.
|
||||
// https://github.com/swagger-api/swagger-parser/issues/1369
|
||||
// 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.
|
||||
if (validationMessages.size() > 0) {
|
||||
Set<String> warnings = new HashSet<>();
|
||||
if (specification != null) {
|
||||
List<String> unusedModels = ModelUtils.getUnusedSchemas(specification);
|
||||
List<String> unusedModels = modelUtils.getUnusedSchemas();
|
||||
if (unusedModels != null) {
|
||||
unusedModels.forEach(name -> warnings.add("Unused model: " + name));
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
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.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
@@ -46,11 +47,13 @@ public class ExampleGenerator {
|
||||
|
||||
protected Map<String, Schema> examples;
|
||||
private OpenAPI openAPI;
|
||||
private ModelUtils modelUtils;
|
||||
private Random random;
|
||||
|
||||
public ExampleGenerator(Map<String, Schema> examples, OpenAPI openAPI) {
|
||||
this.examples = examples;
|
||||
this.openAPI = openAPI;
|
||||
this.modelUtils = new ModelUtils(openAPI);
|
||||
// use a fixed seed to make the "random" numbers reproducible.
|
||||
this.random = new Random("ExampleGenerator".hashCode());
|
||||
}
|
||||
@@ -69,7 +72,7 @@ public class ExampleGenerator {
|
||||
}
|
||||
|
||||
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
|
||||
return null;
|
||||
}
|
||||
@@ -78,14 +81,14 @@ public class ExampleGenerator {
|
||||
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;
|
||||
if (as.getItems() != null && StringUtils.isEmpty(as.getItems().get$ref())) { // arary of primtive types
|
||||
return generate((Map<String, Object>) responseSchema.getExample(),
|
||||
new ArrayList<String>(producesInfo), as.getItems());
|
||||
} else if (as.getItems() != null && !StringUtils.isEmpty(as.getItems().get$ref())) { // array of model
|
||||
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 {
|
||||
// TODO log warning message as such case is not handled at the moment
|
||||
return null;
|
||||
@@ -95,7 +98,7 @@ public class ExampleGenerator {
|
||||
new ArrayList<String>(producesInfo), responseSchema);
|
||||
} else { // model
|
||||
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);
|
||||
}
|
||||
} 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) {
|
||||
kv.put(EXAMPLE, example);
|
||||
output.add(kv);
|
||||
@@ -165,7 +168,7 @@ public class ExampleGenerator {
|
||||
}
|
||||
} else if (modelName != null && mediaType.startsWith(MIME_TYPE_XML)) {
|
||||
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) {
|
||||
kv.put(EXAMPLE, example);
|
||||
output.add(kv);
|
||||
@@ -222,13 +225,13 @@ public class ExampleGenerator {
|
||||
if (property.getExample() != null) {
|
||||
LOGGER.debug("Example set in openapi spec, returning example: '{}'", property.getExample().toString());
|
||||
return property.getExample();
|
||||
} else if (ModelUtils.isBooleanSchema(property)) {
|
||||
} else if (modelUtils.isBooleanSchema(property)) {
|
||||
Object defaultValue = property.getDefault();
|
||||
if (defaultValue != null) {
|
||||
return defaultValue;
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
} else if (ModelUtils.isArraySchema(property)) {
|
||||
} else if (modelUtils.isArraySchema(property)) {
|
||||
Schema innerType = ((ArraySchema) property).getItems();
|
||||
if (innerType != null) {
|
||||
int arrayLength = null == ((ArraySchema) property).getMaxItems() ? 2 : ((ArraySchema) property).getMaxItems();
|
||||
@@ -241,45 +244,45 @@ public class ExampleGenerator {
|
||||
}
|
||||
return objectProperties;
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(property)) {
|
||||
} else if (modelUtils.isDateSchema(property)) {
|
||||
return "2000-01-23";
|
||||
} else if (ModelUtils.isDateTimeSchema(property)) {
|
||||
} else if (modelUtils.isDateTimeSchema(property)) {
|
||||
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 max = getPropertyValue(property.getMaximum());
|
||||
if (ModelUtils.isFloatSchema(property)) { // float
|
||||
if (modelUtils.isFloatSchema(property)) { // float
|
||||
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));
|
||||
} else { // no format defined
|
||||
return randomNumber(min, max);
|
||||
}
|
||||
} else if (ModelUtils.isFileSchema(property)) {
|
||||
} else if (modelUtils.isFileSchema(property)) {
|
||||
return ""; // TODO
|
||||
|
||||
} else if (ModelUtils.isIntegerSchema(property)) {
|
||||
} else if (modelUtils.isIntegerSchema(property)) {
|
||||
Double min = getPropertyValue(property.getMinimum());
|
||||
Double max = getPropertyValue(property.getMaximum());
|
||||
if (ModelUtils.isLongSchema(property)) {
|
||||
if (modelUtils.isLongSchema(property)) {
|
||||
return (long) 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>();
|
||||
if (property.getName() != null) {
|
||||
mp.put(property.getName(),
|
||||
resolvePropertyToExample(propertyName, mediaType, ModelUtils.getAdditionalProperties(openAPI, property), processedModels));
|
||||
resolvePropertyToExample(propertyName, mediaType, modelUtils.getAdditionalProperties(property), processedModels));
|
||||
} else {
|
||||
mp.put("key",
|
||||
resolvePropertyToExample(propertyName, mediaType, ModelUtils.getAdditionalProperties(openAPI, property), processedModels));
|
||||
resolvePropertyToExample(propertyName, mediaType, modelUtils.getAdditionalProperties(property), processedModels));
|
||||
}
|
||||
return mp;
|
||||
} else if (ModelUtils.isUUIDSchema(property)) {
|
||||
} else if (modelUtils.isUUIDSchema(property)) {
|
||||
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
||||
} else if (ModelUtils.isURISchema(property)) {
|
||||
} else if (modelUtils.isURISchema(property)) {
|
||||
return "https://openapi-generator.tech";
|
||||
} else if (ModelUtils.isStringSchema(property)) {
|
||||
} else if (modelUtils.isStringSchema(property)) {
|
||||
LOGGER.debug("String property");
|
||||
String defaultValue = (String) property.getDefault();
|
||||
if (defaultValue != null && !defaultValue.isEmpty()) {
|
||||
@@ -299,14 +302,14 @@ public class ExampleGenerator {
|
||||
LOGGER.debug("No values found, using property name " + propertyName + " as example");
|
||||
return propertyName;
|
||||
} else if (!StringUtils.isEmpty(property.get$ref())) { // model
|
||||
String simpleName = ModelUtils.getSimpleRef(property.get$ref());
|
||||
Schema schema = ModelUtils.getSchema(openAPI, simpleName);
|
||||
String simpleName = modelUtils.getSimpleRef(property.get$ref());
|
||||
Schema schema = modelUtils.getSchema(simpleName);
|
||||
if (schema == null) { // couldn't find the model/schema
|
||||
return "{}";
|
||||
}
|
||||
return resolveModelToExample(simpleName, mediaType, schema, processedModels);
|
||||
|
||||
} else if (ModelUtils.isObjectSchema(property)) {
|
||||
} else if (modelUtils.isObjectSchema(property)) {
|
||||
return "{}";
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
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.Schema;
|
||||
import io.swagger.v3.oas.models.media.XML;
|
||||
@@ -35,8 +36,12 @@ public class XmlExampleGenerator {
|
||||
public static String TAG_END = "</";
|
||||
private static String EMPTY = "";
|
||||
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;
|
||||
if (examples == null) {
|
||||
this.examples = new HashMap<String, Schema>();
|
||||
@@ -124,7 +129,7 @@ public class XmlExampleGenerator {
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
if (modelUtils.isArraySchema(schema)) {
|
||||
ArraySchema as = (ArraySchema) schema;
|
||||
Schema inner = as.getItems();
|
||||
boolean wrapped = false;
|
||||
@@ -177,29 +182,29 @@ public class XmlExampleGenerator {
|
||||
protected String getExample(Schema schema) {
|
||||
if (schema.getExample() != null) {
|
||||
return schema.getExample().toString();
|
||||
} else if (ModelUtils.isDateTimeSchema(schema)) {
|
||||
} else if (modelUtils.isDateTimeSchema(schema)) {
|
||||
return "2000-01-23T04:56:07.000Z";
|
||||
} else if (ModelUtils.isDateSchema(schema)) {
|
||||
} else if (modelUtils.isDateSchema(schema)) {
|
||||
return "2000-01-23";
|
||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
||||
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||
return "true";
|
||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
||||
if (ModelUtils.isFloatSchema(schema)) { // float
|
||||
} else if (modelUtils.isNumberSchema(schema)) {
|
||||
if (modelUtils.isFloatSchema(schema)) { // float
|
||||
return "1.3579";
|
||||
} else { // double
|
||||
return "3.149";
|
||||
}
|
||||
} else if (ModelUtils.isPasswordSchema(schema)) {
|
||||
} else if (modelUtils.isPasswordSchema(schema)) {
|
||||
return "********";
|
||||
} else if (ModelUtils.isUUIDSchema(schema)) {
|
||||
} else if (modelUtils.isUUIDSchema(schema)) {
|
||||
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
||||
} else if (ModelUtils.isURISchema(schema)) {
|
||||
} else if (modelUtils.isURISchema(schema)) {
|
||||
return "https://openapi-generator.tech";
|
||||
// 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";
|
||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
||||
if (ModelUtils.isLongSchema(schema)) { // long
|
||||
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||
if (modelUtils.isLongSchema(schema)) { // long
|
||||
return "123456789";
|
||||
} else { //integer
|
||||
return "123";
|
||||
|
||||
@@ -410,12 +410,12 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
schemaType = schemaType.replace("-", "_");
|
||||
}
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getTypeDeclaration(inner) + "_Vectors.Vector";
|
||||
}
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
String name = getTypeDeclaration(inner) + "_Map";
|
||||
if (name.startsWith("Swagger.")) {
|
||||
@@ -432,7 +432,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
return schemaType;
|
||||
}
|
||||
String modelType = toModelName(schemaType).replace("-", "_");
|
||||
if (ModelUtils.isStringSchema(p) || ModelUtils.isFileSchema(p)
|
||||
if (modelUtils.isStringSchema(p) || modelUtils.isFileSchema(p)
|
||||
|| languageSpecificPrimitives.contains(modelType)) {
|
||||
return modelType;
|
||||
}
|
||||
@@ -526,8 +526,8 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
||||
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
||||
if (methodResponse != null && ModelUtils.getSchemaFromResponse(methodResponse) != null) {
|
||||
CodegenProperty cm = fromProperty("response", ModelUtils.getSchemaFromResponse(methodResponse));
|
||||
if (methodResponse != null && modelUtils.getSchemaFromResponse(methodResponse) != null) {
|
||||
CodegenProperty cm = fromProperty("response", modelUtils.getSchemaFromResponse(methodResponse));
|
||||
op.vendorExtensions.put("x-codegen-response", cm);
|
||||
op.vendorExtensions.put("x-is-model-type", isModelType(cm));
|
||||
op.vendorExtensions.put("x-is-stream-type", isStreamType(cm));
|
||||
|
||||
@@ -185,7 +185,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
if (inner == null) {
|
||||
@@ -194,7 +194,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
return null;
|
||||
}
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
|
||||
if (inner == null) {
|
||||
@@ -217,7 +217,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
final ArraySchema ap = (ArraySchema) p;
|
||||
final String pattern = "new ArrayList<%s>()";
|
||||
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()));
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
final MapSchema ap = (MapSchema) p;
|
||||
final String pattern = "new HashMap<%s>()";
|
||||
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))));
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
} else if (modelUtils.isLongSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "l";
|
||||
}
|
||||
return "null";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return "null";
|
||||
} else if (ModelUtils.isFloatSchema(p)) {
|
||||
} else if (modelUtils.isFloatSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "f";
|
||||
}
|
||||
return "null";
|
||||
} else if (ModelUtils.isDoubleSchema(p)) {
|
||||
} else if (modelUtils.isDoubleSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "d";
|
||||
}
|
||||
return "null";
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
} else if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return "null";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
String _default = (String) p.getDefault();
|
||||
if (p.getEnum() == null) {
|
||||
@@ -314,18 +314,18 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
Object obj = p.getExample();
|
||||
String example = obj == null ? "" : obj.toString();
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
example = "new " + getTypeDeclaration(p) + "{" + toExampleValue(
|
||||
((ArraySchema) p).getItems()) + "}";
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
} else if (modelUtils.isBooleanSchema(p)) {
|
||||
example = String.valueOf(!"false".equals(example));
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
} else if (modelUtils.isByteArraySchema(p)) {
|
||||
if (example.isEmpty()) {
|
||||
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
||||
}
|
||||
p.setExample(example);
|
||||
example = "EncodingUtil.base64Decode('" + example + "')";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
if (example.matches("^\\d{4}(-\\d{2}){2}")) {
|
||||
example = example.substring(0, 10).replaceAll("-0?", ", ");
|
||||
} else if (example.isEmpty()) {
|
||||
@@ -336,7 +336,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
example = "2000, 1, 23";
|
||||
}
|
||||
example = "Date.newInstance(" + example + ")";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
if (example.matches("^\\d{4}([-T:]\\d{2}){5}.+")) {
|
||||
example = example.substring(0, 19).replaceAll("[-T:]0?", ", ");
|
||||
} else if (example.isEmpty()) {
|
||||
@@ -347,31 +347,31 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
example = "2000, 1, 23, 4, 56, 7";
|
||||
}
|
||||
example = "Datetime.newInstanceGmt(" + example + ")";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
example = example.replaceAll("[^-0-9.]", "");
|
||||
example = example.isEmpty() ? "1.3579" : example;
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
} else if (modelUtils.isFileSchema(p)) {
|
||||
if (example.isEmpty()) {
|
||||
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
||||
p.setExample(example);
|
||||
}
|
||||
example = "EncodingUtil.base64Decode(" + example + ")";
|
||||
} else if (ModelUtils.isEmailSchema(p)) {
|
||||
} else if (modelUtils.isEmailSchema(p)) {
|
||||
if (example.isEmpty()) {
|
||||
example = "example@example.com";
|
||||
p.setExample(example);
|
||||
}
|
||||
example = "'" + example + "'";
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
} else if (modelUtils.isLongSchema(p)) {
|
||||
example = example.isEmpty() ? "123456789L" : example + "L";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(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);
|
||||
p.setExample(example);
|
||||
example = "'" + example + "'";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
List<String> enums = p.getEnum();
|
||||
if (enums != null && example.isEmpty()) {
|
||||
example = enums.get(0);
|
||||
@@ -383,13 +383,13 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
p.setExample(example);
|
||||
}
|
||||
example = "'" + example + "'";
|
||||
} else if (ModelUtils.isUUIDSchema(p)) {
|
||||
} else if (modelUtils.isUUIDSchema(p)) {
|
||||
example = example.isEmpty()
|
||||
? "'046b6c7f-0b8a-43b9-b35d-6489e6daee91'"
|
||||
: "'" + escapeText(example) + "'";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
example = example.matches("^-?\\d+$") ? example : "0";
|
||||
} else if (ModelUtils.isObjectSchema(p)) {
|
||||
} else if (modelUtils.isObjectSchema(p)) {
|
||||
example = example.isEmpty() ? "null" : example;
|
||||
} else {
|
||||
example = getTypeDeclaration(p) + ".getExample()";
|
||||
@@ -571,7 +571,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
if (op.getHasExamples()) {
|
||||
// prepare examples for Apex test classes
|
||||
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
||||
final Schema responseSchema = ModelUtils.getSchemaFromResponse(apiResponse);
|
||||
final Schema responseSchema = modelUtils.getSchemaFromResponse(apiResponse);
|
||||
String deserializedExample = toExampleValue(responseSchema);
|
||||
for (Map<String, String> example : op.examples) {
|
||||
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) {
|
||||
Map<String, CodegenModel> enumRefs = new HashMap<String, CodegenModel>();
|
||||
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) {
|
||||
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()) {
|
||||
String openAPIName = entry.getKey();
|
||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
||||
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||
if (model != null) {
|
||||
for (CodegenProperty var : model.allVars) {
|
||||
if (enumRefs.containsKey(var.dataType)) {
|
||||
@@ -594,7 +594,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
protected void updateValueTypeProperty(Map<String, Object> models) {
|
||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||
String openAPIName = entry.getKey();
|
||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
||||
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||
if (model != null) {
|
||||
for (CodegenProperty var : model.vars) {
|
||||
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) {
|
||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||
String openAPIName = entry.getKey();
|
||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
||||
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||
if (model != null) {
|
||||
for (CodegenProperty var : model.vars) {
|
||||
if (!var.isContainer && (nullableType.contains(var.dataType) || var.isEnum)) {
|
||||
@@ -859,23 +859,23 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
*/
|
||||
@Override
|
||||
public String toExampleValue(Schema p) {
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getExample() != null) {
|
||||
return "\"" + p.getExample().toString() + "\"";
|
||||
}
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
} else if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getExample() != null) {
|
||||
return p.getExample().toString();
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getExample() != null) {
|
||||
return p.getExample().toString();
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getExample() != null) {
|
||||
return p.getExample().toString();
|
||||
}
|
||||
@@ -891,33 +891,33 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
*/
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
}
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
}
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
if (ModelUtils.isFloatSchema(p)) { // float
|
||||
if (modelUtils.isFloatSchema(p)) { // float
|
||||
return p.getDefault().toString() + "F";
|
||||
} else if (ModelUtils.isDoubleSchema(p)) { // double
|
||||
} else if (modelUtils.isDoubleSchema(p)) { // double
|
||||
return p.getDefault().toString() + "D";
|
||||
} else { // decimal
|
||||
return p.getDefault().toString() + "M";
|
||||
}
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
String _default = (String) p.getDefault();
|
||||
if (p.getEnum() == null) {
|
||||
@@ -989,7 +989,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
return getArrayTypeDeclaration((ArraySchema) p);
|
||||
}
|
||||
return super.toInstantiationType(p);
|
||||
@@ -997,9 +997,9 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
return getArrayTypeDeclaration((ArraySchema) p);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
// Should we also support maps of maps?
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
||||
|
||||
@@ -326,7 +326,7 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
public void preprocessOpenAPI() {
|
||||
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
||||
String port = URLPathUtils.getPort(url, "");
|
||||
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){
|
||||
Map<String, Object> models = super.postProcessAllModels(objs);
|
||||
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);
|
||||
}
|
||||
return models;
|
||||
@@ -379,7 +379,7 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
||||
}
|
||||
String childPropertyType = property.isContainer? property.mostInnerItems.baseType : property.baseType;
|
||||
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 ){
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
|
||||
setReservedWordsLowerCase(Arrays.asList(
|
||||
// language reserved words
|
||||
"across", "agent", "alias", "all", "and", "as", "assign", "attribute", "check", "class", "convert",
|
||||
"create", "Current", "debug", "deferred", "do", "else", "elseif", "end", "ensure", "expanded", "export",
|
||||
"across", "agent", "alias", "all", "and", "as", "assign", "attached", "attribute", "check", "class", "convert",
|
||||
"create", "Current", "debug", "deferred", "detachable", "do", "else", "elseif", "end", "ensure", "expanded", "export",
|
||||
"external", "False", "feature", "from", "frozen", "if", "implies", "inherit", "inspect", "invariant",
|
||||
"like", "local", "loop", "not", "note", "obsolete", "old", "once", "only", "or", "Precursor",
|
||||
"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("number", "REAL_32");
|
||||
typeMapping.put("float", "REAL_32");
|
||||
typeMapping.put("decimal", "REAL_64");
|
||||
typeMapping.put("double", "REAL_64");
|
||||
typeMapping.put("boolean", "BOOLEAN");
|
||||
typeMapping.put("string", "STRING_32");
|
||||
@@ -85,10 +86,17 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
typeMapping.put("map", "STRING_TABLE");
|
||||
typeMapping.put("array", "LIST");
|
||||
typeMapping.put("list", "LIST");
|
||||
typeMapping.put("AnyType", "ANY");
|
||||
|
||||
instantiationTypes.put("array", "ARRAYED_LIST");
|
||||
instantiationTypes.put("list", "ARRAYED_LIST");
|
||||
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();
|
||||
@@ -167,6 +175,12 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
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)) {
|
||||
name = modelNamePrefix + "_" + name;
|
||||
}
|
||||
@@ -191,6 +205,13 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
name = "model_" + name; // e.g. 200Response => Model200Response
|
||||
// (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);
|
||||
}
|
||||
@@ -271,14 +292,14 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "LIST [" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
return getSchemaType(p) + " [" + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
// return super.getTypeDeclaration(p);
|
||||
|
||||
@@ -315,7 +336,12 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
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
|
||||
if (isReservedWord(sanitizedOperationId)) {
|
||||
@@ -323,6 +349,13 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
+ camelize("call_" + operationId));
|
||||
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.
|
||||
sanitizedOperationId = unCamelize(sanitizedOperationId);
|
||||
|
||||
@@ -430,7 +463,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
|
||||
private void postProcessParentModels(final Map<String, Object> models) {
|
||||
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);
|
||||
for (final CodegenModel child : childrenModels) {
|
||||
processParentPropertiesInChildModel(parentModel, child);
|
||||
@@ -459,7 +492,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
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);
|
||||
if (allDefinitions != null && codegenModel.parentSchema != null && codegenModel.hasEnums) {
|
||||
final Schema parentModel = allDefinitions.get(codegenModel.parentSchema);
|
||||
@@ -537,22 +570,23 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
Schema additionalProperties2 = getAdditionalProperties(p);
|
||||
String type = additionalProperties2.getType();
|
||||
if (null == type) {
|
||||
LOGGER.error("No Type defined for Additional Schema " + additionalProperties2 + "\n" //
|
||||
+ "\tIn Schema: " + p);
|
||||
}
|
||||
String inner = toModelName(getSchemaType(additionalProperties2));
|
||||
return instantiationTypes.get("map") + " [" + inner + "]";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = toModelName(getSchemaType(ap.getItems()));
|
||||
return instantiationTypes.get("array") + " [" + inner + "]";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return getTypeDeclaration(p);
|
||||
// if (modelUtils.isMapSchema(p)) {
|
||||
// Schema additionalProperties2 = getAdditionalProperties(p);
|
||||
// String type = additionalProperties2.getType();
|
||||
// if (null == type) {
|
||||
// LOGGER.error("No Type defined for Additional Schema " + additionalProperties2 + "\n" //
|
||||
// + "\tIn Schema: " + p);
|
||||
// }
|
||||
// String inner = toModelName(getSchemaType(additionalProperties2));
|
||||
// return instantiationTypes.get("map") + " [" + inner + "]";
|
||||
// } else if (modelUtils.isArraySchema(p)) {
|
||||
// ArraySchema ap = (ArraySchema) p;
|
||||
// String inner = toModelName(getSchemaType(ap.getItems()));
|
||||
// return instantiationTypes.get("array") + " [" + inner + "]";
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
|
||||
public String unCamelize(String name) {
|
||||
|
||||
@@ -358,7 +358,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
|
||||
for (String k : objs.keySet()) {
|
||||
CodegenModel model = ModelUtils.getModelByName(k, objs);
|
||||
CodegenModel model = modelUtils.getModelByName(k, objs);
|
||||
if (model == null || model.classname == null) {
|
||||
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) {
|
||||
Map<String, CodegenModel> enumRefs = new HashMap<String, CodegenModel>();
|
||||
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) {
|
||||
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()) {
|
||||
String openAPIName = entry.getKey();
|
||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
||||
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||
if (model != null) {
|
||||
for (CodegenProperty var : model.allVars) {
|
||||
if (enumRefs.containsKey(var.dataType)) {
|
||||
@@ -735,23 +735,23 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
*/
|
||||
@Override
|
||||
public String toExampleValue(Schema p) {
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getExample() != null) {
|
||||
return "\"" + p.getExample().toString() + "\"";
|
||||
}
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
} else if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getExample() != null) {
|
||||
return p.getExample().toString();
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getExample() != null) {
|
||||
return p.getExample().toString();
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getExample() != null) {
|
||||
return p.getExample().toString();
|
||||
}
|
||||
@@ -768,33 +768,33 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
*/
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
}
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
}
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
if (ModelUtils.isFloatSchema(p)) { // float
|
||||
if (modelUtils.isFloatSchema(p)) { // float
|
||||
return p.getDefault().toString() + "F";
|
||||
} else if (ModelUtils.isDoubleSchema(p)) { // double
|
||||
} else if (modelUtils.isDoubleSchema(p)) { // double
|
||||
return p.getDefault().toString() + "D";
|
||||
} else { // decimal
|
||||
return p.getDefault().toString() + "M";
|
||||
}
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
String _default = (String) p.getDefault();
|
||||
if (p.getEnum() == null) {
|
||||
@@ -817,7 +817,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
public String getNullableType(Schema p, String type) {
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||
return type + " option";
|
||||
} else {
|
||||
return type;
|
||||
@@ -869,7 +869,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
return getArrayTypeDeclaration((ArraySchema) p);
|
||||
}
|
||||
return super.toInstantiationType(p);
|
||||
@@ -877,9 +877,9 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
return getArrayTypeDeclaration((ArraySchema) p);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
// Should we also support maps of maps?
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
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.Schema;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
@@ -330,7 +331,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
// 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.
|
||||
// When "items" is not specified, the elements of the array may be anything at all.
|
||||
if (inner != null) {
|
||||
inner = ModelUtils.unaliasSchema(this.openAPI, inner);
|
||||
inner = modelUtils.unaliasSchema(inner);
|
||||
}
|
||||
String typDecl;
|
||||
if (inner != null) {
|
||||
@@ -347,9 +348,9 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
typDecl = "interface{}";
|
||||
}
|
||||
return "[]" + typDecl;
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(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);
|
||||
|
||||
@@ -394,7 +395,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
if (ref != null && !ref.isEmpty()) {
|
||||
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.
|
||||
type = "interface{}";
|
||||
} else if (typeMapping.containsKey(openAPIType)) {
|
||||
@@ -425,9 +426,9 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
*/
|
||||
@Override
|
||||
public String toInstantiationType(Schema property) {
|
||||
if (ModelUtils.isMapSchema(property)) {
|
||||
if (modelUtils.isMapSchema(property)) {
|
||||
return getTypeDeclaration(property);
|
||||
} else if (ModelUtils.isArraySchema(property)) {
|
||||
} else if (modelUtils.isArraySchema(property)) {
|
||||
return getTypeDeclaration(property);
|
||||
}
|
||||
return super.toInstantiationType(property);
|
||||
|
||||
@@ -266,11 +266,11 @@ public abstract class AbstractGraphQLCodegen extends DefaultCodegen implements C
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
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
|
||||
// the type.
|
||||
String schemaType = getSchemaType(p);
|
||||
String nullable = ModelUtils.isNullable(p) ? "" : "!";
|
||||
String nullable = modelUtils.isNullable(p) ? "" : "!";
|
||||
/*
|
||||
if (p != null && Boolean.TRUE.equals(p.getNullable())) {
|
||||
nullable = "";
|
||||
|
||||
@@ -21,10 +21,12 @@ import com.google.common.base.Strings;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
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.ComposedSchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
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.parser.util.SchemaTypeUtil;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
@@ -792,13 +794,13 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
Schema<?> schema = ModelUtils.unaliasSchema(this.openAPI, p, importMapping);
|
||||
Schema<?> target = ModelUtils.isGenerateAliasAsModel() ? p : schema;
|
||||
if (ModelUtils.isArraySchema(target)) {
|
||||
Schema<?> schema = modelUtils.unaliasSchema(p, importMapping);
|
||||
Schema<?> target = modelUtils.isGenerateAliasAsModel() ? p : schema;
|
||||
if (modelUtils.isArraySchema(target)) {
|
||||
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
||||
return getSchemaType(target) + "<" + getTypeDeclaration(items) + ">";
|
||||
} else if (ModelUtils.isMapSchema(target)) {
|
||||
// Note: ModelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
||||
} else if (modelUtils.isMapSchema(target)) {
|
||||
// Note: modelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
||||
// additionalproperties: true
|
||||
Schema<?> inner = getAdditionalProperties(target);
|
||||
if (inner == null) {
|
||||
@@ -821,10 +823,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema schema) {
|
||||
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
schema = modelUtils.getReferencedSchema(schema);
|
||||
if (modelUtils.isArraySchema(schema)) {
|
||||
final String pattern;
|
||||
if (ModelUtils.isSet(schema)) {
|
||||
if (modelUtils.isSet(schema)) {
|
||||
String mapInstantiationType = instantiationTypes().getOrDefault("set", "LinkedHashSet");
|
||||
pattern = "new " + mapInstantiationType + "<%s>()";
|
||||
} else {
|
||||
@@ -834,7 +836,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
||||
|
||||
String typeDeclaration = getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, items));
|
||||
String typeDeclaration = getTypeDeclaration(modelUtils.unaliasSchema(items));
|
||||
Object java8obj = additionalProperties.get("java8");
|
||||
if (java8obj != null) {
|
||||
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);
|
||||
} else if (ModelUtils.isMapSchema(schema) && !(schema instanceof ComposedSchema)) {
|
||||
} else if (modelUtils.isMapSchema(schema) && !(schema instanceof ComposedSchema)) {
|
||||
if (schema.getProperties() != null && schema.getProperties().size() > 0) {
|
||||
// object is complex object with free-form additional properties
|
||||
if (schema.getDefault() != null) {
|
||||
@@ -870,7 +872,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
|
||||
return String.format(Locale.ROOT, pattern, typeDeclaration);
|
||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
||||
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||
if (schema.getDefault() != null) {
|
||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(schema.getFormat())) {
|
||||
return schema.getDefault().toString() + "l";
|
||||
@@ -879,26 +881,28 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
||||
} else if (modelUtils.isNumberSchema(schema)) {
|
||||
if (schema.getDefault() != null) {
|
||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(schema.getFormat())) {
|
||||
return schema.getDefault().toString() + "f";
|
||||
} else {
|
||||
} else if (SchemaTypeUtil.DOUBLE_FORMAT.equals(schema.getFormat())) {
|
||||
return schema.getDefault().toString() + "d";
|
||||
} else {
|
||||
return "new BigDecimal(\"" + schema.getDefault().toString() + "\")";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
||||
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||
if (schema.getDefault() != null) {
|
||||
return schema.getDefault().toString();
|
||||
}
|
||||
return null;
|
||||
} else if (ModelUtils.isURISchema(schema)) {
|
||||
} else if (modelUtils.isURISchema(schema)) {
|
||||
if (schema.getDefault() != null) {
|
||||
return "URI.create(\"" + escapeText((String) schema.getDefault()) + "\")";
|
||||
}
|
||||
return null;
|
||||
} else if (ModelUtils.isStringSchema(schema)) {
|
||||
} else if (modelUtils.isStringSchema(schema)) {
|
||||
if (schema.getDefault() != null) {
|
||||
String _default;
|
||||
if (schema.getDefault() instanceof Date) {
|
||||
@@ -919,7 +923,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else if (ModelUtils.isObjectSchema(schema)) {
|
||||
} else if (modelUtils.isObjectSchema(schema)) {
|
||||
if (schema.getDefault() != null) {
|
||||
return super.toDefaultValue(schema);
|
||||
}
|
||||
@@ -929,6 +933,37 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
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
|
||||
public void setParameterExampleValue(CodegenParameter p) {
|
||||
String example;
|
||||
@@ -957,15 +992,17 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
if (example == null) {
|
||||
example = "56";
|
||||
}
|
||||
example = example + "L";
|
||||
example = StringUtils.appendIfMissingIgnoreCase(example, "L");
|
||||
} else if ("Float".equals(type)) {
|
||||
if (example == null) {
|
||||
example = "3.4";
|
||||
}
|
||||
example = example + "F";
|
||||
example = StringUtils.appendIfMissingIgnoreCase(example, "F");
|
||||
} else if ("Double".equals(type)) {
|
||||
example = "3.4";
|
||||
example = example + "D";
|
||||
if (example == null) {
|
||||
example = "3.4";
|
||||
}
|
||||
example = StringUtils.appendIfMissingIgnoreCase(example, "D");
|
||||
} else if ("Boolean".equals(type)) {
|
||||
if (example == null) {
|
||||
example = "true";
|
||||
@@ -977,6 +1014,14 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
example = "new File(\"" + escapeText(example) + "\")";
|
||||
} else if ("Date".equals(type)) {
|
||||
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)) {
|
||||
// type is a model class, e.g. User
|
||||
example = "new " + type + "()";
|
||||
@@ -1055,7 +1100,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
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);
|
||||
if (codegenModel.description != null) {
|
||||
codegenModel.imports.add("ApiModel");
|
||||
@@ -1139,12 +1184,24 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
if (openAPI == null) {
|
||||
return;
|
||||
}
|
||||
@@ -1156,13 +1213,13 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
for (Operation operation : path.readOperations()) {
|
||||
LOGGER.info("Processing operation " + operation.getOperationId());
|
||||
if (hasBodyParameter(openAPI, operation) || hasFormParameter(openAPI, operation)) {
|
||||
String defaultContentType = hasFormParameter(openAPI, operation) ? "application/x-www-form-urlencoded" : "application/json";
|
||||
List<String> consumes = new ArrayList<>(getConsumesInfo(openAPI, operation));
|
||||
if (hasBodyParameter(operation) || hasFormParameter(operation)) {
|
||||
String defaultContentType = hasFormParameter(operation) ? "application/x-www-form-urlencoded" : "application/json";
|
||||
List<String> consumes = new ArrayList<>(getConsumesInfo(operation));
|
||||
String contentType = consumes == null || consumes.isEmpty() ? defaultContentType : consumes.get(0);
|
||||
operation.addExtension("x-contentType", contentType);
|
||||
}
|
||||
String accepts = getAccept(openAPI, operation);
|
||||
String accepts = getAccept(operation);
|
||||
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 defaultContentType = "application/json";
|
||||
Set<String> producesInfo = getProducesInfo(openAPI, operation);
|
||||
Set<String> producesInfo = getProducesInfo(operation);
|
||||
if (producesInfo != null && !producesInfo.isEmpty()) {
|
||||
ArrayList<String> produces = new ArrayList<>(producesInfo);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -127,8 +127,8 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
/* TODO there should be no need for the following logic
|
||||
if ("/".equals(swagger.getBasePath())) {
|
||||
swagger.setBasePath("");
|
||||
|
||||
@@ -310,13 +310,13 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
Schema<?> schema = ModelUtils.unaliasSchema(this.openAPI, p, importMapping);
|
||||
Schema<?> target = ModelUtils.isGenerateAliasAsModel() ? p : schema;
|
||||
if (ModelUtils.isArraySchema(target)) {
|
||||
Schema<?> schema = modelUtils.unaliasSchema(p, importMapping);
|
||||
Schema<?> target = modelUtils.isGenerateAliasAsModel() ? p : schema;
|
||||
if (modelUtils.isArraySchema(target)) {
|
||||
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
||||
return getSchemaType(target) + "<" + getTypeDeclaration(items) + ">";
|
||||
} else if (ModelUtils.isMapSchema(target)) {
|
||||
// Note: ModelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
||||
} else if (modelUtils.isMapSchema(target)) {
|
||||
// Note: modelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
||||
// additionalproperties: true
|
||||
Schema<?> inner = getAdditionalProperties(target);
|
||||
if (inner == null) {
|
||||
@@ -899,27 +899,27 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isURISchema(p)) {
|
||||
} else if (modelUtils.isURISchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "URI.create('" + p.getDefault() + "')";
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault() + "\"";
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
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");
|
||||
}
|
||||
return getTypeDeclaration(inner) + "[]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
if (inner == null) {
|
||||
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
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "'" + p.getDefault() + "'";
|
||||
}
|
||||
|
||||
@@ -345,11 +345,11 @@ public abstract class AbstractPythonConnexionServerCodegen extends DefaultCodege
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[str, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
@@ -372,7 +372,7 @@ public abstract class AbstractPythonConnexionServerCodegen extends DefaultCodege
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
public void preprocessOpenAPI() {
|
||||
// need vendor extensions for x-openapi-router-controller
|
||||
Map<String, PathItem> paths = openAPI.getPaths();
|
||||
if (paths != null) {
|
||||
@@ -704,26 +704,26 @@ public abstract class AbstractPythonConnexionServerCodegen extends DefaultCodege
|
||||
*/
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
||||
return "False";
|
||||
else
|
||||
return "True";
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "'" + (String) p.getDefault() + "'";
|
||||
}
|
||||
|
||||
@@ -114,10 +114,10 @@ abstract public class AbstractRubyCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema schema) {
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
if (modelUtils.isArraySchema(schema)) {
|
||||
Schema inner = ((ArraySchema) schema).getItems();
|
||||
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(schema)) {
|
||||
} else if (modelUtils.isMapSchema(schema)) {
|
||||
Schema inner = getAdditionalProperties(schema);
|
||||
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
@@ -127,11 +127,11 @@ abstract public class AbstractRubyCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Schema schema) {
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
if (modelUtils.isMapSchema(schema)) {
|
||||
return instantiationTypes.get("map");
|
||||
} else if (ModelUtils.isArraySchema(schema)) {
|
||||
} else if (modelUtils.isArraySchema(schema)) {
|
||||
String parentType;
|
||||
if (ModelUtils.isSet(schema)) {
|
||||
if (modelUtils.isSet(schema)) {
|
||||
parentType = "set";
|
||||
} else {
|
||||
parentType = "array";
|
||||
@@ -143,12 +143,12 @@ abstract public class AbstractRubyCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
p = ModelUtils.getReferencedSchema(this.openAPI, p);
|
||||
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
|
||||
p = modelUtils.getReferencedSchema(p);
|
||||
if (modelUtils.isIntegerSchema(p) || modelUtils.isNumberSchema(p) || modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
if (p.getDefault() instanceof Date) {
|
||||
Date date = (Date) p.getDefault();
|
||||
|
||||
@@ -320,11 +320,11 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
@@ -335,7 +335,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
@Override
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
if (ModelUtils.isSet(p)) {
|
||||
if (modelUtils.isSet(p)) {
|
||||
openAPIType = "set";
|
||||
}
|
||||
|
||||
@@ -353,13 +353,13 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
if (modelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(getAdditionalProperties(p));
|
||||
return instantiationTypes.get("map") + "[String, " + inner + "]";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} else if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
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 {
|
||||
return null;
|
||||
}
|
||||
@@ -372,24 +372,24 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
}
|
||||
|
||||
// comment out the following as the default value is no handled differently
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
return null;
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
return null;
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
return null;
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
return null;
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
return null;
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(getAdditionalProperties(p));
|
||||
return "new HashMap[String, " + inner + "]() ";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} else if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
String genericType;
|
||||
if (ModelUtils.isSet(ap)) {
|
||||
if (modelUtils.isSet(ap)) {
|
||||
genericType = instantiationTypes.get("set");
|
||||
} else {
|
||||
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.
|
||||
return "new " + genericType + "[" + inner + "]() ";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
return null;
|
||||
} else {
|
||||
return null;
|
||||
@@ -427,9 +427,9 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
@Override
|
||||
public CodegenProperty fromProperty(String name, Schema p) {
|
||||
CodegenProperty prop = super.fromProperty(name, p);
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema as = (ArraySchema) p;
|
||||
if (ModelUtils.isSet(as)) {
|
||||
if (modelUtils.isSet(as)) {
|
||||
prop.containerType = "set";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
public void preprocessOpenAPI() {
|
||||
|
||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||
|
||||
@@ -413,16 +413,16 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
Schema<?> items = getSchemaItems((ArraySchema) p);
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, items)) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(modelUtils.unaliasSchema(items)) + ">";
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema<?> inner = getSchemaAdditionalProperties(p);
|
||||
String nullSafeSuffix = getNullSafeAdditionalProps() ? " | undefined" : "";
|
||||
return "{ [key: string]: " + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner)) + nullSafeSuffix + "; }";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return "{ [key: string]: " + getTypeDeclaration(modelUtils.unaliasSchema(inner)) + nullSafeSuffix + "; }";
|
||||
} else if (modelUtils.isFileSchema(p)) {
|
||||
return "any";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
} else if (modelUtils.isBinarySchema(p)) {
|
||||
return "any";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
@@ -432,37 +432,37 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
protected String getParameterDataType(Parameter parameter, Schema p) {
|
||||
// handle enums of various data types
|
||||
Schema inner;
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema mp1 = (ArraySchema) p;
|
||||
inner = mp1.getItems();
|
||||
return this.getSchemaType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
inner = getAdditionalProperties(p);
|
||||
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
// Handle string enums
|
||||
if (p.getEnum() != null) {
|
||||
return enumValuesToEnumTypeUnion(p.getEnum(), "string");
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
// Handle integer enums
|
||||
if (p.getEnum() != null) {
|
||||
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
||||
}
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
// Handle double enums
|
||||
if (p.getEnum() != null) {
|
||||
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
||||
}
|
||||
}
|
||||
/* TODO revise the logic below
|
||||
else if (ModelUtils.isDateSchema(p)) {
|
||||
else if (modelUtils.isDateSchema(p)) {
|
||||
// Handle date enums
|
||||
DateSchema sp = (DateSchema) p;
|
||||
if (sp.getEnum() != null) {
|
||||
return enumValuesToEnumTypeUnion(sp.getEnum(), "string");
|
||||
}
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
// Handle datetime enums
|
||||
DateTimeSchema sp = (DateTimeSchema) p;
|
||||
if (sp.getEnum() != null) {
|
||||
@@ -510,27 +510,27 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return UNDEFINED_VALUE;
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return UNDEFINED_VALUE;
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return UNDEFINED_VALUE;
|
||||
} else if (ModelUtils.isNumberSchema(p) || ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p) || modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return UNDEFINED_VALUE;
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "'" + (String) p.getDefault() + "'";
|
||||
}
|
||||
@@ -551,7 +551,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
String type = null;
|
||||
if (ModelUtils.isComposedSchema(p)) {
|
||||
if (modelUtils.isComposedSchema(p)) {
|
||||
return openAPIType;
|
||||
} else if (typeMapping.containsKey(openAPIType)) {
|
||||
type = typeMapping.get(openAPIType);
|
||||
@@ -898,7 +898,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
|
||||
return filteredSchemas.stream().map(schema -> {
|
||||
String schemaType = getSchemaType(schema);
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
if (modelUtils.isArraySchema(schema)) {
|
||||
ArraySchema ap = (ArraySchema) schema;
|
||||
Schema inner = ap.getItems();
|
||||
schemaType = schemaType + "<" + getSchemaType(inner) + ">";
|
||||
|
||||
@@ -223,11 +223,11 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
|
||||
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
|
||||
@@ -158,7 +158,7 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
public void preprocessOpenAPI() {
|
||||
String calloutLabel = openAPI.getInfo().getTitle();
|
||||
if (StringUtils.isNotBlank(namedCredential)) {
|
||||
calloutLabel = namedCredential;
|
||||
@@ -221,24 +221,24 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
String out = null;
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
Schema inner = ((ArraySchema) p).getItems();
|
||||
out = String.format(
|
||||
Locale.ROOT,
|
||||
"new List<%s>()",
|
||||
inner == null ? "Object" : getTypeDeclaration(inner)
|
||||
);
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
} else if (modelUtils.isBooleanSchema(p)) {
|
||||
// true => "true", false => "false", null => "null"
|
||||
out = String.valueOf(p.getDefault());
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
} else if (modelUtils.isLongSchema(p)) {
|
||||
Long def = (Long) p.getDefault();
|
||||
out = def == null ? out : def.toString() + "L";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
String s = inner == null ? "Object" : getTypeDeclaration(inner);
|
||||
out = String.format(Locale.ROOT, "new Map<String, %s>()", s);
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
String def = p.getDefault().toString();
|
||||
if (def != null) {
|
||||
|
||||
@@ -359,14 +359,14 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpenAPI(OpenAPI openAPI) {
|
||||
public void processOpenAPI() {
|
||||
if (this.includeSpecMarkupLambda != null) {
|
||||
LOGGER.debug("specs: " + ": " + this.includeSpecMarkupLambda.resetCounter());
|
||||
}
|
||||
if (this.includeSnippetMarkupLambda != null) {
|
||||
LOGGER.debug("snippets: " + ": " + this.includeSnippetMarkupLambda.resetCounter());
|
||||
}
|
||||
super.processOpenAPI(openAPI);
|
||||
super.processOpenAPI();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -304,8 +304,8 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
||||
additionalProperties.put("serverHost", url.getHost());
|
||||
additionalProperties.put("serverPort", URLPathUtils.getPort(url, 8080));
|
||||
@@ -450,7 +450,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
@Override
|
||||
public String getNullableType(Schema p, String type) {
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||
return type + "?";
|
||||
} else {
|
||||
return type;
|
||||
|
||||
@@ -423,11 +423,11 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
@@ -619,7 +619,7 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod,
|
||||
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);
|
||||
|
||||
/**
|
||||
@@ -663,8 +663,8 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
* If the operation produces Json and has nonempty example
|
||||
* try to reformat it.
|
||||
*/
|
||||
if (getConsumesInfo(this.openAPI, operation) != null
|
||||
&& getConsumesInfo(this.openAPI, operation).contains("application/json")
|
||||
if (getConsumesInfo(operation) != null
|
||||
&& getConsumesInfo(operation).contains("application/json")
|
||||
&& definitions.get(p.dataType).getExample() != null) {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -697,8 +697,8 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
* @param openAPI [description]
|
||||
*/
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
|
||||
/* TODO need to revise the logic below
|
||||
if ("/".equals(openAPI.getServers())) {
|
||||
|
||||
@@ -296,10 +296,10 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema schema) {
|
||||
/* 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();
|
||||
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(schema)) {
|
||||
} else if (modelUtils.isMapSchema(schema)) {
|
||||
Schema inner = (Schema) schema.getAdditionalProperties();
|
||||
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
@@ -310,11 +310,11 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
@Override
|
||||
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) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "'" + escapeText((String) p.getDefault()) + "'";
|
||||
}
|
||||
@@ -327,17 +327,17 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
public String toExampleValue(Schema 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,
|
||||
// though this tooling supports it.
|
||||
return "NULL";
|
||||
}
|
||||
// correct "'"s into "'"s after toString()
|
||||
if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null) {
|
||||
if (modelUtils.isStringSchema(schema) && schema.getDefault() != null) {
|
||||
example = (String) schema.getDefault();
|
||||
}
|
||||
if (StringUtils.isNotBlank(example) && !"null".equals(example)) {
|
||||
if (ModelUtils.isStringSchema(schema)) {
|
||||
if (modelUtils.isStringSchema(schema)) {
|
||||
example = "\"" + example + "\"";
|
||||
}
|
||||
return example;
|
||||
@@ -346,7 +346,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
if (schema.getEnum() != null && !schema.getEnum().isEmpty()) {
|
||||
// Enum case:
|
||||
example = schema.getEnum().get(0).toString();
|
||||
/* if (ModelUtils.isStringSchema(schema)) {
|
||||
/* if (modelUtils.isStringSchema(schema)) {
|
||||
example = "'" + escapeText(example) + "'";
|
||||
}*/
|
||||
if (null == example)
|
||||
@@ -355,8 +355,8 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
return example;
|
||||
} else if (null != schema.get$ref()) {
|
||||
// $ref case:
|
||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
||||
String ref = ModelUtils.getSimpleRef(schema.get$ref());
|
||||
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||
String ref = modelUtils.getSimpleRef(schema.get$ref());
|
||||
if (allDefinitions != null) {
|
||||
Schema refSchema = allDefinitions.get(ref);
|
||||
if (null == refSchema) {
|
||||
@@ -372,18 +372,18 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
LOGGER.warn("allDefinitions not defined in toExampleValue!\n");
|
||||
}
|
||||
}
|
||||
if (ModelUtils.isDateSchema(schema)) {
|
||||
if (modelUtils.isDateSchema(schema)) {
|
||||
example = "\"2013-10-20\"";
|
||||
return example;
|
||||
} else if (ModelUtils.isDateTimeSchema(schema)) {
|
||||
} else if (modelUtils.isDateTimeSchema(schema)) {
|
||||
example = "\"2013-10-20T19:20:30+01:00\"";
|
||||
return example;
|
||||
} else if (ModelUtils.isBinarySchema(schema)) {
|
||||
} else if (modelUtils.isBinarySchema(schema)) {
|
||||
example = "instantiate_binary_t(\"blah\", 5)";
|
||||
return example;
|
||||
} else if (ModelUtils.isByteArraySchema(schema)) {
|
||||
} else if (modelUtils.isByteArraySchema(schema)) {
|
||||
example = "YQ==";
|
||||
} else if (ModelUtils.isStringSchema(schema)) {
|
||||
} else if (modelUtils.isStringSchema(schema)) {
|
||||
// decimal (type: string, format: decimal)
|
||||
if ("number".equalsIgnoreCase(schema.getFormat())) {
|
||||
return "1";
|
||||
@@ -398,29 +398,29 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
example = "";
|
||||
for (int i = 0; i < len; i++)
|
||||
example += i;
|
||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
||||
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||
if (schema.getMinimum() != null)
|
||||
example = schema.getMinimum().toString();
|
||||
else
|
||||
example = "56";
|
||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
||||
} else if (modelUtils.isNumberSchema(schema)) {
|
||||
if (schema.getMinimum() != null)
|
||||
example = schema.getMinimum().toString();
|
||||
else
|
||||
example = "1.337";
|
||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
||||
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||
example = "1";
|
||||
} else if (ModelUtils.isArraySchema(schema)) {
|
||||
} else if (modelUtils.isArraySchema(schema)) {
|
||||
example = "list_create()";
|
||||
} else if (ModelUtils.isMapSchema(schema)) {
|
||||
} else if (modelUtils.isMapSchema(schema)) {
|
||||
example = "list_create()";
|
||||
} else if (ModelUtils.isObjectSchema(schema)) {
|
||||
} else if (modelUtils.isObjectSchema(schema)) {
|
||||
return null; // models are managed at moustache level
|
||||
} else {
|
||||
LOGGER.warn("Type " + schema.getType() + " not handled properly in toExampleValue");
|
||||
}
|
||||
|
||||
if (ModelUtils.isStringSchema(schema)) {
|
||||
if (modelUtils.isStringSchema(schema)) {
|
||||
example = "\"" + escapeText(example) + "\"";
|
||||
}
|
||||
|
||||
@@ -716,7 +716,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
public void preprocessOpenAPI() {
|
||||
if (openAPI.getInfo() != null) {
|
||||
Info info = openAPI.getInfo();
|
||||
setProjectName((escapeText(info.getTitle())));
|
||||
@@ -744,7 +744,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
@Override
|
||||
public CodegenProperty fromProperty(String name, Schema p) {
|
||||
CodegenProperty cm = super.fromProperty(name, p);
|
||||
Schema ref = ModelUtils.getReferencedSchema(openAPI, p);
|
||||
Schema ref = modelUtils.getReferencedSchema(p);
|
||||
if (ref != null) {
|
||||
if (ref.getEnum() != null) {
|
||||
cm.isEnum = true;
|
||||
|
||||
@@ -588,7 +588,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@Override
|
||||
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);
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
||||
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||
@@ -965,14 +965,14 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
*/
|
||||
@Override
|
||||
public String toInstantiationType(Schema schema) {
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
if (modelUtils.isMapSchema(schema)) {
|
||||
Schema additionalProperties = getAdditionalProperties(schema);
|
||||
String inner = getSchemaType(additionalProperties);
|
||||
if (ModelUtils.isMapSchema(additionalProperties)) {
|
||||
if (modelUtils.isMapSchema(additionalProperties)) {
|
||||
inner = toInstantiationType(additionalProperties);
|
||||
}
|
||||
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
||||
} else if (ModelUtils.isArraySchema(schema)) {
|
||||
} else if (modelUtils.isArraySchema(schema)) {
|
||||
ArraySchema arraySchema = (ArraySchema) schema;
|
||||
String inner = getSchemaType(arraySchema.getItems());
|
||||
return instantiationTypes.get("array") + "<" + inner + ">";
|
||||
@@ -984,7 +984,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
@Override
|
||||
public String getNullableType(Schema p, String type) {
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||
return type + "?";
|
||||
} else {
|
||||
return type;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
private static final String PACKAGE_CONTEXT = "packageContext";
|
||||
private static final String ASYNC_SERVER = "asyncServer";
|
||||
|
||||
private static final Map<String, Predicate<Schema>> propertyToOpenAPITypeMapping =
|
||||
private final Map<String, Predicate<Schema>> propertyToOpenAPITypeMapping =
|
||||
createPropertyToOpenAPITypeMapping();
|
||||
|
||||
private String packageGuid = "{" + randomUUID().toString().toUpperCase(Locale.ROOT) + "}";
|
||||
@@ -270,7 +270,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
private void postProcessParentModels(final Map<String, Object> models) {
|
||||
LOGGER.debug("Processing parents: " + parentModels);
|
||||
for (final String parent : parentModels) {
|
||||
final CodegenModel parentModel = ModelUtils.getModelByName(parent, models);
|
||||
final CodegenModel parentModel = modelUtils.getModelByName(parent, models);
|
||||
if (parentModel != null) {
|
||||
parentModel.hasChildren = true;
|
||||
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
||||
@@ -373,7 +373,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(final OpenAPI openAPI) {
|
||||
public void preprocessOpenAPI() {
|
||||
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
||||
String path = URLPathUtils.getPath(url, "/");
|
||||
final String packageContextOption = (String) additionalProperties.get(PACKAGE_CONTEXT);
|
||||
@@ -397,17 +397,17 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
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();
|
||||
mapping.put("time", timeProperty());
|
||||
return mapping.build();
|
||||
}
|
||||
|
||||
private static Predicate<Schema> timeProperty() {
|
||||
private Predicate<Schema> timeProperty() {
|
||||
return new Predicate<Schema>() {
|
||||
@Override
|
||||
public boolean apply(Schema property) {
|
||||
return ModelUtils.isStringSchema(property) && "time".equalsIgnoreCase(property.getFormat());
|
||||
return modelUtils.isStringSchema(property) && "time".equalsIgnoreCase(property.getFormat());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@Override
|
||||
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);
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
||||
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||
@@ -401,7 +401,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
@Override
|
||||
public String getNullableType(Schema p, String type) {
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||
return type + "?";
|
||||
} else {
|
||||
return type;
|
||||
@@ -968,14 +968,14 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
*/
|
||||
@Override
|
||||
public String toInstantiationType(Schema schema) {
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
if (modelUtils.isMapSchema(schema)) {
|
||||
Schema additionalProperties = getAdditionalProperties(schema);
|
||||
String inner = getSchemaType(additionalProperties);
|
||||
if (ModelUtils.isMapSchema(additionalProperties)) {
|
||||
if (modelUtils.isMapSchema(additionalProperties)) {
|
||||
inner = toInstantiationType(additionalProperties);
|
||||
}
|
||||
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
||||
} else if (ModelUtils.isArraySchema(schema)) {
|
||||
} else if (modelUtils.isArraySchema(schema)) {
|
||||
ArraySchema arraySchema = (ArraySchema) schema;
|
||||
String inner = getSchemaType(arraySchema.getItems());
|
||||
return instantiationTypes.get("array") + "<" + inner + ">";
|
||||
|
||||
@@ -168,7 +168,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
Schema inner = ap.getItems();
|
||||
|
||||
return "(s/coll-of " + getTypeDeclaration(inner) + ")";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
|
||||
return "(s/map-of string? " + getTypeDeclaration(inner) + ")";
|
||||
@@ -216,8 +216,8 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
|
||||
if (additionalProperties.containsKey(PROJECT_NAME)) {
|
||||
projectName = ((String) additionalProperties.get(PROJECT_NAME));
|
||||
|
||||
@@ -102,11 +102,11 @@ public class ConfluenceWikiCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
||||
|
||||
if (apiResponse != null) {
|
||||
Schema response = ModelUtils.getSchemaFromResponse(apiResponse);
|
||||
Schema response = modelUtils.getSchemaFromResponse(apiResponse);
|
||||
if (response != null) {
|
||||
CodegenProperty cm = fromProperty("response", response);
|
||||
op.vendorExtensions.put("x-codegen-response", cm);
|
||||
@@ -350,20 +350,20 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
String openAPIType = getSchemaType(p);
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
} else if (modelUtils.isByteArraySchema(p)) {
|
||||
return "std::string";
|
||||
}
|
||||
if (ModelUtils.isStringSchema(p)
|
||||
|| ModelUtils.isDateSchema(p)
|
||||
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|
||||
if (modelUtils.isStringSchema(p)
|
||||
|| modelUtils.isDateSchema(p)
|
||||
|| modelUtils.isDateTimeSchema(p) || modelUtils.isFileSchema(p)
|
||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||
return toModelName(openAPIType);
|
||||
}
|
||||
@@ -373,34 +373,34 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
return "\"\"";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
return "\"\"";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (ModelUtils.isFloatSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (modelUtils.isFloatSchema(p)) {
|
||||
return "0.0f";
|
||||
}
|
||||
return "0.0";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (ModelUtils.isLongSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (modelUtils.isLongSchema(p)) {
|
||||
return "0L";
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
} else if (modelUtils.isByteArraySchema(p)) {
|
||||
return "\"\"";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(getAdditionalProperties(p));
|
||||
return "std::map<std::string, " + inner + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} 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 toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
return "\"\"";
|
||||
}
|
||||
|
||||
|
||||
@@ -181,16 +181,16 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
String openAPIType = getSchemaType(p);
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
} else if (modelUtils.isBinarySchema(p)) {
|
||||
return getSchemaType(p);
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
} else if (modelUtils.isFileSchema(p)) {
|
||||
return getSchemaType(p);
|
||||
}
|
||||
if (foundationClasses.contains(openAPIType)) {
|
||||
@@ -205,33 +205,33 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
return "NULL";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
return "NULL";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
||||
return "0.0f";
|
||||
}
|
||||
return "0.0";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
||||
return "0L";
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return "QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} else if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "QList<" + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
return "QString(\"\")";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
return toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
}
|
||||
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("object.mustache", sourceFolder, PREFIX + "Object.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"));
|
||||
if (optionalProjectFileFlag) {
|
||||
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("object.mustache", sourceFolder, modelNamePrefix + "Object.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"));
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.meta.features.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -271,8 +270,8 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
||||
|
||||
if (methodResponse != null) {
|
||||
Schema response = ModelUtils.getSchemaFromResponse(methodResponse);
|
||||
response = ModelUtils.unaliasSchema(this.openAPI, response, importMapping);
|
||||
Schema response = modelUtils.getSchemaFromResponse(methodResponse);
|
||||
response = modelUtils.unaliasSchema(response, importMapping);
|
||||
if (response != null) {
|
||||
CodegenProperty cm = fromProperty("response", response);
|
||||
op.vendorExtensions.put("x-codegen-response", cm);
|
||||
@@ -344,18 +343,18 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
String openAPIType = getSchemaType(p);
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
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 + ">";
|
||||
} else if (ModelUtils.isStringSchema(p)
|
||||
|| ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)
|
||||
|| ModelUtils.isFileSchema(p) || ModelUtils.isUUIDSchema(p)
|
||||
} else if (modelUtils.isStringSchema(p)
|
||||
|| modelUtils.isDateSchema(p) || modelUtils.isDateTimeSchema(p)
|
||||
|| modelUtils.isFileSchema(p) || modelUtils.isUUIDSchema(p)
|
||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||
return toModelName(openAPIType);
|
||||
}
|
||||
@@ -365,26 +364,26 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
return "utility::datetime()";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
return "utility::datetime()";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (ModelUtils.isFloatSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (modelUtils.isFloatSchema(p)) {
|
||||
return "0.0f";
|
||||
}
|
||||
return "0.0";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (ModelUtils.isLongSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (modelUtils.isLongSchema(p)) {
|
||||
return "0L";
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(getAdditionalProperties(p));
|
||||
return "std::map<utility::string_t, " + inner + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} else if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
if (!languageSpecificPrimitives.contains(inner)) {
|
||||
@@ -392,10 +391,10 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
}
|
||||
return "std::vector<" + inner + ">()";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
return "new " + toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
return "utility::conversions::to_string_t(\"\")";
|
||||
} else if (isFreeFormObject(p)) {
|
||||
} else if (modelUtils.isFreeFormObject(p)) {
|
||||
return "new Object()";
|
||||
}
|
||||
|
||||
@@ -446,7 +445,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
|
||||
private void postProcessParentModels(final Map<String, Object> models) {
|
||||
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);
|
||||
for (final CodegenModel child : childrenModels) {
|
||||
processParentPropertiesInChildModel(parentModel, child);
|
||||
|
||||
@@ -345,18 +345,18 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
String openAPIType = getSchemaType(p);
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
} else if (modelUtils.isByteArraySchema(p)) {
|
||||
return "std::string";
|
||||
} else if (ModelUtils.isStringSchema(p)
|
||||
|| ModelUtils.isDateSchema(p)
|
||||
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|
||||
} else if (modelUtils.isStringSchema(p)
|
||||
|| modelUtils.isDateSchema(p)
|
||||
|| modelUtils.isDateTimeSchema(p) || modelUtils.isFileSchema(p)
|
||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||
return toModelName(openAPIType);
|
||||
}
|
||||
@@ -366,32 +366,32 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
} else if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "false";
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (ModelUtils.isFloatSchema(p)) { // float
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (modelUtils.isFloatSchema(p)) { // float
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "f";
|
||||
} else {
|
||||
@@ -404,8 +404,8 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
return "0.0";
|
||||
}
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (ModelUtils.isLongSchema(p)) { // long
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (modelUtils.isLongSchema(p)) { // long
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "L";
|
||||
} else {
|
||||
@@ -418,16 +418,16 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
} else if (modelUtils.isByteArraySchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(getAdditionalProperties(p));
|
||||
return "std::map<std::string, " + inner + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} else if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
if (!languageSpecificPrimitives.contains(inner)) {
|
||||
@@ -435,7 +435,7 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
}
|
||||
return "std::vector<" + inner + ">()";
|
||||
} 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";
|
||||
|
||||
@@ -161,9 +161,9 @@ public class CppTizenClientCodegen extends AbstractCppCodegen implements Codegen
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
if (modelUtils.isMapSchema(p)) {
|
||||
return instantiationTypes.get("map");
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} else if (modelUtils.isArraySchema(p)) {
|
||||
return instantiationTypes.get("array");
|
||||
} else {
|
||||
return null;
|
||||
@@ -232,28 +232,28 @@ public class CppTizenClientCodegen extends AbstractCppCodegen implements Codegen
|
||||
//Might not be needed
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
return "bool(false)";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
||||
return "float(0)";
|
||||
}
|
||||
return "double(0)";
|
||||
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
||||
return "long(0)";
|
||||
}
|
||||
return "int(0)";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
return "new std::map()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} else if (modelUtils.isArraySchema(p)) {
|
||||
return "new std::list()";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
} else if (ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)) {
|
||||
return "new " + toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
} else if (modelUtils.isDateSchema(p) || modelUtils.isDateTimeSchema(p)) {
|
||||
return "null";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
return "std::string()";
|
||||
}
|
||||
return "null";
|
||||
|
||||
@@ -379,11 +379,11 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
String openAPIType = getSchemaType(p);
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(getAdditionalProperties(p));
|
||||
return getSchemaType(p) + "<FString, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
@@ -404,41 +404,41 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "TEXT(\"" + p.getDefault().toString() + "\")";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
} else if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "false";
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
return "FDateTime(0)";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
return "FDateTime(0)";
|
||||
} else if (ModelUtils.isDoubleSchema(p)) {
|
||||
} else if (modelUtils.isDoubleSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0.0";
|
||||
}
|
||||
} else if (ModelUtils.isFloatSchema(p)) {
|
||||
} else if (modelUtils.isFloatSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0.0f";
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
} else if (modelUtils.isLongSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
|
||||
@@ -412,14 +412,14 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema schema) {
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
if (modelUtils.isMapSchema(schema)) {
|
||||
return "const {}";
|
||||
} else if (ModelUtils.isArraySchema(schema)) {
|
||||
} else if (modelUtils.isArraySchema(schema)) {
|
||||
return "const []";
|
||||
}
|
||||
|
||||
if (schema.getDefault() != null) {
|
||||
if (ModelUtils.isStringSchema(schema)) {
|
||||
if (modelUtils.isStringSchema(schema)) {
|
||||
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
||||
}
|
||||
return schema.getDefault().toString();
|
||||
@@ -430,11 +430,11 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// 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(
|
||||
"supporting-mustache",
|
||||
"model-test",
|
||||
|
||||
@@ -51,7 +51,7 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
||||
|
||||
private static final String IS_FORMAT_JSON = "jsonFormat";
|
||||
private static final String CLIENT_NAME = "clientName";
|
||||
private static Set<String> modelToIgnore = new HashSet<>();
|
||||
private static final Set<String> modelToIgnore = new HashSet<>();
|
||||
|
||||
static {
|
||||
modelToIgnore.add("datetime");
|
||||
@@ -71,10 +71,6 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
||||
embeddedTemplateDir = "dart-dio";
|
||||
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"));
|
||||
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use").defaultValue(this.getDateLibrary());
|
||||
Map<String, String> dateOptions = new HashMap<>();
|
||||
@@ -88,6 +84,7 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
||||
typeMapping.put("AnyType", "Object");
|
||||
|
||||
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("JsonObject", "package:built_value/json_object.dart");
|
||||
importMapping.put("Uint8List", "dart:typed_data");
|
||||
@@ -109,7 +106,6 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
||||
this.nullableFields = nullableFields;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "dart-dio";
|
||||
@@ -122,14 +118,14 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema schema) {
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
if (modelUtils.isMapSchema(schema)) {
|
||||
return "const {}";
|
||||
} else if (ModelUtils.isArraySchema(schema)) {
|
||||
} else if (modelUtils.isArraySchema(schema)) {
|
||||
return "const []";
|
||||
}
|
||||
|
||||
if (schema.getDefault() != null) {
|
||||
if (ModelUtils.isStringSchema(schema)) {
|
||||
if (modelUtils.isStringSchema(schema)) {
|
||||
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
||||
}
|
||||
return schema.getDefault().toString();
|
||||
@@ -316,6 +312,11 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
||||
if (property.dataType.contains("JsonObject")) {
|
||||
model.imports.add("JsonObject");
|
||||
}
|
||||
|
||||
if (property.isEnum) {
|
||||
// enums are generated with built_value and make use of BuiltSet
|
||||
model.imports.add("BuiltSet");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -378,5 +379,4 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -132,14 +132,14 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema schema) {
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
if (modelUtils.isMapSchema(schema)) {
|
||||
return "const {}";
|
||||
} else if (ModelUtils.isArraySchema(schema)) {
|
||||
} else if (modelUtils.isArraySchema(schema)) {
|
||||
return "const []";
|
||||
}
|
||||
|
||||
if (schema.getDefault() != null) {
|
||||
if (ModelUtils.isStringSchema(schema)) {
|
||||
if (modelUtils.isStringSchema(schema)) {
|
||||
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
||||
}
|
||||
return schema.getDefault().toString();
|
||||
|
||||
@@ -264,7 +264,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
public void preprocessOpenAPI() {
|
||||
Info info = openAPI.getInfo();
|
||||
if (moduleName == null) {
|
||||
if (info.getTitle() != null) {
|
||||
@@ -490,42 +490,42 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return "%{optional(String.t) => " + getTypeDeclaration(inner) + "}";
|
||||
} else if (ModelUtils.isPasswordSchema(p)) {
|
||||
} else if (modelUtils.isPasswordSchema(p)) {
|
||||
return "String.t";
|
||||
} else if (ModelUtils.isEmailSchema(p)) {
|
||||
} else if (modelUtils.isEmailSchema(p)) {
|
||||
return "String.t";
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
} else if (modelUtils.isByteArraySchema(p)) {
|
||||
return "binary()";
|
||||
} else if (ModelUtils.isUUIDSchema(p)) {
|
||||
} else if (modelUtils.isUUIDSchema(p)) {
|
||||
return "String.t";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
return "Date.t";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
return "DateTime.t";
|
||||
} else if (ModelUtils.isObjectSchema(p)) {
|
||||
} else if (modelUtils.isObjectSchema(p)) {
|
||||
// TODO How to map it?
|
||||
return super.getTypeDeclaration(p);
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
return "integer()";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
return "float()";
|
||||
} else if (ModelUtils.isBinarySchema(p) || ModelUtils.isFileSchema(p)) {
|
||||
} else if (modelUtils.isBinarySchema(p) || modelUtils.isFileSchema(p)) {
|
||||
return "String.t";
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
} else if (modelUtils.isBooleanSchema(p)) {
|
||||
return "boolean()";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
||||
// How to map it?
|
||||
return super.getTypeDeclaration(p);
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
} else if (modelUtils.isFileSchema(p)) {
|
||||
return "String.t";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
return "String.t";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.samskivert.mustache.Mustache.Lambda;
|
||||
import com.samskivert.mustache.Template;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.meta.features.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
@@ -37,6 +38,7 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@@ -174,6 +176,31 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
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
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
@@ -211,7 +238,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
return instantiationTypes.get("array") + " " + inner;
|
||||
@@ -387,19 +414,19 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
}
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
} else if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return Boolean.valueOf(p.getDefault().toString()) ? "True" : "False";
|
||||
}
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
@@ -423,11 +450,11 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getTypeDeclaration(inner);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getTypeDeclaration(inner);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Schema model) {
|
||||
CodegenModel cm = super.fromModel(name, model);
|
||||
if(ModelUtils.isArraySchema(model)) {
|
||||
if(modelUtils.isArraySchema(model)) {
|
||||
return new CodegenArrayModel(cm, (ArraySchema) model);
|
||||
} else {
|
||||
return cm;
|
||||
@@ -152,7 +152,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema schema) {
|
||||
String typeDeclaration = super.getSchemaType(schema);
|
||||
if(ModelUtils.isArraySchema(schema)) {
|
||||
if(modelUtils.isArraySchema(schema)) {
|
||||
ArraySchema arraySchema = (ArraySchema) schema;
|
||||
String complexType = getSchemaType(arraySchema.getItems());
|
||||
|
||||
@@ -170,7 +170,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String getSchemaType(Schema schema) {
|
||||
String schemaType = super.getSchemaType(schema);
|
||||
if(ModelUtils.isArraySchema(schema)) {
|
||||
if(modelUtils.isArraySchema(schema)) {
|
||||
ArraySchema arraySchema = (ArraySchema) schema;
|
||||
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);
|
||||
|
||||
return sb.append(")").toString();
|
||||
} else if(ModelUtils.isIntegerSchema(schema)) {
|
||||
} else if(modelUtils.isIntegerSchema(schema)) {
|
||||
StringBuilder sb = new StringBuilder("integer(");
|
||||
|
||||
BigDecimal min = schema.getMinimum();
|
||||
@@ -192,9 +192,9 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
||||
if(min != null && max != null) sb.append(", ").append(max);
|
||||
|
||||
return sb.append(")").toString();
|
||||
} else if(ModelUtils.isDateSchema(schema) || ModelUtils.isDateTimeSchema(schema)) {
|
||||
} else if(modelUtils.isDateSchema(schema) || modelUtils.isDateTimeSchema(schema)) {
|
||||
return typeMapping.get(schemaType);
|
||||
} else if(ModelUtils.isStringSchema(schema)) {
|
||||
} else if(modelUtils.isStringSchema(schema)) {
|
||||
StringBuilder sb = new StringBuilder("binary(");
|
||||
Integer min = schema.getMinLength();
|
||||
Integer max = schema.getMaxLength();
|
||||
|
||||
@@ -235,7 +235,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p) || ModelUtils.isMapSchema(p)) {
|
||||
if (modelUtils.isArraySchema(p) || modelUtils.isMapSchema(p)) {
|
||||
return getSchemaType(p);
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
@@ -258,27 +258,27 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
return "null";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
return "null";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return "0.0";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
return "new Dictionary()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} else if (modelUtils.isArraySchema(p)) {
|
||||
return "new Array()";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
return "null";
|
||||
} else {
|
||||
return "NaN";
|
||||
|
||||
@@ -166,8 +166,8 @@ public class FsharpGiraffeServerCodegen extends AbstractFSharpCodegen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
||||
additionalProperties.put("serverHost", url.getHost());
|
||||
additionalProperties.put("serverPort", URLPathUtils.getPort(url, 8080));
|
||||
|
||||
@@ -349,8 +349,8 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
p = ModelUtils.getReferencedSchema(this.openAPI, p);
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
p = modelUtils.getReferencedSchema(p);
|
||||
if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
||||
}
|
||||
@@ -452,14 +452,10 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
}
|
||||
|
||||
for (CodegenOperation operation : operationList) {
|
||||
boolean needTimeImport = false;
|
||||
for (CodegenParameter cp : operation.allParams) {
|
||||
cp.vendorExtensions.put("x-go-example", constructExampleCode(cp, modelMaps, processedModelMaps));
|
||||
if (cp.isDateTime || cp.isDate) { // datetime or date
|
||||
needTimeImport = true;
|
||||
}
|
||||
}
|
||||
if (needTimeImport) {
|
||||
if (processedModelMaps.containsKey("time.Time")) {
|
||||
operation.vendorExtensions.put("x-go-import", " \"time\"");
|
||||
}
|
||||
processedModelMaps.clear();
|
||||
@@ -485,7 +481,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
return prefix + "{\"key\": " + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
|
||||
} else if (codegenParameter.isPrimitiveType) { // primitive type
|
||||
if (codegenParameter.isString) {
|
||||
if (!StringUtils.isEmpty(codegenParameter.example) && codegenParameter.example != "null") {
|
||||
if (!StringUtils.isEmpty(codegenParameter.example) && !"null".equals(codegenParameter.example)) {
|
||||
return "\"" + codegenParameter.example + "\"";
|
||||
} else {
|
||||
return "\"" + codegenParameter.paramName + "_example\"";
|
||||
@@ -499,11 +495,12 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
} else if (codegenParameter.isUri) { // URL
|
||||
return "\"https://example.com\"";
|
||||
} else if (codegenParameter.isDateTime || codegenParameter.isDate) { // datetime or date
|
||||
processedModelMap.put("time.Time", 1);
|
||||
return "time.Now()";
|
||||
} else if (codegenParameter.isFile) {
|
||||
return "os.NewFile(1234, \"some_file\")";
|
||||
} else { // numeric
|
||||
if (!StringUtils.isEmpty(codegenParameter.example) && codegenParameter.example != "null") {
|
||||
if (!StringUtils.isEmpty(codegenParameter.example) && !"null".equals(codegenParameter.example)) {
|
||||
return codegenParameter.dataType + "(" + codegenParameter.example + ")";
|
||||
} else {
|
||||
return codegenParameter.dataType + "(987)";
|
||||
@@ -513,6 +510,15 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
// look up the model
|
||||
if (modelMaps.containsKey(codegenParameter.dataType)) {
|
||||
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 {
|
||||
//LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenParameter.dataType);
|
||||
return "TODO";
|
||||
@@ -537,7 +543,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
return prefix + "{\"key\": " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
|
||||
} else if (codegenProperty.isPrimitiveType) { // primitive type
|
||||
if (codegenProperty.isString) {
|
||||
if (!StringUtils.isEmpty(codegenProperty.example) && codegenProperty.example != "null") {
|
||||
if (!StringUtils.isEmpty(codegenProperty.example) && !"null".equals(codegenProperty.example)) {
|
||||
return "\"" + codegenProperty.example + "\"";
|
||||
} else {
|
||||
return "\"" + codegenProperty.name + "_example\"";
|
||||
@@ -551,10 +557,11 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
} else if (codegenProperty.isUri) { // URL
|
||||
return "\"https://example.com\"";
|
||||
} else if (codegenProperty.isDateTime || codegenProperty.isDate) { // datetime or date
|
||||
processedModelMap.put("time.Time", 1);
|
||||
return "time.Now()";
|
||||
} else { // numeric
|
||||
String example;
|
||||
if (!StringUtils.isEmpty(codegenProperty.example) && codegenProperty.example != "null") {
|
||||
if (!StringUtils.isEmpty(codegenProperty.example) && !"null".equals(codegenProperty.example)) {
|
||||
example = codegenProperty.example;
|
||||
} else {
|
||||
example = "123";
|
||||
@@ -566,6 +573,15 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
// look up the model
|
||||
if (modelMaps.containsKey(codegenProperty.dataType)) {
|
||||
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 {
|
||||
//LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenProperty.dataType);
|
||||
return "\"TODO\"";
|
||||
@@ -601,6 +617,6 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
for (CodegenProperty codegenProperty : codegenModel.requiredVars) {
|
||||
propertyExamples.add(constructExampleCode(codegenProperty, modelMaps, processedModelMap));
|
||||
}
|
||||
return "*" + goImportAlias + ".New" + model + "(" + StringUtils.join(propertyExamples, ", ") + ")";
|
||||
return "*" + goImportAlias + ".New" + toModelName(model) + "(" + StringUtils.join(propertyExamples, ", ") + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class GraphQLNodeJSExpressServerCodegen extends AbstractGraphQLCodegen im
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
|
||||
@@ -131,7 +131,7 @@ public class GraphQLNodeJSExpressServerCodegen extends AbstractGraphQLCodegen im
|
||||
// between some specific types for GraphQL:
|
||||
// return "[" + getTypeDeclaration(inner) + "]";
|
||||
return getTypeDeclaration(inner);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
|
||||
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:
|
||||
String schemaType = getSchemaType(p);
|
||||
String nullable = ModelUtils.isNullable(p) ? "" : "!";
|
||||
String nullable = modelUtils.isNullable(p) ? "" : "!";
|
||||
|
||||
if (typeMapping.containsKey(schemaType)) {
|
||||
return typeMapping.get(schemaType) + nullable;
|
||||
|
||||
@@ -519,7 +519,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
public void preprocessOpenAPI() {
|
||||
String baseTitle = openAPI.getInfo().getTitle();
|
||||
|
||||
if (baseTitle == null) {
|
||||
@@ -612,7 +612,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
additionalProperties.put(X_HAS_IMPORT_MAPPINGS, true);
|
||||
}
|
||||
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
super.preprocessOpenAPI();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -624,11 +624,11 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
||||
}
|
||||
@@ -650,7 +650,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
if (modelUtils.isMapSchema(p)) {
|
||||
Schema additionalProperties2 = getAdditionalProperties(p);
|
||||
String type = additionalProperties2.getType();
|
||||
if (null == type) {
|
||||
@@ -659,7 +659,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
}
|
||||
String inner = getSchemaType(additionalProperties2);
|
||||
return "(Map.Map Text " + inner + ")";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} else if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
return getSchemaType(ap.getItems());
|
||||
} else {
|
||||
@@ -1245,11 +1245,11 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
||||
}
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
} else if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
||||
return "False";
|
||||
|
||||
@@ -268,7 +268,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
public void preprocessOpenAPI() {
|
||||
// From the title, compute a reasonable name for the package and the API
|
||||
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
|
||||
additionalProperties.put("generateToSchema", true);
|
||||
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
super.preprocessOpenAPI();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -368,11 +368,11 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
||||
}
|
||||
@@ -407,7 +407,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
if (modelUtils.isMapSchema(p)) {
|
||||
Schema additionalProperties2 = getAdditionalProperties(p);
|
||||
String type = additionalProperties2.getType();
|
||||
if (null == type) {
|
||||
@@ -416,7 +416,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
String inner = getSchemaType(additionalProperties2);
|
||||
return "(Map.Map Text " + inner + ")";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
} else if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
// Return only the inner type; the wrapping with QueryList is done
|
||||
|
||||
@@ -147,7 +147,7 @@ public class JMeterClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
public void preprocessOpenAPI() {
|
||||
if (openAPI != null && openAPI.getPaths() != null) {
|
||||
for (String pathname : openAPI.getPaths().keySet()) {
|
||||
PathItem path = openAPI.getPaths().get(pathname);
|
||||
@@ -201,11 +201,11 @@ public class JMeterClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
|
||||
@@ -138,6 +138,14 @@ public class JavaCXFClientCodegen extends AbstractJavaCodegen
|
||||
model.imports.remove("ApiModel");
|
||||
model.imports.remove("JsonSerialize");
|
||||
model.imports.remove("ToStringSerializer");
|
||||
|
||||
//Add imports for Jackson when model has inner enum
|
||||
if (additionalProperties.containsKey("jackson")) {
|
||||
if (Boolean.FALSE.equals(model.isEnum) && Boolean.TRUE.equals(model.hasEnums)) {
|
||||
model.imports.add("JsonCreator");
|
||||
model.imports.add("JsonValue");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1431,9 +1431,9 @@ public class JavaCXFExtServerCodegen extends JavaCXFServerCodegen implements CXF
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isGenerateAliasAsModel(p) && StringUtils.isNotEmpty(p.get$ref())) {
|
||||
Schema<?> ref = ModelUtils.getReferencedSchema(this.openAPI, p);
|
||||
if (ModelUtils.isArraySchema(ref) || ModelUtils.isMapSchema(ref)) {
|
||||
if (modelUtils.isGenerateAliasAsModel(p) && StringUtils.isNotEmpty(p.get$ref())) {
|
||||
Schema<?> ref = modelUtils.getReferencedSchema(p);
|
||||
if (modelUtils.isArraySchema(ref) || modelUtils.isMapSchema(ref)) {
|
||||
String typeDeclaration = getTypeDeclaration(p);
|
||||
return String.format(Locale.ROOT, "new %s()", typeDeclaration);
|
||||
}
|
||||
|
||||
@@ -243,6 +243,14 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
model.imports.remove("ApiModel");
|
||||
model.imports.remove("JsonSerialize");
|
||||
model.imports.remove("ToStringSerializer");
|
||||
|
||||
//Add imports for Jackson when model has inner enum
|
||||
if (additionalProperties.containsKey("jackson")) {
|
||||
if (Boolean.FALSE.equals(model.isEnum) && Boolean.TRUE.equals(model.hasEnums)) {
|
||||
model.imports.add("JsonCreator");
|
||||
model.imports.add("JsonValue");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -454,8 +454,8 @@ public class JavaPKMSTServerCodegen extends AbstractJavaCodegen {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
if (openAPI == null || openAPI.getPaths() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
public static final String HANDLE_EXCEPTIONS = "handleExceptions";
|
||||
public static final String WRAP_CALLS = "wrapCalls";
|
||||
public static final String USE_SWAGGER_UI = "useSwaggerUI";
|
||||
public static final String SUPPORT_ASYNC = "supportAsync";
|
||||
|
||||
protected String title = "openapi-java-playframework";
|
||||
protected String configPackage = "org.openapitools.configuration";
|
||||
@@ -54,6 +55,7 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
protected boolean handleExceptions = true;
|
||||
protected boolean wrapCalls = true;
|
||||
protected boolean useSwaggerUI = true;
|
||||
protected boolean supportAsync = false;
|
||||
|
||||
public JavaPlayFrameworkCodegen() {
|
||||
super();
|
||||
@@ -94,6 +96,7 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
cliOptions.add(createBooleanCliWithDefault(HANDLE_EXCEPTIONS, "Add a 'throw exception' to each controller function. Add also a custom error handler where you can put your custom logic", handleExceptions));
|
||||
cliOptions.add(createBooleanCliWithDefault(WRAP_CALLS, "Add a wrapper to each controller function to handle things like metrics, response modification, etc..", wrapCalls));
|
||||
cliOptions.add(createBooleanCliWithDefault(USE_SWAGGER_UI, "Add a route to /api which show your documentation in swagger-ui. Will also import needed dependencies", useSwaggerUI));
|
||||
cliOptions.add(createBooleanCliWithDefault(SUPPORT_ASYNC, "Support Async operations", supportAsync));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,6 +170,11 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
}
|
||||
writePropertyBack(USE_SWAGGER_UI, useSwaggerUI);
|
||||
|
||||
if (additionalProperties.containsKey(SUPPORT_ASYNC)) {
|
||||
this.setSupportAsync(convertPropertyToBoolean(SUPPORT_ASYNC));
|
||||
}
|
||||
writePropertyBack(SUPPORT_ASYNC, supportAsync);
|
||||
|
||||
//We don't use annotation anymore
|
||||
importMapping.remove("ApiModelProperty");
|
||||
importMapping.remove("ApiModel");
|
||||
@@ -287,6 +295,10 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
this.useSwaggerUI = useSwaggerUI;
|
||||
}
|
||||
|
||||
public void setSupportAsync(boolean supportAsync) {
|
||||
this.supportAsync = supportAsync;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
|
||||
@@ -223,8 +223,8 @@ public class JavaVertXServerCodegen extends AbstractJavaCodegen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
|
||||
// add server port from the swagger file, 8080 by default
|
||||
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
||||
|
||||
@@ -255,8 +255,8 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
|
||||
if (openAPI.getInfo() != null) {
|
||||
Info info = openAPI.getInfo();
|
||||
@@ -560,11 +560,11 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return "{String: " + getTypeDeclaration(inner) + "}";
|
||||
}
|
||||
@@ -573,23 +573,23 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "'" + p.getDefault() + "'";
|
||||
}
|
||||
@@ -814,7 +814,7 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
||||
@Override
|
||||
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);
|
||||
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||
@@ -822,14 +822,14 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||
codegenModel = JavascriptApolloClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
}
|
||||
if (ModelUtils.isArraySchema(model)) {
|
||||
if (modelUtils.isArraySchema(model)) {
|
||||
ArraySchema am = (ArraySchema) model;
|
||||
if (codegenModel != null && am.getItems() != null) {
|
||||
String itemType = getSchemaType(am.getItems());
|
||||
codegenModel.vendorExtensions.put("x-is-array", true);
|
||||
codegenModel.vendorExtensions.put("x-item-type", itemType);
|
||||
}
|
||||
} else if (ModelUtils.isMapSchema(model)) {
|
||||
} else if (modelUtils.isMapSchema(model)) {
|
||||
if (codegenModel != null && getAdditionalProperties(model) != null) {
|
||||
String itemType = getSchemaType(getAdditionalProperties(model));
|
||||
codegenModel.vendorExtensions.put("x-is-map", true);
|
||||
|
||||
@@ -281,8 +281,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
|
||||
if (openAPI.getInfo() != null) {
|
||||
Info info = openAPI.getInfo();
|
||||
@@ -611,11 +611,11 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return "{String: " + getTypeDeclaration(inner) + "}";
|
||||
}
|
||||
@@ -624,23 +624,23 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (modelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
} else if (modelUtils.isDateSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||
// TODO
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
} else if (modelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (modelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
} else if (modelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "'" + p.getDefault() + "'";
|
||||
}
|
||||
@@ -865,7 +865,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
@Override
|
||||
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);
|
||||
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||
@@ -873,14 +873,14 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||
codegenModel = JavascriptClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
}
|
||||
if (ModelUtils.isArraySchema(model)) {
|
||||
if (modelUtils.isArraySchema(model)) {
|
||||
ArraySchema am = (ArraySchema) model;
|
||||
if (codegenModel != null && am.getItems() != null) {
|
||||
String itemType = getSchemaType(am.getItems());
|
||||
codegenModel.vendorExtensions.put("x-is-array", true);
|
||||
codegenModel.vendorExtensions.put("x-item-type", itemType);
|
||||
}
|
||||
} else if (ModelUtils.isMapSchema(model)) {
|
||||
} else if (modelUtils.isMapSchema(model)) {
|
||||
if (codegenModel != null && getAdditionalProperties(model) != null) {
|
||||
String itemType = getSchemaType(getAdditionalProperties(model));
|
||||
codegenModel.vendorExtensions.put("x-is-map", true);
|
||||
@@ -1220,4 +1220,16 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCollectionFormat(CodegenParameter codegenParameter) {
|
||||
// This method will return `passthrough` when the parameter data format is binary and an array.
|
||||
// `passthrough` is not part of the OAS spec. However, this will act like a flag that we should
|
||||
// not do any processing on the collection type (i.e. convert to tsv, csv, etc..). This is
|
||||
// critical to support multi file uploads correctly.
|
||||
if (codegenParameter.isArray && Objects.equals(codegenParameter.dataFormat, "binary")) {
|
||||
return "passthrough";
|
||||
}
|
||||
return super.getCollectionFormat(codegenParameter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,8 +112,8 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
|
||||
if (useEs6) {
|
||||
embeddedTemplateDir = templateDir = "Javascript-Closure-Angular/es6";
|
||||
@@ -220,14 +220,14 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (modelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<!" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (modelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return "Object<!string, "+ getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
} else if (modelUtils.isFileSchema(p)) {
|
||||
return "Object";
|
||||
}
|
||||
String type = super.getTypeDeclaration(p);
|
||||
|
||||
@@ -136,8 +136,8 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
|
||||
if (openAPI.getInfo() != null) {
|
||||
Info info = openAPI.getInfo();
|
||||
|
||||
@@ -238,8 +238,8 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
|
||||
if (openAPI.getInfo() != null) {
|
||||
Info info = openAPI.getInfo();
|
||||
@@ -325,16 +325,16 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
if (hasBodyParameter(openAPI, operation) || hasFormParameter(openAPI, operation)) {
|
||||
String defaultContentType = hasFormParameter(openAPI, operation) ? "application/x-www-form-urlencoded" : "application/json";
|
||||
List<String> consumes = new ArrayList<>(getConsumesInfo(openAPI, operation));
|
||||
if (hasBodyParameter(operation) || hasFormParameter(operation)) {
|
||||
String defaultContentType = hasFormParameter(operation) ? "application/x-www-form-urlencoded" : "application/json";
|
||||
List<String> consumes = new ArrayList<>(getConsumesInfo(operation));
|
||||
String contentTypeValue = consumes == null || consumes.isEmpty() ? defaultContentType : consumes.get(0);
|
||||
if (contentTypeValue.equals("*/*"))
|
||||
contentTypeValue = "application/json";
|
||||
Parameter contentType = new Parameter("Content-Type", getDoubleQuotedString(contentTypeValue));
|
||||
httpParams.add(contentType);
|
||||
|
||||
RequestBody requestBody = ModelUtils.getReferencedRequestBody(openAPI, operation.getRequestBody());
|
||||
RequestBody requestBody = modelUtils.getReferencedRequestBody(operation.getRequestBody());
|
||||
|
||||
for (Map.Entry<String, ApiResponse> responseEntry : operation.getResponses().entrySet()) {
|
||||
CodegenResponse r = fromResponse(responseEntry.getKey(), responseEntry.getValue());
|
||||
@@ -349,7 +349,7 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
for (CodegenParameter parameter : formParameteres) {
|
||||
String reference = "";
|
||||
if (parameter.isModel) {
|
||||
Schema nestedSchema = ModelUtils.getSchema(openAPI, parameter.baseType);
|
||||
Schema nestedSchema = modelUtils.getSchema(parameter.baseType);
|
||||
CodegenModel model = fromModel(parameter.paramName, nestedSchema);
|
||||
reference = generateNestedModelTemplate(model);
|
||||
if (parameter.dataType.equals("List")) {
|
||||
@@ -369,7 +369,7 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
bodyOrFormParams.add(k6Parameter);
|
||||
}
|
||||
}
|
||||
String accepts = getAccept(openAPI, operation);
|
||||
String accepts = getAccept(operation);
|
||||
String responseType = getDoubleQuotedString(accepts);
|
||||
|
||||
try {
|
||||
@@ -602,10 +602,10 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
private static String getAccept(OpenAPI openAPI, Operation operation) {
|
||||
private String getAccept(Operation operation) {
|
||||
String accepts = null;
|
||||
String defaultContentType = "application/json";
|
||||
Set<String> producesInfo = getProducesInfo(openAPI, operation);
|
||||
Set<String> producesInfo = getProducesInfo(operation);
|
||||
if (producesInfo != null && !producesInfo.isEmpty()) {
|
||||
ArrayList<String> produces = new ArrayList<>(producesInfo);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -474,8 +474,8 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
super.preprocessOpenAPI(openAPI);
|
||||
public void preprocessOpenAPI() {
|
||||
super.preprocessOpenAPI();
|
||||
|
||||
if (!additionalProperties.containsKey(TITLE)) {
|
||||
// The purpose of the title is for:
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user