forked from loafle/openapi-generator-original
Compare commits
40 Commits
v7.9.0
...
update-mus
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
277b43bcea | ||
|
|
38dac13c26 | ||
|
|
0a39a1760e | ||
|
|
ca032113f2 | ||
|
|
65b1859161 | ||
|
|
8f7d9f7467 | ||
|
|
c487a6ea18 | ||
|
|
21a8e4e623 | ||
|
|
b1dd6b262e | ||
|
|
1214ad7492 | ||
|
|
4ddfb6fc41 | ||
|
|
3b3f9a770a | ||
|
|
2354d402a8 | ||
|
|
b5b760a8a2 | ||
|
|
8849156d29 | ||
|
|
2838b9584b | ||
|
|
d1ca82cb8b | ||
|
|
462f450366 | ||
|
|
185c0639c0 | ||
|
|
715f6b634e | ||
|
|
7f899dff97 | ||
|
|
368b9b7e37 | ||
|
|
a84946bdb3 | ||
|
|
d9cdecf3c3 | ||
|
|
b357744048 | ||
|
|
45fa4384e7 | ||
|
|
ea4b17c32f | ||
|
|
b730e36937 | ||
|
|
43fd18935c | ||
|
|
30e6612558 | ||
|
|
d14eab8446 | ||
|
|
627c0f43cd | ||
|
|
31be9b9207 | ||
|
|
d60200de38 | ||
|
|
22b8c47b93 | ||
|
|
ba169342a1 | ||
|
|
b3b3f46ee2 | ||
|
|
25b834131c | ||
|
|
7c84177e65 | ||
|
|
e2c458b9ea |
@@ -11,6 +11,7 @@ on:
|
||||
- samples/openapi3/client/petstore/java/jersey2-java8-swagger2/**
|
||||
- samples/openapi3/client/petstore/java/native**
|
||||
- samples/client/others/java/okhttp-gson-oneOf/**
|
||||
- samples/client/others/java/okhttp-gson-oneOf-array/**
|
||||
- samples/client/others/java/resttemplate-useAbstractionForFiles/**
|
||||
- samples/client/others/java/webclient-useAbstractionForFiles/**
|
||||
- samples/client/others/java/jersey2-oneOf-duplicates/**
|
||||
@@ -26,6 +27,7 @@ on:
|
||||
- samples/openapi3/client/petstore/java/jersey2-java8-swagger2/**
|
||||
- samples/openapi3/client/petstore/java/native**
|
||||
- samples/client/others/java/okhttp-gson-oneOf/**
|
||||
- samples/client/others/java/okhttp-gson-oneOf-array/**
|
||||
- samples/client/others/java/resttemplate-useAbstractionForFiles/**
|
||||
- samples/client/others/java/webclient-useAbstractionForFiles/**
|
||||
- samples/client/others/java/jersey2-oneOf-duplicates/**
|
||||
@@ -75,6 +77,7 @@ jobs:
|
||||
- samples/client/petstore/java/resttemplate-swagger2/
|
||||
- samples/openapi3/client/petstore/java/jersey2-java8-swagger2/
|
||||
- samples/client/others/java/okhttp-gson-oneOf/
|
||||
- samples/client/others/java/okhttp-gson-oneOf-array/
|
||||
- samples/client/echo_api/java/okhttp-gson-user-defined-templates/
|
||||
- samples/client/others/java/resttemplate-useAbstractionForFiles/
|
||||
- samples/client/others/java/webclient-useAbstractionForFiles/
|
||||
|
||||
2
.github/workflows/samples-kotlin-server.yaml
vendored
2
.github/workflows/samples-kotlin-server.yaml
vendored
@@ -17,7 +17,7 @@ on:
|
||||
# - samples/server/petstore/kotlin-spring-default/**
|
||||
|
||||
env:
|
||||
GRADLE_VERSION: 6.9
|
||||
GRADLE_VERSION: 7.6.4
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
23
.travis.yml
23
.travis.yml
@@ -201,16 +201,19 @@ after_success:
|
||||
echo "Pushed to $DOCKER_CODEGEN_CLI_IMAGE_NAME";
|
||||
fi;
|
||||
fi;
|
||||
# publish latest website, variables below are secure environment variables which are unavailable to PRs from forks.
|
||||
#- if [ "$TRAVIS_BRANCH" = "master" ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
||||
# cd website;
|
||||
# git config --global user.name "${GH_NAME}";
|
||||
# git config --global user.email "${GH_EMAIL}";
|
||||
# echo "machine github.com login ${GH_NAME} password ${GH_TOKEN}" > ~/.netrc;
|
||||
# yarn install;
|
||||
# GIT_USER="${GH_NAME}" yarn run publish-gh-pages;
|
||||
# fi;
|
||||
|
||||
## NOTE; we will do the followign manually instead as the page doesn't need to be updated in every single travis build
|
||||
## publish latest website, variables below are secure environment variables which are unavailable to PRs from forks.
|
||||
# - if [ "$TRAVIS_BRANCH" = "master" ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
||||
# sed -i "s/Vector{UInt8}/Vector\{UInt8\}/g" docs/generators/julia-client.md;
|
||||
# sed -i "s/Vector{UInt8}/Vector\{UInt8\}/g" docs/generators/julia-server.md;
|
||||
# cd website;
|
||||
# git config --global user.name "${GH_NAME}";
|
||||
# git config --global user.email "${GH_EMAIL}";
|
||||
# echo "machine github.com login ${GH_NAME} password ${GH_TOKEN}" > ~/.netrc;
|
||||
# yarn install;
|
||||
# GIT_USER="${GH_NAME}" yarn run publish-gh-pages;
|
||||
# fi;
|
||||
#
|
||||
env:
|
||||
- DOCKER_GENERATOR_IMAGE_NAME=openapitools/openapi-generator-online DOCKER_CODEGEN_CLI_IMAGE_NAME=openapitools/openapi-generator-cli NODE_ENV=test CC=gcc-5 CXX=g++-5
|
||||
|
||||
|
||||
@@ -115,6 +115,7 @@ else
|
||||
(cd samples/client/petstore/java/jersey2-java8 && mvn integration-test)
|
||||
(cd samples/openapi3/client/petstore/java/jersey2-java8 && mvn integration-test)
|
||||
(cd samples/client/petstore/java/jersey3 && mvn integration-test)
|
||||
(cd samples/client/petstore/java/jersey3-oneOf && mvn integration-test)
|
||||
(cd samples/client/others/java/okhttp-gson-streaming && mvn integration-test)
|
||||
(cd samples/client/petstore/java/okhttp-gson && mvn integration-test)
|
||||
(cd samples/client/petstore/java/okhttp-gson-3.1 && mvn integration-test)
|
||||
|
||||
17
README.md
17
README.md
@@ -15,7 +15,7 @@
|
||||
|
||||
<div align="center">
|
||||
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`7.9.0`):
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`7.10.0`):
|
||||
[](https://app.travis-ci.com/github/OpenAPITools/openapi-generator/builds)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator)
|
||||
@@ -129,7 +129,8 @@ The OpenAPI Specification has undergone 3 revisions since initial creation in 20
|
||||
|
||||
| OpenAPI Generator Version | Release Date | Notes |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------------------------------------------- |
|
||||
| 7.9.0 (upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.9.0-SNAPSHOT/) | 07.10.2024 | Minor release with breaking changes (with fallback) |
|
||||
| 7.10.0 (upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.10.0-SNAPSHOT/) | 07.11.2024 | Minor release with breaking changes (with fallback) |
|
||||
| [7.9.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v7.9.0) (latest stable release) | 07.10.2024 | Minor release with breaking changes (with fallback) |
|
||||
| [7.8.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v7.8.0) (latest stable release) | 19.08.2024 | Minor release with breaking changes (with fallback) |
|
||||
| [6.6.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v6.6.0) | 11.05.2023 | Minor release with breaking changes (with fallback) |
|
||||
| [5.4.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v5.4.0) | 31.01.2022 | Minor release with breaking changes (with fallback) |
|
||||
@@ -193,16 +194,16 @@ See the different versions of the [openapi-generator-cli](https://search.maven.o
|
||||
<!-- RELEASE_VERSION -->
|
||||
If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 11 runtime at a minimum):
|
||||
|
||||
JAR location: `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.8.0/openapi-generator-cli-7.8.0.jar`
|
||||
JAR location: `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.9.0/openapi-generator-cli-7.9.0.jar`
|
||||
|
||||
For **Mac/Linux** users:
|
||||
```sh
|
||||
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.8.0/openapi-generator-cli-7.8.0.jar -O openapi-generator-cli.jar
|
||||
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.9.0/openapi-generator-cli-7.9.0.jar -O openapi-generator-cli.jar
|
||||
```
|
||||
|
||||
For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.
|
||||
```
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.8.0/openapi-generator-cli-7.8.0.jar
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.9.0/openapi-generator-cli-7.9.0.jar
|
||||
```
|
||||
|
||||
After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage.
|
||||
@@ -437,7 +438,7 @@ openapi-generator-cli version
|
||||
To use a specific version of "openapi-generator-cli"
|
||||
|
||||
```sh
|
||||
openapi-generator-cli version-manager set 7.8.0
|
||||
openapi-generator-cli version-manager set 7.9.0
|
||||
```
|
||||
|
||||
Or install it as dev-dependency:
|
||||
@@ -464,7 +465,7 @@ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generat
|
||||
(if you're on Windows, replace the last command with `java -jar modules\openapi-generator-cli\target\openapi-generator-cli.jar generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php -o c:\temp\php_api_client`)
|
||||
|
||||
<!-- RELEASE_VERSION -->
|
||||
You can also download the JAR (latest release) directly from [maven.org](https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.8.0/openapi-generator-cli-7.8.0.jar)
|
||||
You can also download the JAR (latest release) directly from [maven.org](https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.9.0/openapi-generator-cli-7.9.0.jar)
|
||||
<!-- /RELEASE_VERSION -->
|
||||
|
||||
To get a list of **general** options available, please run `java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar help generate`
|
||||
@@ -1198,7 +1199,7 @@ If you want to join the committee, please kindly apply by sending an email to te
|
||||
| JMeter | @kannkyo (2021/01) |
|
||||
| Jetbrains HTTP Client | @jlengrand (2023/01) |
|
||||
| Julia | @tanmaykm (2023/01) |
|
||||
| Kotlin | @dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) |
|
||||
| Kotlin | @dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10) |
|
||||
| Lua | @daurnimator (2017/08) |
|
||||
| N4JS | @mmews-n4 (2023/03) |
|
||||
| Nim | |
|
||||
|
||||
@@ -2,6 +2,7 @@ generatorName: java-helidon-client
|
||||
library: mp
|
||||
outputDir: samples/client/petstore/java-helidon-client/v3/mp
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/java-helidon/client
|
||||
additionalProperties:
|
||||
helidonVersion: 3.2.7
|
||||
artifactId: petstore-helidon-client-mp
|
||||
|
||||
@@ -2,6 +2,7 @@ generatorName: java-helidon-client
|
||||
library: mp
|
||||
outputDir: samples/client/petstore/java-helidon-client/v4/mp
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/java-helidon/client
|
||||
additionalProperties:
|
||||
helidonVersion: 4.0.11
|
||||
artifactId: petstore-helidon-client-mp
|
||||
|
||||
@@ -2,6 +2,7 @@ generatorName: java-helidon-client
|
||||
library: se
|
||||
outputDir: samples/client/petstore/java-helidon-client/v3/se
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/java-helidon/client
|
||||
additionalProperties:
|
||||
helidonVersion: 3.2.7
|
||||
artifactId: petstore-helidon-client-se
|
||||
|
||||
@@ -2,6 +2,7 @@ generatorName: java-helidon-client
|
||||
library: se
|
||||
outputDir: samples/client/petstore/java-helidon-client/v4/se
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/java-helidon/client
|
||||
additionalProperties:
|
||||
helidonVersion: 4.0.11
|
||||
artifactId: petstore-helidon-client-se
|
||||
|
||||
@@ -10,4 +10,4 @@ additionalProperties:
|
||||
build: "all"
|
||||
test: "spock"
|
||||
useAuth: "false"
|
||||
fullProject: "true"
|
||||
fullProject: "true"
|
||||
|
||||
@@ -7,4 +7,4 @@ additionalProperties:
|
||||
helidonVersion: 3.2.7
|
||||
artifactId: format-helidon-server-mp
|
||||
hideGenerationTimestamp: "true"
|
||||
fullProject: "true"
|
||||
fullProject: "true"
|
||||
|
||||
7
bin/configs/java-jersey3-oneOf.yaml
Normal file
7
bin/configs/java-jersey3-oneOf.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
generatorName: java
|
||||
outputDir: samples/client/petstore/java/jersey3-oneOf
|
||||
library: jersey3
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf_additionalProperties.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/Java
|
||||
additionalProperties:
|
||||
hideGenerationTimestamp: true
|
||||
@@ -1,6 +1,7 @@
|
||||
generatorName: java-micronaut-client
|
||||
outputDir: samples/client/petstore/java-micronaut-client/
|
||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/java-micronaut/
|
||||
additionalProperties:
|
||||
artifactId: petstore-micronaut
|
||||
hideGenerationTimestamp: "true"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
generatorName: java-micronaut-server
|
||||
outputDir: samples/server/petstore/java-micronaut-server/
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/java-micronaut/
|
||||
additionalProperties:
|
||||
artifactId: petstore-micronaut-server
|
||||
hideGenerationTimestamp: "true"
|
||||
|
||||
8
bin/configs/java-okhttp-gson-oneOf-array.yaml
Normal file
8
bin/configs/java-okhttp-gson-oneOf-array.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
generatorName: java
|
||||
outputDir: samples/client/others/java/okhttp-gson-oneOf-array
|
||||
library: okhttp-gson
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf_array.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/Java
|
||||
additionalProperties:
|
||||
hideGenerationTimestamp: "true"
|
||||
useBeanValidation: "true"
|
||||
@@ -5,6 +5,7 @@ templateDir: modules/openapi-generator/src/main/resources/kotlin-client
|
||||
additionalProperties:
|
||||
artifactId: kotlin-petstore-string
|
||||
serializableModel: "true"
|
||||
mapFileBinaryToByteArray: "true"
|
||||
sortModelPropertiesByRequiredFlag: "false"
|
||||
sortParamsByRequiredFlag: "false"
|
||||
dateLibrary: string
|
||||
|
||||
@@ -92,16 +92,401 @@ git clone https://github.com/openapitools/openapi-generator.git
|
||||
cd openapi-generator/samples/client/petstore/swift/default/OpenAPIClientTests
|
||||
mvn integration-test
|
||||
```
|
||||
Besides `default` (folder), there's another folder `promisekit` for Swift API client with [PromiseKit support](https://github.com/mxcl/PromiseKit)
|
||||
|
||||
### Which Swift generator is still actively maintained?
|
||||
|
||||
Please use `swift5` generator because Swift 4.x is deprecated.
|
||||
There is a new `swift6` generator, that is currently in beta, try it and give us your feedback.
|
||||
|
||||
### How do I implement bearer token authentication with URLSession on the Swift 5 API client?
|
||||
|
||||
First you subclass RequestBuilderFactory
|
||||
|
||||
```
|
||||
git clone https://github.com/openapitools/openapi-generator.git
|
||||
cd openapi-generator/samples/client/petstore/swift/promisekit/OpenAPIClientTests
|
||||
mvn integration-test
|
||||
class BearerRequestBuilderFactory: RequestBuilderFactory {
|
||||
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type {
|
||||
BearerRequestBuilder<T>.self
|
||||
}
|
||||
|
||||
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type {
|
||||
BearerDecodableRequestBuilder<T>.self
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Is Swift (2.x) generator still actively maintained?
|
||||
Then you subclass URLSessionRequestBuilder and URLSessionDecodableRequestBuilder
|
||||
```
|
||||
class BearerRequestBuilder<T>: URLSessionRequestBuilder<T> {
|
||||
@discardableResult
|
||||
override func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (Result<Response<T>, ErrorResponse>) -> Void) -> RequestTask {
|
||||
|
||||
// Before making the request, we can validate if we have a bearer token to be able to make a request
|
||||
BearerTokenHandler.refreshTokenIfDoesntExist {
|
||||
|
||||
// Here we make the request
|
||||
super.execute(apiResponseQueue) { result in
|
||||
|
||||
switch result {
|
||||
case .success:
|
||||
// If we got a successful response, we send the response to the completion block
|
||||
completion(result)
|
||||
|
||||
case let .failure(error):
|
||||
|
||||
// If we got a failure response, we will analyse the error to see what we should do with it
|
||||
if case let ErrorResponse.error(_, data, response, error) = error {
|
||||
|
||||
// If the error is an ErrorResponse.error() we will analyse it to see if it's a 401, and if it's a 401, we will refresh the token and retry the request
|
||||
BearerTokenHandler.refreshTokenIfUnauthorizedRequestResponse(
|
||||
data: data,
|
||||
response: response,
|
||||
error: error
|
||||
) { wasTokenRefreshed in
|
||||
|
||||
if wasTokenRefreshed {
|
||||
// If the token was refreshed, it's because it was a 401 error, so we refreshed the token, and we are going to retry the request by calling self.execute()
|
||||
self.execute(apiResponseQueue, completion)
|
||||
} else {
|
||||
// If the token was not refreshed, it's because it was not a 401 error, so we send the response to the completion block
|
||||
completion(result)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If it's an unknown error, we send the response to the completion block
|
||||
completion(result)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return requestTask
|
||||
}
|
||||
}
|
||||
|
||||
class BearerDecodableRequestBuilder<T: Decodable>: URLSessionDecodableRequestBuilder<T> {
|
||||
@discardableResult
|
||||
override func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (Result<Response<T>, ErrorResponse>) -> Void) -> RequestTask {
|
||||
// Before making the request, we can validate if we have a bearer token to be able to make a request
|
||||
BearerTokenHandler.refreshTokenIfDoesntExist {
|
||||
|
||||
// Here we make the request
|
||||
super.execute(apiResponseQueue) { result in
|
||||
|
||||
switch result {
|
||||
case .success:
|
||||
// If we got a successful response, we send the response to the completion block
|
||||
completion(result)
|
||||
|
||||
case let .failure(error):
|
||||
|
||||
// If we got a failure response, we will analyse the error to see what we should do with it
|
||||
if case let ErrorResponse.error(_, data, response, error) = error {
|
||||
|
||||
// If the error is an ErrorResponse.error() we will analyse it to see if it's a 401, and if it's a 401, we will refresh the token and retry the request
|
||||
BearerTokenHandler.refreshTokenIfUnauthorizedRequestResponse(
|
||||
data: data,
|
||||
response: response,
|
||||
error: error
|
||||
) { wasTokenRefreshed in
|
||||
|
||||
if wasTokenRefreshed {
|
||||
// If the token was refreshed, it's because it was a 401 error, so we refreshed the token, and we are going to retry the request by calling self.execute()
|
||||
self.execute(apiResponseQueue, completion)
|
||||
} else {
|
||||
// If the token was not refreshed, it's because it was not a 401 error, so we send the response to the completion block
|
||||
completion(result)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If it's an unknown error, we send the response to the completion block
|
||||
completion(result)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return requestTask
|
||||
}
|
||||
}
|
||||
|
||||
class BearerTokenHandler {
|
||||
private static var bearerToken: String? = nil
|
||||
|
||||
static func refreshTokenIfDoesntExist(completionHandler: @escaping () -> Void) {
|
||||
if bearerToken != nil {
|
||||
completionHandler()
|
||||
} else {
|
||||
startRefreshingToken {
|
||||
completionHandler()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func refreshTokenIfUnauthorizedRequestResponse(data: Data?, response: URLResponse?, error: Error?, completionHandler: @escaping (Bool) -> Void) {
|
||||
if let response = response as? HTTPURLResponse, response.statusCode == 401 {
|
||||
startRefreshingToken {
|
||||
completionHandler(true)
|
||||
}
|
||||
} else {
|
||||
completionHandler(false)
|
||||
}
|
||||
}
|
||||
|
||||
private static func startRefreshingToken(completionHandler: @escaping () -> Void) {
|
||||
// Get a bearer token
|
||||
let dummyBearerToken = "..."
|
||||
|
||||
bearerToken = dummyBearerToken
|
||||
PetstoreClientAPI.customHeaders["Authorization"] = "Bearer \(dummyBearerToken)"
|
||||
|
||||
completionHandler()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
No, please use `swift3` or `swift4` generator instead as we want to focus on Swift 3.x, 4.x.
|
||||
Then you assign the `BearerRequestBuilderFactory` to the property `requestBuilderFactory`.
|
||||
|
||||
`PetstoreClientAPI.requestBuilderFactory = BearerRequestBuilderFactory()`
|
||||
|
||||
The name `PetstoreClientAPI.requestBuilderFactory` will change depending on your project name.
|
||||
|
||||
Here is a working sample that put's together all of this.
|
||||
[AppDelegate.swift](https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/swift5/urlsessionLibrary/SwaggerClientTests/SwaggerClient/AppDelegate.swift)
|
||||
[BearerDecodableRequestBuilder.swift](https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/swift5/urlsessionLibrary/SwaggerClientTests/SwaggerClient/BearerDecodableRequestBuilder.swift)
|
||||
|
||||
### How do I implement bearer token authentication with Alamofire on the Swift 5 API client?
|
||||
|
||||
First you subclass RequestBuilderFactory
|
||||
|
||||
```
|
||||
class BearerRequestBuilderFactory: RequestBuilderFactory {
|
||||
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type {
|
||||
BearerRequestBuilder<T>.self
|
||||
}
|
||||
|
||||
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type {
|
||||
BearerDecodableRequestBuilder<T>.self
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then you subclass AlamofireRequestBuilder and AlamofireDecodableRequestBuilder
|
||||
```
|
||||
class BearerRequestBuilder<T>: AlamofireRequestBuilder<T> {
|
||||
override func createSessionManager() -> SessionManager {
|
||||
let sessionManager = super.createSessionManager()
|
||||
|
||||
let bearerTokenHandler = BearerTokenHandler()
|
||||
sessionManager.adapter = bearerTokenHandler
|
||||
sessionManager.retrier = bearerTokenHandler
|
||||
|
||||
return sessionManager
|
||||
}
|
||||
}
|
||||
|
||||
class BearerDecodableRequestBuilder<T: Decodable>: AlamofireDecodableRequestBuilder<T> {
|
||||
override func createSessionManager() -> SessionManager {
|
||||
let sessionManager = super.createSessionManager()
|
||||
|
||||
let bearerTokenHandler = BearerTokenHandler()
|
||||
sessionManager.adapter = bearerTokenHandler
|
||||
sessionManager.retrier = bearerTokenHandler
|
||||
|
||||
return sessionManager
|
||||
}
|
||||
}
|
||||
|
||||
class BearerTokenHandler: RequestAdapter, RequestRetrier {
|
||||
private static var bearerToken: String? = nil
|
||||
|
||||
func adapt(_ urlRequest: URLRequest) throws -> URLRequest {
|
||||
if let bearerToken = Self.bearerToken {
|
||||
var urlRequest = urlRequest
|
||||
urlRequest.setValue("Bearer \(bearerToken)", forHTTPHeaderField: "Authorization")
|
||||
return urlRequest
|
||||
}
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
|
||||
func should(_: SessionManager, retry request: Request, with _: Error, completion: @escaping RequestRetryCompletion) {
|
||||
if let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401 {
|
||||
Self.startRefreshingToken { isTokenRefreshed in
|
||||
completion(isTokenRefreshed, 0.0)
|
||||
}
|
||||
} else {
|
||||
completion(false, 0.0)
|
||||
}
|
||||
}
|
||||
|
||||
private static func startRefreshingToken(completionHandler: @escaping (Bool) -> Void) {
|
||||
// Get a bearer token
|
||||
let dummyBearerToken = "..."
|
||||
|
||||
bearerToken = dummyBearerToken
|
||||
PetstoreClientAPI.customHeaders["Authorization"] = "Bearer \(dummyBearerToken)"
|
||||
|
||||
completionHandler(true)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then you assign the `BearerRequestBuilderFactory` to the property `requestBuilderFactory`.
|
||||
|
||||
`PetstoreClientAPI.requestBuilderFactory = BearerRequestBuilderFactory()`
|
||||
|
||||
The name `PetstoreClientAPI.requestBuilderFactory` will change depending on your project name.
|
||||
|
||||
Here is a working sample that put's together all of this.
|
||||
[AppDelegate.swift](https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/swift5/alamofireLibrary/SwaggerClientTests/SwaggerClient/AppDelegate.swift)
|
||||
[BearerTokenHandler.swift](https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/swift5/alamofireLibrary/SwaggerClientTests/SwaggerClient/BearerDecodableRequestBuilder.swift)
|
||||
|
||||
### How do I implement bearer token authentication with URLSession on the Swift 6 API client?
|
||||
|
||||
First you implement the `OpenAPIInterceptor` protocol.
|
||||
```
|
||||
public class BearerOpenAPIInterceptor: OpenAPIInterceptor {
|
||||
public init() {}
|
||||
|
||||
public func intercept(urlRequest: URLRequest, urlSession: URLSessionProtocol, openAPIClient: OpenAPIClient, completion: @escaping (Result<URLRequest, any Error>) -> Void) {
|
||||
refreshTokenIfDoesntExist { token in
|
||||
|
||||
// Change the current url request
|
||||
var newUrlRequest = urlRequest
|
||||
newUrlRequest.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
|
||||
|
||||
// Change the global headers
|
||||
openAPIClient.customHeaders["Authorization"] = "Bearer \(token)"
|
||||
|
||||
completion(.success(newUrlRequest))
|
||||
}
|
||||
}
|
||||
|
||||
public func retry(urlRequest: URLRequest, urlSession: URLSessionProtocol, openAPIClient: OpenAPIClient, data: Data?, response: URLResponse, error: Error, completion: @escaping (OpenAPIInterceptorRetry) -> Void) {
|
||||
// We will analyse the response to see if it's a 401, and if it's a 401, we will refresh the token and retry the request
|
||||
refreshTokenIfUnauthorizedRequestResponse(
|
||||
data: data,
|
||||
response: response,
|
||||
error: error
|
||||
) { (wasTokenRefreshed, newToken) in
|
||||
|
||||
if wasTokenRefreshed, let newToken = newToken {
|
||||
|
||||
// Change the global headers
|
||||
openAPIClient.customHeaders["Authorization"] = "Bearer \(newToken)"
|
||||
|
||||
completion(.retry)
|
||||
} else {
|
||||
// If the token was not refreshed, it's because it was not a 401 error, so we send the response to the completion block
|
||||
completion(.dontRetry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var bearerToken: String? = nil
|
||||
|
||||
func refreshTokenIfDoesntExist(completionHandler: @escaping (String) -> Void) {
|
||||
if let bearerToken = bearerToken {
|
||||
completionHandler(bearerToken)
|
||||
} else {
|
||||
startRefreshingToken { token in
|
||||
completionHandler(token)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func refreshTokenIfUnauthorizedRequestResponse(data: Data?, response: URLResponse, error: Error, completionHandler: @escaping (Bool, String?) -> Void) {
|
||||
if let response = response as? HTTPURLResponse, response.statusCode == 401 {
|
||||
startRefreshingToken { token in
|
||||
completionHandler(true, token)
|
||||
}
|
||||
} else {
|
||||
completionHandler(false, nil)
|
||||
}
|
||||
}
|
||||
|
||||
private func startRefreshingToken(completionHandler: @escaping (String) -> Void) {
|
||||
// Get a bearer token
|
||||
let dummyBearerToken = "..."
|
||||
|
||||
bearerToken = dummyBearerToken
|
||||
|
||||
completionHandler(dummyBearerToken)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then you assign the `BearerOpenAPIInterceptor` to the property `OpenAPIClient.shared.interceptor`.
|
||||
|
||||
`OpenAPIClient.shared.interceptor = BearerOpenAPIInterceptor()`
|
||||
|
||||
Here is a working sample that put's together all of this.
|
||||
[AppDelegate.swift](https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/swift6/urlsessionLibrary/SwaggerClientTests/SwaggerClient/AppDelegate.swift)
|
||||
[BearerTokenHandler.swift](https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/swift5/urlsessionLibrary/SwaggerClientTests/SwaggerClient/BearerDecodableRequestBuilder.swift)
|
||||
|
||||
### How do I implement bearer token authentication with Alamofire on the Swift 6 API client?
|
||||
|
||||
First implement the `Alamofire` `RequestInterceptor` protocol.
|
||||
```
|
||||
class BearerTokenHandler: RequestInterceptor, @unchecked Sendable {
|
||||
private var bearerToken: String? = nil
|
||||
|
||||
func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result<URLRequest, Error>) -> Void) {
|
||||
if let bearerToken = bearerToken {
|
||||
var urlRequest = urlRequest
|
||||
urlRequest.setValue("Bearer \(bearerToken)", forHTTPHeaderField: "Authorization")
|
||||
|
||||
completion(.success(urlRequest))
|
||||
return
|
||||
}
|
||||
|
||||
completion(.success(urlRequest))
|
||||
}
|
||||
|
||||
func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) {
|
||||
if let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401 {
|
||||
startRefreshingToken { isTokenRefreshed in
|
||||
completion(.retry)
|
||||
}
|
||||
} else {
|
||||
completion(.doNotRetryWithError(error))
|
||||
}
|
||||
}
|
||||
|
||||
private func startRefreshingToken(completionHandler: @escaping (Bool) -> Void) {
|
||||
// Get a bearer token
|
||||
let dummyBearerToken = "..."
|
||||
|
||||
bearerToken = dummyBearerToken
|
||||
OpenAPIClient.shared.customHeaders["Authorization"] = "Bearer \(dummyBearerToken)"
|
||||
|
||||
completionHandler(true)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then you assign the `BearerTokenHandler` to the property `OpenAPIClient.shared.interceptor`.
|
||||
|
||||
`OpenAPIClient.shared.interceptor = BearerTokenHandler()`
|
||||
|
||||
Here is a working sample that put's together all of this.
|
||||
[AppDelegate.swift](https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/swift6/alamofireLibrary/SwaggerClientTests/SwaggerClient/AppDelegate.swift)
|
||||
[BearerTokenHandler.swift](https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/swift6/alamofireLibrary/SwaggerClientTests/SwaggerClient/BearerTokenHandler.swift)
|
||||
|
||||
### How do I migrate from the Swift 5 generator to the swift 6 generator?
|
||||
|
||||
- Change the generator to the new `swift6` generator, e.g. `openapi-generator generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g swift6 -o /tmp/test/`
|
||||
- Check the `swift6` [URLSession](https://github.com/OpenAPITools/openapi-generator/tree/master/samples/client/petstore/swift6/urlsessionLibrary) and [Alamofire](https://github.com/OpenAPITools/openapi-generator/tree/master/samples/client/petstore/swift6/alamofireLibrary) samples.
|
||||
- The infrastructure files have been moved to a new directory called `Infrastructure`. Please delete the old ones.
|
||||
- The `AnyCodable` dependency has been removed and replaced with a new enum called `JSONValue`, allowing you to use this generator without external dependencies.
|
||||
- The `Combine` response is now deferred by default, meaning the request will only start when you begin listening to it. To restore the previous behavior, set the `combineDeferred` flag to `false`.
|
||||
- A new configuration, `apiStaticMethod`, allows you to use instance methods instead of class methods for API calls. For more information, check the sample project [apiNonStaticMethod](https://github.com/OpenAPITools/openapi-generator/tree/master/samples/client/petstore/swift6/apiNonStaticMethod).
|
||||
- The new default response is based on async/await. To revert to the previous behavior, set the `responseAs` flag to `ObjcBlock`.
|
||||
- The default project structure now follows the SPM (Swift Package Manager) structure. To revert to the old structure, set the `useSPMFileStructure` flag to `false`.
|
||||
- The former `{{projectName}}API` is now called `OpenAPIClient`.
|
||||
- You can now set a request interceptor and retrier by configuring `OpenAPIClient.shared.interceptor`, making authenticated requests easier to manage.
|
||||
|
||||
## TypeScript
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ The following generators are available:
|
||||
* [scalaz](generators/scalaz.md)
|
||||
* [swift-combine](generators/swift-combine.md)
|
||||
* [swift5](generators/swift5.md)
|
||||
* [swift6 (experimental)](generators/swift6.md)
|
||||
* [swift6 (beta)](generators/swift6.md)
|
||||
* [typescript (experimental)](generators/typescript.md)
|
||||
* [typescript-angular](generators/typescript-angular.md)
|
||||
* [typescript-aurelia](generators/typescript-aurelia.md)
|
||||
|
||||
@@ -120,6 +120,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
<li>if</li>
|
||||
<li>inline</li>
|
||||
<li>int</li>
|
||||
<li>linux</li>
|
||||
<li>long</li>
|
||||
<li>mutable</li>
|
||||
<li>namespace</li>
|
||||
|
||||
@@ -31,6 +31,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|groupId|Generated artifact package's organization (i.e. maven groupId).| |org.openapitools|
|
||||
|idea|Add IntellJ Idea plugin and mark Kotlin main and test folders as source folders.| |false|
|
||||
|library|Library template (sub-template) to use|<dl><dt>**jvm-ktor**</dt><dd>Platform: Java Virtual Machine. HTTP client: Ktor 1.6.7. JSON processing: Gson, Jackson (default).</dd><dt>**jvm-okhttp4**</dt><dd>[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.</dd><dt>**jvm-spring-webclient**</dt><dd>Platform: Java Virtual Machine. HTTP: Spring 5 (or 6 with useSpringBoot3 enabled) WebClient. JSON processing: Jackson.</dd><dt>**jvm-spring-restclient**</dt><dd>Platform: Java Virtual Machine. HTTP: Spring 6 RestClient. JSON processing: Jackson.</dd><dt>**jvm-retrofit2**</dt><dd>Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2.</dd><dt>**multiplatform**</dt><dd>Platform: Kotlin multiplatform. HTTP client: Ktor 1.6.7. JSON processing: Kotlinx Serialization: 1.2.1.</dd><dt>**jvm-volley**</dt><dd>Platform: JVM for Android. HTTP client: Volley 1.2.1. JSON processing: gson 2.8.9</dd><dt>**jvm-vertx**</dt><dd>Platform: Java Virtual Machine. HTTP client: Vert.x Web Client. JSON processing: Moshi, Gson or Jackson.</dd></dl>|jvm-okhttp4|
|
||||
|mapFileBinaryToByteArray|Map File and Binary to ByteArray (default: false)| |false|
|
||||
|modelMutable|Create mutable models| |false|
|
||||
|moshiCodeGen|Whether to enable codegen with the Moshi library. Refer to the [official Moshi doc](https://github.com/square/moshi#codegen) for more info.| |false|
|
||||
|nullableReturnType|Nullable return type| |false|
|
||||
|
||||
@@ -7,7 +7,7 @@ title: Documentation for the swift6 Generator
|
||||
| Property | Value | Notes |
|
||||
| -------- | ----- | ----- |
|
||||
| generator name | swift6 | pass this to the generate command after -g |
|
||||
| generator stability | EXPERIMENTAL | |
|
||||
| generator stability | BETA | |
|
||||
| generator type | CLIENT | |
|
||||
| generator language | Swift | |
|
||||
| generator default templating engine | mustache | |
|
||||
|
||||
@@ -22,7 +22,7 @@ npm install @openapitools/openapi-generator-cli -g
|
||||
To install a specific version of the tool, pass the version during installation:
|
||||
<!-- RELEASE_VERSION -->
|
||||
```bash
|
||||
openapi-generator-cli version-manager set 7.8.0
|
||||
openapi-generator-cli version-manager set 7.9.0
|
||||
```
|
||||
<!-- /RELEASE_VERSION -->
|
||||
To install the tool as a dev dependency in your current project:
|
||||
@@ -103,18 +103,18 @@ docker run --rm \
|
||||
<!-- RELEASE_VERSION -->
|
||||
If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 11 runtime at a minimum):
|
||||
|
||||
JAR location: `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.8.0/openapi-generator-cli-7.8.0.jar`
|
||||
JAR location: `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.9.0/openapi-generator-cli-7.9.0.jar`
|
||||
|
||||
For **Mac/Linux** users:
|
||||
|
||||
```bash
|
||||
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.8.0/openapi-generator-cli-7.8.0.jar -O openapi-generator-cli.jar
|
||||
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.9.0/openapi-generator-cli-7.9.0.jar -O openapi-generator-cli.jar
|
||||
```
|
||||
|
||||
For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.
|
||||
|
||||
```powershell
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.8.0/openapi-generator-cli-7.8.0.jar
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.9.0/openapi-generator-cli-7.9.0.jar
|
||||
```
|
||||
<!-- /RELEASE_VERSION -->
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ Add to your `build->plugins` section (default phase is `generate-sources` phase)
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>7.8.0</version>
|
||||
<version>7.9.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# RELEASE_VERSION
|
||||
openApiGeneratorVersion=7.9.0
|
||||
openApiGeneratorVersion=7.10.0-SNAPSHOT
|
||||
# /RELEASE_VERSION
|
||||
|
||||
# BEGIN placeholders
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# RELEASE_VERSION
|
||||
openApiGeneratorVersion=7.9.0
|
||||
openApiGeneratorVersion=7.10.0-SNAPSHOT
|
||||
# /RELEASE_VERSION
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.9.0</version>
|
||||
<version>7.10.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -3158,7 +3158,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
additionalPropertiesIsAnyType = true;
|
||||
}
|
||||
} else {
|
||||
// if additioanl properties is set (e.g. free form object, any type, string, etc)
|
||||
// if additional properties is set (e.g. free form object, any type, string, etc)
|
||||
addPropProp = fromProperty(getAdditionalPropertiesName(), (Schema) schema.getAdditionalProperties(), false);
|
||||
additionalPropertiesIsAnyType = true;
|
||||
}
|
||||
@@ -8444,6 +8444,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
List<CodegenProperty> xOf = new ArrayList<>();
|
||||
Set<String> dataTypeSet = new HashSet<>(); // to keep track of dataType
|
||||
Set<String> dataTypeSetIgnoringErasure = new HashSet<>();
|
||||
int i = 0;
|
||||
for (Schema xOfSchema : xOfCollection) {
|
||||
CodegenProperty cp = fromProperty(collectionName + "_" + i, xOfSchema, false);
|
||||
@@ -8452,7 +8453,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
if (dataTypeSet.contains(cp.dataType)
|
||||
|| (isTypeErasedGenerics() && dataTypeSet.contains(cp.baseType))) {
|
||||
// add "x-duplicated-data-type" to indicate if the dataType already occurs before
|
||||
// add "x-duplicated-data-type" to indicate if the (base) dataType already occurs before
|
||||
// in other sub-schemas of allOf/anyOf/oneOf
|
||||
cp.vendorExtensions.putIfAbsent("x-duplicated-data-type", true);
|
||||
} else {
|
||||
@@ -8462,6 +8463,13 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
dataTypeSet.add(cp.dataType);
|
||||
}
|
||||
}
|
||||
if (dataTypeSetIgnoringErasure.contains(cp.dataType)) {
|
||||
// add "x-duplicated-data-type-ignoring-erasure" to indicate if the dataType already occurs before
|
||||
// in other sub-schemas of allOf/anyOf/oneOf
|
||||
cp.vendorExtensions.putIfAbsent("x-duplicated-data-type-ignoring-erasure", true);
|
||||
} else {
|
||||
dataTypeSetIgnoringErasure.add(cp.dataType);
|
||||
}
|
||||
}
|
||||
return xOf;
|
||||
}
|
||||
|
||||
@@ -493,12 +493,64 @@ public class OpenAPINormalizer {
|
||||
}
|
||||
}
|
||||
|
||||
// auto fix self reference schema to avoid stack overflow
|
||||
fixSelfReferenceSchema(schemaName, schema);
|
||||
|
||||
// normalize the schemas
|
||||
schemas.put(schemaName, normalizeSchema(schema, new HashSet<>()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto fix a self referencing schema using any type to replace the self-referencing sub-item.
|
||||
*
|
||||
* @param name Schema name
|
||||
* @param schema Schema
|
||||
*/
|
||||
public void fixSelfReferenceSchema(String name, Schema schema) {
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
if (isSelfReference(name, schema.getItems())) {
|
||||
LOGGER.error("Array schema {} has a sub-item referencing itself. Worked around the self-reference schema using any type instead.", name);
|
||||
schema.setItems(new Schema<>());
|
||||
}
|
||||
}
|
||||
|
||||
if (ModelUtils.isOneOf(schema)) {
|
||||
for (int i = 0; i < schema.getOneOf().size(); i++) {
|
||||
if (isSelfReference(name, (Schema) schema.getOneOf().get(i))) {
|
||||
LOGGER.error("oneOf schema {} has a sub-item referencing itself. Worked around the self-reference schema by removing it.", name);
|
||||
schema.getOneOf().remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ModelUtils.isAnyOf(schema)) {
|
||||
for (int i = 0; i < schema.getAnyOf().size(); i++) {
|
||||
if (isSelfReference(name, (Schema) schema.getAnyOf().get(i))) {
|
||||
LOGGER.error("anyOf schema {} has a sub-item referencing itself. Worked around the self-reference schema by removing it.", name);
|
||||
schema.getAnyOf().remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (schema.getAdditionalProperties() != null && schema.getAdditionalProperties() instanceof Schema) {
|
||||
if (isSelfReference(name, (Schema) schema.getAdditionalProperties())) {
|
||||
LOGGER.error("Schema {} (with additional properties) has a sub-item referencing itself. Worked around the self-reference schema using any type instead.", name);
|
||||
schema.setAdditionalProperties(new Schema<>());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isSelfReference(String name, Schema subSchema) {
|
||||
if (subSchema != null && name.equals(ModelUtils.getSimpleRef(subSchema.get$ref()))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a schema
|
||||
*
|
||||
@@ -899,68 +951,7 @@ public class OpenAPINormalizer {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the schema is of type 'null' or schema itself is pointing to null
|
||||
* <p>
|
||||
* Return true if the schema's type is 'null' or not specified
|
||||
*
|
||||
* @param schema Schema
|
||||
* @param openAPI OpenAPI
|
||||
*
|
||||
* @return true if schema is null type
|
||||
*/
|
||||
public boolean isNullTypeSchema(OpenAPI openAPI, Schema schema) {
|
||||
if (schema == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// dereference the schema
|
||||
schema = ModelUtils.getReferencedSchema(openAPI, schema);
|
||||
|
||||
// allOf/anyOf/oneOf
|
||||
if (ModelUtils.hasAllOf(schema) || ModelUtils.hasOneOf(schema) || ModelUtils.hasAnyOf(schema)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// schema with properties
|
||||
if (schema.getProperties() != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// convert referenced enum of null only to `nullable:true`
|
||||
if (schema.getEnum() != null && schema.getEnum().size() == 1) {
|
||||
if ("null".equals(String.valueOf(schema.getEnum().get(0)))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (schema.getTypes() != null && !schema.getTypes().isEmpty()) {
|
||||
// 3.1 spec
|
||||
if (schema.getTypes().size() == 1) { // 1 type only
|
||||
String type = (String) schema.getTypes().iterator().next();
|
||||
return type == null || "null".equals(type);
|
||||
} else { // more than 1 type so must not be just null
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (schema instanceof JsonSchema) { // 3.1 spec
|
||||
if (Boolean.TRUE.equals(schema.getNullable())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// for `type: null`
|
||||
if (schema.getTypes() == null && schema.get$ref() == null) {
|
||||
return true;
|
||||
}
|
||||
} else { // 3.0.x or 2.x spec
|
||||
if ((schema.getType() == null || schema.getType().equals("null")) && schema.get$ref() == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the schema is oneOf and the sub-schemas is null, set `nullable: true`
|
||||
@@ -1004,7 +995,7 @@ public class OpenAPINormalizer {
|
||||
}
|
||||
}
|
||||
|
||||
if (oneOfSchemas.removeIf(oneOf -> isNullTypeSchema(openAPI, oneOf))) {
|
||||
if (oneOfSchemas.removeIf(oneOf -> ModelUtils.isNullTypeSchema(openAPI, oneOf))) {
|
||||
schema.setNullable(true);
|
||||
|
||||
// if only one element left, simplify to just the element (schema)
|
||||
@@ -1140,7 +1131,7 @@ public class OpenAPINormalizer {
|
||||
}
|
||||
}
|
||||
|
||||
if (anyOfSchemas.removeIf(anyOf -> isNullTypeSchema(openAPI, anyOf))) {
|
||||
if (anyOfSchemas.removeIf(anyOf -> ModelUtils.isNullTypeSchema(openAPI, anyOf))) {
|
||||
schema.setNullable(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -642,7 +642,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
convertPropertyToBooleanAndWriteBack(CONTAINER_DEFAULT_TO_NULL, this::setContainerDefaultToNull);
|
||||
|
||||
additionalProperties.put("sanitizeGeneric", (Mustache.Lambda) (fragment, writer) -> {
|
||||
String content = fragment.execute();
|
||||
String content = removeAnnotations(fragment.execute());
|
||||
for (final String s: List.of("<", ">", ",", " ")) {
|
||||
content = content.replace(s, "");
|
||||
}
|
||||
@@ -1493,7 +1493,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
MediaType mediaType = content.values().iterator().next();
|
||||
if (mediaType.getExample() != null) {
|
||||
if (isModel) {
|
||||
LOGGER.warn("Ignoring complex example on request body");
|
||||
once(LOGGER).warn("Ignoring complex example on request body");
|
||||
} else {
|
||||
codegenParameter.example = mediaType.getExample().toString();
|
||||
return;
|
||||
@@ -1504,7 +1504,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
Example example = mediaType.getExamples().values().iterator().next();
|
||||
if (example.getValue() != null) {
|
||||
if (isModel) {
|
||||
LOGGER.warn("Ignoring complex example on request body");
|
||||
once(LOGGER).warn("Ignoring complex example on request body");
|
||||
} else {
|
||||
codegenParameter.example = example.getValue().toString();
|
||||
return;
|
||||
@@ -1793,16 +1793,20 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return;
|
||||
}
|
||||
|
||||
// the response data types should not contains a bean validation annotation.
|
||||
// the response data types should not contain a bean validation annotation.
|
||||
if (property.dataType.contains("@")) {
|
||||
property.dataType = property.dataType.replaceAll("(?:(?i)@[a-z0-9]*+([(].*[)]|\\s*))*+", "");
|
||||
property.dataType = removeAnnotations(property.dataType);
|
||||
}
|
||||
// the response data types should not contains a bean validation annotation.
|
||||
// the response data types should not contain a bean validation annotation.
|
||||
if (response.dataType.contains("@")) {
|
||||
response.dataType = response.dataType.replaceAll("(?:(?i)@[a-z0-9]*+([(].*[)]|\\s*))*+", "");
|
||||
response.dataType = removeAnnotations(response.dataType);
|
||||
}
|
||||
}
|
||||
|
||||
private String removeAnnotations(String type) {
|
||||
return type.replaceAll("(?:(?i)@[a-z0-9]*+([(].*[)]|\\s*))*+", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelsMap postProcessModels(ModelsMap objs) {
|
||||
// recursively add import for mapping one type to multiple imports
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.CodegenResponse;
|
||||
import org.openapitools.codegen.DefaultCodegen;
|
||||
import org.openapitools.codegen.GeneratorLanguage;
|
||||
import org.openapitools.codegen.IJsonSchemaValidationProperties;
|
||||
@@ -1264,6 +1265,23 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
|
||||
);
|
||||
}
|
||||
|
||||
// update typing import for operation responses type
|
||||
// only python-fastapi needs this at the moment
|
||||
if (this instanceof PythonFastAPIServerCodegen) {
|
||||
for (CodegenResponse response : operation.responses) {
|
||||
// Not interested in the result, only in the update of the imports
|
||||
getPydanticType(
|
||||
response.returnProperty,
|
||||
modelImports,
|
||||
exampleImports,
|
||||
postponedModelImports,
|
||||
postponedExampleImports,
|
||||
moduleImports,
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// add import for code samples
|
||||
// import models one by one
|
||||
if (!exampleImports.isEmpty()) {
|
||||
|
||||
@@ -255,7 +255,11 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
// VC++ reserved keywords
|
||||
"stdin",
|
||||
"stdout",
|
||||
"stderr")
|
||||
"stderr",
|
||||
|
||||
// gcc predefined macros
|
||||
"linux"
|
||||
)
|
||||
);
|
||||
|
||||
instantiationTypes.clear();
|
||||
|
||||
@@ -707,10 +707,8 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Optional<DataExtractSubstituteParameter> dataExtract = getDataExtractSubstituteParameter(
|
||||
dataExtractSubstituteParams, operationId);
|
||||
|
||||
// calculate order for this current request
|
||||
Integer requestOrder = calculateRequestOrder(operationGroupingOrder, requests.size());
|
||||
|
||||
requests.put(requestOrder, new HTTPRequest(
|
||||
// create requests
|
||||
requests.putIfAbsent(requests.size(), new HTTPRequest(
|
||||
operationId,
|
||||
method.toString().toLowerCase(Locale.ROOT),
|
||||
path,
|
||||
@@ -933,7 +931,7 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
existingHTTPRequestGroup.addRequests(requests);
|
||||
existingHTTPRequestGroup.addVariables(variables);
|
||||
} else {
|
||||
requestGroups.put(groupName, new HTTPRequestGroup(groupName, variables, requests));
|
||||
requestGroups.putIfAbsent(groupName, new HTTPRequestGroup(groupName, variables, requests));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1127,36 +1125,6 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate order for this current request
|
||||
*
|
||||
* @param operationGroupingOrder
|
||||
* @param requestsSize
|
||||
* @return request order
|
||||
*/
|
||||
private Integer calculateRequestOrder(OptionalInt operationGroupingOrder, int requestsSize) {
|
||||
int requestOrder;
|
||||
|
||||
if (operationGroupingOrder.isPresent()) {
|
||||
requestOrder = operationGroupingOrder.getAsInt() - 1;
|
||||
|
||||
} else {
|
||||
switch (requestsSize) {
|
||||
case 0:
|
||||
case 1:
|
||||
requestOrder = requestsSize;
|
||||
break;
|
||||
|
||||
default:
|
||||
requestOrder = (requestsSize - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return requestOrder;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
/**
|
||||
* Any variables not defined yet but used for subsequent data extraction must be
|
||||
|
||||
@@ -93,10 +93,13 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
|
||||
|
||||
public static final String SUPPORT_ANDROID_API_LEVEL_25_AND_BELLOW = "supportAndroidApiLevel25AndBelow";
|
||||
|
||||
public static final String MAP_FILE_BINARY_TO_BYTE_ARRAY = "mapFileBinaryToByteArray";
|
||||
|
||||
public static final String GENERATE_ONEOF_ANYOF_WRAPPERS = "generateOneOfAnyOfWrappers";
|
||||
|
||||
protected static final String VENDOR_EXTENSION_BASE_NAME_LITERAL = "x-base-name-literal";
|
||||
|
||||
|
||||
@Setter protected String dateLibrary = DateLibrary.JAVA8.value;
|
||||
@Setter protected String requestDateConverter = RequestDateConverter.TO_JSON.value;
|
||||
@Setter protected String collectionType = CollectionType.LIST.value;
|
||||
@@ -108,6 +111,7 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
|
||||
protected boolean generateRoomModels = false;
|
||||
@Setter protected String roomModelPackage = "";
|
||||
@Setter protected boolean omitGradleWrapper = false;
|
||||
@Setter protected boolean mapFileBinaryToByteArray = false;
|
||||
@Setter protected boolean generateOneOfAnyOfWrappers = true;
|
||||
@Getter @Setter protected boolean failOnUnknownProperties = false;
|
||||
|
||||
@@ -269,6 +273,8 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(SUPPORT_ANDROID_API_LEVEL_25_AND_BELLOW, "[WARNING] This flag will generate code that has a known security vulnerability. It uses `kotlin.io.createTempFile` instead of `java.nio.file.Files.createTempFile` in order to support Android API level 25 and bellow. For more info, please check the following links https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-23x4-m842-fmwf, https://github.com/OpenAPITools/openapi-generator/pull/9284"));
|
||||
|
||||
cliOptions.add(new CliOption(MAP_FILE_BINARY_TO_BYTE_ARRAY, "Map File and Binary to ByteArray (default: false)").defaultValue(Boolean.FALSE.toString()));
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(GENERATE_ONEOF_ANYOF_WRAPPERS, "Generate oneOf, anyOf schemas as wrappers."));
|
||||
|
||||
CliOption serializationLibraryOpt = new CliOption(CodegenConstants.SERIALIZATION_LIBRARY, SERIALIZATION_LIBRARY_DESC);
|
||||
@@ -437,6 +443,15 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
|
||||
additionalProperties.put(this.serializationLibrary.name(), true);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(MAP_FILE_BINARY_TO_BYTE_ARRAY)) {
|
||||
setMapFileBinaryToByteArray(convertPropertyToBooleanAndWriteBack(MAP_FILE_BINARY_TO_BYTE_ARRAY));
|
||||
}
|
||||
additionalProperties.put(MAP_FILE_BINARY_TO_BYTE_ARRAY, mapFileBinaryToByteArray);
|
||||
if (mapFileBinaryToByteArray) {
|
||||
typeMapping.put("file", "kotlin.ByteArray");
|
||||
typeMapping.put("binary", "kotlin.ByteArray");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_ONEOF_ANYOF_WRAPPERS)) {
|
||||
setGenerateOneOfAnyOfWrappers(Boolean.parseBoolean(additionalProperties.get(GENERATE_ONEOF_ANYOF_WRAPPERS).toString()));
|
||||
}
|
||||
|
||||
@@ -272,13 +272,13 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
if (library.equals(Constants.KTOR)) {
|
||||
if (isKtor()) {
|
||||
supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile"));
|
||||
}
|
||||
|
||||
String gradleBuildFile = "build.gradle";
|
||||
|
||||
if (isJavalin()) {
|
||||
if (isJavalin() || isKtor()) {
|
||||
gradleBuildFile = "build.gradle.kts";
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
|
||||
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
supportingFiles.add(new SupportingFile("gradle.properties", "", "gradle.properties"));
|
||||
|
||||
if (library.equals(Constants.KTOR)) {
|
||||
if (isKtor()) {
|
||||
supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.kt.mustache", packageFolder, "Configuration.kt"));
|
||||
|
||||
@@ -300,6 +300,11 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
|
||||
final String infrastructureFolder = (sourceFolder + File.separator + packageName + File.separator + "infrastructure").replace(".", File.separator);
|
||||
|
||||
supportingFiles.add(new SupportingFile("ApiKeyAuth.kt.mustache", infrastructureFolder, "ApiKeyAuth.kt"));
|
||||
|
||||
if (!getOmitGradleWrapper()) {
|
||||
supportingFiles.add(new SupportingFile("gradle-wrapper.properties", "gradle" + File.separator + "wrapper", "gradle-wrapper.properties"));
|
||||
}
|
||||
|
||||
} else if (isJavalin()) {
|
||||
supportingFiles.add(new SupportingFile("Main.kt.mustache", packageFolder, "Main.kt"));
|
||||
apiTemplateFiles.put("service.mustache", "Service.kt");
|
||||
@@ -412,4 +417,8 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
|
||||
private boolean isJavalin() {
|
||||
return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library);
|
||||
}
|
||||
|
||||
private boolean isKtor() {
|
||||
return Constants.KTOR.equals(library);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +219,8 @@ public class PythonFastAPIServerCodegen extends AbstractPythonCodegen {
|
||||
|
||||
@Override
|
||||
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
|
||||
super.postProcessOperationsWithModels(objs, allModels);
|
||||
|
||||
OperationMap operations = objs.getOperations();
|
||||
// Set will make sure that no duplicated items are used.
|
||||
Set<String> securityImports = new HashSet<>();
|
||||
|
||||
@@ -39,6 +39,10 @@ import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
public class ScalaCaskServerCodegen extends AbstractScalaCodegen implements CodegenConfig {
|
||||
public static final String PROJECT_NAME = "projectName";
|
||||
|
||||
// this is our opinionated json type - ujson.Value - which is a first-class
|
||||
// citizen of cask
|
||||
private static final String AdditionalPropertiesType = "Value";
|
||||
|
||||
private final Logger LOGGER = LoggerFactory.getLogger(ScalaCaskServerCodegen.class);
|
||||
|
||||
@Override
|
||||
@@ -115,6 +119,8 @@ public class ScalaCaskServerCodegen extends AbstractScalaCodegen implements Code
|
||||
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("long", "Long");
|
||||
typeMapping.put("AnyType", AdditionalPropertiesType);
|
||||
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "String");
|
||||
@@ -241,6 +247,7 @@ public class ScalaCaskServerCodegen extends AbstractScalaCodegen implements Code
|
||||
importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
|
||||
importMapping.put("LocalTime", "java.time.LocalTime");
|
||||
importMapping.put("Value", "ujson.Value");
|
||||
importMapping.put(AdditionalPropertiesType, "ujson.Value");
|
||||
}
|
||||
|
||||
static boolean consumesMimetype(CodegenOperation op, String mimetype) {
|
||||
@@ -614,7 +621,7 @@ public class ScalaCaskServerCodegen extends AbstractScalaCodegen implements Code
|
||||
if (p.getIsEnumOrRef()) {
|
||||
p.defaultValue = "null";
|
||||
} else {
|
||||
p.defaultValue = defaultValueNonOption(p);
|
||||
p.defaultValue = defaultValueNonOption(p, "null");
|
||||
}
|
||||
} else if (p.defaultValue.contains("Seq.empty")) {
|
||||
p.defaultValue = "Nil";
|
||||
@@ -767,6 +774,23 @@ public class ScalaCaskServerCodegen extends AbstractScalaCodegen implements Code
|
||||
return defaultValueNonOption(p, fallbackDefaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* the subtypes of IJsonSchemaValidationProperties have an 'isNumeric', but that's not a method on IJsonSchemaValidationProperties.
|
||||
*
|
||||
* This helper method tries to isolate that noisy logic in a safe way so we can ask 'is this IJsonSchemaValidationProperties numeric'?
|
||||
* @param p the property
|
||||
* @return true if the property is numeric
|
||||
*/
|
||||
private static boolean isNumeric(IJsonSchemaValidationProperties p) {
|
||||
if (p instanceof CodegenParameter) {
|
||||
return ((CodegenParameter)p).isNumeric;
|
||||
} else if (p instanceof CodegenProperty) {
|
||||
return ((CodegenProperty)p).isNumeric;
|
||||
} else {
|
||||
return p.getIsNumber() || p.getIsFloat() || p.getIsDecimal() || p.getIsDouble() || p.getIsInteger() || p.getIsLong() || p.getIsUnboundedInteger();
|
||||
}
|
||||
}
|
||||
|
||||
private static String defaultValueNonOption(IJsonSchemaValidationProperties p, String fallbackDefaultValue) {
|
||||
if (p.getIsArray()) {
|
||||
if (p.getUniqueItems()) {
|
||||
@@ -777,7 +801,7 @@ public class ScalaCaskServerCodegen extends AbstractScalaCodegen implements Code
|
||||
if (p.getIsMap()) {
|
||||
return "Map.empty";
|
||||
}
|
||||
if (p.getIsNumber()) {
|
||||
if (isNumeric(p)) {
|
||||
return "0";
|
||||
}
|
||||
if (p.getIsEnum()) {
|
||||
@@ -792,38 +816,13 @@ public class ScalaCaskServerCodegen extends AbstractScalaCodegen implements Code
|
||||
if (p.getIsString()) {
|
||||
return "\"\"";
|
||||
}
|
||||
return fallbackDefaultValue;
|
||||
}
|
||||
if (fallbackDefaultValue != null && !fallbackDefaultValue.trim().isEmpty()) {
|
||||
return fallbackDefaultValue;
|
||||
}
|
||||
|
||||
private static String defaultValueNonOption(CodegenProperty p) {
|
||||
if (p.getIsArray()) {
|
||||
return "Nil";
|
||||
}
|
||||
if (p.getIsMap()) {
|
||||
return "Map.empty";
|
||||
}
|
||||
if (p.isNumber || p.isNumeric) {
|
||||
return "0";
|
||||
}
|
||||
if (p.isBoolean) {
|
||||
return "false";
|
||||
}
|
||||
if (p.isUuid) {
|
||||
return "java.util.UUID.randomUUID()";
|
||||
}
|
||||
if (p.isModel) {
|
||||
return "null";
|
||||
}
|
||||
if (p.isDate || p.isDateTime) {
|
||||
return "null";
|
||||
}
|
||||
if (p.isString) {
|
||||
return "\"\"";
|
||||
}
|
||||
return p.defaultValue;
|
||||
return "null";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenProperty fromProperty(String name, Schema schema) {
|
||||
CodegenProperty property = super.fromProperty(name, schema);
|
||||
@@ -847,9 +846,9 @@ public class ScalaCaskServerCodegen extends AbstractScalaCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
final String result = super.toModelImport(name);
|
||||
String result = super.toModelImport(name);
|
||||
if (importMapping.containsKey(name)) {
|
||||
return importMapping.get(name);
|
||||
result = importMapping.get(name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -366,7 +366,6 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
codegenModel.vars = codegenProperties;
|
||||
}
|
||||
|
||||
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
@@ -847,7 +846,6 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
operationId = camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
|
||||
return operationId;
|
||||
}
|
||||
|
||||
@@ -1305,6 +1303,13 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
System.out.println("# #");
|
||||
System.out.println("# swift5 generator is contributed by Bruno Coelho (https://github.com/4brunu). #");
|
||||
System.out.println("# Please support his work directly via https://paypal.com/paypalme/4brunu \uD83D\uDE4F #");
|
||||
System.out.println("# #");
|
||||
System.out.println("# There is a new swift6 generator, that is currently in beta. #");
|
||||
System.out.println("# Try it and give us your feedback. #");
|
||||
System.out.println("# https://openapi-generator.tech/docs/generators/swift6 #");
|
||||
System.out.println("# #");
|
||||
System.out.println("# If you need help migrating from the swift5 to the swift6 generator, check the following url.#");
|
||||
System.out.println("# https://openapi-generator.tech/docs/faq-generators/#how-do-i-migrate-from-the-swift-5-generator-to-the-swift-6-generator");
|
||||
System.out.println("################################################################################");
|
||||
}
|
||||
|
||||
|
||||
@@ -86,45 +86,25 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
protected static final String RESPONSE_LIBRARY_ASYNC_AWAIT = "AsyncAwait";
|
||||
protected static final String RESPONSE_LIBRARY_OBJC_BLOCK = "ObjcBlock";
|
||||
protected static final String[] RESPONSE_LIBRARIES = { RESPONSE_LIBRARY_ASYNC_AWAIT, RESPONSE_LIBRARY_COMBINE, RESPONSE_LIBRARY_RESULT, RESPONSE_LIBRARY_RX_SWIFT, RESPONSE_LIBRARY_OBJC_BLOCK, RESPONSE_LIBRARY_PROMISE_KIT };
|
||||
@Setter
|
||||
protected String projectName = "OpenAPIClient";
|
||||
@Setter
|
||||
protected boolean nonPublicApi = false;
|
||||
@Setter
|
||||
protected boolean objcCompatible = false;
|
||||
@Setter
|
||||
protected boolean readonlyProperties = false;
|
||||
@Setter
|
||||
protected boolean swiftUseApiNamespace = false;
|
||||
@Setter
|
||||
protected boolean useSPMFileStructure = true;
|
||||
@Setter
|
||||
protected String swiftPackagePath = "Sources" + File.separator + projectName;
|
||||
@Setter
|
||||
protected boolean oneOfUnknownDefaultCase = false;
|
||||
@Setter
|
||||
protected boolean useClasses = false;
|
||||
@Setter
|
||||
protected boolean useBacktickEscapes = false;
|
||||
@Setter
|
||||
protected boolean generateModelAdditionalProperties = true;
|
||||
@Setter
|
||||
protected boolean hashableModels = true;
|
||||
@Setter
|
||||
protected boolean useJsonEncodable = true;
|
||||
@Getter
|
||||
@Setter
|
||||
protected boolean mapFileBinaryToData = false;
|
||||
@Setter
|
||||
protected boolean useCustomDateWithoutTime = false;
|
||||
@Setter
|
||||
protected boolean validatable = true;
|
||||
@Setter
|
||||
protected boolean apiStaticMethod = true;
|
||||
@Setter
|
||||
protected boolean combineDeferred = true;
|
||||
@Setter
|
||||
protected String[] responseAs = { RESPONSE_LIBRARY_ASYNC_AWAIT };
|
||||
@Setter protected String projectName = "OpenAPIClient";
|
||||
@Setter protected boolean nonPublicApi = false;
|
||||
@Setter protected boolean objcCompatible = false;
|
||||
@Setter protected boolean readonlyProperties = false;
|
||||
@Setter protected boolean swiftUseApiNamespace = false;
|
||||
@Setter protected boolean useSPMFileStructure = true;
|
||||
@Setter protected String swiftPackagePath = "Sources" + File.separator + projectName;
|
||||
@Setter protected boolean oneOfUnknownDefaultCase = false;
|
||||
@Setter protected boolean useClasses = false;
|
||||
@Setter protected boolean useBacktickEscapes = false;
|
||||
@Setter protected boolean generateModelAdditionalProperties = true;
|
||||
@Setter protected boolean hashableModels = true;
|
||||
@Setter protected boolean useJsonEncodable = true;
|
||||
@Getter @Setter protected boolean mapFileBinaryToData = false;
|
||||
@Setter protected boolean useCustomDateWithoutTime = false;
|
||||
@Setter protected boolean validatable = true;
|
||||
@Setter protected boolean apiStaticMethod = true;
|
||||
@Setter protected boolean combineDeferred = true;
|
||||
@Setter protected String[] responseAs = { RESPONSE_LIBRARY_ASYNC_AWAIT };
|
||||
protected String sourceFolder = swiftPackagePath;
|
||||
protected HashSet objcReservedWords;
|
||||
protected String apiDocPath = "docs/";
|
||||
@@ -138,7 +118,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
this.useOneOfInterfaces = true;
|
||||
|
||||
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
|
||||
.stability(Stability.EXPERIMENTAL)
|
||||
.stability(Stability.BETA)
|
||||
.build();
|
||||
|
||||
outputFolder = "generated-code" + File.separator + "swift";
|
||||
@@ -184,19 +164,20 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"Empty",
|
||||
"AnyObject",
|
||||
"Any",
|
||||
"Decimal"));
|
||||
"Decimal")
|
||||
);
|
||||
|
||||
objcReservedWords = new HashSet<>(
|
||||
Arrays.asList(
|
||||
// Added for Objective-C compatibility
|
||||
"id", "description", "NSArray", "NSURL", "CGFloat", "NSSet", "NSString", "NSInteger",
|
||||
"NSUInteger",
|
||||
"id", "description", "NSArray", "NSURL", "CGFloat", "NSSet", "NSString", "NSInteger", "NSUInteger",
|
||||
"NSError", "NSDictionary",
|
||||
// 'Property 'hash' with type 'String' cannot override a property with type
|
||||
// 'Int' (when objcCompatible=true)
|
||||
// 'Property 'hash' with type 'String' cannot override a property with type 'Int' (when objcCompatible=true)
|
||||
"hash",
|
||||
// Cannot override with a stored property 'className'
|
||||
"className"));
|
||||
"className"
|
||||
)
|
||||
);
|
||||
|
||||
reservedWords = new HashSet<>(
|
||||
Arrays.asList(
|
||||
@@ -207,29 +188,22 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
// https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/doc/uid/TP40014097-CH30-ID410
|
||||
//
|
||||
// Keywords used in declarations
|
||||
"associatedtype", "class", "deinit", "enum", "extension", "fileprivate", "func", "import",
|
||||
"init",
|
||||
"inout", "internal", "let", "open", "operator", "private", "protocol", "public", "static",
|
||||
"struct",
|
||||
"associatedtype", "class", "deinit", "enum", "extension", "fileprivate", "func", "import", "init",
|
||||
"inout", "internal", "let", "open", "operator", "private", "protocol", "public", "static", "struct",
|
||||
"subscript", "typealias", "var",
|
||||
// Keywords uses in statements
|
||||
"break", "case", "continue", "default", "defer", "do", "else", "fallthrough", "for", "guard",
|
||||
"if",
|
||||
"break", "case", "continue", "default", "defer", "do", "else", "fallthrough", "for", "guard", "if",
|
||||
"in", "repeat", "return", "switch", "where", "while",
|
||||
// Keywords used in expressions and types
|
||||
"as", "Any", "catch", "false", "is", "nil", "rethrows", "super", "self", "Self", "throw",
|
||||
"throws", "true", "try",
|
||||
"as", "Any", "catch", "false", "is", "nil", "rethrows", "super", "self", "Self", "throw", "throws", "true", "try",
|
||||
// Keywords used in patterns
|
||||
"_",
|
||||
// Keywords that begin with a number sign
|
||||
"#available", "#colorLiteral", "#column", "#else", "#elseif", "#endif", "#file", "#fileLiteral",
|
||||
"#function", "#if",
|
||||
"#available", "#colorLiteral", "#column", "#else", "#elseif", "#endif", "#file", "#fileLiteral", "#function", "#if",
|
||||
"#imageLiteral", "#line", "#selector", "#sourceLocation",
|
||||
// Keywords reserved in particular contexts
|
||||
"associativity", "convenience", "dynamic", "didSet", "final", "get", "infix", "indirect",
|
||||
"lazy", "left",
|
||||
"mutating", "none", "nonmutating", "optional", "override", "postfix", "precedence", "prefix",
|
||||
"Protocol",
|
||||
"associativity", "convenience", "dynamic", "didSet", "final", "get", "infix", "indirect", "lazy", "left",
|
||||
"mutating", "none", "nonmutating", "optional", "override", "postfix", "precedence", "prefix", "Protocol",
|
||||
"required", "right", "set", "Type", "unowned", "weak", "willSet",
|
||||
|
||||
//
|
||||
@@ -239,8 +213,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
// Numbers and Basic Values
|
||||
"Bool", "Int", "Double", "Float", "Range", "ClosedRange", "Error", "Optional",
|
||||
// Special-Use Numeric Types
|
||||
"UInt", "UInt8", "UInt16", "UInt32", "UInt64", "Int8", "Int16", "Int32", "Int64", "Float80",
|
||||
"Float32", "Float64",
|
||||
"UInt", "UInt8", "UInt16", "UInt32", "UInt64", "Int8", "Int16", "Int32", "Int64", "Float80", "Float32", "Float64",
|
||||
// Strings and Text
|
||||
"String", "Character", "Unicode", "StaticString",
|
||||
// Collections
|
||||
@@ -250,7 +223,9 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"URL", "Data", "Codable", "Encodable", "Decodable",
|
||||
|
||||
// The following are other words we want to reserve
|
||||
"Void", "AnyObject", "Class", "dynamicType", "COLUMN", "FILE", "FUNCTION", "LINE"));
|
||||
"Void", "AnyObject", "Class", "dynamicType", "COLUMN", "FILE", "FUNCTION", "LINE"
|
||||
)
|
||||
);
|
||||
|
||||
typeMapping = new HashMap<>();
|
||||
typeMapping.put("array", "Array");
|
||||
@@ -368,7 +343,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
private static CodegenModel reconcileProperties(CodegenModel codegenModel,
|
||||
CodegenModel parentCodegenModel) {
|
||||
CodegenModel parentCodegenModel) {
|
||||
// To support inheritance in this generator, we will analyze
|
||||
// the parent and child models, look for properties that match, and remove
|
||||
// them from the child models and leave them in the parent.
|
||||
@@ -423,7 +398,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel,
|
||||
Schema schema) {
|
||||
Schema schema) {
|
||||
|
||||
final Schema additionalProperties = ModelUtils.getAdditionalProperties(schema);
|
||||
|
||||
@@ -435,8 +410,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
inner = ModelUtils.getAdditionalProperties(schema);
|
||||
}
|
||||
|
||||
codegenModel.additionalPropertiesType = inner != null ? getTypeDeclaration(inner)
|
||||
: getSchemaType(additionalProperties);
|
||||
codegenModel.additionalPropertiesType = inner != null ? getTypeDeclaration(inner) : getSchemaType(additionalProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,10 +419,8 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("SWIFT_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info(
|
||||
"Environment variable SWIFT_POST_PROCESS_FILE not defined so the Swift code may not be properly formatted. To define it, try 'export SWIFT_POST_PROCESS_FILE=/usr/local/bin/swiftformat' (Linux/Mac)");
|
||||
LOGGER.info(
|
||||
"NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).");
|
||||
LOGGER.info("Environment variable SWIFT_POST_PROCESS_FILE not defined so the Swift code may not be properly formatted. To define it, try 'export SWIFT_POST_PROCESS_FILE=/usr/local/bin/swiftformat' (Linux/Mac)");
|
||||
LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).");
|
||||
} else if (!this.isEnablePostProcessFile()) {
|
||||
LOGGER.info("Warning: Environment variable 'SWIFT_POST_PROCESS_FILE' is set but file post-processing is not enabled. To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).");
|
||||
}
|
||||
@@ -536,8 +508,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
sourceFolder = projectName + File.separator + "Classes" + File.separator + "OpenAPIs";
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SWIFT_PACKAGE_PATH)
|
||||
&& ((String) additionalProperties.get(SWIFT_PACKAGE_PATH)).length() > 0) {
|
||||
if (additionalProperties.containsKey(SWIFT_PACKAGE_PATH) && ((String) additionalProperties.get(SWIFT_PACKAGE_PATH)).length() > 0) {
|
||||
setSwiftPackagePath((String) additionalProperties.get(SWIFT_PACKAGE_PATH));
|
||||
sourceFolder = swiftPackagePath;
|
||||
}
|
||||
@@ -547,8 +518,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_MODEL_ADDITIONAL_PROPERTIES)) {
|
||||
setGenerateModelAdditionalProperties(
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_MODEL_ADDITIONAL_PROPERTIES));
|
||||
setGenerateModelAdditionalProperties(convertPropertyToBooleanAndWriteBack(GENERATE_MODEL_ADDITIONAL_PROPERTIES));
|
||||
}
|
||||
additionalProperties.put(GENERATE_MODEL_ADDITIONAL_PROPERTIES, generateModelAdditionalProperties);
|
||||
|
||||
@@ -704,7 +674,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
protected boolean isReservedWord(String word) {
|
||||
return word != null && reservedWords.contains(word); // don't lowercase as super does
|
||||
return word != null && reservedWords.contains(word); //don't lowercase as super does
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -731,8 +701,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
Schema inner = ModelUtils.getSchemaItems(p);
|
||||
return ModelUtils.isSet(p) ? "Set<" + getTypeDeclaration(inner) + ">"
|
||||
: "[" + getTypeDeclaration(inner) + "]";
|
||||
return ModelUtils.isSet(p) ? "Set<" + getTypeDeclaration(inner) + ">" : "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "[String: " + getTypeDeclaration(inner) + "]";
|
||||
@@ -835,13 +804,10 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
|
||||
return p.getDefault().toString();
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
// Datetime time stamps in Swift are expressed as Seconds with Microsecond
|
||||
// precision.
|
||||
// In Java, we need to be creative to get the Timestamp in Microseconds as a
|
||||
// long.
|
||||
// Datetime time stamps in Swift are expressed as Seconds with Microsecond precision.
|
||||
// In Java, we need to be creative to get the Timestamp in Microseconds as a long.
|
||||
Instant instant = ((OffsetDateTime) p.getDefault()).toInstant();
|
||||
long epochMicro = TimeUnit.SECONDS.toMicros(instant.getEpochSecond())
|
||||
+ (instant.get(ChronoField.MICRO_OF_SECOND));
|
||||
long epochMicro = TimeUnit.SECONDS.toMicros(instant.getEpochSecond()) + (instant.get(ChronoField.MICRO_OF_SECOND));
|
||||
return "Date(timeIntervalSince1970: " + epochMicro + ".0 / 1_000_000)";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
return "\"" + escapeText(String.valueOf(p.getDefault())) + "\"";
|
||||
@@ -909,8 +875,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId,
|
||||
camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER));
|
||||
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER));
|
||||
operationId = camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
@@ -1055,8 +1020,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
// for symbol, e.g. $, #
|
||||
if (getSymbolName(name) != null) {
|
||||
return camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase(Locale.ROOT)),
|
||||
LOWERCASE_FIRST_LETTER);
|
||||
return camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase(Locale.ROOT)), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
// Camelize only when we have a structure defined below
|
||||
@@ -1079,9 +1043,9 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return replaceSpecialCharacters(name);
|
||||
}
|
||||
|
||||
char[] separators = { '-', '_', ' ', ':', '(', ')' };
|
||||
char[] separators = {'-', '_', ' ', ':', '(', ')'};
|
||||
return camelize(replaceSpecialCharacters(WordUtils.capitalizeFully(StringUtils.lowerCase(name), separators)
|
||||
.replaceAll("[-_ :\\(\\)]", "")),
|
||||
.replaceAll("[-_ :\\(\\)]", "")),
|
||||
LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
@@ -1169,8 +1133,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
//
|
||||
// CodegenProperty.vendorExtensions["x-codegen-escaped-property-name"] = true
|
||||
//
|
||||
// Also, if any property in the model has x-codegen-escaped-property-name=true,
|
||||
// then we mark:
|
||||
// Also, if any property in the model has x-codegen-escaped-property-name=true, then we mark:
|
||||
//
|
||||
// CodegenModel.vendorExtensions["x-codegen-has-escaped-property-names"] = true
|
||||
//
|
||||
@@ -1188,8 +1151,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
if (prop.defaultValue == null || prop.defaultValue.equals("null")) {
|
||||
prop.vendorExtensions.put("x-null-encodable-default-value", ".encodeNull");
|
||||
} else {
|
||||
prop.vendorExtensions.put("x-null-encodable-default-value",
|
||||
".encodeValue(" + prop.defaultValue + ")");
|
||||
prop.vendorExtensions.put("x-null-encodable-default-value", ".encodeValue(" + prop.defaultValue + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1259,8 +1221,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return objs;
|
||||
}
|
||||
|
||||
public String constructExampleCode(CodegenParameter codegenParameter, HashMap<String, CodegenModel> modelMaps,
|
||||
Set<String> visitedModels) {
|
||||
public String constructExampleCode(CodegenParameter codegenParameter, HashMap<String, CodegenModel> modelMaps, Set<String> visitedModels) {
|
||||
if (codegenParameter.isArray) { // array
|
||||
return "[" + constructExampleCode(codegenParameter.items, modelMaps, visitedModels) + "]";
|
||||
} else if (codegenParameter.isMap) { // TODO: map, file type
|
||||
@@ -1302,15 +1263,13 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return constructExampleCode(modelMaps.get(codegenParameter.dataType), modelMaps, visitedModels);
|
||||
}
|
||||
} else {
|
||||
// LOGGER.error("Error in constructing examples. Failed to look up the model " +
|
||||
// codegenParameter.dataType);
|
||||
//LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenParameter.dataType);
|
||||
return "TODO";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String constructExampleCode(CodegenProperty codegenProperty, HashMap<String, CodegenModel> modelMaps,
|
||||
Set<String> visitedModels) {
|
||||
public String constructExampleCode(CodegenProperty codegenProperty, HashMap<String, CodegenModel> modelMaps, Set<String> visitedModels) {
|
||||
if (codegenProperty.isArray) { // array
|
||||
return "[" + constructExampleCode(codegenProperty.items, modelMaps, visitedModels) + "]";
|
||||
} else if (codegenProperty.isMap) { // TODO: map, file type
|
||||
@@ -1350,21 +1309,18 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return constructExampleCode(modelMaps.get(codegenProperty.dataType), modelMaps, visitedModels);
|
||||
}
|
||||
} else {
|
||||
// LOGGER.error("Error in constructing examples. Failed to look up the model " +
|
||||
// codegenProperty.dataType);
|
||||
//LOGGER.error("Error in constructing examples. Failed to look up the model " + codegenProperty.dataType);
|
||||
return "\"TODO\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String constructExampleCode(CodegenModel codegenModel, HashMap<String, CodegenModel> modelMaps,
|
||||
Set<String> visitedModels) {
|
||||
public String constructExampleCode(CodegenModel codegenModel, HashMap<String, CodegenModel> modelMaps, Set<String> visitedModels) {
|
||||
String example;
|
||||
example = codegenModel.name + "(";
|
||||
List<String> propertyExamples = new ArrayList<>();
|
||||
for (CodegenProperty codegenProperty : codegenModel.vars) {
|
||||
propertyExamples
|
||||
.add(codegenProperty.name + ": " + constructExampleCode(codegenProperty, modelMaps, visitedModels));
|
||||
propertyExamples.add(codegenProperty.name + ": " + constructExampleCode(codegenProperty, modelMaps, visitedModels));
|
||||
}
|
||||
example += StringUtils.join(propertyExamples, ", ");
|
||||
example += ")";
|
||||
@@ -1375,13 +1331,14 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public void postProcess() {
|
||||
System.out.println("################################################################################");
|
||||
System.out.println("# Thanks for using OpenAPI Generator. #");
|
||||
System.out
|
||||
.println("# Please consider donation to help us maintain this project \uD83D\uDE4F #");
|
||||
System.out.println("# Please consider donation to help us maintain this project \uD83D\uDE4F #");
|
||||
System.out.println("# https://opencollective.com/openapi_generator/donate #");
|
||||
System.out.println("# #");
|
||||
System.out.println("# swift6 generator is contributed by Bruno Coelho (https://github.com/4brunu). #");
|
||||
System.out
|
||||
.println("# Please support his work directly via https://paypal.com/paypalme/4brunu \uD83D\uDE4F #");
|
||||
System.out.println("# Please support his work directly via https://paypal.com/paypalme/4brunu \uD83D\uDE4F #");
|
||||
System.out.println("# #");
|
||||
System.out.println("# If you need help migrating from the swift5 to the swift6 generator, check the following url.#");
|
||||
System.out.println("# https://openapi-generator.tech/docs/faq-generators/#how-do-i-migrate-from-the-swift-5-generator-to-the-swift-6-generator");
|
||||
System.out.println("################################################################################");
|
||||
}
|
||||
|
||||
|
||||
@@ -2199,6 +2199,69 @@ public class ModelUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the schema is of type 'null' or schema itself is pointing to null
|
||||
* <p>
|
||||
* Return true if the schema's type is 'null' or not specified
|
||||
*
|
||||
* @param schema Schema
|
||||
* @param openAPI OpenAPI
|
||||
*
|
||||
* @return true if schema is null type
|
||||
*/
|
||||
public static boolean isNullTypeSchema(OpenAPI openAPI, Schema schema) {
|
||||
if (schema == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// dereference the schema
|
||||
schema = ModelUtils.getReferencedSchema(openAPI, schema);
|
||||
|
||||
// allOf/anyOf/oneOf
|
||||
if (ModelUtils.hasAllOf(schema) || ModelUtils.hasOneOf(schema) || ModelUtils.hasAnyOf(schema)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// schema with properties
|
||||
if (schema.getProperties() != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// convert referenced enum of null only to `nullable:true`
|
||||
if (schema.getEnum() != null && schema.getEnum().size() == 1) {
|
||||
if ("null".equals(String.valueOf(schema.getEnum().get(0)))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (schema.getTypes() != null && !schema.getTypes().isEmpty()) {
|
||||
// 3.1 spec
|
||||
if (schema.getTypes().size() == 1) { // 1 type only
|
||||
String type = (String) schema.getTypes().iterator().next();
|
||||
return type == null || "null".equals(type);
|
||||
} else { // more than 1 type so must not be just null
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (schema instanceof JsonSchema) { // 3.1 spec
|
||||
if (Boolean.TRUE.equals(schema.getNullable())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// for `type: null`
|
||||
if (schema.getTypes() == null && schema.get$ref() == null) {
|
||||
return true;
|
||||
}
|
||||
} else { // 3.0.x or 2.x spec
|
||||
if ((schema.getType() == null || schema.getType().equals("null")) && schema.get$ref() == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface OpenAPISchemaVisitor {
|
||||
|
||||
|
||||
@@ -17,4 +17,4 @@ isInteger set
|
||||
isLong set
|
||||
}}{{#isLong}}{{#minimum}} @Min({{.}}L){{/minimum}}{{#maximum}} @Max({{.}}L){{/maximum}}{{/isLong}}{{!
|
||||
Not Integer, not Long => we have a decimal value!
|
||||
}}{{^isInteger}}{{^isLong}}{{#minimum}} @DecimalMin({{#exclusiveMinimum}}value={{/exclusiveMinimum}}"{{minimum}}"{{#exclusiveMinimum}},inclusive=false{{/exclusiveMinimum}}){{/minimum}}{{#maximum}} @DecimalMax({{#exclusiveMaximum}}value={{/exclusiveMaximum}}"{{maximum}}"{{#exclusiveMaximum}},inclusive=false{{/exclusiveMaximum}}){{/maximum}}{{/isLong}}{{/isInteger}}
|
||||
}}{{^isInteger}}{{^isLong}}{{#minimum}} @DecimalMin({{#exclusiveMinimum}}value={{/exclusiveMinimum}}"{{minimum}}"{{#exclusiveMinimum}},inclusive=false{{/exclusiveMinimum}}){{/minimum}}{{#maximum}} @DecimalMax({{#exclusiveMaximum}}value={{/exclusiveMaximum}}"{{maximum}}"{{#exclusiveMaximum}},inclusive=false{{/exclusiveMaximum}}){{/maximum}}{{/isLong}}{{/isInteger}}
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -11,4 +11,4 @@
|
||||
{{#isContainer}}
|
||||
@JacksonXmlElementWrapper({{#isXmlWrapped}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}", {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}{{/isXmlWrapped}}useWrapping = {{isXmlWrapped}})
|
||||
{{/isContainer}}
|
||||
{{/withXml}}
|
||||
{{/withXml}}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
public static class Builder {{#parentModel}}extends {{classname}}.Builder {{/parentModel}}{
|
||||
public static class Builder {{#parentModel}}extends {{classname}}.Builder {{/parentModel}}{
|
||||
|
||||
private {{classname}} instance;
|
||||
|
||||
|
||||
@@ -20,7 +20,12 @@
|
||||
{{/hasDiscriminatorWithNonEmptyMapping}}
|
||||
{{/isClassnameSanitized}}
|
||||
{{/jackson}}
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{>generatedAnnotation}}
|
||||
{{#discriminator}}
|
||||
{{>typeInfoAnnotation}}
|
||||
{{/discriminator}}
|
||||
{{>xmlAnnotation}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
@@ -39,6 +44,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{>modelInnerEnum}}
|
||||
{{/mostInnerItems}}
|
||||
{{/isContainer}}
|
||||
|
||||
{{/isEnum}}
|
||||
{{#gson}}
|
||||
public static final String SERIALIZED_NAME_{{nameInSnakeCase}} = "{{baseName}}";
|
||||
@@ -72,6 +78,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{/isContainer}}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{>nullable_var_annotations}}
|
||||
|
||||
{{#isContainer}}
|
||||
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/isContainer}}
|
||||
@@ -113,7 +121,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#vars}}
|
||||
|
||||
{{^isReadOnly}}
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
public {{classname}} {{name}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}this.{{name}} = {{name}};{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
return this;
|
||||
@@ -189,17 +197,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#required}}
|
||||
{{#isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nonnull
|
||||
{{/isNullable}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/required}}
|
||||
{{>nullable_var_annotations}}
|
||||
|
||||
{{#jsonb}}
|
||||
@JsonbProperty("{{baseName}}")
|
||||
{{/jsonb}}
|
||||
@@ -246,7 +245,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
|
||||
{{^isReadOnly}}
|
||||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
|
||||
@@ -68,10 +68,23 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
return ret;
|
||||
}
|
||||
{{/discriminator}}
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
// deserialize {{{.}}}
|
||||
// deserialize {{{dataType}}}{{#isNullable}} (nullable){{/isNullable}}
|
||||
try {
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{.}}}.class);
|
||||
{{^isArray}}
|
||||
{{^isMap}}
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{dataType}}}.class);
|
||||
{{/isMap}}
|
||||
{{/isArray}}
|
||||
{{#isArray}}
|
||||
final TypeReference<{{{dataType}}}> ref = new TypeReference<{{{dataType}}}>(){};
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs(ref);
|
||||
{{/isArray}}
|
||||
{{#isMap}}
|
||||
final TypeReference<{{{dataType}}}> ref = new TypeReference<{{{dataType}}}>(){};
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs(ref);
|
||||
{{/isMap}}
|
||||
{{classname}} ret = new {{classname}}();
|
||||
ret.setActualInstance(deserialized);
|
||||
return ret;
|
||||
@@ -81,6 +94,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
}
|
||||
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
throw new IOException(String.format("Failed deserialization for {{classname}}: no match found"));
|
||||
}
|
||||
|
||||
@@ -119,13 +133,17 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties);
|
||||
}
|
||||
{{/additionalPropertiesType}}
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
public {{classname}}({{{.}}} o) {
|
||||
{{^vendorExtensions.x-duplicated-data-type}}
|
||||
public {{classname}}({{{baseType}}} o) {
|
||||
super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
|
||||
setActualInstance(o);
|
||||
}
|
||||
|
||||
{{/vendorExtensions.x-duplicated-data-type}}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
static {
|
||||
{{#anyOf}}
|
||||
schemas.put("{{{.}}}", new GenericType<{{{.}}}>() {
|
||||
@@ -165,13 +183,17 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
}
|
||||
|
||||
{{/isNullable}}
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
if (JSON.isInstanceOf({{{.}}}.class, instance, new HashSet<>())) {
|
||||
{{^vendorExtensions.x-duplicated-data-type}}
|
||||
if (JSON.isInstanceOf({{{baseType}}}.class, instance, new HashSet<>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
{{/vendorExtensions.x-duplicated-data-type}}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
throw new RuntimeException("Invalid instance type. Must be {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}");
|
||||
}
|
||||
|
||||
@@ -186,17 +208,21 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
return super.getActualInstance();
|
||||
}
|
||||
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
{{^vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
/**
|
||||
* Get the actual instance of `{{{.}}}`. If the actual instance is not `{{{.}}}`,
|
||||
* Get the actual instance of `{{{dataType}}}`. If the actual instance is not `{{{dataType}}}`,
|
||||
* the ClassCastException will be thrown.
|
||||
*
|
||||
* @return The actual instance of `{{{.}}}`
|
||||
* @throws ClassCastException if the instance is not `{{{.}}}`
|
||||
* @return The actual instance of `{{{dataType}}}`
|
||||
* @throws ClassCastException if the instance is not `{{{dataType}}}`
|
||||
*/
|
||||
public {{{.}}} get{{{.}}}() throws ClassCastException {
|
||||
return ({{{.}}})super.getActualInstance();
|
||||
public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException {
|
||||
return ({{{dataType}}})super.getActualInstance();
|
||||
}
|
||||
|
||||
{{/vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,13 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
if (attemptParsing) {
|
||||
{{#isMap}}
|
||||
final TypeReference<{{{dataType}}}> ref = new TypeReference<{{{dataType}}}>(){};
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs(ref);
|
||||
{{/isMap}}
|
||||
{{^isMap}}
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{dataType}}}.class);
|
||||
{{/isMap}}
|
||||
// TODO: there is no validation against JSON schema constraints
|
||||
// (min, max, enum, pattern...), this does not perform a strict JSON
|
||||
// validation, which means the 'match' count may be higher than it should be.
|
||||
@@ -266,6 +272,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
{{^vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
/**
|
||||
* Get the actual instance of `{{{dataType}}}`. If the actual instance is not `{{{dataType}}}`,
|
||||
* the ClassCastException will be thrown.
|
||||
@@ -273,17 +280,11 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
* @return The actual instance of `{{{dataType}}}`
|
||||
* @throws ClassCastException if the instance is not `{{{dataType}}}`
|
||||
*/
|
||||
{{^isArray}}
|
||||
public {{{dataType}}} get{{{dataType}}}() throws ClassCastException {
|
||||
public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException {
|
||||
return ({{{dataType}}})super.getActualInstance();
|
||||
}
|
||||
{{/isArray}}
|
||||
{{#isArray}}
|
||||
public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException {
|
||||
return ({{{dataType}}})super.getActualInstance();
|
||||
}
|
||||
{{/isArray}}
|
||||
|
||||
{{/vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,12 @@
|
||||
@JsonTypeName("{{name}}")
|
||||
{{/isClassnameSanitized}}
|
||||
{{/jackson}}
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{>generatedAnnotation}}
|
||||
{{#discriminator}}
|
||||
{{>typeInfoAnnotation}}
|
||||
{{/discriminator}}
|
||||
{{>xmlAnnotation}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
@@ -81,6 +86,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{>nullable_var_annotations}}
|
||||
|
||||
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
|
||||
@@ -113,7 +120,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
public {{classname}} {{name}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-enum-as-string}}
|
||||
if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) {
|
||||
throw new IllegalArgumentException({{name}} + " is invalid. Possible values for {{name}}: " + String.join(", ", {{{nameInSnakeCase}}}_VALUES));
|
||||
@@ -197,17 +204,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#required}}
|
||||
{{#isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nonnull
|
||||
{{/isNullable}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/required}}
|
||||
{{>nullable_var_annotations}}
|
||||
|
||||
{{#useBeanValidation}}
|
||||
{{>beanValidation}}
|
||||
{{/useBeanValidation}}
|
||||
@@ -244,7 +242,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
public JsonNullable<{{{datatypeWithEnum}}}> {{getter}}_JsonNullable() {
|
||||
return {{name}};
|
||||
}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}})
|
||||
{{#isReadOnly}}private{{/isReadOnly}}{{^isReadOnly}}public{{/isReadOnly}} void {{setter}}_JsonNullable(JsonNullable<{{{datatypeWithEnum}}}> {{name}}) {
|
||||
{{! For getters/setters that have name differing from attribute name, we must include setter (albeit private) for jackson to be able to set the attribute}}
|
||||
@@ -257,7 +256,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-enum-as-string}}
|
||||
if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) {
|
||||
throw new IllegalArgumentException({{name}} + " is invalid. Possible values for {{name}}: " + String.join(", ", {{{nameInSnakeCase}}}_VALUES));
|
||||
|
||||
@@ -68,10 +68,23 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
return ret;
|
||||
}
|
||||
{{/discriminator}}
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
// deserialize {{{.}}}
|
||||
// deserialize {{{dataType}}}{{#isNullable}} (nullable){{/isNullable}}
|
||||
try {
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{.}}}.class);
|
||||
{{^isArray}}
|
||||
{{^isMap}}
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{dataType}}}.class);
|
||||
{{/isMap}}
|
||||
{{/isArray}}
|
||||
{{#isArray}}
|
||||
final TypeReference<{{{dataType}}}> ref = new TypeReference<{{{dataType}}}>(){};
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs(ref);
|
||||
{{/isArray}}
|
||||
{{#isMap}}
|
||||
final TypeReference<{{{dataType}}}> ref = new TypeReference<{{{dataType}}}>(){};
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs(ref);
|
||||
{{/isMap}}
|
||||
{{classname}} ret = new {{classname}}();
|
||||
ret.setActualInstance(deserialized);
|
||||
return ret;
|
||||
@@ -81,6 +94,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
}
|
||||
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
throw new IOException(String.format("Failed deserialization for {{classname}}: no match found"));
|
||||
}
|
||||
|
||||
@@ -119,13 +133,17 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties);
|
||||
}
|
||||
{{/additionalPropertiesType}}
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
public {{classname}}({{{.}}} o) {
|
||||
{{^vendorExtensions.x-duplicated-data-type}}
|
||||
public {{classname}}({{{baseType}}} o) {
|
||||
super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
|
||||
setActualInstance(o);
|
||||
}
|
||||
|
||||
{{/vendorExtensions.x-duplicated-data-type}}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
static {
|
||||
{{#anyOf}}
|
||||
schemas.put("{{{.}}}", new GenericType<{{{.}}}>() {
|
||||
@@ -165,13 +183,17 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
}
|
||||
|
||||
{{/isNullable}}
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
if (JSON.isInstanceOf({{{.}}}.class, instance, new HashSet<>())) {
|
||||
{{^vendorExtensions.x-duplicated-data-type}}
|
||||
if (JSON.isInstanceOf({{{baseType}}}.class, instance, new HashSet<>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
{{/vendorExtensions.x-duplicated-data-type}}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
throw new RuntimeException("Invalid instance type. Must be {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}");
|
||||
}
|
||||
|
||||
@@ -186,17 +208,21 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
return super.getActualInstance();
|
||||
}
|
||||
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
{{^vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
/**
|
||||
* Get the actual instance of `{{{.}}}`. If the actual instance is not `{{{.}}}`,
|
||||
* Get the actual instance of `{{{dataType}}}`. If the actual instance is not `{{{dataType}}}`,
|
||||
* the ClassCastException will be thrown.
|
||||
*
|
||||
* @return The actual instance of `{{{.}}}`
|
||||
* @throws ClassCastException if the instance is not `{{{.}}}`
|
||||
* @return The actual instance of `{{{dataType}}}`
|
||||
* @throws ClassCastException if the instance is not `{{{dataType}}}`
|
||||
*/
|
||||
public {{{.}}} get{{{.}}}() throws ClassCastException {
|
||||
return ({{{.}}})super.getActualInstance();
|
||||
public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException {
|
||||
return ({{{dataType}}})super.getActualInstance();
|
||||
}
|
||||
|
||||
{{/vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -120,7 +120,13 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
if (attemptParsing) {
|
||||
{{#isMap}}
|
||||
final TypeReference<{{{dataType}}}> ref = new TypeReference<{{{dataType}}}>(){};
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs(ref);
|
||||
{{/isMap}}
|
||||
{{^isMap}}
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{dataType}}}.class);
|
||||
{{/isMap}}
|
||||
// TODO: there is no validation against JSON schema constraints
|
||||
// (min, max, enum, pattern...), this does not perform a strict JSON
|
||||
// validation, which means the 'match' count may be higher than it should be.
|
||||
@@ -266,6 +272,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
{{^vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
/**
|
||||
* Get the actual instance of `{{{dataType}}}`. If the actual instance is not `{{{dataType}}}`,
|
||||
* the ClassCastException will be thrown.
|
||||
@@ -273,17 +280,11 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
* @return The actual instance of `{{{dataType}}}`
|
||||
* @throws ClassCastException if the instance is not `{{{dataType}}}`
|
||||
*/
|
||||
{{^isArray}}
|
||||
public {{{dataType}}} get{{{dataType}}}() throws ClassCastException {
|
||||
public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException {
|
||||
return ({{{dataType}}})super.getActualInstance();
|
||||
}
|
||||
{{/isArray}}
|
||||
{{#isArray}}
|
||||
public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException {
|
||||
return ({{{dataType}}})super.getActualInstance();
|
||||
}
|
||||
{{/isArray}}
|
||||
|
||||
{{/vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,12 @@
|
||||
@JsonTypeName("{{name}}")
|
||||
{{/isClassnameSanitized}}
|
||||
{{/jackson}}
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{>generatedAnnotation}}
|
||||
{{#discriminator}}
|
||||
{{>typeInfoAnnotation}}
|
||||
{{/discriminator}}
|
||||
{{>xmlAnnotation}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
@@ -44,6 +49,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{>modelInnerEnum}}
|
||||
{{/mostInnerItems}}
|
||||
{{/isContainer}}
|
||||
|
||||
{{/isEnum}}
|
||||
{{#gson}}
|
||||
public static final String SERIALIZED_NAME_{{nameInSnakeCase}} = "{{baseName}}";
|
||||
@@ -81,6 +87,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{>nullable_var_annotations}}
|
||||
|
||||
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
|
||||
@@ -113,7 +121,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
public {{classname}} {{name}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-enum-as-string}}
|
||||
if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) {
|
||||
throw new IllegalArgumentException({{name}} + " is invalid. Possible values for {{name}}: " + String.join(", ", {{{nameInSnakeCase}}}_VALUES));
|
||||
@@ -197,17 +205,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#required}}
|
||||
{{#isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nonnull
|
||||
{{/isNullable}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/required}}
|
||||
{{>nullable_var_annotations}}
|
||||
|
||||
{{#useBeanValidation}}
|
||||
{{>beanValidation}}
|
||||
{{/useBeanValidation}}
|
||||
@@ -224,7 +223,11 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{!unannotated, Jackson would pick this up automatically and add it *in addition* to the _JsonNullable getter field}}
|
||||
@JsonIgnore
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}{{#jackson}}{{> jackson_annotations}}{{/jackson}}{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#jackson}}
|
||||
{{> jackson_annotations}}
|
||||
{{/jackson}}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#isReadOnly}}{{! A readonly attribute doesn't have setter => jackson will set null directly if explicitly returned by API, so make sure we have an empty JsonNullable}}
|
||||
@@ -244,7 +247,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
public JsonNullable<{{{datatypeWithEnum}}}> {{getter}}_JsonNullable() {
|
||||
return {{name}};
|
||||
}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}})
|
||||
{{#isReadOnly}}private{{/isReadOnly}}{{^isReadOnly}}public{{/isReadOnly}} void {{setter}}_JsonNullable(JsonNullable<{{{datatypeWithEnum}}}> {{name}}) {
|
||||
{{! For getters/setters that have name differing from attribute name, we must include setter (albeit private) for jackson to be able to set the attribute}}
|
||||
@@ -256,8 +260,15 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-setter-extra-annotation}}
|
||||
{{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}
|
||||
{{#jackson}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{> jackson_annotations}}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{/jackson}}
|
||||
public void {{setter}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-enum-as-string}}
|
||||
if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) {
|
||||
throw new IllegalArgumentException({{name}} + " is invalid. Possible values for {{name}}: " + String.join(", ", {{{nameInSnakeCase}}}_VALUES));
|
||||
@@ -297,11 +308,13 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
|
||||
return {{#parent}}super.equals(o){{/parent}}{{^parent}}true{{/parent}};{{/hasVars}}
|
||||
{{/useReflectionEqualsHashCode}}
|
||||
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
}
|
||||
{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
|
||||
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
|
||||
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
|
||||
}{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
}
|
||||
{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@@ -311,14 +324,16 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{^useReflectionEqualsHashCode}}
|
||||
return Objects.hash({{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}hashCodeNullable({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}{{#additionalPropertiesType}}{{#hasVars}}, {{/hasVars}}{{^hasVars}}{{#parent}}, {{/parent}}{{/hasVars}}additionalProperties{{/additionalPropertiesType}});
|
||||
{{/useReflectionEqualsHashCode}}
|
||||
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
}
|
||||
{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
|
||||
private static <T> int hashCodeNullable(JsonNullable<T> a) {
|
||||
if (a == null) {
|
||||
return 1;
|
||||
}
|
||||
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
|
||||
}{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
}
|
||||
{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{rootJavaEEPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{rootJavaEEPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -26,7 +26,12 @@ import {{invokerPackage}}.ApiClient;
|
||||
{{/vars}}
|
||||
})
|
||||
{{/jackson}}
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{>generatedAnnotation}}
|
||||
{{#discriminator}}
|
||||
{{>typeInfoAnnotation}}
|
||||
{{/discriminator}}
|
||||
{{>xmlAnnotation}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
@@ -47,6 +52,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{>modelInnerEnum}}
|
||||
{{/mostInnerItems}}
|
||||
{{/isContainer}}
|
||||
|
||||
{{/isEnum}}
|
||||
{{#gson}}
|
||||
public static final String SERIALIZED_NAME_{{nameInSnakeCase}} = "{{baseName}}";
|
||||
@@ -75,6 +81,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{/isContainer}}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{>nullable_var_annotations}}
|
||||
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
|
||||
@@ -104,7 +111,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
));
|
||||
|
||||
{{/vendorExtensions.x-enum-as-string}}
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
public {{classname}} {{name}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-enum-as-string}}
|
||||
if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) {
|
||||
throw new IllegalArgumentException({{name}} + " is invalid. Possible values for {{name}}: " + String.join(", ", {{{nameInSnakeCase}}}_VALUES));
|
||||
@@ -188,17 +195,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#required}}
|
||||
{{#isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nonnull
|
||||
{{/isNullable}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/required}}
|
||||
{{>nullable_var_annotations}}
|
||||
{{#useBeanValidation}}
|
||||
{{>beanValidation}}
|
||||
{{/useBeanValidation}}
|
||||
@@ -244,7 +241,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
|
||||
{{^isReadOnly}}
|
||||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-enum-as-string}}
|
||||
if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) {
|
||||
throw new IllegalArgumentException({{name}} + " is invalid. Possible values for {{name}}: " + String.join(", ", {{{nameInSnakeCase}}}_VALUES));
|
||||
@@ -266,7 +263,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#allVars}}
|
||||
{{#isOverridden}}
|
||||
@Override
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
public {{classname}} {{name}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{setter}}(JsonNullable.<{{{datatypeWithEnum}}}>of({{name}}));
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
@@ -582,6 +579,6 @@ static {
|
||||
{{/discriminator}}
|
||||
{{#generateBuilders}}
|
||||
|
||||
{{>javaBuilder}}
|
||||
{{>javaBuilder}}
|
||||
{{/generateBuilders}}
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
{{^vendorExtensions.x-duplicated-data-type}}
|
||||
{{^vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
/**
|
||||
* Get the actual instance of `{{{dataType}}}`. If the actual instance is not `{{{dataType}}}`,
|
||||
* the ClassCastException will be thrown.
|
||||
@@ -291,13 +291,13 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
* @return The actual instance of `{{{dataType}}}`
|
||||
* @throws ClassCastException if the instance is not `{{{dataType}}}`
|
||||
*/
|
||||
public {{{dataType}}} get{{#isArray}}{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}() throws ClassCastException {
|
||||
public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException {
|
||||
return ({{{dataType}}})super.getActualInstance();
|
||||
}
|
||||
{{/vendorExtensions.x-duplicated-data-type}}
|
||||
|
||||
{{/vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
|
||||
/**
|
||||
* Validates the JSON Element and throws an exception if issues found
|
||||
*
|
||||
|
||||
@@ -361,7 +361,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
{{^vendorExtensions.x-duplicated-data-type}}
|
||||
{{^vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
/**
|
||||
* Get the actual instance of `{{{dataType}}}`. If the actual instance is not `{{{dataType}}}`,
|
||||
* the ClassCastException will be thrown.
|
||||
@@ -372,10 +372,10 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException {
|
||||
return ({{{dataType}}})super.getActualInstance();
|
||||
}
|
||||
{{/vendorExtensions.x-duplicated-data-type}}
|
||||
|
||||
{{/vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
|
||||
/**
|
||||
* Validates the JSON Element and throws an exception if issues found
|
||||
*
|
||||
|
||||
@@ -70,6 +70,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#vendorExtensions.x-field-extra-annotation}}
|
||||
{{{vendorExtensions.x-field-extra-annotation}}}
|
||||
{{/vendorExtensions.x-field-extra-annotation}}
|
||||
{{>nullable_var_annotations}}
|
||||
{{#isDiscriminator}}protected{{/isDiscriminator}}{{^isDiscriminator}}private{{/isDiscriminator}} {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
|
||||
{{/vars}}
|
||||
@@ -106,7 +107,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
public {{classname}} {{name}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
return this;
|
||||
}
|
||||
@@ -153,17 +154,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#required}}
|
||||
{{#isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nonnull
|
||||
{{/isNullable}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/required}}
|
||||
{{>nullable_var_annotations}}
|
||||
{{#useBeanValidation}}
|
||||
{{>beanValidation}}
|
||||
{{/useBeanValidation}}
|
||||
@@ -183,7 +174,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{^isReadOnly}}
|
||||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#deprecated}} @Deprecated
|
||||
{{/deprecated}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{/deprecated}} public void {{setter}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
{{/isReadOnly}}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
{{#withXml}}
|
||||
@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
||||
{{/withXml}}
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
{{{name}}}({{^isUri}}{{dataType}}.valueOf({{/isUri}}{{{value}}}{{^isUri}}){{/isUri}}){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
|
||||
1
modules/openapi-generator/src/main/resources/Java/nullable_var_annotations.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/Java/nullable_var_annotations.mustache
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{{#required}}{{#isNullable}}@{{javaxPackage}}.annotation.Nullable{{/isNullable}}{{^isNullable}}@{{javaxPackage}}.annotation.Nonnull{{/isNullable}}{{/required}}{{^required}}@{{javaxPackage}}.annotation.Nullable{{/required}}
|
||||
@@ -25,7 +25,12 @@
|
||||
{{/hasDiscriminatorWithNonEmptyMapping}}
|
||||
{{/isClassnameSanitized}}
|
||||
{{/jackson}}
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{>generatedAnnotation}}
|
||||
{{#discriminator}}
|
||||
{{>typeInfoAnnotation}}
|
||||
{{/discriminator}}
|
||||
{{>xmlAnnotation}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
@@ -44,6 +49,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{>modelInnerEnum}}
|
||||
{{/mostInnerItems}}
|
||||
{{/isContainer}}
|
||||
|
||||
{{/isEnum}}
|
||||
{{#gson}}
|
||||
public static final String SERIALIZED_NAME_{{nameInSnakeCase}} = "{{baseName}}";
|
||||
@@ -65,6 +71,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#gson}}
|
||||
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
|
||||
{{/gson}}
|
||||
{{>nullable_var_annotations}}
|
||||
|
||||
{{#vendorExtensions.x-field-extra-annotation}}
|
||||
{{{vendorExtensions.x-field-extra-annotation}}}
|
||||
{{/vendorExtensions.x-field-extra-annotation}}
|
||||
@@ -134,7 +142,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
|
||||
{{#vars}}
|
||||
{{^isReadOnly}}
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
public {{classname}} {{name}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}this.{{name}} = {{name}};{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
return this;
|
||||
@@ -210,17 +218,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#required}}
|
||||
{{#isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
@{{javaxPackage}}.annotation.Nonnull
|
||||
{{/isNullable}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
@{{javaxPackage}}.annotation.Nullable
|
||||
{{/required}}
|
||||
{{>nullable_var_annotations}}
|
||||
|
||||
{{#jsonb}}
|
||||
@JsonbProperty("{{baseName}}")
|
||||
{{/jsonb}}
|
||||
@@ -270,7 +269,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
|
||||
{{^isReadOnly}}
|
||||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
@@ -285,7 +284,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#readWriteVars}}
|
||||
{{#isOverridden}}
|
||||
@Override
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
public {{classname}} {{name}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{setter}}(JsonNullable.<{{{datatypeWithEnum}}}>of({{name}}));
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
{{#jackson}}
|
||||
|
||||
@JsonIgnoreProperties(
|
||||
value = "{{{discriminator.propertyBaseName}}}", // ignore manually set {{{discriminator.propertyBaseName}}}, it will be automatically generated by Jackson during serialization
|
||||
allowSetters = true // allows the {{{discriminator.propertyBaseName}}} to be set during deserialization
|
||||
|
||||
@@ -3,4 +3,6 @@
|
||||
@XmlRootElement({{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}name = "{{xmlName}}{{^xmlName}}{{classname}}{{/xmlName}}")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
{{#jackson}}
|
||||
@JacksonXmlRootElement({{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}localName = "{{xmlName}}{{^xmlName}}{{classname}}{{/xmlName}}"){{/jackson}}{{/withXml}}
|
||||
@JacksonXmlRootElement({{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}localName = "{{xmlName}}{{^xmlName}}{{classname}}{{/xmlName}}")
|
||||
{{/jackson}}
|
||||
{{/withXml}}
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -17,21 +17,35 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
{ {{#vars}}"{{name}}"{{^-last}}, {{/-last}}{{/vars}}
|
||||
}){{/hasVars}}
|
||||
{{^hasVars}}@XmlType(name = "{{classname}}"){{/hasVars}}
|
||||
{{^parent}}@XmlRootElement(name="{{classname}}"){{/parent}}
|
||||
{{^parent}}
|
||||
@XmlRootElement(name="{{classname}}")
|
||||
{{/parent}}
|
||||
{{/withXml}}
|
||||
{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{#description}}
|
||||
{{#discriminator}}
|
||||
{{>typeInfoAnnotation}}
|
||||
{{/discriminator}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
@ApiModel(description="{{{description}}}")
|
||||
{{/description}}{{>additionalModelTypeAnnotations}}
|
||||
{{/description}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
|
||||
{{#vars}}{{#isEnum}}{{^isContainer}}
|
||||
{{>enumClass}}{{/isContainer}}{{#isContainer}}{{#mostInnerItems}}
|
||||
{{>enumClass}}{{/mostInnerItems}}{{/isContainer}}{{/isEnum}}
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
{{^isContainer}}
|
||||
{{>enumClass}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#mostInnerItems}}
|
||||
{{>enumClass}}
|
||||
{{/mostInnerItems}}
|
||||
{{/isContainer}}
|
||||
{{/isEnum}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{.}}}
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
{{#hasVars}} @XmlType(name = "{{classname}}", propOrder =
|
||||
{ {{#vars}}"{{name}}"{{^-last}}, {{/-last}}{{/vars}}
|
||||
}){{/hasVars}}
|
||||
{{^hasVars}}@XmlType(name = "{{classname}}"){{/hasVars}}
|
||||
{{^parent}}@XmlRootElement(name="{{classname}}"){{/parent}}
|
||||
{{/withXml}}
|
||||
{{^hasVars}}
|
||||
@XmlType(name = "{{classname}}")
|
||||
{{/hasVars}}
|
||||
{{^parent}}
|
||||
@XmlRootElement(name="{{classname}}")
|
||||
{{/parent}}
|
||||
{{/withXml}}
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
{{/vars}}
|
||||
})
|
||||
{{/jackson}}
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{>generatedAnnotation}}
|
||||
{{#discriminator}}
|
||||
{{>typeInfoAnnotation}}
|
||||
{{/discriminator}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
{{/vars}}
|
||||
})
|
||||
{{/jackson}}
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{>generatedAnnotation}}
|
||||
{{#discriminator}}
|
||||
{{>typeInfoAnnotation}}
|
||||
{{/discriminator}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -42,3 +42,4 @@
|
||||
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -6,7 +6,8 @@ import {{javaxPackage}}.validation.Valid;
|
||||
/**
|
||||
* {{description}}{{^description}}{{classname}}{{/description}}
|
||||
*/
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{>generatedAnnotation}}
|
||||
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
@@ -33,15 +34,11 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens
|
||||
{{{vendorExtensions.x-field-extra-annotation}}}
|
||||
{{/vendorExtensions.x-field-extra-annotation}}
|
||||
{{#isContainer}}
|
||||
{{#useBeanValidation}}
|
||||
{{>beanValidation}}
|
||||
{{/useBeanValidation}}
|
||||
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}
|
||||
private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
{{#useBeanValidation}}
|
||||
{{>beanValidation}}
|
||||
{{/useBeanValidation}}
|
||||
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}
|
||||
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/isContainer}}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public interface {{classname}}Delegate {
|
||||
{{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{>responseType}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#isArray}}List<{{/isArray}}{{#reactive}}Flux<Part>{{/reactive}}{{^reactive}}{{#isFormParam}}MultipartFile{{/isFormParam}}{{^isFormParam}}{{>optionalDataType}}{{/isFormParam}}{{/reactive}}{{#isArray}}>{{/isArray}}{{/isFile}} {{paramName}}{{^-last}},
|
||||
{{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}},
|
||||
{{/hasParams}}ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
|
||||
{{>methodBody}}
|
||||
{{>methodBody}}
|
||||
}{{/jdk8-default-interface}}
|
||||
|
||||
{{/operation}}
|
||||
|
||||
@@ -1 +1 @@
|
||||
@Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
}
|
||||
|
||||
protected Builder copyOf({{classname}} value) { {{#parentModel}}
|
||||
super.copyOf(instance);{{/parentModel}}{{#vars}}
|
||||
super.copyOf(value);{{/parentModel}}{{#vars}}
|
||||
this.instance.{{setter}}(value.{{name}});{{/vars}}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
{{#examples}}
|
||||
{{#-first}}
|
||||
{{#async}}
|
||||
return CompletableFuture.supplyAsync(()-> {
|
||||
{{/async}}getRequest().ifPresent(request -> {
|
||||
return CompletableFuture.supplyAsync(()-> {
|
||||
{{/async}} getRequest().ifPresent(request -> {
|
||||
{{#async}} {{/async}} for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
{{/-first}}
|
||||
{{#async}} {{/async}}{{^async}} {{/async}} if (mediaType.isCompatibleWith(MediaType.valueOf("{{{contentType}}}"))) {
|
||||
@@ -24,7 +24,7 @@ return CompletableFuture.supplyAsync(()-> {
|
||||
{{/-last}}
|
||||
{{/examples}}
|
||||
{{^examples}}
|
||||
{{#useResponseEntity}}return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>({{#returnSuccessCode}}HttpStatus.OK{{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}}){{#async}}){{/async}};
|
||||
{{#useResponseEntity}} return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>({{#returnSuccessCode}}HttpStatus.OK{{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}}){{#async}}){{/async}};
|
||||
{{/useResponseEntity}}
|
||||
{{^useResponseEntity}}throw new IllegalArgumentException("Not implemented");
|
||||
{{/useResponseEntity}}
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
@JacksonXmlRootElement({{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}localName = "{{xmlName}}{{^xmlName}}{{classname}}{{/xmlName}}")
|
||||
{{/jackson}}
|
||||
@XmlRootElement({{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}name = "{{xmlName}}{{^xmlName}}{{classname}}{{/xmlName}}")
|
||||
@XmlAccessorType(XmlAccessType.FIELD){{/withXml}}
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
{{/withXml}}
|
||||
|
||||
@@ -27,7 +27,11 @@ using {{packageName}}.Converters;
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
namespace {{modelPackage}}
|
||||
{ {{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}}
|
||||
{
|
||||
{{#isEnum}}
|
||||
{{>enumClass}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
@@ -60,6 +64,7 @@ namespace {{modelPackage}}
|
||||
{{^complexType}}
|
||||
{{>enumClass}}
|
||||
{{/complexType}}
|
||||
|
||||
{{/isEnum}}
|
||||
/// <summary>
|
||||
/// {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
|
||||
|
||||
@@ -51,14 +51,14 @@ bool {{classname}}::validate(std::stringstream& msg, const std::string& pathPref
|
||||
{{#required}}/* {{name}} */ {{/required}}{
|
||||
const {{{dataType}}}& value = m_{{name}};
|
||||
const std::string currentValuePath = _pathPrefix + ".{{nameInCamelCase}}";
|
||||
{{> model-validation-body }}
|
||||
{{> model-validation-body }}
|
||||
}
|
||||
{{/isArray}}{{^isArray}}{{#hasValidation}} {{! Only generate validation if necessary }}
|
||||
{{^required}}if ({{nameInCamelCase}}IsSet()){{/required}}
|
||||
{{#required}}/* {{name}} */ {{/required}}{
|
||||
const {{{dataType}}}& value = m_{{name}};
|
||||
const std::string currentValuePath = _pathPrefix + ".{{nameInCamelCase}}";
|
||||
{{> model-validation-body }}
|
||||
{{> model-validation-body }}
|
||||
}
|
||||
{{/hasValidation}}{{#required}}{{#isModel}}
|
||||
if (!m_{{name}}.validate(msg, _pathPrefix + ".{{nameInCamelCase}}")) {
|
||||
|
||||
@@ -47,13 +47,7 @@ void {{prefix}}HttpRequestInput::add_file(QString variable_name, QString local_f
|
||||
|
||||
{{prefix}}HttpRequestWorker::{{prefix}}HttpRequestWorker(QObject *parent, QNetworkAccessManager *_manager)
|
||||
: QObject(parent), manager(_manager), timeOutTimer(this), isResponseCompressionEnabled(false), isRequestCompressionEnabled(false), httpResponseCode(-1) {
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
randomGenerator = QRandomGenerator(QDateTime::currentDateTime().toSecsSinceEpoch());
|
||||
#else
|
||||
qsrand(QDateTime::currentDateTime().toTime_t());
|
||||
#endif
|
||||
|
||||
if (manager == nullptr) {
|
||||
manager = new QNetworkAccessManager(this);
|
||||
}
|
||||
@@ -212,13 +206,8 @@ void {{prefix}}HttpRequestWorker::execute({{prefix}}HttpRequestInput *input) {
|
||||
// variable layout is MULTIPART
|
||||
|
||||
boundary = QString("__-----------------------%1%2")
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
.arg(QDateTime::currentDateTime().toSecsSinceEpoch())
|
||||
.arg(randomGenerator.generate());
|
||||
#else
|
||||
.arg(QDateTime::currentDateTime().toTime_t())
|
||||
.arg(qrand());
|
||||
#endif
|
||||
QString boundary_delimiter = "--";
|
||||
QString new_line = "\r\n";
|
||||
|
||||
@@ -359,26 +348,17 @@ void {{prefix}}HttpRequestWorker::execute({{prefix}}HttpRequestInput *input) {
|
||||
} else if (input->http_method == "DELETE") {
|
||||
reply = manager->deleteResource(request);
|
||||
} else {
|
||||
#if (QT_VERSION >= 0x050800)
|
||||
reply = manager->sendCustomRequest(request, input->http_method.toLatin1(), request_content);
|
||||
#else
|
||||
QBuffer *buffer = new QBuffer;
|
||||
buffer->setData(request_content);
|
||||
buffer->open(QIODevice::ReadOnly);
|
||||
|
||||
reply = manager->sendCustomRequest(request, input->http_method.toLatin1(), buffer);
|
||||
buffer->setParent(reply);
|
||||
#endif
|
||||
}
|
||||
if (reply != nullptr) {
|
||||
reply->setParent(this);
|
||||
connect(reply, &QNetworkReply::downloadProgress, this, &{{prefix}}HttpRequestWorker::downloadProgress);
|
||||
connect(reply, &QNetworkReply::finished, [this, reply] {
|
||||
connect(reply, &QNetworkReply::finished, this, [this, reply] {
|
||||
on_reply_finished(reply);
|
||||
});
|
||||
}
|
||||
if (timeOutTimer.interval() > 0) {
|
||||
QObject::connect(&timeOutTimer, &QTimer::timeout, [this, reply] {
|
||||
QObject::connect(&timeOutTimer, &QTimer::timeout, this, [this, reply] {
|
||||
on_reply_timeout(reply);
|
||||
});
|
||||
timeOutTimer.start();
|
||||
|
||||
@@ -23,9 +23,6 @@ void {{classname}}::initializeServerConfigs() {
|
||||
//Default server
|
||||
QList<{{prefix}}ServerConfiguration> defaultConf = QList<{{prefix}}ServerConfiguration>();
|
||||
//varying endpoint server
|
||||
{{#servers}}
|
||||
QList<{{prefix}}ServerConfiguration> serverConf = QList<{{prefix}}ServerConfiguration>();
|
||||
{{/servers}}
|
||||
{{#vendorExtensions.x-cpp-global-server-list}}
|
||||
defaultConf.append({{prefix}}ServerConfiguration(
|
||||
QUrl("{{{url}}}"),
|
||||
@@ -42,15 +39,18 @@ void {{classname}}::initializeServerConfigs() {
|
||||
_serverIndices.insert("{{nickname}}", 0);
|
||||
{{/servers}}
|
||||
{{#servers}}
|
||||
serverConf.append({{prefix}}ServerConfiguration(
|
||||
QUrl("{{{url}}}"),
|
||||
"{{{description}}}{{^description}}No description provided{{/description}}",
|
||||
{{#variables}}{{#-first}}QMap<QString, {{prefix}}ServerVariable>{ {{/-first}}
|
||||
{"{{{name}}}", {{prefix}}ServerVariable("{{{description}}}{{^description}}No description provided{{/description}}","{{{defaultValue}}}",
|
||||
QSet<QString>{ {{#enumValues}}{"{{{.}}}"}{{#-last}} })}, {{/-last}}{{^-last}},{{/-last}}{{/enumValues}}{{^enumValues}}{"{{defaultValue}}"} })},{{/enumValues}}{{#-last}} }));{{/-last}}
|
||||
{{/variables}}{{^variables}}QMap<QString, {{prefix}}ServerVariable>()));{{/variables}}
|
||||
{{#-last}}_serverConfigs.insert("{{nickname}}", serverConf);
|
||||
_serverIndices.insert("{{nickname}}", 0);{{/-last}}
|
||||
{
|
||||
QList<{{prefix}}ServerConfiguration> serverConf = QList<{{prefix}}ServerConfiguration>();
|
||||
serverConf.append({{prefix}}ServerConfiguration(
|
||||
QUrl("{{{url}}}"),
|
||||
"{{{description}}}{{^description}}No description provided{{/description}}",
|
||||
{{#variables}}{{#-first}}QMap<QString, {{prefix}}ServerVariable>{ {{/-first}}
|
||||
{"{{{name}}}", {{prefix}}ServerVariable("{{{description}}}{{^description}}No description provided{{/description}}","{{{defaultValue}}}",
|
||||
QSet<QString>{ {{#enumValues}}{"{{{.}}}"}{{#-last}} })}, {{/-last}}{{^-last}},{{/-last}}{{/enumValues}}{{^enumValues}}{"{{defaultValue}}"} })},{{/enumValues}}{{#-last}} }));{{/-last}}
|
||||
{{/variables}}{{^variables}}QMap<QString, {{prefix}}ServerVariable>()));{{/variables}}
|
||||
{{#-last}}_serverConfigs.insert("{{nickname}}", serverConf);
|
||||
_serverIndices.insert("{{nickname}}", 0);{{/-last}}
|
||||
}
|
||||
{{/servers}}
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
@@ -664,7 +664,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
||||
connect(worker, &{{prefix}}HttpRequestWorker::downloadProgress, this, &{{classname}}::{{nickname}}Progress);{{/addDownloadProgress}}
|
||||
connect(worker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
|
||||
connect(this, &{{classname}}::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||
connect(worker, &QObject::destroyed, this, [this]() {
|
||||
connect(worker, &QObject::destroyed, this, [this] {
|
||||
if (findChildren<{{prefix}}HttpRequestWorker*>().count() == 0) {
|
||||
Q_EMIT allPendingRequestsCompleted();
|
||||
}
|
||||
@@ -690,7 +690,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
||||
|
||||
connect(_latestWorker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
|
||||
connect(this, &{{classname}}::abortRequestsSignal, _latestWorker, &QObject::deleteLater);
|
||||
connect(_latestWorker, &QObject::destroyed, [this](){
|
||||
connect(_latestWorker, &QObject::destroyed, this, [this] {
|
||||
if(findChildren<{{prefix}}HttpRequestWorker*>().count() == 0){
|
||||
Q_EMIT allPendingRequestsCompleted();
|
||||
}
|
||||
@@ -720,7 +720,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
||||
|
||||
connect(_latestWorker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
|
||||
connect(this, &{{classname}}::abortRequestsSignal, _latestWorker, &QObject::deleteLater);
|
||||
connect(_latestWorker, &QObject::destroyed, [this](){
|
||||
connect(_latestWorker, &QObject::destroyed, this, [this] {
|
||||
if(findChildren<{{prefix}}HttpRequestWorker*>().count() == 0){
|
||||
Q_EMIT allPendingRequestsCompleted();
|
||||
}
|
||||
@@ -750,7 +750,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
||||
|
||||
connect(_latestWorker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
|
||||
connect(this, &{{classname}}::abortRequestsSignal, _latestWorker, &QObject::deleteLater);
|
||||
connect(_latestWorker, &QObject::destroyed, [this](){
|
||||
connect(_latestWorker, &QObject::destroyed, this, [this] {
|
||||
if(findChildren<{{prefix}}HttpRequestWorker*>().count() == 0){
|
||||
Q_EMIT allPendingRequestsCompleted();
|
||||
}
|
||||
@@ -780,7 +780,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
||||
|
||||
connect(_latestWorker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
|
||||
connect(this, &{{classname}}::abortRequestsSignal, _latestWorker, &QObject::deleteLater);
|
||||
connect(_latestWorker, &QObject::destroyed, [this](){
|
||||
connect(_latestWorker, &QObject::destroyed, this, [this] {
|
||||
if(findChildren<{{prefix}}HttpRequestWorker*>().count() == 0){
|
||||
Q_EMIT allPendingRequestsCompleted();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const auto request = session->get_request();
|
||||
const auto request = session->get_request();
|
||||
{{#hasBodyParam}}
|
||||
// body params or form params here from the body content string
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
@@ -151,7 +151,7 @@ void {{vendorExtensions.x-codegen-resource-name}}Resource::defaultSessionClose(c
|
||||
void {{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
{{#lambda.indented}}
|
||||
{{>api-source-HandlerBody}}
|
||||
{{>api-source-HandlerBody}}
|
||||
{{/lambda.indented}}
|
||||
|
||||
}
|
||||
@@ -160,7 +160,7 @@ void {{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}
|
||||
// x-extension
|
||||
void {{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
{{#lambda.indented}}
|
||||
{{>api-source-HandlerBody}}
|
||||
{{>api-source-HandlerBody}}
|
||||
{{/lambda.indented}}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user