Compare commits

..

27 Commits

Author SHA1 Message Date
William Cheng
2715f1371a Prepare 5.0.0 beta3 (#7984)
* prepare 5.0.0-beta3 release

* update samples

* remove beta3 from readme
2020-11-20 15:18:58 +08:00
William Cheng
dd26e406b5 Fix duplicated mappedModels (#7924)
* fix duplicated mapped models

* replace discriminatorExplicitMappingVerbose with legacyDiscriminatorBehavior in comments

* use mappingName for comparison

* improve template

* fix tests

* update comments

* update ts samples
2020-11-20 11:57:48 +08:00
William Cheng
cf8ea9120a fix additional properties without variables (#7978) 2020-11-20 11:54:39 +08:00
William Cheng
c02fc812fe add warning about unsupported libraries in python client generator (#7981) 2020-11-20 11:54:16 +08:00
William Cheng
5e02a5bd45 Set generateAliasAsModel to false in tests (#7979)
* set generateAliasAsModel false in tests

* add missing import
2020-11-20 10:56:05 +08:00
William Cheng
b5ce7cec8b comment out angular v6, v7 tests 2020-11-18 16:13:09 +08:00
William Cheng
78611b3e38 update samples 2020-11-18 14:46:36 +08:00
William Cheng
3bf8ca7484 [python] Renames python generators (#7965)
* python->python-legacy, python-experimental->python

* test with openjdk8

* test with openjdk11

* comment out rm

* move kotlin tests to circleci

* move kotlin tests

* move tests to circleci

* fix circleci

* rearrange test

* move tests

* use wrapper

Co-authored-by: Justin Black <justin.a.black@gmail.com>
2020-11-18 14:34:00 +08:00
Justin Black
c08f14500e Revert "Do not use cached properties for additionalProperties (#7955)" (#7971)
This reverts commit 057647cf1e.
2020-11-17 21:08:55 -08:00
Justin Black
057647cf1e Do not use cached properties for additionalProperties (#7955)
* Fixes additionalProperties, do not use cached properties for additonalProperties

* Regnerates samples
2020-11-16 11:26:54 -08:00
Alexis Cote
36aba267a0 [typescript-fetch] Allow to generate client without runtime checks (#7894)
* Add CLI options to remove runtime checks (serialization/deserialization).

* Update templates to support the new parameter

- Generates all the models in a same file to avoid import complexity
- Extract interfaces creator templates to reuse them

* Fix formatting and generate client examples

* Add documentation
2020-11-16 14:17:29 +01:00
Alexander Rashed
54d6257865 Fix parameter uniqueness for form- and body-params (#7577)
If a form-parameter had the same name as another (header-, query-,
path-, or cookie-)parameter, a conflict could be caused (for example
in the typescript generator). This fix executes the same uniqueness-
check and renaming for form- and body-parameters as it is done for
all other parameters.

@see issue #7575

Co-authored-by: Alexander Rashed <alexander.rashed@ntsretail.com>
2020-11-16 21:16:53 +08:00
William Cheng
aca6927ce0 add lvm_versicherungen logo (#7946) 2020-11-16 15:35:12 +08:00
patst
023e6dd9ed typescript-angular: Angular 11 support (#7937)
* #7935 typescript-angular: support angular 11

* regenerate angular 11 sample project

* Update ngVersion to 11.0.0 in typescript-angular.md
2020-11-14 08:23:13 +01:00
Kai Brandes
88dc21959d Add "LVM Versicherungen" to list of companies (#7931) 2020-11-13 22:33:08 +08:00
William Cheng
a3a0af7c84 [C#][netcore] Add test for AdditionalProperties in both child and parent (#7921)
* add test for ap in both child and parent

* add cat test to net47
2020-11-13 21:13:16 +08:00
Esteban Gehring
e725c4e56f update typescript-fetch samples (#7936) 2020-11-13 13:42:55 +01:00
berlysia
920eafc9c1 [typescript-fetch] add samples of nullable enum (#7754)
* [typescript-fetch] add sample

* [typescript-fetch] add sample for nullable enums
2020-11-13 13:17:35 +01:00
William Cheng
405aa24737 fix shippable issue (#7932) 2020-11-13 19:48:55 +08:00
Thomas Hervé
777031f24f Fix a few issues with go examples generation (#7873)
* Fix a few issues with go examples generation

This fixes a bunch of issues seen when generating go examples, namely
 - Numbers aren't casted to the right type
 - The time import is missing
 - Enums are treated as regular models

* Rebuild more samples

* Use examples properly

* Handle multiple instances in the same doc

* Fix wrong array closure

* Handle model arrays

* Fix file and enum namespace

* Regenerate samples

* Handle maps of complex types

* Handle oneOf

* Fix padding

* Fix enum doc

* Removes links to basic types in arrays

* Remove links to basic types in maps

* Fix enum links

* Minor indent fix

* Handle review comments
2020-11-12 23:36:40 +08:00
Daniel Varnai
3b84e8bb55 Fix missing parenthesis (#7923) 2020-11-12 11:13:50 +01:00
Jeff Brower
ec13288c02 Fix NPE in CodegenIgnoreProcessor.java (fixes #3356) (#7846)
Fixes NullPointerException when using an override ignore file with no parent.
2020-11-11 10:22:51 -05:00
Justin Black
13673962cb Adds tests case showing not sending optional params (#7918) 2020-11-10 08:52:43 -08:00
William Cheng
eab26d493b Better decimal support in Scala generators (#7876)
* fix decimal mapping in scala generators

* add mapping for decimal, number in scala generators

* update doc

* use scala.math.BigDecimal
2020-11-10 11:29:50 +08:00
William Cheng
f8766d591c [C#][Nancyfx] fix incorrect import (#7907)
* fix incorrect import

* remove importMapping
2020-11-10 09:33:34 +08:00
William Cheng
b1b64cb356 throw exception for invalid framework (#7901) 2020-11-10 09:33:07 +08:00
Rocky Warren
81e0e8dfa8 [typescript-axios]: Check configuration is defined in api.ts so it compiles with strict flag (#7892)
* Check configuration is defined

* Update samples
2020-11-09 20:56:08 +01:00
2141 changed files with 55182 additions and 44791 deletions

View File

@@ -103,9 +103,7 @@ The OpenAPI Specification has undergone 3 revisions since initial creation in 20
| OpenAPI Generator Version | Release Date | Notes |
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------------------------------------------- |
| 5.0.0 (upcoming major release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.0.0-SNAPSHOT/) | TBD | Major release with breaking changes (no fallback) |
| 5.0.0-beta3 (upcoming beta release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.0.0-SNAPSHOT/) | 01.11.2020 | Major beta release with breaking changes (no fallback) |
| [5.0.0-beta2](https://github.com/OpenAPITools/openapi-generator/releases/tag/v5.0.0-beta2) (latest beta release) | 04.09.2020 | Major beta release with breaking changes (no fallback) |
| [5.0.0-beta](https://github.com/OpenAPITools/openapi-generator/releases/tag/v5.0.0-beta) (latest beta release) | 30.06.2020 | Major beta release with breaking changes (no fallback) |
| [5.0.0-beta3](https://github.com/OpenAPITools/openapi-generator/releases/tag/v5.0.0-beta3) (latest beta release) | 20.11.2020 | Major beta release with breaking changes (no fallback) |
| [4.3.1](https://github.com/OpenAPITools/openapi-generator/releases/tag/v4.3.1) (latest stable release) | 06.05.2020 | Patch release (enhancements, bug fixes, etc) |
OpenAPI Spec compatibility: 1.0, 1.1, 1.2, 2.0, 3.0
@@ -162,16 +160,16 @@ See the different versions of the [openapi-generator-cli](https://mvnrepository.
<!-- RELEASE_VERSION -->
If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum):
JAR location: `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta2/openapi-generator-cli-5.0.0-beta2.jar`
JAR location: `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta3/openapi-generator-cli-5.0.0-beta3.jar`
For **Mac/Linux** users:
```sh
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta2/openapi-generator-cli-5.0.0-beta2.jar -O openapi-generator-cli.jar
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta3/openapi-generator-cli-5.0.0-beta3.jar -O openapi-generator-cli.jar
```
For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.
```
Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta2/openapi-generator-cli-5.0.0-beta2.jar
Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta3/openapi-generator-cli-5.0.0-beta3.jar
```
After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage.
@@ -420,7 +418,7 @@ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generat
(if you're on Windows, replace the last command with `java -jar modules\openapi-generator-cli\target\openapi-generator-cli.jar generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php -o c:\temp\php_api_client`)
<!-- RELEASE_VERSION -->
You can also download the JAR (latest release) directly from [maven.org](https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta2/openapi-generator-cli-5.0.0-beta2.jar)
You can also download the JAR (latest release) directly from [maven.org](https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta3/openapi-generator-cli-5.0.0-beta3.jar)
<!-- /RELEASE_VERSION -->
To get a list of **general** options available, please run `java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar help generate`
@@ -612,6 +610,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
- [Kubernetes](https://kubernetes.io)
- [Linode](https://www.linode.com/)
- [Logicdrop](https://www.logicdrop.com)
- [LVM Versicherungen](https://www.lvm.de)
- [MailSlurp](https://www.mailslurp.com)
- [Médiavision](https://www.mediavision.fr/)
- [Metaswitch](https://www.metaswitch.com/)
@@ -859,7 +858,7 @@ Here is a list of template creators:
* PHP (Guzzle): @baartosz
* PowerShell: @beatcracker
* PowerShell (refactored in 5.0.0): @wing328
* Python-experimental: @spacether
* Python: @spacether
* R: @ramnov
* Ruby (Faraday): @meganemura @dkliban
* Rust: @farcaller

View File

@@ -1,4 +0,0 @@
generatorName: cpp-oatpp-server
outputDir: samples/server/petstore/cpp-oatpp
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/cpp-oatpp-server

View File

@@ -1,7 +1,7 @@
generatorName: python
generatorName: python-legacy
outputDir: samples/client/petstore/python-asyncio
library: asyncio
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/python
templateDir: modules/openapi-generator/src/main/resources/python-legacy
additionalProperties:
packageName: petstore_api

View File

@@ -1,7 +0,0 @@
generatorName: python-experimental
outputDir: samples/client/petstore/python-experimental
inputSpec: modules/openapi-generator/src/test/resources/2_0/python-client-experimental/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/python
additionalProperties:
disallowAdditionalPropertiesIfNotPresent: "true"
packageName: petstore_api

View File

@@ -1,7 +0,0 @@
generatorName: python-experimental
outputDir: samples/openapi3/client/petstore/python-experimental
inputSpec: modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
templateDir: modules/openapi-generator/src/main/resources/python
additionalProperties:
packageName: petstore_api
recursionLimit: "1234"

View File

@@ -1,5 +1,5 @@
generatorName: python-experimental
outputDir: samples/openapi3/client/extensions/x-auth-id-alias/python-experimental/
generatorName: python
outputDir: samples/openapi3/client/extensions/x-auth-id-alias/python/
inputSpec: modules/openapi-generator/src/test/resources/3_0/extensions/x-auth-id-alias.yaml
templateDir: modules/openapi-generator/src/main/resources/python
additionalProperties:

View File

@@ -1,5 +1,5 @@
generatorName: python-experimental
outputDir: samples/openapi3/client/features/dynamic-servers/python-experimental/
generatorName: python
outputDir: samples/openapi3/client/features/dynamic-servers/python/
inputSpec: modules/openapi-generator/src/test/resources/3_0/features/dynamic-servers.yaml
templateDir: modules/openapi-generator/src/main/resources/python
additionalProperties:

View File

@@ -0,0 +1,6 @@
generatorName: python-legacy
outputDir: samples/client/petstore/python-legacy
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/python-legacy
additionalProperties:
packageName: petstore_api

View File

@@ -0,0 +1,6 @@
generatorName: python-legacy
outputDir: samples/openapi3/client/petstore/python-legacy
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/python-legacy
additionalProperties:
packageName: petstore_api

View File

@@ -1,6 +1,7 @@
generatorName: python
outputDir: samples/client/petstore/python
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
inputSpec: modules/openapi-generator/src/test/resources/2_0/python-client-experimental/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/python
additionalProperties:
disallowAdditionalPropertiesIfNotPresent: "true"
packageName: petstore_api

View File

@@ -1,7 +1,7 @@
generatorName: python
generatorName: python-legacy
outputDir: samples/client/petstore/python-tornado
library: tornado
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/python
templateDir: modules/openapi-generator/src/main/resources/python-legacy
additionalProperties:
packageName: petstore_api

View File

@@ -1,6 +1,7 @@
generatorName: python
outputDir: samples/openapi3/client/petstore/python
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
inputSpec: modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
templateDir: modules/openapi-generator/src/main/resources/python
additionalProperties:
packageName: petstore_api
recursionLimit: "1234"

View File

@@ -0,0 +1,9 @@
generatorName: typescript-angular
outputDir: samples/client/petstore/typescript-angular-v11-provided-in-root/builds/with-npm
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
additionalProperties:
ngVersion: 11.0.0
npmVersion: 1.0.0
npmName: '@openapitools/typescript-angular-petstore'
npmRepository: https://skimdb.npmjs.com/registry
snapshot: false

View File

@@ -0,0 +1,5 @@
generatorName: typescript-angular
outputDir: samples/client/petstore/typescript-angular-v11-provided-in-root/builds/default
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
additionalProperties:
ngVersion: 11.0.0

View File

@@ -0,0 +1,3 @@
generatorName: typescript-fetch
outputDir: samples/client/petstore/typescript-fetch/builds/default-v3.0
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml

View File

@@ -0,0 +1,3 @@
generatorName: typescript-fetch
outputDir: samples/client/petstore/typescript-fetch/builds/enum
inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-fetch/enum.yaml

View File

@@ -0,0 +1,9 @@
generatorName: typescript-fetch
outputDir: samples/client/petstore/typescript-fetch/builds/without-runtime-checks
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
additionalProperties:
npmVersion: 1.0.0
npmName: '@openapitools/typescript-fetch-petstore'
npmRepository: https://skimdb.npmjs.com/registry
withoutRuntimeChecks: true
snapshot: false

View File

@@ -48,8 +48,8 @@ The following generators are available:
* [perl](generators/perl.md)
* [php](generators/php.md)
* [powershell (beta)](generators/powershell.md)
* [python](generators/python.md)
* [python-experimental (experimental)](generators/python-experimental.md)
* [python (experimental)](generators/python.md)
* [python-legacy](generators/python-legacy.md)
* [r](generators/r.md)
* [ruby](generators/ruby.md)
* [rust](generators/rust.md)

View File

@@ -40,8 +40,8 @@ The following generators are available:
* [perl](perl.md)
* [php](php.md)
* [powershell](powershell.md)
* [python](python.md)
* [python-experimental (experimental)](python-experimental.md)
* [python](python.md)
* [python-legacy](python-legacy.md)
* [r](r.md)
* [ruby](ruby.md)
* [rust](rust.md)

View File

@@ -1,6 +1,6 @@
---
title: Config Options for python-experimental
sidebar_label: python-experimental
title: Config Options for python-legacy
sidebar_label: python-legacy
---
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
@@ -14,8 +14,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|packageUrl|python package URL.| |null|
|packageVersion|python package version.| |1.0.0|
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|pythonAttrNoneIfUnset|when accessing unset attribute, return `None` instead of raising `ApiAttributeError`| |false|
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|useNose|use the nose test framework| |false|
## IMPORT MAPPING
@@ -28,7 +28,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| Type/Alias | Instantiated By |
| ---------- | --------------- |
|map|dict|
## LANGUAGE PRIMITIVES
@@ -40,11 +39,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>datetime</li>
<li>dict</li>
<li>file</li>
<li>file_type</li>
<li>float</li>
<li>int</li>
<li>list</li>
<li>none_type</li>
<li>object</li>
<li>str</li>
</ul>
@@ -167,7 +164,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Examples|✓|OAS2,OAS3
|XMLStructureDefinitions|✗|OAS2,OAS3
|MultiServer|✗|OAS3
|ParameterizedServer||OAS3
|ParameterizedServer||OAS3
|ParameterStyling|✗|OAS3
|Callbacks|✗|OAS3
|LinkObjects|✗|OAS3

View File

@@ -14,8 +14,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|packageUrl|python package URL.| |null|
|packageVersion|python package version.| |1.0.0|
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|pythonAttrNoneIfUnset|when accessing unset attribute, return `None` instead of raising `ApiAttributeError`| |false|
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|useNose|use the nose test framework| |false|
## IMPORT MAPPING
@@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| Type/Alias | Instantiated By |
| ---------- | --------------- |
|map|dict|
## LANGUAGE PRIMITIVES
@@ -39,9 +40,11 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>datetime</li>
<li>dict</li>
<li>file</li>
<li>file_type</li>
<li>float</li>
<li>int</li>
<li>list</li>
<li>none_type</li>
<li>object</li>
<li>str</li>
</ul>
@@ -164,7 +167,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Examples|✓|OAS2,OAS3
|XMLStructureDefinitions|✗|OAS2,OAS3
|MultiServer|✗|OAS3
|ParameterizedServer||OAS3
|ParameterizedServer||OAS3
|ParameterStyling|✗|OAS3
|Callbacks|✗|OAS3
|LinkObjects|✗|OAS3

View File

@@ -16,7 +16,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| Type/Alias | Imports |
| ---------- | ------- |
|ArrayBuffer|scala.collection.mutable.ArrayBuffer|
|BigDecimal|java.math.BigDecimal|
|Date|java.util.Date|
|DateTime|java.time.LocalDateTime|
|File|java.io.File|

View File

@@ -26,7 +26,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| ---------- | ------- |
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
|Date|java.util.Date|
|DateTime|org.joda.time.DateTime|
|File|java.io.File|

View File

@@ -19,7 +19,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|modelFileSuffix|The suffix of the file of the generated model (model&lt;suffix&gt;.ts).| |null|
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original|
|modelSuffix|The suffix of the generated model.| |null|
|ngVersion|The version of Angular. (At least 6.0.0)| |10.0.0|
|ngVersion|The version of Angular. (At least 6.0.0)| |11.0.0|
|npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null|
|npmRepository|Use this property to set an url your private npmRepo in the package.json| |null|
|npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0|

View File

@@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|typescriptThreePlus|Setting this property to true will generate TypeScript 3.6+ compatible code.| |false|
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |true|
|withInterfaces|Setting this property to true will generate interfaces next to the default class implementations.| |false|
|withoutRuntimeChecks|Setting this property to true will remove any runtime checks on the request and response payloads. Payloads will be casted to their expected types.| |false|
## IMPORT MAPPING

View File

@@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -6,7 +6,7 @@
<artifactId>openapi-generator-project</artifactId>
<groupId>org.openapitools</groupId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -97,7 +97,7 @@ task validateGoodSpec(type: org.openapitools.generator.gradle.plugin.tasks.Valid
[source,group]
----
plugins {
id "org.openapi.generator" version "4.3.1"
id "org.openapi.generator" version "5.0.0-beta3"
}
----
@@ -113,7 +113,7 @@ buildscript {
// url "https://plugins.gradle.org/m2/"
}
dependencies {
classpath "org.openapitools:openapi-generator-gradle-plugin:4.3.1"
classpath "org.openapitools:openapi-generator-gradle-plugin:5.0.0-beta3"
}
}

View File

@@ -1,5 +1,5 @@
# RELEASE_VERSION
openApiGeneratorVersion=5.0.0-SNAPSHOT
openApiGeneratorVersion=5.0.0-beta3
# /RELEASE_VERSION
# BEGIN placeholders

View File

@@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -18,5 +18,5 @@ gradle generateGoWithInvalidSpec # expected outcome: BUILD FAILED
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
```bash
gradle -PopenApiGeneratorVersion=4.3.0 openApiValidate
gradle -PopenApiGeneratorVersion=5.0.0-beta3 openApiValidate
```

View File

@@ -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>4.3.1</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>

View File

@@ -13,7 +13,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>

View File

@@ -19,7 +19,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<dependencies>
<dependency>

View File

@@ -13,7 +13,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>

View File

@@ -13,7 +13,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>

View File

@@ -5,7 +5,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-beta3</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -2,7 +2,7 @@ package org.openapitools.codegen;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.util.LinkedHashSet;
import java.util.TreeSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
@@ -25,14 +25,14 @@ public class CodegenDiscriminator {
private String propertyType;
private Map<String, String> mapping;
// mappedModels is populated differently if discriminatorExplicitMappingVerbose is
// mappedModels is populated differently if legacyDiscriminatorBehavior is
// True or False. When:
//
// discriminatorExplicitMappingVerbose == False, this contains:
// legacyDiscriminatorBehavior == False, this contains:
// - the name to schema map info in the discriminator mapping entry in your openapi spec OR
// - child schemas that allOf inherit self schema
//
// discriminatorExplicitMappingVerbose == True, this contains:
// legacyDiscriminatorBehavior == True, this contains:
// - the name to schema map info in the discriminMappedModelator mapping entry in your openapi spec AND
// - x-discriminator-value mappings in child oneOf + anyOf schemas + descendant schemas that allOf inherit self schema AND
// - descendant schemas that allOf inherit self schema AND
@@ -40,7 +40,7 @@ public class CodegenDiscriminator {
//
// see the method createDiscriminator in DefaultCodegen.java
private Set<MappedModel> mappedModels = new LinkedHashSet<>();
private Set<MappedModel> mappedModels = new TreeSet<>();
public String getPropertyName() {
return propertyName;

View File

@@ -2936,7 +2936,16 @@ public class DefaultCodegen implements CodegenConfig {
// for schemas that allOf inherit from this schema, add those descendants to this discriminator map
List<MappedModel> otherDescendants = getAllOfDescendants(schemaName, openAPI);
for (MappedModel otherDescendant : otherDescendants) {
if (!uniqueDescendants.contains(otherDescendant)) {
// add only if the mapping names are not the same
boolean matched = false;
for (MappedModel uniqueDescendant: uniqueDescendants) {
if (uniqueDescendant.getMappingName().equals(otherDescendant.getMappingName())) {
matched = true;
break;
}
}
if (matched == false) {
uniqueDescendants.add(otherDescendant);
}
}
@@ -2954,6 +2963,7 @@ public class DefaultCodegen implements CodegenConfig {
Collections.sort(uniqueDescendants);
}
discriminator.getMappedModels().addAll(uniqueDescendants);
return discriminator;
}
@@ -3856,10 +3866,20 @@ public class DefaultCodegen implements CodegenConfig {
// add form/body parameter (if any) to the end of all parameter list
if (!prependFormOrBodyParameters) {
for (CodegenParameter cp : formParams) {
if (ensureUniqueParams) {
if (!isParameterNameUnique(cp, allParams)) {
cp.paramName = generateNextName(cp.paramName);
}
}
allParams.add(cp.copy());
}
for (CodegenParameter cp : bodyParams) {
if (ensureUniqueParams) {
if (!isParameterNameUnique(cp, allParams)) {
cp.paramName = generateNextName(cp.paramName);
}
}
allParams.add(cp.copy());
}
}

View File

@@ -41,7 +41,7 @@ import org.openapitools.codegen.config.GlobalSettings;
import org.openapitools.codegen.api.TemplatingEngineAdapter;
import org.openapitools.codegen.api.TemplateFileType;
import org.openapitools.codegen.ignore.CodegenIgnoreProcessor;
import org.openapitools.codegen.languages.PythonClientExperimentalCodegen;
import org.openapitools.codegen.languages.PythonClientCodegen;
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.serializer.SerializerUtils;
@@ -520,9 +520,9 @@ public class DefaultGenerator implements Generator {
Map<String, Object> modelTemplate = (Map<String, Object>) ((List<Object>) models.get("models")).get(0);
if (modelTemplate != null && modelTemplate.containsKey("model")) {
CodegenModel m = (CodegenModel) modelTemplate.get("model");
if (m.isAlias && !(config instanceof PythonClientExperimentalCodegen)) {
if (m.isAlias && !(config instanceof PythonClientCodegen)) {
// alias to number, string, enum, etc, which should not be generated as model
// for PythonClientExperimentalCodegen, all aliases are generated as models
// for PythonClientCodegen, all aliases are generated as models
continue; // Don't create user-defined classes for aliases
}
}

View File

@@ -142,7 +142,7 @@ public class CodegenIgnoreProcessor {
public boolean allowsFile(final File targetFile) {
if(this.ignoreFile == null) return true;
File file = new File(this.ignoreFile.getParentFile().toURI().relativize(targetFile.toURI()).getPath());
File file = new File(this.ignoreFile.getAbsoluteFile().getParentFile().toURI().relativize(targetFile.toURI()).getPath());
Boolean directoryExcluded = false;
Boolean exclude = false;
if(exclusionRules.size() == 0 && inclusionRules.size() == 0) {

View File

@@ -118,8 +118,6 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
addSwitch(ASYNC_SERVER, "Set to true to enable the generation of async routes/endpoints.", this.asyncServer);
typeMapping.putAll(nodaTimeTypesMappings());
languageSpecificPrimitives.addAll(nodaTimePrimitiveTypes());
importMapping.clear();
}
@Override

View File

@@ -31,6 +31,7 @@ import java.io.File;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.openapitools.codegen.utils.StringUtils.camelize;
@@ -547,7 +548,6 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
additionalProperties.put(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES, optionalEmitDefaultValuesFlag);
}
if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) {
setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING));
}
@@ -561,13 +561,24 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
clientPackage = "Client";
String framework = (String) additionalProperties.getOrDefault(CodegenConstants.DOTNET_FRAMEWORK, defaultFramework.name);
boolean strategyMatched = false;
FrameworkStrategy strategy = defaultFramework;
for (FrameworkStrategy frameworkStrategy : frameworkStrategies) {
if (framework.equals(frameworkStrategy.name)) {
strategy = frameworkStrategy;
strategyMatched = true;
}
}
// throws exception if the input targetFramework is invalid
if (strategyMatched == false) {
throw new IllegalArgumentException("Invalid .NET framework version: " +
framework + ". List of supported versions: " +
frameworkStrategies.stream()
.map(p -> p.name)
.collect(Collectors.joining(", ")));
}
strategy.configureAdditionalProperties(additionalProperties);
setTargetFrameworkNuget(strategy.getNugetFrameworkIdentifier());
@@ -710,7 +721,11 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
public void setTargetFramework(String dotnetFramework) {
if (!frameworks.containsKey(dotnetFramework)) {
LOGGER.warn("Invalid .NET framework version, defaulting to " + this.targetFramework);
throw new IllegalArgumentException("Invalid .NET framework version: " +
dotnetFramework + ". List of supported versions: " +
frameworkStrategies.stream()
.map(p -> p.name)
.collect(Collectors.joining(", ")));
} else {
this.targetFramework = dotnetFramework;
}

View File

@@ -1,438 +0,0 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.servers.Server;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
import static org.openapitools.codegen.utils.StringUtils.underscore;
public class CppOatppServerCodegen extends AbstractCppCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(CppOatppServerCodegen.class);
protected String implFolder = "impl";
protected boolean isAddExternalLibs = true;
protected boolean isUseStructModel = false;
public static final String OPTIONAL_EXTERNAL_LIB = "addExternalLibs";
public static final String OPTIONAL_EXTERNAL_LIB_DESC = "Add the Possibility to fetch and compile external Libraries needed by this Framework.";
public static final String OPTION_USE_STRUCT_MODEL = "useStructModel";
public static final String OPTION_USE_STRUCT_MODEL_DESC = "Use struct-based model template instead of get/set-based model template";
public static final String HELPERS_PACKAGE_NAME = "helpersPackage";
public static final String HELPERS_PACKAGE_NAME_DESC = "Specify the package name to be used for the helpers (e.g. org.openapitools.server.helpers).";
protected final String PREFIX = "";
protected String helpersPackage = "";
@Override
public CodegenType getTag() {
return CodegenType.SERVER;
}
@Override
public String getName() {
return "cpp-oatpp-server";
}
@Override
public String getHelp() {
// Ref: https://github.com/oatpp/oatpp
return "Generates a C++ API server (based on Oat++)";
}
public CppOatppServerCodegen() {
super();
if (StringUtils.isEmpty(modelNamePrefix)) {
modelNamePrefix = PREFIX;
}
helpersPackage = "org.openapitools.server.helpers";
apiPackage = "org.openapitools.server.api";
modelPackage = "org.openapitools.server.model";
apiTemplateFiles.put("api-header.mustache", ".h");
apiTemplateFiles.put("api-source.mustache", ".cpp");
apiTemplateFiles.put("api-impl-header.mustache", ".h");
apiTemplateFiles.put("api-impl-source.mustache", ".cpp");
embeddedTemplateDir = templateDir = "cpp-oatpp-server";
cliOptions.clear();
addSwitch(OPTIONAL_EXTERNAL_LIB, OPTIONAL_EXTERNAL_LIB_DESC, this.isAddExternalLibs);
addOption(HELPERS_PACKAGE_NAME, HELPERS_PACKAGE_NAME_DESC, this.helpersPackage);
addOption(RESERVED_WORD_PREFIX_OPTION, RESERVED_WORD_PREFIX_DESC, this.reservedWordPrefix);
addSwitch(OPTION_USE_STRUCT_MODEL, OPTION_USE_STRUCT_MODEL_DESC, this.isUseStructModel);
addOption(VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_OPTION,
VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_DESC,
Boolean.toString(this.variableNameFirstCharacterUppercase));
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
supportingFiles.add(new SupportingFile("cmake.mustache", "", "CMakeLists.txt"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
languageSpecificPrimitives = new HashSet<String>(
Arrays.asList("int", "char", "bool", "long", "float", "double", "int32_t", "int64_t"));
typeMapping = new HashMap<String, String>();
typeMapping.put("date", "std::string");
typeMapping.put("DateTime", "std::string");
typeMapping.put("string", "std::string");
typeMapping.put("integer", "int32_t");
typeMapping.put("long", "int64_t");
typeMapping.put("boolean", "bool");
typeMapping.put("array", "std::vector");
typeMapping.put("map", "std::map");
typeMapping.put("file", "std::string");
typeMapping.put("object", "Object");
typeMapping.put("binary", "std::string");
typeMapping.put("number", "double");
typeMapping.put("UUID", "std::string");
typeMapping.put("URI", "std::string");
typeMapping.put("ByteArray", "std::string");
importMapping = new HashMap<String, String>();
importMapping.put("std::vector", "#include <vector>");
importMapping.put("std::map", "#include <map>");
importMapping.put("std::string", "#include <string>");
importMapping.put("Object", "#include \"Object.h\"");
}
@Override
public void processOpts() {
super.processOpts();
if (additionalProperties.containsKey(HELPERS_PACKAGE_NAME)) {
helpersPackage = (String) additionalProperties.get(HELPERS_PACKAGE_NAME);
}
if (additionalProperties.containsKey("modelNamePrefix")) {
additionalProperties().put("prefix", modelNamePrefix);
supportingFiles.clear();
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
supportingFiles.add(new SupportingFile("cmake.mustache", "", "CMakeLists.txt"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
}
if (additionalProperties.containsKey(RESERVED_WORD_PREFIX_OPTION)) {
reservedWordPrefix = (String) additionalProperties.get(RESERVED_WORD_PREFIX_OPTION);
}
additionalProperties.put("modelNamespaceDeclarations", modelPackage.split("\\."));
additionalProperties.put("modelNamespace", modelPackage.replaceAll("\\.", "::"));
additionalProperties.put("apiNamespaceDeclarations", apiPackage.split("\\."));
additionalProperties.put("apiNamespace", apiPackage.replaceAll("\\.", "::"));
additionalProperties.put("helpersNamespaceDeclarations", helpersPackage.split("\\."));
additionalProperties.put("helpersNamespace", helpersPackage.replaceAll("\\.", "::"));
additionalProperties.put(RESERVED_WORD_PREFIX_OPTION, reservedWordPrefix);
if (additionalProperties.containsKey(OPTIONAL_EXTERNAL_LIB)) {
setAddExternalLibs(convertPropertyToBooleanAndWriteBack(OPTIONAL_EXTERNAL_LIB));
} else {
additionalProperties.put(OPTIONAL_EXTERNAL_LIB, isAddExternalLibs);
}
// setup model templates
if (additionalProperties.containsKey(OPTION_USE_STRUCT_MODEL))
isUseStructModel = convertPropertyToBooleanAndWriteBack(OPTION_USE_STRUCT_MODEL);
if (isUseStructModel) {
LOGGER.info("Using struct-based model template");
modelTemplateFiles.put("model-struct-header.mustache", ".h");
modelTemplateFiles.put("model-struct-source.mustache", ".cpp");
} else {
LOGGER.info("Using get/set-based model template");
modelTemplateFiles.put("model-header.mustache", ".h");
modelTemplateFiles.put("model-source.mustache", ".cpp");
}
}
@Override
public String toModelImport(String name) {
if (importMapping.containsKey(name)) {
return importMapping.get(name);
} else {
return "#include \"" + name + ".h\"";
}
}
@Override
public CodegenModel fromModel(String name, Schema model) {
CodegenModel codegenModel = super.fromModel(name, model);
Set<String> oldImports = codegenModel.imports;
codegenModel.imports = new HashSet<>();
for (String imp : oldImports) {
String newImp = toModelImport(imp);
if (!newImp.isEmpty()) {
codegenModel.imports.add(newImp);
}
}
return codegenModel;
}
@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
if (apiResponse != null) {
Schema response = ModelUtils.getSchemaFromResponse(apiResponse);
if (response != null) {
CodegenProperty cm = fromProperty("response", response);
op.vendorExtensions.put("x-codegen-response", cm);
if ("HttpContent".equals(cm.dataType)) {
op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);
}
}
}
}
String pathForOatpp = path.replaceAll("\\{(.*?)}", ":$1");
op.vendorExtensions.put("x-codegen-oatpp-path", pathForOatpp);
return op;
}
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
String classname = (String) operations.get("classname");
operations.put("classnameSnakeUpperCase", underscore(classname).toUpperCase(Locale.ROOT));
operations.put("classnameSnakeLowerCase", underscore(classname).toLowerCase(Locale.ROOT));
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation op : operationList) {
boolean consumeJson = false;
boolean isParsingSupported = true;
if (op.bodyParam != null) {
if (op.bodyParam.vendorExtensions == null) {
op.bodyParam.vendorExtensions = new HashMap<>();
}
boolean isStringOrDate = op.bodyParam.isString || op.bodyParam.isDate;
op.bodyParam.vendorExtensions.put("x-codegen-oatpp-is-string-or-date", isStringOrDate);
}
if (op.consumes != null) {
for (Map<String, String> consume : op.consumes) {
if (consume.get("mediaType") != null && consume.get("mediaType").equals("application/json")) {
consumeJson = true;
}
}
}
op.httpMethod = op.httpMethod.substring(0, 1).toUpperCase(Locale.ROOT) + op.httpMethod.substring(1).toLowerCase(Locale.ROOT);
for (CodegenParameter param : op.allParams) {
if (param.isFormParam) isParsingSupported = false;
if (param.isFile) isParsingSupported = false;
if (param.isCookieParam) isParsingSupported = false;
//TODO: This changes the info about the real type but it is needed to parse the header params
if (param.isHeaderParam) {
param.dataType = "Oatpp::Optional<Oatpp::Http::Header::Raw>";
param.baseType = "Oatpp::Optional<Oatpp::Http::Header::Raw>";
} else if (param.isQueryParam) {
if (param.isPrimitiveType) {
param.dataType = "Oatpp::Optional<" + param.dataType + ">";
} else {
param.dataType = "Oatpp::Optional<" + param.dataType + ">";
param.baseType = "Oatpp::Optional<" + param.baseType + ">";
}
}
}
if (op.vendorExtensions == null) {
op.vendorExtensions = new HashMap<>();
}
op.vendorExtensions.put("x-codegen-oatpp-consumes-json", consumeJson);
op.vendorExtensions.put("x-codegen-oatpp-is-parsing-supported", isParsingSupported);
// Check if any one of the operations needs a model, then at API file level, at least one model has to be included.
for (String hdr : op.imports) {
if (importMapping.containsKey(hdr)) {
continue;
}
operations.put("hasModelImport", true);
}
}
return objs;
}
@Override
public String toModelFilename(String name) {
return toModelName(name);
}
@Override
public String apiFilename(String templateName, String tag) {
String result = super.apiFilename(templateName, tag);
if (templateName.endsWith("impl-header.mustache")) {
int ix = result.lastIndexOf(File.separatorChar);
result = result.substring(0, ix) + result.substring(ix, result.length() - 2) + "Impl.h";
result = result.replace(apiFileFolder(), implFileFolder());
} else if (templateName.endsWith("impl-source.mustache")) {
int ix = result.lastIndexOf(File.separatorChar);
result = result.substring(0, ix) + result.substring(ix, result.length() - 4) + "Impl.cpp";
result = result.replace(apiFileFolder(), implFileFolder());
}
return result;
}
@Override
public String toApiFilename(String name) {
return toApiName(name);
}
/**
* Optional - type declaration. This is a String which is used by the
* templates to instantiate your types. There is typically special handling
* for different property types
*
* @return a string value used as the `dataType` field for model templates,
* `returnType` for api templates
*/
@Override
public String getTypeDeclaration(Schema p) {
String openAPIType = getSchemaType(p);
if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
Schema inner = ap.getItems();
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = getAdditionalProperties(p);
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
} else if (ModelUtils.isByteArraySchema(p)) {
return "std::string";
} else if (ModelUtils.isStringSchema(p)
|| ModelUtils.isDateSchema(p)
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|| languageSpecificPrimitives.contains(openAPIType)) {
return toModelName(openAPIType);
}
return openAPIType;
}
@Override
public String toDefaultValue(Schema p) {
if (ModelUtils.isBooleanSchema(p)) {
return "false";
} else if (ModelUtils.isDateSchema(p)) {
return "\"\"";
} else if (ModelUtils.isDateTimeSchema(p)) {
return "\"\"";
} else if (ModelUtils.isNumberSchema(p)) {
if (ModelUtils.isFloatSchema(p)) {
return "0.0f";
}
return "0.0";
} else if (ModelUtils.isIntegerSchema(p)) {
if (ModelUtils.isLongSchema(p)) {
return "0L";
}
return "0";
} else if (ModelUtils.isByteArraySchema(p)) {
return "\"\"";
} else if (ModelUtils.isMapSchema(p)) {
String inner = getSchemaType(getAdditionalProperties(p));
return "std::map<std::string, " + inner + ">()";
} else if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
String inner = getSchemaType(ap.getItems());
return "std::vector<" + inner + ">()";
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
} else if (ModelUtils.isStringSchema(p)) {
return "\"\"";
}
return "";
}
/**
* Location to write model files. You can use the modelPackage() as defined
* when the class is instantiated
*/
public String modelFileFolder() {
return (outputFolder + "/model").replace("/", File.separator);
}
/**
* Location to write api files. You can use the apiPackage() as defined when
* the class is instantiated
*/
@Override
public String apiFileFolder() {
return (outputFolder + "/api").replace("/", File.separator);
}
private String implFileFolder() {
return (outputFolder + "/" + implFolder).replace("/", File.separator);
}
/**
* Optional - OpenAPI type conversion. This is used to map OpenAPI types in
* a `Schema` into either language specific types via `typeMapping` or
* into complex models if there is not a mapping.
*
* @return a string value of the type or complex model for this property
*/
@Override
public String getSchemaType(Schema p) {
String openAPIType = super.getSchemaType(p);
String type = null;
if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
if (languageSpecificPrimitives.contains(type))
return toModelName(type);
} else
type = openAPIType;
return toModelName(type);
}
@Override
public String getTypeDeclaration(String str) {
return toModelName(str);
}
/**
* Specify whether external libraries will be added during the generation
*
* @param value the value to be set
*/
public void setAddExternalLibs(boolean value) {
isAddExternalLibs = value;
}
}

View File

@@ -448,13 +448,21 @@ public class GoClientCodegen extends AbstractGoCodegen {
for (CodegenParameter p : op.allParams) {
p.vendorExtensions.put("x-go-example", constructExampleCode(p, modelMaps, processedModelMaps));
}
processedModelMaps.clear();
}
processedModelMaps.clear();
for (CodegenOperation operation : operationList) {
boolean needTimeImport = false;
for (CodegenParameter cp : operation.allParams) {
cp.vendorExtensions.put("x-go-example", constructExampleCode(cp, modelMaps, processedModelMaps));
if (cp.isDateTime || cp.isDate) { // datetime or date
needTimeImport = true;
}
}
if (needTimeImport) {
operation.vendorExtensions.put("x-go-import", " \"time\"");
}
processedModelMaps.clear();
}
return objs;
@@ -462,12 +470,22 @@ public class GoClientCodegen extends AbstractGoCodegen {
private String constructExampleCode(CodegenParameter codegenParameter, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
if (codegenParameter.isArray) { // array
return codegenParameter.dataType + "{" + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
String prefix = codegenParameter.dataType;
String dataType = StringUtils.removeStart(codegenParameter.dataType, "[]");
if (modelMaps.containsKey(dataType)) {
prefix = "[]" + goImportAlias + "." + dataType;
}
return prefix + "{" + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
} else if (codegenParameter.isMap) {
return codegenParameter.dataType + "{ \"key\": " + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
String prefix = codegenParameter.dataType;
String dataType = StringUtils.removeStart(codegenParameter.dataType, "map[string][]");
if (modelMaps.containsKey(dataType)) {
prefix = "map[string][]" + goImportAlias + "." + dataType;
}
return prefix + "{\"key\": " + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
} else if (codegenParameter.isPrimitiveType) { // primitive type
if (codegenParameter.isString) {
if (StringUtils.isEmpty(codegenParameter.example)) {
if (!StringUtils.isEmpty(codegenParameter.example) && codegenParameter.example != "null") {
return "\"" + codegenParameter.example + "\"";
} else {
return "\"" + codegenParameter.paramName + "_example\"";
@@ -482,11 +500,13 @@ public class GoClientCodegen extends AbstractGoCodegen {
return "\"https://example.com\"";
} else if (codegenParameter.isDateTime || codegenParameter.isDate) { // datetime or date
return "time.Now()";
} else if (codegenParameter.isFile) {
return "os.NewFile(1234, \"some_file\")";
} else { // numeric
if (StringUtils.isEmpty(codegenParameter.example)) {
return codegenParameter.example;
if (!StringUtils.isEmpty(codegenParameter.example) && codegenParameter.example != "null") {
return codegenParameter.dataType + "(" + codegenParameter.example + ")";
} else {
return "987";
return codegenParameter.dataType + "(987)";
}
}
} else { // model
@@ -502,12 +522,22 @@ public class GoClientCodegen extends AbstractGoCodegen {
private String constructExampleCode(CodegenProperty codegenProperty, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
if (codegenProperty.isArray) { // array
return codegenProperty.dataType + "{" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + ")";
String prefix = codegenProperty.dataType;
String dataType = StringUtils.removeStart(codegenProperty.dataType, "[]");
if (modelMaps.containsKey(dataType)) {
prefix = "[]" + goImportAlias + "." + dataType;
}
return prefix + "{" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
} else if (codegenProperty.isMap) { // map
return codegenProperty.dataType + "{ \"key\": " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
String prefix = codegenProperty.dataType;
String dataType = StringUtils.removeStart(codegenProperty.dataType, "map[string][]");
if (modelMaps.containsKey(dataType)) {
prefix = "map[string][]" + goImportAlias + "." + dataType;
}
return prefix + "{\"key\": " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
} else if (codegenProperty.isPrimitiveType) { // primitive type
if (codegenProperty.isString) {
if (StringUtils.isEmpty(codegenProperty.example)) {
if (!StringUtils.isEmpty(codegenProperty.example) && codegenProperty.example != "null") {
return "\"" + codegenProperty.example + "\"";
} else {
return "\"" + codegenProperty.name + "_example\"";
@@ -524,17 +554,13 @@ public class GoClientCodegen extends AbstractGoCodegen {
return "time.Now()";
} else { // numeric
String example;
if (StringUtils.isEmpty(codegenProperty.example)) {
if (!StringUtils.isEmpty(codegenProperty.example) && codegenProperty.example != "null") {
example = codegenProperty.example;
} else {
example = "123";
}
if (codegenProperty.isLong) {
return "int64(" + example + ")";
} else {
return example;
}
return codegenProperty.dataType + "(" + example + ")";
}
} else {
// look up the model
@@ -548,8 +574,6 @@ public class GoClientCodegen extends AbstractGoCodegen {
}
private String constructExampleCode(CodegenModel codegenModel, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
String example;
// break infinite recursion. Return, in case a model is already processed in the current context.
String model = codegenModel.name;
if (processedModelMap.containsKey(model)) {
@@ -561,6 +585,14 @@ public class GoClientCodegen extends AbstractGoCodegen {
} else {
throw new RuntimeException("Invalid count when constructing example: " + count);
}
} else if (codegenModel.isEnum) {
Map<String, Object> allowableValues = codegenModel.allowableValues;
List<Object> values = (List<Object>) allowableValues.get("values");
return goImportAlias + "." + model + "(\"" + String.valueOf(values.get(0)) + "\")";
} else if (codegenModel.oneOf != null && !codegenModel.oneOf.isEmpty()) {
String subModel = (String) codegenModel.oneOf.toArray()[0];
String oneOf = constructExampleCode(modelMaps.get(subModel), modelMaps, processedModelMap).substring(1);
return goImportAlias + "." + model + "{" + subModel + ": " + oneOf + "}";
} else {
processedModelMap.put(model, 1);
}
@@ -569,6 +601,6 @@ public class GoClientCodegen extends AbstractGoCodegen {
for (CodegenProperty codegenProperty : codegenModel.requiredVars) {
propertyExamples.add(constructExampleCode(codegenProperty, modelMaps, processedModelMap));
}
return "*" + goImportAlias + ".New" + codegenModel.name + "(" + StringUtils.join(propertyExamples, ", ") + ")";
return "*" + goImportAlias + ".New" + model + "(" + StringUtils.join(propertyExamples, ", ") + ")";
}
}

View File

@@ -133,7 +133,8 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
typeMapping.put("object", "Any");
typeMapping.put("file", "File");
typeMapping.put("binary", "File");
typeMapping.put("number", "Double");
typeMapping.put("number", "BigDecimal");
typeMapping.put("decimal", "BigDecimal");
instantiationTypes.put("array", "ListBuffer");
instantiationTypes.put("map", "Map");

View File

@@ -137,6 +137,7 @@ public class ScalaAkkaHttpServerCodegen extends AbstractScalaCodegen implements
typeMapping.put("file", "File");
typeMapping.put("binary", "File");
typeMapping.put("number", "Double");
typeMapping.put("decimal", "BigDecimal");
instantiationTypes.put("array", "ListBuffer");
instantiationTypes.put("map", "Map");

View File

@@ -113,10 +113,11 @@ public class ScalaFinchServerCodegen extends DefaultCodegen implements CodegenCo
typeMapping.put("string", "String");
typeMapping.put("boolean", "Boolean");
typeMapping.put("integer", "Int");
typeMapping.put("float", "Float");
typeMapping.put("long", "Long");
typeMapping.put("float", "Float");
typeMapping.put("double", "Double");
typeMapping.put("number", "BigDecimal");
typeMapping.put("decimal", "BigDecimal");
typeMapping.put("date-time", "ZonedDateTime");
typeMapping.put("date", "LocalDateTime");
typeMapping.put("file", "File");
@@ -177,7 +178,6 @@ public class ScalaFinchServerCodegen extends DefaultCodegen implements CodegenCo
instantiationTypes.put("map", "HashMap");
importMapping = new HashMap<String, String>();
importMapping.put("BigDecimal", "java.math.BigDecimal");
importMapping.put("UUID", "java.util.UUID");
importMapping.put("URI", "java.net.URI");
importMapping.put("File", "java.io.File");

View File

@@ -97,10 +97,11 @@ public class ScalaPlayFrameworkServerCodegen extends AbstractScalaCodegen implem
typeMapping.put("ByteArray", "Array[Byte]");
typeMapping.put("object", "JsObject");
typeMapping.put("file", "TemporaryFile");
typeMapping.put("number", "BigDecimal");
typeMapping.put("decimal", "BigDecimal");
importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
importMapping.put("LocalDate", "java.time.LocalDate");
importMapping.remove("BigDecimal");
importMapping.put("TemporaryFile", "play.api.libs.Files.TemporaryFile");
cliOptions.removeIf(opt -> DATE_LIBRARY.equals(opt.getOpt()));

View File

@@ -140,6 +140,7 @@ public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements Code
typeMapping.put("file", "File");
typeMapping.put("binary", "File");
typeMapping.put("number", "Double");
typeMapping.put("decimal", "BigDecimal");
instantiationTypes.put("array", "ListBuffer");
instantiationTypes.put("map", "Map");

View File

@@ -93,6 +93,7 @@ public class ScalatraServerCodegen extends AbstractScalaCodegen implements Codeg
typeMapping.put("file", "File");
typeMapping.put("binary", "File");
typeMapping.put("number", "Double");
typeMapping.put("decimal", "BigDecimal");
additionalProperties.put("appName", "OpenAPI Sample");
additionalProperties.put("appDescription", "A sample openapi server");
@@ -118,7 +119,6 @@ public class ScalatraServerCodegen extends AbstractScalaCodegen implements Codeg
supportingFiles.add(new SupportingFile("sbt", "", "sbt"));
importMapping = new HashMap<String, String>();
importMapping.put("BigDecimal", "java.math.BigDecimal");
importMapping.put("UUID", "java.util.UUID");
importMapping.put("URI", "java.net.URI");
importMapping.put("File", "java.io.File");

View File

@@ -121,6 +121,7 @@ public class ScalazClientCodegen extends AbstractScalaCodegen implements Codegen
typeMapping.put("file", "File");
typeMapping.put("binary", "File");
typeMapping.put("number", "BigDecimal");
typeMapping.put("decimal", "BigDecimal");
typeMapping.put("date-time", "DateTime");
typeMapping.put("date", "DateTime");

View File

@@ -62,7 +62,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
public static final String STRING_ENUMS_DESC = "Generate string enums instead of objects for enum values.";
public static final String QUERY_PARAM_OBJECT_FORMAT = "queryParamObjectFormat";
protected String ngVersion = "10.0.0";
protected String ngVersion = "11.0.0";
protected String npmRepository = null;
private boolean useSingleRequestParameter = false;
protected String serviceSuffix = "Service";
@@ -131,7 +131,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
@Override
public String getHelp() {
return "Generates a TypeScript Angular (6.x - 10.x) client library.";
return "Generates a TypeScript Angular (6.x - 11.x) client library.";
}
@Override
@@ -258,7 +258,9 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
}
// Set the typescript version compatible to the Angular version
if (ngVersion.atLeast("10.0.0")) {
if (ngVersion.atLeast("11.0.0")) {
additionalProperties.put("tsVersion", ">=4.0.0 <4.1.0");
} else if (ngVersion.atLeast("10.0.0")) {
additionalProperties.put("tsVersion", ">=3.9.2 <4.0.0");
} else if (ngVersion.atLeast("9.0.0")) {
additionalProperties.put("tsVersion", ">=3.6.0 <3.8.0");
@@ -288,7 +290,10 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
supportingFiles.add(new SupportingFile("ng-package.mustache", getIndexDirectory(), "ng-package.json"));
// Specific ng-packagr configuration
if (ngVersion.atLeast("10.0.0")) {
if (ngVersion.atLeast("11.0.0")) {
additionalProperties.put("ngPackagrVersion", "11.0.2");
additionalProperties.put("tsickleVersion", "0.39.1");
} else if (ngVersion.atLeast("10.0.0")) {
additionalProperties.put("ngPackagrVersion", "10.0.3");
additionalProperties.put("tsickleVersion", "0.39.1");
} else if (ngVersion.atLeast("9.0.0")) {
@@ -309,7 +314,9 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
}
// set zone.js version
if (ngVersion.atLeast("9.0.0")) {
if (ngVersion.atLeast("11.0.0")) {
additionalProperties.put("zonejsVersion", "0.11.3");
} else if (ngVersion.atLeast("9.0.0")) {
additionalProperties.put("zonejsVersion", "0.10.2");
} else if (ngVersion.atLeast("8.0.0")) {
additionalProperties.put("zonejsVersion", "0.9.1");

View File

@@ -39,6 +39,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter";
public static final String PREFIX_PARAMETER_INTERFACES = "prefixParameterInterfaces";
public static final String TYPESCRIPT_THREE_PLUS = "typescriptThreePlus";
public static final String WITHOUT_RUNTIME_CHECKS = "withoutRuntimeChecks";
protected String npmRepository = null;
private boolean useSingleRequestParameter = true;
@@ -46,6 +47,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
protected boolean addedApiIndex = false;
protected boolean addedModelIndex = false;
protected boolean typescriptThreePlus = false;
protected boolean withoutRuntimeChecks = false;
public TypeScriptFetchClientCodegen() {
@@ -61,7 +63,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
embeddedTemplateDir = templateDir = "typescript-fetch";
this.apiTemplateFiles.put("apis.mustache", ".ts");
this.modelTemplateFiles.put("models.mustache", ".ts");
this.addExtraReservedWords();
typeMapping.put("date", "Date");
@@ -73,6 +75,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
this.cliOptions.add(new CliOption(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER, CodegenConstants.USE_SINGLE_REQUEST_PARAMETER_DESC, SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.TRUE.toString()));
this.cliOptions.add(new CliOption(PREFIX_PARAMETER_INTERFACES, "Setting this property to true will generate parameter interface declarations prefixed with API class name to avoid name conflicts.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(TYPESCRIPT_THREE_PLUS, "Setting this property to true will generate TypeScript 3.6+ compatible code.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(WITHOUT_RUNTIME_CHECKS, "Setting this property to true will remove any runtime checks on the request and response payloads. Payloads will be casted to their expected types.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
}
@Override
@@ -101,6 +104,14 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
this.typescriptThreePlus = typescriptThreePlus;
}
public Boolean getWithoutRuntimeChecks(){
return withoutRuntimeChecks;
}
public void setWithoutRuntimeChecks(Boolean withoutRuntimeChecks){
this.withoutRuntimeChecks = withoutRuntimeChecks;
}
@Override
public void processOpts() {
super.processOpts();
@@ -135,6 +146,14 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
if (additionalProperties.containsKey(TYPESCRIPT_THREE_PLUS)) {
this.setTypescriptThreePlus(convertPropertyToBoolean(TYPESCRIPT_THREE_PLUS));
}
if (additionalProperties.containsKey(WITHOUT_RUNTIME_CHECKS)) {
this.setWithoutRuntimeChecks(convertPropertyToBoolean(WITHOUT_RUNTIME_CHECKS));
}
if(!withoutRuntimeChecks){
this.modelTemplateFiles.put("models.mustache", ".ts");
}
}
@Override

View File

@@ -282,7 +282,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE
return HashCodeBuilder.reflectionHashCode(this);
{{/useReflectionEqualsHashCode}}
{{^useReflectionEqualsHashCode}}
return Objects.hash({{#vars}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}{{#additionalPropertiesType}}, additionalProperties{{/additionalPropertiesType}});
return Objects.hash({{#vars}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}{{#additionalPropertiesType}}{{#hasVars}}, {{/hasVars}}{{^hasVars}}{{#parent}}, {{/parent}}{{/hasVars}}additionalProperties{{/additionalPropertiesType}});
{{/useReflectionEqualsHashCode}}
}

View File

@@ -12,7 +12,6 @@ org.openapitools.codegen.languages.ClojureClientCodegen
org.openapitools.codegen.languages.ConfluenceWikiCodegen
org.openapitools.codegen.languages.CppQt5ClientCodegen
org.openapitools.codegen.languages.CppQt5QHttpEngineServerCodegen
org.openapitools.codegen.languages.CppOatppServerCodegen
org.openapitools.codegen.languages.CppPistacheServerCodegen
org.openapitools.codegen.languages.CppRestbedServerCodegen
org.openapitools.codegen.languages.CppRestSdkClientCodegen
@@ -90,8 +89,8 @@ org.openapitools.codegen.languages.PhpSymfonyServerCodegen
org.openapitools.codegen.languages.PhpZendExpressivePathHandlerServerCodegen
org.openapitools.codegen.languages.PowerShellClientCodegen
org.openapitools.codegen.languages.ProtobufSchemaCodegen
org.openapitools.codegen.languages.PythonLegacyClientCodegen
org.openapitools.codegen.languages.PythonClientCodegen
org.openapitools.codegen.languages.PythonClientExperimentalCodegen
org.openapitools.codegen.languages.PythonFlaskConnexionServerCodegen
org.openapitools.codegen.languages.PythonAiohttpConnexionServerCodegen
org.openapitools.codegen.languages.PythonBluePlanetServerCodegen

View File

@@ -1,48 +0,0 @@
# REST API Server for {{appName}}
## Overview
This API Server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
It uses the [Oat++](https://github.com/oatpp/oatpp) Framework.
## Files organization
The Oat++ C++ REST server generator creates three folders:
- `api`: This folder contains the handlers for each method specified in the OpenAPI definition. Every handler extracts
the path and body parameters (if any) from the requests and tries to parse and possibly validate them.
Once this step is completed, the main API class calls the corresponding abstract method that should be implemented
by the developer (a basic implementation is provided under the `impl` folder)
- `impl`: As written above, the implementation folder contains, for each API, the corresponding implementation class,
which extends the main API class and implements the abstract methods.
Every method receives the path and body parameters as constant reference variables and a reference to the response
object, that should be filled with the right response and sent at the end of the method with the command:
response.send(returnCode, responseBody, [mimeType])
- `model`: This folder contains the corresponding class for every object schema found in the OpenAPI specification.
The main folder contains also a file with a main that can be used to start the server.
Of course, is you should customize this file based on your needs
## Installation
First of all, you need to download and install the libraries listed [here](#libraries-required).
Once the libraries are installed, in order to compile and run the server please follow the steps below:
```bash
mkdir build
cd build
cmake ..
make
```
Once compiled run the server:
```bash
cd build
./api-server
```
## Libraries required
- [Oat++](http://github.com/oatpp/oatpp)
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
put it under the model/nlohmann folder
## Namespaces
{{{apiPackage}}}
{{{modelPackage}}}

View File

@@ -1,72 +0,0 @@
{{>licenseInfo}}
{{#operations}}/*
* {{classname}}.h
*
* {{description}}
*/
#ifndef {{classname}}_H_
#define {{classname}}_H_
{{{defaultInclude}}}
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
{{^hasModelImport}}#include <nlohmann/json.hpp>{{/hasModelImport}}
{{#imports}}{{{import}}}
{{/imports}}
{{#apiNamespaceDeclarations}}
namespace {{this}} {
{{/apiNamespaceDeclarations}}
{{#hasModelImport}}
using namespace {{modelNamespace}};{{/hasModelImport}}
class {{declspec}} {{classname}} {
public:
{{classname}}(std::shared_ptr<Pistache::Rest::Router>);
virtual ~{{classname}}() {}
void init();
const std::string base = "{{basePathWithoutHost}}";
private:
void setupRoutes();
{{#operation}}
void {{operationIdSnakeCase}}_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
{{/operation}}
void {{classnameSnakeLowerCase}}_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
{{#operation}}
/// <summary>
/// {{summary}}
/// </summary>
/// <remarks>
/// {{notes}}
/// </remarks>
{{#vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
{{#allParams}}
/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
{{/allParams}}
virtual void {{operationIdSnakeCase}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) = 0;
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
{{^vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
virtual void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
{{/operation}}
};
{{#apiNamespaceDeclarations}}
}
{{/apiNamespaceDeclarations}}
#endif /* {{classname}}_H_ */
{{/operations}}

View File

@@ -1,55 +0,0 @@
{{>licenseInfo}}
{{#operations}}/*
* {{classname}}Impl.h
*
* {{description}}
*/
#ifndef {{classnameSnakeUpperCase}}_IMPL_H_
#define {{classnameSnakeUpperCase}}_IMPL_H_
{{{defaultInclude}}}
#include <pistache/endpoint.h>
#include <pistache/http.h>
#include <pistache/router.h>
#include <memory>
#include <{{classname}}.h>
#include <pistache/optional.h>
{{#imports}}{{{import}}}
{{/imports}}
{{#apiNamespaceDeclarations}}
namespace {{this}} {
{{/apiNamespaceDeclarations}}
{{#hasModelImport}}
using namespace {{modelNamespace}};{{/hasModelImport}}
class {{classname}}Impl : public {{apiNamespace}}::{{classname}} {
public:
{{classname}}Impl(std::shared_ptr<Pistache::Rest::Router>);
~{{classname}}Impl() {}
{{#operation}}
{{#vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
void {{operationIdSnakeCase}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response);
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
{{^vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
{{/operation}}
};
{{#apiNamespaceDeclarations}}
}
{{/apiNamespaceDeclarations}}
{{/operations}}
#endif

View File

@@ -1,34 +0,0 @@
{{>licenseInfo}}
{{#operations}}
#include "{{classname}}Impl.h"
{{#apiNamespaceDeclarations}}
namespace {{this}} {
{{/apiNamespaceDeclarations}}
{{#hasModelImport}}
using namespace {{modelNamespace}};{{/hasModelImport}}
{{classname}}Impl::{{classname}}Impl(std::shared_ptr<Pistache::Rest::Router> rtr)
: {{classname}}(rtr)
{ }
{{#operation}}
{{#vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
void {{classname}}Impl::{{operationIdSnakeCase}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
{{^vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
void {{classname}}Impl::{{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
{{/operation}}
{{#apiNamespaceDeclarations}}
}
{{/apiNamespaceDeclarations}}
{{/operations}}

View File

@@ -1,111 +0,0 @@
{{>licenseInfo}}
{{#operations}}
#include "{{classname}}.h"
#include "{{prefix}}Helpers.h"
{{#apiNamespaceDeclarations}}
namespace {{this}} {
{{/apiNamespaceDeclarations}}
using namespace {{helpersNamespace}};
{{#hasModelImport}}
using namespace {{modelNamespace}};{{/hasModelImport}}
{{classname}}::{{classname}}(std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void {{classname}}::init() {
setupRoutes();
}
void {{classname}}::setupRoutes() {
using namespace Pistache::Rest;
{{#operation}}
Routes::{{httpMethod}}(*router, base + "{{{vendorExtensions.x-codegen-oatpp-path}}}", Routes::bind(&{{classname}}::{{operationIdSnakeCase}}_handler, this));
{{/operation}}
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(&{{classname}}::{{classnameSnakeLowerCase}}_default_handler, this));
}
{{#operation}}
void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Request &{{#hasParams}}request{{/hasParams}}, Pistache::Http::ResponseWriter response) {
{{#vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
{{#hasPathParams}}
// Getting the path params
{{#pathParams}}
auto {{paramName}} = request.param(":{{paramName}}").as<{{dataType}}>();
{{/pathParams}}
{{/hasPathParams}}{{#hasBodyParam}}
// Getting the body param
{{#bodyParam}}
{{^isPrimitiveType}}{{^isContainer}}
{{baseType}} {{paramName}};{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}> {{paramName}};{{/isArray}}{{#isMap}}std::map<std::string, {{items.baseType}}> {{paramName}};{{/isMap}}{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{dataType}} {{paramName}};
{{/isPrimitiveType}}
{{/bodyParam}}
{{/hasBodyParam}}{{#hasQueryParams}}
// Getting the query params
{{#queryParams}}
auto {{paramName}}Query = request.query().get("{{baseName}}");
Pistache::Optional<{{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}}> {{paramName}};
if(!{{paramName}}Query.isEmpty()){
{{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}} valueQuery_instance;
if(fromStringValue({{paramName}}Query.get(), valueQuery_instance)){
{{paramName}} = Pistache::Some(valueQuery_instance);
}
}
{{/queryParams}}
{{/hasQueryParams}}{{#hasHeaderParams}}
// Getting the header params
{{#headerParams}}
auto {{paramName}} = request.headers().tryGetRaw("{{baseName}}");
{{/headerParams}}
{{/hasHeaderParams}}
try {
{{#hasBodyParam}}
{{#bodyParam}}
{{^isPrimitiveType}}
nlohmann::json::parse(request.body()).get_to({{paramName}});
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{paramName}} = request.body();
{{/isPrimitiveType}}
{{/bodyParam}}
{{/hasBodyParam}}
this->{{operationIdSnakeCase}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}response);
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
{{^vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
try {
this->{{operationIdSnakeCase}}(request, response);
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
{{/operation}}
void {{classname}}::{{classnameSnakeLowerCase}}_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
{{#apiNamespaceDeclarations}}
}
{{/apiNamespaceDeclarations}}
{{/operations}}

View File

@@ -1,39 +0,0 @@
cmake_minimum_required (VERSION 3.2)
project(api-server)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pg -g3" )
{{#addExternalLibs}}
include(ExternalProject)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
ExternalProject_Add(PISTACHE
GIT_REPOSITORY https://github.com/oktal/pistache.git
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)
ExternalProject_Add(NLOHMANN
GIT_REPOSITORY https://github.com/nlohmann/json.git
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
{{/addExternalLibs}}
include_directories(model)
include_directories(api)
include_directories(impl)
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/api/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/model/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)
add_executable(${PROJECT_NAME} ${SRCS} )
{{#addExternalLibs}}add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN){{/addExternalLibs}}
target_link_libraries(${PROJECT_NAME} pistache pthread)

View File

@@ -1,64 +0,0 @@
{{>licenseInfo}}
/*
* {{prefix}}Helpers.h
*
* This is the helper class for models and primitives
*/
#ifndef {{prefix}}Helpers_H_
#define {{prefix}}Helpers_H_
#include <ctime>
#include <string>
#include <sstream>
#include <vector>
#include <map>
{{#helpersNamespaceDeclarations}}
namespace {{this}} {
{{/helpersNamespaceDeclarations}}
std::string toStringValue(const std::string &value);
std::string toStringValue(const int32_t &value);
std::string toStringValue(const int64_t &value);
std::string toStringValue(const bool &value);
std::string toStringValue(const float &value);
std::string toStringValue(const double &value);
bool fromStringValue(const std::string &inStr, std::string &value);
bool fromStringValue(const std::string &inStr, int32_t &value);
bool fromStringValue(const std::string &inStr, int64_t &value);
bool fromStringValue(const std::string &inStr, bool &value);
bool fromStringValue(const std::string &inStr, float &value);
bool fromStringValue(const std::string &inStr, double &value);
template<typename T>
bool fromStringValue(const std::vector<std::string> &inStr, std::vector<T> &value){
try{
for(auto & item : inStr){
T itemValue;
if(fromStringValue(item, itemValue)){
value.push_back(itemValue);
}
}
}
catch(...){
return false;
}
return value.size() > 0;
}
template<typename T>
bool fromStringValue(const std::string &inStr, std::vector<T> &value, char separator = ','){
std::vector<std::string> inStrings;
std::istringstream f(inStr);
std::string s;
while (std::getline(f, s, separator)) {
inStrings.push_back(s);
}
return fromStringValue(inStrings, value);
}
{{#helpersNamespaceDeclarations}}
}
{{/helpersNamespaceDeclarations}}
#endif // {{prefix}}Helpers_H_

View File

@@ -1,86 +0,0 @@
{{>licenseInfo}}
#include "{{prefix}}Helpers.h"
{{#helpersNamespaceDeclarations}}
namespace {{this}} {
{{/helpersNamespaceDeclarations}}
std::string toStringValue(const std::string &value){
return std::string(value);
}
std::string toStringValue(const int32_t &value){
return std::to_string(value);
}
std::string toStringValue(const int64_t &value){
return std::to_string(value);
}
std::string toStringValue(const bool &value){
return value?std::string("true"):std::string("false");
}
std::string toStringValue(const float &value){
return std::to_string(value);
}
std::string toStringValue(const double &value){
return std::to_string(value);
}
bool fromStringValue(const std::string &inStr, std::string &value){
value = std::string(inStr);
return true;
}
bool fromStringValue(const std::string &inStr, int32_t &value){
try {
value = std::stoi( inStr );
}
catch (const std::invalid_argument&) {
return false;
}
return true;
}
bool fromStringValue(const std::string &inStr, int64_t &value){
try {
value = std::stol( inStr );
}
catch (const std::invalid_argument&) {
return false;
}
return true;
}
bool fromStringValue(const std::string &inStr, bool &value){
bool result = true;
inStr == "true"?value = true: inStr == "false"?value = false: result = false;
return result;
}
bool fromStringValue(const std::string &inStr, float &value){
try {
value = std::stof( inStr );
}
catch (const std::invalid_argument&) {
return false;
}
return true;
}
bool fromStringValue(const std::string &inStr, double &value){
try {
value = std::stod( inStr );
}
catch (const std::invalid_argument&) {
return false;
}
return true;
}
{{#helpersNamespaceDeclarations}}
}
{{/helpersNamespaceDeclarations}}

View File

@@ -1,11 +0,0 @@
/**
* {{{appName}}}
* {{{appDescription}}}
*
* {{#version}}The version of the OpenAPI document: {{{version}}}{{/version}}
* {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -1,79 +0,0 @@
{{>licenseInfo}}
#include "pistache/endpoint.h"
#include "pistache/http.h"
#include "pistache/router.h"
#ifdef __linux__
#include <vector>
#include <signal.h>
#include <unistd.h>
#endif
{{#apiInfo}}{{#apis}}{{#operations}}
#include "{{classname}}Impl.h"{{/operations}}{{/apis}}{{/apiInfo}}
#define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
#define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768
static Pistache::Http::Endpoint *httpEndpoint;
#ifdef __linux__
static void sigHandler [[noreturn]] (int sig){
switch(sig){
case SIGINT:
case SIGQUIT:
case SIGTERM:
case SIGHUP:
default:
httpEndpoint->shutdown();
break;
}
exit(0);
}
static void setUpUnixSignals(std::vector<int> quitSignals) {
sigset_t blocking_mask;
sigemptyset(&blocking_mask);
for (auto sig : quitSignals)
sigaddset(&blocking_mask, sig);
struct sigaction sa;
sa.sa_handler = sigHandler;
sa.sa_mask = blocking_mask;
sa.sa_flags = 0;
for (auto sig : quitSignals)
sigaction(sig, &sa, nullptr);
}
#endif
using namespace {{apiNamespace}};
int main() {
#ifdef __linux__
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
setUpUnixSignals(sigs);
#endif
Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port({{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}8080{{/serverPort}}));
httpEndpoint = new Pistache::Http::Endpoint((addr));
auto router = std::make_shared<Pistache::Rest::Router>();
auto opts = Pistache::Http::Endpoint::options()
.threads(PISTACHE_SERVER_THREADS);
opts.flags(Pistache::Tcp::Options::ReuseAddr);
opts.maxRequestSize(PISTACHE_SERVER_MAX_REQUEST_SIZE);
opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE);
httpEndpoint->init(opts);
{{#apiInfo}}{{#apis}}{{#operations}}
{{classname}}Impl {{classname}}server(router);
{{classname}}server.init();{{/operations}}{{/apis}}{{/apiInfo}}
httpEndpoint->setHandler(router->handler());
httpEndpoint->serve();
httpEndpoint->shutdown();
}

View File

@@ -1,60 +0,0 @@
{{>licenseInfo}}
{{#models}}{{#model}}/*
* {{classname}}.h
*
* {{description}}
*/
#ifndef {{classname}}_H_
#define {{classname}}_H_
{{{defaultInclude}}}
{{#imports}}{{{this}}}
{{/imports}}
#include <nlohmann/json.hpp>
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
/// <summary>
/// {{description}}
/// </summary>
class {{declspec}} {{classname}}
{
public:
{{classname}}();
virtual ~{{classname}}();
void validate();
/////////////////////////////////////////////
/// {{classname}} members
{{#vars}}
/// <summary>
/// {{description}}
/// </summary>
{{{dataType}}}{{#isContainer}}&{{/isContainer}} {{getter}}(){{^isContainer}} const{{/isContainer}};
void {{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value);{{^required}}
bool {{nameInCamelCase}}IsSet() const;
void unset{{name}}();{{/required}}
{{/vars}}
friend void to_json(nlohmann::json& j, const {{classname}}& o);
friend void from_json(const nlohmann::json& j, {{classname}}& o);
protected:
{{#vars}}
{{{dataType}}} m_{{name}};
{{^required}}
bool m_{{name}}IsSet;{{/required}}
{{/vars}}
};
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}
#endif /* {{classname}}_H_ */
{{/model}}
{{/models}}

View File

@@ -1,73 +0,0 @@
{{>licenseInfo}}
{{#models}}{{#model}}
#include "{{classname}}.h"
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
{{classname}}::{{classname}}()
{
{{#vars}}{{^isContainer}}{{#isPrimitiveType}}m_{{name}} = {{{defaultValue}}};
{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isString}}m_{{name}} = {{{defaultValue}}};
{{/isString}}{{#isDateTime}}m_{{name}} = {{{defaultValue}}};
{{/isDateTime}}{{/isPrimitiveType}}{{/isContainer}}{{^required}}m_{{name}}IsSet = false;
{{/required}}{{/vars}}
}
{{classname}}::~{{classname}}()
{
}
void {{classname}}::validate()
{
// TODO: implement validation
}
void to_json(nlohmann::json& j, const {{classname}}& o)
{
j = nlohmann::json();
{{#vars}}
{{#required}}j["{{baseName}}"] = o.m_{{name}};{{/required}}{{^required}}if(o.{{nameInCamelCase}}IsSet(){{#isContainer}} || !o.m_{{name}}.empty(){{/isContainer}})
j["{{baseName}}"] = o.m_{{name}};{{/required}}
{{/vars}}
}
void from_json(const nlohmann::json& j, {{classname}}& o)
{
{{#vars}}
{{#required}}j.at("{{baseName}}").get_to(o.m_{{name}});{{/required}}{{^required}}if(j.find("{{baseName}}") != j.end())
{
j.at("{{baseName}}").get_to(o.m_{{name}});
o.m_{{name}}IsSet = true;
} {{/required}}
{{/vars}}
}
{{#vars}}{{{dataType}}}{{#isContainer}}&{{/isContainer}} {{classname}}::{{getter}}(){{^isContainer}} const{{/isContainer}}
{
return m_{{name}};
}
void {{classname}}::{{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value)
{
m_{{name}} = value;{{^required}}
m_{{name}}IsSet = true;{{/required}}
}
{{^required}}bool {{classname}}::{{nameInCamelCase}}IsSet() const
{
return m_{{name}}IsSet;
}
void {{classname}}::unset{{name}}()
{
m_{{name}}IsSet = false;
}
{{/required}}
{{/vars}}
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}
{{/model}}
{{/models}}

View File

@@ -1,43 +0,0 @@
{{>licenseInfo}}
{{#models}}{{#model}}/*
* {{classname}}.h
*
* {{description}}
*/
#ifndef {{classname}}_H_
#define {{classname}}_H_
{{{defaultInclude}}}
{{#imports}}{{{this}}}
{{/imports}}
#include <nlohmann/json.hpp>
{{#hasOptional}}#include <pistache/optional.h>{{/hasOptional}}
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
struct {{classname}}
{
{{#vars}}
{{^required}}Pistache::Optional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{name}};
{{/vars}}
bool operator==(const {{classname}}& other) const;
bool operator!=(const {{classname}}& other) const;
nlohmann::json to_json() const;
static {{classname}} from_json(const nlohmann::json& j);
};
void to_json(nlohmann::json& j, const {{classname}}& o);
void from_json(const nlohmann::json& j, {{classname}}& o);
{{#modelNamespaceDeclarations}}
} // {{this}}
{{/modelNamespaceDeclarations}}
#endif /* {{classname}}_H_ */
{{/model}}
{{/models}}

View File

@@ -1,59 +0,0 @@
{{>licenseInfo}}
{{#models}}{{#model}}
#include "{{classname}}.h"
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
nlohmann::json {{classname}}::to_json() const
{
nlohmann::json j;
{{#modelNamespaceDeclarations}}::{{this}}{{/modelNamespaceDeclarations}}::to_json(j, *this);
return j;
}
{{classname}} {{classname}}::from_json(const nlohmann::json& j)
{
{{classname}} o{};
{{#modelNamespaceDeclarations}}::{{this}}{{/modelNamespaceDeclarations}}::from_json(j, o);
return o;
}
bool {{classname}}::operator==(const {{classname}}& other) const
{
return {{#vars}}{{name}} == other.{{name}}{{^-last}} && {{/-last}}{{/vars}};
}
bool {{classname}}::operator!=(const {{classname}}& other) const
{
return !(*this == other);
}
void to_json(nlohmann::json& j, const {{classname}}& o)
{
{{#vars}}
{{^required}}if (!o.{{name}}.isEmpty()){{/required}}
j["{{baseName}}"] = o.{{name}}{{^required}}.get(){{/required}};
{{/vars}}
}
void from_json(const nlohmann::json& j, {{classname}}& o)
{
{{#vars}}
{{#required}}j.at("{{baseName}}").get_to(o.{{name}});{{/required}}
{{^required}}if (j.find("{{baseName}}") != j.end()) {
{{{dataType}}} temporary_{{name}};
j.at("{{baseName}}").get_to(temporary_{{name}});
o.{{name}} = Pistache::Some(temporary_{{name}});
}{{/required}}
{{/vars}}
}
{{#modelNamespaceDeclarations}}
} // {{this}}
{{/modelNamespaceDeclarations}}
{{/model}}
{{/models}}

View File

@@ -7,8 +7,6 @@ using {{packageName}}.{{packageContext}}.Models;
using {{packageName}}.{{packageContext}}.Utils;
using NodaTime;{{#asyncServer}}
using System.Threading.Tasks;{{/asyncServer}}
{{#imports}}using {{import}};
{{/imports}}
namespace {{packageName}}.{{packageContext}}.Modules
{ {{#operations}}{{#operation}}{{#allParams}}{{#isEnum}}

View File

@@ -4,8 +4,6 @@ using System.IO;
using System.Text;
using Sharpility.Extensions;
using NodaTime;
{{#imports}}using {{import}};
{{/imports}}
namespace {{packageName}}.{{packageContext}}.Models
{
@@ -14,4 +12,4 @@ namespace {{packageName}}.{{packageContext}}.Models
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}}
{{/model}}
{{/models}}
}
}

View File

@@ -4,11 +4,8 @@
[DataContract(Name = "{{{name}}}")]
{{#discriminator}}
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]
{{#children}}
[JsonSubtypes.KnownSubType(typeof({{classname}}), "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}")]
{{/children}}
{{#mappedModels}}
[JsonSubtypes.KnownSubType(typeof({{{modelName}}}), "{{{mappingName}}}")]
[JsonSubtypes.KnownSubType(typeof({{{modelName}}}), "{{^vendorExtensions.x-discriminator-value}}{{{mappingName}}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{.}}}{{/vendorExtensions.x-discriminator-value}}")]
{{/mappedModels}}
{{/discriminator}}
{{>visibility}} partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}>{{#validatable}}, IValidatableObject{{/validatable}}

View File

@@ -29,6 +29,9 @@ import (
"context"
"fmt"
"os"
{{#vendorExtensions.x-go-import}}
{{{vendorExtensions.x-go-import}}}
{{/vendorExtensions.x-go-import}}
{{goImportAlias}} "./openapi"
)
@@ -66,7 +69,7 @@ Other parameters are passed through a pointer to a api{{{nickname}}}Request stru
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}{{#allParams}}
{{^isPathParam}} **{{paramName}}** | {{^isPrimitiveType}}{{^isFile}}[{{/isFile}}{{/isPrimitiveType}}**{{dataType}}**{{^isPrimitiveType}}{{^isFile}}]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}} | {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/isPathParam}}{{/allParams}}
{{^isPathParam}} **{{paramName}}** | {{#isContainer}}{{#isArray}}{{#items}}{{^isPrimitiveType}}{{^isFile}}[{{/isFile}}{{/isPrimitiveType}}**[]{{dataType}}**{{^isPrimitiveType}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{#baseType}}{{baseType}}{{/baseType}}.md){{/isFile}}{{/isPrimitiveType}}{{/items}}{{/isArray}}{{#isMap}}{{#items}}{{^isPrimitiveType}}{{^isFile}}[{{/isFile}}{{/isPrimitiveType}}**map[string]{{dataType}}**{{^isPrimitiveType}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{#baseType}}{{baseType}}{{/baseType}}.md){{/isFile}}{{/isPrimitiveType}}{{/items}}{{/isMap}}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}{{^isFile}}[{{/isFile}}{{/isPrimitiveType}}**{{dataType}}**{{^isPrimitiveType}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{#baseType}}{{baseType}}{{/baseType}}.md){{/isFile}}{{/isPrimitiveType}}{{/isContainer}} | {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/isPathParam}}{{/allParams}}
### Return type

View File

@@ -1,5 +1,6 @@
{{#models}}{{#model}}# {{classname}}
{{^isEnum}}
## Properties
Name | Type | Description | Notes
@@ -12,7 +13,6 @@ Name | Type | Description | Notes
{{/vars}}
{{/vendorExtensions.x-is-one-of-interface}}
{{^isEnum}}
## Methods
{{^vendorExtensions.x-is-one-of-interface}}
@@ -84,6 +84,13 @@ Convenience method to wrap this instance of {{classname}} in {{{.}}}
{{/vendorExtensions.x-implements}}
{{/vendorExtensions.x-is-one-of-interface}}
{{/isEnum}}
{{#isEnum}}
## Enum
{{#allowableValues}}{{#enumVars}}
* `{{name}}` (value: `{{{value}}}`)
{{/enumVars}}{{/allowableValues}}
{{/isEnum}}
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -17,7 +17,7 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
## Requirements.
Python >= 3.5
Python 2.7 and 3.4+
## Installation & Usage
### pip install
@@ -52,4 +52,4 @@ import {{{packageName}}}
Please follow the [installation procedure](#installation--usage) and then run the following:
{{> python-experimental/README_common }}
{{> common_README }}

View File

@@ -17,7 +17,7 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
## Requirements.
Python >= 3.5
Python 2.7 and 3.4+
## Installation & Usage
@@ -26,6 +26,7 @@ This python library package is generated without supporting files like setup.py
To be able to use it, you will need these dependencies in your own package that uses this library:
* urllib3 >= 1.15
* six >= 1.10
* certifi
* python-dateutil
{{#asyncio}}
@@ -40,4 +41,4 @@ To be able to use it, you will need these dependencies in your own package that
In your own code, to use this library to connect and interact with {{{projectName}}},
you can run the following:
{{> python-experimental/README_common }}
{{> common_README }}

View File

@@ -0,0 +1,7 @@
from __future__ import absolute_import
# flake8: noqa
# import apis into api package
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classVarName}} import {{classname}}
{{/apis}}{{/apiInfo}}

View File

@@ -0,0 +1,10 @@
# coding: utf-8
# flake8: noqa
{{>partial_header}}
from __future__ import absolute_import
# import models into model package
{{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}}{{/model}}
{{/models}}

View File

@@ -4,24 +4,25 @@
{{>partial_header}}
from __future__ import absolute_import
__version__ = "{{packageVersion}}"
# import apis into sdk package
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classVarName}} import {{classname}}
{{/apis}}{{/apiInfo}}
# import ApiClient
from {{packageName}}.api_client import ApiClient
# import Configuration
from {{packageName}}.configuration import Configuration
{{#hasHttpSignatureMethods}}
from {{packageName}}.signing import HttpSigningConfiguration
{{/hasHttpSignatureMethods}}
# import exceptions
from {{packageName}}.exceptions import OpenApiException
from {{packageName}}.exceptions import ApiAttributeError
from {{packageName}}.exceptions import ApiTypeError
from {{packageName}}.exceptions import ApiValueError
from {{packageName}}.exceptions import ApiKeyError
from {{packageName}}.exceptions import ApiAttributeError
from {{packageName}}.exceptions import ApiException
# import models into sdk package
{{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}}
{{/model}}{{/models}}
{{#recursionLimit}}
__import__('sys').setrecursionlimit({{{.}}})

View File

@@ -0,0 +1,294 @@
# coding: utf-8
{{>partial_header}}
from __future__ import absolute_import
import re # noqa: F401
# python 2 and python 3 compatibility library
import six
from {{packageName}}.api_client import ApiClient
from {{packageName}}.exceptions import ( # noqa: F401
ApiTypeError,
ApiValueError
)
{{#operations}}
class {{classname}}(object):
"""NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
def __init__(self, api_client=None):
if api_client is None:
api_client = ApiClient()
self.api_client = api_client
{{#operation}}
def {{operationId}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs): # noqa: E501
"""{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501
{{#notes}}
{{{notes}}} # noqa: E501
{{/notes}}
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
{{#sortParamsByRequiredFlag}}
>>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}async_req=True)
{{/sortParamsByRequiredFlag}}
{{^sortParamsByRequiredFlag}}
>>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}async_req=True)
{{/sortParamsByRequiredFlag}}
>>> result = thread.get()
{{#allParams}}
:param {{paramName}}:{{#description}} {{{description}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
:type {{paramName}}: {{dataType}}{{#optional}}, optional{{/optional}}
{{/allParams}}
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _preload_content: if False, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Default is True.
:type _preload_content: bool, optional
: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.
:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
:rtype: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
"""
kwargs['_return_http_data_only'] = True
return self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs) # noqa: E501
def {{operationId}}_with_http_info(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs): # noqa: E501
"""{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501
{{#notes}}
{{{notes}}} # noqa: E501
{{/notes}}
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
{{#sortParamsByRequiredFlag}}
>>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}async_req=True)
{{/sortParamsByRequiredFlag}}
{{^sortParamsByRequiredFlag}}
>>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}async_req=True)
{{/sortParamsByRequiredFlag}}
>>> result = thread.get()
{{#allParams}}
:param {{paramName}}:{{#description}} {{{description}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
:type {{paramName}}: {{dataType}}{{#optional}}, optional{{/optional}}
{{/allParams}}
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _return_http_data_only: response data without head status code
and headers
:type _return_http_data_only: bool, optional
:param _preload_content: if False, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Default is True.
:type _preload_content: bool, optional
: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.
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
:type _request_auth: dict, optional
:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
:rtype: {{#returnType}}tuple({{returnType}}, status_code(int), headers(HTTPHeaderDict)){{/returnType}}{{^returnType}}None{{/returnType}}
"""
{{#servers.0}}
local_var_hosts = [
{{#servers}}
'{{{url}}}'{{^-last}},{{/-last}}
{{/servers}}
]
local_var_host = local_var_hosts[0]
if kwargs.get('_host_index'):
_host_index = int(kwargs.get('_host_index'))
if _host_index < 0 or _host_index >= len(local_var_hosts):
raise ApiValueError(
"Invalid host index. Must be 0 <= index < %s"
% len(local_var_host)
)
local_var_host = local_var_hosts[_host_index]
{{/servers.0}}
local_var_params = locals()
all_params = [
{{#allParams}}
'{{paramName}}'{{^-last}},{{/-last}}
{{/allParams}}
]
all_params.extend(
[
'async_req',
'_return_http_data_only',
'_preload_content',
'_request_timeout',
'_request_auth'
]
)
for key, val in six.iteritems(local_var_params['kwargs']):
if key not in all_params{{#servers.0}} and key != "_host_index"{{/servers.0}}:
raise ApiTypeError(
"Got an unexpected keyword argument '%s'"
" to method {{operationId}}" % key
)
local_var_params[key] = val
del local_var_params['kwargs']
{{#allParams}}
{{^isNullable}}
{{#required}}
# verify the required parameter '{{paramName}}' is set
if self.api_client.client_side_validation and ('{{paramName}}' not in local_var_params or # noqa: E501
local_var_params['{{paramName}}'] is None): # noqa: E501
raise ApiValueError("Missing the required parameter `{{paramName}}` when calling `{{operationId}}`") # noqa: E501
{{/required}}
{{/isNullable}}
{{/allParams}}
{{#allParams}}
{{#hasValidation}}
{{#maxLength}}
if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and # noqa: E501
len(local_var_params['{{paramName}}']) > {{maxLength}}): # noqa: E501
raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501
{{/maxLength}}
{{#minLength}}
if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and # noqa: E501
len(local_var_params['{{paramName}}']) < {{minLength}}): # noqa: E501
raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501
{{/minLength}}
{{#maximum}}
if self.api_client.client_side_validation and '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}: # noqa: E501
raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501
{{/maximum}}
{{#minimum}}
if self.api_client.client_side_validation and '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}: # noqa: E501
raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501
{{/minimum}}
{{#pattern}}
if self.api_client.client_side_validation and '{{paramName}}' in local_var_params and not re.search(r'{{{vendorExtensions.x-regex}}}', local_var_params['{{paramName}}']{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}): # noqa: E501
raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must conform to the pattern `{{{pattern}}}`") # noqa: E501
{{/pattern}}
{{#maxItems}}
if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and # noqa: E501
len(local_var_params['{{paramName}}']) > {{maxItems}}): # noqa: E501
raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501
{{/maxItems}}
{{#minItems}}
if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and # noqa: E501
len(local_var_params['{{paramName}}']) < {{minItems}}): # noqa: E501
raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501
{{/minItems}}
{{/hasValidation}}
{{#-last}}
{{/-last}}
{{/allParams}}
collection_formats = {}
path_params = {}
{{#pathParams}}
if '{{paramName}}' in local_var_params:
path_params['{{baseName}}'] = local_var_params['{{paramName}}']{{#isArray}} # noqa: E501
collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}} # noqa: E501
{{/pathParams}}
query_params = []
{{#queryParams}}
if '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] is not None: # noqa: E501
query_params.append(('{{baseName}}', local_var_params['{{paramName}}'])){{#isArray}} # noqa: E501
collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}} # noqa: E501
{{/queryParams}}
header_params = {}
{{#headerParams}}
if '{{paramName}}' in local_var_params:
header_params['{{baseName}}'] = local_var_params['{{paramName}}']{{#isArray}} # noqa: E501
collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}} # noqa: E501
{{/headerParams}}
form_params = []
local_var_files = {}
{{#formParams}}
if '{{paramName}}' in local_var_params:
{{^isFile}}form_params.append(('{{baseName}}', local_var_params['{{paramName}}'])){{/isFile}}{{#isFile}}local_var_files['{{baseName}}'] = local_var_params['{{paramName}}']{{/isFile}}{{#isArray}} # noqa: E501
collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}} # noqa: E501
{{/formParams}}
body_params = None
{{#bodyParam}}
if '{{paramName}}' in local_var_params:
body_params = local_var_params['{{paramName}}']
{{/bodyParam}}
{{#hasProduces}}
# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
[{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}]) # noqa: E501
{{/hasProduces}}
{{#hasConsumes}}
# HTTP header `Content-Type`
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
[{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}]) # noqa: E501
{{/hasConsumes}}
# Authentication setting
auth_settings = [{{#authMethods}}'{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}] # noqa: E501
{{#returnType}}
{{#responses}}
{{#-first}}
response_types_map = {
{{/-first}}
{{^isWildcard}}
{{code}}: {{#dataType}}"{{dataType}}"{{/dataType}}{{^dataType}}None{{/dataType}},
{{/isWildcard}}
{{#-last}}
}
{{/-last}}
{{/responses}}
{{/returnType}}
{{^returnType}}
response_types_map = {}
{{/returnType}}
return self.api_client.call_api(
'{{{path}}}', '{{httpMethod}}',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_types_map=response_types_map,
auth_settings=auth_settings,
async_req=local_var_params.get('async_req'),
_return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501
_preload_content=local_var_params.get('_preload_content', True),
_request_timeout=local_var_params.get('_request_timeout'),
{{#servers.0}}
_host=local_var_host,
{{/servers.0}}
collection_formats=collection_formats,
_request_auth=local_var_params.get('_request_auth'))
{{/operation}}
{{/operations}}

View File

@@ -0,0 +1,717 @@
# coding: utf-8
{{>partial_header}}
from __future__ import absolute_import
import atexit
import datetime
from dateutil.parser import parse
import json
import mimetypes
from multiprocessing.pool import ThreadPool
import os
import re
import tempfile
# python 2 and python 3 compatibility library
import six
from six.moves.urllib.parse import quote
{{#tornado}}
import tornado.gen
{{/tornado}}
from {{packageName}}.configuration import Configuration
import {{modelPackage}}
from {{packageName}} import rest
from {{packageName}}.exceptions import ApiValueError, ApiException
class ApiClient(object):
"""Generic API client for OpenAPI client library builds.
OpenAPI generic API client. This client handles the client-
server communication, and is invariant across implementations. Specifics of
the methods and models for each application are generated from the OpenAPI
templates.
NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
:param configuration: .Configuration object for this client
:param header_name: a header to pass when making calls to the API.
:param header_value: a header value to pass when making calls to
the API.
:param cookie: a cookie to include in the header when making calls
to the API
:param pool_threads: The number of threads to use for async requests
to the API. More threads means more concurrent API requests.
"""
PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types
NATIVE_TYPES_MAPPING = {
'int': int,
'long': int if six.PY3 else long, # noqa: F821
'float': float,
'str': str,
'bool': bool,
'date': datetime.date,
'datetime': datetime.datetime,
'object': object,
}
_pool = None
def __init__(self, configuration=None, header_name=None, header_value=None,
cookie=None, pool_threads=1):
if configuration is None:
configuration = Configuration.get_default_copy()
self.configuration = configuration
self.pool_threads = pool_threads
self.rest_client = rest.RESTClientObject(configuration)
self.default_headers = {}
if header_name is not None:
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
self.user_agent = '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/python{{/httpUserAgent}}'
self.client_side_validation = configuration.client_side_validation
{{#asyncio}}
async def __aenter__(self):
return self
async def __aexit__(self, exc_type, exc_value, traceback):
await self.close()
{{/asyncio}}
{{^asyncio}}
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.close()
{{/asyncio}}
{{#asyncio}}async {{/asyncio}}def close(self):
{{#asyncio}}
await self.rest_client.close()
{{/asyncio}}
if self._pool:
self._pool.close()
self._pool.join()
self._pool = None
if hasattr(atexit, 'unregister'):
atexit.unregister(self.close)
@property
def pool(self):
"""Create thread pool on first request
avoids instantiating unused threadpool for blocking clients.
"""
if self._pool is None:
atexit.register(self.close)
self._pool = ThreadPool(self.pool_threads)
return self._pool
@property
def user_agent(self):
"""User agent for this API client"""
return self.default_headers['User-Agent']
@user_agent.setter
def user_agent(self, value):
self.default_headers['User-Agent'] = value
def set_default_header(self, header_name, header_value):
self.default_headers[header_name] = header_value
{{#tornado}}
@tornado.gen.coroutine
{{/tornado}}
{{#asyncio}}async {{/asyncio}}def __call_api(
self, resource_path, method, path_params=None,
query_params=None, header_params=None, body=None, post_params=None,
files=None, response_types_map=None, auth_settings=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_request_auth=None):
config = self.configuration
# header parameters
header_params = header_params or {}
header_params.update(self.default_headers)
if self.cookie:
header_params['Cookie'] = self.cookie
if header_params:
header_params = self.sanitize_for_serialization(header_params)
header_params = dict(self.parameters_to_tuples(header_params,
collection_formats))
# path parameters
if path_params:
path_params = self.sanitize_for_serialization(path_params)
path_params = self.parameters_to_tuples(path_params,
collection_formats)
for k, v in path_params:
# specified safe chars, encode everything
resource_path = resource_path.replace(
'{%s}' % k,
quote(str(v), safe=config.safe_chars_for_path_param)
)
# query parameters
if query_params:
query_params = self.sanitize_for_serialization(query_params)
query_params = self.parameters_to_tuples(query_params,
collection_formats)
# post parameters
if post_params or files:
post_params = post_params if post_params else []
post_params = self.sanitize_for_serialization(post_params)
post_params = self.parameters_to_tuples(post_params,
collection_formats)
post_params.extend(self.files_parameters(files))
# auth setting
self.update_params_for_auth(
header_params, query_params, auth_settings,
request_auth=_request_auth)
# body
if body:
body = self.sanitize_for_serialization(body)
# request url
if _host is None:
url = self.configuration.host + resource_path
else:
# use server/host defined in path or operation instead
url = _host + resource_path
try:
# perform request and return response
response_data = {{#asyncio}}await {{/asyncio}}{{#tornado}}yield {{/tornado}}self.request(
method, url, query_params=query_params, headers=header_params,
post_params=post_params, body=body,
_preload_content=_preload_content,
_request_timeout=_request_timeout)
except ApiException as e:
e.body = e.body.decode('utf-8') if six.PY3 else e.body
raise e
self.last_response = response_data
return_data = response_data
if not _preload_content:
{{^tornado}}
return return_data
{{/tornado}}
{{#tornado}}
raise tornado.gen.Return(return_data)
{{/tornado}}
response_type = response_types_map.get(response_data.status, None)
if six.PY3 and response_type not in ["file", "bytes"]:
match = None
content_type = response_data.getheader('content-type')
if content_type is not None:
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s\;]?", content_type)
encoding = match.group(1) if match else "utf-8"
response_data.data = response_data.data.decode(encoding)
# deserialize response data
if response_type:
return_data = self.deserialize(response_data, response_type)
else:
return_data = None
{{^tornado}}
if _return_http_data_only:
return (return_data)
else:
return (return_data, response_data.status,
response_data.getheaders())
{{/tornado}}
{{#tornado}}
if _return_http_data_only:
raise tornado.gen.Return(return_data)
else:
raise tornado.gen.Return((return_data, response_data.status,
response_data.getheaders()))
{{/tornado}}
def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
If obj is list, sanitize each element in the list.
If obj is dict, return the dict.
If obj is OpenAPI model, return the properties dict.
:param obj: The data to serialize.
:return: The serialized form of data.
"""
if obj is None:
return None
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
return [self.sanitize_for_serialization(sub_obj)
for sub_obj in obj]
elif isinstance(obj, tuple):
return tuple(self.sanitize_for_serialization(sub_obj)
for sub_obj in obj)
elif isinstance(obj, (datetime.datetime, datetime.date)):
return obj.isoformat()
if isinstance(obj, dict):
obj_dict = obj
else:
# Convert model obj to dict except
# attributes `openapi_types`, `attribute_map`
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
for attr, _ in six.iteritems(obj.openapi_types)
if getattr(obj, attr) is not None}
return {key: self.sanitize_for_serialization(val)
for key, val in six.iteritems(obj_dict)}
def deserialize(self, response, response_type):
"""Deserializes response into an object.
:param response: RESTResponse object to be deserialized.
:param response_type: class literal for
deserialized object, or string of class name.
:return: deserialized object.
"""
# handle file downloading
# save response body into a tmp file and return the instance
if response_type == "file":
return self.__deserialize_file(response)
# fetch data from response object
try:
data = json.loads(response.data)
except ValueError:
data = response.data
return self.__deserialize(data, response_type)
def __deserialize(self, data, klass):
"""Deserializes dict, list, str into an object.
:param data: dict, list or str.
:param klass: class literal, or string of class name.
:return: object.
"""
if data is None:
return None
if type(klass) == str:
if klass.startswith('list['):
sub_kls = re.match(r'list\[(.*)\]', klass).group(1)
return [self.__deserialize(sub_data, sub_kls)
for sub_data in data]
if klass.startswith('dict('):
sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2)
return {k: self.__deserialize(v, sub_kls)
for k, v in six.iteritems(data)}
# convert str to class
if klass in self.NATIVE_TYPES_MAPPING:
klass = self.NATIVE_TYPES_MAPPING[klass]
else:
klass = getattr({{modelPackage}}, klass)
if klass in self.PRIMITIVE_TYPES:
return self.__deserialize_primitive(data, klass)
elif klass == object:
return self.__deserialize_object(data)
elif klass == datetime.date:
return self.__deserialize_date(data)
elif klass == datetime.datetime:
return self.__deserialize_datetime(data)
else:
return self.__deserialize_model(data, klass)
def call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
response_types_map=None, auth_settings=None,
async_req=None, _return_http_data_only=None,
collection_formats=None,_preload_content=True,
_request_timeout=None, _host=None, _request_auth=None):
"""Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter.
:param resource_path: Path to method endpoint.
:param method: Method to call.
:param path_params: Path parameters in the url.
:param query_params: Query parameters in the url.
:param header_params: Header parameters to be
placed in the request header.
:param body: Request body.
:param post_params dict: Request post form parameters,
for `application/x-www-form-urlencoded`, `multipart/form-data`.
:param auth_settings list: Auth Settings names for the request.
:param response: Response data type.
:param files dict: key -> filename, value -> filepath,
for `multipart/form-data`.
:param async_req bool: execute request asynchronously
:param _return_http_data_only: response data without head status code
and headers
:param collection_formats: dict of collection formats for path, query,
header, and post parameters.
:param _preload_content: if False, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Default is True.
: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.
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
:type _request_token: dict, optional
:return:
If async_req parameter is True,
the request will be called asynchronously.
The method will return the request thread.
If parameter async_req is False or missing,
then the method will return the response directly.
"""
if not async_req:
return self.__call_api(resource_path, method,
path_params, query_params, header_params,
body, post_params, files,
response_types_map, auth_settings,
_return_http_data_only, collection_formats,
_preload_content, _request_timeout, _host,
_request_auth)
return self.pool.apply_async(self.__call_api, (resource_path,
method, path_params,
query_params,
header_params, body,
post_params, files,
response_types_map,
auth_settings,
_return_http_data_only,
collection_formats,
_preload_content,
_request_timeout,
_host, _request_auth))
def request(self, method, url, query_params=None, headers=None,
post_params=None, body=None, _preload_content=True,
_request_timeout=None):
"""Makes the HTTP request using RESTClient."""
if method == "GET":
return self.rest_client.GET(url,
query_params=query_params,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
headers=headers)
elif method == "HEAD":
return self.rest_client.HEAD(url,
query_params=query_params,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
headers=headers)
elif method == "OPTIONS":
return self.rest_client.OPTIONS(url,
query_params=query_params,
headers=headers,
_preload_content=_preload_content,
_request_timeout=_request_timeout)
elif method == "POST":
return self.rest_client.POST(url,
query_params=query_params,
headers=headers,
post_params=post_params,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
body=body)
elif method == "PUT":
return self.rest_client.PUT(url,
query_params=query_params,
headers=headers,
post_params=post_params,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
body=body)
elif method == "PATCH":
return self.rest_client.PATCH(url,
query_params=query_params,
headers=headers,
post_params=post_params,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
body=body)
elif method == "DELETE":
return self.rest_client.DELETE(url,
query_params=query_params,
headers=headers,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
body=body)
else:
raise ApiValueError(
"http method must be `GET`, `HEAD`, `OPTIONS`,"
" `POST`, `PATCH`, `PUT` or `DELETE`."
)
def parameters_to_tuples(self, params, collection_formats):
"""Get parameters as list of tuples, formatting collections.
:param params: Parameters as dict or list of two-tuples
:param dict collection_formats: Parameter collection formats
:return: Parameters as list of tuples, collections formatted
"""
new_params = []
if collection_formats is None:
collection_formats = {}
for k, v in six.iteritems(params) if isinstance(params, dict) else params: # noqa: E501
if k in collection_formats:
collection_format = collection_formats[k]
if collection_format == 'multi':
new_params.extend((k, value) for value in v)
else:
if collection_format == 'ssv':
delimiter = ' '
elif collection_format == 'tsv':
delimiter = '\t'
elif collection_format == 'pipes':
delimiter = '|'
else: # csv is the default
delimiter = ','
new_params.append(
(k, delimiter.join(str(value) for value in v)))
else:
new_params.append((k, v))
return new_params
def files_parameters(self, files=None):
"""Builds form parameters.
:param files: File parameters.
:return: Form parameters with files.
"""
params = []
if files:
for k, v in six.iteritems(files):
if not v:
continue
file_names = v if type(v) is list else [v]
for n in file_names:
with open(n, 'rb') as f:
filename = os.path.basename(f.name)
filedata = f.read()
mimetype = (mimetypes.guess_type(filename)[0] or
'application/octet-stream')
params.append(
tuple([k, tuple([filename, filedata, mimetype])]))
return params
def select_header_accept(self, accepts):
"""Returns `Accept` based on an array of accepts provided.
:param accepts: List of headers.
:return: Accept (e.g. application/json).
"""
if not accepts:
return
accepts = [x.lower() for x in accepts]
if 'application/json' in accepts:
return 'application/json'
else:
return ', '.join(accepts)
def select_header_content_type(self, content_types):
"""Returns `Content-Type` based on an array of content_types provided.
:param content_types: List of content-types.
:return: Content-Type (e.g. application/json).
"""
if not content_types:
return 'application/json'
content_types = [x.lower() for x in content_types]
if 'application/json' in content_types or '*/*' in content_types:
return 'application/json'
else:
return content_types[0]
def update_params_for_auth(self, headers, querys, auth_settings,
request_auth=None):
"""Updates header and query params based on authentication setting.
:param headers: Header parameters dict to be updated.
:param querys: Query parameters tuple list to be updated.
:param auth_settings: Authentication setting identifiers list.
:param request_auth: if set, the provided settings will
override the token in the configuration.
"""
if not auth_settings:
return
if request_auth:
self._apply_auth_params(headers, querys, request_auth)
return
for auth in auth_settings:
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
self._apply_auth_params(headers, querys, auth_setting)
def _apply_auth_params(self, headers, querys, auth_setting):
"""Updates the request parameters based on a single auth_setting
:param headers: Header parameters dict to be updated.
:param querys: Query parameters tuple list to be updated.
:param auth_setting: auth settings for the endpoint
"""
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']
elif auth_setting['in'] == 'query':
querys.append((auth_setting['key'], auth_setting['value']))
else:
raise ApiValueError(
'Authentication token must be in `query` or `header`'
)
def __deserialize_file(self, response):
"""Deserializes body to file
Saves response body into a file in a temporary folder,
using the filename from the `Content-Disposition` header if provided.
:param response: RESTResponse.
:return: file path.
"""
fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
os.close(fd)
os.remove(path)
content_disposition = response.getheader("Content-Disposition")
if content_disposition:
filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
content_disposition).group(1)
path = os.path.join(os.path.dirname(path), filename)
with open(path, "wb") as f:
f.write(response.data)
return path
def __deserialize_primitive(self, data, klass):
"""Deserializes string to primitive type.
:param data: str.
:param klass: class literal.
:return: int, long, float, str, bool.
"""
try:
return klass(data)
except UnicodeEncodeError:
return six.text_type(data)
except TypeError:
return data
def __deserialize_object(self, value):
"""Return an original value.
:return: object.
"""
return value
def __deserialize_date(self, string):
"""Deserializes string to date.
:param string: str.
:return: date.
"""
try:
return parse(string).date()
except ImportError:
return string
except ValueError:
raise rest.ApiException(
status=0,
reason="Failed to parse `{0}` as date object".format(string)
)
def __deserialize_datetime(self, string):
"""Deserializes string to datetime.
The string should be in iso8601 datetime format.
:param string: str.
:return: datetime.
"""
try:
return parse(string)
except ImportError:
return string
except ValueError:
raise rest.ApiException(
status=0,
reason=(
"Failed to parse `{0}` as datetime object"
.format(string)
)
)
def __deserialize_model(self, data, klass):
"""Deserializes list or dict to model.
:param data: dict, list.
:param klass: class literal.
:return: model object.
"""
has_discriminator = False
if (hasattr(klass, 'get_real_child_model')
and klass.discriminator_value_class_map):
has_discriminator = True
if not klass.openapi_types and has_discriminator is False:
return data
kwargs = {}
if (data is not None and
klass.openapi_types is not None and
isinstance(data, (list, dict))):
for attr, attr_type in six.iteritems(klass.openapi_types):
if klass.attribute_map[attr] in data:
value = data[klass.attribute_map[attr]]
kwargs[attr] = self.__deserialize(value, attr_type)
instance = klass(**kwargs)
if has_discriminator:
klass_name = instance.get_real_child_model(data)
if klass_name:
instance = self.__deserialize(data, klass_name)
return instance

View File

@@ -11,7 +11,7 @@ Method | HTTP request | Description
{{#operations}}
{{#operation}}
# **{{{operationId}}}**
> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#requiredParams}}{{^defaultValue}}{{paramName}}{{^-last}}, {{/-last}}{{/defaultValue}}{{/requiredParams}})
> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#allParams}}{{#required}}{{{paramName}}}{{/required}}{{^required}}{{{paramName}}}={{{paramName}}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
{{{summary}}}{{#notes}}
@@ -35,17 +35,18 @@ Method | HTTP request | Description
{{#isOAuth}}
* OAuth Authentication ({{name}}):
{{/isOAuth }}
{{> api_doc_example }}
{{/authMethods}}
{{/hasAuthMethods}}
{{> python-experimental/api_doc_example }}
{{^hasAuthMethods}}
{{> api_doc_example }}
{{/hasAuthMethods}}
### Parameters
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
{{#requiredParams}}{{^defaultValue}} **{{paramName}}** | {{^baseType}}**{{dataType}}**{{/baseType}}{{#baseType}}[**{{dataType}}**]({{baseType}}.md){{/baseType}}| {{description}} |
{{/defaultValue}}{{/requiredParams}}{{#requiredParams}}{{#defaultValue}} **{{paramName}}** | {{^baseType}}**{{dataType}}**{{/baseType}}{{#baseType}}[**{{dataType}}**]({{baseType}}.md){{/baseType}}| {{description}} | defaults to {{{.}}}
{{/defaultValue}}{{/requiredParams}}{{#optionalParams}} **{{paramName}}** | {{^baseType}}**{{dataType}}**{{/baseType}}{{#baseType}}[**{{dataType}}**]({{baseType}}.md){{/baseType}}| {{description}} | [optional]{{#defaultValue}} if omitted the server will use the default value of {{{.}}}{{/defaultValue}}
{{/optionalParams}}
{{#allParams}} **{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{baseType}}.md){{/isPrimitiveType}}{{/isFile}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
{{/allParams}}
### Return type

View File

@@ -0,0 +1,26 @@
```python
from __future__ import print_function
import time
import {{{packageName}}}
from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{> python_doc_auth_partial}}
# Enter a context with an instance of the API client
{{#hasAuthMethods}}
with {{{packageName}}}.ApiClient(configuration) as api_client:
{{/hasAuthMethods}}
{{^hasAuthMethods}}
with {{{packageName}}}.ApiClient() as api_client:
{{/hasAuthMethods}}
# Create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}
try:
{{#summary}} # {{{.}}}
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}
pprint(api_response){{/returnType}}
except ApiException as e:
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
```

View File

@@ -2,17 +2,20 @@
{{>partial_header}}
from __future__ import absolute_import
import unittest
import {{packageName}}
from {{apiPackage}}.{{classVarName}} import {{classname}} # noqa: E501
from {{packageName}}.rest import ApiException
class {{#operations}}Test{{classname}}(unittest.TestCase):
"""{{classname}} unit test stubs"""
def setUp(self):
self.api = {{classname}}() # noqa: E501
self.api = {{apiPackage}}.{{classVarName}}.{{classname}}() # noqa: E501
def tearDown(self):
pass

View File

@@ -0,0 +1,246 @@
# coding: utf-8
{{>partial_header}}
import io
import json
import logging
import re
import ssl
import aiohttp
import certifi
# python 2 and python 3 compatibility library
from six.moves.urllib.parse import urlencode
from {{packageName}}.exceptions import ApiException, ApiValueError
logger = logging.getLogger(__name__)
class RESTResponse(io.IOBase):
def __init__(self, resp, data):
self.aiohttp_response = resp
self.status = resp.status
self.reason = resp.reason
self.data = data
def getheaders(self):
"""Returns a CIMultiDictProxy of the response headers."""
return self.aiohttp_response.headers
def getheader(self, name, default=None):
"""Returns a given response header."""
return self.aiohttp_response.headers.get(name, default)
class RESTClientObject(object):
def __init__(self, configuration, pools_size=4, maxsize=None):
# maxsize is number of requests to host that are allowed in parallel
if maxsize is None:
maxsize = configuration.connection_pool_maxsize
# ca_certs
if configuration.ssl_ca_cert:
ca_certs = configuration.ssl_ca_cert
else:
# if not set certificate file, use Mozilla's root certificates.
ca_certs = certifi.where()
ssl_context = ssl.create_default_context(cafile=ca_certs)
if configuration.cert_file:
ssl_context.load_cert_chain(
configuration.cert_file, keyfile=configuration.key_file
)
if not configuration.verify_ssl:
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
connector = aiohttp.TCPConnector(
limit=maxsize,
ssl=ssl_context
)
self.proxy = configuration.proxy
self.proxy_headers = configuration.proxy_headers
# https pool manager
self.pool_manager = aiohttp.ClientSession(
connector=connector
)
async def close(self):
await self.pool_manager.close()
async def request(self, method, url, query_params=None, headers=None,
body=None, post_params=None, _preload_content=True,
_request_timeout=None):
"""Execute request
:param method: http request method
:param url: http request url
:param query_params: query parameters in the 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 _preload_content: this is a non-applicable field for
the AiohttpClient.
: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
}
if self.proxy:
args["proxy"] = self.proxy
if self.proxy_headers:
args["proxy_headers"] = self.proxy_headers
if query_params:
args["url"] += '?' + urlencode(query_params)
# 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:
body = json.dumps(body)
args["data"] = body
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
args["data"] = aiohttp.FormData(post_params)
elif headers['Content-Type'] == 'multipart/form-data':
# must del headers['Content-Type'], or the correct
# Content-Type which generated by aiohttp
del headers['Content-Type']
data = aiohttp.FormData()
for param in post_params:
k, v = param
if isinstance(v, tuple) and len(v) == 3:
data.add_field(k,
value=v[1],
filename=v[0],
content_type=v[2])
else:
data.add_field(k, v)
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, 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)
r = await self.pool_manager.request(**args)
if _preload_content:
data = await r.read()
r = RESTResponse(r, data)
# log response body
logger.debug("response body: %s", r.data)
if not 200 <= r.status <= 299:
raise ApiException(http_resp=r)
return r
async def GET(self, url, headers=None, query_params=None,
_preload_content=True, _request_timeout=None):
return (await self.request("GET", url,
headers=headers,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
query_params=query_params))
async def HEAD(self, url, headers=None, query_params=None,
_preload_content=True, _request_timeout=None):
return (await self.request("HEAD", url,
headers=headers,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
query_params=query_params))
async def OPTIONS(self, url, headers=None, query_params=None,
post_params=None, body=None, _preload_content=True,
_request_timeout=None):
return (await self.request("OPTIONS", url,
headers=headers,
query_params=query_params,
post_params=post_params,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
body=body))
async def DELETE(self, url, headers=None, query_params=None, body=None,
_preload_content=True, _request_timeout=None):
return (await self.request("DELETE", url,
headers=headers,
query_params=query_params,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
body=body))
async def POST(self, url, headers=None, query_params=None,
post_params=None, body=None, _preload_content=True,
_request_timeout=None):
return (await self.request("POST", url,
headers=headers,
query_params=query_params,
post_params=post_params,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
body=body))
async def PUT(self, url, headers=None, query_params=None, post_params=None,
body=None, _preload_content=True, _request_timeout=None):
return (await self.request("PUT", url,
headers=headers,
query_params=query_params,
post_params=post_params,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
body=body))
async def PATCH(self, url, headers=None, query_params=None,
post_params=None, body=None, _preload_content=True,
_request_timeout=None):
return (await self.request("PATCH", url,
headers=headers,
query_params=query_params,
post_params=post_params,
_preload_content=_preload_content,
_request_timeout=_request_timeout,
body=body))

View File

@@ -2,6 +2,8 @@
{{>partial_header}}
from __future__ import absolute_import
import copy
import logging
{{^asyncio}}
@@ -10,7 +12,8 @@ import multiprocessing
import sys
import urllib3
from http import client as http_client
import six
from six.moves import http_client as httplib
from {{packageName}}.exceptions import ApiValueError
@@ -299,8 +302,9 @@ conf = {{{packageName}}}.Configuration(
# Enable client side validation
self.client_side_validation = True
# Options to pass down to the underlying urllib3 socket
self.socket_options = None
"""Options to pass down to the underlying urllib3 socket
"""
def __deepcopy__(self, memo):
cls = self.__class__
@@ -385,7 +389,7 @@ conf = {{{packageName}}}.Configuration(
# then add file handler and remove stream handler.
self.logger_file_handler = logging.FileHandler(self.__logger_file)
self.logger_file_handler.setFormatter(self.logger_formatter)
for _, logger in self.logger.items():
for _, logger in six.iteritems(self.logger):
logger.addHandler(self.logger_file_handler)
@property
@@ -407,17 +411,17 @@ conf = {{{packageName}}}.Configuration(
self.__debug = value
if self.__debug:
# if debug status is True, turn on debug logging
for _, logger in self.logger.items():
for _, logger in six.iteritems(self.logger):
logger.setLevel(logging.DEBUG)
# turn on http_client debug
http_client.HTTPConnection.debuglevel = 1
# turn on httplib debug
httplib.HTTPConnection.debuglevel = 1
else:
# if debug status is False, turn off debug logging,
# setting log level to default `logging.WARNING`
for _, logger in self.logger.items():
for _, logger in six.iteritems(self.logger):
logger.setLevel(logging.WARNING)
# turn off http_client debug
http_client.HTTPConnection.debuglevel = 0
# turn off httplib debug
httplib.HTTPConnection.debuglevel = 0
@property
def logger_format(self):

View File

@@ -2,6 +2,8 @@
{{>partial_header}}
import six
class OpenApiException(Exception):
"""The base exception class for all OpenAPIExceptions"""
@@ -118,11 +120,35 @@ class ApiException(OpenApiException):
return error_message
class NotFoundException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None):
super(NotFoundException, self).__init__(status, reason, http_resp)
class UnauthorizedException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None):
super(UnauthorizedException, self).__init__(status, reason, http_resp)
class ForbiddenException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None):
super(ForbiddenException, self).__init__(status, reason, http_resp)
class ServiceException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None):
super(ServiceException, self).__init__(status, reason, http_resp)
def render_path(path_to_item):
"""Returns a string representation of a path"""
result = ""
for pth in path_to_item:
if isinstance(pth, int):
if isinstance(pth, six.integer_types):
result += "[{0}]".format(pth)
else:
result += "['{0}']".format(pth)

View File

@@ -0,0 +1,58 @@
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com"
git_user_id=$1
git_repo_id=$2
release_note=$3
git_host=$4
if [ "$git_host" = "" ]; then
git_host="{{{gitHost}}}"
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
fi
if [ "$git_user_id" = "" ]; then
git_user_id="{{{gitUserId}}}"
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
fi
if [ "$git_repo_id" = "" ]; then
git_repo_id="{{{gitRepoId}}}"
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
fi
if [ "$release_note" = "" ]; then
release_note="{{{releaseNote}}}"
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
fi
# Initialize the local directory as a Git repository
git init
# Adds the files in the local repository and stages them for commit.
git add .
# Commits the tracked changes and prepares them to be pushed to a remote repository.
git commit -m "$release_note"
# Sets the new remote
git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined
if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git
fi
fi
git pull origin master
# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'

View File

@@ -3,7 +3,7 @@
stages:
- test
.tests:
.nosetest:
stage: test
script:
- pip install -r requirements.txt
@@ -15,15 +15,24 @@ stages:
- pytest --cov={{{packageName}}}
{{/useNose}}
test-3.5:
extends: .tests
nosetest-2.7:
extends: .nosetest
image: python:2.7-alpine
nosetest-3.3:
extends: .nosetest
image: python:3.3-alpine
nosetest-3.4:
extends: .nosetest
image: python:3.4-alpine
nosetest-3.5:
extends: .nosetest
image: python:3.5-alpine
test-3.6:
extends: .tests
nosetest-3.6:
extends: .nosetest
image: python:3.6-alpine
test-3.7:
extends: .tests
nosetest-3.7:
extends: .nosetest
image: python:3.7-alpine
test-3.8:
extends: .tests
nosetest-3.8:
extends: .nosetest
image: python:3.8-alpine

View File

@@ -0,0 +1,254 @@
# coding: utf-8
{{>partial_header}}
import inspect
import pprint
import re # noqa: F401
import six
from {{packageName}}.configuration import Configuration
{{#models}}
{{#model}}
class {{classname}}(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""{{#allowableValues}}
"""
allowed enum values
"""
{{#enumVars}}
{{name}} = {{{value}}}{{^-last}}
{{/-last}}
{{/enumVars}}{{/allowableValues}}
{{#allowableValues}}
allowable_values = [{{#enumVars}}{{name}}{{^-last}}, {{/-last}}{{/enumVars}}] # noqa: E501
{{/allowableValues}}
"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
{{#vars}}
'{{name}}': '{{{dataType}}}'{{^-last}},{{/-last}}
{{/vars}}
}
attribute_map = {
{{#vars}}
'{{name}}': '{{baseName}}'{{^-last}},{{/-last}}
{{/vars}}
}
{{#discriminator}}
discriminator_value_class_map = {
{{#children}}
'{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': '{{{classname}}}'{{^-last}},{{/-last}}
{{/children}}
}
{{/discriminator}}
def __init__(self{{#vars}}, {{name}}={{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}, local_vars_configuration=None): # noqa: E501
"""{{classname}} - a model defined in OpenAPI""" # noqa: E501
if local_vars_configuration is None:
local_vars_configuration = Configuration()
self.local_vars_configuration = local_vars_configuration
{{#vars}}{{#-first}}
{{/-first}}
self._{{name}} = None
{{/vars}}
self.discriminator = {{#discriminator}}'{{{discriminatorName}}}'{{/discriminator}}{{^discriminator}}None{{/discriminator}}
{{#vars}}{{#-first}}
{{/-first}}
{{#required}}
self.{{name}} = {{name}}
{{/required}}
{{^required}}
{{#isNullable}}
self.{{name}} = {{name}}
{{/isNullable}}
{{^isNullable}}
if {{name}} is not None:
self.{{name}} = {{name}}
{{/isNullable}}
{{/required}}
{{/vars}}
{{#vars}}
@property
def {{name}}(self):
"""Gets the {{name}} of this {{classname}}. # noqa: E501
{{#description}}
{{{description}}} # noqa: E501
{{/description}}
:return: The {{name}} of this {{classname}}. # noqa: E501
:rtype: {{dataType}}
"""
return self._{{name}}
@{{name}}.setter
def {{name}}(self, {{name}}):
"""Sets the {{name}} of this {{classname}}.
{{#description}}
{{{description}}} # noqa: E501
{{/description}}
:param {{name}}: The {{name}} of this {{classname}}. # noqa: E501
:type {{name}}: {{dataType}}
"""
{{^isNullable}}
{{#required}}
if self.local_vars_configuration.client_side_validation and {{name}} is None: # noqa: E501
raise ValueError("Invalid value for `{{name}}`, must not be `None`") # noqa: E501
{{/required}}
{{/isNullable}}
{{#isEnum}}
{{#isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#items.isString}}"{{/items.isString}}{{{this}}}{{#items.isString}}"{{/items.isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
{{#isArray}}
if (self.local_vars_configuration.client_side_validation and
not set({{{name}}}).issubset(set(allowed_values))): # noqa: E501
raise ValueError(
"Invalid values for `{{{name}}}` [{0}], must be a subset of [{1}]" # noqa: E501
.format(", ".join(map(str, set({{{name}}}) - set(allowed_values))), # noqa: E501
", ".join(map(str, allowed_values)))
)
{{/isArray}}
{{#isMap}}
if (self.local_vars_configuration.client_side_validation and
not set({{{name}}}.keys()).issubset(set(allowed_values))): # noqa: E501
raise ValueError(
"Invalid keys in `{{{name}}}` [{0}], must be a subset of [{1}]" # noqa: E501
.format(", ".join(map(str, set({{{name}}}.keys()) - set(allowed_values))), # noqa: E501
", ".join(map(str, allowed_values)))
)
{{/isMap}}
{{/isContainer}}
{{^isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#isString}}"{{/isString}}{{{this}}}{{#isString}}"{{/isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
if self.local_vars_configuration.client_side_validation and {{{name}}} not in allowed_values: # noqa: E501
raise ValueError(
"Invalid value for `{{{name}}}` ({0}), must be one of {1}" # noqa: E501
.format({{{name}}}, allowed_values)
)
{{/isContainer}}
{{/isEnum}}
{{^isEnum}}
{{#hasValidation}}
{{#maxLength}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and len({{name}}) > {{maxLength}}):
raise ValueError("Invalid value for `{{name}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501
{{/maxLength}}
{{#minLength}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and len({{name}}) < {{minLength}}):
raise ValueError("Invalid value for `{{name}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501
{{/minLength}}
{{#maximum}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and {{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}): # noqa: E501
raise ValueError("Invalid value for `{{name}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501
{{/maximum}}
{{#minimum}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and {{name}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}): # noqa: E501
raise ValueError("Invalid value for `{{name}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501
{{/minimum}}
{{#pattern}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and not re.search(r'{{{vendorExtensions.x-regex}}}', {{name}}{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}})): # noqa: E501
raise ValueError(r"Invalid value for `{{name}}`, must be a follow pattern or equal to `{{{pattern}}}`") # noqa: E501
{{/pattern}}
{{#maxItems}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and len({{name}}) > {{maxItems}}):
raise ValueError("Invalid value for `{{name}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501
{{/maxItems}}
{{#minItems}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and len({{name}}) < {{minItems}}):
raise ValueError("Invalid value for `{{name}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501
{{/minItems}}
{{/hasValidation}}
{{/isEnum}}
self._{{name}} = {{name}}
{{/vars}}
{{#discriminator}}
def get_real_child_model(self, data):
"""Returns the real base class specified by the discriminator"""
discriminator_key = self.attribute_map[self.discriminator]
discriminator_value = data[discriminator_key]
return self.discriminator_value_class_map.get(discriminator_value)
{{/discriminator}}
def to_dict(self, serialize=False):
"""Returns the model properties as a dict"""
result = {}
def convert(x):
if hasattr(x, "to_dict"):
args = inspect.getargspec(x.to_dict).args
if len(args) == 1:
return x.to_dict()
else:
return x.to_dict(serialize)
else:
return x
for attr, _ in six.iteritems(self.openapi_types):
value = getattr(self, attr)
attr = self.attribute_map.get(attr, attr) if serialize else attr
if isinstance(value, list):
result[attr] = list(map(
lambda x: convert(x),
value
))
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], convert(item[1])),
value.items()
))
else:
result[attr] = convert(value)
return result
def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, {{classname}}):
return False
return self.to_dict() == other.to_dict()
def __ne__(self, other):
"""Returns true if both objects are not equal"""
if not isinstance(other, {{classname}}):
return True
return self.to_dict() != other.to_dict()
{{/model}}
{{/models}}

View File

@@ -0,0 +1,13 @@
{{#models}}{{#model}}# {{classname}}
{{#description}}{{&description}}
{{/description}}
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}}
{{/vars}}
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
{{/model}}{{/models}}

Some files were not shown because too many files have changed in this diff Show More