mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-01-27 04:30:56 +00:00
Compare commits
44 Commits
ruby-githu
...
devhl-labs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70ada0e7e7 | ||
|
|
b199901aab | ||
|
|
941a5ccf13 | ||
|
|
5f13c53825 | ||
|
|
1240d103ff | ||
|
|
42af4f9529 | ||
|
|
81a3488556 | ||
|
|
08da0abfca | ||
|
|
fb277f82d5 | ||
|
|
6b1b5cc4c5 | ||
|
|
fd84c8fbd6 | ||
|
|
f092f72cc5 | ||
|
|
37cac71f87 | ||
|
|
b8d805980a | ||
|
|
b49ec6e033 | ||
|
|
4352a2fcd0 | ||
|
|
6f3dacafc4 | ||
|
|
2d2e1c41c4 | ||
|
|
a955bead08 | ||
|
|
d7b79a26c6 | ||
|
|
1d7d399ec2 | ||
|
|
4121803442 | ||
|
|
602549cb36 | ||
|
|
1c082c7287 | ||
|
|
7ab9364094 | ||
|
|
28e7e7f2eb | ||
|
|
e8a688a724 | ||
|
|
ddb15d4b9d | ||
|
|
885ea07b17 | ||
|
|
c0b72ee970 | ||
|
|
ee76a05def | ||
|
|
30096d63b7 | ||
|
|
44a3be170f | ||
|
|
e38f6c0580 | ||
|
|
2afac1aa28 | ||
|
|
bab5ca2452 | ||
|
|
c1931c10da | ||
|
|
d8d9744154 | ||
|
|
dc0d5c6839 | ||
|
|
89edad5b8a | ||
|
|
258d971f42 | ||
|
|
5e8dcc9f07 | ||
|
|
67b24330c9 | ||
|
|
21c9ffd497 |
2
.github/ISSUE_TEMPLATE.md
vendored
2
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,6 +1,6 @@
|
||||
<!--
|
||||
Please follow the issue template below for bug reports and feature requests.
|
||||
Also please indicate in the issue title which language/library is concerned. Eg: [JAVA] Bug generating foo with bar
|
||||
Also please indicate in the issue title which language/library is concerned. E.g.: [JAVA] Bug generating foo with bar
|
||||
-->
|
||||
|
||||
##### Description
|
||||
|
||||
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -18,7 +18,7 @@ assignees: ''
|
||||
|
||||
<!--
|
||||
Please follow the issue template below for bug reports.
|
||||
Also please indicate in the issue title which language/library is concerned. Eg: [BUG][JAVA] Bug generating foo with bar
|
||||
Also please indicate in the issue title which language/library is concerned. E.g.: [BUG][JAVA] Bug generating foo with bar
|
||||
-->
|
||||
|
||||
##### Description
|
||||
|
||||
6
.github/workflows/linux.yaml
vendored
6
.github/workflows/linux.yaml
vendored
@@ -44,12 +44,12 @@ jobs:
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
- uses: gradle/actions/setup-gradle@v5
|
||||
with:
|
||||
gradle-version: '8.14.3'
|
||||
|
||||
- name: Setup Maven
|
||||
uses: s4u/setup-maven-action@v1.18.0
|
||||
uses: s4u/setup-maven-action@v1.19.0
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
maven-version: 3.8.8
|
||||
@@ -91,7 +91,7 @@ jobs:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v5
|
||||
- name: Setup Maven
|
||||
uses: s4u/setup-maven-action@v1.18.0
|
||||
uses: s4u/setup-maven-action@v1.19.0
|
||||
with:
|
||||
java-version: 11
|
||||
maven-version: 3.8.8
|
||||
|
||||
7
.github/workflows/samples-go.yaml
vendored
7
.github/workflows/samples-go.yaml
vendored
@@ -6,13 +6,13 @@ on:
|
||||
- 'samples/server/petstore/go-echo-server/**'
|
||||
- 'samples/server/petstore/go-api-server/**'
|
||||
- 'samples/server/petstore/go-chi-server/**'
|
||||
- 'samples/server/others/go-server/no-body-path-params/**'
|
||||
- 'samples/server/others/go-server/**'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'samples/server/petstore/go-echo-server/**'
|
||||
- 'samples/server/petstore/go-api-server/**'
|
||||
- 'samples/server/petstore/go-chi-server/**'
|
||||
- 'samples/server/others/go-server/no-body-path-params/**'
|
||||
- 'samples/server/others/go-server/**'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -26,6 +26,7 @@ jobs:
|
||||
- samples/server/petstore/go-api-server/
|
||||
- samples/server/petstore/go-chi-server/
|
||||
- samples/server/others/go-server/no-body-path-params/
|
||||
- samples/server/others/go-server/optional-body/
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-go@v6
|
||||
@@ -58,4 +59,4 @@ jobs:
|
||||
go mod tidy
|
||||
- name: Run tests
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: go test ./samples_tests -v
|
||||
run: go test ./samples_tests -v
|
||||
|
||||
@@ -5,6 +5,7 @@ on:
|
||||
paths:
|
||||
- 'samples/client/petstore/java/**'
|
||||
- samples/client/petstore/jaxrs-cxf-client/**
|
||||
- samples/client/petstore/jaxrs-cxf-client-swagger2/**
|
||||
- samples/client/petstore/java-micronaut-client/**
|
||||
- samples/openapi3/client/petstore/java/jersey2-java8-special-characters/**
|
||||
- samples/openapi3/client/petstore/java/jersey2-java8-swagger1/**
|
||||
@@ -27,6 +28,7 @@ on:
|
||||
paths:
|
||||
- 'samples/client/petstore/java/**'
|
||||
- samples/client/petstore/jaxrs-cxf-client/**
|
||||
- samples/client/petstore/jaxrs-cxf-client-swagger2/**
|
||||
- samples/client/petstore/java-micronaut-client/**
|
||||
- samples/openapi3/client/petstore/java/jersey2-java8-special-characters/**
|
||||
- samples/openapi3/client/petstore/java/jersey2-java8-swagger1/**
|
||||
@@ -54,6 +56,7 @@ jobs:
|
||||
matrix:
|
||||
sample:
|
||||
# clients
|
||||
- samples/client/petstore/jaxrs-cxf-client-swagger2
|
||||
- samples/client/petstore/jaxrs-cxf-client
|
||||
- samples/client/petstore/java/native
|
||||
- samples/client/petstore/java/native-async
|
||||
|
||||
51
.github/workflows/samples-javascript.yaml
vendored
Normal file
51
.github/workflows/samples-javascript.yaml
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
name: Samples JS clients
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
#- samples/client/petstore/javascript-flowtyped/**
|
||||
- samples/client/petstore/javascript-es6/**
|
||||
- samples/client/petstore/javascript-promise-es6/**
|
||||
pull_request:
|
||||
paths:
|
||||
#- samples/client/petstore/javascript-flowtyped/**
|
||||
- samples/client/petstore/javascript-es6/**
|
||||
- samples/client/petstore/javascript-promise-es6/**
|
||||
jobs:
|
||||
build:
|
||||
name: Build projects
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node:
|
||||
- "18.x"
|
||||
- "20.x"
|
||||
sample:
|
||||
# clients
|
||||
- samples/client/petstore/javascript-es6/
|
||||
- samples/client/petstore/javascript-promise-es6/
|
||||
services:
|
||||
petstore-api:
|
||||
image: swaggerapi/petstore
|
||||
ports:
|
||||
- 80:8080
|
||||
env:
|
||||
SWAGGER_HOST: http://petstore.swagger.io
|
||||
SWAGGER_BASE_PATH: /v2
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- name: Add hosts to /etc/hosts
|
||||
run: |
|
||||
sudo echo "127.0.0.1 petstore.swagger.io" | sudo tee -a /etc/hosts
|
||||
- name: Use Node.js 20.x
|
||||
uses: actions/setup-node@v5
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
cache: 'npm' # Or 'yarn'
|
||||
- name: npm install
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: npm install
|
||||
- name: npm test
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: npm test
|
||||
@@ -34,6 +34,7 @@ jobs:
|
||||
# server
|
||||
- samples/server/petstore/kotlin-server-required-and-nullable-properties
|
||||
- samples/server/petstore/kotlin-springboot-3
|
||||
- samples/server/petstore/kotlin-springboot-additionalproperties
|
||||
- samples/server/petstore/kotlin-springboot-delegate-nodefaults
|
||||
- samples/server/petstore/kotlin-springboot-request-cookie
|
||||
- samples/server/petstore/kotlin-server/jaxrs-spec
|
||||
@@ -67,4 +68,4 @@ jobs:
|
||||
arguments: wrapper
|
||||
- name: Build
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: ./gradlew build -x test
|
||||
run: ./gradlew build -x test
|
||||
|
||||
2
.github/workflows/samples-kotlin-server.yaml
vendored
2
.github/workflows/samples-kotlin-server.yaml
vendored
@@ -76,4 +76,4 @@ jobs:
|
||||
arguments: wrapper
|
||||
- name: Build
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: ./gradlew build -x test
|
||||
run: ./gradlew build -x test
|
||||
|
||||
@@ -34,6 +34,7 @@ jobs:
|
||||
- "3.13"
|
||||
sample:
|
||||
- samples/openapi3/client/petstore/python-aiohttp
|
||||
- samples/openapi3/client/petstore/python-httpx
|
||||
- samples/openapi3/client/petstore/python
|
||||
- samples/openapi3/client/petstore/python-lazyImports
|
||||
services:
|
||||
|
||||
34
.github/workflows/samples-typescript-server.yaml
vendored
Normal file
34
.github/workflows/samples-typescript-server.yaml
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
name: Samples TS servers
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- samples/server/petstore/typescript-nestjs-server/**
|
||||
pull_request:
|
||||
paths:
|
||||
- samples/server/petstore/typescript-nestjs-server/**
|
||||
jobs:
|
||||
build:
|
||||
name: Build projects
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node:
|
||||
- "18.x"
|
||||
- "20.x"
|
||||
sample:
|
||||
- samples/server/petstore/typescript-nestjs-server/
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- name: Use Node.js 20.x
|
||||
uses: actions/setup-node@v5
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
cache: 'npm' # Or 'yarn'
|
||||
- name: npm install
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: npm install
|
||||
- name: npm test
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: npm test
|
||||
2
.github/workflows/windows.yaml
vendored
2
.github/workflows/windows.yaml
vendored
@@ -39,7 +39,7 @@ jobs:
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
- name: Setup Maven
|
||||
uses: s4u/setup-maven-action@v1.18.0
|
||||
uses: s4u/setup-maven-action@v1.19.0
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
maven-version: 3.8.8
|
||||
|
||||
@@ -107,10 +107,6 @@ elif [ "$NODE_INDEX" = "3" ]; then
|
||||
(cd samples/client/petstore/typescript-axios/builds/with-npm-version && mvn integration-test)
|
||||
(cd samples/client/petstore/typescript-axios/tests/default && mvn integration-test)
|
||||
(cd samples/client/petstore/typescript-axios/tests/with-complex-headers && mvn integration-test)
|
||||
(cd samples/client/petstore/javascript-flowtyped && mvn integration-test)
|
||||
(cd samples/client/petstore/javascript-es6 && mvn integration-test)
|
||||
(cd samples/client/petstore/javascript-promise-es6 && mvn integration-test)
|
||||
(cd samples/server/petstore/typescript-nestjs-server && mvn integration-test)
|
||||
|
||||
else
|
||||
echo "Running node $NODE_INDEX ..."
|
||||
|
||||
18
README.md
18
README.md
@@ -15,7 +15,7 @@
|
||||
|
||||
<div align="center">
|
||||
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`7.16.0`):
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`7.17.0`):
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.bitrise.io/app/4a2b10a819d12b67)
|
||||
|
||||
@@ -148,8 +148,8 @@ The OpenAPI Specification has undergone 3 revisions since initial creation in 20
|
||||
|
||||
| OpenAPI Generator Version | Release Date | Notes |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------------------------------------------- |
|
||||
| 7.16.0 (upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.16.0-SNAPSHOT/) | 22.09.2025 | Minor release with breaking changes (with fallback) |
|
||||
| [7.15.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v7.15.0) (latest stable release) | 22.08.2025 | Minor release with breaking changes (with fallback) |
|
||||
| 7.17.0 (upcoming minor release) [SNAPSHOT](https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-to-test-with-the-latest-master-of-openapi-generator) | 24.10.2025 | Minor release with breaking changes (with fallback) |
|
||||
| [7.16.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v7.16.0) (latest stable release) | 28.09.2025 | 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) |
|
||||
| [4.3.1](https://github.com/OpenAPITools/openapi-generator/releases/tag/v4.3.1) | 06.05.2020 | Patch release (enhancements, bug fixes, etc) |
|
||||
@@ -212,16 +212,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.15.0/openapi-generator-cli-7.15.0.jar`
|
||||
JAR location: `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.16.0/openapi-generator-cli-7.16.0.jar`
|
||||
|
||||
For **Mac/Linux** users:
|
||||
```sh
|
||||
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.15.0/openapi-generator-cli-7.15.0.jar -O openapi-generator-cli.jar
|
||||
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.16.0/openapi-generator-cli-7.16.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.15.0/openapi-generator-cli-7.15.0.jar
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.16.0/openapi-generator-cli-7.16.0.jar
|
||||
```
|
||||
|
||||
After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage.
|
||||
@@ -456,7 +456,7 @@ openapi-generator-cli version
|
||||
To use a specific version of "openapi-generator-cli"
|
||||
|
||||
```sh
|
||||
openapi-generator-cli version-manager set 7.15.0
|
||||
openapi-generator-cli version-manager set 7.16.0
|
||||
```
|
||||
|
||||
Or install it as dev-dependency:
|
||||
@@ -480,7 +480,7 @@ pip install openapi-generator-cli
|
||||
|
||||
To install a specific version
|
||||
```
|
||||
pip install openapi-generator-cli==7.15.0
|
||||
pip install openapi-generator-cli==7.16.0
|
||||
```
|
||||
|
||||
You can also install with [jdk4py](https://github.com/activeviam/jdk4py) instead of java binary. (python>=3.10 is required)
|
||||
@@ -506,7 +506,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.15.0/openapi-generator-cli-7.15.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.16.0/openapi-generator-cli-7.16.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`
|
||||
|
||||
8
bin/configs/go-server-optional-body.yaml
Normal file
8
bin/configs/go-server-optional-body.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
generatorName: go-server
|
||||
outputDir: samples/server/others/go-server/optional-body
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/optional_body.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/go-server
|
||||
additionalProperties:
|
||||
hideGenerationTimestamp: "true"
|
||||
packageName: petstoreserver
|
||||
addResponseHeaders: true
|
||||
8
bin/configs/jaxrs-cxf-client-swagger2.yaml
Normal file
8
bin/configs/jaxrs-cxf-client-swagger2.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
generatorName: jaxrs-cxf-client
|
||||
outputDir: samples/client/petstore/jaxrs-cxf-client-swagger2
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/JavaJaxRS/cxf
|
||||
additionalProperties:
|
||||
artifactId: jaxrs-cxf-petstore-swagger2
|
||||
documentationProvider: swagger2
|
||||
annotationLibrary: swagger2
|
||||
14
bin/configs/kotlin-spring-boot-additionalproperties.yaml
Normal file
14
bin/configs/kotlin-spring-boot-additionalproperties.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
generatorName: kotlin-spring
|
||||
outputDir: samples/server/petstore/kotlin-springboot-additionalproperties
|
||||
library: spring-boot
|
||||
inputSpec: samples/server/petstore/kotlin-springboot-additionalproperties/src/main/resources/openapi.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
|
||||
additionalProperties:
|
||||
documentationProvider: none
|
||||
annotationLibrary: none
|
||||
useSwaggerUI: "false"
|
||||
serviceImplementation: "true"
|
||||
serializableModel: "true"
|
||||
beanValidations: "true"
|
||||
useSpringBoot3: "true"
|
||||
requestMappingMode: api_interface
|
||||
15
bin/configs/python-httpx.yaml
Normal file
15
bin/configs/python-httpx.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
generatorName: python
|
||||
outputDir: samples/openapi3/client/petstore/python-httpx
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/python
|
||||
library: httpx
|
||||
additionalProperties:
|
||||
packageName: petstore_api
|
||||
mapNumberTo: float
|
||||
poetry1: true
|
||||
nameMappings:
|
||||
_type: underscore_type
|
||||
type_: type_with_underscore
|
||||
modelNameMappings:
|
||||
# The OpenAPI spec ApiResponse conflicts with the internal ApiResponse
|
||||
ApiResponse: ModelApiResponse
|
||||
@@ -5,11 +5,11 @@ Running `./save_dart_keywords.sh` from this directory will generate `dart-keywor
|
||||
|
||||
## When should the keywords be generated?
|
||||
|
||||
`save_dart_keywords.sh` should be run when a new version of Dart is release to update the keywords file.
|
||||
`save_dart_keywords.sh` should be run when a new version of Dart is released to update the keywords file.
|
||||
|
||||
The last Dart version that was used to generate the keywords can be found in `dart-version.txt`.
|
||||
|
||||
## What does the shellscript do?
|
||||
## What does the shell script do?
|
||||
|
||||
1. run the dart app
|
||||
- `dart run save-dart-keywords.dart`
|
||||
|
||||
@@ -61,4 +61,4 @@
|
||||
- filename: "samples/server/petstore/rust-axum/output/rust-axum-oneof/tests/oneof_with_discriminator.rs"
|
||||
sha256: 2d4f5a069fdcb3057bb078d5e75b3de63cd477b97725e457079df24bd2c30600
|
||||
- filename: "samples/server/petstore/rust-axum/output/openapi-v3/tests/oneof_untagged.rs"
|
||||
sha256: e72fbf81a9849dc7abb7e2169f2fc355c8b1cf991c0e2ffc083126abd9e966e7
|
||||
sha256: 1d3fb01f65e98290b1d3eece28014c7d3e3f2fdf18e7110249d3c591cc4642ab
|
||||
|
||||
@@ -5,7 +5,7 @@ title: Debugging
|
||||
|
||||
## Generation
|
||||
|
||||
As a user there may be times when generated outputs don't match your expectations it's unclear why. The CLI supports a `--dry-run` option which may be used to inspect the anticipated file operations without making changes to the file system.
|
||||
As a user there may be times when generated outputs don't match your expectations and it's unclear why. The CLI supports a `--dry-run` option which may be used to inspect the anticipated file operations without making changes to the file system.
|
||||
|
||||
Suppose you generate using the `--minimal-update` option, and you notice on subsequent generations of a client that no files have changed. This is by design.
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||
|sourceFolder|source folder for generated code| |src/main/java|
|
||||
|springApiVersion|Value for 'version' attribute in @RequestMapping (for Spring 7 and above).| |null|
|
||||
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|
||||
|title|server title name or client service name| |OpenAPI Spring|
|
||||
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
|
||||
@@ -132,6 +133,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|x-spring-paginated|Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.|OPERATION|false
|
||||
|x-version-param|Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false|OPERATION_PARAMETER|null
|
||||
|x-pattern-message|Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable|FIELD, OPERATION_PARAMETER|null
|
||||
|x-spring-api-version|Value for 'version' attribute in @RequestMapping (for Spring 7 and above).|OPERATION|null
|
||||
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
---
|
||||
title: Documentation for the postman Generator
|
||||
---
|
||||
|
||||
## METADATA
|
||||
|
||||
| Property | Value | Notes |
|
||||
| -------- | ----- | ----- |
|
||||
| generator name | postman | pass this to the generate command after -g |
|
||||
| generator stability | BETA | |
|
||||
| generator type | DOCUMENTATION | |
|
||||
| generator default templating engine | mustache | |
|
||||
| helpTxt | Generates a postman JSON file | |
|
||||
|
||||
## CONFIG OPTIONS
|
||||
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
|
||||
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|folderStrategy|whether to create folders according to the spec’s paths or tags| |null|
|
||||
|pathParamsAsVariables|whether to create Postman variables for path parameters| |false|
|
||||
|postmanGuid|whether to convert placeholders (i.e. {{UNIQUE_REFERENCE}}) into Postman formula {{$guid}}| |null|
|
||||
|postmanGuidPlaceholderName|name of the placeholder (i.e. {{UNIQUE_REFERENCE}}) to replace with Postman formula {{$guid}}| |null|
|
||||
|postmanIsoTimestamp|whether to convert placeholders (i.e. {{ISO_TIMESTAMP}}) into Postman formula {{$isoTimestamp}}| |null|
|
||||
|postmanIsoTimestampPlaceholderName|name of the placeholder (i.e. {{ISO_TIMESTAMP}}) to replace with Postman formula {{$isoTimestamp}}| |null|
|
||||
|postmanVariables|whether to convert placeholders (i.e. {{VAR_1}}) into Postman variables| |null|
|
||||
|requestParameterGeneration|whether to generate the request parameters based on the schema or the examples| |null|
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
| Type/Alias | Imports |
|
||||
| ---------- | ------- |
|
||||
|
||||
|
||||
## INSTANTIATION TYPES
|
||||
|
||||
| Type/Alias | Instantiated By |
|
||||
| ---------- | --------------- |
|
||||
|
||||
|
||||
## LANGUAGE PRIMITIVES
|
||||
|
||||
<ul class="column-ul">
|
||||
</ul>
|
||||
|
||||
## RESERVED WORDS
|
||||
|
||||
<ul class="column-ul">
|
||||
</ul>
|
||||
|
||||
## FEATURE SET
|
||||
|
||||
|
||||
### Client Modification Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|BasePath|✗|ToolingExtension
|
||||
|Authorizations|✗|ToolingExtension
|
||||
|UserAgent|✗|ToolingExtension
|
||||
|MockServer|✗|ToolingExtension
|
||||
|
||||
### Data Type Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|Custom|✗|OAS2,OAS3
|
||||
|Int32|✓|OAS2,OAS3
|
||||
|Int64|✓|OAS2,OAS3
|
||||
|Float|✓|OAS2,OAS3
|
||||
|Double|✓|OAS2,OAS3
|
||||
|Decimal|✓|ToolingExtension
|
||||
|String|✓|OAS2,OAS3
|
||||
|Byte|✓|OAS2,OAS3
|
||||
|Binary|✓|OAS2,OAS3
|
||||
|Boolean|✓|OAS2,OAS3
|
||||
|Date|✓|OAS2,OAS3
|
||||
|DateTime|✓|OAS2,OAS3
|
||||
|Password|✓|OAS2,OAS3
|
||||
|File|✓|OAS2
|
||||
|Uuid|✗|
|
||||
|Array|✓|OAS2,OAS3
|
||||
|Null|✗|OAS3
|
||||
|AnyType|✗|OAS2,OAS3
|
||||
|Object|✓|OAS2,OAS3
|
||||
|Maps|✓|ToolingExtension
|
||||
|CollectionFormat|✓|OAS2
|
||||
|CollectionFormatMulti|✓|OAS2
|
||||
|Enum|✓|OAS2,OAS3
|
||||
|ArrayOfEnum|✓|ToolingExtension
|
||||
|ArrayOfModel|✓|ToolingExtension
|
||||
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
|
||||
|ArrayOfCollectionOfModel|✓|ToolingExtension
|
||||
|ArrayOfCollectionOfEnum|✓|ToolingExtension
|
||||
|MapOfEnum|✓|ToolingExtension
|
||||
|MapOfModel|✓|ToolingExtension
|
||||
|MapOfCollectionOfPrimitives|✓|ToolingExtension
|
||||
|MapOfCollectionOfModel|✓|ToolingExtension
|
||||
|MapOfCollectionOfEnum|✓|ToolingExtension
|
||||
|
||||
### Documentation Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|Readme|✗|ToolingExtension
|
||||
|Model|✓|ToolingExtension
|
||||
|Api|✓|ToolingExtension
|
||||
|
||||
### Global Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|Host|✓|OAS2,OAS3
|
||||
|BasePath|✓|OAS2,OAS3
|
||||
|Info|✓|OAS2,OAS3
|
||||
|Schemes|✗|OAS2,OAS3
|
||||
|PartialSchemes|✓|OAS2,OAS3
|
||||
|Consumes|✓|OAS2
|
||||
|Produces|✓|OAS2
|
||||
|ExternalDocumentation|✓|OAS2,OAS3
|
||||
|Examples|✓|OAS2,OAS3
|
||||
|XMLStructureDefinitions|✗|OAS2,OAS3
|
||||
|MultiServer|✗|OAS3
|
||||
|ParameterizedServer|✗|OAS3
|
||||
|ParameterStyling|✗|OAS3
|
||||
|Callbacks|✓|OAS3
|
||||
|LinkObjects|✗|OAS3
|
||||
|
||||
### Parameter Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|Path|✓|OAS2,OAS3
|
||||
|Query|✓|OAS2,OAS3
|
||||
|Header|✓|OAS2,OAS3
|
||||
|Body|✓|OAS2
|
||||
|FormUnencoded|✓|OAS2
|
||||
|FormMultipart|✓|OAS2
|
||||
|Cookie|✓|OAS3
|
||||
|
||||
### Schema Support Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|Simple|✓|OAS2,OAS3
|
||||
|Composite|✓|OAS2,OAS3
|
||||
|Polymorphism|✓|OAS2,OAS3
|
||||
|Union|✗|OAS3
|
||||
|allOf|✗|OAS2,OAS3
|
||||
|anyOf|✗|OAS3
|
||||
|oneOf|✗|OAS3
|
||||
|not|✗|OAS3
|
||||
|
||||
### Security Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|BasicAuth|✓|OAS2,OAS3
|
||||
|ApiKey|✓|OAS2,OAS3
|
||||
|OpenIDConnect|✗|OAS3
|
||||
|BearerToken|✓|OAS3
|
||||
|OAuth2_Implicit|✓|OAS2,OAS3
|
||||
|OAuth2_Password|✓|OAS2,OAS3
|
||||
|OAuth2_ClientCredentials|✓|OAS2,OAS3
|
||||
|OAuth2_AuthorizationCode|✓|OAS2,OAS3
|
||||
|SignatureAuth|✗|OAS3
|
||||
|
||||
### Wire Format Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|JSON|✓|OAS2,OAS3
|
||||
|XML|✓|OAS2,OAS3
|
||||
|PROTOBUF|✗|ToolingExtension
|
||||
|Custom|✗|OAS2,OAS3
|
||||
@@ -25,7 +25,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|generateSourceCodeOnly|Specifies that only a library source code is to be generated.| |false|
|
||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||
|lazyImports|Enable lazy imports.| |false|
|
||||
|library|library template (sub-template) to use: asyncio, tornado (deprecated), urllib3| |urllib3|
|
||||
|library|library template (sub-template) to use: asyncio, tornado (deprecated), urllib3, httpx| |urllib3|
|
||||
|mapNumberTo|Map number to Union[StrictFloat, StrictInt], StrictStr or float.| |Union[StrictFloat, StrictInt]|
|
||||
|packageName|python package name (convention: snake_case).| |openapi_client|
|
||||
|packageUrl|python package URL.| |null|
|
||||
|
||||
@@ -77,6 +77,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
<li>dyn</li>
|
||||
<li>else</li>
|
||||
<li>enum</li>
|
||||
<li>errors</li>
|
||||
<li>extern</li>
|
||||
<li>false</li>
|
||||
<li>final</li>
|
||||
@@ -207,8 +208,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|Composite|✓|OAS2,OAS3
|
||||
|Polymorphism|✗|OAS2,OAS3
|
||||
|Union|✗|OAS3
|
||||
|allOf|✗|OAS2,OAS3
|
||||
|anyOf|✗|OAS3
|
||||
|allOf|✓|OAS2,OAS3
|
||||
|anyOf|✓|OAS3
|
||||
|oneOf|✓|OAS3
|
||||
|not|✗|OAS3
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|packageName|Rust package name (convention: lowercase).| |openapi|
|
||||
|packageVersion|Rust package version.| |1.0.0|
|
||||
|preferUnsignedInt|Prefer unsigned integers where minimum value is >= 0| |false|
|
||||
|reqwestDefaultFeatures|Default features for the reqwest dependency (comma-separated). Use empty for no defaults. This option is for 'reqwest' and 'reqwest-trait' library only.| |native-tls|
|
||||
|supportAsync|If set, generate async function call instead. This option is for 'reqwest' library only| |true|
|
||||
|supportMiddleware|If set, add support for reqwest-middleware. This option is for 'reqwest' and 'reqwest-trait' library only| |false|
|
||||
|supportMultipleResponses|If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' and 'reqwest-trait' library only| |false|
|
||||
|
||||
@@ -88,6 +88,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||
|sourceFolder|source folder for generated code| |src/main/java|
|
||||
|springApiVersion|Value for 'version' attribute in @RequestMapping (for Spring 7 and above).| |null|
|
||||
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|
||||
|title|server title name or client service name| |OpenAPI Spring|
|
||||
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
|
||||
@@ -125,6 +126,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|x-spring-paginated|Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.|OPERATION|false
|
||||
|x-version-param|Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false|OPERATION_PARAMETER|null
|
||||
|x-pattern-message|Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable|FIELD, OPERATION_PARAMETER|null
|
||||
|x-spring-api-version|Value for 'version' attribute in @RequestMapping (for Spring 7 and above).|OPERATION|null
|
||||
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
@@ -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.15.0
|
||||
openapi-generator-cli version-manager set 7.16.0
|
||||
```
|
||||
<!-- /RELEASE_VERSION -->
|
||||
To install the tool as a dev dependency in your current project:
|
||||
@@ -119,18 +119,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.15.0/openapi-generator-cli-7.15.0.jar`
|
||||
JAR location: `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.16.0/openapi-generator-cli-7.16.0.jar`
|
||||
|
||||
For **Mac/Linux** users:
|
||||
|
||||
```bash
|
||||
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.15.0/openapi-generator-cli-7.15.0.jar -O openapi-generator-cli.jar
|
||||
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.16.0/openapi-generator-cli-7.16.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.15.0/openapi-generator-cli-7.15.0.jar
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.16.0/openapi-generator-cli-7.16.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.15.0</version>
|
||||
<version>7.16.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.16.0-SNAPSHOT</version>
|
||||
<version>7.17.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.16.0-SNAPSHOT</version>
|
||||
<version>7.17.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -97,7 +97,7 @@ task validateGoodSpec(type: org.openapitools.generator.gradle.plugin.tasks.Valid
|
||||
[source,group]
|
||||
----
|
||||
plugins {
|
||||
id "org.openapi.generator" version "7.15.0"
|
||||
id "org.openapi.generator" version "7.16.0"
|
||||
}
|
||||
----
|
||||
|
||||
@@ -113,7 +113,7 @@ buildscript {
|
||||
// url "https://plugins.gradle.org/m2/"
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:7.15.0"
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:7.16.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -759,7 +759,7 @@ buildscript {
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
classpath('org.openapitools:openapi-generator-gradle-plugin:7.15.0') {
|
||||
classpath('org.openapitools:openapi-generator-gradle-plugin:7.16.0') {
|
||||
exclude group: 'com.google.guava'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# RELEASE_VERSION
|
||||
openApiGeneratorVersion=7.16.0-SNAPSHOT
|
||||
openApiGeneratorVersion=7.17.0-SNAPSHOT
|
||||
# /RELEASE_VERSION
|
||||
|
||||
# BEGIN placeholders
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.16.0-SNAPSHOT</version>
|
||||
<version>7.17.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -19,5 +19,5 @@ gradle generateGoWithInvalidSpec # expected outcome: BUILD FAILED
|
||||
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
|
||||
|
||||
```bash
|
||||
gradle -PopenApiGeneratorVersion=7.15.0 openApiValidate
|
||||
gradle -PopenApiGeneratorVersion=7.16.0 openApiValidate
|
||||
```
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# RELEASE_VERSION
|
||||
openApiGeneratorVersion=7.16.0-SNAPSHOT
|
||||
openApiGeneratorVersion=7.17.0-SNAPSHOT
|
||||
# /RELEASE_VERSION
|
||||
|
||||
@@ -12,7 +12,7 @@ Add to your `build->plugins` section (default phase is `generate-sources` phase)
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.15.0</version>
|
||||
<version>7.16.0</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.16.0-SNAPSHOT</version>
|
||||
<version>7.17.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.16.0-SNAPSHOT</version>
|
||||
<version>7.17.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.16.0-SNAPSHOT</version>
|
||||
<version>7.17.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.16.0-SNAPSHOT</version>
|
||||
<version>7.17.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.16.0-SNAPSHOT</version>
|
||||
<version>7.17.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.16.0-SNAPSHOT</version>
|
||||
<version>7.17.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<version>7.16.0-SNAPSHOT</version>
|
||||
<version>7.17.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.16.0-SNAPSHOT</version>
|
||||
<version>7.17.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.16.0-SNAPSHOT</version>
|
||||
<version>7.17.0-SNAPSHOT</version>
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -456,4 +456,31 @@ public class CodegenConstants {
|
||||
public static final String USE_DEFAULT_VALUES_FOR_REQUIRED_VARS = "useDefaultValuesForRequiredVars";
|
||||
|
||||
public static final String DEFAULT_TO_EMPTY_CONTAINER = "defaultToEmptyContainer";
|
||||
|
||||
// Vendor extensions
|
||||
public static final String X_INTERNAL = "x-internal";
|
||||
public static final String X_PARENT = "x-parent";
|
||||
public static final String X_COMPOSED_DATA_TYPE = "x-composed-data-type";
|
||||
public static final String X_BASE_NAME = "x-base-name";
|
||||
public static final String X_IS_VALUE_TYPE = "x-is-value-type";
|
||||
public static final String X_IS_REFERENCE_TYPE = "x-is-reference-type";
|
||||
public static final String X_IS_NULLABLE_TYPE = "x-is-nullable-type";
|
||||
public static final String X_IS_BASE_OR_NEW_DISCRIMINATOR = "x-is-base-or-new-discriminator";
|
||||
public static final String X_ENUM_BYTE = "x-enum-byte";
|
||||
public static final String X_HTTP_STATUS = "x-http-status";
|
||||
public static final String X_HTTP_STATUSES_WITH_RETURN = "x-http-statuses-with-return";
|
||||
public static final String X_SET_COOKIE = "x-set-cookie";
|
||||
public static final String X_DUPLICATES = "x-duplicates";
|
||||
public static final String X_HTTP_STATUS_IS_DEFAULT = "x-http-status-is-default";
|
||||
public static final String X_ONLY_DEFAULT = "x-only-default";
|
||||
public static final String X_HTTP_STATUS_RANGE = "x-http-status-range";
|
||||
public static final String X_NOT_NULLABLE_REFERENCE_TYPES = "x-not-nullable-reference-types";
|
||||
public static final String X_HAS_NOT_NULLABLE_REFERENCE_TYPES = "x-has-not-nullable-reference-types";
|
||||
public static final String X_NULLABLE_VALUE_TYPE = "x-nullable-value-type";
|
||||
public static final String X_NULLABLE_TYPE = "x-nullable-type";
|
||||
public static final String X_CSHARP_VALUE_TYPE = "x-csharp-value-type";
|
||||
public static final String X_REGEX = "x-regex";
|
||||
public static final String X_MODIFIERS = "x-modifiers";
|
||||
public static final String X_MODIFIER_PREFIX = "x-modifier-";
|
||||
public static final String X_MODEL_IS_MUTABLE = "x-model-is-mutable";
|
||||
}
|
||||
|
||||
@@ -115,6 +115,15 @@ public class CodegenOperation {
|
||||
return nonEmpty(bodyParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there's at least one optional body parameter
|
||||
*
|
||||
* @return true if optional body parameter exists, false otherwise
|
||||
*/
|
||||
public boolean getHasOptionalBodyParam() {
|
||||
return nonEmpty(bodyParams) && nonEmpty(optionalParams) && bodyParams.stream().anyMatch(optionalParams::contains);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there's at least one query parameter
|
||||
*
|
||||
|
||||
@@ -88,8 +88,7 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.DEFAULT_TO_EMPTY_CONTAINER;
|
||||
import static org.openapitools.codegen.CodegenConstants.UNSUPPORTED_V310_SPEC_MSG;
|
||||
import static org.openapitools.codegen.CodegenConstants.*;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.OnceLogger.once;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
@@ -5197,7 +5196,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
String method = p.getKey();
|
||||
Operation op = p.getValue();
|
||||
|
||||
if (op.getExtensions() != null && Boolean.TRUE.equals(op.getExtensions().get("x-internal"))) {
|
||||
if (op.getExtensions() != null && Boolean.TRUE.equals(op.getExtensions().get(X_INTERNAL))) {
|
||||
// skip operation if x-internal sets to true
|
||||
LOGGER.info("Operation ({} {} - {}) not generated since x-internal is set to true",
|
||||
method, expression, op.getOperationId());
|
||||
|
||||
@@ -61,6 +61,7 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.removeStart;
|
||||
import static org.openapitools.codegen.CodegenConstants.X_INTERNAL;
|
||||
import static org.openapitools.codegen.utils.OnceLogger.once;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -486,7 +487,7 @@ public class DefaultGenerator implements Generator {
|
||||
|
||||
Schema schema = ModelUtils.getSchemas(this.openAPI).get(name);
|
||||
|
||||
if (schema.getExtensions() != null && Boolean.TRUE.equals(schema.getExtensions().get("x-internal"))) {
|
||||
if (schema.getExtensions() != null && Boolean.TRUE.equals(schema.getExtensions().get(X_INTERNAL))) {
|
||||
LOGGER.info("Model {} not generated since x-internal is set to true", name);
|
||||
continue;
|
||||
} else if (ModelUtils.isFreeFormObject(schema, openAPI)) { // check to see if it's a free-form object
|
||||
@@ -1564,7 +1565,7 @@ public class DefaultGenerator implements Generator {
|
||||
final List<SecurityRequirement> globalSecurities = openAPI.getSecurity();
|
||||
for (Tag tag : tags) {
|
||||
try {
|
||||
if (operation.getExtensions() != null && Boolean.TRUE.equals(operation.getExtensions().get("x-internal"))) {
|
||||
if (operation.getExtensions() != null && Boolean.TRUE.equals(operation.getExtensions().get(X_INTERNAL))) {
|
||||
// skip operation if x-internal sets to true
|
||||
LOGGER.info("Operation ({} {} - {}) not generated since x-internal is set to true",
|
||||
httpMethod, resourcePath, operation.getOperationId());
|
||||
|
||||
@@ -37,6 +37,8 @@ import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.X_INTERNAL;
|
||||
import static org.openapitools.codegen.CodegenConstants.X_PARENT;
|
||||
import static org.openapitools.codegen.utils.ModelUtils.simplifyOneOfAnyOfWithOnlyOneNonNullSubSchema;
|
||||
import static org.openapitools.codegen.utils.StringUtils.getUniqueString;
|
||||
|
||||
@@ -127,7 +129,6 @@ public class OpenAPINormalizer {
|
||||
|
||||
// when set to true, remove x-internal: true from models, operations
|
||||
final String REMOVE_X_INTERNAL = "REMOVE_X_INTERNAL";
|
||||
final String X_INTERNAL = "x-internal";
|
||||
boolean removeXInternal;
|
||||
|
||||
// when set (e.g. operationId:getPetById|addPet), filter out (or remove) everything else
|
||||
@@ -431,17 +432,17 @@ public class OpenAPINormalizer {
|
||||
for (Operation operation : operations) {
|
||||
if (operationIdFilters.size() > 0) {
|
||||
if (operationIdFilters.contains(operation.getOperationId())) {
|
||||
operation.addExtension("x-internal", false);
|
||||
operation.addExtension(X_INTERNAL, false);
|
||||
} else {
|
||||
LOGGER.info("operation `{}` marked as internal only (x-internal: true) by the operationId FILTER", operation.getOperationId());
|
||||
operation.addExtension("x-internal", true);
|
||||
operation.addExtension(X_INTERNAL, true);
|
||||
}
|
||||
} else if (!tagFilters.isEmpty()) {
|
||||
if (operation.getTags().stream().anyMatch(tagFilters::contains)) {
|
||||
operation.addExtension("x-internal", false);
|
||||
operation.addExtension(X_INTERNAL, false);
|
||||
} else {
|
||||
LOGGER.info("operation `{}` marked as internal only (x-internal: true) by the tag FILTER", operation.getOperationId());
|
||||
operation.addExtension("x-internal", true);
|
||||
operation.addExtension(X_INTERNAL, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -723,15 +724,17 @@ public class OpenAPINormalizer {
|
||||
if (skipNormalization(schema, visitedSchemas)) {
|
||||
return schema;
|
||||
}
|
||||
|
||||
if (ModelUtils.isNullTypeSchema(openAPI, schema)) {
|
||||
return schema;
|
||||
}
|
||||
|
||||
markSchemaAsVisited(schema, visitedSchemas);
|
||||
|
||||
if (ModelUtils.isArraySchema(schema)) { // array
|
||||
Schema result = normalizeArraySchema(schema);
|
||||
normalizeSchema(result.getItems(), visitedSchemas);
|
||||
return result;
|
||||
} else if (schema.getAdditionalProperties() instanceof Schema) { // map
|
||||
normalizeMapSchema(schema);
|
||||
normalizeSchema((Schema) schema.getAdditionalProperties(), visitedSchemas);
|
||||
} else if (ModelUtils.isOneOf(schema)) { // oneOf
|
||||
return normalizeOneOf(schema, visitedSchemas);
|
||||
} else if (ModelUtils.isAnyOf(schema)) { // anyOf
|
||||
@@ -768,6 +771,9 @@ public class OpenAPINormalizer {
|
||||
return schema;
|
||||
} else if (schema.getProperties() != null && !schema.getProperties().isEmpty()) {
|
||||
normalizeProperties(schema.getProperties(), visitedSchemas);
|
||||
} else if (schema.getAdditionalProperties() instanceof Schema) { // map
|
||||
normalizeMapSchema(schema);
|
||||
normalizeSchema((Schema) schema.getAdditionalProperties(), visitedSchemas);
|
||||
} else if (schema instanceof BooleanSchema) {
|
||||
normalizeBooleanSchema(schema, visitedSchemas);
|
||||
} else if (schema instanceof IntegerSchema) {
|
||||
@@ -849,6 +855,20 @@ public class OpenAPINormalizer {
|
||||
}
|
||||
for (Map.Entry<String, Schema> propertiesEntry : properties.entrySet()) {
|
||||
Schema property = propertiesEntry.getValue();
|
||||
|
||||
// remove x-internal if needed (same logic as normalizeComponentsSchemas)
|
||||
if (property.getExtensions() != null && getRule(REMOVE_X_INTERNAL)) {
|
||||
Object xInternalValue = property.getExtensions().get(X_INTERNAL);
|
||||
boolean isInternal = false;
|
||||
if (xInternalValue instanceof Boolean) {
|
||||
isInternal = (Boolean) xInternalValue;
|
||||
} else if (xInternalValue instanceof String) {
|
||||
isInternal = Boolean.parseBoolean((String) xInternalValue);
|
||||
}
|
||||
if (isInternal) {
|
||||
property.getExtensions().remove(X_INTERNAL);
|
||||
}
|
||||
}
|
||||
Schema newProperty = normalizeSchema(property, new HashSet<>());
|
||||
propertiesEntry.setValue(newProperty);
|
||||
}
|
||||
@@ -1011,6 +1031,7 @@ public class OpenAPINormalizer {
|
||||
if (schema.getAnyOf() == null) {
|
||||
return schema;
|
||||
}
|
||||
|
||||
for (int i = 0; i < schema.getAnyOf().size(); i++) {
|
||||
// normalize anyOf sub schemas one by one
|
||||
Object item = schema.getAnyOf().get(i);
|
||||
@@ -1083,10 +1104,10 @@ public class OpenAPINormalizer {
|
||||
refSchema.setExtensions(new HashMap<>());
|
||||
}
|
||||
|
||||
if (refSchema.getExtensions().containsKey("x-parent")) {
|
||||
if (refSchema.getExtensions().containsKey(X_PARENT)) {
|
||||
// doing nothing as x-parent already exists
|
||||
} else {
|
||||
refSchema.getExtensions().put("x-parent", true);
|
||||
refSchema.getExtensions().put(X_PARENT, true);
|
||||
}
|
||||
|
||||
LOGGER.debug("processUseAllOfRefAsParent added `x-parent: true` to {}", refSchema);
|
||||
@@ -1108,7 +1129,7 @@ public class OpenAPINormalizer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Boolean.parseBoolean(String.valueOf(operation.getExtensions().get("x-internal")))) {
|
||||
if (Boolean.parseBoolean(String.valueOf(operation.getExtensions().get(X_INTERNAL)))) {
|
||||
operation.getExtensions().remove(X_INTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public enum VendorExtension {
|
||||
X_KOTLIN_IMPLEMENTS("x-kotlin-implements", ExtensionLevel.MODEL, "Ability to specify interfaces that model must implement", "empty array"),
|
||||
X_KOTLIN_IMPLEMENTS_FIELDS("x-kotlin-implements-fields", ExtensionLevel.MODEL, "Specify attributes that are implemented by the interface(s) added via `x-kotlin-implements`", "empty array"),
|
||||
X_SPRING_PAGINATED("x-spring-paginated", ExtensionLevel.OPERATION, "Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.", "false"),
|
||||
X_SPRING_API_VERSION("x-spring-api-version", ExtensionLevel.OPERATION, "Value for 'version' attribute in @RequestMapping (for Spring 7 and above).", null),
|
||||
X_SPRING_PROVIDE_ARGS("x-spring-provide-args", ExtensionLevel.OPERATION, "Allows adding additional hidden parameters in the API specification to allow access to content such as header values or properties", "empty array"),
|
||||
X_DISCRIMINATOR_VALUE("x-discriminator-value", ExtensionLevel.MODEL, "Used with model inheritance to specify value for discriminator that identifies current model", ""),
|
||||
X_SETTER_EXTRA_ANNOTATION("x-setter-extra-annotation", ExtensionLevel.FIELD, "Custom annotation that can be specified over java setter for specific field", "When field is array & uniqueItems, then this extension is used to add `@JsonDeserialize(as = LinkedHashSet.class)` over setter, otherwise no value"),
|
||||
@@ -26,8 +27,7 @@ public enum VendorExtension {
|
||||
X_OPERATION_EXTRA_ANNOTATION("x-operation-extra-annotation", ExtensionLevel.OPERATION, "List of custom annotations to be added to operation", null),
|
||||
X_VERSION_PARAM("x-version-param", ExtensionLevel.OPERATION_PARAMETER, "Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false", null),
|
||||
X_PATTERN_MESSAGE("x-pattern-message", Arrays.asList(ExtensionLevel.FIELD, ExtensionLevel.OPERATION_PARAMETER), "Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable", null),
|
||||
X_ZERO_BASED_ENUM("x-zero-based-enum", ExtensionLevel.MODEL, "When used on an enum, the index will not be generated and the default numbering will be used, zero-based", "false"),
|
||||
;
|
||||
X_ZERO_BASED_ENUM("x-zero-based-enum", ExtensionLevel.MODEL, "When used on an enum, the index will not be generated and the default numbering will be used, zero-based", "false");
|
||||
|
||||
private final String name;
|
||||
private final List<ExtensionLevel> levels;
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.*;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.ModelUtils.getSchemaItems;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
@@ -543,7 +544,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
if (dataTypeSet.contains(oneOfProperty.dataType)) {
|
||||
// add "x-duplicated-data-type" to indicate if the dataType already occurs before
|
||||
// in other sub-schemas of allOf/anyOf/oneOf
|
||||
oneOfProperty.vendorExtensions.putIfAbsent("x-composed-data-type", true);
|
||||
oneOfProperty.vendorExtensions.putIfAbsent(X_COMPOSED_DATA_TYPE, true);
|
||||
} else {
|
||||
dataTypeSet.add(oneOfProperty.dataType);
|
||||
}
|
||||
@@ -557,7 +558,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
if (dataTypeSet.contains(anyOfProperty.dataType)) {
|
||||
// add "x-duplicated-data-type" to indicate if the dataType already occurs before
|
||||
// in other sub-schemas of allOf/anyOf/oneOf
|
||||
anyOfProperty.vendorExtensions.putIfAbsent("x-composed-data-type", true);
|
||||
anyOfProperty.vendorExtensions.putIfAbsent(X_COMPOSED_DATA_TYPE, true);
|
||||
} else {
|
||||
dataTypeSet.add(anyOfProperty.dataType);
|
||||
}
|
||||
@@ -619,7 +620,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
continue;
|
||||
}
|
||||
|
||||
model.vendorExtensions.put("x-model-is-mutable", modelIsMutable(model, null));
|
||||
model.vendorExtensions.put(X_MODEL_IS_MUTABLE, modelIsMutable(model, null));
|
||||
|
||||
CodegenComposedSchemas composedSchemas = model.getComposedSchemas();
|
||||
if (composedSchemas != null) {
|
||||
@@ -639,7 +640,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
patchProperty(enumRefs, model, property);
|
||||
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
|
||||
property.isNullable = true;
|
||||
property.vendorExtensions.put("x-base-name", model.name.substring(model.name.lastIndexOf('_') + 1));
|
||||
property.vendorExtensions.put(X_BASE_NAME, model.name.substring(model.name.lastIndexOf('_') + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -650,7 +651,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
patchProperty(enumRefs, model, property);
|
||||
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
|
||||
property.isNullable = true;
|
||||
property.vendorExtensions.put("x-base-name", model.name.substring(model.name.lastIndexOf('_') + 1));
|
||||
property.vendorExtensions.put(X_BASE_NAME, model.name.substring(model.name.lastIndexOf('_') + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -752,9 +753,13 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes nested maps so the generic type is defined
|
||||
* Convertes List<List>> to List<List<T>>
|
||||
/**
|
||||
* Ensures property name is unique and not a reserved word.
|
||||
* @param model
|
||||
* @param property
|
||||
* @param value
|
||||
* @param composedPropertyNames
|
||||
* @return
|
||||
*/
|
||||
private String patchPropertyName(CodegenModel model, CodegenProperty property, String value, Set<String> composedPropertyNames) {
|
||||
value = setUniquePropertyName(model, property, value);
|
||||
@@ -784,15 +789,19 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
|
||||
private void patchPropertyVendorExtensions(CodegenProperty property) {
|
||||
boolean isValueType = isValueType(property);
|
||||
property.vendorExtensions.put("x-is-value-type", isValueType);
|
||||
property.vendorExtensions.put("x-is-reference-type", !isValueType);
|
||||
property.vendorExtensions.put("x-is-nullable-type", this.getNullableReferencesTypes() || isValueType);
|
||||
property.vendorExtensions.put("x-is-base-or-new-discriminator", (property.isDiscriminator && !property.isInherited) || (property.isDiscriminator && property.isNew));
|
||||
property.vendorExtensions.put(X_IS_VALUE_TYPE, isValueType);
|
||||
property.vendorExtensions.put(X_IS_REFERENCE_TYPE, !isValueType);
|
||||
property.vendorExtensions.put(X_IS_NULLABLE_TYPE, this.getNullableReferencesTypes() || isValueType);
|
||||
property.vendorExtensions.put(X_IS_BASE_OR_NEW_DISCRIMINATOR, (property.isDiscriminator && !property.isInherited) || (property.isDiscriminator && property.isNew));
|
||||
}
|
||||
|
||||
protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes nested maps so the generic type is defined
|
||||
* Convertes List<List>> to List<List<T>>
|
||||
*/
|
||||
private void patchNestedMaps(CodegenProperty property) {
|
||||
// Process nested types before making any replacements to ensure we have the correct inner type
|
||||
if (property.items != null) {
|
||||
@@ -824,6 +833,41 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes nested maps so the generic type is defined
|
||||
* Convertes List<List>> to List<List<T>>
|
||||
*/
|
||||
private void patchNestedMaps(CodegenResponse response) {
|
||||
// Process nested types before making any replacements to ensure we have the correct inner type
|
||||
if (response.items != null) {
|
||||
patchNestedMaps(response.items);
|
||||
}
|
||||
|
||||
String[] nestedTypes = {"List", "Collection", "ICollection", "Dictionary"};
|
||||
|
||||
if (response.dataType != null) {
|
||||
String originalType = response.dataType;
|
||||
|
||||
for (String nestedType : nestedTypes) {
|
||||
// fix incorrect data types for maps of maps
|
||||
if (response.items != null) {
|
||||
if (response.dataType.contains(", " + nestedType + ">")) {
|
||||
response.dataType = response.dataType.replace(", " + nestedType + ">", ", " + response.items.datatypeWithEnum + ">");
|
||||
}
|
||||
|
||||
if (response.dataType.contains("<" + nestedType + ">")) {
|
||||
response.dataType = response.dataType.replace("<" + nestedType + ">", "<" + response.items.datatypeWithEnum + ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only update dataType if we actually made changes
|
||||
if (!originalType.equals(response.dataType)) {
|
||||
response.dataType = response.dataType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel model, CodegenProperty property) {
|
||||
if (enumRefs.containsKey(property.dataType)) {
|
||||
// Handle any enum properties referred to by $ref.
|
||||
@@ -888,7 +932,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
// Because C# uses nullable primitives for datatype, and datatype is used in DefaultCodegen for determining enum-ness, guard against weirdness here.
|
||||
if (var.isEnum) {
|
||||
if ("byte".equals(var.dataFormat)) {// C# Actually supports byte and short enums.
|
||||
var.vendorExtensions.put("x-enum-byte", true);
|
||||
var.vendorExtensions.put(X_ENUM_BYTE, true);
|
||||
var.isString = false;
|
||||
var.isLong = false;
|
||||
var.isInteger = false;
|
||||
@@ -909,7 +953,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
}
|
||||
|
||||
private void postProcessResponseCode(CodegenResponse response, String status, Set<String> httpStatusesWithReturn) {
|
||||
response.vendorExtensions.put("x-http-status", status);
|
||||
response.vendorExtensions.put(X_HTTP_STATUS, status);
|
||||
if (response.dataType != null) {
|
||||
httpStatusesWithReturn.add(status);
|
||||
}
|
||||
@@ -942,11 +986,11 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
}
|
||||
|
||||
private void postProcessOperations(OperationMap operations, List<ModelMap> allModels) {
|
||||
Set<String> httpStatusesWithReturn = additionalProperties.get("x-http-statuses-with-return") instanceof Set<?>
|
||||
? (Set<String>) additionalProperties.get("x-http-statuses-with-return")
|
||||
Set<String> httpStatusesWithReturn = additionalProperties.get(X_HTTP_STATUSES_WITH_RETURN) instanceof Set<?>
|
||||
? (Set<String>) additionalProperties.get(X_HTTP_STATUSES_WITH_RETURN)
|
||||
: new HashSet<String>();
|
||||
|
||||
additionalProperties.put("x-http-statuses-with-return", httpStatusesWithReturn);
|
||||
additionalProperties.put(X_HTTP_STATUSES_WITH_RETURN, httpStatusesWithReturn);
|
||||
|
||||
HashMap<String, CodegenModel> modelMaps = ModelMap.toCodegenModelMap(allModels);
|
||||
|
||||
@@ -955,22 +999,23 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
for (CodegenOperation operation : ops) {
|
||||
String duplicates = duplicateOf.get(operation.operationId);
|
||||
if (duplicates != null) {
|
||||
operation.vendorExtensions.put("x-duplicates", duplicates);
|
||||
operation.vendorExtensions.put(X_DUPLICATES, duplicates);
|
||||
} else {
|
||||
duplicateOf.put(operation.operationId, operations.getClassname());
|
||||
}
|
||||
if (operation.responses != null) {
|
||||
for (CodegenResponse response : operation.responses) {
|
||||
patchNestedMaps(response);
|
||||
|
||||
if (response.returnProperty != null) {
|
||||
Boolean isValueType = isValueType(response.returnProperty);
|
||||
response.vendorExtensions.put("x-is-value-type", isValueType);
|
||||
response.vendorExtensions.put("x-is-reference-type", !isValueType);
|
||||
response.vendorExtensions.put(X_IS_VALUE_TYPE, isValueType);
|
||||
response.vendorExtensions.put(X_IS_REFERENCE_TYPE, !isValueType);
|
||||
}
|
||||
|
||||
if (response.headers != null && response.headers.stream().anyMatch(h -> h.baseName.equals("Set-Cookie"))) {
|
||||
response.vendorExtensions.put("x-set-cookie", true);
|
||||
operation.vendorExtensions.put("x-set-cookie", true);
|
||||
response.vendorExtensions.put(X_SET_COOKIE, true);
|
||||
operation.vendorExtensions.put(X_SET_COOKIE, true);
|
||||
}
|
||||
|
||||
String code = response.code.toLowerCase(Locale.ROOT);
|
||||
@@ -978,9 +1023,9 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
case "default":
|
||||
case "0":
|
||||
postProcessResponseCode(response, "Default", httpStatusesWithReturn);
|
||||
response.vendorExtensions.put("x-http-status-is-default", true);
|
||||
response.vendorExtensions.put(X_HTTP_STATUS_IS_DEFAULT, true);
|
||||
if ((long) operation.responses.size() == 1) {
|
||||
response.vendorExtensions.put("x-only-default", true);
|
||||
response.vendorExtensions.put(X_ONLY_DEFAULT, true);
|
||||
}
|
||||
break;
|
||||
case "100":
|
||||
@@ -1161,23 +1206,23 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
postProcessResponseCode(response, "NetworkAuthenticationRequired", httpStatusesWithReturn);
|
||||
break;
|
||||
case "1xx":
|
||||
response.vendorExtensions.put("x-http-status-range", 1);
|
||||
response.vendorExtensions.put(X_HTTP_STATUS_RANGE, 1);
|
||||
postProcessResponseCode(response, "HttpStatusCode1XX", httpStatusesWithReturn);
|
||||
break;
|
||||
case "2xx":
|
||||
response.vendorExtensions.put("x-http-status-range", 2);
|
||||
response.vendorExtensions.put(X_HTTP_STATUS_RANGE, 2);
|
||||
postProcessResponseCode(response, "HttpStatusCode2XX", httpStatusesWithReturn);
|
||||
break;
|
||||
case "3xx":
|
||||
response.vendorExtensions.put("x-http-status-range", 3);
|
||||
response.vendorExtensions.put(X_HTTP_STATUS_RANGE, 3);
|
||||
postProcessResponseCode(response, "HttpStatusCode3XX", httpStatusesWithReturn);
|
||||
break;
|
||||
case "4xx":
|
||||
response.vendorExtensions.put("x-http-status-range", 4);
|
||||
response.vendorExtensions.put(X_HTTP_STATUS_RANGE, 4);
|
||||
postProcessResponseCode(response, "HttpStatusCode4XX", httpStatusesWithReturn);
|
||||
break;
|
||||
case "5xx":
|
||||
response.vendorExtensions.put("x-http-status-range", 5);
|
||||
response.vendorExtensions.put(X_HTTP_STATUS_RANGE, 5);
|
||||
postProcessResponseCode(response, "HttpStatusCode5XX", httpStatusesWithReturn);
|
||||
break;
|
||||
default:
|
||||
@@ -1278,9 +1323,9 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
patchParameter(model, parameter);
|
||||
}
|
||||
|
||||
List<CodegenParameter> referenceTypes = operation.allParams.stream().filter(p -> p.vendorExtensions.get("x-is-value-type") == null && !p.isNullable).collect(Collectors.toList());
|
||||
operation.vendorExtensions.put("x-not-nullable-reference-types", referenceTypes);
|
||||
operation.vendorExtensions.put("x-has-not-nullable-reference-types", referenceTypes.size() > 0);
|
||||
List<CodegenParameter> referenceTypes = operation.allParams.stream().filter(p -> p.vendorExtensions.get(X_IS_VALUE_TYPE) == null && !p.isNullable).collect(Collectors.toList());
|
||||
operation.vendorExtensions.put(X_NOT_NULLABLE_REFERENCE_TYPES, referenceTypes);
|
||||
operation.vendorExtensions.put(X_HAS_NOT_NULLABLE_REFERENCE_TYPES, referenceTypes.size() > 0);
|
||||
processOperation(operation);
|
||||
|
||||
// Remove constant params from allParams list and add to constantParams
|
||||
@@ -1291,7 +1336,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
|
||||
protected void patchVendorExtensionNullableValueType(CodegenParameter parameter) {
|
||||
if (parameter.isNullable && !parameter.isContainer && (this.getValueTypes().contains(parameter.dataType) || parameter.isEnum)) {
|
||||
parameter.vendorExtensions.put("x-nullable-value-type", true);
|
||||
parameter.vendorExtensions.put(X_NULLABLE_VALUE_TYPE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1307,15 +1352,15 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
*/
|
||||
protected void patchVendorExtensionNullableValueTypeLegacy(CodegenParameter parameter) {
|
||||
if (parameter.isNullable && !parameter.isContainer && (this.getNullableTypes().contains(parameter.dataType) || parameter.isEnum)) {
|
||||
parameter.vendorExtensions.put("x-nullable-value-type", true);
|
||||
parameter.vendorExtensions.put(X_NULLABLE_VALUE_TYPE, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void patchParameter(CodegenModel model, CodegenParameter parameter) {
|
||||
patchVendorExtensionNullableValueType(parameter);
|
||||
|
||||
if (this.getNullableReferencesTypes() || (parameter.vendorExtensions.get("x-nullable-value-type") != null)) {
|
||||
parameter.vendorExtensions.put("x-nullable-type", true);
|
||||
if (this.getNullableReferencesTypes() || (parameter.vendorExtensions.get(X_NULLABLE_VALUE_TYPE) != null)) {
|
||||
parameter.vendorExtensions.put(X_NULLABLE_TYPE, true);
|
||||
}
|
||||
|
||||
if (!isSupportNullable()) {
|
||||
@@ -1362,12 +1407,12 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
parameter.isEnum = true;
|
||||
parameter.allowableValues = model.allowableValues;
|
||||
parameter.isPrimitiveType = true;
|
||||
parameter.vendorExtensions.put("x-csharp-value-type", true);
|
||||
parameter.vendorExtensions.put(X_CSHARP_VALUE_TYPE, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!parameter.isContainer && this.getNullableTypes().contains(parameter.dataType)) {
|
||||
parameter.vendorExtensions.put("x-csharp-value-type", true);
|
||||
parameter.vendorExtensions.put(X_CSHARP_VALUE_TYPE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1377,12 +1422,12 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
parameter.isEnum = true;
|
||||
parameter.allowableValues = model.allowableValues;
|
||||
parameter.isPrimitiveType = true;
|
||||
parameter.vendorExtensions.put("x-is-value-type", true);
|
||||
parameter.vendorExtensions.put(X_IS_VALUE_TYPE, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!parameter.isContainer && this.getValueTypes().contains(parameter.dataType)) {
|
||||
parameter.vendorExtensions.put("x-is-value-type", true);
|
||||
parameter.vendorExtensions.put(X_IS_VALUE_TYPE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2050,13 +2095,13 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
} else if (c == 'l') {
|
||||
modifiers.remove("CultureInvariant");
|
||||
} else {
|
||||
vendorExtensions.put("x-modifier-" + c, c);
|
||||
vendorExtensions.put(X_MODIFIER_PREFIX + c, c);
|
||||
}
|
||||
}
|
||||
|
||||
String regex = pattern.substring(start, end).replace("\"", "\"\"");
|
||||
vendorExtensions.put("x-regex", regex);
|
||||
vendorExtensions.put("x-modifiers", modifiers);
|
||||
vendorExtensions.put(X_REGEX, regex);
|
||||
vendorExtensions.put(X_MODIFIERS, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.X_ENUM_BYTE;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
@@ -433,7 +434,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
if (model.dataType.startsWith("byte")) {
|
||||
// F# Actually supports byte and short enums, swagger spec only supports byte.
|
||||
isByte = true;
|
||||
model.vendorExtensions.put("x-enum-byte", true);
|
||||
model.vendorExtensions.put(X_ENUM_BYTE, true);
|
||||
} else if (model.dataType.startsWith("int32")) {
|
||||
isInteger = true;
|
||||
model.vendorExtensions.put("x-enum-integer", true);
|
||||
@@ -487,7 +488,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
// Because C# uses nullable primitives for datatype, and datatype is used in DefaultCodegen for determining enum-ness, guard against weirdness here.
|
||||
if (var.isEnum) {
|
||||
if ("byte".equals(var.dataFormat)) {// C# Actually supports byte and short enums.
|
||||
var.vendorExtensions.put("x-enum-byte", true);
|
||||
var.vendorExtensions.put(X_ENUM_BYTE, true);
|
||||
var.isString = false;
|
||||
var.isLong = false;
|
||||
var.isInteger = false;
|
||||
|
||||
@@ -40,6 +40,8 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.X_MODIFIERS;
|
||||
import static org.openapitools.codegen.CodegenConstants.X_REGEX;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
|
||||
@@ -1353,9 +1355,9 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
|
||||
}
|
||||
}
|
||||
|
||||
vendorExtensions.put("x-regex", regex.replace("\"", "\\\""));
|
||||
vendorExtensions.put(X_REGEX, regex.replace("\"", "\\\""));
|
||||
vendorExtensions.put("x-pattern", pattern.replace("\"", "\\\""));
|
||||
vendorExtensions.put("x-modifiers", modifiers);
|
||||
vendorExtensions.put(X_MODIFIERS, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.X_MODIFIERS;
|
||||
import static org.openapitools.codegen.CodegenConstants.X_REGEX;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public abstract class AbstractPythonConnexionServerCodegen extends AbstractPythonCodegen implements CodegenConfig {
|
||||
@@ -743,8 +745,8 @@ public abstract class AbstractPythonConnexionServerCodegen extends AbstractPytho
|
||||
}
|
||||
}
|
||||
|
||||
vendorExtensions.put("x-regex", regex);
|
||||
vendorExtensions.put("x-modifiers", modifiers);
|
||||
vendorExtensions.put(X_REGEX, regex);
|
||||
vendorExtensions.put(X_MODIFIERS, modifiers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.X_MODIFIERS;
|
||||
import static org.openapitools.codegen.CodegenConstants.X_REGEX;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public abstract class AbstractPythonPydanticV1Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
@@ -1915,9 +1917,9 @@ public abstract class AbstractPythonPydanticV1Codegen extends DefaultCodegen imp
|
||||
}
|
||||
}
|
||||
|
||||
vendorExtensions.put("x-regex", regex.replace("\"", "\\\""));
|
||||
vendorExtensions.put(X_REGEX, regex.replace("\"", "\\\""));
|
||||
vendorExtensions.put("x-pattern", pattern.replace("\"", "\\\""));
|
||||
vendorExtensions.put("x-modifiers", modifiers);
|
||||
vendorExtensions.put(X_MODIFIERS, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
import static java.util.UUID.randomUUID;
|
||||
import static org.openapitools.codegen.CodegenConstants.X_CSHARP_VALUE_TYPE;
|
||||
|
||||
public class AspNetServerCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@@ -347,7 +348,7 @@ public class AspNetServerCodegen extends AbstractCSharpCodegen {
|
||||
protected void updateCodegenParameterEnum(CodegenParameter parameter, CodegenModel model) {
|
||||
super.updateCodegenParameterEnumLegacy(parameter, model);
|
||||
|
||||
if (!parameter.required && parameter.vendorExtensions.get("x-csharp-value-type") != null) { //optional
|
||||
if (!parameter.required && parameter.vendorExtensions.get(X_CSHARP_VALUE_TYPE) != null) { //optional
|
||||
parameter.dataType = parameter.dataType + "?";
|
||||
}
|
||||
}
|
||||
@@ -627,7 +628,7 @@ public class AspNetServerCodegen extends AbstractCSharpCodegen {
|
||||
super.patchProperty(enumRefs, model, property);
|
||||
|
||||
if (!property.isContainer && (this.getNullableTypes().contains(property.dataType) || property.isEnum)) {
|
||||
property.vendorExtensions.put("x-csharp-value-type", true);
|
||||
property.vendorExtensions.put(X_CSHARP_VALUE_TYPE, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
import static org.openapitools.codegen.CodegenConstants.X_CSHARP_VALUE_TYPE;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
@@ -409,7 +410,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
super.updateCodegenParameterEnumLegacy(parameter, model);
|
||||
|
||||
if (!parameter.required && parameter.vendorExtensions.get("x-csharp-value-type") != null) { //optional
|
||||
if (!parameter.required && parameter.vendorExtensions.get(X_CSHARP_VALUE_TYPE) != null) { //optional
|
||||
parameter.dataType = parameter.dataType + "?";
|
||||
}
|
||||
}
|
||||
@@ -1626,7 +1627,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
if (!GENERICHOST.equals(getLibrary())) {
|
||||
if (!property.isContainer && (this.getNullableTypes().contains(property.dataType) || property.isEnum)) {
|
||||
property.vendorExtensions.put("x-csharp-value-type", true);
|
||||
property.vendorExtensions.put(X_CSHARP_VALUE_TYPE, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
import static java.util.UUID.randomUUID;
|
||||
import static org.openapitools.codegen.CodegenConstants.X_CSHARP_VALUE_TYPE;
|
||||
|
||||
public class CSharpFunctionsServerCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@@ -287,7 +288,7 @@ public class CSharpFunctionsServerCodegen extends AbstractCSharpCodegen {
|
||||
super.patchProperty(enumRefs, model, property);
|
||||
|
||||
if (!property.isContainer && (this.getNullableTypes().contains(property.dataType) || property.isEnum)) {
|
||||
property.vendorExtensions.put("x-csharp-value-type", true);
|
||||
property.vendorExtensions.put(X_CSHARP_VALUE_TYPE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,7 +296,7 @@ public class CSharpFunctionsServerCodegen extends AbstractCSharpCodegen {
|
||||
protected void updateCodegenParameterEnum(CodegenParameter parameter, CodegenModel model) {
|
||||
super.updateCodegenParameterEnumLegacy(parameter, model);
|
||||
|
||||
if (!parameter.required && parameter.vendorExtensions.get("x-csharp-value-type") != null) { //optional
|
||||
if (!parameter.required && parameter.vendorExtensions.get(X_CSHARP_VALUE_TYPE) != null) { //optional
|
||||
parameter.dataType = parameter.dataType + "?";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
import static org.openapitools.codegen.CodegenConstants.X_CSHARP_VALUE_TYPE;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
@@ -350,7 +351,7 @@ public class CSharpReducedClientCodegen extends AbstractCSharpCodegen {
|
||||
super.patchProperty(enumRefs, model, property);
|
||||
|
||||
if (!property.isContainer && (this.getNullableTypes().contains(property.dataType) || property.isEnum)) {
|
||||
property.vendorExtensions.put("x-csharp-value-type", true);
|
||||
property.vendorExtensions.put(X_CSHARP_VALUE_TYPE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,7 +359,7 @@ public class CSharpReducedClientCodegen extends AbstractCSharpCodegen {
|
||||
protected void updateCodegenParameterEnum(CodegenParameter parameter, CodegenModel model) {
|
||||
super.updateCodegenParameterEnumLegacy(parameter, model);
|
||||
|
||||
if (!parameter.required && parameter.vendorExtensions.get("x-csharp-value-type") != null) { //optional
|
||||
if (!parameter.required && parameter.vendorExtensions.get(X_CSHARP_VALUE_TYPE) != null) { //optional
|
||||
parameter.dataType = parameter.dataType + "?";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +226,7 @@ public class ElixirClientCodegen extends DefaultCodegen {
|
||||
typeMapping.put("date", "Date.t");
|
||||
typeMapping.put("date-time", "DateTime.t");
|
||||
// other
|
||||
typeMapping.put("AnyType", "any()");
|
||||
typeMapping.put("ByteArray", "binary()");
|
||||
typeMapping.put("DateTime", "DateTime.t");
|
||||
typeMapping.put("UUID", "String.t");
|
||||
|
||||
@@ -410,6 +410,7 @@ public class GoServerCodegen extends AbstractGoCodegen {
|
||||
private void addConditionalImportInformation(OperationsMap operations) {
|
||||
boolean hasPathParams = false;
|
||||
boolean hasBodyParams = false;
|
||||
boolean hasOptionalBodyParams = false;
|
||||
|
||||
for (CodegenOperation op : operations.getOperations().getOperation()) {
|
||||
if (op.getHasPathParams()) {
|
||||
@@ -418,10 +419,14 @@ public class GoServerCodegen extends AbstractGoCodegen {
|
||||
if (op.getHasBodyParam()) {
|
||||
hasBodyParams = true;
|
||||
}
|
||||
if (op.getHasOptionalBodyParam()) {
|
||||
hasOptionalBodyParams = true;
|
||||
}
|
||||
}
|
||||
|
||||
additionalProperties.put("hasPathParams", hasPathParams);
|
||||
additionalProperties.put("hasBodyParams", hasBodyParams);
|
||||
additionalProperties.put("hasOptionalBodyParams", hasOptionalBodyParams);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -996,6 +996,7 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
private Stream<List<CodegenProperty>> getAllVarProperties(CodegenModel model) {
|
||||
return Stream.of(model.vars, model.allVars, model.optionalVars, model.requiredVars, model.readOnlyVars, model.readWriteVars);
|
||||
}
|
||||
@@ -1113,6 +1114,27 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
super.postProcessParameter(parameter);
|
||||
adjustEnumRefDefault(parameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Properly set the default value for enum (reference).
|
||||
*
|
||||
* @param param codegen parameter
|
||||
*/
|
||||
private void adjustEnumRefDefault(CodegenParameter param) {
|
||||
if (StringUtils.isEmpty(param.defaultValue) || !(param.isEnum || param.isEnumRef)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String type = StringUtils.defaultIfEmpty(param.datatypeWithEnum, param.dataType);
|
||||
param.enumDefaultValue = toEnumVarName(param.defaultValue, type);
|
||||
param.defaultValue = type + "." + param.enumDefaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcess() {
|
||||
System.out.println("################################################################################");
|
||||
|
||||
@@ -157,7 +157,8 @@ public class PythonClientCodegen extends AbstractPythonCodegen implements Codege
|
||||
supportedLibraries.put("urllib3", "urllib3-based client");
|
||||
supportedLibraries.put("asyncio", "asyncio-based client");
|
||||
supportedLibraries.put("tornado", "tornado-based client (deprecated)");
|
||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use: asyncio, tornado (deprecated), urllib3");
|
||||
supportedLibraries.put("httpx", "httpx-based client");
|
||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use: asyncio, tornado (deprecated), urllib3, httpx");
|
||||
libraryOption.setDefault(DEFAULT_LIBRARY);
|
||||
cliOptions.add(libraryOption);
|
||||
setLibrary(DEFAULT_LIBRARY);
|
||||
@@ -330,10 +331,15 @@ public class PythonClientCodegen extends AbstractPythonCodegen implements Codege
|
||||
|
||||
if ("asyncio".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("asyncio/rest.mustache", packagePath(), "rest.py"));
|
||||
additionalProperties.put("async", "true");
|
||||
additionalProperties.put("asyncio", "true");
|
||||
} else if ("tornado".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("tornado/rest.mustache", packagePath(), "rest.py"));
|
||||
additionalProperties.put("tornado", "true");
|
||||
} else if ("httpx".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("httpx/rest.mustache", packagePath(), "rest.py"));
|
||||
additionalProperties.put("async", "true");
|
||||
additionalProperties.put("httpx", "true");
|
||||
} else {
|
||||
supportingFiles.add(new SupportingFile("rest.mustache", packagePath(), "rest.py"));
|
||||
}
|
||||
|
||||
@@ -99,6 +99,18 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
public RustAxumServerCodegen() {
|
||||
super();
|
||||
|
||||
// The `#[validate(nested)]` macro relies on an internal field named `errors` to accumulate validation results. Therefore, defining a struct like this will fail:
|
||||
//
|
||||
// ```rust
|
||||
// struct A {
|
||||
// #[validate(nested)]
|
||||
// errors: B,
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// To avoid this, either rename the field to something other than "errors", or reserve it.
|
||||
this.reservedWords.add("errors");
|
||||
|
||||
modifyFeatureSet(features -> features
|
||||
.wireFormatFeatures(EnumSet.of(
|
||||
WireFormatFeature.JSON,
|
||||
@@ -112,7 +124,9 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
.schemaSupportFeatures(EnumSet.of(
|
||||
SchemaSupportFeature.Simple,
|
||||
SchemaSupportFeature.Composite,
|
||||
SchemaSupportFeature.oneOf
|
||||
SchemaSupportFeature.oneOf,
|
||||
SchemaSupportFeature.anyOf,
|
||||
SchemaSupportFeature.allOf
|
||||
))
|
||||
.excludeGlobalFeatures(
|
||||
GlobalFeature.Info,
|
||||
@@ -633,105 +647,163 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
return op;
|
||||
}
|
||||
|
||||
private void postProcessOneOfModels(List<ModelMap> allModels) {
|
||||
final HashMap<String, List<String>> oneOfMapDiscriminator = new HashMap<>();
|
||||
private void postProcessPolymorphism(final List<ModelMap> allModels) {
|
||||
final HashMap<String, List<String>> discriminatorsForModel = new HashMap<>();
|
||||
|
||||
for (ModelMap mo : allModels) {
|
||||
for (final ModelMap mo : allModels) {
|
||||
final CodegenModel cm = mo.getModel();
|
||||
|
||||
final CodegenComposedSchemas cs = cm.getComposedSchemas();
|
||||
if (cs != null) {
|
||||
final List<CodegenProperty> csOneOf = cs.getOneOf();
|
||||
|
||||
if (csOneOf != null) {
|
||||
for (CodegenProperty model : csOneOf) {
|
||||
// Generate a valid name for the enum variant.
|
||||
// Mainly needed for primitive types.
|
||||
|
||||
model.datatypeWithEnum = camelize(model.dataType.replaceAll("(?:\\w+::)+(\\w+)", "$1")
|
||||
.replace("<", "Of").replace(">", ""));
|
||||
|
||||
// Primitive type is not properly set, this overrides it to guarantee adequate model generation.
|
||||
if (!model.getDataType().matches(String.format(Locale.ROOT, ".*::%s", model.getDatatypeWithEnum()))) {
|
||||
model.isPrimitiveType = true;
|
||||
}
|
||||
}
|
||||
|
||||
processPolymorphismDataType(csOneOf);
|
||||
cs.setOneOf(csOneOf);
|
||||
cm.setComposedSchemas(cs);
|
||||
}
|
||||
|
||||
final List<CodegenProperty> csAnyOf = cs.getAnyOf();
|
||||
if (csAnyOf != null) {
|
||||
processPolymorphismDataType(csAnyOf);
|
||||
cs.setAnyOf(csAnyOf);
|
||||
cm.setComposedSchemas(cs);
|
||||
}
|
||||
}
|
||||
|
||||
if (cm.discriminator != null) {
|
||||
for (String model : cm.oneOf) {
|
||||
List<String> discriminators = oneOfMapDiscriminator.getOrDefault(model, new ArrayList<>());
|
||||
for (final String model : cm.oneOf) {
|
||||
final List<String> discriminators = discriminatorsForModel.getOrDefault(model, new ArrayList<>());
|
||||
discriminators.add(cm.discriminator.getPropertyName());
|
||||
oneOfMapDiscriminator.put(model, discriminators);
|
||||
discriminatorsForModel.put(model, discriminators);
|
||||
}
|
||||
|
||||
for (final String model : cm.anyOf) {
|
||||
final List<String> discriminators = discriminatorsForModel.getOrDefault(model, new ArrayList<>());
|
||||
discriminators.add(cm.discriminator.getPropertyName());
|
||||
discriminatorsForModel.put(model, discriminators);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final var blocking = new HashSet<String>();
|
||||
for (ModelMap mo : allModels) {
|
||||
final CodegenModel cm = mo.getModel();
|
||||
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
var.isDiscriminator = false;
|
||||
final List<String> discriminators = discriminatorsForModel.get(cm.getSchemaName());
|
||||
if (discriminators != null) {
|
||||
// If the discriminator field is not a defined attribute in the variant structure, create it.
|
||||
if (!discriminating(discriminators, cm)) {
|
||||
final String discriminator = discriminators.get(0);
|
||||
|
||||
CodegenProperty property = new CodegenProperty();
|
||||
|
||||
// Static attributes
|
||||
// Only strings are supported by serde for tag field types, so it's the only one we'll deal with
|
||||
property.openApiType = "string";
|
||||
property.complexType = "string";
|
||||
property.dataType = "String";
|
||||
property.datatypeWithEnum = "String";
|
||||
property.baseType = "string";
|
||||
property.required = true;
|
||||
property.isPrimitiveType = true;
|
||||
property.isString = true;
|
||||
property.isDiscriminator = true;
|
||||
|
||||
// Attributes based on the discriminator value
|
||||
property.baseName = discriminator;
|
||||
property.name = discriminator;
|
||||
property.nameInCamelCase = camelize(discriminator);
|
||||
property.nameInPascalCase = property.nameInCamelCase.substring(0, 1).toUpperCase(Locale.ROOT) + property.nameInCamelCase.substring(1);
|
||||
property.nameInSnakeCase = underscore(discriminator).toUpperCase(Locale.ROOT);
|
||||
property.getter = String.format(Locale.ROOT, "get%s", property.nameInPascalCase);
|
||||
property.setter = String.format(Locale.ROOT, "set%s", property.nameInPascalCase);
|
||||
property.defaultValueWithParam = String.format(Locale.ROOT, " = data.%s;", property.name);
|
||||
|
||||
// Attributes based on the model name
|
||||
property.defaultValue = String.format(Locale.ROOT, "r#\"%s\"#.to_string()", cm.getSchemaName());
|
||||
property.jsonSchema = String.format(Locale.ROOT, "{ \"default\":\"%s\"; \"type\":\"string\" }", cm.getSchemaName());
|
||||
|
||||
cm.vars.add(property);
|
||||
}
|
||||
}
|
||||
|
||||
final List<String> discriminatorsForModel = oneOfMapDiscriminator.get(cm.getSchemaName());
|
||||
if (cm.vars.stream().noneMatch(v -> v.isDiscriminator)) {
|
||||
blocking.add(cm.getSchemaName());
|
||||
}
|
||||
}
|
||||
|
||||
if (discriminatorsForModel != null) {
|
||||
for (String discriminator : discriminatorsForModel) {
|
||||
boolean hasDiscriminatorDefined = false;
|
||||
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
if (var.baseName.equals(discriminator)) {
|
||||
var.isDiscriminator = true;
|
||||
hasDiscriminatorDefined = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the discriminator field is not a defined attribute in the variant structure, create it.
|
||||
if (!hasDiscriminatorDefined) {
|
||||
CodegenProperty property = new CodegenProperty();
|
||||
|
||||
// Static attributes
|
||||
// Only strings are supported by serde for tag field types, so it's the only one we'll deal with
|
||||
property.openApiType = "string";
|
||||
property.complexType = "string";
|
||||
property.dataType = "String";
|
||||
property.datatypeWithEnum = "String";
|
||||
property.baseType = "string";
|
||||
property.required = true;
|
||||
property.isPrimitiveType = true;
|
||||
property.isString = true;
|
||||
property.isDiscriminator = true;
|
||||
|
||||
// Attributes based on the discriminator value
|
||||
property.baseName = discriminator;
|
||||
property.name = discriminator;
|
||||
property.nameInCamelCase = camelize(discriminator);
|
||||
property.nameInPascalCase = property.nameInCamelCase.substring(0, 1).toUpperCase(Locale.ROOT) + property.nameInCamelCase.substring(1);
|
||||
property.nameInSnakeCase = underscore(discriminator).toUpperCase(Locale.ROOT);
|
||||
property.getter = String.format(Locale.ROOT, "get%s", property.nameInPascalCase);
|
||||
property.setter = String.format(Locale.ROOT, "set%s", property.nameInPascalCase);
|
||||
property.defaultValueWithParam = String.format(Locale.ROOT, " = data.%s;", property.name);
|
||||
|
||||
// Attributes based on the model name
|
||||
property.defaultValue = String.format(Locale.ROOT, "r#\"%s\"#.to_string()", cm.getSchemaName());
|
||||
property.jsonSchema = String.format(Locale.ROOT, "{ \"default\":\"%s\"; \"type\":\"string\" }", cm.getSchemaName());
|
||||
|
||||
cm.vars.add(property);
|
||||
}
|
||||
for (final ModelMap mo : allModels) {
|
||||
final CodegenModel cm = mo.getModel();
|
||||
if (cm.discriminator != null) {
|
||||
// if no discriminator in any of variant -> disable discriminator
|
||||
if (cm.oneOf.stream().anyMatch(blocking::contains) || cm.anyOf.stream().anyMatch(blocking::contains)) {
|
||||
cm.discriminator = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean discriminating(final List<String> discriminatorsForModel, final CodegenModel cm) {
|
||||
resetDiscriminatorProperty(cm);
|
||||
|
||||
// Discriminator will be presented as enum tag -> One and only one tag is allowed
|
||||
int countString = 0;
|
||||
int countNonString = 0;
|
||||
for (final CodegenProperty var : cm.vars) {
|
||||
if (discriminatorsForModel.stream().anyMatch(discriminator -> var.baseName.equals(discriminator) || var.name.equals(discriminator))) {
|
||||
if (var.isString) {
|
||||
var.isDiscriminator = true;
|
||||
++countString;
|
||||
} else
|
||||
++countNonString;
|
||||
}
|
||||
}
|
||||
|
||||
if (countString > 0 && (countNonString > 0 || countString > 1)) {
|
||||
// at least two discriminator, one of them is string -> should not render serde tag
|
||||
resetDiscriminatorProperty(cm);
|
||||
}
|
||||
|
||||
return countNonString > 0 || countString > 0;
|
||||
}
|
||||
|
||||
private static void resetDiscriminatorProperty(final CodegenModel cm) {
|
||||
for (final CodegenProperty var : cm.vars) {
|
||||
var.isDiscriminator = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void processPolymorphismDataType(final List<CodegenProperty> cp) {
|
||||
final HashSet<String> dedupDataTypeWithEnum = new HashSet<>();
|
||||
final HashMap<String, Integer> dedupDataType = new HashMap<>();
|
||||
|
||||
int idx = 0;
|
||||
for (CodegenProperty model : cp) {
|
||||
// Generate a valid name for the enum variant.
|
||||
// Mainly needed for primitive types.
|
||||
model.datatypeWithEnum = camelize(model.dataType.replaceAll("(?:\\w+::)+(\\w+)", "$1")
|
||||
.replace("<", "Of").replace(">", "")).replace(" ", "").replace(",", "");
|
||||
if (!dedupDataTypeWithEnum.add(model.datatypeWithEnum)) {
|
||||
model.datatypeWithEnum += ++idx;
|
||||
}
|
||||
|
||||
dedupDataType.put(model.getDataType(), dedupDataType.getOrDefault(model.getDataType(), 0) + 1);
|
||||
|
||||
if (!model.getDataType().matches(String.format(Locale.ROOT, ".*::%s", model.getDatatypeWithEnum()))) {
|
||||
model.isPrimitiveType = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (CodegenProperty model : cp) {
|
||||
if (dedupDataType.get(model.getDataType()) == 1) {
|
||||
model.vendorExtensions.put("x-from-trait", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperationsMap postProcessOperationsWithModels(final OperationsMap operationsMap, List<ModelMap> allModels) {
|
||||
postProcessOneOfModels(allModels);
|
||||
postProcessPolymorphism(allModels);
|
||||
|
||||
final OperationMap operations = operationsMap.getOperations();
|
||||
operations.put("classnamePascalCase", camelize(operations.getClassname()));
|
||||
@@ -901,7 +973,7 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
// restore things to sensible values.
|
||||
@Override
|
||||
public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName) {
|
||||
final Schema original_schema = ModelUtils.getSchemaFromRequestBody(body);
|
||||
final var original_schema = ModelUtils.getSchemaFromRequestBody(body);
|
||||
CodegenParameter codegenParameter = super.fromRequestBody(body, imports, bodyParameterName);
|
||||
|
||||
if (StringUtils.isNotBlank(original_schema.get$ref())) {
|
||||
@@ -920,10 +992,10 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
@Override
|
||||
public String toInstantiationType(final Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
final Schema inner = ModelUtils.getSchemaItems(p);
|
||||
final var inner = ModelUtils.getSchemaItems(p);
|
||||
return instantiationTypes.get("array") + "<" + getSchemaType(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
final Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
final var inner = ModelUtils.getAdditionalProperties(p);
|
||||
return instantiationTypes.get("map") + "<" + typeMapping.get("string") + ", " + getSchemaType(inner) + ">";
|
||||
} else {
|
||||
return null;
|
||||
@@ -952,6 +1024,10 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
@Override
|
||||
public String toDefaultValue(final Schema p) {
|
||||
String defaultValue = null;
|
||||
|
||||
if (ModelUtils.isEnumSchema(p))
|
||||
return null;
|
||||
|
||||
if ((ModelUtils.isNullable(p)) && (p.getDefault() != null) && ("null".equalsIgnoreCase(p.getDefault().toString())))
|
||||
return "Nullable::Null";
|
||||
|
||||
@@ -965,6 +1041,9 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
defaultValue = p.getDefault().toString();
|
||||
if (!defaultValue.contains(".")) {
|
||||
defaultValue += ".0";
|
||||
}
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
@@ -1081,7 +1160,7 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
String cmd = System.getenv("RUST_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(cmd)) {
|
||||
cmd = "rustfmt";
|
||||
command = new String[]{cmd, "--edition", "2021", fileName};
|
||||
command = new String[]{cmd, "--edition", "2024", fileName};
|
||||
} else {
|
||||
command = new String[]{cmd, fileName};
|
||||
}
|
||||
@@ -1093,7 +1172,7 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateParameterForString(CodegenParameter codegenParameter, Schema parameterSchema) {
|
||||
protected void updateParameterForString(CodegenParameter codegenParameter, final Schema parameterSchema) {
|
||||
if (ModelUtils.isEmailSchema(parameterSchema)) {
|
||||
codegenParameter.isEmail = true;
|
||||
} else if (ModelUtils.isUUIDSchema(parameterSchema)) {
|
||||
@@ -1120,7 +1199,7 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
codegenParameter.isDecimal = true;
|
||||
codegenParameter.isPrimitiveType = true;
|
||||
}
|
||||
if (Boolean.TRUE.equals(codegenParameter.isString)) {
|
||||
if (codegenParameter.isString) {
|
||||
codegenParameter.isPrimitiveType = true;
|
||||
}
|
||||
}
|
||||
@@ -1152,6 +1231,16 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
final var varName = super.toVarName(name);
|
||||
|
||||
if (varName.startsWith("r#"))
|
||||
return "r_" + varName.substring(2);
|
||||
|
||||
return varName;
|
||||
}
|
||||
|
||||
static class PathMethodOperations {
|
||||
public String path;
|
||||
public ArrayList<MethodOperation> methodOperations;
|
||||
|
||||
@@ -58,6 +58,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
|
||||
@Setter private boolean preferUnsignedInt = false;
|
||||
@Setter private boolean bestFitInt = false;
|
||||
@Setter private boolean avoidBoxedModels = false;
|
||||
private List<String> reqwestDefaultFeatures = Arrays.asList("native-tls");
|
||||
|
||||
public static final String PACKAGE_NAME = "packageName";
|
||||
public static final String EXTERN_CRATE_NAME = "externCrateName";
|
||||
@@ -77,6 +78,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
|
||||
public static final String TOP_LEVEL_API_CLIENT = "topLevelApiClient";
|
||||
public static final String MOCKALL = "mockall";
|
||||
public static final String BON_BUILDER = "useBonBuilder";
|
||||
public static final String REQWEST_DEFAULT_FEATURES = "reqwestDefaultFeatures";
|
||||
|
||||
@Setter protected String packageName = "openapi";
|
||||
@Setter protected String packageVersion = "1.0.0";
|
||||
@@ -227,6 +229,8 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
|
||||
.defaultValue(Boolean.FALSE.toString()));
|
||||
cliOptions.add(new CliOption(BON_BUILDER, "Use the bon crate for building parameter types. This option is for the 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE)
|
||||
.defaultValue(Boolean.FALSE.toString()));
|
||||
cliOptions.add(new CliOption(REQWEST_DEFAULT_FEATURES, "Default features for the reqwest dependency (comma-separated). Use empty for no defaults. This option is for 'reqwest' and 'reqwest-trait' library only.")
|
||||
.defaultValue("native-tls"));
|
||||
|
||||
supportedLibraries.put(HYPER_LIBRARY, "HTTP client: Hyper (v1.x).");
|
||||
supportedLibraries.put(HYPER0X_LIBRARY, "HTTP client: Hyper (v0.x).");
|
||||
@@ -307,69 +311,6 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
|
||||
mdl.getComposedSchemas().setOneOf(newOneOfs);
|
||||
}
|
||||
|
||||
// Handle anyOf schemas similarly to oneOf
|
||||
// This is pragmatic since Rust's untagged enum will deserialize to the first matching variant
|
||||
if (mdl.getComposedSchemas() != null && mdl.getComposedSchemas().getAnyOf() != null
|
||||
&& !mdl.getComposedSchemas().getAnyOf().isEmpty()) {
|
||||
|
||||
List<CodegenProperty> newAnyOfs = mdl.getComposedSchemas().getAnyOf().stream()
|
||||
.map(CodegenProperty::clone)
|
||||
.collect(Collectors.toList());
|
||||
List<Schema> schemas = ModelUtils.getInterfaces(model);
|
||||
if (newAnyOfs.size() != schemas.size()) {
|
||||
// For safety reasons, this should never happen unless there is an error in the code
|
||||
throw new RuntimeException("anyOf size does not match the model");
|
||||
}
|
||||
|
||||
Map<String, String> refsMapping = Optional.ofNullable(model.getDiscriminator())
|
||||
.map(Discriminator::getMapping).orElse(Collections.emptyMap());
|
||||
|
||||
// Reverse mapped references to use as baseName for anyOf, but different keys may point to the same $ref.
|
||||
// Thus, we group them by the value
|
||||
Map<String, List<String>> mappedNamesByRef = refsMapping.entrySet().stream()
|
||||
.collect(Collectors.groupingBy(Map.Entry::getValue,
|
||||
Collectors.mapping(Map.Entry::getKey, Collectors.toList())
|
||||
));
|
||||
|
||||
for (int i = 0; i < newAnyOfs.size(); i++) {
|
||||
CodegenProperty anyOf = newAnyOfs.get(i);
|
||||
Schema schema = schemas.get(i);
|
||||
|
||||
if (mappedNamesByRef.containsKey(schema.get$ref())) {
|
||||
// prefer mapped names if present
|
||||
// remove mapping not in order not to reuse for the next occurrence of the ref
|
||||
List<String> names = mappedNamesByRef.get(schema.get$ref());
|
||||
String mappedName = names.remove(0);
|
||||
anyOf.setBaseName(mappedName);
|
||||
anyOf.setName(toModelName(mappedName));
|
||||
} else if (!org.apache.commons.lang3.StringUtils.isEmpty(schema.get$ref())) {
|
||||
// use $ref if it's reference
|
||||
String refName = ModelUtils.getSimpleRef(schema.get$ref());
|
||||
if (refName != null) {
|
||||
String modelName = toModelName(refName);
|
||||
anyOf.setName(modelName);
|
||||
anyOf.setBaseName(refName);
|
||||
}
|
||||
} else if (anyOf.isArray) {
|
||||
// If the type is an array, extend the name with the inner type to prevent name collisions
|
||||
// in case multiple arrays with different types are defined. If the user has manually specified
|
||||
// a name, use that name instead.
|
||||
String collectionWithTypeName = toModelName(schema.getType()) + anyOf.containerTypeMapped + anyOf.items.dataType;
|
||||
String anyOfName = Optional.ofNullable(schema.getTitle()).orElse(collectionWithTypeName);
|
||||
anyOf.setName(anyOfName);
|
||||
}
|
||||
else {
|
||||
// In-placed type (primitive), because there is no mapping or ref for it.
|
||||
// use camelized `title` if present, otherwise use `type`
|
||||
String anyOfName = Optional.ofNullable(schema.getTitle()).orElseGet(schema::getType);
|
||||
anyOf.setName(toModelName(anyOfName));
|
||||
}
|
||||
}
|
||||
|
||||
// Set anyOf as oneOf for template processing since we want the same output
|
||||
mdl.getComposedSchemas().setOneOf(newAnyOfs);
|
||||
}
|
||||
|
||||
return mdl;
|
||||
}
|
||||
|
||||
@@ -494,6 +435,21 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
|
||||
}
|
||||
writePropertyBack(AVOID_BOXED_MODELS, getAvoidBoxedModels());
|
||||
|
||||
if (additionalProperties.containsKey(REQWEST_DEFAULT_FEATURES)) {
|
||||
Object value = additionalProperties.get(REQWEST_DEFAULT_FEATURES);
|
||||
if (value instanceof List) {
|
||||
reqwestDefaultFeatures = (List<String>) value;
|
||||
} else if (value instanceof String) {
|
||||
String str = (String) value;
|
||||
if (str.isEmpty()) {
|
||||
reqwestDefaultFeatures = new ArrayList<>();
|
||||
} else {
|
||||
reqwestDefaultFeatures = Arrays.asList(str.split(",\\s*"));
|
||||
}
|
||||
}
|
||||
}
|
||||
additionalProperties.put(REQWEST_DEFAULT_FEATURES, reqwestDefaultFeatures);
|
||||
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||
additionalProperties.put(EXTERN_CRATE_NAME, getExternCrateName());
|
||||
|
||||
@@ -100,6 +100,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
public static final String OPTIONAL_ACCEPT_NULLABLE = "optionalAcceptNullable";
|
||||
public static final String USE_SPRING_BUILT_IN_VALIDATION = "useSpringBuiltInValidation";
|
||||
public static final String USE_DEDUCTION_FOR_ONE_OF_INTERFACES = "useDeductionForOneOfInterfaces";
|
||||
public static final String SPRING_API_VERSION = "springApiVersion";
|
||||
|
||||
@Getter
|
||||
public enum RequestMappingMode {
|
||||
@@ -286,6 +287,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
optionalAcceptNullable));
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, "whether to use deduction for generated oneOf interfaces", useDeductionForOneOfInterfaces));
|
||||
cliOptions.add(CliOption.newString(SPRING_API_VERSION, "Value for 'version' attribute in @RequestMapping (for Spring 7 and above)."));
|
||||
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
|
||||
supportedLibraries.put(SPRING_CLOUD_LIBRARY,
|
||||
"Spring-Cloud-Feign client with Spring-Boot auto-configured settings.");
|
||||
@@ -855,6 +857,8 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
|
||||
private void prepareVersioningParameters(List<CodegenOperation> operations) {
|
||||
Object apiVersion = additionalProperties.get(SPRING_API_VERSION);
|
||||
boolean hasApiVersion = apiVersion != null;
|
||||
for (CodegenOperation operation : operations) {
|
||||
if (operation.getHasHeaderParams()) {
|
||||
List<CodegenParameter> versionParams = operation.headerParams.stream()
|
||||
@@ -877,6 +881,9 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
operation.hasVersionQueryParams = !versionParams.isEmpty();
|
||||
operation.vendorExtensions.put("versionQueryParamsList", versionParams);
|
||||
}
|
||||
if (hasApiVersion) {
|
||||
operation.vendorExtensions.putIfAbsent(VendorExtension.X_SPRING_API_VERSION.getName(), apiVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -981,6 +988,11 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
codegenModel.imports.remove("ApiModel");
|
||||
}
|
||||
|
||||
if (getAnnotationLibrary() != AnnotationLibrary.SWAGGER2) {
|
||||
// remove swagger imports
|
||||
codegenModel.imports.remove("Schema");
|
||||
}
|
||||
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
@@ -1205,6 +1217,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
extensions.add(VendorExtension.X_SPRING_PAGINATED);
|
||||
extensions.add(VendorExtension.X_VERSION_PARAM);
|
||||
extensions.add(VendorExtension.X_PATTERN_MESSAGE);
|
||||
extensions.add(VendorExtension.X_SPRING_API_VERSION);
|
||||
return extensions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.X_PARENT;
|
||||
import static org.openapitools.codegen.utils.OnceLogger.once;
|
||||
|
||||
public class ModelUtils {
|
||||
@@ -1716,7 +1717,7 @@ public class ModelUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object xParent = schema.getExtensions().get("x-parent");
|
||||
Object xParent = schema.getExtensions().get(X_PARENT);
|
||||
if (xParent == null) {
|
||||
return false;
|
||||
} else if (xParent instanceof Boolean) {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "{{classname}}.h"
|
||||
|
||||
#define MAX_NUMBER_LENGTH 16
|
||||
#define MAX_BUFFER_LENGTH 4096
|
||||
#define MAX_NUMBER_LENGTH_LONG 21
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
@@ -229,10 +231,16 @@ end:
|
||||
// query parameters
|
||||
{{^isArray}}
|
||||
char *keyQuery_{{{paramName}}} = NULL;
|
||||
{{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}char *{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}char *{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}} *{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueQuery_{{{paramName}}} {{#isString}}{{^isEnum}}= NULL{{/isEnum}}{{/isString}}{{#isInteger}}= NULL{{/isInteger}}{{#isBoolean}}= NULL{{/isBoolean}};
|
||||
{{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}char *{{/isLong}}{{#isInteger}}char *{{/isInteger}}{{#isDouble}}char *{{/isDouble}}{{#isFloat}}char *{{/isFloat}}{{#isBoolean}}char *{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}} *{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueQuery_{{{paramName}}} {{#isString}}{{^isEnum}}= NULL{{/isEnum}}{{/isString}}{{#isInteger}}= NULL{{/isInteger}}{{#isBoolean}}= NULL{{/isBoolean}}{{#isDouble}}= NULL{{/isDouble}}{{#isFloat}}= NULL{{/isFloat}};
|
||||
keyValuePair_t *keyPairQuery_{{paramName}} = 0;
|
||||
{{/isArray}}
|
||||
{{^isLong}}
|
||||
{{^isFloat}}
|
||||
{{^isDouble}}
|
||||
if ({{paramName}})
|
||||
{{/isDouble}}
|
||||
{{/isFloat}}
|
||||
{{/isLong}}
|
||||
{
|
||||
{{#isArray}}
|
||||
list_addElement(localVarQueryParameters,{{paramName}});
|
||||
@@ -243,17 +251,43 @@ end:
|
||||
valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH);
|
||||
snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH, "%d", *{{{paramName}}});
|
||||
{{/isInteger}}
|
||||
{{#isFloat}}
|
||||
int s = snprintf(NULL, 0, "%.7e", {{{paramName}}});
|
||||
if (s >= 0)
|
||||
{
|
||||
valueQuery_{{{paramName}}} = calloc(1,s+1);
|
||||
snprintf(valueQuery_{{{paramName}}}, s+1, "%.7e", {{{paramName}}});
|
||||
}
|
||||
{{/isFloat}}
|
||||
{{#isDouble}}
|
||||
int s = snprintf(NULL, 0, "%.16e", {{{paramName}}});
|
||||
if (s >= 0)
|
||||
{
|
||||
valueQuery_{{{paramName}}} = calloc(1,s+1);
|
||||
snprintf(valueQuery_{{{paramName}}}, s+1, "%.16e", {{{paramName}}});
|
||||
}
|
||||
{{/isDouble}}
|
||||
{{#isLong}}
|
||||
valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_LONG);
|
||||
snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_LONG, "%d", {{{paramName}}});
|
||||
{{/isLong}}
|
||||
{{#isBoolean}}
|
||||
valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH);
|
||||
snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH, "%d", *{{{paramName}}});
|
||||
{{/isBoolean}}
|
||||
{{^isInteger}}
|
||||
{{^isBoolean}}
|
||||
{{^isFloat}}
|
||||
{{^isDouble}}
|
||||
{{^isLong}}
|
||||
valueQuery_{{{paramName}}} = {{#isString}}{{^isEnum}}strdup({{/isEnum}}{{/isString}}({{{paramName}}}){{#isString}}{{^isEnum}}){{/isEnum}}{{/isString}};
|
||||
{{/isLong}}
|
||||
{{/isDouble}}
|
||||
{{/isFloat}}
|
||||
{{/isBoolean}}
|
||||
{{/isInteger}}
|
||||
keyPairQuery_{{paramName}} = keyValuePair_create(keyQuery_{{{paramName}}}, {{#isEnum}}strdup({{{operationId}}}_{{enumName}}_ToString(
|
||||
{{/isEnum}}{{^isString}}{{^isInteger}}{{^isBoolean}}&{{/isBoolean}}{{/isInteger}}{{/isString}}valueQuery_{{{paramName}}}{{#isEnum}})){{/isEnum}});
|
||||
{{/isEnum}}{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}{{^isLong}}{{^isBoolean}}&{{/isBoolean}}{{/isLong}}{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}valueQuery_{{{paramName}}}{{#isEnum}})){{/isEnum}});
|
||||
list_addElement(localVarQueryParameters,keyPairQuery_{{paramName}});
|
||||
{{/isArray}}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{#pattern}} @Pattern(regexp="{{{.}}}"){{/pattern}}{{!
|
||||
{{^isUuid}}{{#pattern}} @Pattern(regexp="{{{.}}}"){{/pattern}}{{!
|
||||
minLength && maxLength set
|
||||
}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{!
|
||||
minLength set, maxLength not
|
||||
@@ -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("{{.}}"){{/minimum}}{{#maximum}} @DecimalMax("{{.}}"){{/maximum}}{{/isLong}}{{/isInteger}}
|
||||
}}{{^isInteger}}{{^isLong}}{{#minimum}} @DecimalMin("{{.}}"){{/minimum}}{{#maximum}} @DecimalMax("{{.}}"){{/maximum}}{{/isLong}}{{/isInteger}}{{/isUuid}}
|
||||
@@ -357,10 +357,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
* @return ApiClient this client
|
||||
*/
|
||||
public ApiClient addDefaultHeader(String name, String value) {
|
||||
if (defaultHeaders.containsKey(name)) {
|
||||
defaultHeaders.remove(name);
|
||||
}
|
||||
defaultHeaders.add(name, value);
|
||||
defaultHeaders.set(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -737,7 +734,12 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
* @param requestBuilder The current request
|
||||
*/
|
||||
protected void addHeadersToRequest(HttpHeaders headers, WebClient.RequestBodySpec requestBuilder) {
|
||||
{{#useJakartaEe}}
|
||||
for (Entry<String, List<String>> entry : headers.headerSet()) {
|
||||
{{/useJakartaEe}}
|
||||
{{^useJakartaEe}}
|
||||
for (Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
{{/useJakartaEe}}
|
||||
List<String> values = entry.getValue();
|
||||
for(String value : values) {
|
||||
if (value != null) {
|
||||
|
||||
@@ -131,7 +131,7 @@ ext {
|
||||
swagger_annotations_version = "2.2.9"
|
||||
{{/swagger2AnnotationLibrary}}
|
||||
{{#useJakartaEe}}
|
||||
spring_boot_version = "3.0.12"
|
||||
spring_boot_version = "3.2.12"
|
||||
jakarta_annotation_version = "2.1.1"
|
||||
beanvalidation_version = "3.0.2"
|
||||
reactor_version = "3.5.12"
|
||||
|
||||
@@ -173,7 +173,7 @@
|
||||
<jackson-databind-nullable-version>0.2.7</jackson-databind-nullable-version>
|
||||
{{/openApiNullable}}
|
||||
{{#useJakartaEe}}
|
||||
<spring-boot-version>3.0.12</spring-boot-version>
|
||||
<spring-boot-version>3.2.12</spring-boot-version>
|
||||
<jakarta-annotation-version>2.1.1</jakarta-annotation-version>
|
||||
<reactor-version>3.5.12</reactor-version>
|
||||
<reactor-netty-version>1.2.8</reactor-netty-version>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{{>additionalOneOfTypeAnnotations}}{{>generatedAnnotation}}{{>typeInfoAnnotation}}{{>xmlAnnotation}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
public {{>sealed}}interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}}{{>permits}}{
|
||||
{{#discriminator}}
|
||||
public {{propertyType}} {{propertyGetter}}();
|
||||
|
||||
@@ -27,7 +27,7 @@ import {{javaxPackage}}.validation.Valid;
|
||||
@Path("{{commonPath}}")
|
||||
@RequestScoped
|
||||
|
||||
@Api(description = "the {{{baseName}}} API")
|
||||
@Api
|
||||
{{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}}
|
||||
{{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}}
|
||||
{{>generatedAnnotation}}
|
||||
|
||||
@@ -8,7 +8,9 @@ import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
{{#useBeanValidation}}
|
||||
import {{javaxPackage}}.validation.Valid;
|
||||
{{/useBeanValidation}}
|
||||
import {{javaxPackage}}.ws.rs.core.Response;
|
||||
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
|
||||
import org.apache.cxf.jaxrs.client.ClientConfiguration;
|
||||
|
||||
@@ -252,7 +252,8 @@ public interface {{classname}} {
|
||||
produces = { {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }{{/hasProduces}}{{#hasConsumes}},
|
||||
consumes = { {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }{{/hasConsumes}}{{/singleContentTypes}}{{#hasVersionHeaders}},
|
||||
headers = { {{#vendorExtensions.versionHeaderParamsList}}"{{baseName}}{{#defaultValue}}={{{.}}}{{/defaultValue}}"{{^-last}}, {{/-last}}{{/vendorExtensions.versionHeaderParamsList}} } {{/hasVersionHeaders}}{{#hasVersionQueryParams}},
|
||||
params = { {{#vendorExtensions.versionQueryParamsList}}"{{baseName}}{{#defaultValue}}={{{.}}}{{/defaultValue}}"{{^-last}}, {{/-last}}{{/vendorExtensions.versionQueryParamsList}} } {{/hasVersionQueryParams}}
|
||||
params = { {{#vendorExtensions.versionQueryParamsList}}"{{baseName}}{{#defaultValue}}={{{.}}}{{/defaultValue}}"{{^-last}}, {{/-last}}{{/vendorExtensions.versionQueryParamsList}} } {{/hasVersionQueryParams}}{{#vendorExtensions.x-spring-api-version}}{{^empty}},
|
||||
version = "{{{vendorExtensions.x-spring-api-version}}}"{{/empty}}{{/vendorExtensions.x-spring-api-version}}
|
||||
)
|
||||
{{^useResponseEntity}}
|
||||
@ResponseStatus({{#springHttpStatus}}{{#responses.0}}{{{code}}}{{/responses.0}}{{/springHttpStatus}})
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
@JsonSubTypes.Type(value = {{classname}}.class){{^-last}}, {{/-last}}
|
||||
{{/interfaceModels}}
|
||||
})
|
||||
{{/useDeductionForOneOfInterfaces}}
|
||||
{{/useDeductionForOneOfInterfaces}}{{#vendorExtensions.x-class-extra-annotation}}{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
{{/discriminator}}
|
||||
{{>generatedAnnotation}}
|
||||
|
||||
|
||||
@@ -6,12 +6,10 @@ import (
|
||||
{{#hasBodyParams}}
|
||||
"encoding/json"
|
||||
{{/hasBodyParams}}
|
||||
{{#isBodyParam}}
|
||||
{{^required}}
|
||||
{{#hasOptionalBodyParams}}
|
||||
"errors"
|
||||
"io"
|
||||
{{/required}}
|
||||
{{/isBodyParam}}
|
||||
{{/hasOptionalBodyParams}}
|
||||
"net/http"
|
||||
"strings"
|
||||
{{#imports}} "{{import}}"
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
{{#multiplatform}}
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.*
|
||||
import kotlinx.serialization.encoding.*
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
/**
|
||||
* {{{description}}}
|
||||
*
|
||||
*/
|
||||
{{#isDeprecated}}
|
||||
@Deprecated(message = "This schema is deprecated.")
|
||||
{{/isDeprecated}}
|
||||
@Serializable(with = {{classname}}.{{classname}}Serializer::class)
|
||||
{{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}data class {{classname}}(var actualInstance: Any? = null) {
|
||||
|
||||
object {{classname}}Serializer : KSerializer<{{classname}}> {
|
||||
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("{{classname}}") {
|
||||
element("type", JsonPrimitive.serializer().descriptor)
|
||||
element("actualInstance", JsonElement.serializer().descriptor)
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: {{classname}}) {
|
||||
val jsonEncoder = encoder as? JsonEncoder ?: throw SerializationException("{{classname}} can only be serialized with Json")
|
||||
|
||||
when (val instance = value.actualInstance) {
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isString}}
|
||||
is kotlin.String -> jsonEncoder.encodeString(instance)
|
||||
{{/isString}}
|
||||
{{#isBoolean}}
|
||||
is kotlin.Boolean -> jsonEncoder.encodeBoolean(instance)
|
||||
{{/isBoolean}}
|
||||
{{#isInteger}}
|
||||
is kotlin.Int -> jsonEncoder.encodeInt(instance)
|
||||
{{/isInteger}}
|
||||
{{#isNumber}}
|
||||
{{#isDouble}}
|
||||
is kotlin.Double -> jsonEncoder.encodeDouble(instance)
|
||||
{{/isDouble}}
|
||||
{{#isFloat}}
|
||||
is kotlin.Float -> jsonEncoder.encodeFloat(instance)
|
||||
{{/isFloat}}
|
||||
{{/isNumber}}
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
is {{{dataType}}} -> jsonEncoder.encodeSerializableValue({{{dataType}}}.serializer(), instance)
|
||||
{{/isPrimitiveType}}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
null -> jsonEncoder.encodeJsonElement(JsonNull)
|
||||
else -> throw SerializationException("Unknown type in actualInstance: ${instance::class}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): {{classname}} {
|
||||
val jsonDecoder = decoder as? JsonDecoder ?: throw SerializationException("{{classname}} can only be deserialized with Json")
|
||||
val jsonElement = jsonDecoder.decodeJsonElement()
|
||||
|
||||
val errorMessages = mutableListOf<String>()
|
||||
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
try {
|
||||
val instance = jsonDecoder.json.decodeFromJsonElement<{{{dataType}}}>(jsonElement)
|
||||
return {{classname}}(actualInstance = instance)
|
||||
} catch (e: Exception) {
|
||||
errorMessages.add("Failed to deserialize as {{{dataType}}}: ${e.message}")
|
||||
}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
|
||||
throw SerializationException("Cannot deserialize {{classname}}. Tried: ${errorMessages.joinToString(", ")}")
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/multiplatform}}
|
||||
@@ -0,0 +1,79 @@
|
||||
{{#multiplatform}}
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.*
|
||||
import kotlinx.serialization.encoding.*
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
/**
|
||||
* {{{description}}}
|
||||
*
|
||||
*/
|
||||
{{#isDeprecated}}
|
||||
@Deprecated(message = "This schema is deprecated.")
|
||||
{{/isDeprecated}}
|
||||
@Serializable(with = {{classname}}.{{classname}}Serializer::class)
|
||||
{{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}data class {{classname}}(var actualInstance: Any? = null) {
|
||||
|
||||
object {{classname}}Serializer : KSerializer<{{classname}}> {
|
||||
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("{{classname}}") {
|
||||
element("type", JsonPrimitive.serializer().descriptor)
|
||||
element("actualInstance", JsonElement.serializer().descriptor)
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: {{classname}}) {
|
||||
val jsonEncoder = encoder as? JsonEncoder ?: throw SerializationException("{{classname}} can only be serialized with Json")
|
||||
|
||||
when (val instance = value.actualInstance) {
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isString}}
|
||||
is kotlin.String -> jsonEncoder.encodeString(instance)
|
||||
{{/isString}}
|
||||
{{#isBoolean}}
|
||||
is kotlin.Boolean -> jsonEncoder.encodeBoolean(instance)
|
||||
{{/isBoolean}}
|
||||
{{#isInteger}}
|
||||
is kotlin.Int -> jsonEncoder.encodeInt(instance)
|
||||
{{/isInteger}}
|
||||
{{#isNumber}}
|
||||
{{#isDouble}}
|
||||
is kotlin.Double -> jsonEncoder.encodeDouble(instance)
|
||||
{{/isDouble}}
|
||||
{{#isFloat}}
|
||||
is kotlin.Float -> jsonEncoder.encodeFloat(instance)
|
||||
{{/isFloat}}
|
||||
{{/isNumber}}
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
is {{{dataType}}} -> jsonEncoder.encodeSerializableValue({{{dataType}}}.serializer(), instance)
|
||||
{{/isPrimitiveType}}
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
null -> jsonEncoder.encodeJsonElement(JsonNull)
|
||||
else -> throw SerializationException("Unknown type in actualInstance: ${instance::class}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): {{classname}} {
|
||||
val jsonDecoder = decoder as? JsonDecoder ?: throw SerializationException("{{classname}} can only be deserialized with Json")
|
||||
val jsonElement = jsonDecoder.decodeJsonElement()
|
||||
|
||||
val errorMessages = mutableListOf<String>()
|
||||
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
try {
|
||||
val instance = jsonDecoder.json.decodeFromJsonElement<{{{dataType}}}>(jsonElement)
|
||||
return {{classname}}(actualInstance = instance)
|
||||
} catch (e: Exception) {
|
||||
errorMessages.add("Failed to deserialize as {{{dataType}}}: ${e.message}")
|
||||
}
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
|
||||
throw SerializationException("Cannot deserialize {{classname}}. Tried: ${errorMessages.joinToString(", ")}")
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/multiplatform}}
|
||||
@@ -18,7 +18,7 @@
|
||||
{{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>dataClassOptVar}}{{^-last}},
|
||||
{{/-last}}{{/optionalVars}}
|
||||
){{/discriminator}}{{! no newline
|
||||
}}{{#parent}} : {{{.}}}{{! no newline
|
||||
}}{{#parent}} : {{{.}}}{{#isMap}}(){{/isMap}}{{! no newline
|
||||
}}{{#serializableModel}}{{! no newline
|
||||
}}{{^vendorExtensions.x-kotlin-implements}}, Serializable{{/vendorExtensions.x-kotlin-implements}}{{! no newline
|
||||
}}{{#vendorExtensions.x-kotlin-implements}}, Serializable, {{! no newline
|
||||
|
||||
@@ -579,6 +579,6 @@ class ObjectSerializer
|
||||
}
|
||||
}
|
||||
|
||||
return $qs ? (string) substr($qs, 0, -1) : '';
|
||||
return $qs ? substr($qs, 0, -1) : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,6 +586,6 @@ class ObjectSerializer
|
||||
}
|
||||
}
|
||||
|
||||
return $qs ? (string) substr($qs, 0, -1) : '';
|
||||
return $qs ? substr($qs, 0, -1) : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# {{invokerPackage}}\{{classname}}{{#description}}
|
||||
# {{invokerPackage}}\{{classname}}{{#operationTagDescription}}
|
||||
|
||||
{{.}}{{/description}}
|
||||
{{operationTagDescription}}{{/operationTagDescription}}
|
||||
|
||||
All URIs are relative to {{basePath}}, except if the operation defines another base path.
|
||||
|
||||
|
||||
@@ -28,10 +28,10 @@ To be able to use it, you will need these dependencies in your own package that
|
||||
|
||||
* urllib3 >= 2.1.0, < 3.0.0
|
||||
* python-dateutil >= 2.8.2
|
||||
{{#asyncio}}
|
||||
{{#async}}
|
||||
* aiohttp >= 3.8.4
|
||||
* aiohttp-retry >= 2.8.3
|
||||
{{/asyncio}}
|
||||
{{/async}}
|
||||
{{#tornado}}
|
||||
* tornado >= 4.2, < 5
|
||||
{{/tornado}}
|
||||
|
||||
@@ -32,14 +32,14 @@ class {{classname}}:
|
||||
|
||||
|
||||
@validate_call
|
||||
{{#asyncio}}async {{/asyncio}}def {{operationId}}{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
|
||||
{{#async}}async {{/async}}def {{operationId}}{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
|
||||
{{>partial_api}}
|
||||
|
||||
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(
|
||||
response_data = {{#async}}await {{/async}}self.api_client.call_api(
|
||||
*_param,
|
||||
_request_timeout=_request_timeout
|
||||
)
|
||||
{{#asyncio}}await {{/asyncio}}response_data.read()
|
||||
{{#async}}await {{/async}}response_data.read()
|
||||
return self.api_client.response_deserialize(
|
||||
response_data=response_data,
|
||||
response_types_map=_response_types_map,
|
||||
@@ -47,14 +47,14 @@ class {{classname}}:
|
||||
|
||||
|
||||
@validate_call
|
||||
{{#asyncio}}async {{/asyncio}}def {{operationId}}_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
|
||||
{{#async}}async {{/async}}def {{operationId}}_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
|
||||
{{>partial_api}}
|
||||
|
||||
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(
|
||||
response_data = {{#async}}await {{/async}}self.api_client.call_api(
|
||||
*_param,
|
||||
_request_timeout=_request_timeout
|
||||
)
|
||||
{{#asyncio}}await {{/asyncio}}response_data.read()
|
||||
{{#async}}await {{/async}}response_data.read()
|
||||
return self.api_client.response_deserialize(
|
||||
response_data=response_data,
|
||||
response_types_map=_response_types_map,
|
||||
@@ -62,10 +62,10 @@ class {{classname}}:
|
||||
|
||||
|
||||
@validate_call
|
||||
{{#asyncio}}async {{/asyncio}}def {{operationId}}_without_preload_content{{>partial_api_args}} -> RESTResponseType:
|
||||
{{#async}}async {{/async}}def {{operationId}}_without_preload_content{{>partial_api_args}} -> RESTResponseType:
|
||||
{{>partial_api}}
|
||||
|
||||
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(
|
||||
response_data = {{#async}}await {{/async}}self.api_client.call_api(
|
||||
*_param,
|
||||
_request_timeout=_request_timeout
|
||||
)
|
||||
|
||||
@@ -88,7 +88,7 @@ class ApiClient:
|
||||
self.user_agent = '{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/python{{/httpUserAgent}}'
|
||||
self.client_side_validation = configuration.client_side_validation
|
||||
|
||||
{{#asyncio}}
|
||||
{{#async}}
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
@@ -97,14 +97,14 @@ class ApiClient:
|
||||
|
||||
async def close(self):
|
||||
await self.rest_client.close()
|
||||
{{/asyncio}}
|
||||
{{^asyncio}}
|
||||
{{/async}}
|
||||
{{^async}}
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
pass
|
||||
{{/asyncio}}
|
||||
{{/async}}
|
||||
|
||||
@property
|
||||
def user_agent(self):
|
||||
@@ -257,7 +257,7 @@ class ApiClient:
|
||||
{{#tornado}}
|
||||
@tornado.gen.coroutine
|
||||
{{/tornado}}
|
||||
{{#asyncio}}async {{/asyncio}}def call_api(
|
||||
{{#async}}async {{/async}}def call_api(
|
||||
self,
|
||||
method,
|
||||
url,
|
||||
@@ -280,7 +280,7 @@ class ApiClient:
|
||||
|
||||
try:
|
||||
# perform request and return response
|
||||
response_data = {{#asyncio}}await {{/asyncio}}{{#tornado}}yield {{/tornado}}self.rest_client.request(
|
||||
response_data = {{#async}}await {{/async}}{{#tornado}}yield {{/tornado}}self.rest_client.request(
|
||||
method, url,
|
||||
headers=header_params,
|
||||
body=body, post_params=post_params,
|
||||
|
||||
@@ -10,7 +10,7 @@ from pprint import pprint
|
||||
{{> python_doc_auth_partial}}
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
{{#asyncio}}async {{/asyncio}}with {{{packageName}}}.ApiClient(configuration) as api_client:
|
||||
{{#async}}async {{/async}}with {{{packageName}}}.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
|
||||
{{#allParams}}
|
||||
@@ -21,7 +21,7 @@ from pprint import pprint
|
||||
{{#summary}}
|
||||
# {{{.}}}
|
||||
{{/summary}}
|
||||
{{#returnType}}api_response = {{/returnType}}{{#asyncio}}await {{/asyncio}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{{#returnType}}api_response = {{/returnType}}{{#async}}await {{/async}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{{#returnType}}
|
||||
print("The response of {{classname}}->{{operationId}}:\n")
|
||||
pprint(api_response)
|
||||
|
||||
@@ -8,31 +8,31 @@ import unittest
|
||||
from {{apiPackage}}.{{classFilename}} import {{classname}}
|
||||
|
||||
|
||||
class {{#operations}}Test{{classname}}(unittest.{{#asyncio}}IsolatedAsyncio{{/asyncio}}TestCase):
|
||||
class {{#operations}}Test{{classname}}(unittest.{{#async}}IsolatedAsyncio{{/async}}TestCase):
|
||||
"""{{classname}} unit test stubs"""
|
||||
|
||||
{{#asyncio}}
|
||||
{{#async}}
|
||||
async def asyncSetUp(self) -> None:
|
||||
self.api = {{classname}}()
|
||||
|
||||
async def asyncTearDown(self) -> None:
|
||||
await self.api.api_client.close()
|
||||
{{/asyncio}}
|
||||
{{^asyncio}}
|
||||
{{/async}}
|
||||
{{^async}}
|
||||
def setUp(self) -> None:
|
||||
self.api = {{classname}}()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
pass
|
||||
{{/asyncio}}
|
||||
{{/async}}
|
||||
|
||||
{{#operation}}
|
||||
{{#asyncio}}
|
||||
{{#async}}
|
||||
async def test_{{operationId}}(self) -> None:
|
||||
{{/asyncio}}
|
||||
{{^asyncio}}
|
||||
{{/async}}
|
||||
{{^async}}
|
||||
def test_{{operationId}}(self) -> None:
|
||||
{{/asyncio}}
|
||||
{{/async}}
|
||||
"""Test case for {{{operationId}}}
|
||||
|
||||
{{#summary}}
|
||||
|
||||
@@ -8,7 +8,7 @@ from pprint import pprint
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
{{#asyncio}}async {{/asyncio}}with {{{packageName}}}.ApiClient(configuration) as api_client:
|
||||
{{#async}}async {{/async}}with {{{packageName}}}.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
|
||||
{{#allParams}}
|
||||
@@ -19,7 +19,7 @@ from pprint import pprint
|
||||
{{#summary}}
|
||||
# {{{.}}}
|
||||
{{/summary}}
|
||||
{{#returnType}}api_response = {{/returnType}}{{#asyncio}}await {{/asyncio}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{{#returnType}}api_response = {{/returnType}}{{#async}}await {{/async}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{{#returnType}}
|
||||
print("The response of {{classname}}->{{operationId}}:\n")
|
||||
pprint(api_response)
|
||||
|
||||
@@ -7,9 +7,9 @@ import copy
|
||||
import http.client as httplib
|
||||
import logging
|
||||
from logging import FileHandler
|
||||
{{^asyncio}}
|
||||
{{^async}}
|
||||
import multiprocessing
|
||||
{{/asyncio}}
|
||||
{{/async}}
|
||||
import sys
|
||||
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
||||
from typing_extensions import NotRequired, Self
|
||||
@@ -395,13 +395,13 @@ conf = {{{packageName}}}.Configuration(
|
||||
Set this to the SNI value expected by the server.
|
||||
"""
|
||||
|
||||
{{#asyncio}}
|
||||
{{#async}}
|
||||
self.connection_pool_maxsize = 100
|
||||
"""This value is passed to the aiohttp to limit simultaneous connections.
|
||||
Default values is 100, None means no-limit.
|
||||
"""
|
||||
{{/asyncio}}
|
||||
{{^asyncio}}
|
||||
{{/async}}
|
||||
{{^async}}
|
||||
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
|
||||
"""urllib3 connection pool's maximum number of connections saved
|
||||
per pool. urllib3 uses 1 connection as default value, but this is
|
||||
@@ -409,7 +409,7 @@ conf = {{{packageName}}}.Configuration(
|
||||
requests to the same host, which is often the case here.
|
||||
cpu_count * 5 is used as default value to increase performance.
|
||||
"""
|
||||
{{/asyncio}}
|
||||
{{/async}}
|
||||
|
||||
self.proxy: Optional[str] = None
|
||||
"""Proxy URL
|
||||
|
||||
185
modules/openapi-generator/src/main/resources/python/httpx/rest.mustache
vendored
Normal file
185
modules/openapi-generator/src/main/resources/python/httpx/rest.mustache
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
# coding: utf-8
|
||||
|
||||
{{>partial_header}}
|
||||
|
||||
|
||||
import io
|
||||
import json
|
||||
import re
|
||||
import ssl
|
||||
from typing import Optional, Union
|
||||
|
||||
import httpx
|
||||
|
||||
from {{packageName}}.exceptions import ApiException, ApiValueError
|
||||
|
||||
RESTResponseType = httpx.Response
|
||||
|
||||
class RESTResponse(io.IOBase):
|
||||
|
||||
def __init__(self, resp) -> None:
|
||||
self.response = resp
|
||||
self.status = resp.status_code
|
||||
self.reason = resp.reason_phrase
|
||||
self.data = None
|
||||
|
||||
async def read(self):
|
||||
if self.data is None:
|
||||
self.data = await self.response.aread()
|
||||
return self.data
|
||||
|
||||
def getheaders(self):
|
||||
"""Returns a CIMultiDictProxy of the response headers."""
|
||||
return self.response.headers
|
||||
|
||||
def getheader(self, name, default=None):
|
||||
"""Returns a given response header."""
|
||||
return self.response.headers.get(name, default)
|
||||
|
||||
|
||||
class RESTClientObject:
|
||||
|
||||
def __init__(self, configuration) -> None:
|
||||
|
||||
# maxsize is number of requests to host that are allowed in parallel
|
||||
self.maxsize = configuration.connection_pool_maxsize
|
||||
|
||||
self.ssl_context = ssl.create_default_context(
|
||||
cafile=configuration.ssl_ca_cert,
|
||||
cadata=configuration.ca_cert_data,
|
||||
)
|
||||
if configuration.cert_file:
|
||||
self.ssl_context.load_cert_chain(
|
||||
configuration.cert_file, keyfile=configuration.key_file
|
||||
)
|
||||
|
||||
if not configuration.verify_ssl:
|
||||
self.ssl_context.check_hostname = False
|
||||
self.ssl_context.verify_mode = ssl.CERT_NONE
|
||||
|
||||
self.proxy = configuration.proxy
|
||||
self.proxy_headers = configuration.proxy_headers
|
||||
|
||||
self.pool_manager: Optional[httpx.AsyncClient] = None
|
||||
|
||||
async def close(self):
|
||||
if self.pool_manager is not None:
|
||||
await self.pool_manager.aclose()
|
||||
|
||||
async def request(
|
||||
self,
|
||||
method,
|
||||
url,
|
||||
headers=None,
|
||||
body=None,
|
||||
post_params=None,
|
||||
_request_timeout=None):
|
||||
"""Execute request
|
||||
|
||||
:param method: http request method
|
||||
:param url: http request url
|
||||
:param headers: http request headers
|
||||
:param body: request json body, for `application/json`
|
||||
:param post_params: request post parameters,
|
||||
`application/x-www-form-urlencoded`
|
||||
and `multipart/form-data`
|
||||
:param _request_timeout: timeout setting for this request. If one
|
||||
number provided, it will be total request
|
||||
timeout. It can also be a pair (tuple) of
|
||||
(connection, read) timeouts.
|
||||
"""
|
||||
method = method.upper()
|
||||
assert method in [
|
||||
'GET',
|
||||
'HEAD',
|
||||
'DELETE',
|
||||
'POST',
|
||||
'PUT',
|
||||
'PATCH',
|
||||
'OPTIONS'
|
||||
]
|
||||
|
||||
if post_params and body:
|
||||
raise ApiValueError(
|
||||
"body parameter cannot be used with post_params parameter."
|
||||
)
|
||||
|
||||
post_params = post_params or {}
|
||||
headers = headers or {}
|
||||
timeout = _request_timeout or 5 * 60
|
||||
|
||||
if 'Content-Type' not in headers:
|
||||
headers['Content-Type'] = 'application/json'
|
||||
|
||||
args = {
|
||||
"method": method,
|
||||
"url": url,
|
||||
"timeout": timeout,
|
||||
"headers": headers
|
||||
}
|
||||
|
||||
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
||||
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
|
||||
if re.search('json', headers['Content-Type'], re.IGNORECASE):
|
||||
if body is not None:
|
||||
args["json"] = body
|
||||
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
|
||||
args["data"] = dict(post_params)
|
||||
elif headers['Content-Type'] == 'multipart/form-data':
|
||||
# must del headers['Content-Type'], or the correct
|
||||
# Content-Type which generated by httpx
|
||||
del headers['Content-Type']
|
||||
|
||||
files = []
|
||||
data = {}
|
||||
for param in post_params:
|
||||
k, v = param
|
||||
if isinstance(v, tuple) and len(v) == 3:
|
||||
files.append((k, v))
|
||||
else:
|
||||
# Ensures that dict objects are serialized
|
||||
if isinstance(v, dict):
|
||||
v = json.dumps(v)
|
||||
elif isinstance(v, int):
|
||||
v = str(v)
|
||||
data[k] = v
|
||||
|
||||
if files:
|
||||
args["files"] = files
|
||||
if data:
|
||||
args["data"] = data
|
||||
|
||||
# Pass a `bytes` parameter directly in the body to support
|
||||
# other content types than Json when `body` argument is provided
|
||||
# in serialized form
|
||||
elif isinstance(body, str) or isinstance(body, bytes):
|
||||
args["data"] = body
|
||||
else:
|
||||
# Cannot generate the request from given parameters
|
||||
msg = """Cannot prepare a request message for provided
|
||||
arguments. Please check that your arguments match
|
||||
declared content type."""
|
||||
raise ApiException(status=0, reason=msg)
|
||||
|
||||
if self.pool_manager is None:
|
||||
self.pool_manager = self._create_pool_manager()
|
||||
|
||||
r = await self.pool_manager.request(**args)
|
||||
return RESTResponse(r)
|
||||
|
||||
def _create_pool_manager(self) -> httpx.AsyncClient:
|
||||
limits = httpx.Limits(max_connections=self.maxsize)
|
||||
|
||||
proxy = None
|
||||
if self.proxy:
|
||||
proxy = httpx.Proxy(
|
||||
url=self.proxy,
|
||||
headers=self.proxy_headers
|
||||
)
|
||||
|
||||
return httpx.AsyncClient(
|
||||
limits=limits,
|
||||
proxy=proxy,
|
||||
verify=self.ssl_context,
|
||||
trust_env=True
|
||||
)
|
||||
@@ -39,6 +39,9 @@ python-dateutil = ">= 2.8.2"
|
||||
aiohttp = ">= 3.8.4"
|
||||
aiohttp-retry = ">= 2.8.3"
|
||||
{{/asyncio}}
|
||||
{{#httpx}}
|
||||
httpx = ">= 0.28.1"
|
||||
{{/httpx}}
|
||||
{{#tornado}}
|
||||
tornado = ">=4.2, <5"
|
||||
{{/tornado}}
|
||||
@@ -58,10 +61,10 @@ requires-python = ">=3.9"
|
||||
dependencies = [
|
||||
"urllib3 (>=2.1.0,<3.0.0)",
|
||||
"python-dateutil (>=2.8.2)",
|
||||
{{#asyncio}}
|
||||
{{#async}}
|
||||
"aiohttp (>=3.8.4)",
|
||||
"aiohttp-retry (>=2.8.3)",
|
||||
{{/asyncio}}
|
||||
{{/async}}
|
||||
{{#tornado}}
|
||||
"tornado (>=4.2,<5)",
|
||||
{{/tornado}}
|
||||
|
||||
@@ -4,6 +4,9 @@ python_dateutil >= 2.8.2
|
||||
aiohttp >= 3.8.4
|
||||
aiohttp-retry >= 2.8.3
|
||||
{{/asyncio}}
|
||||
{{#httpx}}
|
||||
httpx = ">= 0.28.1"
|
||||
{{/httpx}}
|
||||
{{#tornado}}
|
||||
tornado = ">= 4.2, < 5"
|
||||
{{/tornado}}
|
||||
|
||||
@@ -21,6 +21,9 @@ REQUIRES = [
|
||||
"aiohttp >= 3.8.4",
|
||||
"aiohttp-retry >= 2.8.3",
|
||||
{{/asyncio}}
|
||||
{{#httpx}}
|
||||
"httpx >= 0.28.1",
|
||||
{{/httpx}}
|
||||
{{#tornado}}
|
||||
"tornado>=4.2, < 5",
|
||||
{{/tornado}}
|
||||
|
||||
@@ -524,7 +524,7 @@ pub fn check_xss_map<T>(v: &std::collections::HashMap<String, T>) -> std::result
|
||||
/// Enumeration of values.
|
||||
/// Since this enum's variants do not hold data, we can easily define them as `#[repr(C)]`
|
||||
/// which helps with FFI.
|
||||
#[allow(non_camel_case_types)]
|
||||
#[allow(non_camel_case_types, clippy::large_enum_variant)]
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)]
|
||||
#[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))]
|
||||
@@ -751,17 +751,38 @@ impl std::str::FromStr for {{{classname}}} {
|
||||
{{^arrayModelType}}
|
||||
{{! general struct}}
|
||||
{{#anyOf.size}}
|
||||
/// Any of:
|
||||
{{#anyOf}}
|
||||
/// - {{{.}}}
|
||||
{{/anyOf}}
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct {{{classname}}}(Box<serde_json::value::RawValue>);
|
||||
{{#discriminator}}
|
||||
#[derive(Debug, Clone, PartialEq, serde::Deserialize)]
|
||||
#[serde(tag = "{{{propertyBaseName}}}")]
|
||||
{{/discriminator}}
|
||||
{{^discriminator}}
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(untagged)]
|
||||
{{/discriminator}}
|
||||
#[allow(non_camel_case_types, clippy::large_enum_variant)]
|
||||
pub enum {{{classname}}} {
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
{{{datatypeWithEnum}}}({{{dataType}}}),
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
}
|
||||
|
||||
impl validator::Validate for {{{classname}}}
|
||||
{
|
||||
fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> {
|
||||
std::result::Result::Ok(())
|
||||
match self {
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
{{^isModel}}
|
||||
Self::{{{datatypeWithEnum}}}(_) => std::result::Result::Ok(()),
|
||||
{{/isModel}}
|
||||
{{#isModel}}
|
||||
Self::{{{datatypeWithEnum}}}(v) => v.validate(),
|
||||
{{/isModel}}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -776,11 +797,32 @@ impl std::str::FromStr for {{{classname}}} {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for {{{classname}}} {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0.get() == other.0.get()
|
||||
{{#discriminator}}
|
||||
impl serde::Serialize for {{{classname}}} {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: serde::Serializer {
|
||||
match self {
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
Self::{{{datatypeWithEnum}}}(x) => x.serialize(serializer),
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/discriminator}}
|
||||
|
||||
{{#composedSchemas}}
|
||||
{{#anyOf}}
|
||||
{{#vendorExtensions.x-from-trait}}
|
||||
impl From<{{{dataType}}}> for {{{classname}}} {
|
||||
fn from(value: {{{dataType}}}) -> Self {
|
||||
Self::{{{datatypeWithEnum}}}(value)
|
||||
}
|
||||
}
|
||||
{{/vendorExtensions.x-from-trait}}
|
||||
{{/anyOf}}
|
||||
{{/composedSchemas}}
|
||||
|
||||
{{/anyOf.size}}
|
||||
{{#oneOf.size}}
|
||||
@@ -792,11 +834,11 @@ impl PartialEq for {{{classname}}} {
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(untagged)]
|
||||
{{/discriminator}}
|
||||
#[allow(non_camel_case_types)]
|
||||
#[allow(non_camel_case_types, clippy::large_enum_variant)]
|
||||
pub enum {{{classname}}} {
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
{{{datatypeWithEnum}}}(Box<{{{dataType}}}>),
|
||||
{{{datatypeWithEnum}}}({{{dataType}}}),
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
}
|
||||
@@ -807,18 +849,29 @@ impl validator::Validate for {{{classname}}}
|
||||
match self {
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
{{#isPrimitiveType}}
|
||||
{{^isModel}}
|
||||
Self::{{{datatypeWithEnum}}}(_) => std::result::Result::Ok(()),
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
Self::{{{datatypeWithEnum}}}(x) => x.validate(),
|
||||
{{/isPrimitiveType}}
|
||||
{{/isModel}}
|
||||
{{#isModel}}
|
||||
Self::{{{datatypeWithEnum}}}(v) => v.validate(),
|
||||
{{/isModel}}
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts Query Parameters representation (style=form, explode=false) to a {{{classname}}} value
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl std::str::FromStr for {{{classname}}} {
|
||||
type Err = serde_json::Error;
|
||||
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
{{#discriminator}}
|
||||
impl serde::Serialize for {{{classname}}} {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
@@ -834,29 +887,18 @@ impl serde::Serialize for {{{classname}}} {
|
||||
}
|
||||
{{/discriminator}}
|
||||
|
||||
|
||||
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
{{#vendorExtensions.x-from-trait}}
|
||||
impl From<{{{dataType}}}> for {{{classname}}} {
|
||||
fn from(value: {{{dataType}}}) -> Self {
|
||||
Self::{{{datatypeWithEnum}}}(Box::new(value))
|
||||
Self::{{{datatypeWithEnum}}}(value)
|
||||
}
|
||||
}
|
||||
{{/vendorExtensions.x-from-trait}}
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
|
||||
/// Converts Query Parameters representation (style=form, explode=false) to a {{{classname}}} value
|
||||
/// as specified in https://swagger.io/docs/specification/serialization/
|
||||
/// Should be implemented in a serde deserializer
|
||||
impl std::str::FromStr for {{{classname}}} {
|
||||
type Err = serde_json::Error;
|
||||
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
{{/oneOf.size}}
|
||||
{{^anyOf.size}}
|
||||
{{^oneOf.size}}
|
||||
@@ -871,8 +913,10 @@ pub struct {{{classname}}} {
|
||||
/// Note: inline enums are not fully supported by openapi-generator
|
||||
{{/isEnum}}
|
||||
{{#isDiscriminator}}
|
||||
{{#isString}}
|
||||
#[serde(default = "{{{classname}}}::_name_for_{{{name}}}")]
|
||||
#[serde(serialize_with = "{{{classname}}}::_serialize_{{{name}}}")]
|
||||
{{/isString}}
|
||||
{{/isDiscriminator}}
|
||||
#[serde(rename = "{{{baseName}}}")]
|
||||
{{#hasValidation}}
|
||||
@@ -989,9 +1033,9 @@ pub struct {{{classname}}} {
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
|
||||
{{#vars}}
|
||||
{{#isDiscriminator}}
|
||||
{{#isString}}
|
||||
impl {{{classname}}} {
|
||||
fn _name_for_{{{name}}}() -> String {
|
||||
String::from("{{{classname}}}")
|
||||
@@ -1004,10 +1048,10 @@ impl {{{classname}}} {
|
||||
s.serialize_str(&Self::_name_for_{{{name}}}())
|
||||
}
|
||||
}
|
||||
{{/isString}}
|
||||
{{/isDiscriminator}}
|
||||
{{/vars}}
|
||||
|
||||
|
||||
{{#vars}}
|
||||
{{#hasValidation}}
|
||||
{{#pattern}}
|
||||
@@ -1035,9 +1079,9 @@ fn validate_byte_{{#lambda.lowercase}}{{{classname}}}_{{{name}}}{{/lambda.lowerc
|
||||
|
||||
impl {{{classname}}} {
|
||||
#[allow(clippy::new_without_default, clippy::too_many_arguments)]
|
||||
pub fn new({{#vars}}{{^defaultValue}}{{{name}}}: {{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}, {{/defaultValue}}{{/vars}}) -> {{{classname}}} {
|
||||
pub fn new({{#vars}}{{^isDiscriminator}}{{^defaultValue}}{{{name}}}: {{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}, {{/defaultValue}}{{/isDiscriminator}}{{#isDiscriminator}}{{^isString}}{{^defaultValue}}{{{name}}}: {{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}, {{/defaultValue}}{{/isString}}{{/isDiscriminator}}{{/vars}}) -> {{{classname}}} {
|
||||
{{{classname}}} {
|
||||
{{#vars}} {{#defaultValue}}{{{name}}}: {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}{{{name}}}{{/defaultValue}},
|
||||
{{#vars}} {{^isDiscriminator}}{{#defaultValue}}{{{name}}}: {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}{{{name}}}{{/defaultValue}}{{/isDiscriminator}}{{#isDiscriminator}}{{#isString}}{{{name}}}: Self::_name_for_{{{name}}}(){{/isString}}{{^isString}}{{#defaultValue}}{{{name}}}: {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}{{{name}}}{{/defaultValue}}{{/isString}}{{/isDiscriminator}},
|
||||
{{/vars}}
|
||||
}
|
||||
}
|
||||
@@ -1075,7 +1119,7 @@ impl std::fmt::Display for {{{classname}}} {
|
||||
{{/isArray}}
|
||||
{{#isArray}}
|
||||
{{#isNullable}}
|
||||
Some(self.{{{name}}}.as_ref().map_or(vec!["null".to_string()], |x| x.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(","))),
|
||||
Some(self.{{{name}}}.as_ref().map_or("null".to_string(), |x| x.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(","))),
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
Some(self.{{{name}}}.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(",")),
|
||||
@@ -1226,7 +1270,6 @@ impl std::convert::TryFrom<HeaderValue> for header::IntoHeaderValue<{{{classname
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{{/oneOf.size}}
|
||||
{{/anyOf.size}}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ google-cloud-token = "^0.1"
|
||||
{{/supportAsync}}
|
||||
|
||||
[features]
|
||||
default = ["native-tls"]
|
||||
default = [{{#reqwestDefaultFeatures}}"{{.}}"{{^-last}}, {{/-last}}{{/reqwestDefaultFeatures}}]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
{{/reqwest}}
|
||||
@@ -109,7 +109,7 @@ mockall = { version = "^0.13", optional = true}
|
||||
bon = { version = "2.3", optional = true }
|
||||
{{/useBonBuilder}}
|
||||
[features]
|
||||
default = ["native-tls"]
|
||||
default = [{{#reqwestDefaultFeatures}}"{{.}}"{{^-last}}, {{/-last}}{{/reqwestDefaultFeatures}}]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
{{#mockall}}
|
||||
|
||||
@@ -121,145 +121,80 @@ impl Default for {{classname}} {
|
||||
{{!-- for non-enum schemas --}}
|
||||
{{^isEnum}}
|
||||
{{^discriminator}}
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
{{#-first}}
|
||||
{{! Model with composedSchemas.oneOf - generate enum}}
|
||||
{{#vendorExtensions.x-rust-has-byte-array}}#[serde_as]
|
||||
{{/vendorExtensions.x-rust-has-byte-array}}{{#oneOf.isEmpty}}#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct {{{classname}}} {
|
||||
{{#vars}}
|
||||
{{#description}}
|
||||
/// {{{.}}}
|
||||
{{/description}}
|
||||
{{#isByteArray}}
|
||||
{{#vendorExtensions.isMandatory}}#[serde_as(as = "serde_with::base64::Base64")]{{/vendorExtensions.isMandatory}}{{^vendorExtensions.isMandatory}}#[serde_as(as = "{{^serdeAsDoubleOption}}Option{{/serdeAsDoubleOption}}{{#serdeAsDoubleOption}}super::DoubleOption{{/serdeAsDoubleOption}}<serde_with::base64::Base64>")]{{/vendorExtensions.isMandatory}}
|
||||
{{/isByteArray}}
|
||||
#[serde(rename = "{{{baseName}}}"{{^required}}{{#isNullable}}, default{{^isByteArray}}, with = "::serde_with::rust::double_option"{{/isByteArray}}{{/isNullable}}{{/required}}{{^required}}, skip_serializing_if = "Option::is_none"{{/required}}{{#required}}{{#isNullable}}, deserialize_with = "Option::deserialize"{{/isNullable}}{{/required}})]
|
||||
pub {{{name}}}: {{!
|
||||
### Option Start
|
||||
}}{{#isNullable}}Option<{{/isNullable}}{{^required}}Option<{{/required}}{{!
|
||||
### Enums
|
||||
}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{!
|
||||
### Non-Enums Start
|
||||
}}{{^isEnum}}{{!
|
||||
### Models
|
||||
}}{{#isModel}}{{^avoidBoxedModels}}Box<{{/avoidBoxedModels}}{{{dataType}}}{{^avoidBoxedModels}}>{{/avoidBoxedModels}}{{/isModel}}{{!
|
||||
### Primative datatypes
|
||||
}}{{^isModel}}{{#isByteArray}}Vec<u8>{{/isByteArray}}{{^isByteArray}}{{{dataType}}}{{/isByteArray}}{{/isModel}}{{!
|
||||
### Non-Enums End
|
||||
}}{{/isEnum}}{{!
|
||||
### Option End (and trailing comma)
|
||||
}}{{#isNullable}}>{{/isNullable}}{{^required}}>{{/required}},
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
impl {{{classname}}} {
|
||||
{{#description}}
|
||||
/// {{{.}}}
|
||||
{{/description}}
|
||||
pub fn new({{#requiredVars}}{{{name}}}: {{!
|
||||
### Option Start
|
||||
}}{{#isNullable}}Option<{{/isNullable}}{{!
|
||||
### Enums
|
||||
}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{!
|
||||
### Non-Enums
|
||||
}}{{^isEnum}}{{#isByteArray}}Vec<u8>{{/isByteArray}}{{^isByteArray}}{{{dataType}}}{{/isByteArray}}{{/isEnum}}{{!
|
||||
### Option End
|
||||
}}{{#isNullable}}>{{/isNullable}}{{!
|
||||
### Comma for next arguement
|
||||
}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
|
||||
{{{classname}}} {
|
||||
{{#vars}}
|
||||
{{{name}}}{{^required}}: None{{/required}}{{#required}}{{#isModel}}{{^avoidBoxedModels}}: {{^isNullable}}Box::new({{{name}}}){{/isNullable}}{{#isNullable}}if let Some(x) = {{{name}}} {Some(Box::new(x))} else {None}{{/isNullable}}{{/avoidBoxedModels}}{{/isModel}}{{/required}},
|
||||
{{/vars}}
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/oneOf.isEmpty}}
|
||||
{{^oneOf.isEmpty}}
|
||||
{{! TODO: add other vars that are not part of the oneOf}}
|
||||
{{#description}}
|
||||
/// {{{.}}}
|
||||
{{/description}}
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum {{classname}} {
|
||||
{{/-first}}
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
{{#composedSchemas.oneOf}}
|
||||
{{#description}}
|
||||
/// {{{.}}}
|
||||
{{/description}}
|
||||
{{{name}}}({{#isModel}}{{^avoidBoxedModels}}Box<{{/avoidBoxedModels}}{{/isModel}}{{{dataType}}}{{#isModel}}{{^avoidBoxedModels}}>{{/avoidBoxedModels}}{{/isModel}}),
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
{{#composedSchemas}}
|
||||
{{#oneOf}}
|
||||
{{#-last}}
|
||||
{{/composedSchemas.oneOf}}
|
||||
}
|
||||
|
||||
impl Default for {{classname}} {
|
||||
fn default() -> Self {
|
||||
{{#oneOf}}{{#-first}}Self::{{{name}}}(Default::default()){{/-first}}{{/oneOf}}
|
||||
{{#composedSchemas.oneOf}}{{#-first}}Self::{{{name}}}(Default::default()){{/-first}}{{/composedSchemas.oneOf}}
|
||||
}
|
||||
}
|
||||
{{/-last}}
|
||||
{{/oneOf}}
|
||||
{{^oneOf}}
|
||||
{{! composedSchemas exists but no oneOf - generate normal struct}}
|
||||
{{#vendorExtensions.x-rust-has-byte-array}}#[serde_as]
|
||||
{{/vendorExtensions.x-rust-has-byte-array}}#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct {{{classname}}} {
|
||||
{{#vars}}
|
||||
{{#description}}
|
||||
/// {{{.}}}
|
||||
{{/description}}
|
||||
{{#isByteArray}}
|
||||
{{#vendorExtensions.isMandatory}}#[serde_as(as = "serde_with::base64::Base64")]{{/vendorExtensions.isMandatory}}{{^vendorExtensions.isMandatory}}#[serde_as(as = "{{^serdeAsDoubleOption}}Option{{/serdeAsDoubleOption}}{{#serdeAsDoubleOption}}super::DoubleOption{{/serdeAsDoubleOption}}<serde_with::base64::Base64>")]{{/vendorExtensions.isMandatory}}
|
||||
{{/isByteArray}}
|
||||
#[serde(rename = "{{{baseName}}}"{{^required}}{{#isNullable}}, default{{^isByteArray}}, with = "::serde_with::rust::double_option"{{/isByteArray}}{{/isNullable}}{{/required}}{{^required}}, skip_serializing_if = "Option::is_none"{{/required}}{{#required}}{{#isNullable}}, deserialize_with = "Option::deserialize"{{/isNullable}}{{/required}})]
|
||||
pub {{{name}}}: {{!
|
||||
### Option Start
|
||||
}}{{#isNullable}}Option<{{/isNullable}}{{^required}}Option<{{/required}}{{!
|
||||
### Enums
|
||||
}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{!
|
||||
### Non-Enums Start
|
||||
}}{{^isEnum}}{{!
|
||||
### Models
|
||||
}}{{#isModel}}{{^avoidBoxedModels}}Box<{{/avoidBoxedModels}}{{{dataType}}}{{^avoidBoxedModels}}>{{/avoidBoxedModels}}{{/isModel}}{{!
|
||||
### Primative datatypes
|
||||
}}{{^isModel}}{{#isByteArray}}Vec<u8>{{/isByteArray}}{{^isByteArray}}{{{dataType}}}{{/isByteArray}}{{/isModel}}{{!
|
||||
### Non-Enums End
|
||||
}}{{/isEnum}}{{!
|
||||
### Option End (and trailing comma)
|
||||
}}{{#isNullable}}>{{/isNullable}}{{^required}}>{{/required}},
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
impl {{{classname}}} {
|
||||
{{#description}}
|
||||
/// {{{.}}}
|
||||
{{/description}}
|
||||
pub fn new({{#requiredVars}}{{{name}}}: {{!
|
||||
### Option Start
|
||||
}}{{#isNullable}}Option<{{/isNullable}}{{!
|
||||
### Enums
|
||||
}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{!
|
||||
### Non-Enums
|
||||
}}{{^isEnum}}{{#isByteArray}}Vec<u8>{{/isByteArray}}{{^isByteArray}}{{{dataType}}}{{/isByteArray}}{{/isEnum}}{{!
|
||||
### Option End
|
||||
}}{{#isNullable}}>{{/isNullable}}{{!
|
||||
### Comma for next arguement
|
||||
}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
|
||||
{{{classname}}} {
|
||||
{{#vars}}
|
||||
{{{name}}}{{^required}}: None{{/required}}{{#required}}{{#isModel}}{{^avoidBoxedModels}}: {{^isNullable}}Box::new({{{name}}}){{/isNullable}}{{#isNullable}}if let Some(x) = {{{name}}} {Some(Box::new(x))} else {None}{{/isNullable}}{{/avoidBoxedModels}}{{/isModel}}{{/required}},
|
||||
{{/vars}}
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/oneOf}}
|
||||
{{/composedSchemas}}
|
||||
{{^composedSchemas}}
|
||||
{{! Normal struct without composedSchemas}}
|
||||
{{#vendorExtensions.x-rust-has-byte-array}}#[serde_as]
|
||||
{{/vendorExtensions.x-rust-has-byte-array}}#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct {{{classname}}} {
|
||||
{{#vars}}
|
||||
{{#description}}
|
||||
/// {{{.}}}
|
||||
{{/description}}
|
||||
{{#isByteArray}}
|
||||
{{#vendorExtensions.isMandatory}}#[serde_as(as = "serde_with::base64::Base64")]{{/vendorExtensions.isMandatory}}{{^vendorExtensions.isMandatory}}#[serde_as(as = "{{^serdeAsDoubleOption}}Option{{/serdeAsDoubleOption}}{{#serdeAsDoubleOption}}super::DoubleOption{{/serdeAsDoubleOption}}<serde_with::base64::Base64>")]{{/vendorExtensions.isMandatory}}
|
||||
{{/isByteArray}}
|
||||
#[serde(rename = "{{{baseName}}}"{{^required}}{{#isNullable}}, default{{^isByteArray}}, with = "::serde_with::rust::double_option"{{/isByteArray}}{{/isNullable}}{{/required}}{{^required}}, skip_serializing_if = "Option::is_none"{{/required}}{{#required}}{{#isNullable}}, deserialize_with = "Option::deserialize"{{/isNullable}}{{/required}})]
|
||||
pub {{{name}}}: {{!
|
||||
### Option Start
|
||||
}}{{#isNullable}}Option<{{/isNullable}}{{^required}}Option<{{/required}}{{!
|
||||
### Enums
|
||||
}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{!
|
||||
### Non-Enums Start
|
||||
}}{{^isEnum}}{{!
|
||||
### Models
|
||||
}}{{#isModel}}{{^avoidBoxedModels}}Box<{{/avoidBoxedModels}}{{{dataType}}}{{^avoidBoxedModels}}>{{/avoidBoxedModels}}{{/isModel}}{{!
|
||||
### Primative datatypes
|
||||
}}{{^isModel}}{{#isByteArray}}Vec<u8>{{/isByteArray}}{{^isByteArray}}{{{dataType}}}{{/isByteArray}}{{/isModel}}{{!
|
||||
### Non-Enums End
|
||||
}}{{/isEnum}}{{!
|
||||
### Option End (and trailing comma)
|
||||
}}{{#isNullable}}>{{/isNullable}}{{^required}}>{{/required}},
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
impl {{{classname}}} {
|
||||
{{#description}}
|
||||
/// {{{.}}}
|
||||
{{/description}}
|
||||
pub fn new({{#requiredVars}}{{{name}}}: {{!
|
||||
### Option Start
|
||||
}}{{#isNullable}}Option<{{/isNullable}}{{!
|
||||
### Enums
|
||||
}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{!
|
||||
### Non-Enums
|
||||
}}{{^isEnum}}{{#isByteArray}}Vec<u8>{{/isByteArray}}{{^isByteArray}}{{{dataType}}}{{/isByteArray}}{{/isEnum}}{{!
|
||||
### Option End
|
||||
}}{{#isNullable}}>{{/isNullable}}{{!
|
||||
### Comma for next arguement
|
||||
}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
|
||||
{{{classname}}} {
|
||||
{{#vars}}
|
||||
{{{name}}}{{^required}}: None{{/required}}{{#required}}{{#isModel}}{{^avoidBoxedModels}}: {{^isNullable}}Box::new({{{name}}}){{/isNullable}}{{#isNullable}}if let Some(x) = {{{name}}} {Some(Box::new(x))} else {None}{{/isNullable}}{{/avoidBoxedModels}}{{/isModel}}{{/required}},
|
||||
{{/vars}}
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/composedSchemas}}
|
||||
{{/oneOf.isEmpty}}
|
||||
{{/discriminator}}
|
||||
{{/isEnum}}
|
||||
{{!-- for properties that are of enum type --}}
|
||||
|
||||
@@ -65,5 +65,5 @@ import {operationId} from './symlinkDir';
|
||||
The CommonJS syntax is as follows:
|
||||
|
||||
```
|
||||
import localName = require('./symlinkDir')';
|
||||
import localName = require('./symlinkDir');
|
||||
```
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user