forked from loafle/openapi-generator-original
python: copy the current Python generator into a "pydantic v1" generator (#16656)
* Copy the current Python generator into a "pydantic v1" generator This generator will be deprecated over time and the normal generator will focus on Pydantic v2. * add missing doc
This commit is contained in:
parent
d58e68f8c0
commit
3b95f701e5
@ -4,7 +4,7 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
- samples/client/echo_api/python/**
|
- samples/client/echo_api/python/**
|
||||||
- .github/workflows/samples-python-nextgen-client-echo-api.yaml
|
- .github/workflows/samples-python-client-echo-api.yaml
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
44
.github/workflows/samples-python-pydantic-v1-client-echo-api.yaml
vendored
Normal file
44
.github/workflows/samples-python-pydantic-v1-client-echo-api.yaml
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
name: Python Client pydantic v1 (Echo API)
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- samples/client/echo_api/python-pydantic-v1/**
|
||||||
|
- .github/workflows/samples-python-pydantic-v1-client-echo-api.yaml
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Test Python client
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
sample:
|
||||||
|
# clients
|
||||||
|
- samples/client/echo_api/python
|
||||||
|
python-version:
|
||||||
|
- "3.7"
|
||||||
|
- "3.8"
|
||||||
|
- "3.9"
|
||||||
|
- "3.10"
|
||||||
|
- "3.11"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
- name: Setup node.js
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
- name: Run echo server
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/wing328/http-echo-server -b openapi-generator-test-server
|
||||||
|
(cd http-echo-server && npm install && npm start &)
|
||||||
|
- name: Install
|
||||||
|
working-directory: ${{ matrix.sample }}
|
||||||
|
run: |
|
||||||
|
pip install -r requirements.txt
|
||||||
|
pip install -r test-requirements.txt
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
working-directory: ${{ matrix.sample }}
|
||||||
|
run: python -m pytest
|
59
.github/workflows/samples-python-pydantic-v1-petstore.yaml
vendored
Normal file
59
.github/workflows/samples-python-pydantic-v1-petstore.yaml
vendored
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
name: "Python Client pydantic v1: Petstore"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/**
|
||||||
|
- samples/openapi3/client/petstore/python-pydantic-v1/**
|
||||||
|
- .github/workflows/samples-python-pydantic-v1-petstore.yaml
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Test Python client
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
python-version:
|
||||||
|
- "3.7"
|
||||||
|
- "3.8"
|
||||||
|
- "3.9"
|
||||||
|
- "3.10"
|
||||||
|
- "3.11"
|
||||||
|
sample:
|
||||||
|
- samples/openapi3/client/petstore/python-aiohttp
|
||||||
|
- samples/openapi3/client/petstore/python
|
||||||
|
services:
|
||||||
|
petstore-api:
|
||||||
|
image: swaggerapi/petstore
|
||||||
|
ports:
|
||||||
|
- 80:8080
|
||||||
|
env:
|
||||||
|
SWAGGER_HOST: http://petstore.swagger.io
|
||||||
|
SWAGGER_BASE_PATH: /v2
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-python@v4
|
||||||
|
id: py
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
|
- name: Cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
key: ${{ runner.os }}-python-${{ steps.py.outputs.python-version }}-
|
||||||
|
path: |
|
||||||
|
~/.cache/pypoetry/virtualenvs/
|
||||||
|
~/.local/pipx/venvs/poetry/
|
||||||
|
.mypy_cache/
|
||||||
|
|
||||||
|
- name: Install poetry
|
||||||
|
run: pipx install --python '${{ steps.py.outputs.python-path }}' poetry
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
working-directory: ${{ matrix.sample }}
|
||||||
|
run: poetry install
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
working-directory: ${{ matrix.sample }}
|
||||||
|
run: poetry run pytest -v
|
8
bin/configs/python-pydantic-v1-aiohttp.yaml
Normal file
8
bin/configs/python-pydantic-v1-aiohttp.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
generatorName: python-pydantic-v1
|
||||||
|
outputDir: samples/openapi3/client/petstore/python-pydantic-v1-aiohttp
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/python-pydantic-v1
|
||||||
|
library: asyncio
|
||||||
|
additionalProperties:
|
||||||
|
packageName: petstore_api
|
||||||
|
mapNumberTo: float
|
6
bin/configs/python-pydantic-v1-echo-api.yaml
Normal file
6
bin/configs/python-pydantic-v1-echo-api.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
generatorName: python-pydantic-v1
|
||||||
|
outputDir: samples/client/echo_api/python-pydantic-v1
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/python-pydantic-v1
|
||||||
|
additionalProperties:
|
||||||
|
hideGenerationTimestamp: "true"
|
12
bin/configs/python-pydantic-v1.yaml
Normal file
12
bin/configs/python-pydantic-v1.yaml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
generatorName: python-pydantic-v1
|
||||||
|
outputDir: samples/openapi3/client/petstore/python-pydantic-v1
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/python-pydantic-v1
|
||||||
|
additionalProperties:
|
||||||
|
packageName: petstore_api
|
||||||
|
useOneOfDiscriminatorLookup: "true"
|
||||||
|
disallowAdditionalPropertiesIfNotPresent: false
|
||||||
|
mapNumberTo: StrictFloat
|
||||||
|
nameMappings:
|
||||||
|
_type: underscore_type
|
||||||
|
type_: type_with_underscore
|
@ -53,6 +53,7 @@ The following generators are available:
|
|||||||
* [php-nextgen (beta)](generators/php-nextgen.md)
|
* [php-nextgen (beta)](generators/php-nextgen.md)
|
||||||
* [powershell (beta)](generators/powershell.md)
|
* [powershell (beta)](generators/powershell.md)
|
||||||
* [python](generators/python.md)
|
* [python](generators/python.md)
|
||||||
|
* [python-pydantic-v1](generators/python-pydantic-v1.md)
|
||||||
* [r](generators/r.md)
|
* [r](generators/r.md)
|
||||||
* [ruby](generators/ruby.md)
|
* [ruby](generators/ruby.md)
|
||||||
* [rust](generators/rust.md)
|
* [rust](generators/rust.md)
|
||||||
|
232
docs/generators/python-pydantic-v1.md
Normal file
232
docs/generators/python-pydantic-v1.md
Normal file
@ -0,0 +1,232 @@
|
|||||||
|
---
|
||||||
|
title: Documentation for the python-pydantic-v1 Generator
|
||||||
|
---
|
||||||
|
|
||||||
|
## METADATA
|
||||||
|
|
||||||
|
| Property | Value | Notes |
|
||||||
|
| -------- | ----- | ----- |
|
||||||
|
| generator name | python-pydantic-v1 | pass this to the generate command after -g |
|
||||||
|
| generator stability | STABLE | |
|
||||||
|
| generator type | CLIENT | |
|
||||||
|
| generator language | Python | |
|
||||||
|
| generator language version | 3.7+ | |
|
||||||
|
| generator default templating engine | mustache | |
|
||||||
|
| helpTxt | Generates a Python client library. | |
|
||||||
|
|
||||||
|
## CONFIG OPTIONS
|
||||||
|
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
|
||||||
|
|
||||||
|
| Option | Description | Values | Default |
|
||||||
|
| ------ | ----------- | ------ | ------- |
|
||||||
|
|dateFormat|date format for query parameters| |%Y-%m-%d|
|
||||||
|
|datetimeFormat|datetime format for query parameters| |%Y-%m-%dT%H:%M:%S%z|
|
||||||
|
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
|
||||||
|
|generateSourceCodeOnly|Specifies that only a library source code is to be generated.| |false|
|
||||||
|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||||
|
|library|library template (sub-template) to use: asyncio, tornado (deprecated), urllib3| |urllib3|
|
||||||
|
|mapNumberTo|Map number to Union[StrictFloat, StrictInt], StrictStr or float.| |Union[StrictFloat, StrictInt]|
|
||||||
|
|packageName|python package name (convention: snake_case).| |openapi_client|
|
||||||
|
|packageUrl|python package URL.| |null|
|
||||||
|
|packageVersion|python package version.| |1.0.0|
|
||||||
|
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|
||||||
|
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|
||||||
|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped.| |false|
|
||||||
|
|
||||||
|
## IMPORT MAPPING
|
||||||
|
|
||||||
|
| Type/Alias | Imports |
|
||||||
|
| ---------- | ------- |
|
||||||
|
|
||||||
|
|
||||||
|
## INSTANTIATION TYPES
|
||||||
|
|
||||||
|
| Type/Alias | Instantiated By |
|
||||||
|
| ---------- | --------------- |
|
||||||
|
|
||||||
|
|
||||||
|
## LANGUAGE PRIMITIVES
|
||||||
|
|
||||||
|
<ul class="column-ul">
|
||||||
|
<li>Dict</li>
|
||||||
|
<li>List</li>
|
||||||
|
<li>bool</li>
|
||||||
|
<li>bytearray</li>
|
||||||
|
<li>bytes</li>
|
||||||
|
<li>date</li>
|
||||||
|
<li>datetime</li>
|
||||||
|
<li>decimal.Decimal</li>
|
||||||
|
<li>dict</li>
|
||||||
|
<li>float</li>
|
||||||
|
<li>int</li>
|
||||||
|
<li>list</li>
|
||||||
|
<li>none_type</li>
|
||||||
|
<li>object</li>
|
||||||
|
<li>str</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
## RESERVED WORDS
|
||||||
|
|
||||||
|
<ul class="column-ul">
|
||||||
|
<li>and</li>
|
||||||
|
<li>as</li>
|
||||||
|
<li>assert</li>
|
||||||
|
<li>async</li>
|
||||||
|
<li>await</li>
|
||||||
|
<li>base64</li>
|
||||||
|
<li>break</li>
|
||||||
|
<li>class</li>
|
||||||
|
<li>continue</li>
|
||||||
|
<li>date</li>
|
||||||
|
<li>def</li>
|
||||||
|
<li>del</li>
|
||||||
|
<li>elif</li>
|
||||||
|
<li>else</li>
|
||||||
|
<li>except</li>
|
||||||
|
<li>exec</li>
|
||||||
|
<li>false</li>
|
||||||
|
<li>finally</li>
|
||||||
|
<li>for</li>
|
||||||
|
<li>from</li>
|
||||||
|
<li>global</li>
|
||||||
|
<li>if</li>
|
||||||
|
<li>import</li>
|
||||||
|
<li>in</li>
|
||||||
|
<li>is</li>
|
||||||
|
<li>json</li>
|
||||||
|
<li>lambda</li>
|
||||||
|
<li>none</li>
|
||||||
|
<li>nonlocal</li>
|
||||||
|
<li>not</li>
|
||||||
|
<li>or</li>
|
||||||
|
<li>pass</li>
|
||||||
|
<li>print</li>
|
||||||
|
<li>property</li>
|
||||||
|
<li>raise</li>
|
||||||
|
<li>return</li>
|
||||||
|
<li>schema</li>
|
||||||
|
<li>self</li>
|
||||||
|
<li>true</li>
|
||||||
|
<li>try</li>
|
||||||
|
<li>while</li>
|
||||||
|
<li>with</li>
|
||||||
|
<li>yield</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
## FEATURE SET
|
||||||
|
|
||||||
|
|
||||||
|
### Client Modification Feature
|
||||||
|
| Name | Supported | Defined By |
|
||||||
|
| ---- | --------- | ---------- |
|
||||||
|
|BasePath|✗|ToolingExtension
|
||||||
|
|Authorizations|✗|ToolingExtension
|
||||||
|
|UserAgent|✗|ToolingExtension
|
||||||
|
|MockServer|✗|ToolingExtension
|
||||||
|
|
||||||
|
### Data Type Feature
|
||||||
|
| Name | Supported | Defined By |
|
||||||
|
| ---- | --------- | ---------- |
|
||||||
|
|Custom|✗|OAS2,OAS3
|
||||||
|
|Int32|✓|OAS2,OAS3
|
||||||
|
|Int64|✓|OAS2,OAS3
|
||||||
|
|Float|✓|OAS2,OAS3
|
||||||
|
|Double|✓|OAS2,OAS3
|
||||||
|
|Decimal|✓|ToolingExtension
|
||||||
|
|String|✓|OAS2,OAS3
|
||||||
|
|Byte|✓|OAS2,OAS3
|
||||||
|
|Binary|✓|OAS2,OAS3
|
||||||
|
|Boolean|✓|OAS2,OAS3
|
||||||
|
|Date|✓|OAS2,OAS3
|
||||||
|
|DateTime|✓|OAS2,OAS3
|
||||||
|
|Password|✓|OAS2,OAS3
|
||||||
|
|File|✓|OAS2
|
||||||
|
|Uuid|✗|
|
||||||
|
|Array|✓|OAS2,OAS3
|
||||||
|
|Null|✗|OAS3
|
||||||
|
|AnyType|✗|OAS2,OAS3
|
||||||
|
|Object|✓|OAS2,OAS3
|
||||||
|
|Maps|✓|ToolingExtension
|
||||||
|
|CollectionFormat|✓|OAS2
|
||||||
|
|CollectionFormatMulti|✓|OAS2
|
||||||
|
|Enum|✓|OAS2,OAS3
|
||||||
|
|ArrayOfEnum|✓|ToolingExtension
|
||||||
|
|ArrayOfModel|✓|ToolingExtension
|
||||||
|
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
|
||||||
|
|ArrayOfCollectionOfModel|✓|ToolingExtension
|
||||||
|
|ArrayOfCollectionOfEnum|✓|ToolingExtension
|
||||||
|
|MapOfEnum|✓|ToolingExtension
|
||||||
|
|MapOfModel|✓|ToolingExtension
|
||||||
|
|MapOfCollectionOfPrimitives|✓|ToolingExtension
|
||||||
|
|MapOfCollectionOfModel|✓|ToolingExtension
|
||||||
|
|MapOfCollectionOfEnum|✓|ToolingExtension
|
||||||
|
|
||||||
|
### Documentation Feature
|
||||||
|
| Name | Supported | Defined By |
|
||||||
|
| ---- | --------- | ---------- |
|
||||||
|
|Readme|✓|ToolingExtension
|
||||||
|
|Model|✓|ToolingExtension
|
||||||
|
|Api|✓|ToolingExtension
|
||||||
|
|
||||||
|
### Global Feature
|
||||||
|
| Name | Supported | Defined By |
|
||||||
|
| ---- | --------- | ---------- |
|
||||||
|
|Host|✓|OAS2,OAS3
|
||||||
|
|BasePath|✓|OAS2,OAS3
|
||||||
|
|Info|✓|OAS2,OAS3
|
||||||
|
|Schemes|✗|OAS2,OAS3
|
||||||
|
|PartialSchemes|✓|OAS2,OAS3
|
||||||
|
|Consumes|✓|OAS2
|
||||||
|
|Produces|✓|OAS2
|
||||||
|
|ExternalDocumentation|✓|OAS2,OAS3
|
||||||
|
|Examples|✓|OAS2,OAS3
|
||||||
|
|XMLStructureDefinitions|✗|OAS2,OAS3
|
||||||
|
|MultiServer|✗|OAS3
|
||||||
|
|ParameterizedServer|✗|OAS3
|
||||||
|
|ParameterStyling|✗|OAS3
|
||||||
|
|Callbacks|✗|OAS3
|
||||||
|
|LinkObjects|✗|OAS3
|
||||||
|
|
||||||
|
### Parameter Feature
|
||||||
|
| Name | Supported | Defined By |
|
||||||
|
| ---- | --------- | ---------- |
|
||||||
|
|Path|✓|OAS2,OAS3
|
||||||
|
|Query|✓|OAS2,OAS3
|
||||||
|
|Header|✓|OAS2,OAS3
|
||||||
|
|Body|✓|OAS2
|
||||||
|
|FormUnencoded|✓|OAS2
|
||||||
|
|FormMultipart|✓|OAS2
|
||||||
|
|Cookie|✗|OAS3
|
||||||
|
|
||||||
|
### Schema Support Feature
|
||||||
|
| Name | Supported | Defined By |
|
||||||
|
| ---- | --------- | ---------- |
|
||||||
|
|Simple|✓|OAS2,OAS3
|
||||||
|
|Composite|✓|OAS2,OAS3
|
||||||
|
|Polymorphism|✓|OAS2,OAS3
|
||||||
|
|Union|✗|OAS3
|
||||||
|
|allOf|✓|OAS2,OAS3
|
||||||
|
|anyOf|✓|OAS3
|
||||||
|
|oneOf|✓|OAS3
|
||||||
|
|not|✗|OAS3
|
||||||
|
|
||||||
|
### Security Feature
|
||||||
|
| Name | Supported | Defined By |
|
||||||
|
| ---- | --------- | ---------- |
|
||||||
|
|BasicAuth|✓|OAS2,OAS3
|
||||||
|
|ApiKey|✓|OAS2,OAS3
|
||||||
|
|OpenIDConnect|✗|OAS3
|
||||||
|
|BearerToken|✓|OAS3
|
||||||
|
|OAuth2_Implicit|✓|OAS2,OAS3
|
||||||
|
|OAuth2_Password|✗|OAS2,OAS3
|
||||||
|
|OAuth2_ClientCredentials|✗|OAS2,OAS3
|
||||||
|
|OAuth2_AuthorizationCode|✗|OAS2,OAS3
|
||||||
|
|SignatureAuth|✓|OAS3
|
||||||
|
|
||||||
|
### Wire Format Feature
|
||||||
|
| Name | Supported | Defined By |
|
||||||
|
| ---- | --------- | ---------- |
|
||||||
|
|JSON|✓|OAS2,OAS3
|
||||||
|
|XML|✓|OAS2,OAS3
|
||||||
|
|PROTOBUF|✗|ToolingExtension
|
||||||
|
|Custom|✓|OAS2,OAS3
|
@ -0,0 +1,484 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||||
|
* Copyright 2018 SmartBear Software
|
||||||
|
*
|
||||||
|
* 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.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.openapitools.codegen.*;
|
||||||
|
import org.openapitools.codegen.meta.GeneratorMetadata;
|
||||||
|
import org.openapitools.codegen.meta.Stability;
|
||||||
|
import org.openapitools.codegen.meta.features.*;
|
||||||
|
import org.openapitools.codegen.meta.features.*;
|
||||||
|
import org.openapitools.codegen.model.ModelMap;
|
||||||
|
import org.openapitools.codegen.model.ModelsMap;
|
||||||
|
import org.openapitools.codegen.model.OperationMap;
|
||||||
|
import org.openapitools.codegen.model.OperationsMap;
|
||||||
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
|
import org.openapitools.codegen.utils.ProcessUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.escape;
|
||||||
|
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||||
|
|
||||||
|
public class PythonClientPydanticV1Codegen extends AbstractPythonCodegen implements CodegenConfig {
|
||||||
|
private final Logger LOGGER = LoggerFactory.getLogger(PythonClientCodegen.class);
|
||||||
|
|
||||||
|
public static final String PACKAGE_URL = "packageUrl";
|
||||||
|
public static final String DEFAULT_LIBRARY = "urllib3";
|
||||||
|
public static final String RECURSION_LIMIT = "recursionLimit";
|
||||||
|
public static final String DATETIME_FORMAT = "datetimeFormat";
|
||||||
|
public static final String DATE_FORMAT = "dateFormat";
|
||||||
|
|
||||||
|
protected String packageUrl;
|
||||||
|
protected String apiDocPath = "docs/";
|
||||||
|
protected String modelDocPath = "docs/";
|
||||||
|
protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
|
||||||
|
protected String datetimeFormat = "%Y-%m-%dT%H:%M:%S.%f%z";
|
||||||
|
protected String dateFormat = "%Y-%m-%d";
|
||||||
|
|
||||||
|
|
||||||
|
private String testFolder;
|
||||||
|
|
||||||
|
public PythonClientPydanticV1Codegen() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
// force sortParamsByRequiredFlag to true to make the api method signature less complicated
|
||||||
|
sortParamsByRequiredFlag = true;
|
||||||
|
|
||||||
|
modifyFeatureSet(features -> features
|
||||||
|
.includeDocumentationFeatures(DocumentationFeature.Readme)
|
||||||
|
.wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON, WireFormatFeature.XML, WireFormatFeature.Custom))
|
||||||
|
.includeSecurityFeatures(SecurityFeature.SignatureAuth)
|
||||||
|
.excludeGlobalFeatures(
|
||||||
|
GlobalFeature.XMLStructureDefinitions,
|
||||||
|
GlobalFeature.Callbacks,
|
||||||
|
GlobalFeature.LinkObjects,
|
||||||
|
GlobalFeature.ParameterStyling
|
||||||
|
)
|
||||||
|
.includeSchemaSupportFeatures(
|
||||||
|
SchemaSupportFeature.Polymorphism,
|
||||||
|
SchemaSupportFeature.allOf,
|
||||||
|
SchemaSupportFeature.oneOf,
|
||||||
|
SchemaSupportFeature.anyOf
|
||||||
|
)
|
||||||
|
.excludeParameterFeatures(
|
||||||
|
ParameterFeature.Cookie
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
|
||||||
|
.stability(Stability.STABLE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// clear import mapping (from default generator) as python does not use it
|
||||||
|
// at the moment
|
||||||
|
importMapping.clear();
|
||||||
|
|
||||||
|
// override type mapping in abstract python codegen
|
||||||
|
typeMapping.put("array", "List");
|
||||||
|
typeMapping.put("set", "List");
|
||||||
|
typeMapping.put("map", "Dict");
|
||||||
|
typeMapping.put("decimal", "decimal.Decimal");
|
||||||
|
typeMapping.put("file", "bytearray");
|
||||||
|
typeMapping.put("binary", "bytearray");
|
||||||
|
typeMapping.put("ByteArray", "bytearray");
|
||||||
|
|
||||||
|
languageSpecificPrimitives.remove("file");
|
||||||
|
languageSpecificPrimitives.add("decimal.Decimal");
|
||||||
|
languageSpecificPrimitives.add("bytearray");
|
||||||
|
languageSpecificPrimitives.add("none_type");
|
||||||
|
|
||||||
|
supportsInheritance = true;
|
||||||
|
modelPackage = "models";
|
||||||
|
apiPackage = "api";
|
||||||
|
outputFolder = "generated-code" + File.separatorChar + "python";
|
||||||
|
|
||||||
|
modelTemplateFiles.put("model.mustache", ".py");
|
||||||
|
apiTemplateFiles.put("api.mustache", ".py");
|
||||||
|
|
||||||
|
modelTestTemplateFiles.put("model_test.mustache", ".py");
|
||||||
|
apiTestTemplateFiles.put("api_test.mustache", ".py");
|
||||||
|
|
||||||
|
embeddedTemplateDir = templateDir = "python";
|
||||||
|
|
||||||
|
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||||
|
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||||
|
|
||||||
|
testFolder = "test";
|
||||||
|
|
||||||
|
// default HIDE_GENERATION_TIMESTAMP to true
|
||||||
|
hideGenerationTimestamp = Boolean.TRUE;
|
||||||
|
|
||||||
|
// from https://docs.python.org/3/reference/lexical_analysis.html#keywords
|
||||||
|
setReservedWordsLowerCase(
|
||||||
|
Arrays.asList(
|
||||||
|
// pydantic keyword
|
||||||
|
"schema", "base64", "json",
|
||||||
|
"date",
|
||||||
|
// @property
|
||||||
|
"property",
|
||||||
|
// python reserved words
|
||||||
|
"and", "del", "from", "not", "while", "as", "elif", "global", "or", "with",
|
||||||
|
"assert", "else", "if", "pass", "yield", "break", "except", "import",
|
||||||
|
"print", "class", "exec", "in", "raise", "continue", "finally", "is",
|
||||||
|
"return", "def", "for", "lambda", "try", "self", "nonlocal", "None", "True",
|
||||||
|
"False", "async", "await"));
|
||||||
|
|
||||||
|
cliOptions.clear();
|
||||||
|
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "python package name (convention: snake_case).")
|
||||||
|
.defaultValue("openapi_client"));
|
||||||
|
cliOptions.add(new CliOption(CodegenConstants.PROJECT_NAME, "python project name in setup.py (e.g. petstore-api)."));
|
||||||
|
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "python package version.")
|
||||||
|
.defaultValue("1.0.0"));
|
||||||
|
cliOptions.add(new CliOption(PACKAGE_URL, "python package URL."));
|
||||||
|
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
|
||||||
|
.defaultValue(Boolean.TRUE.toString()));
|
||||||
|
cliOptions.add(new CliOption(CodegenConstants.SOURCECODEONLY_GENERATION, CodegenConstants.SOURCECODEONLY_GENERATION_DESC)
|
||||||
|
.defaultValue(Boolean.FALSE.toString()));
|
||||||
|
cliOptions.add(new CliOption(RECURSION_LIMIT, "Set the recursion limit. If not set, use the system default value."));
|
||||||
|
cliOptions.add(new CliOption(MAP_NUMBER_TO, "Map number to Union[StrictFloat, StrictInt], StrictStr or float.")
|
||||||
|
.defaultValue("Union[StrictFloat, StrictInt]"));
|
||||||
|
cliOptions.add(new CliOption(DATETIME_FORMAT, "datetime format for query parameters")
|
||||||
|
.defaultValue("%Y-%m-%dT%H:%M:%S%z"));
|
||||||
|
cliOptions.add(new CliOption(DATE_FORMAT, "date format for query parameters")
|
||||||
|
.defaultValue("%Y-%m-%d"));
|
||||||
|
cliOptions.add(new CliOption(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC).defaultValue("false"));
|
||||||
|
|
||||||
|
supportedLibraries.put("urllib3", "urllib3-based client");
|
||||||
|
supportedLibraries.put("asyncio", "asyncio-based client");
|
||||||
|
supportedLibraries.put("tornado", "tornado-based client (deprecated)");
|
||||||
|
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use: asyncio, tornado (deprecated), urllib3");
|
||||||
|
libraryOption.setDefault(DEFAULT_LIBRARY);
|
||||||
|
cliOptions.add(libraryOption);
|
||||||
|
setLibrary(DEFAULT_LIBRARY);
|
||||||
|
|
||||||
|
// option to change how we process + set the data in the 'additionalProperties' keyword.
|
||||||
|
CliOption disallowAdditionalPropertiesIfNotPresentOpt = CliOption.newBoolean(
|
||||||
|
CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT,
|
||||||
|
CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT_DESC).defaultValue(Boolean.TRUE.toString());
|
||||||
|
Map<String, String> disallowAdditionalPropertiesIfNotPresentOpts = new HashMap<>();
|
||||||
|
disallowAdditionalPropertiesIfNotPresentOpts.put("false",
|
||||||
|
"The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.");
|
||||||
|
disallowAdditionalPropertiesIfNotPresentOpts.put("true",
|
||||||
|
"Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.");
|
||||||
|
disallowAdditionalPropertiesIfNotPresentOpt.setEnum(disallowAdditionalPropertiesIfNotPresentOpts);
|
||||||
|
cliOptions.add(disallowAdditionalPropertiesIfNotPresentOpt);
|
||||||
|
this.setDisallowAdditionalPropertiesIfNotPresent(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processOpts() {
|
||||||
|
this.setLegacyDiscriminatorBehavior(false);
|
||||||
|
|
||||||
|
super.processOpts();
|
||||||
|
|
||||||
|
// map to Dot instead of Period
|
||||||
|
specialCharReplacements.put(".", "Dot");
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(System.getenv("PYTHON_POST_PROCESS_FILE"))) {
|
||||||
|
LOGGER.info("Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE=\"/usr/local/bin/yapf -i\"' (Linux/Mac)");
|
||||||
|
LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).");
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean excludeTests = false;
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||||
|
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(CodegenConstants.PROJECT_NAME)) {
|
||||||
|
setProjectName((String) additionalProperties.get(CodegenConstants.PROJECT_NAME));
|
||||||
|
} else {
|
||||||
|
// default: set project based on package name
|
||||||
|
// e.g. petstore_api (package name) => petstore-api (project name)
|
||||||
|
setProjectName(packageName.replaceAll("_", "-"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
|
||||||
|
setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
|
||||||
|
}
|
||||||
|
|
||||||
|
additionalProperties.put(CodegenConstants.PROJECT_NAME, projectName);
|
||||||
|
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||||
|
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(CodegenConstants.EXCLUDE_TESTS)) {
|
||||||
|
excludeTests = Boolean.valueOf(additionalProperties.get(CodegenConstants.EXCLUDE_TESTS).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean generateSourceCodeOnly = false;
|
||||||
|
if (additionalProperties.containsKey(CodegenConstants.SOURCECODEONLY_GENERATION)) {
|
||||||
|
generateSourceCodeOnly = Boolean.valueOf(additionalProperties.get(CodegenConstants.SOURCECODEONLY_GENERATION).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (generateSourceCodeOnly) {
|
||||||
|
// tests in <package>/test
|
||||||
|
testFolder = packagePath() + File.separatorChar + testFolder;
|
||||||
|
// api/model docs in <package>/docs
|
||||||
|
apiDocPath = packagePath() + "/" + apiDocPath;
|
||||||
|
modelDocPath = packagePath() + "/" + modelDocPath;
|
||||||
|
}
|
||||||
|
// make api and model doc path available in mustache template
|
||||||
|
additionalProperties.put("apiDocPath", apiDocPath);
|
||||||
|
additionalProperties.put("modelDocPath", modelDocPath);
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(PACKAGE_URL)) {
|
||||||
|
setPackageUrl((String) additionalProperties.get(PACKAGE_URL));
|
||||||
|
}
|
||||||
|
|
||||||
|
// check to see if setRecursionLimit is set and whether it's an integer
|
||||||
|
if (additionalProperties.containsKey(RECURSION_LIMIT)) {
|
||||||
|
try {
|
||||||
|
Integer.parseInt((String) additionalProperties.get(RECURSION_LIMIT));
|
||||||
|
} catch (NumberFormatException | NullPointerException e) {
|
||||||
|
throw new IllegalArgumentException("recursionLimit must be an integer, e.g. 2000.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP)) {
|
||||||
|
setUseOneOfDiscriminatorLookup(convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP));
|
||||||
|
} else {
|
||||||
|
additionalProperties.put(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, useOneOfDiscriminatorLookup);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(MAP_NUMBER_TO)) {
|
||||||
|
setMapNumberTo(String.valueOf(additionalProperties.get(MAP_NUMBER_TO)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(DATETIME_FORMAT)) {
|
||||||
|
setDatetimeFormat((String) additionalProperties.get(DATETIME_FORMAT));
|
||||||
|
} else {
|
||||||
|
additionalProperties.put(DATETIME_FORMAT, datetimeFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(DATE_FORMAT)) {
|
||||||
|
setDateFormat((String) additionalProperties.get(DATE_FORMAT));
|
||||||
|
} else {
|
||||||
|
additionalProperties.put(DATE_FORMAT, dateFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
String modelPath = packagePath() + File.separatorChar + modelPackage.replace('.', File.separatorChar);
|
||||||
|
String apiPath = packagePath() + File.separatorChar + apiPackage.replace('.', File.separatorChar);
|
||||||
|
|
||||||
|
String readmePath = "README.md";
|
||||||
|
String readmeTemplate = "README.mustache";
|
||||||
|
if (generateSourceCodeOnly) {
|
||||||
|
readmePath = packagePath() + "_" + readmePath;
|
||||||
|
readmeTemplate = "README_onlypackage.mustache";
|
||||||
|
}
|
||||||
|
supportingFiles.add(new SupportingFile(readmeTemplate, "", readmePath));
|
||||||
|
|
||||||
|
if (!generateSourceCodeOnly) {
|
||||||
|
supportingFiles.add(new SupportingFile("tox.mustache", "", "tox.ini"));
|
||||||
|
supportingFiles.add(new SupportingFile("test-requirements.mustache", "", "test-requirements.txt"));
|
||||||
|
supportingFiles.add(new SupportingFile("requirements.mustache", "", "requirements.txt"));
|
||||||
|
supportingFiles.add(new SupportingFile("setup_cfg.mustache", "", "setup.cfg"));
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||||
|
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||||
|
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
|
||||||
|
supportingFiles.add(new SupportingFile("github-workflow.mustache", ".github/workflows", "python.yml"));
|
||||||
|
supportingFiles.add(new SupportingFile("gitlab-ci.mustache", "", ".gitlab-ci.yml"));
|
||||||
|
supportingFiles.add(new SupportingFile("setup.mustache", "", "setup.py"));
|
||||||
|
supportingFiles.add(new SupportingFile("pyproject.mustache", "", "pyproject.toml"));
|
||||||
|
supportingFiles.add(new SupportingFile("py.typed.mustache", packagePath(), "py.typed"));
|
||||||
|
}
|
||||||
|
supportingFiles.add(new SupportingFile("configuration.mustache", packagePath(), "configuration.py"));
|
||||||
|
supportingFiles.add(new SupportingFile("__init__package.mustache", packagePath(), "__init__.py"));
|
||||||
|
supportingFiles.add(new SupportingFile("__init__model.mustache", modelPath, "__init__.py"));
|
||||||
|
supportingFiles.add(new SupportingFile("__init__api.mustache", apiPath, "__init__.py"));
|
||||||
|
// Generate the 'signing.py' module, but only if the 'HTTP signature' security scheme is specified in the OAS.
|
||||||
|
Map<String, SecurityScheme> securitySchemeMap = openAPI != null ?
|
||||||
|
(openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null) : null;
|
||||||
|
List<CodegenSecurity> authMethods = fromSecurity(securitySchemeMap);
|
||||||
|
if (ProcessUtils.hasHttpSignatureMethods(authMethods)) {
|
||||||
|
supportingFiles.add(new SupportingFile("signing.mustache", packagePath(), "signing.py"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the package name consists of dots(openapi.client), then we need to create the directory structure like openapi/client with __init__ files.
|
||||||
|
String[] packageNameSplits = packageName.split("\\.");
|
||||||
|
String currentPackagePath = "";
|
||||||
|
for (int i = 0; i < packageNameSplits.length - 1; i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
currentPackagePath = currentPackagePath + File.separatorChar;
|
||||||
|
}
|
||||||
|
currentPackagePath = currentPackagePath + packageNameSplits[i];
|
||||||
|
supportingFiles.add(new SupportingFile("__init__.mustache", currentPackagePath, "__init__.py"));
|
||||||
|
}
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("exceptions.mustache", packagePath(), "exceptions.py"));
|
||||||
|
|
||||||
|
if (Boolean.FALSE.equals(excludeTests)) {
|
||||||
|
supportingFiles.add(new SupportingFile("__init__.mustache", testFolder, "__init__.py"));
|
||||||
|
}
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("api_client.mustache", packagePath(), "api_client.py"));
|
||||||
|
supportingFiles.add(new SupportingFile("api_response.mustache", packagePath(), "api_response.py"));
|
||||||
|
|
||||||
|
if ("asyncio".equals(getLibrary())) {
|
||||||
|
supportingFiles.add(new SupportingFile("asyncio/rest.mustache", packagePath(), "rest.py"));
|
||||||
|
additionalProperties.put("asyncio", "true");
|
||||||
|
} else if ("tornado".equals(getLibrary())) {
|
||||||
|
supportingFiles.add(new SupportingFile("tornado/rest.mustache", packagePath(), "rest.py"));
|
||||||
|
additionalProperties.put("tornado", "true");
|
||||||
|
} else {
|
||||||
|
supportingFiles.add(new SupportingFile("rest.mustache", packagePath(), "rest.py"));
|
||||||
|
}
|
||||||
|
|
||||||
|
modelPackage = this.packageName + "." + modelPackage;
|
||||||
|
apiPackage = this.packageName + "." + apiPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseOneOfDiscriminatorLookup(boolean useOneOfDiscriminatorLookup) {
|
||||||
|
this.useOneOfDiscriminatorLookup = useOneOfDiscriminatorLookup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getUseOneOfDiscriminatorLookup() {
|
||||||
|
return this.useOneOfDiscriminatorLookup;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelImport(String name) {
|
||||||
|
String modelImport;
|
||||||
|
if (StringUtils.startsWithAny(name, "import", "from")) {
|
||||||
|
modelImport = name;
|
||||||
|
} else {
|
||||||
|
modelImport = "from ";
|
||||||
|
if (!"".equals(modelPackage())) {
|
||||||
|
modelImport += modelPackage() + ".";
|
||||||
|
}
|
||||||
|
modelImport += toModelFilename(name) + " import " + name;
|
||||||
|
}
|
||||||
|
return modelImport;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CodegenType getTag() {
|
||||||
|
return CodegenType.CLIENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "python-pydantic-v1";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelp() {
|
||||||
|
return "Generates a Python client library.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apiDocFileFolder() {
|
||||||
|
return (outputFolder + File.separator + apiDocPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String modelDocFileFolder() {
|
||||||
|
return (outputFolder + File.separator + modelDocPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelDocFilename(String name) {
|
||||||
|
return toModelName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toApiDocFilename(String name) {
|
||||||
|
return toApiName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apiFileFolder() {
|
||||||
|
return outputFolder + File.separatorChar + apiPackage().replace('.', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String modelFileFolder() {
|
||||||
|
return outputFolder + File.separatorChar + modelPackage().replace('.', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apiTestFileFolder() {
|
||||||
|
return outputFolder + File.separatorChar + testFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String modelTestFileFolder() {
|
||||||
|
return outputFolder + File.separatorChar + testFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPackageUrl(String packageUrl) {
|
||||||
|
this.packageUrl = packageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String packagePath() {
|
||||||
|
return packageName.replace('.', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate Python package name from String `packageName`
|
||||||
|
* <p>
|
||||||
|
* (PEP 0008) Python packages should also have short, all-lowercase names,
|
||||||
|
* although the use of underscores is discouraged.
|
||||||
|
*
|
||||||
|
* @param packageName Package name
|
||||||
|
* @return Python package name that conforms to PEP 0008
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("static-method")
|
||||||
|
public String generatePackageName(String packageName) {
|
||||||
|
return underscore(packageName.replaceAll("[^\\w]+", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generatorLanguageVersion() {
|
||||||
|
return "3.7+";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||||
|
final Schema additionalProperties = ModelUtils.getAdditionalProperties(schema);
|
||||||
|
|
||||||
|
if (additionalProperties != null) {
|
||||||
|
codegenModel.additionalPropertiesType = getSchemaType(additionalProperties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeReservedWord(String name) {
|
||||||
|
if (this.reservedWordsMappings().containsKey(name)) {
|
||||||
|
return this.reservedWordsMappings().get(name);
|
||||||
|
}
|
||||||
|
return "var_" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatetimeFormat(String datetimeFormat) {
|
||||||
|
this.datetimeFormat = datetimeFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateFormat(String dateFormat) {
|
||||||
|
this.dateFormat = dateFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -101,6 +101,7 @@ org.openapitools.codegen.languages.PostmanCollectionCodegen
|
|||||||
org.openapitools.codegen.languages.PowerShellClientCodegen
|
org.openapitools.codegen.languages.PowerShellClientCodegen
|
||||||
org.openapitools.codegen.languages.ProtobufSchemaCodegen
|
org.openapitools.codegen.languages.ProtobufSchemaCodegen
|
||||||
org.openapitools.codegen.languages.PythonClientCodegen
|
org.openapitools.codegen.languages.PythonClientCodegen
|
||||||
|
org.openapitools.codegen.languages.PythonClientPydanticV1Codegen
|
||||||
org.openapitools.codegen.languages.PythonFastAPIServerCodegen
|
org.openapitools.codegen.languages.PythonFastAPIServerCodegen
|
||||||
org.openapitools.codegen.languages.PythonFlaskConnexionServerCodegen
|
org.openapitools.codegen.languages.PythonFlaskConnexionServerCodegen
|
||||||
org.openapitools.codegen.languages.PythonAiohttpConnexionServerCodegen
|
org.openapitools.codegen.languages.PythonAiohttpConnexionServerCodegen
|
||||||
|
59
modules/openapi-generator/src/main/resources/python-pydantic-v1/README.mustache
vendored
Normal file
59
modules/openapi-generator/src/main/resources/python-pydantic-v1/README.mustache
vendored
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# {{{projectName}}}
|
||||||
|
{{#appDescriptionWithNewLines}}
|
||||||
|
{{{.}}}
|
||||||
|
{{/appDescriptionWithNewLines}}
|
||||||
|
|
||||||
|
This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||||
|
|
||||||
|
- API version: {{appVersion}}
|
||||||
|
- Package version: {{packageVersion}}
|
||||||
|
{{^hideGenerationTimestamp}}
|
||||||
|
- Build date: {{generatedDate}}
|
||||||
|
{{/hideGenerationTimestamp}}
|
||||||
|
- Build package: {{generatorClass}}
|
||||||
|
{{#infoUrl}}
|
||||||
|
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
|
||||||
|
{{/infoUrl}}
|
||||||
|
|
||||||
|
## Requirements.
|
||||||
|
|
||||||
|
Python {{{generatorLanguageVersion}}}
|
||||||
|
|
||||||
|
## Installation & Usage
|
||||||
|
### pip install
|
||||||
|
|
||||||
|
If the python package is hosted on a repository, you can install directly using:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pip install git+https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}.git
|
||||||
|
```
|
||||||
|
(you may need to run `pip` with root permission: `sudo pip install git+https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}.git`)
|
||||||
|
|
||||||
|
Then import the package:
|
||||||
|
```python
|
||||||
|
import {{{packageName}}}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setuptools
|
||||||
|
|
||||||
|
Install via [Setuptools](http://pypi.python.org/pypi/setuptools).
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python setup.py install --user
|
||||||
|
```
|
||||||
|
(or `sudo python setup.py install` to install the package for all users)
|
||||||
|
|
||||||
|
Then import the package:
|
||||||
|
```python
|
||||||
|
import {{{packageName}}}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Tests
|
||||||
|
|
||||||
|
Execute `pytest` to run the tests.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Please follow the [installation procedure](#installation--usage) and then run the following:
|
||||||
|
|
||||||
|
{{> common_README }}
|
44
modules/openapi-generator/src/main/resources/python-pydantic-v1/README_onlypackage.mustache
vendored
Normal file
44
modules/openapi-generator/src/main/resources/python-pydantic-v1/README_onlypackage.mustache
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# {{{projectName}}}
|
||||||
|
{{#appDescription}}
|
||||||
|
{{{.}}}
|
||||||
|
{{/appDescription}}
|
||||||
|
|
||||||
|
The `{{packageName}}` package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||||
|
|
||||||
|
- API version: {{appVersion}}
|
||||||
|
- Package version: {{packageVersion}}
|
||||||
|
{{^hideGenerationTimestamp}}
|
||||||
|
- Build date: {{generatedDate}}
|
||||||
|
{{/hideGenerationTimestamp}}
|
||||||
|
- Build package: {{generatorClass}}
|
||||||
|
{{#infoUrl}}
|
||||||
|
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
|
||||||
|
{{/infoUrl}}
|
||||||
|
|
||||||
|
## Requirements.
|
||||||
|
|
||||||
|
Python {{{generatorLanguageVersion}}}
|
||||||
|
|
||||||
|
## Installation & Usage
|
||||||
|
|
||||||
|
This python library package is generated without supporting files like setup.py or requirements files
|
||||||
|
|
||||||
|
To be able to use it, you will need these dependencies in your own package that uses this library:
|
||||||
|
|
||||||
|
* urllib3 >= 1.25.3
|
||||||
|
* python-dateutil
|
||||||
|
{{#asyncio}}
|
||||||
|
* aiohttp
|
||||||
|
{{/asyncio}}
|
||||||
|
{{#tornado}}
|
||||||
|
* tornado>=4.2,<5
|
||||||
|
{{/tornado}}
|
||||||
|
* pydantic
|
||||||
|
* aenum
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
In your own code, to use this library to connect and interact with {{{projectName}}},
|
||||||
|
you can run the following:
|
||||||
|
|
||||||
|
{{> common_README }}
|
0
modules/openapi-generator/src/main/resources/python-pydantic-v1/__init__.mustache
vendored
Normal file
0
modules/openapi-generator/src/main/resources/python-pydantic-v1/__init__.mustache
vendored
Normal file
5
modules/openapi-generator/src/main/resources/python-pydantic-v1/__init__api.mustache
vendored
Normal file
5
modules/openapi-generator/src/main/resources/python-pydantic-v1/__init__api.mustache
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# flake8: noqa
|
||||||
|
|
||||||
|
# import apis into api package
|
||||||
|
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}}
|
||||||
|
{{/apis}}{{/apiInfo}}
|
11
modules/openapi-generator/src/main/resources/python-pydantic-v1/__init__model.mustache
vendored
Normal file
11
modules/openapi-generator/src/main/resources/python-pydantic-v1/__init__model.mustache
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
# flake8: noqa
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
# import models into model package
|
||||||
|
{{#models}}
|
||||||
|
{{#model}}
|
||||||
|
from {{modelPackage}}.{{classFilename}} import {{classname}}
|
||||||
|
{{/model}}
|
||||||
|
{{/models}}
|
35
modules/openapi-generator/src/main/resources/python-pydantic-v1/__init__package.mustache
vendored
Normal file
35
modules/openapi-generator/src/main/resources/python-pydantic-v1/__init__package.mustache
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
# flake8: noqa
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
__version__ = "{{packageVersion}}"
|
||||||
|
|
||||||
|
# import apis into sdk package
|
||||||
|
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}}
|
||||||
|
{{/apis}}{{/apiInfo}}
|
||||||
|
# import ApiClient
|
||||||
|
from {{packageName}}.api_response import ApiResponse
|
||||||
|
from {{packageName}}.api_client import ApiClient
|
||||||
|
from {{packageName}}.configuration import Configuration
|
||||||
|
from {{packageName}}.exceptions import OpenApiException
|
||||||
|
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
|
||||||
|
{{#hasHttpSignatureMethods}}
|
||||||
|
from {{packageName}}.signing import HttpSigningConfiguration
|
||||||
|
{{/hasHttpSignatureMethods}}
|
||||||
|
|
||||||
|
# import models into sdk package
|
||||||
|
{{#models}}
|
||||||
|
{{#model}}
|
||||||
|
from {{modelPackage}}.{{classFilename}} import {{classname}}
|
||||||
|
{{/model}}
|
||||||
|
{{/models}}
|
||||||
|
{{#recursionLimit}}
|
||||||
|
|
||||||
|
__import__('sys').setrecursionlimit({{{.}}})
|
||||||
|
{{/recursionLimit}}
|
321
modules/openapi-generator/src/main/resources/python-pydantic-v1/api.mustache
vendored
Normal file
321
modules/openapi-generator/src/main/resources/python-pydantic-v1/api.mustache
vendored
Normal file
@ -0,0 +1,321 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
import re # noqa: F401
|
||||||
|
import io
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
from pydantic import validate_arguments, ValidationError
|
||||||
|
{{#asyncio}}
|
||||||
|
from typing import overload, Optional, Union, Awaitable
|
||||||
|
{{/asyncio}}
|
||||||
|
|
||||||
|
{{#imports}}
|
||||||
|
{{import}}
|
||||||
|
{{/imports}}
|
||||||
|
|
||||||
|
from {{packageName}}.api_client import ApiClient
|
||||||
|
from {{packageName}}.api_response import ApiResponse
|
||||||
|
from {{packageName}}.exceptions import ( # noqa: F401
|
||||||
|
ApiTypeError,
|
||||||
|
ApiValueError
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
{{#operations}}
|
||||||
|
class {{classname}}:
|
||||||
|
"""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) -> None:
|
||||||
|
if api_client is None:
|
||||||
|
api_client = ApiClient.get_default()
|
||||||
|
self.api_client = api_client
|
||||||
|
{{#operation}}
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
{{#asyncio}}
|
||||||
|
async def {{operationId}}(self, {{#allParams}}{{paramName}} : {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}}, {{/allParams}}**kwargs) -> {{{returnType}}}{{^returnType}}None{{/returnType}}: # noqa: E501
|
||||||
|
{{/asyncio}}
|
||||||
|
{{^asyncio}}
|
||||||
|
def {{operationId}}(self, {{#allParams}}{{paramName}} : {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}}, {{/allParams}}**kwargs) -> {{{returnType}}}{{^returnType}}None{{/returnType}}: # noqa: E501
|
||||||
|
{{/asyncio}}
|
||||||
|
"""{{#isDeprecated}}(Deprecated) {{/isDeprecated}}{{{summary}}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501
|
||||||
|
|
||||||
|
{{#notes}}
|
||||||
|
{{{.}}} # noqa: E501
|
||||||
|
{{/notes}}
|
||||||
|
{{^asyncio}}
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
{{/asyncio}}
|
||||||
|
|
||||||
|
{{#allParams}}
|
||||||
|
:param {{paramName}}:{{#description}} {{{.}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
|
||||||
|
:type {{paramName}}: {{dataType}}{{#optional}}, optional{{/optional}}
|
||||||
|
{{/allParams}}
|
||||||
|
{{^asyncio}}
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: bool, optional
|
||||||
|
{{/asyncio}}
|
||||||
|
: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}}None{{/returnType}}
|
||||||
|
"""
|
||||||
|
kwargs['_return_http_data_only'] = True
|
||||||
|
if '_preload_content' in kwargs:
|
||||||
|
message = "Error! Please call the {{operationId}}_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501
|
||||||
|
raise ValueError(message)
|
||||||
|
return {{#asyncio}}await {{/asyncio}}self.{{operationId}}_with_http_info({{#allParams}}{{paramName}}, {{/allParams}}**kwargs) # noqa: E501
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
{{#asyncio}}
|
||||||
|
async def {{operationId}}_with_http_info(self, {{#allParams}}{{paramName}} : {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}}, {{/allParams}}**kwargs) -> ApiResponse: # noqa: E501
|
||||||
|
{{/asyncio}}
|
||||||
|
{{^asyncio}}
|
||||||
|
def {{operationId}}_with_http_info(self, {{#allParams}}{{paramName}} : {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}}, {{/allParams}}**kwargs) -> ApiResponse: # noqa: E501
|
||||||
|
{{/asyncio}}
|
||||||
|
"""{{#isDeprecated}}(Deprecated) {{/isDeprecated}}{{{summary}}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501
|
||||||
|
|
||||||
|
{{#notes}}
|
||||||
|
{{{.}}} # noqa: E501
|
||||||
|
{{/notes}}
|
||||||
|
{{^asyncio}}
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{paramName}}, {{/allParams}}async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
{{/asyncio}}
|
||||||
|
|
||||||
|
{{#allParams}}
|
||||||
|
:param {{paramName}}:{{#description}} {{{.}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
|
||||||
|
:type {{paramName}}: {{dataType}}{{#optional}}, optional{{/optional}}
|
||||||
|
{{/allParams}}
|
||||||
|
{{^asyncio}}
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: bool, optional
|
||||||
|
{{/asyncio}}
|
||||||
|
:param _preload_content: if False, the ApiResponse.data will
|
||||||
|
be set to none and raw_data will store the
|
||||||
|
HTTP response body without reading/decoding.
|
||||||
|
Default is True.
|
||||||
|
:type _preload_content: bool, optional
|
||||||
|
:param _return_http_data_only: response data instead of ApiResponse
|
||||||
|
object with status code, headers, etc
|
||||||
|
:type _return_http_data_only: 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
|
||||||
|
:type _content_type: string, optional: force content-type for the request
|
||||||
|
:return: Returns the result object.
|
||||||
|
If the method is called asynchronously,
|
||||||
|
returns the request thread.
|
||||||
|
:rtype: {{#returnType}}tuple({{.}}, status_code(int), headers(HTTPHeaderDict)){{/returnType}}{{^returnType}}None{{/returnType}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
{{#isDeprecated}}
|
||||||
|
warnings.warn("{{{httpMethod}}} {{{path}}} is deprecated.", DeprecationWarning)
|
||||||
|
|
||||||
|
{{/isDeprecated}}
|
||||||
|
{{#servers.0}}
|
||||||
|
_hosts = [
|
||||||
|
{{#servers}}
|
||||||
|
'{{{url}}}'{{^-last}},{{/-last}}
|
||||||
|
{{/servers}}
|
||||||
|
]
|
||||||
|
_host = _hosts[0]
|
||||||
|
if kwargs.get('_host_index'):
|
||||||
|
_host_index = int(kwargs.get('_host_index'))
|
||||||
|
if _host_index < 0 or _host_index >= len(_hosts):
|
||||||
|
raise ApiValueError(
|
||||||
|
"Invalid host index. Must be 0 <= index < %s"
|
||||||
|
% len(_host)
|
||||||
|
)
|
||||||
|
_host = _hosts[_host_index]
|
||||||
|
{{/servers.0}}
|
||||||
|
_params = locals()
|
||||||
|
|
||||||
|
_all_params = [
|
||||||
|
{{#allParams}}
|
||||||
|
'{{paramName}}'{{^-last}},{{/-last}}
|
||||||
|
{{/allParams}}
|
||||||
|
]
|
||||||
|
_all_params.extend(
|
||||||
|
[
|
||||||
|
{{^asyncio}}
|
||||||
|
'async_req',
|
||||||
|
{{/asyncio}}
|
||||||
|
'_return_http_data_only',
|
||||||
|
'_preload_content',
|
||||||
|
'_request_timeout',
|
||||||
|
'_request_auth',
|
||||||
|
'_content_type',
|
||||||
|
'_headers'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# validate the arguments
|
||||||
|
for _key, _val in _params['kwargs'].items():
|
||||||
|
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
|
||||||
|
)
|
||||||
|
_params[_key] = _val
|
||||||
|
del _params['kwargs']
|
||||||
|
|
||||||
|
_collection_formats = {}
|
||||||
|
|
||||||
|
# process the path parameters
|
||||||
|
_path_params = {}
|
||||||
|
{{#pathParams}}
|
||||||
|
if _params['{{paramName}}'] is not None:
|
||||||
|
_path_params['{{baseName}}'] = _params['{{paramName}}']
|
||||||
|
{{#isArray}}
|
||||||
|
_collection_formats['{{baseName}}'] = '{{collectionFormat}}'
|
||||||
|
{{/isArray}}
|
||||||
|
|
||||||
|
{{/pathParams}}
|
||||||
|
|
||||||
|
# process the query parameters
|
||||||
|
_query_params = []
|
||||||
|
{{#queryParams}}
|
||||||
|
if _params.get('{{paramName}}') is not None: # noqa: E501
|
||||||
|
{{#isDateTime}}
|
||||||
|
if isinstance(_params['{{paramName}}'], datetime):
|
||||||
|
_query_params.append(('{{baseName}}', _params['{{paramName}}'].strftime(self.api_client.configuration.datetime_format)))
|
||||||
|
else:
|
||||||
|
_query_params.append(('{{baseName}}', _params['{{paramName}}']))
|
||||||
|
{{/isDateTime}}
|
||||||
|
{{^isDateTime}}
|
||||||
|
{{#isDate}}
|
||||||
|
if isinstance(_params['{{paramName}}'], date):
|
||||||
|
_query_params.append(('{{baseName}}', _params['{{paramName}}'].strftime(self.api_client.configuration.date_format)))
|
||||||
|
else:
|
||||||
|
_query_params.append(('{{baseName}}', _params['{{paramName}}']))
|
||||||
|
{{/isDate}}
|
||||||
|
{{^isDate}}
|
||||||
|
_query_params.append(('{{baseName}}', _params['{{paramName}}']{{#isEnumRef}}.value{{/isEnumRef}}))
|
||||||
|
{{/isDate}}
|
||||||
|
{{/isDateTime}}
|
||||||
|
{{#isArray}}
|
||||||
|
_collection_formats['{{baseName}}'] = '{{collectionFormat}}'
|
||||||
|
{{/isArray}}
|
||||||
|
|
||||||
|
{{/queryParams}}
|
||||||
|
# process the header parameters
|
||||||
|
_header_params = dict(_params.get('_headers', {}))
|
||||||
|
{{#headerParams}}
|
||||||
|
if _params['{{paramName}}'] is not None:
|
||||||
|
_header_params['{{baseName}}'] = _params['{{paramName}}']
|
||||||
|
{{#isArray}}
|
||||||
|
_collection_formats['{{baseName}}'] = '{{collectionFormat}}'
|
||||||
|
{{/isArray}}
|
||||||
|
|
||||||
|
{{/headerParams}}
|
||||||
|
# process the form parameters
|
||||||
|
_form_params = []
|
||||||
|
_files = {}
|
||||||
|
{{#formParams}}
|
||||||
|
if _params['{{paramName}}'] is not None:
|
||||||
|
{{^isFile}}
|
||||||
|
_form_params.append(('{{{baseName}}}', _params['{{paramName}}']))
|
||||||
|
{{/isFile}}
|
||||||
|
{{#isFile}}
|
||||||
|
_files['{{{baseName}}}'] = _params['{{paramName}}']
|
||||||
|
{{/isFile}}
|
||||||
|
{{#isArray}}
|
||||||
|
_collection_formats['{{{baseName}}}'] = '{{collectionFormat}}'
|
||||||
|
{{/isArray}}
|
||||||
|
|
||||||
|
{{/formParams}}
|
||||||
|
# process the body parameter
|
||||||
|
_body_params = None
|
||||||
|
{{#bodyParam}}
|
||||||
|
if _params['{{paramName}}'] is not None:
|
||||||
|
_body_params = _params['{{paramName}}']
|
||||||
|
{{#isBinary}}
|
||||||
|
# convert to byte array if the input is a file name (str)
|
||||||
|
if isinstance(_body_params, str):
|
||||||
|
with io.open(_body_params, "rb") as _fp:
|
||||||
|
_body_params_from_file = _fp.read()
|
||||||
|
_body_params = _body_params_from_file
|
||||||
|
{{/isBinary}}
|
||||||
|
|
||||||
|
{{/bodyParam}}
|
||||||
|
{{#hasProduces}}
|
||||||
|
# set the HTTP header `Accept`
|
||||||
|
_header_params['Accept'] = self.api_client.select_header_accept(
|
||||||
|
[{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}]) # noqa: E501
|
||||||
|
|
||||||
|
{{/hasProduces}}
|
||||||
|
{{#hasConsumes}}
|
||||||
|
# set the HTTP header `Content-Type`
|
||||||
|
_content_types_list = _params.get('_content_type',
|
||||||
|
self.api_client.select_header_content_type(
|
||||||
|
[{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}]))
|
||||||
|
if _content_types_list:
|
||||||
|
_header_params['Content-Type'] = _content_types_list
|
||||||
|
|
||||||
|
{{/hasConsumes}}
|
||||||
|
# authentication setting
|
||||||
|
_auth_settings = [{{#authMethods}}'{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}] # noqa: E501
|
||||||
|
|
||||||
|
{{#returnType}}
|
||||||
|
{{#responses}}
|
||||||
|
{{#-first}}
|
||||||
|
_response_types_map = {
|
||||||
|
{{/-first}}
|
||||||
|
{{^isWildcard}}
|
||||||
|
'{{code}}': {{#dataType}}"{{.}}"{{/dataType}}{{^dataType}}None{{/dataType}},
|
||||||
|
{{/isWildcard}}
|
||||||
|
{{#-last}}
|
||||||
|
}
|
||||||
|
{{/-last}}
|
||||||
|
{{/responses}}
|
||||||
|
{{/returnType}}
|
||||||
|
{{^returnType}}
|
||||||
|
_response_types_map = {}
|
||||||
|
{{/returnType}}
|
||||||
|
|
||||||
|
return {{#asyncio}}await {{/asyncio}}self.api_client.call_api(
|
||||||
|
'{{{path}}}', '{{httpMethod}}',
|
||||||
|
_path_params,
|
||||||
|
_query_params,
|
||||||
|
_header_params,
|
||||||
|
body=_body_params,
|
||||||
|
post_params=_form_params,
|
||||||
|
files=_files,
|
||||||
|
response_types_map=_response_types_map,
|
||||||
|
auth_settings=_auth_settings,
|
||||||
|
{{^asyncio}}
|
||||||
|
async_req=_params.get('async_req'),
|
||||||
|
{{/asyncio}}
|
||||||
|
_return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501
|
||||||
|
_preload_content=_params.get('_preload_content', True),
|
||||||
|
_request_timeout=_params.get('_request_timeout'),
|
||||||
|
{{#servers.0}}
|
||||||
|
_host=_host,
|
||||||
|
{{/servers.0}}
|
||||||
|
collection_formats=_collection_formats,
|
||||||
|
_request_auth=_params.get('_request_auth'))
|
||||||
|
{{/operation}}
|
||||||
|
{{/operations}}
|
807
modules/openapi-generator/src/main/resources/python-pydantic-v1/api_client.mustache
vendored
Normal file
807
modules/openapi-generator/src/main/resources/python-pydantic-v1/api_client.mustache
vendored
Normal file
@ -0,0 +1,807 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
import atexit
|
||||||
|
import datetime
|
||||||
|
from dateutil.parser import parse
|
||||||
|
import json
|
||||||
|
import mimetypes
|
||||||
|
{{^asyncio}}
|
||||||
|
from multiprocessing.pool import ThreadPool
|
||||||
|
{{/asyncio}}
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from urllib.parse import quote
|
||||||
|
{{#tornado}}
|
||||||
|
import tornado.gen
|
||||||
|
{{/tornado}}
|
||||||
|
|
||||||
|
from {{packageName}}.configuration import Configuration
|
||||||
|
from {{packageName}}.api_response import ApiResponse
|
||||||
|
import {{modelPackage}}
|
||||||
|
from {{packageName}} import rest
|
||||||
|
from {{packageName}}.exceptions import ApiValueError, ApiException
|
||||||
|
|
||||||
|
|
||||||
|
class ApiClient:
|
||||||
|
"""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.
|
||||||
|
|
||||||
|
: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
|
||||||
|
{{^asyncio}}
|
||||||
|
:param pool_threads: The number of threads to use for async requests
|
||||||
|
to the API. More threads means more concurrent API requests.
|
||||||
|
{{/asyncio}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
PRIMITIVE_TYPES = (float, bool, bytes, str, int)
|
||||||
|
NATIVE_TYPES_MAPPING = {
|
||||||
|
'int': int,
|
||||||
|
'long': int, # TODO remove as only py3 is supported?
|
||||||
|
'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{{^asyncio}}, pool_threads=1{{/asyncio}}) -> None:
|
||||||
|
# use default configuration if none is provided
|
||||||
|
if configuration is None:
|
||||||
|
configuration = Configuration.get_default()
|
||||||
|
self.configuration = configuration
|
||||||
|
{{^asyncio}}
|
||||||
|
self.pool_threads = pool_threads
|
||||||
|
{{/asyncio}}
|
||||||
|
|
||||||
|
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}}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()
|
||||||
|
|
||||||
|
async def close(self):
|
||||||
|
await self.rest_client.close()
|
||||||
|
{{/asyncio}}
|
||||||
|
{{^asyncio}}
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
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
|
||||||
|
{{/asyncio}}
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
|
||||||
|
_default = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_default(cls):
|
||||||
|
"""Return new instance of ApiClient.
|
||||||
|
|
||||||
|
This method returns newly created, based on default constructor,
|
||||||
|
object of ApiClient class or returns a copy of default
|
||||||
|
ApiClient.
|
||||||
|
|
||||||
|
:return: The ApiClient object.
|
||||||
|
"""
|
||||||
|
if cls._default is None:
|
||||||
|
cls._default = ApiClient()
|
||||||
|
return cls._default
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_default(cls, default):
|
||||||
|
"""Set default instance of ApiClient.
|
||||||
|
|
||||||
|
It stores default ApiClient.
|
||||||
|
|
||||||
|
:param default: object of ApiClient.
|
||||||
|
"""
|
||||||
|
cls._default = default
|
||||||
|
|
||||||
|
{{#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)
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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,
|
||||||
|
resource_path, method, body,
|
||||||
|
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
|
||||||
|
|
||||||
|
# query parameters
|
||||||
|
if query_params:
|
||||||
|
query_params = self.sanitize_for_serialization(query_params)
|
||||||
|
url_query = self.parameters_to_url_query(query_params,
|
||||||
|
collection_formats)
|
||||||
|
url += "?" + url_query
|
||||||
|
|
||||||
|
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:
|
||||||
|
if e.body:
|
||||||
|
e.body = e.body.decode('utf-8')
|
||||||
|
raise e
|
||||||
|
|
||||||
|
self.last_response = response_data
|
||||||
|
|
||||||
|
return_data = None # assuming deserialization is not needed
|
||||||
|
# data needs deserialization or returns HTTP data (deserialized) only
|
||||||
|
if _preload_content or _return_http_data_only:
|
||||||
|
response_type = response_types_map.get(str(response_data.status), None)
|
||||||
|
if not response_type and isinstance(response_data.status, int) and 100 <= response_data.status <= 599:
|
||||||
|
# if not found, look for '1XX', '2XX', etc.
|
||||||
|
response_type = response_types_map.get(str(response_data.status)[0] + "XX", None)
|
||||||
|
|
||||||
|
if response_type == "bytearray":
|
||||||
|
response_data.data = response_data.data
|
||||||
|
else:
|
||||||
|
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 == "bytearray":
|
||||||
|
return_data = response_data.data
|
||||||
|
elif 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 ApiResponse(status_code = response_data.status,
|
||||||
|
data = return_data,
|
||||||
|
headers = response_data.getheaders(),
|
||||||
|
raw_data = response_data.data)
|
||||||
|
{{/tornado}}
|
||||||
|
{{#tornado}}
|
||||||
|
if _return_http_data_only:
|
||||||
|
raise tornado.gen.Return(return_data)
|
||||||
|
else:
|
||||||
|
raise tornado.gen.Return(ApiResponse(status_code = response_data.status,
|
||||||
|
data = return_data,
|
||||||
|
headers = response_data.getheaders(),
|
||||||
|
raw_data = response_data.data))
|
||||||
|
{{/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.to_dict()
|
||||||
|
|
||||||
|
return {key: self.sanitize_for_serialization(val)
|
||||||
|
for key, val in obj_dict.items()}
|
||||||
|
|
||||||
|
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 isinstance(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 data.items()}
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
{{#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,
|
||||||
|
{{^asyncio}}async_req=None, {{/asyncio}}_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.
|
||||||
|
|
||||||
|
{{^asyncio}}
|
||||||
|
To make an async_req request, set the async_req parameter.
|
||||||
|
|
||||||
|
{{/asyncio}}
|
||||||
|
: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`.
|
||||||
|
{{^asyncio}}
|
||||||
|
:param async_req bool: execute request asynchronously
|
||||||
|
{{/asyncio}}
|
||||||
|
:param _return_http_data_only: response data instead of ApiResponse
|
||||||
|
object with status code, headers, etc
|
||||||
|
:param _preload_content: if False, the ApiResponse.data will
|
||||||
|
be set to none and raw_data will store the
|
||||||
|
HTTP response body without reading/decoding.
|
||||||
|
Default is True.
|
||||||
|
:param collection_formats: dict of collection formats for path, query,
|
||||||
|
header, and post parameters.
|
||||||
|
: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:
|
||||||
|
{{#asyncio}}
|
||||||
|
The response.
|
||||||
|
{{/asyncio}}
|
||||||
|
{{^asyncio}}
|
||||||
|
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.
|
||||||
|
{{/asyncio}}
|
||||||
|
"""
|
||||||
|
args = (
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
{{#asyncio}}
|
||||||
|
return await self.__call_api(*args)
|
||||||
|
{{/asyncio}}
|
||||||
|
{{^asyncio}}
|
||||||
|
if not async_req:
|
||||||
|
return self.__call_api(*args)
|
||||||
|
|
||||||
|
return self.pool.apply_async(self.__call_api, args)
|
||||||
|
{{/asyncio}}
|
||||||
|
|
||||||
|
{{#asyncio}}async {{/asyncio}}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 {{#asyncio}}await {{/asyncio}}self.rest_client.get_request(url,
|
||||||
|
query_params=query_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
headers=headers)
|
||||||
|
elif method == "HEAD":
|
||||||
|
return {{#asyncio}}await {{/asyncio}}self.rest_client.head_request(url,
|
||||||
|
query_params=query_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
headers=headers)
|
||||||
|
elif method == "OPTIONS":
|
||||||
|
return {{#asyncio}}await {{/asyncio}}self.rest_client.options_request(url,
|
||||||
|
query_params=query_params,
|
||||||
|
headers=headers,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout)
|
||||||
|
elif method == "POST":
|
||||||
|
return {{#asyncio}}await {{/asyncio}}self.rest_client.post_request(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 {{#asyncio}}await {{/asyncio}}self.rest_client.put_request(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 {{#asyncio}}await {{/asyncio}}self.rest_client.patch_request(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 {{#asyncio}}await {{/asyncio}}self.rest_client.delete_request(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 params.items() 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 parameters_to_url_query(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: URL query string (e.g. a=Hello%20World&b=123)
|
||||||
|
"""
|
||||||
|
new_params = []
|
||||||
|
if collection_formats is None:
|
||||||
|
collection_formats = {}
|
||||||
|
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
||||||
|
if isinstance(v, (int, float)):
|
||||||
|
v = str(v)
|
||||||
|
if isinstance(v, bool):
|
||||||
|
v = str(v).lower()
|
||||||
|
if isinstance(v, dict):
|
||||||
|
v = json.dumps(v)
|
||||||
|
|
||||||
|
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(quote(str(value)) for value in v)))
|
||||||
|
else:
|
||||||
|
new_params.append((k, quote(str(v))))
|
||||||
|
|
||||||
|
return "&".join(["=".join(item) for item in 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 files.items():
|
||||||
|
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
|
||||||
|
|
||||||
|
for accept in accepts:
|
||||||
|
if re.search('json', accept, re.IGNORECASE):
|
||||||
|
return accept
|
||||||
|
|
||||||
|
return accepts[0]
|
||||||
|
|
||||||
|
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 None
|
||||||
|
|
||||||
|
for content_type in content_types:
|
||||||
|
if re.search('json', content_type, re.IGNORECASE):
|
||||||
|
return content_type
|
||||||
|
|
||||||
|
return content_types[0]
|
||||||
|
|
||||||
|
def update_params_for_auth(self, headers, queries, auth_settings,
|
||||||
|
resource_path, method, body,
|
||||||
|
request_auth=None):
|
||||||
|
"""Updates header and query params based on authentication setting.
|
||||||
|
|
||||||
|
:param headers: Header parameters dict to be updated.
|
||||||
|
:param queries: Query parameters tuple list to be updated.
|
||||||
|
:param auth_settings: Authentication setting identifiers list.
|
||||||
|
:resource_path: A string representation of the HTTP request resource path.
|
||||||
|
:method: A string representation of the HTTP request method.
|
||||||
|
:body: A object representing the body of the HTTP request.
|
||||||
|
The object type is the return value of sanitize_for_serialization().
|
||||||
|
: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, queries,
|
||||||
|
resource_path, method, body,
|
||||||
|
request_auth)
|
||||||
|
return
|
||||||
|
|
||||||
|
for auth in auth_settings:
|
||||||
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
|
if auth_setting:
|
||||||
|
self._apply_auth_params(headers, queries,
|
||||||
|
resource_path, method, body,
|
||||||
|
auth_setting)
|
||||||
|
|
||||||
|
def _apply_auth_params(self, headers, queries,
|
||||||
|
resource_path, method, body,
|
||||||
|
auth_setting):
|
||||||
|
"""Updates the request parameters based on a single auth_setting
|
||||||
|
|
||||||
|
:param headers: Header parameters dict to be updated.
|
||||||
|
:param queries: Query parameters tuple list to be updated.
|
||||||
|
:resource_path: A string representation of the HTTP request resource path.
|
||||||
|
:method: A string representation of the HTTP request method.
|
||||||
|
:body: A object representing the body of the HTTP request.
|
||||||
|
The object type is the return value of sanitize_for_serialization().
|
||||||
|
:param auth_setting: auth settings for the endpoint
|
||||||
|
"""
|
||||||
|
if auth_setting['in'] == 'cookie':
|
||||||
|
headers['Cookie'] = auth_setting['value']
|
||||||
|
elif auth_setting['in'] == 'header':
|
||||||
|
if auth_setting['type'] != 'http-signature':
|
||||||
|
headers[auth_setting['key']] = auth_setting['value']
|
||||||
|
{{#hasHttpSignatureMethods}}
|
||||||
|
else:
|
||||||
|
# The HTTP signature scheme requires multiple HTTP headers
|
||||||
|
# that are calculated dynamically.
|
||||||
|
signing_info = self.configuration.signing_info
|
||||||
|
auth_headers = signing_info.get_http_signature_headers(
|
||||||
|
resource_path, method, headers, body, queries)
|
||||||
|
headers.update(auth_headers)
|
||||||
|
{{/hasHttpSignatureMethods}}
|
||||||
|
elif auth_setting['in'] == 'query':
|
||||||
|
queries.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 str(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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return klass.from_dict(data)
|
74
modules/openapi-generator/src/main/resources/python-pydantic-v1/api_doc.mustache
vendored
Normal file
74
modules/openapi-generator/src/main/resources/python-pydantic-v1/api_doc.mustache
vendored
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# {{packageName}}.{{classname}}{{#description}}
|
||||||
|
{{.}}{{/description}}
|
||||||
|
|
||||||
|
All URIs are relative to *{{basePath}}*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
{{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{summary}}
|
||||||
|
{{/operation}}{{/operations}}
|
||||||
|
|
||||||
|
{{#operations}}
|
||||||
|
{{#operation}}
|
||||||
|
# **{{{operationId}}}**
|
||||||
|
> {{#returnType}}{{{.}}} {{/returnType}}{{{operationId}}}({{#allParams}}{{#required}}{{{paramName}}}{{/required}}{{^required}}{{{paramName}}}={{{paramName}}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||||
|
|
||||||
|
{{{summary}}}{{#notes}}
|
||||||
|
|
||||||
|
{{{.}}}{{/notes}}
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
{{#hasAuthMethods}}
|
||||||
|
{{#authMethods}}
|
||||||
|
{{#isBasic}}
|
||||||
|
{{#isBasicBasic}}
|
||||||
|
* Basic Authentication ({{name}}):
|
||||||
|
{{/isBasicBasic}}
|
||||||
|
{{#isBasicBearer}}
|
||||||
|
* Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} Authentication ({{name}}):
|
||||||
|
{{/isBasicBearer}}
|
||||||
|
{{/isBasic}}
|
||||||
|
{{#isApiKey}}
|
||||||
|
* Api Key Authentication ({{name}}):
|
||||||
|
{{/isApiKey }}
|
||||||
|
{{#isOAuth}}
|
||||||
|
* OAuth Authentication ({{name}}):
|
||||||
|
{{/isOAuth }}
|
||||||
|
{{/authMethods}}
|
||||||
|
{{/hasAuthMethods}}
|
||||||
|
{{> api_doc_example }}
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
|
||||||
|
{{#allParams}} **{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{baseType}}.md){{/isPrimitiveType}}{{/isFile}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{.}}]{{/defaultValue}}
|
||||||
|
{{/allParams}}
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{{returnType}}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void (empty response body){{/returnType}}
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{{name}}}](../README.md#{{{name}}}){{^-last}}, {{/-last}}{{/authMethods}}
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
|
||||||
|
- **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}}
|
||||||
|
|
||||||
|
{{#responses.0}}
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
{{#responses}}
|
||||||
|
**{{code}}** | {{message}} | {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} |
|
||||||
|
{{/responses}}
|
||||||
|
{{/responses.0}}
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
{{/operation}}
|
||||||
|
{{/operations}}
|
38
modules/openapi-generator/src/main/resources/python-pydantic-v1/api_doc_example.mustache
vendored
Normal file
38
modules/openapi-generator/src/main/resources/python-pydantic-v1/api_doc_example.mustache
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import {{{packageName}}}
|
||||||
|
{{#vendorExtensions.x-py-example-import}}
|
||||||
|
{{{.}}}
|
||||||
|
{{/vendorExtensions.x-py-example-import}}
|
||||||
|
from {{{packageName}}}.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
{{> python_doc_auth_partial}}
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
{{#asyncio}}async {{/asyncio}}with {{{packageName}}}.ApiClient(configuration) as api_client:
|
||||||
|
# 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}}{{#asyncio}}await {{/asyncio}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||||
|
{{#returnType}}
|
||||||
|
print("The response of {{classname}}->{{operationId}}:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
{{/returnType}}
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
{{#vendorExtensions.x-py-postponed-example-imports.size}}
|
||||||
|
{{#vendorExtensions.x-py-postponed-example-imports}}
|
||||||
|
{{{.}}}
|
||||||
|
{{/vendorExtensions.x-py-postponed-example-imports}}
|
||||||
|
{{classname}}.update_forward_refs()
|
||||||
|
{{/vendorExtensions.x-py-postponed-example-imports.size}}
|
25
modules/openapi-generator/src/main/resources/python-pydantic-v1/api_response.mustache
vendored
Normal file
25
modules/openapi-generator/src/main/resources/python-pydantic-v1/api_response.mustache
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
"""API response object."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
from typing import Any, Dict, Optional
|
||||||
|
from pydantic import Field, StrictInt, StrictStr
|
||||||
|
|
||||||
|
class ApiResponse:
|
||||||
|
"""
|
||||||
|
API response object
|
||||||
|
"""
|
||||||
|
|
||||||
|
status_code: Optional[StrictInt] = Field(None, description="HTTP status code")
|
||||||
|
headers: Optional[Dict[StrictStr, StrictStr]] = Field(None, description="HTTP headers")
|
||||||
|
data: Optional[Any] = Field(None, description="Deserialized data given the data type")
|
||||||
|
raw_data: Optional[Any] = Field(None, description="Raw data (HTTP response body)")
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
status_code=None,
|
||||||
|
headers=None,
|
||||||
|
data=None,
|
||||||
|
raw_data=None) -> None:
|
||||||
|
self.status_code = status_code
|
||||||
|
self.headers = headers
|
||||||
|
self.data = data
|
||||||
|
self.raw_data = raw_data
|
33
modules/openapi-generator/src/main/resources/python-pydantic-v1/api_test.mustache
vendored
Normal file
33
modules/openapi-generator/src/main/resources/python-pydantic-v1/api_test.mustache
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from {{apiPackage}}.{{classFilename}} import {{classname}} # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
class {{#operations}}Test{{classname}}(unittest.TestCase):
|
||||||
|
"""{{classname}} unit test stubs"""
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.api = {{classname}}() # noqa: E501
|
||||||
|
|
||||||
|
def tearDown(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
{{#operation}}
|
||||||
|
def test_{{operationId}}(self) -> None:
|
||||||
|
"""Test case for {{{operationId}}}
|
||||||
|
|
||||||
|
{{#summary}}
|
||||||
|
{{{.}}} # noqa: E501
|
||||||
|
{{/summary}}
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
{{/operation}}
|
||||||
|
{{/operations}}
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
241
modules/openapi-generator/src/main/resources/python-pydantic-v1/asyncio/rest.mustache
vendored
Normal file
241
modules/openapi-generator/src/main/resources/python-pydantic-v1/asyncio/rest.mustache
vendored
Normal file
@ -0,0 +1,241 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
import ssl
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
|
from urllib.parse import urlencode, quote_plus
|
||||||
|
|
||||||
|
from {{packageName}}.exceptions import ApiException, ApiValueError
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
|
def __init__(self, resp, data) -> None:
|
||||||
|
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:
|
||||||
|
|
||||||
|
def __init__(self, configuration, pools_size=4, maxsize=None) -> None:
|
||||||
|
|
||||||
|
# maxsize is number of requests to host that are allowed in parallel
|
||||||
|
if maxsize is None:
|
||||||
|
maxsize = configuration.connection_pool_maxsize
|
||||||
|
|
||||||
|
ssl_context = ssl.create_default_context(cafile=configuration.ssl_ca_cert)
|
||||||
|
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,
|
||||||
|
trust_env=True
|
||||||
|
)
|
||||||
|
|
||||||
|
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 {}
|
||||||
|
# url already contains the URL query string
|
||||||
|
# so reset query_params to empty dict
|
||||||
|
query_params = {}
|
||||||
|
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_request(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_request(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_request(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_request(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_request(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_request(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_request(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))
|
85
modules/openapi-generator/src/main/resources/python-pydantic-v1/common_README.mustache
vendored
Normal file
85
modules/openapi-generator/src/main/resources/python-pydantic-v1/common_README.mustache
vendored
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
```python
|
||||||
|
{{#apiInfo}}{{#apis}}{{#-last}}{{#hasHttpSignatureMethods}}import datetime{{/hasHttpSignatureMethods}}{{/-last}}{{/apis}}{{/apiInfo}}
|
||||||
|
import time
|
||||||
|
import {{{packageName}}}
|
||||||
|
from {{{packageName}}}.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
|
||||||
|
{{> python_doc_auth_partial}}
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
{{#asyncio}}async {{/asyncio}}with {{{packageName}}}.ApiClient(configuration) as api_client:
|
||||||
|
# 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}}{{#asyncio}}await {{/asyncio}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||||
|
{{#returnType}}
|
||||||
|
print("The response of {{classname}}->{{operationId}}:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
{{/returnType}}
|
||||||
|
except ApiException as e:
|
||||||
|
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
|
||||||
|
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Documentation for API Endpoints
|
||||||
|
|
||||||
|
All URIs are relative to *{{{basePath}}}*
|
||||||
|
|
||||||
|
Class | Method | HTTP request | Description
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{summary}}
|
||||||
|
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
|
||||||
|
|
||||||
|
## Documentation For Models
|
||||||
|
|
||||||
|
{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md)
|
||||||
|
{{/model}}{{/models}}
|
||||||
|
|
||||||
|
<a id="documentation-for-authorization"></a>
|
||||||
|
## Documentation For Authorization
|
||||||
|
|
||||||
|
{{^authMethods}}Endpoints do not require authorization.{{/authMethods}}
|
||||||
|
{{#hasAuthMethods}}Authentication schemes defined for the API:{{/hasAuthMethods}}
|
||||||
|
{{#authMethods}}
|
||||||
|
<a id="{{name}}"></a>
|
||||||
|
### {{{name}}}
|
||||||
|
|
||||||
|
{{#isApiKey}}
|
||||||
|
- **Type**: API key
|
||||||
|
- **API key parameter name**: {{{keyParamName}}}
|
||||||
|
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
|
||||||
|
{{/isApiKey}}
|
||||||
|
{{#isBasic}}
|
||||||
|
{{#isBasicBasic}}
|
||||||
|
- **Type**: HTTP basic authentication
|
||||||
|
{{/isBasicBasic}}
|
||||||
|
{{#isBasicBearer}}
|
||||||
|
- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
|
||||||
|
{{/isBasicBearer}}
|
||||||
|
{{#isHttpSignature}}
|
||||||
|
- **Type**: HTTP signature authentication
|
||||||
|
{{/isHttpSignature}}
|
||||||
|
{{/isBasic}}
|
||||||
|
{{#isOAuth}}
|
||||||
|
- **Type**: OAuth
|
||||||
|
- **Flow**: {{{flow}}}
|
||||||
|
- **Authorization URL**: {{{authorizationUrl}}}
|
||||||
|
- **Scopes**: {{^scopes}}N/A{{/scopes}}
|
||||||
|
{{#scopes}} - **{{{scope}}}**: {{{description}}}
|
||||||
|
{{/scopes}}
|
||||||
|
{{/isOAuth}}
|
||||||
|
|
||||||
|
{{/authMethods}}
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
{{#apiInfo}}{{#apis}}{{#-last}}{{infoEmail}}
|
||||||
|
{{/-last}}{{/apis}}{{/apiInfo}}
|
615
modules/openapi-generator/src/main/resources/python-pydantic-v1/configuration.mustache
vendored
Normal file
615
modules/openapi-generator/src/main/resources/python-pydantic-v1/configuration.mustache
vendored
Normal file
@ -0,0 +1,615 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
import copy
|
||||||
|
import logging
|
||||||
|
{{^asyncio}}
|
||||||
|
import multiprocessing
|
||||||
|
{{/asyncio}}
|
||||||
|
import sys
|
||||||
|
import urllib3
|
||||||
|
|
||||||
|
import http.client as httplib
|
||||||
|
|
||||||
|
JSON_SCHEMA_VALIDATION_KEYWORDS = {
|
||||||
|
'multipleOf', 'maximum', 'exclusiveMaximum',
|
||||||
|
'minimum', 'exclusiveMinimum', 'maxLength',
|
||||||
|
'minLength', 'pattern', 'maxItems', 'minItems'
|
||||||
|
}
|
||||||
|
|
||||||
|
class Configuration:
|
||||||
|
"""This class contains various settings of the API client.
|
||||||
|
|
||||||
|
:param host: Base url.
|
||||||
|
:param api_key: Dict to store API key(s).
|
||||||
|
Each entry in the dict specifies an API key.
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is the API key secret.
|
||||||
|
:param api_key_prefix: Dict to store API prefix (e.g. Bearer).
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is an API key prefix when generating the auth data.
|
||||||
|
:param username: Username for HTTP basic authentication.
|
||||||
|
:param password: Password for HTTP basic authentication.
|
||||||
|
:param access_token: Access token.
|
||||||
|
{{#hasHttpSignatureMethods}}
|
||||||
|
:param signing_info: Configuration parameters for the HTTP signature security scheme.
|
||||||
|
Must be an instance of {{{packageName}}}.signing.HttpSigningConfiguration
|
||||||
|
{{/hasHttpSignatureMethods}}
|
||||||
|
:param server_index: Index to servers configuration.
|
||||||
|
:param server_variables: Mapping with string values to replace variables in
|
||||||
|
templated server configuration. The validation of enums is performed for
|
||||||
|
variables with defined enum values before.
|
||||||
|
:param server_operation_index: Mapping from operation ID to an index to server
|
||||||
|
configuration.
|
||||||
|
:param server_operation_variables: Mapping from operation ID to a mapping with
|
||||||
|
string values to replace variables in templated server configuration.
|
||||||
|
The validation of enums is performed for variables with defined enum
|
||||||
|
values before.
|
||||||
|
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
||||||
|
in PEM format.
|
||||||
|
|
||||||
|
{{#hasAuthMethods}}
|
||||||
|
:Example:
|
||||||
|
{{#hasApiKeyMethods}}
|
||||||
|
|
||||||
|
API Key Authentication Example.
|
||||||
|
Given the following security scheme in the OpenAPI specification:
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
cookieAuth: # name for the security scheme
|
||||||
|
type: apiKey
|
||||||
|
in: cookie
|
||||||
|
name: JSESSIONID # cookie name
|
||||||
|
|
||||||
|
You can programmatically set the cookie:
|
||||||
|
|
||||||
|
conf = {{{packageName}}}.Configuration(
|
||||||
|
api_key={'cookieAuth': 'abc123'}
|
||||||
|
api_key_prefix={'cookieAuth': 'JSESSIONID'}
|
||||||
|
)
|
||||||
|
|
||||||
|
The following cookie will be added to the HTTP request:
|
||||||
|
Cookie: JSESSIONID abc123
|
||||||
|
{{/hasApiKeyMethods}}
|
||||||
|
{{#hasHttpBasicMethods}}
|
||||||
|
|
||||||
|
HTTP Basic Authentication Example.
|
||||||
|
Given the following security scheme in the OpenAPI specification:
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
http_basic_auth:
|
||||||
|
type: http
|
||||||
|
scheme: basic
|
||||||
|
|
||||||
|
Configure API client with HTTP basic authentication:
|
||||||
|
|
||||||
|
conf = {{{packageName}}}.Configuration(
|
||||||
|
username='the-user',
|
||||||
|
password='the-password',
|
||||||
|
)
|
||||||
|
|
||||||
|
{{/hasHttpBasicMethods}}
|
||||||
|
{{#hasHttpSignatureMethods}}
|
||||||
|
|
||||||
|
HTTP Signature Authentication Example.
|
||||||
|
Given the following security scheme in the OpenAPI specification:
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
http_basic_auth:
|
||||||
|
type: http
|
||||||
|
scheme: signature
|
||||||
|
|
||||||
|
Configure API client with HTTP signature authentication. Use the 'hs2019' signature scheme,
|
||||||
|
sign the HTTP requests with the RSA-SSA-PSS signature algorithm, and set the expiration time
|
||||||
|
of the signature to 5 minutes after the signature has been created.
|
||||||
|
Note you can use the constants defined in the {{{packageName}}}.signing module, and you can
|
||||||
|
also specify arbitrary HTTP headers to be included in the HTTP signature, except for the
|
||||||
|
'Authorization' header, which is used to carry the signature.
|
||||||
|
|
||||||
|
One may be tempted to sign all headers by default, but in practice it rarely works.
|
||||||
|
This is because explicit proxies, transparent proxies, TLS termination endpoints or
|
||||||
|
load balancers may add/modify/remove headers. Include the HTTP headers that you know
|
||||||
|
are not going to be modified in transit.
|
||||||
|
|
||||||
|
conf = {{{packageName}}}.Configuration(
|
||||||
|
signing_info = {{{packageName}}}.signing.HttpSigningConfiguration(
|
||||||
|
key_id = 'my-key-id',
|
||||||
|
private_key_path = 'rsa.pem',
|
||||||
|
signing_scheme = {{{packageName}}}.signing.SCHEME_HS2019,
|
||||||
|
signing_algorithm = {{{packageName}}}.signing.ALGORITHM_RSASSA_PSS,
|
||||||
|
signed_headers = [{{{packageName}}}.signing.HEADER_REQUEST_TARGET,
|
||||||
|
{{{packageName}}}.signing.HEADER_CREATED,
|
||||||
|
{{{packageName}}}.signing.HEADER_EXPIRES,
|
||||||
|
{{{packageName}}}.signing.HEADER_HOST,
|
||||||
|
{{{packageName}}}.signing.HEADER_DATE,
|
||||||
|
{{{packageName}}}.signing.HEADER_DIGEST,
|
||||||
|
'Content-Type',
|
||||||
|
'User-Agent'
|
||||||
|
],
|
||||||
|
signature_max_validity = datetime.timedelta(minutes=5)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{{/hasHttpSignatureMethods}}
|
||||||
|
{{/hasAuthMethods}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
_default = None
|
||||||
|
|
||||||
|
def __init__(self, host=None,
|
||||||
|
api_key=None, api_key_prefix=None,
|
||||||
|
username=None, password=None,
|
||||||
|
access_token=None,
|
||||||
|
{{#hasHttpSignatureMethods}}
|
||||||
|
signing_info=None,
|
||||||
|
{{/hasHttpSignatureMethods}}
|
||||||
|
server_index=None, server_variables=None,
|
||||||
|
server_operation_index=None, server_operation_variables=None,
|
||||||
|
ssl_ca_cert=None,
|
||||||
|
) -> None:
|
||||||
|
"""Constructor
|
||||||
|
"""
|
||||||
|
self._base_path = "{{{basePath}}}" if host is None else host
|
||||||
|
"""Default Base url
|
||||||
|
"""
|
||||||
|
self.server_index = 0 if server_index is None and host is None else server_index
|
||||||
|
self.server_operation_index = server_operation_index or {}
|
||||||
|
"""Default server index
|
||||||
|
"""
|
||||||
|
self.server_variables = server_variables or {}
|
||||||
|
self.server_operation_variables = server_operation_variables or {}
|
||||||
|
"""Default server variables
|
||||||
|
"""
|
||||||
|
self.temp_folder_path = None
|
||||||
|
"""Temp file folder for downloading files
|
||||||
|
"""
|
||||||
|
# Authentication Settings
|
||||||
|
self.api_key = {}
|
||||||
|
if api_key:
|
||||||
|
self.api_key = api_key
|
||||||
|
"""dict to store API key(s)
|
||||||
|
"""
|
||||||
|
self.api_key_prefix = {}
|
||||||
|
if api_key_prefix:
|
||||||
|
self.api_key_prefix = api_key_prefix
|
||||||
|
"""dict to store API prefix (e.g. Bearer)
|
||||||
|
"""
|
||||||
|
self.refresh_api_key_hook = None
|
||||||
|
"""function hook to refresh API key if expired
|
||||||
|
"""
|
||||||
|
self.username = username
|
||||||
|
"""Username for HTTP basic authentication
|
||||||
|
"""
|
||||||
|
self.password = password
|
||||||
|
"""Password for HTTP basic authentication
|
||||||
|
"""
|
||||||
|
self.access_token = access_token
|
||||||
|
"""Access token
|
||||||
|
"""
|
||||||
|
{{#hasHttpSignatureMethods}}
|
||||||
|
if signing_info is not None:
|
||||||
|
signing_info.host = host
|
||||||
|
self.signing_info = signing_info
|
||||||
|
"""The HTTP signing configuration
|
||||||
|
"""
|
||||||
|
{{/hasHttpSignatureMethods}}
|
||||||
|
self.logger = {}
|
||||||
|
"""Logging Settings
|
||||||
|
"""
|
||||||
|
self.logger["package_logger"] = logging.getLogger("{{packageName}}")
|
||||||
|
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
|
||||||
|
self.logger_format = '%(asctime)s %(levelname)s %(message)s'
|
||||||
|
"""Log format
|
||||||
|
"""
|
||||||
|
self.logger_stream_handler = None
|
||||||
|
"""Log stream handler
|
||||||
|
"""
|
||||||
|
self.logger_file_handler = None
|
||||||
|
"""Log file handler
|
||||||
|
"""
|
||||||
|
self.logger_file = None
|
||||||
|
"""Debug file location
|
||||||
|
"""
|
||||||
|
self.debug = False
|
||||||
|
"""Debug switch
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.verify_ssl = True
|
||||||
|
"""SSL/TLS verification
|
||||||
|
Set this to false to skip verifying SSL certificate when calling API
|
||||||
|
from https server.
|
||||||
|
"""
|
||||||
|
self.ssl_ca_cert = ssl_ca_cert
|
||||||
|
"""Set this to customize the certificate file to verify the peer.
|
||||||
|
"""
|
||||||
|
self.cert_file = None
|
||||||
|
"""client certificate file
|
||||||
|
"""
|
||||||
|
self.key_file = None
|
||||||
|
"""client key file
|
||||||
|
"""
|
||||||
|
self.assert_hostname = None
|
||||||
|
"""Set this to True/False to enable/disable SSL hostname verification.
|
||||||
|
"""
|
||||||
|
self.tls_server_name = None
|
||||||
|
"""SSL/TLS Server Name Indication (SNI)
|
||||||
|
Set this to the SNI value expected by the server.
|
||||||
|
"""
|
||||||
|
|
||||||
|
{{#asyncio}}
|
||||||
|
self.connection_pool_maxsize = 100
|
||||||
|
"""This value is passed to the aiohttp to limit simultaneous connections.
|
||||||
|
Default values is 100, None means no-limit.
|
||||||
|
"""
|
||||||
|
{{/asyncio}}
|
||||||
|
{{^asyncio}}
|
||||||
|
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
|
||||||
|
"""urllib3 connection pool's maximum number of connections saved
|
||||||
|
per pool. urllib3 uses 1 connection as default value, but this is
|
||||||
|
not the best value when you are making a lot of possibly parallel
|
||||||
|
requests to the same host, which is often the case here.
|
||||||
|
cpu_count * 5 is used as default value to increase performance.
|
||||||
|
"""
|
||||||
|
{{/asyncio}}
|
||||||
|
|
||||||
|
self.proxy = None
|
||||||
|
"""Proxy URL
|
||||||
|
"""
|
||||||
|
self.proxy_headers = None
|
||||||
|
"""Proxy headers
|
||||||
|
"""
|
||||||
|
self.safe_chars_for_path_param = ''
|
||||||
|
"""Safe chars for path_param
|
||||||
|
"""
|
||||||
|
self.retries = None
|
||||||
|
"""Adding retries to override urllib3 default value 3
|
||||||
|
"""
|
||||||
|
# Enable client side validation
|
||||||
|
self.client_side_validation = True
|
||||||
|
|
||||||
|
self.socket_options = None
|
||||||
|
"""Options to pass down to the underlying urllib3 socket
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.datetime_format = "{{{datetimeFormat}}}"
|
||||||
|
"""datetime format
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.date_format = "{{{dateFormat}}}"
|
||||||
|
"""date format
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __deepcopy__(self, memo):
|
||||||
|
cls = self.__class__
|
||||||
|
result = cls.__new__(cls)
|
||||||
|
memo[id(self)] = result
|
||||||
|
for k, v in self.__dict__.items():
|
||||||
|
if k not in ('logger', 'logger_file_handler'):
|
||||||
|
setattr(result, k, copy.deepcopy(v, memo))
|
||||||
|
# shallow copy of loggers
|
||||||
|
result.logger = copy.copy(self.logger)
|
||||||
|
# use setters to configure loggers
|
||||||
|
result.logger_file = self.logger_file
|
||||||
|
result.debug = self.debug
|
||||||
|
return result
|
||||||
|
|
||||||
|
def __setattr__(self, name, value):
|
||||||
|
object.__setattr__(self, name, value)
|
||||||
|
{{#hasHttpSignatureMethods}}
|
||||||
|
if name == "signing_info" and value is not None:
|
||||||
|
# Ensure the host parameter from signing info is the same as
|
||||||
|
# Configuration.host.
|
||||||
|
value.host = self.host
|
||||||
|
{{/hasHttpSignatureMethods}}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_default(cls, default):
|
||||||
|
"""Set default instance of configuration.
|
||||||
|
|
||||||
|
It stores default configuration, which can be
|
||||||
|
returned by get_default_copy method.
|
||||||
|
|
||||||
|
:param default: object of Configuration
|
||||||
|
"""
|
||||||
|
cls._default = default
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_default_copy(cls):
|
||||||
|
"""Deprecated. Please use `get_default` instead.
|
||||||
|
|
||||||
|
Deprecated. Please use `get_default` instead.
|
||||||
|
|
||||||
|
:return: The configuration object.
|
||||||
|
"""
|
||||||
|
return cls.get_default()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_default(cls):
|
||||||
|
"""Return the default configuration.
|
||||||
|
|
||||||
|
This method returns newly created, based on default constructor,
|
||||||
|
object of Configuration class or returns a copy of default
|
||||||
|
configuration.
|
||||||
|
|
||||||
|
:return: The configuration object.
|
||||||
|
"""
|
||||||
|
if cls._default is None:
|
||||||
|
cls._default = Configuration()
|
||||||
|
return cls._default
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logger_file(self):
|
||||||
|
"""The logger file.
|
||||||
|
|
||||||
|
If the logger_file is None, then add stream handler and remove file
|
||||||
|
handler. Otherwise, add file handler and remove stream handler.
|
||||||
|
|
||||||
|
:param value: The logger_file path.
|
||||||
|
:type: str
|
||||||
|
"""
|
||||||
|
return self.__logger_file
|
||||||
|
|
||||||
|
@logger_file.setter
|
||||||
|
def logger_file(self, value):
|
||||||
|
"""The logger file.
|
||||||
|
|
||||||
|
If the logger_file is None, then add stream handler and remove file
|
||||||
|
handler. Otherwise, add file handler and remove stream handler.
|
||||||
|
|
||||||
|
:param value: The logger_file path.
|
||||||
|
:type: str
|
||||||
|
"""
|
||||||
|
self.__logger_file = value
|
||||||
|
if self.__logger_file:
|
||||||
|
# If set logging file,
|
||||||
|
# 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():
|
||||||
|
logger.addHandler(self.logger_file_handler)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def debug(self):
|
||||||
|
"""Debug status
|
||||||
|
|
||||||
|
:param value: The debug status, True or False.
|
||||||
|
:type: bool
|
||||||
|
"""
|
||||||
|
return self.__debug
|
||||||
|
|
||||||
|
@debug.setter
|
||||||
|
def debug(self, value):
|
||||||
|
"""Debug status
|
||||||
|
|
||||||
|
:param value: The debug status, True or False.
|
||||||
|
:type: bool
|
||||||
|
"""
|
||||||
|
self.__debug = value
|
||||||
|
if self.__debug:
|
||||||
|
# if debug status is True, turn on debug logging
|
||||||
|
for _, logger in self.logger.items():
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
# 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():
|
||||||
|
logger.setLevel(logging.WARNING)
|
||||||
|
# turn off httplib debug
|
||||||
|
httplib.HTTPConnection.debuglevel = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logger_format(self):
|
||||||
|
"""The logger format.
|
||||||
|
|
||||||
|
The logger_formatter will be updated when sets logger_format.
|
||||||
|
|
||||||
|
:param value: The format string.
|
||||||
|
:type: str
|
||||||
|
"""
|
||||||
|
return self.__logger_format
|
||||||
|
|
||||||
|
@logger_format.setter
|
||||||
|
def logger_format(self, value):
|
||||||
|
"""The logger format.
|
||||||
|
|
||||||
|
The logger_formatter will be updated when sets logger_format.
|
||||||
|
|
||||||
|
:param value: The format string.
|
||||||
|
:type: str
|
||||||
|
"""
|
||||||
|
self.__logger_format = value
|
||||||
|
self.logger_formatter = logging.Formatter(self.__logger_format)
|
||||||
|
|
||||||
|
def get_api_key_with_prefix(self, identifier, alias=None):
|
||||||
|
"""Gets API key (with prefix if set).
|
||||||
|
|
||||||
|
:param identifier: The identifier of apiKey.
|
||||||
|
:param alias: The alternative identifier of apiKey.
|
||||||
|
:return: The token for api key authentication.
|
||||||
|
"""
|
||||||
|
if self.refresh_api_key_hook is not None:
|
||||||
|
self.refresh_api_key_hook(self)
|
||||||
|
key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
|
||||||
|
if key:
|
||||||
|
prefix = self.api_key_prefix.get(identifier)
|
||||||
|
if prefix:
|
||||||
|
return "%s %s" % (prefix, key)
|
||||||
|
else:
|
||||||
|
return key
|
||||||
|
|
||||||
|
def get_basic_auth_token(self):
|
||||||
|
"""Gets HTTP basic authentication header (string).
|
||||||
|
|
||||||
|
:return: The token for basic HTTP authentication.
|
||||||
|
"""
|
||||||
|
username = ""
|
||||||
|
if self.username is not None:
|
||||||
|
username = self.username
|
||||||
|
password = ""
|
||||||
|
if self.password is not None:
|
||||||
|
password = self.password
|
||||||
|
return urllib3.util.make_headers(
|
||||||
|
basic_auth=username + ':' + password
|
||||||
|
).get('authorization')
|
||||||
|
|
||||||
|
def auth_settings(self):
|
||||||
|
"""Gets Auth Settings dict for api client.
|
||||||
|
|
||||||
|
:return: The Auth Settings information dict.
|
||||||
|
"""
|
||||||
|
auth = {}
|
||||||
|
{{#authMethods}}
|
||||||
|
{{#isApiKey}}
|
||||||
|
if '{{name}}' in self.api_key{{#vendorExtensions.x-auth-id-alias}} or '{{.}}' in self.api_key{{/vendorExtensions.x-auth-id-alias}}:
|
||||||
|
auth['{{name}}'] = {
|
||||||
|
'type': 'api_key',
|
||||||
|
'in': {{#isKeyInCookie}}'cookie'{{/isKeyInCookie}}{{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}},
|
||||||
|
'key': '{{keyParamName}}',
|
||||||
|
'value': self.get_api_key_with_prefix(
|
||||||
|
'{{name}}',{{#vendorExtensions.x-auth-id-alias}}
|
||||||
|
alias='{{.}}',{{/vendorExtensions.x-auth-id-alias}}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
{{/isApiKey}}
|
||||||
|
{{#isBasic}}
|
||||||
|
{{#isBasicBasic}}
|
||||||
|
if self.username is not None and self.password is not None:
|
||||||
|
auth['{{name}}'] = {
|
||||||
|
'type': 'basic',
|
||||||
|
'in': 'header',
|
||||||
|
'key': 'Authorization',
|
||||||
|
'value': self.get_basic_auth_token()
|
||||||
|
}
|
||||||
|
{{/isBasicBasic}}
|
||||||
|
{{#isBasicBearer}}
|
||||||
|
if self.access_token is not None:
|
||||||
|
auth['{{name}}'] = {
|
||||||
|
'type': 'bearer',
|
||||||
|
'in': 'header',
|
||||||
|
{{#bearerFormat}}
|
||||||
|
'format': '{{{.}}}',
|
||||||
|
{{/bearerFormat}}
|
||||||
|
'key': 'Authorization',
|
||||||
|
'value': 'Bearer ' + self.access_token
|
||||||
|
}
|
||||||
|
{{/isBasicBearer}}
|
||||||
|
{{#isHttpSignature}}
|
||||||
|
if self.signing_info is not None:
|
||||||
|
auth['{{name}}'] = {
|
||||||
|
'type': 'http-signature',
|
||||||
|
'in': 'header',
|
||||||
|
'key': 'Authorization',
|
||||||
|
'value': None # Signature headers are calculated for every HTTP request
|
||||||
|
}
|
||||||
|
{{/isHttpSignature}}
|
||||||
|
{{/isBasic}}
|
||||||
|
{{#isOAuth}}
|
||||||
|
if self.access_token is not None:
|
||||||
|
auth['{{name}}'] = {
|
||||||
|
'type': 'oauth2',
|
||||||
|
'in': 'header',
|
||||||
|
'key': 'Authorization',
|
||||||
|
'value': 'Bearer ' + self.access_token
|
||||||
|
}
|
||||||
|
{{/isOAuth}}
|
||||||
|
{{/authMethods}}
|
||||||
|
return auth
|
||||||
|
|
||||||
|
def to_debug_report(self):
|
||||||
|
"""Gets the essential information for debugging.
|
||||||
|
|
||||||
|
:return: The report for debugging.
|
||||||
|
"""
|
||||||
|
return "Python SDK Debug Report:\n"\
|
||||||
|
"OS: {env}\n"\
|
||||||
|
"Python Version: {pyversion}\n"\
|
||||||
|
"Version of the API: {{version}}\n"\
|
||||||
|
"SDK Package Version: {{packageVersion}}".\
|
||||||
|
format(env=sys.platform, pyversion=sys.version)
|
||||||
|
|
||||||
|
def get_host_settings(self):
|
||||||
|
"""Gets an array of host settings
|
||||||
|
|
||||||
|
:return: An array of host settings
|
||||||
|
"""
|
||||||
|
return [
|
||||||
|
{{#servers}}
|
||||||
|
{
|
||||||
|
'url': "{{{url}}}",
|
||||||
|
'description': "{{{description}}}{{^description}}No description provided{{/description}}",
|
||||||
|
{{#variables}}
|
||||||
|
{{#-first}}
|
||||||
|
'variables': {
|
||||||
|
{{/-first}}
|
||||||
|
'{{{name}}}': {
|
||||||
|
'description': "{{{description}}}{{^description}}No description provided{{/description}}",
|
||||||
|
'default_value': "{{{defaultValue}}}",
|
||||||
|
{{#enumValues}}
|
||||||
|
{{#-first}}
|
||||||
|
'enum_values': [
|
||||||
|
{{/-first}}
|
||||||
|
"{{{.}}}"{{^-last}},{{/-last}}
|
||||||
|
{{#-last}}
|
||||||
|
]
|
||||||
|
{{/-last}}
|
||||||
|
{{/enumValues}}
|
||||||
|
}{{^-last}},{{/-last}}
|
||||||
|
{{#-last}}
|
||||||
|
}
|
||||||
|
{{/-last}}
|
||||||
|
{{/variables}}
|
||||||
|
}{{^-last}},{{/-last}}
|
||||||
|
{{/servers}}
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_host_from_settings(self, index, variables=None, servers=None):
|
||||||
|
"""Gets host URL based on the index and variables
|
||||||
|
:param index: array index of the host settings
|
||||||
|
:param variables: hash of variable and the corresponding value
|
||||||
|
:param servers: an array of host settings or None
|
||||||
|
:return: URL based on host settings
|
||||||
|
"""
|
||||||
|
if index is None:
|
||||||
|
return self._base_path
|
||||||
|
|
||||||
|
variables = {} if variables is None else variables
|
||||||
|
servers = self.get_host_settings() if servers is None else servers
|
||||||
|
|
||||||
|
try:
|
||||||
|
server = servers[index]
|
||||||
|
except IndexError:
|
||||||
|
raise ValueError(
|
||||||
|
"Invalid index {0} when selecting the host settings. "
|
||||||
|
"Must be less than {1}".format(index, len(servers)))
|
||||||
|
|
||||||
|
url = server['url']
|
||||||
|
|
||||||
|
# go through variables and replace placeholders
|
||||||
|
for variable_name, variable in server.get('variables', {}).items():
|
||||||
|
used_value = variables.get(
|
||||||
|
variable_name, variable['default_value'])
|
||||||
|
|
||||||
|
if 'enum_values' in variable \
|
||||||
|
and used_value not in variable['enum_values']:
|
||||||
|
raise ValueError(
|
||||||
|
"The variable `{0}` in the host URL has invalid value "
|
||||||
|
"{1}. Must be {2}.".format(
|
||||||
|
variable_name, variables[variable_name],
|
||||||
|
variable['enum_values']))
|
||||||
|
|
||||||
|
url = url.replace("{" + variable_name + "}", used_value)
|
||||||
|
|
||||||
|
return url
|
||||||
|
|
||||||
|
@property
|
||||||
|
def host(self):
|
||||||
|
"""Return generated host."""
|
||||||
|
return self.get_host_from_settings(self.server_index, variables=self.server_variables)
|
||||||
|
|
||||||
|
@host.setter
|
||||||
|
def host(self, value):
|
||||||
|
"""Fix base path."""
|
||||||
|
self._base_path = value
|
||||||
|
self.server_index = None
|
156
modules/openapi-generator/src/main/resources/python-pydantic-v1/exceptions.mustache
vendored
Normal file
156
modules/openapi-generator/src/main/resources/python-pydantic-v1/exceptions.mustache
vendored
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
class OpenApiException(Exception):
|
||||||
|
"""The base exception class for all OpenAPIExceptions"""
|
||||||
|
|
||||||
|
|
||||||
|
class ApiTypeError(OpenApiException, TypeError):
|
||||||
|
def __init__(self, msg, path_to_item=None, valid_classes=None,
|
||||||
|
key_type=None) -> None:
|
||||||
|
""" Raises an exception for TypeErrors
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): the exception message
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
path_to_item (list): a list of keys an indices to get to the
|
||||||
|
current_item
|
||||||
|
None if unset
|
||||||
|
valid_classes (tuple): the primitive classes that current item
|
||||||
|
should be an instance of
|
||||||
|
None if unset
|
||||||
|
key_type (bool): False if our value is a value in a dict
|
||||||
|
True if it is a key in a dict
|
||||||
|
False if our item is an item in a list
|
||||||
|
None if unset
|
||||||
|
"""
|
||||||
|
self.path_to_item = path_to_item
|
||||||
|
self.valid_classes = valid_classes
|
||||||
|
self.key_type = key_type
|
||||||
|
full_msg = msg
|
||||||
|
if path_to_item:
|
||||||
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||||
|
super(ApiTypeError, self).__init__(full_msg)
|
||||||
|
|
||||||
|
|
||||||
|
class ApiValueError(OpenApiException, ValueError):
|
||||||
|
def __init__(self, msg, path_to_item=None) -> None:
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
msg (str): the exception message
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
path_to_item (list) the path to the exception in the
|
||||||
|
received_data dict. None if unset
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.path_to_item = path_to_item
|
||||||
|
full_msg = msg
|
||||||
|
if path_to_item:
|
||||||
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||||
|
super(ApiValueError, self).__init__(full_msg)
|
||||||
|
|
||||||
|
|
||||||
|
class ApiAttributeError(OpenApiException, AttributeError):
|
||||||
|
def __init__(self, msg, path_to_item=None) -> None:
|
||||||
|
"""
|
||||||
|
Raised when an attribute reference or assignment fails.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): the exception message
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
path_to_item (None/list) the path to the exception in the
|
||||||
|
received_data dict
|
||||||
|
"""
|
||||||
|
self.path_to_item = path_to_item
|
||||||
|
full_msg = msg
|
||||||
|
if path_to_item:
|
||||||
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||||
|
super(ApiAttributeError, self).__init__(full_msg)
|
||||||
|
|
||||||
|
|
||||||
|
class ApiKeyError(OpenApiException, KeyError):
|
||||||
|
def __init__(self, msg, path_to_item=None) -> None:
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
msg (str): the exception message
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
path_to_item (None/list) the path to the exception in the
|
||||||
|
received_data dict
|
||||||
|
"""
|
||||||
|
self.path_to_item = path_to_item
|
||||||
|
full_msg = msg
|
||||||
|
if path_to_item:
|
||||||
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||||
|
super(ApiKeyError, self).__init__(full_msg)
|
||||||
|
|
||||||
|
|
||||||
|
class ApiException(OpenApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> None:
|
||||||
|
if http_resp:
|
||||||
|
self.status = http_resp.status
|
||||||
|
self.reason = http_resp.reason
|
||||||
|
self.body = http_resp.data
|
||||||
|
self.headers = http_resp.getheaders()
|
||||||
|
else:
|
||||||
|
self.status = status
|
||||||
|
self.reason = reason
|
||||||
|
self.body = None
|
||||||
|
self.headers = None
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""Custom error messages for exception"""
|
||||||
|
error_message = "({0})\n"\
|
||||||
|
"Reason: {1}\n".format(self.status, self.reason)
|
||||||
|
if self.headers:
|
||||||
|
error_message += "HTTP response headers: {0}\n".format(
|
||||||
|
self.headers)
|
||||||
|
|
||||||
|
if self.body:
|
||||||
|
error_message += "HTTP response body: {0}\n".format(self.body)
|
||||||
|
|
||||||
|
return error_message
|
||||||
|
|
||||||
|
class BadRequestException(ApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> None:
|
||||||
|
super(BadRequestException, self).__init__(status, reason, http_resp)
|
||||||
|
|
||||||
|
class NotFoundException(ApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> None:
|
||||||
|
super(NotFoundException, self).__init__(status, reason, http_resp)
|
||||||
|
|
||||||
|
|
||||||
|
class UnauthorizedException(ApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> None:
|
||||||
|
super(UnauthorizedException, self).__init__(status, reason, http_resp)
|
||||||
|
|
||||||
|
|
||||||
|
class ForbiddenException(ApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> None:
|
||||||
|
super(ForbiddenException, self).__init__(status, reason, http_resp)
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceException(ApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> 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):
|
||||||
|
result += "[{0}]".format(pth)
|
||||||
|
else:
|
||||||
|
result += "['{0}']".format(pth)
|
||||||
|
return result
|
57
modules/openapi-generator/src/main/resources/python-pydantic-v1/git_push.sh.mustache
vendored
Executable file
57
modules/openapi-generator/src/main/resources/python-pydantic-v1/git_push.sh.mustache
vendored
Executable file
@ -0,0 +1,57 @@
|
|||||||
|
#!/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-petstore-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'
|
39
modules/openapi-generator/src/main/resources/python-pydantic-v1/github-workflow.mustache
vendored
Normal file
39
modules/openapi-generator/src/main/resources/python-pydantic-v1/github-workflow.mustache
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# NOTE: This file is auto generated by OpenAPI Generator.
|
||||||
|
# URL: https://openapi-generator.tech
|
||||||
|
#
|
||||||
|
# ref: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
||||||
|
|
||||||
|
name: {{packageName}} Python package
|
||||||
|
{{=<% %>=}}
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install flake8 pytest
|
||||||
|
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||||
|
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
|
||||||
|
- name: Lint with flake8
|
||||||
|
run: |
|
||||||
|
# stop the build if there are Python syntax errors or undefined names
|
||||||
|
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||||
|
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||||
|
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||||
|
- name: Test with pytest
|
||||||
|
run: |
|
||||||
|
pytest
|
66
modules/openapi-generator/src/main/resources/python-pydantic-v1/gitignore.mustache
vendored
Normal file
66
modules/openapi-generator/src/main/resources/python-pydantic-v1/gitignore.mustache
vendored
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
env/
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*,cover
|
||||||
|
.hypothesis/
|
||||||
|
venv/
|
||||||
|
.venv/
|
||||||
|
.python-version
|
||||||
|
.pytest_cache
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
#Ipython Notebook
|
||||||
|
.ipynb_checkpoints
|
31
modules/openapi-generator/src/main/resources/python-pydantic-v1/gitlab-ci.mustache
vendored
Normal file
31
modules/openapi-generator/src/main/resources/python-pydantic-v1/gitlab-ci.mustache
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# NOTE: This file is auto generated by OpenAPI Generator.
|
||||||
|
# URL: https://openapi-generator.tech
|
||||||
|
#
|
||||||
|
# ref: https://docs.gitlab.com/ee/ci/README.html
|
||||||
|
# ref: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- test
|
||||||
|
|
||||||
|
.pytest:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- pip install -r requirements.txt
|
||||||
|
- pip install -r test-requirements.txt
|
||||||
|
- pytest --cov={{{packageName}}}
|
||||||
|
|
||||||
|
pytest-3.7:
|
||||||
|
extends: .pytest
|
||||||
|
image: python:3.7-alpine
|
||||||
|
pytest-3.8:
|
||||||
|
extends: .pytest
|
||||||
|
image: python:3.8-alpine
|
||||||
|
pytest-3.9:
|
||||||
|
extends: .pytest
|
||||||
|
image: python:3.9-alpine
|
||||||
|
pytest-3.10:
|
||||||
|
extends: .pytest
|
||||||
|
image: python:3.10-alpine
|
||||||
|
pytest-3.11:
|
||||||
|
extends: .pytest
|
||||||
|
image: python:3.11-alpine
|
14
modules/openapi-generator/src/main/resources/python-pydantic-v1/model.mustache
vendored
Normal file
14
modules/openapi-generator/src/main/resources/python-pydantic-v1/model.mustache
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
{{#models}}
|
||||||
|
{{#model}}
|
||||||
|
{{#isEnum}}
|
||||||
|
{{>model_enum}}
|
||||||
|
{{/isEnum}}
|
||||||
|
{{^isEnum}}
|
||||||
|
{{#oneOf}}{{#-first}}{{>model_oneof}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#-first}}{{>model_anyof}}{{/-first}}{{/anyOf}}{{^anyOf}}{{>model_generic}}{{/anyOf}}{{/oneOf}}
|
||||||
|
{{/isEnum}}
|
||||||
|
{{/model}}
|
||||||
|
{{/models}}
|
180
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_anyof.mustache
vendored
Normal file
180
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_anyof.mustache
vendored
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
from inspect import getfullargspec
|
||||||
|
import json
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
{{#vendorExtensions.x-py-datetime-imports}}{{#-first}}from datetime import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-datetime-imports}}
|
||||||
|
{{#vendorExtensions.x-py-typing-imports}}{{#-first}}from typing import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-typing-imports}}
|
||||||
|
{{#vendorExtensions.x-py-pydantic-imports}}{{#-first}}from pydantic import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-pydantic-imports}}
|
||||||
|
{{#vendorExtensions.x-py-model-imports}}
|
||||||
|
{{{.}}}
|
||||||
|
{{/vendorExtensions.x-py-model-imports}}
|
||||||
|
from typing import Union, Any, List, TYPE_CHECKING
|
||||||
|
from pydantic import StrictStr, Field
|
||||||
|
|
||||||
|
{{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ANY_OF_SCHEMAS = [{{#anyOf}}"{{.}}"{{^-last}}, {{/-last}}{{/anyOf}}]
|
||||||
|
|
||||||
|
class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}):
|
||||||
|
"""
|
||||||
|
{{{description}}}{{^description}}{{{classname}}}{{/description}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
{{#composedSchemas.anyOf}}
|
||||||
|
# data type: {{{dataType}}}
|
||||||
|
{{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
|
||||||
|
{{/composedSchemas.anyOf}}
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
actual_instance: Union[{{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}]
|
||||||
|
else:
|
||||||
|
actual_instance: Any
|
||||||
|
any_of_schemas: List[str] = Field({{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ANY_OF_SCHEMAS, const=True)
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
validate_assignment = True
|
||||||
|
{{#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, *args, **kwargs) -> None:
|
||||||
|
if args:
|
||||||
|
if len(args) > 1:
|
||||||
|
raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
|
||||||
|
if kwargs:
|
||||||
|
raise ValueError("If a position argument is used, keyword arguments cannot be used.")
|
||||||
|
super().__init__(actual_instance=args[0])
|
||||||
|
else:
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
@validator('actual_instance')
|
||||||
|
def actual_instance_must_validate_anyof(cls, v):
|
||||||
|
{{#isNullable}}
|
||||||
|
if v is None:
|
||||||
|
return v
|
||||||
|
|
||||||
|
{{/isNullable}}
|
||||||
|
instance = {{{classname}}}.construct()
|
||||||
|
error_messages = []
|
||||||
|
{{#composedSchemas.anyOf}}
|
||||||
|
# validate data type: {{{dataType}}}
|
||||||
|
{{#isContainer}}
|
||||||
|
try:
|
||||||
|
instance.{{vendorExtensions.x-py-name}} = v
|
||||||
|
return v
|
||||||
|
except (ValidationError, ValueError) as e:
|
||||||
|
error_messages.append(str(e))
|
||||||
|
{{/isContainer}}
|
||||||
|
{{^isContainer}}
|
||||||
|
{{#isPrimitiveType}}
|
||||||
|
try:
|
||||||
|
instance.{{vendorExtensions.x-py-name}} = v
|
||||||
|
return v
|
||||||
|
except (ValidationError, ValueError) as e:
|
||||||
|
error_messages.append(str(e))
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{^isPrimitiveType}}
|
||||||
|
if not isinstance(v, {{{dataType}}}):
|
||||||
|
error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`")
|
||||||
|
else:
|
||||||
|
return v
|
||||||
|
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{/composedSchemas.anyOf}}
|
||||||
|
if error_messages:
|
||||||
|
# no match
|
||||||
|
raise ValueError("No match found when setting the actual_instance in {{{classname}}} with anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: " + ", ".join(error_messages))
|
||||||
|
else:
|
||||||
|
return v
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> {{{classname}}}:
|
||||||
|
return cls.from_json(json.dumps(obj))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> {{{classname}}}:
|
||||||
|
"""Returns the object represented by the json string"""
|
||||||
|
instance = {{{classname}}}.construct()
|
||||||
|
{{#isNullable}}
|
||||||
|
if json_str is None:
|
||||||
|
return instance
|
||||||
|
|
||||||
|
{{/isNullable}}
|
||||||
|
error_messages = []
|
||||||
|
{{#composedSchemas.anyOf}}
|
||||||
|
{{#isContainer}}
|
||||||
|
# deserialize data into {{{dataType}}}
|
||||||
|
try:
|
||||||
|
# validation
|
||||||
|
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
|
||||||
|
# assign value to actual_instance
|
||||||
|
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
|
||||||
|
return instance
|
||||||
|
except (ValidationError, ValueError) as e:
|
||||||
|
error_messages.append(str(e))
|
||||||
|
{{/isContainer}}
|
||||||
|
{{^isContainer}}
|
||||||
|
{{#isPrimitiveType}}
|
||||||
|
# deserialize data into {{{dataType}}}
|
||||||
|
try:
|
||||||
|
# validation
|
||||||
|
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
|
||||||
|
# assign value to actual_instance
|
||||||
|
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
|
||||||
|
return instance
|
||||||
|
except (ValidationError, ValueError) as e:
|
||||||
|
error_messages.append(str(e))
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{^isPrimitiveType}}
|
||||||
|
# {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
|
||||||
|
try:
|
||||||
|
instance.actual_instance = {{{dataType}}}.from_json(json_str)
|
||||||
|
return instance
|
||||||
|
except (ValidationError, ValueError) as e:
|
||||||
|
error_messages.append(str(e))
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{/composedSchemas.anyOf}}
|
||||||
|
|
||||||
|
if error_messages:
|
||||||
|
# no match
|
||||||
|
raise ValueError("No match found when deserializing the JSON string into {{{classname}}} with anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: " + ", ".join(error_messages))
|
||||||
|
else:
|
||||||
|
return instance
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the actual instance"""
|
||||||
|
if self.actual_instance is None:
|
||||||
|
return "null"
|
||||||
|
|
||||||
|
to_json = getattr(self.actual_instance, "to_json", None)
|
||||||
|
if callable(to_json):
|
||||||
|
return self.actual_instance.to_json()
|
||||||
|
else:
|
||||||
|
return json.dumps(self.actual_instance)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
"""Returns the dict representation of the actual instance"""
|
||||||
|
if self.actual_instance is None:
|
||||||
|
return "null"
|
||||||
|
|
||||||
|
to_json = getattr(self.actual_instance, "to_json", None)
|
||||||
|
if callable(to_json):
|
||||||
|
return self.actual_instance.to_dict()
|
||||||
|
else:
|
||||||
|
return json.dumps(self.actual_instance)
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the actual instance"""
|
||||||
|
return pprint.pformat(self.dict())
|
||||||
|
|
||||||
|
{{#vendorExtensions.x-py-postponed-model-imports.size}}
|
||||||
|
{{#vendorExtensions.x-py-postponed-model-imports}}
|
||||||
|
{{{.}}}
|
||||||
|
{{/vendorExtensions.x-py-postponed-model-imports}}
|
||||||
|
{{classname}}.update_forward_refs()
|
||||||
|
{{/vendorExtensions.x-py-postponed-model-imports.size}}
|
33
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_doc.mustache
vendored
Normal file
33
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_doc.mustache
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{{#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}}
|
||||||
|
|
||||||
|
{{^isEnum}}
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from {{modelPackage}}.{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}} import {{classname}}
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of {{classname}} from a JSON string
|
||||||
|
{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_instance = {{classname}}.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print {{classname}}.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_dict = {{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_instance.to_dict()
|
||||||
|
# create an instance of {{classname}} from a dict
|
||||||
|
{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_form_dict = {{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}.from_dict({{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_dict)
|
||||||
|
```
|
||||||
|
{{/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)
|
||||||
|
|
||||||
|
{{/model}}{{/models}}
|
36
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_enum.mustache
vendored
Normal file
36
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_enum.mustache
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import json
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
from aenum import Enum, no_arg
|
||||||
|
{{#vendorExtensions.x-py-datetime-imports}}{{#-first}}from datetime import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-datetime-imports}}
|
||||||
|
{{#vendorExtensions.x-py-typing-imports}}{{#-first}}from typing import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-typing-imports}}
|
||||||
|
{{#vendorExtensions.x-py-pydantic-imports}}{{#-first}}from pydantic import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-pydantic-imports}}
|
||||||
|
|
||||||
|
|
||||||
|
class {{classname}}({{vendorExtensions.x-py-enum-type}}, Enum):
|
||||||
|
"""
|
||||||
|
{{{description}}}{{^description}}{{{classname}}}{{/description}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
allowed enum values
|
||||||
|
"""
|
||||||
|
{{#allowableValues}}
|
||||||
|
{{#enumVars}}
|
||||||
|
{{{name}}} = {{{value}}}
|
||||||
|
{{/enumVars}}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> {{{classname}}}:
|
||||||
|
"""Create an instance of {{classname}} from a JSON string"""
|
||||||
|
return {{classname}}(json.loads(json_str))
|
||||||
|
|
||||||
|
{{#defaultValue}}
|
||||||
|
|
||||||
|
#
|
||||||
|
@classmethod
|
||||||
|
def _missing_value_(cls, value):
|
||||||
|
if value is no_arg:
|
||||||
|
return cls.{{{.}}}
|
||||||
|
{{/defaultValue}}
|
||||||
|
{{/allowableValues}}
|
361
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache
vendored
Normal file
361
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache
vendored
Normal file
@ -0,0 +1,361 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
{{#vendorExtensions.x-py-datetime-imports}}{{#-first}}from datetime import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-datetime-imports}}
|
||||||
|
{{#vendorExtensions.x-py-typing-imports}}{{#-first}}from typing import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-typing-imports}}
|
||||||
|
{{#vendorExtensions.x-py-pydantic-imports}}{{#-first}}from pydantic import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-pydantic-imports}}
|
||||||
|
{{#vendorExtensions.x-py-model-imports}}
|
||||||
|
{{{.}}}
|
||||||
|
{{/vendorExtensions.x-py-model-imports}}
|
||||||
|
|
||||||
|
class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}):
|
||||||
|
"""
|
||||||
|
{{#description}}{{{description}}} # noqa: E501{{/description}}{{^description}}{{{classname}}}{{/description}}
|
||||||
|
"""
|
||||||
|
{{#vars}}
|
||||||
|
{{name}}: {{{vendorExtensions.x-py-typing}}}
|
||||||
|
{{/vars}}
|
||||||
|
{{#isAdditionalPropertiesTrue}}
|
||||||
|
additional_properties: Dict[str, Any] = {}
|
||||||
|
{{/isAdditionalPropertiesTrue}}
|
||||||
|
__properties = [{{#allVars}}"{{baseName}}"{{^-last}}, {{/-last}}{{/allVars}}]
|
||||||
|
{{#vars}}
|
||||||
|
{{#vendorExtensions.x-regex}}
|
||||||
|
|
||||||
|
@validator('{{{name}}}')
|
||||||
|
def {{{name}}}_validate_regular_expression(cls, value):
|
||||||
|
"""Validates the regular expression"""
|
||||||
|
{{^required}}
|
||||||
|
if value is None:
|
||||||
|
return value
|
||||||
|
|
||||||
|
{{/required}}
|
||||||
|
{{#required}}
|
||||||
|
{{#isNullable}}
|
||||||
|
if value is None:
|
||||||
|
return value
|
||||||
|
|
||||||
|
{{/isNullable}}
|
||||||
|
{{/required}}
|
||||||
|
if not re.match(r"{{{.}}}", value{{#vendorExtensions.x-modifiers}} ,re.{{{.}}}{{/vendorExtensions.x-modifiers}}):
|
||||||
|
raise ValueError(r"must validate the regular expression {{{vendorExtensions.x-pattern}}}")
|
||||||
|
return value
|
||||||
|
{{/vendorExtensions.x-regex}}
|
||||||
|
{{#isEnum}}
|
||||||
|
|
||||||
|
@validator('{{{name}}}')
|
||||||
|
def {{{name}}}_validate_enum(cls, value):
|
||||||
|
"""Validates the enum"""
|
||||||
|
{{^required}}
|
||||||
|
if value is None:
|
||||||
|
return value
|
||||||
|
|
||||||
|
{{/required}}
|
||||||
|
{{#required}}
|
||||||
|
{{#isNullable}}
|
||||||
|
if value is None:
|
||||||
|
return value
|
||||||
|
|
||||||
|
{{/isNullable}}
|
||||||
|
{{/required}}
|
||||||
|
{{#isArray}}
|
||||||
|
for i in value:
|
||||||
|
if i not in ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}):
|
||||||
|
raise ValueError("each list item must be one of ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})")
|
||||||
|
{{/isArray}}
|
||||||
|
{{^isArray}}
|
||||||
|
if value not in ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}):
|
||||||
|
raise ValueError("must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})")
|
||||||
|
{{/isArray}}
|
||||||
|
return value
|
||||||
|
{{/isEnum}}
|
||||||
|
{{/vars}}
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
{{#hasChildren}}
|
||||||
|
{{#discriminator}}
|
||||||
|
# JSON field name that stores the object type
|
||||||
|
__discriminator_property_name = '{{discriminator.propertyBaseName}}'
|
||||||
|
|
||||||
|
{{#mappedModels}}
|
||||||
|
{{#-first}}
|
||||||
|
# discriminator mappings
|
||||||
|
__discriminator_value_class_map = {
|
||||||
|
{{/-first}}
|
||||||
|
'{{{mappingName}}}': '{{{modelName}}}'{{^-last}},{{/-last}}
|
||||||
|
{{#-last}}
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_discriminator_value(cls, obj: dict) -> str:
|
||||||
|
"""Returns the discriminator value (object type) of the data"""
|
||||||
|
discriminator_value = obj[cls.__discriminator_property_name]
|
||||||
|
if discriminator_value:
|
||||||
|
return cls.__discriminator_value_class_map.get(discriminator_value)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
{{/-last}}
|
||||||
|
{{/mappedModels}}
|
||||||
|
|
||||||
|
{{/discriminator}}
|
||||||
|
{{/hasChildren}}
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> {{^hasChildren}}{{{classname}}}{{/hasChildren}}{{#hasChildren}}{{#discriminator}}Union({{#children}}{{{classname}}}{{^-last}}, {{/-last}}{{/children}}){{/discriminator}}{{^discriminator}}{{{classname}}}{{/discriminator}}{{/hasChildren}}:
|
||||||
|
"""Create an instance of {{{classname}}} from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
{{#vendorExtensions.x-py-readonly}}
|
||||||
|
"{{{.}}}",
|
||||||
|
{{/vendorExtensions.x-py-readonly}}
|
||||||
|
{{#isAdditionalPropertiesTrue}}
|
||||||
|
"additional_properties"
|
||||||
|
{{/isAdditionalPropertiesTrue}}
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
{{#allVars}}
|
||||||
|
{{#isContainer}}
|
||||||
|
{{#isArray}}
|
||||||
|
{{#items.isArray}}
|
||||||
|
{{^items.items.isPrimitiveType}}
|
||||||
|
# override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list of list)
|
||||||
|
_items = []
|
||||||
|
if self.{{{name}}}:
|
||||||
|
for _item in self.{{{name}}}:
|
||||||
|
if _item:
|
||||||
|
_items.append(
|
||||||
|
[_inner_item.to_dict() for _inner_item in _item if _inner_item is not None]
|
||||||
|
)
|
||||||
|
_dict['{{{baseName}}}'] = _items
|
||||||
|
{{/items.items.isPrimitiveType}}
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{^items.isArray}}
|
||||||
|
{{^items.isPrimitiveType}}
|
||||||
|
{{^items.isEnumOrRef}}
|
||||||
|
# override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list)
|
||||||
|
_items = []
|
||||||
|
if self.{{{name}}}:
|
||||||
|
for _item in self.{{{name}}}:
|
||||||
|
if _item:
|
||||||
|
_items.append(_item.to_dict())
|
||||||
|
_dict['{{{baseName}}}'] = _items
|
||||||
|
{{/items.isEnumOrRef}}
|
||||||
|
{{/items.isPrimitiveType}}
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{/isArray}}
|
||||||
|
{{#isMap}}
|
||||||
|
{{#items.isArray}}
|
||||||
|
# override the default output from pydantic by calling `to_dict()` of each value in {{{name}}} (dict of array)
|
||||||
|
_field_dict_of_array = {}
|
||||||
|
if self.{{{name}}}:
|
||||||
|
for _key in self.{{{name}}}:
|
||||||
|
if self.{{{name}}}[_key]:
|
||||||
|
_field_dict_of_array[_key] = [
|
||||||
|
_item.to_dict() for _item in self.{{{name}}}[_key]
|
||||||
|
]
|
||||||
|
_dict['{{{baseName}}}'] = _field_dict_of_array
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{^items.isArray}}
|
||||||
|
{{^items.isPrimitiveType}}
|
||||||
|
{{^items.isEnumOrRef}}
|
||||||
|
# override the default output from pydantic by calling `to_dict()` of each value in {{{name}}} (dict)
|
||||||
|
_field_dict = {}
|
||||||
|
if self.{{{name}}}:
|
||||||
|
for _key in self.{{{name}}}:
|
||||||
|
if self.{{{name}}}[_key]:
|
||||||
|
_field_dict[_key] = self.{{{name}}}[_key].to_dict()
|
||||||
|
_dict['{{{baseName}}}'] = _field_dict
|
||||||
|
{{/items.isEnumOrRef}}
|
||||||
|
{{/items.isPrimitiveType}}
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{/isMap}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{^isContainer}}
|
||||||
|
{{^isPrimitiveType}}
|
||||||
|
{{^isEnumOrRef}}
|
||||||
|
# override the default output from pydantic by calling `to_dict()` of {{{name}}}
|
||||||
|
if self.{{{name}}}:
|
||||||
|
_dict['{{{baseName}}}'] = self.{{{name}}}.to_dict()
|
||||||
|
{{/isEnumOrRef}}
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{/allVars}}
|
||||||
|
{{#isAdditionalPropertiesTrue}}
|
||||||
|
# puts key-value pairs in additional_properties in the top level
|
||||||
|
if self.additional_properties is not None:
|
||||||
|
for _key, _value in self.additional_properties.items():
|
||||||
|
_dict[_key] = _value
|
||||||
|
|
||||||
|
{{/isAdditionalPropertiesTrue}}
|
||||||
|
{{#allVars}}
|
||||||
|
{{#isNullable}}
|
||||||
|
# set to None if {{{name}}} (nullable) is None
|
||||||
|
# and __fields_set__ contains the field
|
||||||
|
if self.{{name}} is None and "{{{name}}}" in self.__fields_set__:
|
||||||
|
_dict['{{{baseName}}}'] = None
|
||||||
|
|
||||||
|
{{/isNullable}}
|
||||||
|
{{/allVars}}
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> {{^hasChildren}}{{{classname}}}{{/hasChildren}}{{#hasChildren}}{{#discriminator}}Union({{#children}}{{{classname}}}{{^-last}}, {{/-last}}{{/children}}){{/discriminator}}{{^discriminator}}{{{classname}}}{{/discriminator}}{{/hasChildren}}:
|
||||||
|
"""Create an instance of {{{classname}}} from a dict"""
|
||||||
|
{{#hasChildren}}
|
||||||
|
{{#discriminator}}
|
||||||
|
# look up the object type based on discriminator mapping
|
||||||
|
object_type = cls.get_discriminator_value(obj)
|
||||||
|
if object_type:
|
||||||
|
klass = globals()[object_type]
|
||||||
|
return klass.from_dict(obj)
|
||||||
|
else:
|
||||||
|
raise ValueError("{{{classname}}} failed to lookup discriminator value from " +
|
||||||
|
json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name +
|
||||||
|
", mapping: " + json.dumps(cls.__discriminator_value_class_map))
|
||||||
|
{{/discriminator}}
|
||||||
|
{{/hasChildren}}
|
||||||
|
{{^hasChildren}}
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return {{{classname}}}.parse_obj(obj)
|
||||||
|
|
||||||
|
{{#disallowAdditionalPropertiesIfNotPresent}}
|
||||||
|
{{^isAdditionalPropertiesTrue}}
|
||||||
|
# raise errors for additional fields in the input
|
||||||
|
for _key in obj.keys():
|
||||||
|
if _key not in cls.__properties:
|
||||||
|
raise ValueError("Error due to additional fields (not defined in {{classname}}) in the input: " + obj)
|
||||||
|
|
||||||
|
{{/isAdditionalPropertiesTrue}}
|
||||||
|
{{/disallowAdditionalPropertiesIfNotPresent}}
|
||||||
|
_obj = {{{classname}}}.parse_obj({
|
||||||
|
{{#allVars}}
|
||||||
|
{{#isContainer}}
|
||||||
|
{{#isArray}}
|
||||||
|
{{#items.isArray}}
|
||||||
|
{{#items.items.isPrimitiveType}}
|
||||||
|
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
||||||
|
{{/items.items.isPrimitiveType}}
|
||||||
|
{{^items.items.isPrimitiveType}}
|
||||||
|
"{{{name}}}": [
|
||||||
|
[{{{items.items.dataType}}}.from_dict(_inner_item) for _inner_item in _item]
|
||||||
|
for _item in obj.get("{{{baseName}}}")
|
||||||
|
] if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
|
||||||
|
{{/items.items.isPrimitiveType}}
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{^items.isArray}}
|
||||||
|
{{^items.isPrimitiveType}}
|
||||||
|
{{#items.isEnumOrRef}}
|
||||||
|
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
||||||
|
{{/items.isEnumOrRef}}
|
||||||
|
{{^items.isEnumOrRef}}
|
||||||
|
"{{{name}}}": [{{{items.dataType}}}.from_dict(_item) for _item in obj.get("{{{baseName}}}")] if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
|
||||||
|
{{/items.isEnumOrRef}}
|
||||||
|
{{/items.isPrimitiveType}}
|
||||||
|
{{#items.isPrimitiveType}}
|
||||||
|
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
||||||
|
{{/items.isPrimitiveType}}
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{/isArray}}
|
||||||
|
{{#isMap}}
|
||||||
|
{{^items.isPrimitiveType}}
|
||||||
|
{{^items.isEnumOrRef}}
|
||||||
|
{{#items.isContainer}}
|
||||||
|
{{#items.isMap}}
|
||||||
|
"{{{name}}}": dict(
|
||||||
|
(_k, dict(
|
||||||
|
(_ik, {{{items.items.dataType}}}.from_dict(_iv))
|
||||||
|
for _ik, _iv in _v.items()
|
||||||
|
)
|
||||||
|
if _v is not None
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
for _k, _v in obj.get("{{{baseName}}}").items()
|
||||||
|
)
|
||||||
|
if obj.get("{{{baseName}}}") is not None
|
||||||
|
else None{{^-last}},{{/-last}}
|
||||||
|
{{/items.isMap}}
|
||||||
|
{{#items.isArray}}
|
||||||
|
"{{{name}}}": dict(
|
||||||
|
(_k,
|
||||||
|
[{{{items.items.dataType}}}.from_dict(_item) for _item in _v]
|
||||||
|
if _v is not None
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
for _k, _v in obj.get("{{{baseName}}}").items()
|
||||||
|
){{^-last}},{{/-last}}
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{/items.isContainer}}
|
||||||
|
{{^items.isContainer}}
|
||||||
|
"{{{name}}}": dict(
|
||||||
|
(_k, {{{items.dataType}}}.from_dict(_v))
|
||||||
|
for _k, _v in obj.get("{{{baseName}}}").items()
|
||||||
|
)
|
||||||
|
if obj.get("{{{baseName}}}") is not None
|
||||||
|
else None{{^-last}},{{/-last}}
|
||||||
|
{{/items.isContainer}}
|
||||||
|
{{/items.isEnumOrRef}}
|
||||||
|
{{#items.isEnumOrRef}}
|
||||||
|
"{{{name}}}": dict((_k, _v) for _k, _v in obj.get("{{{baseName}}}").items()){{^-last}},{{/-last}}
|
||||||
|
{{/items.isEnumOrRef}}
|
||||||
|
{{/items.isPrimitiveType}}
|
||||||
|
{{#items.isPrimitiveType}}
|
||||||
|
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
||||||
|
{{/items.isPrimitiveType}}
|
||||||
|
{{/isMap}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{^isContainer}}
|
||||||
|
{{^isPrimitiveType}}
|
||||||
|
{{^isEnumOrRef}}
|
||||||
|
"{{{name}}}": {{{dataType}}}.from_dict(obj.get("{{{baseName}}}")) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
|
||||||
|
{{/isEnumOrRef}}
|
||||||
|
{{#isEnumOrRef}}
|
||||||
|
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
||||||
|
{{/isEnumOrRef}}
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{#isPrimitiveType}}
|
||||||
|
{{#defaultValue}}
|
||||||
|
"{{{name}}}": obj.get("{{{baseName}}}") if obj.get("{{{baseName}}}") is not None else {{{defaultValue}}}{{^-last}},{{/-last}}
|
||||||
|
{{/defaultValue}}
|
||||||
|
{{^defaultValue}}
|
||||||
|
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
||||||
|
{{/defaultValue}}
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{/allVars}}
|
||||||
|
})
|
||||||
|
{{#isAdditionalPropertiesTrue}}
|
||||||
|
# store additional fields in additional_properties
|
||||||
|
for _key in obj.keys():
|
||||||
|
if _key not in cls.__properties:
|
||||||
|
_obj.additional_properties[_key] = obj.get(_key)
|
||||||
|
|
||||||
|
{{/isAdditionalPropertiesTrue}}
|
||||||
|
return _obj
|
||||||
|
{{/hasChildren}}
|
||||||
|
|
||||||
|
{{#vendorExtensions.x-py-postponed-model-imports.size}}
|
||||||
|
{{#vendorExtensions.x-py-postponed-model-imports}}
|
||||||
|
{{{.}}}
|
||||||
|
{{/vendorExtensions.x-py-postponed-model-imports}}
|
||||||
|
{{classname}}.update_forward_refs()
|
||||||
|
{{/vendorExtensions.x-py-postponed-model-imports.size}}
|
206
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_oneof.mustache
vendored
Normal file
206
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_oneof.mustache
vendored
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
from inspect import getfullargspec
|
||||||
|
import json
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
{{#vendorExtensions.x-py-datetime-imports}}{{#-first}}from datetime import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-datetime-imports}}
|
||||||
|
{{#vendorExtensions.x-py-typing-imports}}{{#-first}}from typing import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-typing-imports}}
|
||||||
|
{{#vendorExtensions.x-py-pydantic-imports}}{{#-first}}from pydantic import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-pydantic-imports}}
|
||||||
|
{{#vendorExtensions.x-py-model-imports}}
|
||||||
|
{{{.}}}
|
||||||
|
{{/vendorExtensions.x-py-model-imports}}
|
||||||
|
from typing import Union, Any, List, TYPE_CHECKING
|
||||||
|
from pydantic import StrictStr, Field
|
||||||
|
|
||||||
|
{{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ONE_OF_SCHEMAS = [{{#oneOf}}"{{.}}"{{^-last}}, {{/-last}}{{/oneOf}}]
|
||||||
|
|
||||||
|
class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}):
|
||||||
|
"""
|
||||||
|
{{{description}}}{{^description}}{{{classname}}}{{/description}}
|
||||||
|
"""
|
||||||
|
{{#composedSchemas.oneOf}}
|
||||||
|
# data type: {{{dataType}}}
|
||||||
|
{{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
|
||||||
|
{{/composedSchemas.oneOf}}
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
actual_instance: Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]
|
||||||
|
else:
|
||||||
|
actual_instance: Any
|
||||||
|
one_of_schemas: List[str] = Field({{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ONE_OF_SCHEMAS, const=True)
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
validate_assignment = True
|
||||||
|
{{#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, *args, **kwargs) -> None:
|
||||||
|
if args:
|
||||||
|
if len(args) > 1:
|
||||||
|
raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
|
||||||
|
if kwargs:
|
||||||
|
raise ValueError("If a position argument is used, keyword arguments cannot be used.")
|
||||||
|
super().__init__(actual_instance=args[0])
|
||||||
|
else:
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
@validator('actual_instance')
|
||||||
|
def actual_instance_must_validate_oneof(cls, v):
|
||||||
|
{{#isNullable}}
|
||||||
|
if v is None:
|
||||||
|
return v
|
||||||
|
|
||||||
|
{{/isNullable}}
|
||||||
|
instance = {{{classname}}}.construct()
|
||||||
|
error_messages = []
|
||||||
|
match = 0
|
||||||
|
{{#composedSchemas.oneOf}}
|
||||||
|
# validate data type: {{{dataType}}}
|
||||||
|
{{#isContainer}}
|
||||||
|
try:
|
||||||
|
instance.{{vendorExtensions.x-py-name}} = v
|
||||||
|
match += 1
|
||||||
|
except (ValidationError, ValueError) as e:
|
||||||
|
error_messages.append(str(e))
|
||||||
|
{{/isContainer}}
|
||||||
|
{{^isContainer}}
|
||||||
|
{{#isPrimitiveType}}
|
||||||
|
try:
|
||||||
|
instance.{{vendorExtensions.x-py-name}} = v
|
||||||
|
match += 1
|
||||||
|
except (ValidationError, ValueError) as e:
|
||||||
|
error_messages.append(str(e))
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{^isPrimitiveType}}
|
||||||
|
if not isinstance(v, {{{dataType}}}):
|
||||||
|
error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`")
|
||||||
|
else:
|
||||||
|
match += 1
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{/composedSchemas.oneOf}}
|
||||||
|
if match > 1:
|
||||||
|
# more than 1 match
|
||||||
|
raise ValueError("Multiple matches found when setting `actual_instance` in {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages))
|
||||||
|
elif match == 0:
|
||||||
|
# no match
|
||||||
|
raise ValueError("No match found when setting `actual_instance` in {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages))
|
||||||
|
else:
|
||||||
|
return v
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> {{{classname}}}:
|
||||||
|
return cls.from_json(json.dumps(obj))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> {{{classname}}}:
|
||||||
|
"""Returns the object represented by the json string"""
|
||||||
|
instance = {{{classname}}}.construct()
|
||||||
|
{{#isNullable}}
|
||||||
|
if json_str is None:
|
||||||
|
return instance
|
||||||
|
|
||||||
|
{{/isNullable}}
|
||||||
|
error_messages = []
|
||||||
|
match = 0
|
||||||
|
|
||||||
|
{{#useOneOfDiscriminatorLookup}}
|
||||||
|
{{#discriminator}}
|
||||||
|
{{#mappedModels}}
|
||||||
|
{{#-first}}
|
||||||
|
# use oneOf discriminator to lookup the data type
|
||||||
|
_data_type = json.loads(json_str).get("{{{propertyBaseName}}}")
|
||||||
|
if not _data_type:
|
||||||
|
raise ValueError("Failed to lookup data type from the field `{{{propertyBaseName}}}` in the input.")
|
||||||
|
|
||||||
|
{{/-first}}
|
||||||
|
# check if data type is `{{{modelName}}}`
|
||||||
|
if _data_type == "{{{mappingName}}}":
|
||||||
|
instance.actual_instance = {{{modelName}}}.from_json(json_str)
|
||||||
|
return instance
|
||||||
|
|
||||||
|
{{/mappedModels}}
|
||||||
|
{{/discriminator}}
|
||||||
|
{{/useOneOfDiscriminatorLookup}}
|
||||||
|
{{#composedSchemas.oneOf}}
|
||||||
|
{{#isContainer}}
|
||||||
|
# deserialize data into {{{dataType}}}
|
||||||
|
try:
|
||||||
|
# validation
|
||||||
|
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
|
||||||
|
# assign value to actual_instance
|
||||||
|
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
|
||||||
|
match += 1
|
||||||
|
except (ValidationError, ValueError) as e:
|
||||||
|
error_messages.append(str(e))
|
||||||
|
{{/isContainer}}
|
||||||
|
{{^isContainer}}
|
||||||
|
{{#isPrimitiveType}}
|
||||||
|
# deserialize data into {{{dataType}}}
|
||||||
|
try:
|
||||||
|
# validation
|
||||||
|
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
|
||||||
|
# assign value to actual_instance
|
||||||
|
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
|
||||||
|
match += 1
|
||||||
|
except (ValidationError, ValueError) as e:
|
||||||
|
error_messages.append(str(e))
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{^isPrimitiveType}}
|
||||||
|
# deserialize data into {{{dataType}}}
|
||||||
|
try:
|
||||||
|
instance.actual_instance = {{{dataType}}}.from_json(json_str)
|
||||||
|
match += 1
|
||||||
|
except (ValidationError, ValueError) as e:
|
||||||
|
error_messages.append(str(e))
|
||||||
|
{{/isPrimitiveType}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{/composedSchemas.oneOf}}
|
||||||
|
|
||||||
|
if match > 1:
|
||||||
|
# more than 1 match
|
||||||
|
raise ValueError("Multiple matches found when deserializing the JSON string into {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages))
|
||||||
|
elif match == 0:
|
||||||
|
# no match
|
||||||
|
raise ValueError("No match found when deserializing the JSON string into {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages))
|
||||||
|
else:
|
||||||
|
return instance
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the actual instance"""
|
||||||
|
if self.actual_instance is None:
|
||||||
|
return "null"
|
||||||
|
|
||||||
|
to_json = getattr(self.actual_instance, "to_json", None)
|
||||||
|
if callable(to_json):
|
||||||
|
return self.actual_instance.to_json()
|
||||||
|
else:
|
||||||
|
return json.dumps(self.actual_instance)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
"""Returns the dict representation of the actual instance"""
|
||||||
|
if self.actual_instance is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
to_dict = getattr(self.actual_instance, "to_dict", None)
|
||||||
|
if callable(to_dict):
|
||||||
|
return self.actual_instance.to_dict()
|
||||||
|
else:
|
||||||
|
# primitive type
|
||||||
|
return self.actual_instance
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the actual instance"""
|
||||||
|
return pprint.pformat(self.dict())
|
||||||
|
|
||||||
|
{{#vendorExtensions.x-py-postponed-model-imports.size}}
|
||||||
|
{{#vendorExtensions.x-py-postponed-model-imports}}
|
||||||
|
{{{.}}}
|
||||||
|
{{/vendorExtensions.x-py-postponed-model-imports}}
|
||||||
|
{{classname}}.update_forward_refs()
|
||||||
|
{{/vendorExtensions.x-py-postponed-model-imports.size}}
|
60
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_test.mustache
vendored
Normal file
60
modules/openapi-generator/src/main/resources/python-pydantic-v1/model_test.mustache
vendored
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
{{#models}}
|
||||||
|
{{#model}}
|
||||||
|
from {{modelPackage}}.{{classFilename}} import {{classname}} # noqa: E501
|
||||||
|
|
||||||
|
class Test{{classname}}(unittest.TestCase):
|
||||||
|
"""{{classname}} unit test stubs"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
{{^isEnum}}
|
||||||
|
|
||||||
|
def make_instance(self, include_optional) -> {{classname}}:
|
||||||
|
"""Test {{classname}}
|
||||||
|
include_option is a boolean, when False only required
|
||||||
|
params are included, when True both required and
|
||||||
|
optional params are included """
|
||||||
|
# uncomment below to create an instance of `{{{classname}}}`
|
||||||
|
"""
|
||||||
|
model = {{classname}}() # noqa: E501
|
||||||
|
if include_optional:
|
||||||
|
return {{classname}}(
|
||||||
|
{{#vars}}
|
||||||
|
{{name}} = {{{example}}}{{^example}}None{{/example}}{{^-last}},{{/-last}}
|
||||||
|
{{/vars}}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return {{classname}}(
|
||||||
|
{{#vars}}
|
||||||
|
{{#required}}
|
||||||
|
{{name}} = {{{example}}}{{^example}}None{{/example}},
|
||||||
|
{{/required}}
|
||||||
|
{{/vars}}
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
{{/isEnum}}
|
||||||
|
|
||||||
|
def test{{classname}}(self):
|
||||||
|
"""Test {{classname}}"""
|
||||||
|
{{^isEnum}}
|
||||||
|
# inst_req_only = self.make_instance(include_optional=False)
|
||||||
|
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||||
|
{{/isEnum}}
|
||||||
|
{{#isEnum}}
|
||||||
|
# inst = {{{classname}}}()
|
||||||
|
{{/isEnum}}
|
||||||
|
{{/model}}
|
||||||
|
{{/models}}
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
19
modules/openapi-generator/src/main/resources/python-pydantic-v1/partial_header.mustache
vendored
Normal file
19
modules/openapi-generator/src/main/resources/python-pydantic-v1/partial_header.mustache
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
"""
|
||||||
|
{{#appName}}
|
||||||
|
{{{.}}}
|
||||||
|
|
||||||
|
{{/appName}}
|
||||||
|
{{#appDescription}}
|
||||||
|
{{{.}}}
|
||||||
|
|
||||||
|
{{/appDescription}}
|
||||||
|
{{#version}}
|
||||||
|
The version of the OpenAPI document: {{{.}}}
|
||||||
|
{{/version}}
|
||||||
|
{{#infoEmail}}
|
||||||
|
Contact: {{{.}}}
|
||||||
|
{{/infoEmail}}
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
0
modules/openapi-generator/src/main/resources/python-pydantic-v1/py.typed.mustache
vendored
Normal file
0
modules/openapi-generator/src/main/resources/python-pydantic-v1/py.typed.mustache
vendored
Normal file
40
modules/openapi-generator/src/main/resources/python-pydantic-v1/pyproject.mustache
vendored
Normal file
40
modules/openapi-generator/src/main/resources/python-pydantic-v1/pyproject.mustache
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
[tool.poetry]
|
||||||
|
name = "{{{packageName}}}"
|
||||||
|
version = "{{{packageVersion}}}"
|
||||||
|
description = "{{{appName}}}"
|
||||||
|
authors = ["{{infoName}}{{^infoName}}OpenAPI Generator Community{{/infoName}} <{{infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}>"]
|
||||||
|
license = "{{{licenseInfo}}}{{^licenseInfo}}NoLicense{{/licenseInfo}}"
|
||||||
|
readme = "README.md"
|
||||||
|
repository = "https://github.com/{{{gitUserId}}}/{{{gitRepoId}}}"
|
||||||
|
keywords = ["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"]
|
||||||
|
include = ["{{packageName}}/py.typed"]
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
python = "^3.7"
|
||||||
|
|
||||||
|
urllib3 = ">= 1.25.3"
|
||||||
|
python-dateutil = ">=2.8.2"
|
||||||
|
{{#asyncio}}
|
||||||
|
aiohttp = ">= 3.8.4"
|
||||||
|
{{/asyncio}}
|
||||||
|
{{#tornado}}
|
||||||
|
tornado = ">=4.2,<5"
|
||||||
|
{{/tornado}}
|
||||||
|
{{#hasHttpSignatureMethods}}
|
||||||
|
pem = ">= 19.3.0"
|
||||||
|
pycryptodome = ">= 3.9.0"
|
||||||
|
{{/hasHttpSignatureMethods}}
|
||||||
|
pydantic = "^1.10.5, <2"
|
||||||
|
aenum = ">=3.1.11"
|
||||||
|
|
||||||
|
[tool.poetry.dev-dependencies]
|
||||||
|
pytest = ">=7.2.1"
|
||||||
|
tox = ">=3.9.0"
|
||||||
|
flake8 = ">=4.0.0"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[tool.pylint.'MESSAGES CONTROL']
|
||||||
|
extension-pkg-whitelist = "pydantic"
|
108
modules/openapi-generator/src/main/resources/python-pydantic-v1/python_doc_auth_partial.mustache
vendored
Normal file
108
modules/openapi-generator/src/main/resources/python-pydantic-v1/python_doc_auth_partial.mustache
vendored
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
# Defining the host is optional and defaults to {{{basePath}}}
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = {{{packageName}}}.Configuration(
|
||||||
|
host = "{{{basePath}}}"
|
||||||
|
)
|
||||||
|
|
||||||
|
{{#hasAuthMethods}}
|
||||||
|
# The client must configure the authentication and authorization parameters
|
||||||
|
# in accordance with the API server security policy.
|
||||||
|
# Examples for each auth method are provided below, use the example that
|
||||||
|
# satisfies your auth use case.
|
||||||
|
{{#authMethods}}
|
||||||
|
{{#isBasic}}
|
||||||
|
{{#isBasicBasic}}
|
||||||
|
|
||||||
|
# Configure HTTP basic authorization: {{{name}}}
|
||||||
|
configuration = {{{packageName}}}.Configuration(
|
||||||
|
username = os.environ["USERNAME"],
|
||||||
|
password = os.environ["PASSWORD"]
|
||||||
|
)
|
||||||
|
{{/isBasicBasic}}
|
||||||
|
{{#isBasicBearer}}
|
||||||
|
|
||||||
|
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
|
||||||
|
configuration = {{{packageName}}}.Configuration(
|
||||||
|
access_token = os.environ["BEARER_TOKEN"]
|
||||||
|
)
|
||||||
|
{{/isBasicBearer}}
|
||||||
|
{{#isHttpSignature}}
|
||||||
|
|
||||||
|
# Configure HTTP message signature: {{{name}}}
|
||||||
|
# The HTTP Signature Header mechanism that can be used by a client to
|
||||||
|
# authenticate the sender of a message and ensure that particular headers
|
||||||
|
# have not been modified in transit.
|
||||||
|
#
|
||||||
|
# You can specify the signing key-id, private key path, signing scheme,
|
||||||
|
# signing algorithm, list of signed headers and signature max validity.
|
||||||
|
# The 'key_id' parameter is an opaque string that the API server can use
|
||||||
|
# to lookup the client and validate the signature.
|
||||||
|
# The 'private_key_path' parameter should be the path to a file that
|
||||||
|
# contains a DER or base-64 encoded private key.
|
||||||
|
# The 'private_key_passphrase' parameter is optional. Set the passphrase
|
||||||
|
# if the private key is encrypted.
|
||||||
|
# The 'signed_headers' parameter is used to specify the list of
|
||||||
|
# HTTP headers included when generating the signature for the message.
|
||||||
|
# You can specify HTTP headers that you want to protect with a cryptographic
|
||||||
|
# signature. Note that proxies may add, modify or remove HTTP headers
|
||||||
|
# for legitimate reasons, so you should only add headers that you know
|
||||||
|
# will not be modified. For example, if you want to protect the HTTP request
|
||||||
|
# body, you can specify the Digest header. In that case, the client calculates
|
||||||
|
# the digest of the HTTP request body and includes the digest in the message
|
||||||
|
# signature.
|
||||||
|
# The 'signature_max_validity' parameter is optional. It is configured as a
|
||||||
|
# duration to express when the signature ceases to be valid. The client calculates
|
||||||
|
# the expiration date every time it generates the cryptographic signature
|
||||||
|
# of an HTTP request. The API server may have its own security policy
|
||||||
|
# that controls the maximum validity of the signature. The client max validity
|
||||||
|
# must be lower than the server max validity.
|
||||||
|
# The time on the client and server must be synchronized, otherwise the
|
||||||
|
# server may reject the client signature.
|
||||||
|
#
|
||||||
|
# The client must use a combination of private key, signing scheme,
|
||||||
|
# signing algorithm and hash algorithm that matches the security policy of
|
||||||
|
# the API server.
|
||||||
|
#
|
||||||
|
# See {{{packageName}}}.signing for a list of all supported parameters.
|
||||||
|
from {{{packageName}}} import signing
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
configuration = {{{packageName}}}.Configuration(
|
||||||
|
host = "{{{basePath}}}",
|
||||||
|
signing_info = {{{packageName}}}.HttpSigningConfiguration(
|
||||||
|
key_id = 'my-key-id',
|
||||||
|
private_key_path = 'private_key.pem',
|
||||||
|
private_key_passphrase = 'YOUR_PASSPHRASE',
|
||||||
|
signing_scheme = {{{packageName}}}.signing.SCHEME_HS2019,
|
||||||
|
signing_algorithm = {{{packageName}}}.signing.ALGORITHM_ECDSA_MODE_FIPS_186_3,
|
||||||
|
hash_algorithm = {{{packageName}}}.signing.SCHEME_RSA_SHA256,
|
||||||
|
signed_headers = [
|
||||||
|
{{{packageName}}}.signing.HEADER_REQUEST_TARGET,
|
||||||
|
{{{packageName}}}.signing.HEADER_CREATED,
|
||||||
|
{{{packageName}}}.signing.HEADER_EXPIRES,
|
||||||
|
{{{packageName}}}.signing.HEADER_HOST,
|
||||||
|
{{{packageName}}}.signing.HEADER_DATE,
|
||||||
|
{{{packageName}}}.signing.HEADER_DIGEST,
|
||||||
|
'Content-Type',
|
||||||
|
'Content-Length',
|
||||||
|
'User-Agent'
|
||||||
|
],
|
||||||
|
signature_max_validity = datetime.timedelta(minutes=5)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{{/isHttpSignature}}
|
||||||
|
{{/isBasic}}
|
||||||
|
{{#isApiKey}}
|
||||||
|
|
||||||
|
# Configure API key authorization: {{{name}}}
|
||||||
|
configuration.api_key['{{{name}}}'] = os.environ["API_KEY"]
|
||||||
|
|
||||||
|
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||||
|
# configuration.api_key_prefix['{{name}}'] = 'Bearer'
|
||||||
|
{{/isApiKey}}
|
||||||
|
{{#isOAuth}}
|
||||||
|
|
||||||
|
configuration.access_token = os.environ["ACCESS_TOKEN"]
|
||||||
|
{{/isOAuth}}
|
||||||
|
{{/authMethods}}
|
||||||
|
{{/hasAuthMethods}}
|
11
modules/openapi-generator/src/main/resources/python-pydantic-v1/requirements.mustache
vendored
Normal file
11
modules/openapi-generator/src/main/resources/python-pydantic-v1/requirements.mustache
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
python_dateutil >= 2.5.3
|
||||||
|
setuptools >= 21.0.0
|
||||||
|
urllib3 >= 1.25.3, < 2.1.0
|
||||||
|
pydantic >= 1.10.5, < 2
|
||||||
|
aenum >= 3.1.11
|
||||||
|
{{#asyncio}}
|
||||||
|
aiohttp >= 3.0.0
|
||||||
|
{{/asyncio}}
|
||||||
|
{{#hasHttpSignatureMethods}}
|
||||||
|
pycryptodome >= 3.9.0
|
||||||
|
{{/hasHttpSignatureMethods}}
|
293
modules/openapi-generator/src/main/resources/python-pydantic-v1/rest.mustache
vendored
Normal file
293
modules/openapi-generator/src/main/resources/python-pydantic-v1/rest.mustache
vendored
Normal file
@ -0,0 +1,293 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
import ssl
|
||||||
|
|
||||||
|
from urllib.parse import urlencode, quote_plus
|
||||||
|
import urllib3
|
||||||
|
|
||||||
|
from {{packageName}}.exceptions import ApiException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException, ApiValueError, BadRequestException
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
|
def __init__(self, resp) -> None:
|
||||||
|
self.urllib3_response = resp
|
||||||
|
self.status = resp.status
|
||||||
|
self.reason = resp.reason
|
||||||
|
self.data = resp.data
|
||||||
|
|
||||||
|
def getheaders(self):
|
||||||
|
"""Returns a dictionary of the response headers."""
|
||||||
|
return self.urllib3_response.headers
|
||||||
|
|
||||||
|
def getheader(self, name, default=None):
|
||||||
|
"""Returns a given response header."""
|
||||||
|
return self.urllib3_response.headers.get(name, default)
|
||||||
|
|
||||||
|
|
||||||
|
class RESTClientObject:
|
||||||
|
|
||||||
|
def __init__(self, configuration, pools_size=4, maxsize=None) -> None:
|
||||||
|
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
||||||
|
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
|
||||||
|
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
|
||||||
|
# maxsize is the number of requests to host that are allowed in parallel # noqa: E501
|
||||||
|
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
|
||||||
|
|
||||||
|
# cert_reqs
|
||||||
|
if configuration.verify_ssl:
|
||||||
|
cert_reqs = ssl.CERT_REQUIRED
|
||||||
|
else:
|
||||||
|
cert_reqs = ssl.CERT_NONE
|
||||||
|
|
||||||
|
addition_pool_args = {}
|
||||||
|
if configuration.assert_hostname is not None:
|
||||||
|
addition_pool_args['assert_hostname'] = configuration.assert_hostname # noqa: E501
|
||||||
|
|
||||||
|
if configuration.retries is not None:
|
||||||
|
addition_pool_args['retries'] = configuration.retries
|
||||||
|
|
||||||
|
if configuration.tls_server_name:
|
||||||
|
addition_pool_args['server_hostname'] = configuration.tls_server_name
|
||||||
|
|
||||||
|
|
||||||
|
if configuration.socket_options is not None:
|
||||||
|
addition_pool_args['socket_options'] = configuration.socket_options
|
||||||
|
|
||||||
|
if maxsize is None:
|
||||||
|
if configuration.connection_pool_maxsize is not None:
|
||||||
|
maxsize = configuration.connection_pool_maxsize
|
||||||
|
else:
|
||||||
|
maxsize = 4
|
||||||
|
|
||||||
|
# https pool manager
|
||||||
|
if configuration.proxy:
|
||||||
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
|
num_pools=pools_size,
|
||||||
|
maxsize=maxsize,
|
||||||
|
cert_reqs=cert_reqs,
|
||||||
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
|
cert_file=configuration.cert_file,
|
||||||
|
key_file=configuration.key_file,
|
||||||
|
proxy_url=configuration.proxy,
|
||||||
|
proxy_headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.pool_manager = urllib3.PoolManager(
|
||||||
|
num_pools=pools_size,
|
||||||
|
maxsize=maxsize,
|
||||||
|
cert_reqs=cert_reqs,
|
||||||
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
|
cert_file=configuration.cert_file,
|
||||||
|
key_file=configuration.key_file,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
|
|
||||||
|
def request(self, method, url, query_params=None, headers=None,
|
||||||
|
body=None, post_params=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
|
"""Perform requests.
|
||||||
|
|
||||||
|
: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: 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.
|
||||||
|
"""
|
||||||
|
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 {}
|
||||||
|
# url already contains the URL query string
|
||||||
|
# so reset query_params to empty dict
|
||||||
|
query_params = {}
|
||||||
|
|
||||||
|
timeout = None
|
||||||
|
if _request_timeout:
|
||||||
|
if isinstance(_request_timeout, (int,float)): # noqa: E501,F821
|
||||||
|
timeout = urllib3.Timeout(total=_request_timeout)
|
||||||
|
elif (isinstance(_request_timeout, tuple) and
|
||||||
|
len(_request_timeout) == 2):
|
||||||
|
timeout = urllib3.Timeout(
|
||||||
|
connect=_request_timeout[0], read=_request_timeout[1])
|
||||||
|
|
||||||
|
try:
|
||||||
|
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
||||||
|
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
|
||||||
|
|
||||||
|
# no content type provided or payload is json
|
||||||
|
if not headers.get('Content-Type') or re.search('json', headers['Content-Type'], re.IGNORECASE):
|
||||||
|
request_body = None
|
||||||
|
if body is not None:
|
||||||
|
request_body = json.dumps(body)
|
||||||
|
r = self.pool_manager.request(
|
||||||
|
method, url,
|
||||||
|
body=request_body,
|
||||||
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
|
headers=headers)
|
||||||
|
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
|
||||||
|
r = self.pool_manager.request(
|
||||||
|
method, url,
|
||||||
|
fields=post_params,
|
||||||
|
encode_multipart=False,
|
||||||
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
|
headers=headers)
|
||||||
|
elif headers['Content-Type'] == 'multipart/form-data':
|
||||||
|
# must del headers['Content-Type'], or the correct
|
||||||
|
# Content-Type which generated by urllib3 will be
|
||||||
|
# overwritten.
|
||||||
|
del headers['Content-Type']
|
||||||
|
r = self.pool_manager.request(
|
||||||
|
method, url,
|
||||||
|
fields=post_params,
|
||||||
|
encode_multipart=True,
|
||||||
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
|
headers=headers)
|
||||||
|
# Pass a `string` parameter directly in the body to support
|
||||||
|
# other content types than Json when `body` argument is
|
||||||
|
# provided in serialized form
|
||||||
|
elif isinstance(body, str) or isinstance(body, bytes):
|
||||||
|
request_body = body
|
||||||
|
r = self.pool_manager.request(
|
||||||
|
method, url,
|
||||||
|
body=request_body,
|
||||||
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
|
headers=headers)
|
||||||
|
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)
|
||||||
|
# For `GET`, `HEAD`
|
||||||
|
else:
|
||||||
|
r = self.pool_manager.request(method, url,
|
||||||
|
fields={},
|
||||||
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
|
headers=headers)
|
||||||
|
except urllib3.exceptions.SSLError as e:
|
||||||
|
msg = "{0}\n{1}".format(type(e).__name__, str(e))
|
||||||
|
raise ApiException(status=0, reason=msg)
|
||||||
|
|
||||||
|
if _preload_content:
|
||||||
|
r = RESTResponse(r)
|
||||||
|
|
||||||
|
# log response body
|
||||||
|
logger.debug("response body: %s", r.data)
|
||||||
|
|
||||||
|
if not 200 <= r.status <= 299:
|
||||||
|
if r.status == 400:
|
||||||
|
raise BadRequestException(http_resp=r)
|
||||||
|
|
||||||
|
if r.status == 401:
|
||||||
|
raise UnauthorizedException(http_resp=r)
|
||||||
|
|
||||||
|
if r.status == 403:
|
||||||
|
raise ForbiddenException(http_resp=r)
|
||||||
|
|
||||||
|
if r.status == 404:
|
||||||
|
raise NotFoundException(http_resp=r)
|
||||||
|
|
||||||
|
if 500 <= r.status <= 599:
|
||||||
|
raise ServiceException(http_resp=r)
|
||||||
|
|
||||||
|
raise ApiException(http_resp=r)
|
||||||
|
|
||||||
|
return r
|
||||||
|
|
||||||
|
def get_request(self, url, headers=None, query_params=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
|
return self.request("GET", url,
|
||||||
|
headers=headers,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
query_params=query_params)
|
||||||
|
|
||||||
|
def head_request(self, url, headers=None, query_params=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
|
return self.request("HEAD", url,
|
||||||
|
headers=headers,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
query_params=query_params)
|
||||||
|
|
||||||
|
def options_request(self, url, headers=None, query_params=None, post_params=None,
|
||||||
|
body=None, _preload_content=True, _request_timeout=None):
|
||||||
|
return self.request("OPTIONS", url,
|
||||||
|
headers=headers,
|
||||||
|
query_params=query_params,
|
||||||
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
body=body)
|
||||||
|
|
||||||
|
def delete_request(self, url, headers=None, query_params=None, body=None,
|
||||||
|
_preload_content=True, _request_timeout=None):
|
||||||
|
return self.request("DELETE", url,
|
||||||
|
headers=headers,
|
||||||
|
query_params=query_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
body=body)
|
||||||
|
|
||||||
|
def post_request(self, url, headers=None, query_params=None, post_params=None,
|
||||||
|
body=None, _preload_content=True, _request_timeout=None):
|
||||||
|
return self.request("POST", url,
|
||||||
|
headers=headers,
|
||||||
|
query_params=query_params,
|
||||||
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
body=body)
|
||||||
|
|
||||||
|
def put_request(self, url, headers=None, query_params=None, post_params=None,
|
||||||
|
body=None, _preload_content=True, _request_timeout=None):
|
||||||
|
return self.request("PUT", url,
|
||||||
|
headers=headers,
|
||||||
|
query_params=query_params,
|
||||||
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
body=body)
|
||||||
|
|
||||||
|
def patch_request(self, url, headers=None, query_params=None, post_params=None,
|
||||||
|
body=None, _preload_content=True, _request_timeout=None):
|
||||||
|
return self.request("PATCH", url,
|
||||||
|
headers=headers,
|
||||||
|
query_params=query_params,
|
||||||
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
body=body)
|
56
modules/openapi-generator/src/main/resources/python-pydantic-v1/setup.mustache
vendored
Normal file
56
modules/openapi-generator/src/main/resources/python-pydantic-v1/setup.mustache
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
from setuptools import setup, find_packages # noqa: H301
|
||||||
|
|
||||||
|
# To install the library, run the following
|
||||||
|
#
|
||||||
|
# python setup.py install
|
||||||
|
#
|
||||||
|
# prerequisite: setuptools
|
||||||
|
# http://pypi.python.org/pypi/setuptools
|
||||||
|
NAME = "{{{projectName}}}"
|
||||||
|
VERSION = "{{packageVersion}}"
|
||||||
|
PYTHON_REQUIRES = ">=3.7"
|
||||||
|
{{#apiInfo}}
|
||||||
|
{{#apis}}
|
||||||
|
{{#-last}}
|
||||||
|
REQUIRES = [
|
||||||
|
"urllib3 >= 1.25.3, < 2.1.0",
|
||||||
|
"python-dateutil",
|
||||||
|
{{#asyncio}}
|
||||||
|
"aiohttp >= 3.0.0",
|
||||||
|
{{/asyncio}}
|
||||||
|
{{#tornado}}
|
||||||
|
"tornado>=4.2,<5",
|
||||||
|
{{/tornado}}
|
||||||
|
{{#hasHttpSignatureMethods}}
|
||||||
|
"pem>=19.3.0",
|
||||||
|
"pycryptodome>=3.9.0",
|
||||||
|
{{/hasHttpSignatureMethods}}
|
||||||
|
"pydantic >= 1.10.5, < 2",
|
||||||
|
"aenum"
|
||||||
|
]
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name=NAME,
|
||||||
|
version=VERSION,
|
||||||
|
description="{{appName}}",
|
||||||
|
author="{{infoName}}{{^infoName}}OpenAPI Generator community{{/infoName}}",
|
||||||
|
author_email="{{infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}",
|
||||||
|
url="{{packageUrl}}",
|
||||||
|
keywords=["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"],
|
||||||
|
install_requires=REQUIRES,
|
||||||
|
packages=find_packages(exclude=["test", "tests"]),
|
||||||
|
include_package_data=True,
|
||||||
|
{{#licenseInfo}}license="{{.}}",
|
||||||
|
{{/licenseInfo}}long_description_content_type='text/markdown',
|
||||||
|
long_description="""\
|
||||||
|
{{appDescription}}
|
||||||
|
""", # noqa: E501
|
||||||
|
package_data={"{{{packageName}}}": ["py.typed"]},
|
||||||
|
)
|
||||||
|
{{/-last}}
|
||||||
|
{{/apis}}
|
||||||
|
{{/apiInfo}}
|
2
modules/openapi-generator/src/main/resources/python-pydantic-v1/setup_cfg.mustache
vendored
Normal file
2
modules/openapi-generator/src/main/resources/python-pydantic-v1/setup_cfg.mustache
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[flake8]
|
||||||
|
max-line-length=99
|
403
modules/openapi-generator/src/main/resources/python-pydantic-v1/signing.mustache
vendored
Normal file
403
modules/openapi-generator/src/main/resources/python-pydantic-v1/signing.mustache
vendored
Normal file
@ -0,0 +1,403 @@
|
|||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
from base64 import b64encode
|
||||||
|
from Crypto.IO import PEM, PKCS8
|
||||||
|
from Crypto.Hash import SHA256, SHA512
|
||||||
|
from Crypto.PublicKey import RSA, ECC
|
||||||
|
from Crypto.Signature import PKCS1_v1_5, pss, DSS
|
||||||
|
from email.utils import formatdate
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from time import time
|
||||||
|
from urllib.parse import urlencode, urlparse
|
||||||
|
|
||||||
|
# The constants below define a subset of HTTP headers that can be included in the
|
||||||
|
# HTTP signature scheme. Additional headers may be included in the signature.
|
||||||
|
|
||||||
|
# The '(request-target)' header is a calculated field that includes the HTTP verb,
|
||||||
|
# the URL path and the URL query.
|
||||||
|
HEADER_REQUEST_TARGET = '(request-target)'
|
||||||
|
# The time when the HTTP signature was generated.
|
||||||
|
HEADER_CREATED = '(created)'
|
||||||
|
# The time when the HTTP signature expires. The API server should reject HTTP requests
|
||||||
|
# that have expired.
|
||||||
|
HEADER_EXPIRES = '(expires)'
|
||||||
|
# The 'Host' header.
|
||||||
|
HEADER_HOST = 'Host'
|
||||||
|
# The 'Date' header.
|
||||||
|
HEADER_DATE = 'Date'
|
||||||
|
# When the 'Digest' header is included in the HTTP signature, the client automatically
|
||||||
|
# computes the digest of the HTTP request body, per RFC 3230.
|
||||||
|
HEADER_DIGEST = 'Digest'
|
||||||
|
# The 'Authorization' header is automatically generated by the client. It includes
|
||||||
|
# the list of signed headers and a base64-encoded signature.
|
||||||
|
HEADER_AUTHORIZATION = 'Authorization'
|
||||||
|
|
||||||
|
# The constants below define the cryptographic schemes for the HTTP signature scheme.
|
||||||
|
SCHEME_HS2019 = 'hs2019'
|
||||||
|
SCHEME_RSA_SHA256 = 'rsa-sha256'
|
||||||
|
SCHEME_RSA_SHA512 = 'rsa-sha512'
|
||||||
|
|
||||||
|
# The constants below define the signature algorithms that can be used for the HTTP
|
||||||
|
# signature scheme.
|
||||||
|
ALGORITHM_RSASSA_PSS = 'RSASSA-PSS'
|
||||||
|
ALGORITHM_RSASSA_PKCS1v15 = 'RSASSA-PKCS1-v1_5'
|
||||||
|
|
||||||
|
ALGORITHM_ECDSA_MODE_FIPS_186_3 = 'fips-186-3'
|
||||||
|
ALGORITHM_ECDSA_MODE_DETERMINISTIC_RFC6979 = 'deterministic-rfc6979'
|
||||||
|
ALGORITHM_ECDSA_KEY_SIGNING_ALGORITHMS = {
|
||||||
|
ALGORITHM_ECDSA_MODE_FIPS_186_3,
|
||||||
|
ALGORITHM_ECDSA_MODE_DETERMINISTIC_RFC6979
|
||||||
|
}
|
||||||
|
|
||||||
|
# The cryptographic hash algorithm for the message signature.
|
||||||
|
HASH_SHA256 = 'sha256'
|
||||||
|
HASH_SHA512 = 'sha512'
|
||||||
|
|
||||||
|
|
||||||
|
class HttpSigningConfiguration:
|
||||||
|
"""The configuration parameters for the HTTP signature security scheme.
|
||||||
|
The HTTP signature security scheme is used to sign HTTP requests with a private key
|
||||||
|
which is in possession of the API client.
|
||||||
|
An 'Authorization' header is calculated by creating a hash of select headers,
|
||||||
|
and optionally the body of the HTTP request, then signing the hash value using
|
||||||
|
a private key. The 'Authorization' header is added to outbound HTTP requests.
|
||||||
|
|
||||||
|
:param key_id: A string value specifying the identifier of the cryptographic key,
|
||||||
|
when signing HTTP requests.
|
||||||
|
:param signing_scheme: A string value specifying the signature scheme, when
|
||||||
|
signing HTTP requests.
|
||||||
|
Supported value are hs2019, rsa-sha256, rsa-sha512.
|
||||||
|
Avoid using rsa-sha256, rsa-sha512 as they are deprecated. These values are
|
||||||
|
available for server-side applications that only support the older
|
||||||
|
HTTP signature algorithms.
|
||||||
|
:param private_key_path: A string value specifying the path of the file containing
|
||||||
|
a private key. The private key is used to sign HTTP requests.
|
||||||
|
:param private_key_passphrase: A string value specifying the passphrase to decrypt
|
||||||
|
the private key.
|
||||||
|
:param signed_headers: A list of strings. Each value is the name of a HTTP header
|
||||||
|
that must be included in the HTTP signature calculation.
|
||||||
|
The two special signature headers '(request-target)' and '(created)' SHOULD be
|
||||||
|
included in SignedHeaders.
|
||||||
|
The '(created)' header expresses when the signature was created.
|
||||||
|
The '(request-target)' header is a concatenation of the lowercased :method, an
|
||||||
|
ASCII space, and the :path pseudo-headers.
|
||||||
|
When signed_headers is not specified, the client defaults to a single value,
|
||||||
|
'(created)', in the list of HTTP headers.
|
||||||
|
When SignedHeaders contains the 'Digest' value, the client performs the
|
||||||
|
following operations:
|
||||||
|
1. Calculate a digest of request body, as specified in RFC3230, section 4.3.2.
|
||||||
|
2. Set the 'Digest' header in the request body.
|
||||||
|
3. Include the 'Digest' header and value in the HTTP signature.
|
||||||
|
:param signing_algorithm: A string value specifying the signature algorithm, when
|
||||||
|
signing HTTP requests.
|
||||||
|
Supported values are:
|
||||||
|
1. For RSA keys: RSASSA-PSS, RSASSA-PKCS1-v1_5.
|
||||||
|
2. For ECDSA keys: fips-186-3, deterministic-rfc6979.
|
||||||
|
If None, the signing algorithm is inferred from the private key.
|
||||||
|
The default signing algorithm for RSA keys is RSASSA-PSS.
|
||||||
|
The default signing algorithm for ECDSA keys is fips-186-3.
|
||||||
|
:param hash_algorithm: The hash algorithm for the signature. Supported values are
|
||||||
|
sha256 and sha512.
|
||||||
|
If the signing_scheme is rsa-sha256, the hash algorithm must be set
|
||||||
|
to None or sha256.
|
||||||
|
If the signing_scheme is rsa-sha512, the hash algorithm must be set
|
||||||
|
to None or sha512.
|
||||||
|
:param signature_max_validity: The signature max validity, expressed as
|
||||||
|
a datetime.timedelta value. It must be a positive value.
|
||||||
|
"""
|
||||||
|
def __init__(self, key_id, signing_scheme, private_key_path,
|
||||||
|
private_key_passphrase=None,
|
||||||
|
signed_headers=None,
|
||||||
|
signing_algorithm=None,
|
||||||
|
hash_algorithm=None,
|
||||||
|
signature_max_validity=None) -> None:
|
||||||
|
self.key_id = key_id
|
||||||
|
if signing_scheme not in {SCHEME_HS2019, SCHEME_RSA_SHA256, SCHEME_RSA_SHA512}:
|
||||||
|
raise Exception("Unsupported security scheme: {0}".format(signing_scheme))
|
||||||
|
self.signing_scheme = signing_scheme
|
||||||
|
if not os.path.exists(private_key_path):
|
||||||
|
raise Exception("Private key file does not exist")
|
||||||
|
self.private_key_path = private_key_path
|
||||||
|
self.private_key_passphrase = private_key_passphrase
|
||||||
|
self.signing_algorithm = signing_algorithm
|
||||||
|
self.hash_algorithm = hash_algorithm
|
||||||
|
if signing_scheme == SCHEME_RSA_SHA256:
|
||||||
|
if self.hash_algorithm is None:
|
||||||
|
self.hash_algorithm = HASH_SHA256
|
||||||
|
elif self.hash_algorithm != HASH_SHA256:
|
||||||
|
raise Exception("Hash algorithm must be sha256 when security scheme is %s" %
|
||||||
|
SCHEME_RSA_SHA256)
|
||||||
|
elif signing_scheme == SCHEME_RSA_SHA512:
|
||||||
|
if self.hash_algorithm is None:
|
||||||
|
self.hash_algorithm = HASH_SHA512
|
||||||
|
elif self.hash_algorithm != HASH_SHA512:
|
||||||
|
raise Exception("Hash algorithm must be sha512 when security scheme is %s" %
|
||||||
|
SCHEME_RSA_SHA512)
|
||||||
|
elif signing_scheme == SCHEME_HS2019:
|
||||||
|
if self.hash_algorithm is None:
|
||||||
|
self.hash_algorithm = HASH_SHA256
|
||||||
|
elif self.hash_algorithm not in {HASH_SHA256, HASH_SHA512}:
|
||||||
|
raise Exception("Invalid hash algorithm")
|
||||||
|
if signature_max_validity is not None and signature_max_validity.total_seconds() < 0:
|
||||||
|
raise Exception("The signature max validity must be a positive value")
|
||||||
|
self.signature_max_validity = signature_max_validity
|
||||||
|
# If the user has not provided any signed_headers, the default must be set to '(created)',
|
||||||
|
# as specified in the 'HTTP signature' standard.
|
||||||
|
if signed_headers is None or len(signed_headers) == 0:
|
||||||
|
signed_headers = [HEADER_CREATED]
|
||||||
|
if self.signature_max_validity is None and HEADER_EXPIRES in signed_headers:
|
||||||
|
raise Exception(
|
||||||
|
"Signature max validity must be set when "
|
||||||
|
"'(expires)' signature parameter is specified")
|
||||||
|
if len(signed_headers) != len(set(signed_headers)):
|
||||||
|
raise Exception("Cannot have duplicates in the signed_headers parameter")
|
||||||
|
if HEADER_AUTHORIZATION in signed_headers:
|
||||||
|
raise Exception("'Authorization' header cannot be included in signed headers")
|
||||||
|
self.signed_headers = signed_headers
|
||||||
|
self.private_key = None
|
||||||
|
"""The private key used to sign HTTP requests.
|
||||||
|
Initialized when the PEM-encoded private key is loaded from a file.
|
||||||
|
"""
|
||||||
|
self.host = None
|
||||||
|
"""The host name, optionally followed by a colon and TCP port number.
|
||||||
|
"""
|
||||||
|
self._load_private_key()
|
||||||
|
|
||||||
|
def get_http_signature_headers(self, resource_path, method, headers, body, query_params):
|
||||||
|
"""Create a cryptographic message signature for the HTTP request and add the signed headers.
|
||||||
|
|
||||||
|
:param resource_path : A string representation of the HTTP request resource path.
|
||||||
|
:param method: A string representation of the HTTP request method, e.g. GET, POST.
|
||||||
|
:param headers: A dict containing the HTTP request headers.
|
||||||
|
:param body: The object representing the HTTP request body.
|
||||||
|
:param query_params: A string representing the HTTP request query parameters.
|
||||||
|
:return: A dict of HTTP headers that must be added to the outbound HTTP request.
|
||||||
|
"""
|
||||||
|
if method is None:
|
||||||
|
raise Exception("HTTP method must be set")
|
||||||
|
if resource_path is None:
|
||||||
|
raise Exception("Resource path must be set")
|
||||||
|
|
||||||
|
signed_headers_list, request_headers_dict = self._get_signed_header_info(
|
||||||
|
resource_path, method, headers, body, query_params)
|
||||||
|
|
||||||
|
header_items = [
|
||||||
|
"{0}: {1}".format(key.lower(), value) for key, value in signed_headers_list]
|
||||||
|
string_to_sign = "\n".join(header_items)
|
||||||
|
|
||||||
|
digest, digest_prefix = self._get_message_digest(string_to_sign.encode())
|
||||||
|
b64_signed_msg = self._sign_digest(digest)
|
||||||
|
|
||||||
|
request_headers_dict[HEADER_AUTHORIZATION] = self._get_authorization_header(
|
||||||
|
signed_headers_list, b64_signed_msg)
|
||||||
|
|
||||||
|
return request_headers_dict
|
||||||
|
|
||||||
|
def get_public_key(self):
|
||||||
|
"""Returns the public key object associated with the private key.
|
||||||
|
"""
|
||||||
|
pubkey = None
|
||||||
|
if isinstance(self.private_key, RSA.RsaKey):
|
||||||
|
pubkey = self.private_key.publickey()
|
||||||
|
elif isinstance(self.private_key, ECC.EccKey):
|
||||||
|
pubkey = self.private_key.public_key()
|
||||||
|
return pubkey
|
||||||
|
|
||||||
|
def _load_private_key(self):
|
||||||
|
"""Load the private key used to sign HTTP requests.
|
||||||
|
The private key is used to sign HTTP requests as defined in
|
||||||
|
https://datatracker.ietf.org/doc/draft-cavage-http-signatures/.
|
||||||
|
"""
|
||||||
|
if self.private_key is not None:
|
||||||
|
return
|
||||||
|
with open(self.private_key_path, 'r') as f:
|
||||||
|
pem_data = f.read()
|
||||||
|
# Verify PEM Pre-Encapsulation Boundary
|
||||||
|
r = re.compile(r"\s*-----BEGIN (.*)-----\s+")
|
||||||
|
m = r.match(pem_data)
|
||||||
|
if not m:
|
||||||
|
raise ValueError("Not a valid PEM pre boundary")
|
||||||
|
pem_header = m.group(1)
|
||||||
|
if pem_header == 'RSA PRIVATE KEY':
|
||||||
|
self.private_key = RSA.importKey(pem_data, self.private_key_passphrase)
|
||||||
|
elif pem_header == 'EC PRIVATE KEY':
|
||||||
|
self.private_key = ECC.import_key(pem_data, self.private_key_passphrase)
|
||||||
|
elif pem_header in {'PRIVATE KEY', 'ENCRYPTED PRIVATE KEY'}:
|
||||||
|
# Key is in PKCS8 format, which is capable of holding many different
|
||||||
|
# types of private keys, not just EC keys.
|
||||||
|
(key_binary, pem_header, is_encrypted) = \
|
||||||
|
PEM.decode(pem_data, self.private_key_passphrase)
|
||||||
|
(oid, privkey, params) = \
|
||||||
|
PKCS8.unwrap(key_binary, passphrase=self.private_key_passphrase)
|
||||||
|
if oid == '1.2.840.10045.2.1':
|
||||||
|
self.private_key = ECC.import_key(pem_data, self.private_key_passphrase)
|
||||||
|
else:
|
||||||
|
raise Exception("Unsupported key: {0}. OID: {1}".format(pem_header, oid))
|
||||||
|
else:
|
||||||
|
raise Exception("Unsupported key: {0}".format(pem_header))
|
||||||
|
# Validate the specified signature algorithm is compatible with the private key.
|
||||||
|
if self.signing_algorithm is not None:
|
||||||
|
supported_algs = None
|
||||||
|
if isinstance(self.private_key, RSA.RsaKey):
|
||||||
|
supported_algs = {ALGORITHM_RSASSA_PSS, ALGORITHM_RSASSA_PKCS1v15}
|
||||||
|
elif isinstance(self.private_key, ECC.EccKey):
|
||||||
|
supported_algs = ALGORITHM_ECDSA_KEY_SIGNING_ALGORITHMS
|
||||||
|
if supported_algs is not None and self.signing_algorithm not in supported_algs:
|
||||||
|
raise Exception(
|
||||||
|
"Signing algorithm {0} is not compatible with private key".format(
|
||||||
|
self.signing_algorithm))
|
||||||
|
|
||||||
|
def _get_signed_header_info(self, resource_path, method, headers, body, query_params):
|
||||||
|
"""Build the HTTP headers (name, value) that need to be included in
|
||||||
|
the HTTP signature scheme.
|
||||||
|
|
||||||
|
:param resource_path : A string representation of the HTTP request resource path.
|
||||||
|
:param method: A string representation of the HTTP request method, e.g. GET, POST.
|
||||||
|
:param headers: A dict containing the HTTP request headers.
|
||||||
|
:param body: The object (e.g. a dict) representing the HTTP request body.
|
||||||
|
:param query_params: A string representing the HTTP request query parameters.
|
||||||
|
:return: A tuple containing two dict objects:
|
||||||
|
The first dict contains the HTTP headers that are used to calculate
|
||||||
|
the HTTP signature.
|
||||||
|
The second dict contains the HTTP headers that must be added to
|
||||||
|
the outbound HTTP request.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if body is None:
|
||||||
|
body = ''
|
||||||
|
else:
|
||||||
|
body = body.to_json()
|
||||||
|
|
||||||
|
# Build the '(request-target)' HTTP signature parameter.
|
||||||
|
target_host = urlparse(self.host).netloc
|
||||||
|
target_path = urlparse(self.host).path
|
||||||
|
request_target = method.lower() + " " + target_path + resource_path
|
||||||
|
if query_params:
|
||||||
|
request_target += "?" + urlencode(query_params)
|
||||||
|
|
||||||
|
# Get UNIX time, e.g. seconds since epoch, not including leap seconds.
|
||||||
|
now = time()
|
||||||
|
# Format date per RFC 7231 section-7.1.1.2. An example is:
|
||||||
|
# Date: Wed, 21 Oct 2015 07:28:00 GMT
|
||||||
|
cdate = formatdate(timeval=now, localtime=False, usegmt=True)
|
||||||
|
# The '(created)' value MUST be a Unix timestamp integer value.
|
||||||
|
# Subsecond precision is not supported.
|
||||||
|
created = int(now)
|
||||||
|
if self.signature_max_validity is not None:
|
||||||
|
expires = now + self.signature_max_validity.total_seconds()
|
||||||
|
|
||||||
|
signed_headers_list = []
|
||||||
|
request_headers_dict = {}
|
||||||
|
for hdr_key in self.signed_headers:
|
||||||
|
hdr_key = hdr_key.lower()
|
||||||
|
if hdr_key == HEADER_REQUEST_TARGET:
|
||||||
|
value = request_target
|
||||||
|
elif hdr_key == HEADER_CREATED:
|
||||||
|
value = '{0}'.format(created)
|
||||||
|
elif hdr_key == HEADER_EXPIRES:
|
||||||
|
value = '{0}'.format(expires)
|
||||||
|
elif hdr_key == HEADER_DATE.lower():
|
||||||
|
value = cdate
|
||||||
|
request_headers_dict[HEADER_DATE] = '{0}'.format(cdate)
|
||||||
|
elif hdr_key == HEADER_DIGEST.lower():
|
||||||
|
request_body = body.encode()
|
||||||
|
body_digest, digest_prefix = self._get_message_digest(request_body)
|
||||||
|
b64_body_digest = b64encode(body_digest.digest())
|
||||||
|
value = digest_prefix + b64_body_digest.decode('ascii')
|
||||||
|
request_headers_dict[HEADER_DIGEST] = '{0}{1}'.format(
|
||||||
|
digest_prefix, b64_body_digest.decode('ascii'))
|
||||||
|
elif hdr_key == HEADER_HOST.lower():
|
||||||
|
value = target_host
|
||||||
|
request_headers_dict[HEADER_HOST] = '{0}'.format(target_host)
|
||||||
|
else:
|
||||||
|
value = next((v for k, v in headers.items() if k.lower() == hdr_key), None)
|
||||||
|
if value is None:
|
||||||
|
raise Exception(
|
||||||
|
"Cannot sign HTTP request. "
|
||||||
|
"Request does not contain the '{0}' header".format(hdr_key))
|
||||||
|
signed_headers_list.append((hdr_key, value))
|
||||||
|
|
||||||
|
return signed_headers_list, request_headers_dict
|
||||||
|
|
||||||
|
def _get_message_digest(self, data):
|
||||||
|
"""Calculates and returns a cryptographic digest of a specified HTTP request.
|
||||||
|
|
||||||
|
:param data: The string representation of the date to be hashed with a cryptographic hash.
|
||||||
|
:return: A tuple of (digest, prefix).
|
||||||
|
The digest is a hashing object that contains the cryptographic digest of
|
||||||
|
the HTTP request.
|
||||||
|
The prefix is a string that identifies the cryptographic hash. It is used
|
||||||
|
to generate the 'Digest' header as specified in RFC 3230.
|
||||||
|
"""
|
||||||
|
if self.hash_algorithm == HASH_SHA512:
|
||||||
|
digest = SHA512.new()
|
||||||
|
prefix = 'SHA-512='
|
||||||
|
elif self.hash_algorithm == HASH_SHA256:
|
||||||
|
digest = SHA256.new()
|
||||||
|
prefix = 'SHA-256='
|
||||||
|
else:
|
||||||
|
raise Exception("Unsupported hash algorithm: {0}".format(self.hash_algorithm))
|
||||||
|
digest.update(data)
|
||||||
|
return digest, prefix
|
||||||
|
|
||||||
|
def _sign_digest(self, digest):
|
||||||
|
"""Signs a message digest with a private key specified in the signing_info.
|
||||||
|
|
||||||
|
:param digest: A hashing object that contains the cryptographic digest of the HTTP request.
|
||||||
|
:return: A base-64 string representing the cryptographic signature of the input digest.
|
||||||
|
"""
|
||||||
|
sig_alg = self.signing_algorithm
|
||||||
|
if isinstance(self.private_key, RSA.RsaKey):
|
||||||
|
if sig_alg is None or sig_alg == ALGORITHM_RSASSA_PSS:
|
||||||
|
# RSASSA-PSS in Section 8.1 of RFC8017.
|
||||||
|
signature = pss.new(self.private_key).sign(digest)
|
||||||
|
elif sig_alg == ALGORITHM_RSASSA_PKCS1v15:
|
||||||
|
# RSASSA-PKCS1-v1_5 in Section 8.2 of RFC8017.
|
||||||
|
signature = PKCS1_v1_5.new(self.private_key).sign(digest)
|
||||||
|
else:
|
||||||
|
raise Exception("Unsupported signature algorithm: {0}".format(sig_alg))
|
||||||
|
elif isinstance(self.private_key, ECC.EccKey):
|
||||||
|
if sig_alg is None:
|
||||||
|
sig_alg = ALGORITHM_ECDSA_MODE_FIPS_186_3
|
||||||
|
if sig_alg in ALGORITHM_ECDSA_KEY_SIGNING_ALGORITHMS:
|
||||||
|
# draft-ietf-httpbis-message-signatures-00 does not specify the ECDSA encoding.
|
||||||
|
# Issue: https://github.com/w3c-ccg/http-signatures/issues/107
|
||||||
|
signature = DSS.new(key=self.private_key, mode=sig_alg,
|
||||||
|
encoding='der').sign(digest)
|
||||||
|
else:
|
||||||
|
raise Exception("Unsupported signature algorithm: {0}".format(sig_alg))
|
||||||
|
else:
|
||||||
|
raise Exception("Unsupported private key: {0}".format(type(self.private_key)))
|
||||||
|
return b64encode(signature)
|
||||||
|
|
||||||
|
def _get_authorization_header(self, signed_headers, signed_msg):
|
||||||
|
"""Calculates and returns the value of the 'Authorization' header when signing HTTP requests.
|
||||||
|
|
||||||
|
:param signed_headers : A list of tuples. Each value is the name of a HTTP header that
|
||||||
|
must be included in the HTTP signature calculation.
|
||||||
|
:param signed_msg: A base-64 encoded string representation of the signature.
|
||||||
|
:return: The string value of the 'Authorization' header, representing the signature
|
||||||
|
of the HTTP request.
|
||||||
|
"""
|
||||||
|
created_ts = None
|
||||||
|
expires_ts = None
|
||||||
|
for k, v in signed_headers:
|
||||||
|
if k == HEADER_CREATED:
|
||||||
|
created_ts = v
|
||||||
|
elif k == HEADER_EXPIRES:
|
||||||
|
expires_ts = v
|
||||||
|
lower_keys = [k.lower() for k, v in signed_headers]
|
||||||
|
headers_value = " ".join(lower_keys)
|
||||||
|
|
||||||
|
auth_str = "Signature keyId=\"{0}\",algorithm=\"{1}\",".format(
|
||||||
|
self.key_id, self.signing_scheme)
|
||||||
|
if created_ts is not None:
|
||||||
|
auth_str = auth_str + "created={0},".format(created_ts)
|
||||||
|
if expires_ts is not None:
|
||||||
|
auth_str = auth_str + "expires={0},".format(expires_ts)
|
||||||
|
auth_str = auth_str + "headers=\"{0}\",signature=\"{1}\"".format(
|
||||||
|
headers_value, signed_msg.decode('ascii'))
|
||||||
|
|
||||||
|
return auth_str
|
3
modules/openapi-generator/src/main/resources/python-pydantic-v1/test-requirements.mustache
vendored
Normal file
3
modules/openapi-generator/src/main/resources/python-pydantic-v1/test-requirements.mustache
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pytest~=7.1.3
|
||||||
|
pytest-cov>=2.8.1
|
||||||
|
pytest-randomly>=3.12.0
|
223
modules/openapi-generator/src/main/resources/python-pydantic-v1/tornado/rest.mustache
vendored
Normal file
223
modules/openapi-generator/src/main/resources/python-pydantic-v1/tornado/rest.mustache
vendored
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
{{>partial_header}}
|
||||||
|
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
|
from urllib.parse import urlencode, quote_plus
|
||||||
|
import tornado
|
||||||
|
import tornado.gen
|
||||||
|
from tornado import httpclient
|
||||||
|
from urllib3.filepost import encode_multipart_formdata
|
||||||
|
|
||||||
|
from {{packageName}}.exceptions import ApiException, ApiValueError
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
|
def __init__(self, resp) -> None:
|
||||||
|
self.tornado_response = resp
|
||||||
|
self.status = resp.code
|
||||||
|
self.reason = resp.reason
|
||||||
|
|
||||||
|
if resp.body:
|
||||||
|
self.data = resp.body
|
||||||
|
else:
|
||||||
|
self.data = None
|
||||||
|
|
||||||
|
def getheaders(self):
|
||||||
|
"""Returns a CIMultiDictProxy of the response headers."""
|
||||||
|
return self.tornado_response.headers
|
||||||
|
|
||||||
|
def getheader(self, name, default=None):
|
||||||
|
"""Returns a given response header."""
|
||||||
|
return self.tornado_response.headers.get(name, default)
|
||||||
|
|
||||||
|
|
||||||
|
class RESTClientObject:
|
||||||
|
|
||||||
|
def __init__(self, configuration, pools_size=4, maxsize=4) -> None:
|
||||||
|
# maxsize is number of requests to host that are allowed in parallel
|
||||||
|
|
||||||
|
self.ca_certs = configuration.ssl_ca_cert
|
||||||
|
self.client_key = configuration.key_file
|
||||||
|
self.client_cert = configuration.cert_file
|
||||||
|
|
||||||
|
self.proxy_port = self.proxy_host = None
|
||||||
|
|
||||||
|
# https pool manager
|
||||||
|
if configuration.proxy:
|
||||||
|
self.proxy_port = 80
|
||||||
|
self.proxy_host = configuration.proxy
|
||||||
|
|
||||||
|
self.pool_manager = httpclient.AsyncHTTPClient()
|
||||||
|
|
||||||
|
@tornado.gen.coroutine
|
||||||
|
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."
|
||||||
|
)
|
||||||
|
|
||||||
|
request = httpclient.HTTPRequest(url)
|
||||||
|
request.allow_nonstandard_methods = True
|
||||||
|
request.ca_certs = self.ca_certs
|
||||||
|
request.client_key = self.client_key
|
||||||
|
request.client_cert = self.client_cert
|
||||||
|
request.proxy_host = self.proxy_host
|
||||||
|
request.proxy_port = self.proxy_port
|
||||||
|
request.method = method
|
||||||
|
if headers:
|
||||||
|
request.headers = headers
|
||||||
|
if 'Content-Type' not in headers:
|
||||||
|
request.headers['Content-Type'] = 'application/json'
|
||||||
|
request.request_timeout = _request_timeout or 5 * 60
|
||||||
|
|
||||||
|
post_params = post_params or {}
|
||||||
|
|
||||||
|
if query_params:
|
||||||
|
request.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:
|
||||||
|
body = json.dumps(body)
|
||||||
|
request.body = body
|
||||||
|
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
|
||||||
|
request.body = urlencode(post_params)
|
||||||
|
elif headers['Content-Type'] == 'multipart/form-data':
|
||||||
|
multipart = encode_multipart_formdata(post_params)
|
||||||
|
request.body, headers['Content-Type'] = multipart
|
||||||
|
# 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):
|
||||||
|
request.body = 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 = yield self.pool_manager.fetch(request, raise_error=False)
|
||||||
|
|
||||||
|
if _preload_content:
|
||||||
|
|
||||||
|
r = RESTResponse(r)
|
||||||
|
|
||||||
|
# log response body
|
||||||
|
logger.debug("response body: %s", r.data)
|
||||||
|
|
||||||
|
if not 200 <= r.status <= 299:
|
||||||
|
raise ApiException(http_resp=r)
|
||||||
|
|
||||||
|
raise tornado.gen.Return(r)
|
||||||
|
|
||||||
|
@tornado.gen.coroutine
|
||||||
|
def GET(self, url, headers=None, query_params=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
|
result = yield self.request("GET", url,
|
||||||
|
headers=headers,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
query_params=query_params)
|
||||||
|
raise tornado.gen.Return(result)
|
||||||
|
|
||||||
|
@tornado.gen.coroutine
|
||||||
|
def HEAD(self, url, headers=None, query_params=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
|
result = yield self.request("HEAD", url,
|
||||||
|
headers=headers,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
query_params=query_params)
|
||||||
|
raise tornado.gen.Return(result)
|
||||||
|
|
||||||
|
@tornado.gen.coroutine
|
||||||
|
def OPTIONS(self, url, headers=None, query_params=None, post_params=None,
|
||||||
|
body=None, _preload_content=True, _request_timeout=None):
|
||||||
|
result = yield self.request("OPTIONS", url,
|
||||||
|
headers=headers,
|
||||||
|
query_params=query_params,
|
||||||
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
body=body)
|
||||||
|
raise tornado.gen.Return(result)
|
||||||
|
|
||||||
|
@tornado.gen.coroutine
|
||||||
|
def DELETE(self, url, headers=None, query_params=None, body=None,
|
||||||
|
_preload_content=True, _request_timeout=None):
|
||||||
|
result = yield self.request("DELETE", url,
|
||||||
|
headers=headers,
|
||||||
|
query_params=query_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
body=body)
|
||||||
|
raise tornado.gen.Return(result)
|
||||||
|
|
||||||
|
@tornado.gen.coroutine
|
||||||
|
def POST(self, url, headers=None, query_params=None, post_params=None,
|
||||||
|
body=None, _preload_content=True, _request_timeout=None):
|
||||||
|
result = yield self.request("POST", url,
|
||||||
|
headers=headers,
|
||||||
|
query_params=query_params,
|
||||||
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
body=body)
|
||||||
|
raise tornado.gen.Return(result)
|
||||||
|
|
||||||
|
@tornado.gen.coroutine
|
||||||
|
def PUT(self, url, headers=None, query_params=None, post_params=None,
|
||||||
|
body=None, _preload_content=True, _request_timeout=None):
|
||||||
|
result = yield self.request("PUT", url,
|
||||||
|
headers=headers,
|
||||||
|
query_params=query_params,
|
||||||
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
body=body)
|
||||||
|
raise tornado.gen.Return(result)
|
||||||
|
|
||||||
|
@tornado.gen.coroutine
|
||||||
|
def PATCH(self, url, headers=None, query_params=None, post_params=None,
|
||||||
|
body=None, _preload_content=True, _request_timeout=None):
|
||||||
|
result = yield self.request("PATCH", url,
|
||||||
|
headers=headers,
|
||||||
|
query_params=query_params,
|
||||||
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
body=body)
|
||||||
|
raise tornado.gen.Return(result)
|
9
modules/openapi-generator/src/main/resources/python-pydantic-v1/tox.mustache
vendored
Normal file
9
modules/openapi-generator/src/main/resources/python-pydantic-v1/tox.mustache
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[tox]
|
||||||
|
envlist = py3
|
||||||
|
|
||||||
|
[testenv]
|
||||||
|
deps=-r{toxinidir}/requirements.txt
|
||||||
|
-r{toxinidir}/test-requirements.txt
|
||||||
|
|
||||||
|
commands=
|
||||||
|
pytest --cov={{{packageName}}}
|
17
modules/openapi-generator/src/main/resources/python-pydantic-v1/travis.mustache
vendored
Normal file
17
modules/openapi-generator/src/main/resources/python-pydantic-v1/travis.mustache
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# ref: https://docs.travis-ci.com/user/languages/python
|
||||||
|
language: python
|
||||||
|
python:
|
||||||
|
- "3.7"
|
||||||
|
- "3.8"
|
||||||
|
- "3.9"
|
||||||
|
- "3.10"
|
||||||
|
- "3.11"
|
||||||
|
# uncomment the following if needed
|
||||||
|
#- "3.11-dev" # 3.11 development branch
|
||||||
|
#- "nightly" # nightly build
|
||||||
|
# command to install dependencies
|
||||||
|
install:
|
||||||
|
- "pip install -r requirements.txt"
|
||||||
|
- "pip install -r test-requirements.txt"
|
||||||
|
# command to run tests
|
||||||
|
script: pytest --cov={{{packageName}}}
|
59
samples-python-pydantic-v1-petstore.yaml
Normal file
59
samples-python-pydantic-v1-petstore.yaml
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
name: "Python Client: Petstore"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- samples/openapi3/client/petstore/python-aiohttp/**
|
||||||
|
- samples/openapi3/client/petstore/python/**
|
||||||
|
- .github/workflows/samples-python-petstore.yaml
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Test Python client
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
python-version:
|
||||||
|
- "3.7"
|
||||||
|
- "3.8"
|
||||||
|
- "3.9"
|
||||||
|
- "3.10"
|
||||||
|
- "3.11"
|
||||||
|
sample:
|
||||||
|
- samples/openapi3/client/petstore/python-aiohttp
|
||||||
|
- samples/openapi3/client/petstore/python
|
||||||
|
services:
|
||||||
|
petstore-api:
|
||||||
|
image: swaggerapi/petstore
|
||||||
|
ports:
|
||||||
|
- 80:8080
|
||||||
|
env:
|
||||||
|
SWAGGER_HOST: http://petstore.swagger.io
|
||||||
|
SWAGGER_BASE_PATH: /v2
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-python@v4
|
||||||
|
id: py
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
|
- name: Cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
key: ${{ runner.os }}-python-${{ steps.py.outputs.python-version }}-
|
||||||
|
path: |
|
||||||
|
~/.cache/pypoetry/virtualenvs/
|
||||||
|
~/.local/pipx/venvs/poetry/
|
||||||
|
.mypy_cache/
|
||||||
|
|
||||||
|
- name: Install poetry
|
||||||
|
run: pipx install --python '${{ steps.py.outputs.python-path }}' poetry
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
working-directory: ${{ matrix.sample }}
|
||||||
|
run: poetry install
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
working-directory: ${{ matrix.sample }}
|
||||||
|
run: poetry run pytest -v
|
38
samples/client/echo_api/python-pydantic-v1/.github/workflows/python.yml
vendored
Normal file
38
samples/client/echo_api/python-pydantic-v1/.github/workflows/python.yml
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# NOTE: This file is auto generated by OpenAPI Generator.
|
||||||
|
# URL: https://openapi-generator.tech
|
||||||
|
#
|
||||||
|
# ref: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
||||||
|
|
||||||
|
name: openapi_client Python package
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install flake8 pytest
|
||||||
|
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||||
|
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
|
||||||
|
- name: Lint with flake8
|
||||||
|
run: |
|
||||||
|
# stop the build if there are Python syntax errors or undefined names
|
||||||
|
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||||
|
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||||
|
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||||
|
- name: Test with pytest
|
||||||
|
run: |
|
||||||
|
pytest
|
66
samples/client/echo_api/python-pydantic-v1/.gitignore
vendored
Normal file
66
samples/client/echo_api/python-pydantic-v1/.gitignore
vendored
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
env/
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*,cover
|
||||||
|
.hypothesis/
|
||||||
|
venv/
|
||||||
|
.venv/
|
||||||
|
.python-version
|
||||||
|
.pytest_cache
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
#Ipython Notebook
|
||||||
|
.ipynb_checkpoints
|
31
samples/client/echo_api/python-pydantic-v1/.gitlab-ci.yml
Normal file
31
samples/client/echo_api/python-pydantic-v1/.gitlab-ci.yml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# NOTE: This file is auto generated by OpenAPI Generator.
|
||||||
|
# URL: https://openapi-generator.tech
|
||||||
|
#
|
||||||
|
# ref: https://docs.gitlab.com/ee/ci/README.html
|
||||||
|
# ref: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- test
|
||||||
|
|
||||||
|
.pytest:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- pip install -r requirements.txt
|
||||||
|
- pip install -r test-requirements.txt
|
||||||
|
- pytest --cov=openapi_client
|
||||||
|
|
||||||
|
pytest-3.7:
|
||||||
|
extends: .pytest
|
||||||
|
image: python:3.7-alpine
|
||||||
|
pytest-3.8:
|
||||||
|
extends: .pytest
|
||||||
|
image: python:3.8-alpine
|
||||||
|
pytest-3.9:
|
||||||
|
extends: .pytest
|
||||||
|
image: python:3.9-alpine
|
||||||
|
pytest-3.10:
|
||||||
|
extends: .pytest
|
||||||
|
image: python:3.10-alpine
|
||||||
|
pytest-3.11:
|
||||||
|
extends: .pytest
|
||||||
|
image: python:3.11-alpine
|
@ -0,0 +1,23 @@
|
|||||||
|
# OpenAPI Generator Ignore
|
||||||
|
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
@ -0,0 +1,56 @@
|
|||||||
|
.github/workflows/python.yml
|
||||||
|
.gitignore
|
||||||
|
.gitlab-ci.yml
|
||||||
|
.travis.yml
|
||||||
|
README.md
|
||||||
|
docs/AuthApi.md
|
||||||
|
docs/Bird.md
|
||||||
|
docs/BodyApi.md
|
||||||
|
docs/Category.md
|
||||||
|
docs/DataQuery.md
|
||||||
|
docs/DefaultValue.md
|
||||||
|
docs/FormApi.md
|
||||||
|
docs/HeaderApi.md
|
||||||
|
docs/NumberPropertiesOnly.md
|
||||||
|
docs/PathApi.md
|
||||||
|
docs/Pet.md
|
||||||
|
docs/Query.md
|
||||||
|
docs/QueryApi.md
|
||||||
|
docs/StringEnumRef.md
|
||||||
|
docs/Tag.md
|
||||||
|
docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md
|
||||||
|
docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md
|
||||||
|
git_push.sh
|
||||||
|
openapi_client/__init__.py
|
||||||
|
openapi_client/api/__init__.py
|
||||||
|
openapi_client/api/auth_api.py
|
||||||
|
openapi_client/api/body_api.py
|
||||||
|
openapi_client/api/form_api.py
|
||||||
|
openapi_client/api/header_api.py
|
||||||
|
openapi_client/api/path_api.py
|
||||||
|
openapi_client/api/query_api.py
|
||||||
|
openapi_client/api_client.py
|
||||||
|
openapi_client/api_response.py
|
||||||
|
openapi_client/configuration.py
|
||||||
|
openapi_client/exceptions.py
|
||||||
|
openapi_client/models/__init__.py
|
||||||
|
openapi_client/models/bird.py
|
||||||
|
openapi_client/models/category.py
|
||||||
|
openapi_client/models/data_query.py
|
||||||
|
openapi_client/models/default_value.py
|
||||||
|
openapi_client/models/number_properties_only.py
|
||||||
|
openapi_client/models/pet.py
|
||||||
|
openapi_client/models/query.py
|
||||||
|
openapi_client/models/string_enum_ref.py
|
||||||
|
openapi_client/models/tag.py
|
||||||
|
openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py
|
||||||
|
openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py
|
||||||
|
openapi_client/py.typed
|
||||||
|
openapi_client/rest.py
|
||||||
|
pyproject.toml
|
||||||
|
requirements.txt
|
||||||
|
setup.cfg
|
||||||
|
setup.py
|
||||||
|
test-requirements.txt
|
||||||
|
test/__init__.py
|
||||||
|
tox.ini
|
@ -0,0 +1 @@
|
|||||||
|
7.1.0-SNAPSHOT
|
17
samples/client/echo_api/python-pydantic-v1/.travis.yml
Normal file
17
samples/client/echo_api/python-pydantic-v1/.travis.yml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# ref: https://docs.travis-ci.com/user/languages/python
|
||||||
|
language: python
|
||||||
|
python:
|
||||||
|
- "3.7"
|
||||||
|
- "3.8"
|
||||||
|
- "3.9"
|
||||||
|
- "3.10"
|
||||||
|
- "3.11"
|
||||||
|
# uncomment the following if needed
|
||||||
|
#- "3.11-dev" # 3.11 development branch
|
||||||
|
#- "nightly" # nightly build
|
||||||
|
# command to install dependencies
|
||||||
|
install:
|
||||||
|
- "pip install -r requirements.txt"
|
||||||
|
- "pip install -r test-requirements.txt"
|
||||||
|
# command to run tests
|
||||||
|
script: pytest --cov=openapi_client
|
149
samples/client/echo_api/python-pydantic-v1/README.md
Normal file
149
samples/client/echo_api/python-pydantic-v1/README.md
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
# openapi-client
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||||
|
|
||||||
|
- API version: 0.1.0
|
||||||
|
- Package version: 1.0.0
|
||||||
|
- Build package: org.openapitools.codegen.languages.PythonClientPydanticV1Codegen
|
||||||
|
|
||||||
|
## Requirements.
|
||||||
|
|
||||||
|
Python 3.7+
|
||||||
|
|
||||||
|
## Installation & Usage
|
||||||
|
### pip install
|
||||||
|
|
||||||
|
If the python package is hosted on a repository, you can install directly using:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git
|
||||||
|
```
|
||||||
|
(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git`)
|
||||||
|
|
||||||
|
Then import the package:
|
||||||
|
```python
|
||||||
|
import openapi_client
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setuptools
|
||||||
|
|
||||||
|
Install via [Setuptools](http://pypi.python.org/pypi/setuptools).
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python setup.py install --user
|
||||||
|
```
|
||||||
|
(or `sudo python setup.py install` to install the package for all users)
|
||||||
|
|
||||||
|
Then import the package:
|
||||||
|
```python
|
||||||
|
import openapi_client
|
||||||
|
```
|
||||||
|
|
||||||
|
### Tests
|
||||||
|
|
||||||
|
Execute `pytest` to run the tests.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Please follow the [installation procedure](#installation--usage) and then run the following:
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
import time
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
# The client must configure the authentication and authorization parameters
|
||||||
|
# in accordance with the API server security policy.
|
||||||
|
# Examples for each auth method are provided below, use the example that
|
||||||
|
# satisfies your auth use case.
|
||||||
|
|
||||||
|
# Configure HTTP basic authorization: http_auth
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
username = os.environ["USERNAME"],
|
||||||
|
password = os.environ["PASSWORD"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.AuthApi(api_client)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# To test HTTP basic authentication
|
||||||
|
api_response = api_instance.test_auth_http_basic()
|
||||||
|
print("The response of AuthApi->test_auth_http_basic:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except ApiException as e:
|
||||||
|
print("Exception when calling AuthApi->test_auth_http_basic: %s\n" % e)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Documentation for API Endpoints
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost:3000*
|
||||||
|
|
||||||
|
Class | Method | HTTP request | Description
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
*AuthApi* | [**test_auth_http_basic**](docs/AuthApi.md#test_auth_http_basic) | **POST** /auth/http/basic | To test HTTP basic authentication
|
||||||
|
*BodyApi* | [**test_binary_gif**](docs/BodyApi.md#test_binary_gif) | **POST** /binary/gif | Test binary (gif) response body
|
||||||
|
*BodyApi* | [**test_body_application_octetstream_binary**](docs/BodyApi.md#test_body_application_octetstream_binary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
|
||||||
|
*BodyApi* | [**test_body_multipart_formdata_array_of_binary**](docs/BodyApi.md#test_body_multipart_formdata_array_of_binary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
|
||||||
|
*BodyApi* | [**test_echo_body_free_form_object_response_string**](docs/BodyApi.md#test_echo_body_free_form_object_response_string) | **POST** /echo/body/FreeFormObject/response_string | Test free form object
|
||||||
|
*BodyApi* | [**test_echo_body_pet**](docs/BodyApi.md#test_echo_body_pet) | **POST** /echo/body/Pet | Test body parameter(s)
|
||||||
|
*BodyApi* | [**test_echo_body_pet_response_string**](docs/BodyApi.md#test_echo_body_pet_response_string) | **POST** /echo/body/Pet/response_string | Test empty response body
|
||||||
|
*BodyApi* | [**test_echo_body_tag_response_string**](docs/BodyApi.md#test_echo_body_tag_response_string) | **POST** /echo/body/Tag/response_string | Test empty json (request body)
|
||||||
|
*FormApi* | [**test_form_integer_boolean_string**](docs/FormApi.md#test_form_integer_boolean_string) | **POST** /form/integer/boolean/string | Test form parameter(s)
|
||||||
|
*FormApi* | [**test_form_oneof**](docs/FormApi.md#test_form_oneof) | **POST** /form/oneof | Test form parameter(s) for oneOf schema
|
||||||
|
*HeaderApi* | [**test_header_integer_boolean_string**](docs/HeaderApi.md#test_header_integer_boolean_string) | **GET** /header/integer/boolean/string | Test header parameter(s)
|
||||||
|
*PathApi* | [**tests_path_string_path_string_integer_path_integer**](docs/PathApi.md#tests_path_string_path_string_integer_path_integer) | **GET** /path/string/{path_string}/integer/{path_integer} | Test path parameter(s)
|
||||||
|
*QueryApi* | [**test_enum_ref_string**](docs/QueryApi.md#test_enum_ref_string) | **GET** /query/enum_ref_string | Test query parameter(s)
|
||||||
|
*QueryApi* | [**test_query_datetime_date_string**](docs/QueryApi.md#test_query_datetime_date_string) | **GET** /query/datetime/date/string | Test query parameter(s)
|
||||||
|
*QueryApi* | [**test_query_integer_boolean_string**](docs/QueryApi.md#test_query_integer_boolean_string) | **GET** /query/integer/boolean/string | Test query parameter(s)
|
||||||
|
*QueryApi* | [**test_query_style_deep_object_explode_true_object**](docs/QueryApi.md#test_query_style_deep_object_explode_true_object) | **GET** /query/style_deepObject/explode_true/object | Test query parameter(s)
|
||||||
|
*QueryApi* | [**test_query_style_deep_object_explode_true_object_all_of**](docs/QueryApi.md#test_query_style_deep_object_explode_true_object_all_of) | **GET** /query/style_deepObject/explode_true/object/allOf | Test query parameter(s)
|
||||||
|
*QueryApi* | [**test_query_style_form_explode_true_array_string**](docs/QueryApi.md#test_query_style_form_explode_true_array_string) | **GET** /query/style_form/explode_true/array_string | Test query parameter(s)
|
||||||
|
*QueryApi* | [**test_query_style_form_explode_true_object**](docs/QueryApi.md#test_query_style_form_explode_true_object) | **GET** /query/style_form/explode_true/object | Test query parameter(s)
|
||||||
|
*QueryApi* | [**test_query_style_form_explode_true_object_all_of**](docs/QueryApi.md#test_query_style_form_explode_true_object_all_of) | **GET** /query/style_form/explode_true/object/allOf | Test query parameter(s)
|
||||||
|
|
||||||
|
|
||||||
|
## Documentation For Models
|
||||||
|
|
||||||
|
- [Bird](docs/Bird.md)
|
||||||
|
- [Category](docs/Category.md)
|
||||||
|
- [DataQuery](docs/DataQuery.md)
|
||||||
|
- [DefaultValue](docs/DefaultValue.md)
|
||||||
|
- [NumberPropertiesOnly](docs/NumberPropertiesOnly.md)
|
||||||
|
- [Pet](docs/Pet.md)
|
||||||
|
- [Query](docs/Query.md)
|
||||||
|
- [StringEnumRef](docs/StringEnumRef.md)
|
||||||
|
- [Tag](docs/Tag.md)
|
||||||
|
- [TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter](docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md)
|
||||||
|
- [TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter](docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md)
|
||||||
|
|
||||||
|
|
||||||
|
<a id="documentation-for-authorization"></a>
|
||||||
|
## Documentation For Authorization
|
||||||
|
|
||||||
|
|
||||||
|
Authentication schemes defined for the API:
|
||||||
|
<a id="http_auth"></a>
|
||||||
|
### http_auth
|
||||||
|
|
||||||
|
- **Type**: HTTP basic authentication
|
||||||
|
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
team@openapitools.org
|
||||||
|
|
||||||
|
|
82
samples/client/echo_api/python-pydantic-v1/docs/AuthApi.md
Normal file
82
samples/client/echo_api/python-pydantic-v1/docs/AuthApi.md
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
# openapi_client.AuthApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost:3000*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**test_auth_http_basic**](AuthApi.md#test_auth_http_basic) | **POST** /auth/http/basic | To test HTTP basic authentication
|
||||||
|
|
||||||
|
|
||||||
|
# **test_auth_http_basic**
|
||||||
|
> str test_auth_http_basic()
|
||||||
|
|
||||||
|
To test HTTP basic authentication
|
||||||
|
|
||||||
|
To test HTTP basic authentication
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
* Basic Authentication (http_auth):
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
# The client must configure the authentication and authorization parameters
|
||||||
|
# in accordance with the API server security policy.
|
||||||
|
# Examples for each auth method are provided below, use the example that
|
||||||
|
# satisfies your auth use case.
|
||||||
|
|
||||||
|
# Configure HTTP basic authorization: http_auth
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
username = os.environ["USERNAME"],
|
||||||
|
password = os.environ["PASSWORD"]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.AuthApi(api_client)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# To test HTTP basic authentication
|
||||||
|
api_response = api_instance.test_auth_http_basic()
|
||||||
|
print("The response of AuthApi->test_auth_http_basic:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling AuthApi->test_auth_http_basic: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
This endpoint does not need any parameter.
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
[http_auth](../README.md#http_auth)
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
29
samples/client/echo_api/python-pydantic-v1/docs/Bird.md
Normal file
29
samples/client/echo_api/python-pydantic-v1/docs/Bird.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Bird
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**size** | **str** | | [optional]
|
||||||
|
**color** | **str** | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_client.models.bird import Bird
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of Bird from a JSON string
|
||||||
|
bird_instance = Bird.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print Bird.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
bird_dict = bird_instance.to_dict()
|
||||||
|
# create an instance of Bird from a dict
|
||||||
|
bird_form_dict = bird.from_dict(bird_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
476
samples/client/echo_api/python-pydantic-v1/docs/BodyApi.md
Normal file
476
samples/client/echo_api/python-pydantic-v1/docs/BodyApi.md
Normal file
@ -0,0 +1,476 @@
|
|||||||
|
# openapi_client.BodyApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost:3000*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**test_binary_gif**](BodyApi.md#test_binary_gif) | **POST** /binary/gif | Test binary (gif) response body
|
||||||
|
[**test_body_application_octetstream_binary**](BodyApi.md#test_body_application_octetstream_binary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
|
||||||
|
[**test_body_multipart_formdata_array_of_binary**](BodyApi.md#test_body_multipart_formdata_array_of_binary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
|
||||||
|
[**test_echo_body_free_form_object_response_string**](BodyApi.md#test_echo_body_free_form_object_response_string) | **POST** /echo/body/FreeFormObject/response_string | Test free form object
|
||||||
|
[**test_echo_body_pet**](BodyApi.md#test_echo_body_pet) | **POST** /echo/body/Pet | Test body parameter(s)
|
||||||
|
[**test_echo_body_pet_response_string**](BodyApi.md#test_echo_body_pet_response_string) | **POST** /echo/body/Pet/response_string | Test empty response body
|
||||||
|
[**test_echo_body_tag_response_string**](BodyApi.md#test_echo_body_tag_response_string) | **POST** /echo/body/Tag/response_string | Test empty json (request body)
|
||||||
|
|
||||||
|
|
||||||
|
# **test_binary_gif**
|
||||||
|
> bytearray test_binary_gif()
|
||||||
|
|
||||||
|
Test binary (gif) response body
|
||||||
|
|
||||||
|
Test binary (gif) response body
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.BodyApi(api_client)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test binary (gif) response body
|
||||||
|
api_response = api_instance.test_binary_gif()
|
||||||
|
print("The response of BodyApi->test_binary_gif:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling BodyApi->test_binary_gif: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
This endpoint does not need any parameter.
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**bytearray**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: image/gif
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_body_application_octetstream_binary**
|
||||||
|
> str test_body_application_octetstream_binary(body=body)
|
||||||
|
|
||||||
|
Test body parameter(s)
|
||||||
|
|
||||||
|
Test body parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.BodyApi(api_client)
|
||||||
|
body = None # bytearray | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test body parameter(s)
|
||||||
|
api_response = api_instance.test_body_application_octetstream_binary(body=body)
|
||||||
|
print("The response of BodyApi->test_body_application_octetstream_binary:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling BodyApi->test_body_application_octetstream_binary: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**body** | **bytearray**| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: application/octet-stream
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_body_multipart_formdata_array_of_binary**
|
||||||
|
> str test_body_multipart_formdata_array_of_binary(files)
|
||||||
|
|
||||||
|
Test array of binary in multipart mime
|
||||||
|
|
||||||
|
Test array of binary in multipart mime
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.BodyApi(api_client)
|
||||||
|
files = None # List[bytearray] |
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test array of binary in multipart mime
|
||||||
|
api_response = api_instance.test_body_multipart_formdata_array_of_binary(files)
|
||||||
|
print("The response of BodyApi->test_body_multipart_formdata_array_of_binary:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling BodyApi->test_body_multipart_formdata_array_of_binary: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**files** | **List[bytearray]**| |
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: multipart/form-data
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_echo_body_free_form_object_response_string**
|
||||||
|
> str test_echo_body_free_form_object_response_string(body=body)
|
||||||
|
|
||||||
|
Test free form object
|
||||||
|
|
||||||
|
Test free form object
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.BodyApi(api_client)
|
||||||
|
body = None # object | Free form object (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test free form object
|
||||||
|
api_response = api_instance.test_echo_body_free_form_object_response_string(body=body)
|
||||||
|
print("The response of BodyApi->test_echo_body_free_form_object_response_string:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling BodyApi->test_echo_body_free_form_object_response_string: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**body** | **object**| Free form object | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: application/json
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_echo_body_pet**
|
||||||
|
> Pet test_echo_body_pet(pet=pet)
|
||||||
|
|
||||||
|
Test body parameter(s)
|
||||||
|
|
||||||
|
Test body parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.models.pet import Pet
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.BodyApi(api_client)
|
||||||
|
pet = openapi_client.Pet() # Pet | Pet object that needs to be added to the store (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test body parameter(s)
|
||||||
|
api_response = api_instance.test_echo_body_pet(pet=pet)
|
||||||
|
print("The response of BodyApi->test_echo_body_pet:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling BodyApi->test_echo_body_pet: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
[**Pet**](Pet.md)
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: application/json
|
||||||
|
- **Accept**: application/json
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_echo_body_pet_response_string**
|
||||||
|
> str test_echo_body_pet_response_string(pet=pet)
|
||||||
|
|
||||||
|
Test empty response body
|
||||||
|
|
||||||
|
Test empty response body
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.models.pet import Pet
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.BodyApi(api_client)
|
||||||
|
pet = openapi_client.Pet() # Pet | Pet object that needs to be added to the store (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test empty response body
|
||||||
|
api_response = api_instance.test_echo_body_pet_response_string(pet=pet)
|
||||||
|
print("The response of BodyApi->test_echo_body_pet_response_string:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling BodyApi->test_echo_body_pet_response_string: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: application/json
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_echo_body_tag_response_string**
|
||||||
|
> str test_echo_body_tag_response_string(tag=tag)
|
||||||
|
|
||||||
|
Test empty json (request body)
|
||||||
|
|
||||||
|
Test empty json (request body)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.models.tag import Tag
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.BodyApi(api_client)
|
||||||
|
tag = openapi_client.Tag() # Tag | Tag object (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test empty json (request body)
|
||||||
|
api_response = api_instance.test_echo_body_tag_response_string(tag=tag)
|
||||||
|
print("The response of BodyApi->test_echo_body_tag_response_string:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling BodyApi->test_echo_body_tag_response_string: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**tag** | [**Tag**](Tag.md)| Tag object | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: application/json
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
29
samples/client/echo_api/python-pydantic-v1/docs/Category.md
Normal file
29
samples/client/echo_api/python-pydantic-v1/docs/Category.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Category
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**id** | **int** | | [optional]
|
||||||
|
**name** | **str** | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_client.models.category import Category
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of Category from a JSON string
|
||||||
|
category_instance = Category.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print Category.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
category_dict = category_instance.to_dict()
|
||||||
|
# create an instance of Category from a dict
|
||||||
|
category_form_dict = category.from_dict(category_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
30
samples/client/echo_api/python-pydantic-v1/docs/DataQuery.md
Normal file
30
samples/client/echo_api/python-pydantic-v1/docs/DataQuery.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# DataQuery
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**suffix** | **str** | test suffix | [optional]
|
||||||
|
**text** | **str** | Some text containing white spaces | [optional]
|
||||||
|
**var_date** | **datetime** | A date | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_client.models.data_query import DataQuery
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of DataQuery from a JSON string
|
||||||
|
data_query_instance = DataQuery.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print DataQuery.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
data_query_dict = data_query_instance.to_dict()
|
||||||
|
# create an instance of DataQuery from a dict
|
||||||
|
data_query_form_dict = data_query.from_dict(data_query_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
|||||||
|
# DefaultValue
|
||||||
|
|
||||||
|
to test the default value of properties
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**array_string_enum_ref_default** | [**List[StringEnumRef]**](StringEnumRef.md) | | [optional] [default to ["success","failure"]]
|
||||||
|
**array_string_enum_default** | **List[str]** | | [optional] [default to ["success","failure"]]
|
||||||
|
**array_string_default** | **List[str]** | | [optional] [default to ["failure","skipped"]]
|
||||||
|
**array_integer_default** | **List[int]** | | [optional] [default to [1,3]]
|
||||||
|
**array_string** | **List[str]** | | [optional]
|
||||||
|
**array_string_nullable** | **List[str]** | | [optional]
|
||||||
|
**array_string_extension_nullable** | **List[str]** | | [optional]
|
||||||
|
**string_nullable** | **str** | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_client.models.default_value import DefaultValue
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of DefaultValue from a JSON string
|
||||||
|
default_value_instance = DefaultValue.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print DefaultValue.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
default_value_dict = default_value_instance.to_dict()
|
||||||
|
# create an instance of DefaultValue from a dict
|
||||||
|
default_value_form_dict = default_value.from_dict(default_value_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
156
samples/client/echo_api/python-pydantic-v1/docs/FormApi.md
Normal file
156
samples/client/echo_api/python-pydantic-v1/docs/FormApi.md
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
# openapi_client.FormApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost:3000*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**test_form_integer_boolean_string**](FormApi.md#test_form_integer_boolean_string) | **POST** /form/integer/boolean/string | Test form parameter(s)
|
||||||
|
[**test_form_oneof**](FormApi.md#test_form_oneof) | **POST** /form/oneof | Test form parameter(s) for oneOf schema
|
||||||
|
|
||||||
|
|
||||||
|
# **test_form_integer_boolean_string**
|
||||||
|
> str test_form_integer_boolean_string(integer_form=integer_form, boolean_form=boolean_form, string_form=string_form)
|
||||||
|
|
||||||
|
Test form parameter(s)
|
||||||
|
|
||||||
|
Test form parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.FormApi(api_client)
|
||||||
|
integer_form = 56 # int | (optional)
|
||||||
|
boolean_form = True # bool | (optional)
|
||||||
|
string_form = 'string_form_example' # str | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test form parameter(s)
|
||||||
|
api_response = api_instance.test_form_integer_boolean_string(integer_form=integer_form, boolean_form=boolean_form, string_form=string_form)
|
||||||
|
print("The response of FormApi->test_form_integer_boolean_string:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling FormApi->test_form_integer_boolean_string: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**integer_form** | **int**| | [optional]
|
||||||
|
**boolean_form** | **bool**| | [optional]
|
||||||
|
**string_form** | **str**| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: application/x-www-form-urlencoded
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_form_oneof**
|
||||||
|
> str test_form_oneof(form1=form1, form2=form2, form3=form3, form4=form4, id=id, name=name)
|
||||||
|
|
||||||
|
Test form parameter(s) for oneOf schema
|
||||||
|
|
||||||
|
Test form parameter(s) for oneOf schema
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.FormApi(api_client)
|
||||||
|
form1 = 'form1_example' # str | (optional)
|
||||||
|
form2 = 56 # int | (optional)
|
||||||
|
form3 = 'form3_example' # str | (optional)
|
||||||
|
form4 = True # bool | (optional)
|
||||||
|
id = 56 # int | (optional)
|
||||||
|
name = 'name_example' # str | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test form parameter(s) for oneOf schema
|
||||||
|
api_response = api_instance.test_form_oneof(form1=form1, form2=form2, form3=form3, form4=form4, id=id, name=name)
|
||||||
|
print("The response of FormApi->test_form_oneof:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling FormApi->test_form_oneof: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**form1** | **str**| | [optional]
|
||||||
|
**form2** | **int**| | [optional]
|
||||||
|
**form3** | **str**| | [optional]
|
||||||
|
**form4** | **bool**| | [optional]
|
||||||
|
**id** | **int**| | [optional]
|
||||||
|
**name** | **str**| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: application/x-www-form-urlencoded
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
79
samples/client/echo_api/python-pydantic-v1/docs/HeaderApi.md
Normal file
79
samples/client/echo_api/python-pydantic-v1/docs/HeaderApi.md
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
# openapi_client.HeaderApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost:3000*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**test_header_integer_boolean_string**](HeaderApi.md#test_header_integer_boolean_string) | **GET** /header/integer/boolean/string | Test header parameter(s)
|
||||||
|
|
||||||
|
|
||||||
|
# **test_header_integer_boolean_string**
|
||||||
|
> str test_header_integer_boolean_string(integer_header=integer_header, boolean_header=boolean_header, string_header=string_header)
|
||||||
|
|
||||||
|
Test header parameter(s)
|
||||||
|
|
||||||
|
Test header parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.HeaderApi(api_client)
|
||||||
|
integer_header = 56 # int | (optional)
|
||||||
|
boolean_header = True # bool | (optional)
|
||||||
|
string_header = 'string_header_example' # str | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test header parameter(s)
|
||||||
|
api_response = api_instance.test_header_integer_boolean_string(integer_header=integer_header, boolean_header=boolean_header, string_header=string_header)
|
||||||
|
print("The response of HeaderApi->test_header_integer_boolean_string:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling HeaderApi->test_header_integer_boolean_string: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**integer_header** | **int**| | [optional]
|
||||||
|
**boolean_header** | **bool**| | [optional]
|
||||||
|
**string_header** | **str**| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
@ -0,0 +1,30 @@
|
|||||||
|
# NumberPropertiesOnly
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**number** | **float** | | [optional]
|
||||||
|
**float** | **float** | | [optional]
|
||||||
|
**double** | **float** | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_client.models.number_properties_only import NumberPropertiesOnly
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of NumberPropertiesOnly from a JSON string
|
||||||
|
number_properties_only_instance = NumberPropertiesOnly.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print NumberPropertiesOnly.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
number_properties_only_dict = number_properties_only_instance.to_dict()
|
||||||
|
# create an instance of NumberPropertiesOnly from a dict
|
||||||
|
number_properties_only_form_dict = number_properties_only.from_dict(number_properties_only_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
77
samples/client/echo_api/python-pydantic-v1/docs/PathApi.md
Normal file
77
samples/client/echo_api/python-pydantic-v1/docs/PathApi.md
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# openapi_client.PathApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost:3000*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**tests_path_string_path_string_integer_path_integer**](PathApi.md#tests_path_string_path_string_integer_path_integer) | **GET** /path/string/{path_string}/integer/{path_integer} | Test path parameter(s)
|
||||||
|
|
||||||
|
|
||||||
|
# **tests_path_string_path_string_integer_path_integer**
|
||||||
|
> str tests_path_string_path_string_integer_path_integer(path_string, path_integer)
|
||||||
|
|
||||||
|
Test path parameter(s)
|
||||||
|
|
||||||
|
Test path parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.PathApi(api_client)
|
||||||
|
path_string = 'path_string_example' # str |
|
||||||
|
path_integer = 56 # int |
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test path parameter(s)
|
||||||
|
api_response = api_instance.tests_path_string_path_string_integer_path_integer(path_string, path_integer)
|
||||||
|
print("The response of PathApi->tests_path_string_path_string_integer_path_integer:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling PathApi->tests_path_string_path_string_integer_path_integer: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**path_string** | **str**| |
|
||||||
|
**path_integer** | **int**| |
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
33
samples/client/echo_api/python-pydantic-v1/docs/Pet.md
Normal file
33
samples/client/echo_api/python-pydantic-v1/docs/Pet.md
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# Pet
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**id** | **int** | | [optional]
|
||||||
|
**name** | **str** | |
|
||||||
|
**category** | [**Category**](Category.md) | | [optional]
|
||||||
|
**photo_urls** | **List[str]** | |
|
||||||
|
**tags** | [**List[Tag]**](Tag.md) | | [optional]
|
||||||
|
**status** | **str** | pet status in the store | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_client.models.pet import Pet
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of Pet from a JSON string
|
||||||
|
pet_instance = Pet.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print Pet.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
pet_dict = pet_instance.to_dict()
|
||||||
|
# create an instance of Pet from a dict
|
||||||
|
pet_form_dict = pet.from_dict(pet_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
29
samples/client/echo_api/python-pydantic-v1/docs/Query.md
Normal file
29
samples/client/echo_api/python-pydantic-v1/docs/Query.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Query
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**id** | **int** | Query | [optional]
|
||||||
|
**outcomes** | **List[str]** | | [optional] [default to ["SUCCESS","FAILURE"]]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_client.models.query import Query
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of Query from a JSON string
|
||||||
|
query_instance = Query.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print Query.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
query_dict = query_instance.to_dict()
|
||||||
|
# create an instance of Query from a dict
|
||||||
|
query_form_dict = query.from_dict(query_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
556
samples/client/echo_api/python-pydantic-v1/docs/QueryApi.md
Normal file
556
samples/client/echo_api/python-pydantic-v1/docs/QueryApi.md
Normal file
@ -0,0 +1,556 @@
|
|||||||
|
# openapi_client.QueryApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost:3000*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**test_enum_ref_string**](QueryApi.md#test_enum_ref_string) | **GET** /query/enum_ref_string | Test query parameter(s)
|
||||||
|
[**test_query_datetime_date_string**](QueryApi.md#test_query_datetime_date_string) | **GET** /query/datetime/date/string | Test query parameter(s)
|
||||||
|
[**test_query_integer_boolean_string**](QueryApi.md#test_query_integer_boolean_string) | **GET** /query/integer/boolean/string | Test query parameter(s)
|
||||||
|
[**test_query_style_deep_object_explode_true_object**](QueryApi.md#test_query_style_deep_object_explode_true_object) | **GET** /query/style_deepObject/explode_true/object | Test query parameter(s)
|
||||||
|
[**test_query_style_deep_object_explode_true_object_all_of**](QueryApi.md#test_query_style_deep_object_explode_true_object_all_of) | **GET** /query/style_deepObject/explode_true/object/allOf | Test query parameter(s)
|
||||||
|
[**test_query_style_form_explode_true_array_string**](QueryApi.md#test_query_style_form_explode_true_array_string) | **GET** /query/style_form/explode_true/array_string | Test query parameter(s)
|
||||||
|
[**test_query_style_form_explode_true_object**](QueryApi.md#test_query_style_form_explode_true_object) | **GET** /query/style_form/explode_true/object | Test query parameter(s)
|
||||||
|
[**test_query_style_form_explode_true_object_all_of**](QueryApi.md#test_query_style_form_explode_true_object_all_of) | **GET** /query/style_form/explode_true/object/allOf | Test query parameter(s)
|
||||||
|
|
||||||
|
|
||||||
|
# **test_enum_ref_string**
|
||||||
|
> str test_enum_ref_string(enum_ref_string_query=enum_ref_string_query)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.models.string_enum_ref import StringEnumRef
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.QueryApi(api_client)
|
||||||
|
enum_ref_string_query = openapi_client.StringEnumRef() # StringEnumRef | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test query parameter(s)
|
||||||
|
api_response = api_instance.test_enum_ref_string(enum_ref_string_query=enum_ref_string_query)
|
||||||
|
print("The response of QueryApi->test_enum_ref_string:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling QueryApi->test_enum_ref_string: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**enum_ref_string_query** | [**StringEnumRef**](.md)| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_query_datetime_date_string**
|
||||||
|
> str test_query_datetime_date_string(datetime_query=datetime_query, date_query=date_query, string_query=string_query)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.QueryApi(api_client)
|
||||||
|
datetime_query = '2013-10-20T19:20:30+01:00' # datetime | (optional)
|
||||||
|
date_query = '2013-10-20' # date | (optional)
|
||||||
|
string_query = 'string_query_example' # str | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test query parameter(s)
|
||||||
|
api_response = api_instance.test_query_datetime_date_string(datetime_query=datetime_query, date_query=date_query, string_query=string_query)
|
||||||
|
print("The response of QueryApi->test_query_datetime_date_string:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling QueryApi->test_query_datetime_date_string: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**datetime_query** | **datetime**| | [optional]
|
||||||
|
**date_query** | **date**| | [optional]
|
||||||
|
**string_query** | **str**| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_query_integer_boolean_string**
|
||||||
|
> str test_query_integer_boolean_string(integer_query=integer_query, boolean_query=boolean_query, string_query=string_query)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.QueryApi(api_client)
|
||||||
|
integer_query = 56 # int | (optional)
|
||||||
|
boolean_query = True # bool | (optional)
|
||||||
|
string_query = 'string_query_example' # str | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test query parameter(s)
|
||||||
|
api_response = api_instance.test_query_integer_boolean_string(integer_query=integer_query, boolean_query=boolean_query, string_query=string_query)
|
||||||
|
print("The response of QueryApi->test_query_integer_boolean_string:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling QueryApi->test_query_integer_boolean_string: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**integer_query** | **int**| | [optional]
|
||||||
|
**boolean_query** | **bool**| | [optional]
|
||||||
|
**string_query** | **str**| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_query_style_deep_object_explode_true_object**
|
||||||
|
> str test_query_style_deep_object_explode_true_object(query_object=query_object)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.models.pet import Pet
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.QueryApi(api_client)
|
||||||
|
query_object = openapi_client.Pet() # Pet | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test query parameter(s)
|
||||||
|
api_response = api_instance.test_query_style_deep_object_explode_true_object(query_object=query_object)
|
||||||
|
print("The response of QueryApi->test_query_style_deep_object_explode_true_object:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling QueryApi->test_query_style_deep_object_explode_true_object: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**query_object** | [**Pet**](.md)| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_query_style_deep_object_explode_true_object_all_of**
|
||||||
|
> str test_query_style_deep_object_explode_true_object_all_of(query_object=query_object)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.QueryApi(api_client)
|
||||||
|
query_object = openapi_client.TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter() # TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test query parameter(s)
|
||||||
|
api_response = api_instance.test_query_style_deep_object_explode_true_object_all_of(query_object=query_object)
|
||||||
|
print("The response of QueryApi->test_query_style_deep_object_explode_true_object_all_of:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling QueryApi->test_query_style_deep_object_explode_true_object_all_of: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**query_object** | [**TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter**](.md)| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_query_style_form_explode_true_array_string**
|
||||||
|
> str test_query_style_form_explode_true_array_string(query_object=query_object)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.QueryApi(api_client)
|
||||||
|
query_object = openapi_client.TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter() # TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test query parameter(s)
|
||||||
|
api_response = api_instance.test_query_style_form_explode_true_array_string(query_object=query_object)
|
||||||
|
print("The response of QueryApi->test_query_style_form_explode_true_array_string:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling QueryApi->test_query_style_form_explode_true_array_string: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**query_object** | [**TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter**](.md)| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_query_style_form_explode_true_object**
|
||||||
|
> str test_query_style_form_explode_true_object(query_object=query_object)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.models.pet import Pet
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.QueryApi(api_client)
|
||||||
|
query_object = openapi_client.Pet() # Pet | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test query parameter(s)
|
||||||
|
api_response = api_instance.test_query_style_form_explode_true_object(query_object=query_object)
|
||||||
|
print("The response of QueryApi->test_query_style_form_explode_true_object:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling QueryApi->test_query_style_form_explode_true_object: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**query_object** | [**Pet**](.md)| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
# **test_query_style_form_explode_true_object_all_of**
|
||||||
|
> str test_query_style_form_explode_true_object_all_of(query_object=query_object)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
Test query parameter(s)
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import openapi_client
|
||||||
|
from openapi_client.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# Defining the host is optional and defaults to http://localhost:3000
|
||||||
|
# See configuration.py for a list of all supported configuration parameters.
|
||||||
|
configuration = openapi_client.Configuration(
|
||||||
|
host = "http://localhost:3000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Enter a context with an instance of the API client
|
||||||
|
with openapi_client.ApiClient(configuration) as api_client:
|
||||||
|
# Create an instance of the API class
|
||||||
|
api_instance = openapi_client.QueryApi(api_client)
|
||||||
|
query_object = openapi_client.DataQuery() # DataQuery | (optional)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test query parameter(s)
|
||||||
|
api_response = api_instance.test_query_style_form_explode_true_object_all_of(query_object=query_object)
|
||||||
|
print("The response of QueryApi->test_query_style_form_explode_true_object_all_of:\n")
|
||||||
|
pprint(api_response)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception when calling QueryApi->test_query_style_form_explode_true_object_all_of: %s\n" % e)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**query_object** | [**DataQuery**](.md)| | [optional]
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
**str**
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: text/plain
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
**200** | Successful operation | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
# StringEnumRef
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
29
samples/client/echo_api/python-pydantic-v1/docs/Tag.md
Normal file
29
samples/client/echo_api/python-pydantic-v1/docs/Tag.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Tag
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**id** | **int** | | [optional]
|
||||||
|
**name** | **str** | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_client.models.tag import Tag
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of Tag from a JSON string
|
||||||
|
tag_instance = Tag.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print Tag.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
tag_dict = tag_instance.to_dict()
|
||||||
|
# create an instance of Tag from a dict
|
||||||
|
tag_form_dict = tag.from_dict(tag_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
|||||||
|
# TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**size** | **str** | | [optional]
|
||||||
|
**color** | **str** | | [optional]
|
||||||
|
**id** | **int** | | [optional]
|
||||||
|
**name** | **str** | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a JSON string
|
||||||
|
test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_dict = test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance.to_dict()
|
||||||
|
# create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a dict
|
||||||
|
test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_form_dict = test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.from_dict(test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
|||||||
|
# TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**values** | **List[str]** | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a JSON string
|
||||||
|
test_query_style_form_explode_true_array_string_query_object_parameter_instance = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
test_query_style_form_explode_true_array_string_query_object_parameter_dict = test_query_style_form_explode_true_array_string_query_object_parameter_instance.to_dict()
|
||||||
|
# create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a dict
|
||||||
|
test_query_style_form_explode_true_array_string_query_object_parameter_form_dict = test_query_style_form_explode_true_array_string_query_object_parameter.from_dict(test_query_style_form_explode_true_array_string_query_object_parameter_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
57
samples/client/echo_api/python-pydantic-v1/git_push.sh
Normal file
57
samples/client/echo_api/python-pydantic-v1/git_push.sh
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#!/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-petstore-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="github.com"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$git_user_id" = "" ]; then
|
||||||
|
git_user_id="GIT_USER_ID"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$git_repo_id" = "" ]; then
|
||||||
|
git_repo_id="GIT_REPO_ID"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$release_note" = "" ]; then
|
||||||
|
release_note="Minor update"
|
||||||
|
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'
|
@ -0,0 +1,50 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
# flake8: noqa
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
__version__ = "1.0.0"
|
||||||
|
|
||||||
|
# import apis into sdk package
|
||||||
|
from openapi_client.api.auth_api import AuthApi
|
||||||
|
from openapi_client.api.body_api import BodyApi
|
||||||
|
from openapi_client.api.form_api import FormApi
|
||||||
|
from openapi_client.api.header_api import HeaderApi
|
||||||
|
from openapi_client.api.path_api import PathApi
|
||||||
|
from openapi_client.api.query_api import QueryApi
|
||||||
|
|
||||||
|
# import ApiClient
|
||||||
|
from openapi_client.api_response import ApiResponse
|
||||||
|
from openapi_client.api_client import ApiClient
|
||||||
|
from openapi_client.configuration import Configuration
|
||||||
|
from openapi_client.exceptions import OpenApiException
|
||||||
|
from openapi_client.exceptions import ApiTypeError
|
||||||
|
from openapi_client.exceptions import ApiValueError
|
||||||
|
from openapi_client.exceptions import ApiKeyError
|
||||||
|
from openapi_client.exceptions import ApiAttributeError
|
||||||
|
from openapi_client.exceptions import ApiException
|
||||||
|
|
||||||
|
# import models into sdk package
|
||||||
|
from openapi_client.models.bird import Bird
|
||||||
|
from openapi_client.models.category import Category
|
||||||
|
from openapi_client.models.data_query import DataQuery
|
||||||
|
from openapi_client.models.default_value import DefaultValue
|
||||||
|
from openapi_client.models.number_properties_only import NumberPropertiesOnly
|
||||||
|
from openapi_client.models.pet import Pet
|
||||||
|
from openapi_client.models.query import Query
|
||||||
|
from openapi_client.models.string_enum_ref import StringEnumRef
|
||||||
|
from openapi_client.models.tag import Tag
|
||||||
|
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
|
||||||
|
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter
|
@ -0,0 +1,10 @@
|
|||||||
|
# flake8: noqa
|
||||||
|
|
||||||
|
# import apis into api package
|
||||||
|
from openapi_client.api.auth_api import AuthApi
|
||||||
|
from openapi_client.api.body_api import BodyApi
|
||||||
|
from openapi_client.api.form_api import FormApi
|
||||||
|
from openapi_client.api.header_api import HeaderApi
|
||||||
|
from openapi_client.api.path_api import PathApi
|
||||||
|
from openapi_client.api.query_api import QueryApi
|
||||||
|
|
@ -0,0 +1,173 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
import re # noqa: F401
|
||||||
|
import io
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
from pydantic import validate_arguments, ValidationError
|
||||||
|
|
||||||
|
|
||||||
|
from openapi_client.api_client import ApiClient
|
||||||
|
from openapi_client.api_response import ApiResponse
|
||||||
|
from openapi_client.exceptions import ( # noqa: F401
|
||||||
|
ApiTypeError,
|
||||||
|
ApiValueError
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AuthApi:
|
||||||
|
"""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) -> None:
|
||||||
|
if api_client is None:
|
||||||
|
api_client = ApiClient.get_default()
|
||||||
|
self.api_client = api_client
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
def test_auth_http_basic(self, **kwargs) -> str: # noqa: E501
|
||||||
|
"""To test HTTP basic authentication # noqa: E501
|
||||||
|
|
||||||
|
To test HTTP basic authentication # noqa: E501
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.test_auth_http_basic(async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: 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: str
|
||||||
|
"""
|
||||||
|
kwargs['_return_http_data_only'] = True
|
||||||
|
if '_preload_content' in kwargs:
|
||||||
|
message = "Error! Please call the test_auth_http_basic_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501
|
||||||
|
raise ValueError(message)
|
||||||
|
return self.test_auth_http_basic_with_http_info(**kwargs) # noqa: E501
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
def test_auth_http_basic_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501
|
||||||
|
"""To test HTTP basic authentication # noqa: E501
|
||||||
|
|
||||||
|
To test HTTP basic authentication # noqa: E501
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.test_auth_http_basic_with_http_info(async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: bool, optional
|
||||||
|
:param _preload_content: if False, the ApiResponse.data will
|
||||||
|
be set to none and raw_data will store the
|
||||||
|
HTTP response body without reading/decoding.
|
||||||
|
Default is True.
|
||||||
|
:type _preload_content: bool, optional
|
||||||
|
:param _return_http_data_only: response data instead of ApiResponse
|
||||||
|
object with status code, headers, etc
|
||||||
|
:type _return_http_data_only: 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
|
||||||
|
:type _content_type: string, optional: force content-type for the request
|
||||||
|
:return: Returns the result object.
|
||||||
|
If the method is called asynchronously,
|
||||||
|
returns the request thread.
|
||||||
|
:rtype: tuple(str, status_code(int), headers(HTTPHeaderDict))
|
||||||
|
"""
|
||||||
|
|
||||||
|
_params = locals()
|
||||||
|
|
||||||
|
_all_params = [
|
||||||
|
]
|
||||||
|
_all_params.extend(
|
||||||
|
[
|
||||||
|
'async_req',
|
||||||
|
'_return_http_data_only',
|
||||||
|
'_preload_content',
|
||||||
|
'_request_timeout',
|
||||||
|
'_request_auth',
|
||||||
|
'_content_type',
|
||||||
|
'_headers'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# validate the arguments
|
||||||
|
for _key, _val in _params['kwargs'].items():
|
||||||
|
if _key not in _all_params:
|
||||||
|
raise ApiTypeError(
|
||||||
|
"Got an unexpected keyword argument '%s'"
|
||||||
|
" to method test_auth_http_basic" % _key
|
||||||
|
)
|
||||||
|
_params[_key] = _val
|
||||||
|
del _params['kwargs']
|
||||||
|
|
||||||
|
_collection_formats = {}
|
||||||
|
|
||||||
|
# process the path parameters
|
||||||
|
_path_params = {}
|
||||||
|
|
||||||
|
# process the query parameters
|
||||||
|
_query_params = []
|
||||||
|
# process the header parameters
|
||||||
|
_header_params = dict(_params.get('_headers', {}))
|
||||||
|
# process the form parameters
|
||||||
|
_form_params = []
|
||||||
|
_files = {}
|
||||||
|
# process the body parameter
|
||||||
|
_body_params = None
|
||||||
|
# set the HTTP header `Accept`
|
||||||
|
_header_params['Accept'] = self.api_client.select_header_accept(
|
||||||
|
['text/plain']) # noqa: E501
|
||||||
|
|
||||||
|
# authentication setting
|
||||||
|
_auth_settings = ['http_auth'] # noqa: E501
|
||||||
|
|
||||||
|
_response_types_map = {
|
||||||
|
'200': "str",
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.api_client.call_api(
|
||||||
|
'/auth/http/basic', 'POST',
|
||||||
|
_path_params,
|
||||||
|
_query_params,
|
||||||
|
_header_params,
|
||||||
|
body=_body_params,
|
||||||
|
post_params=_form_params,
|
||||||
|
files=_files,
|
||||||
|
response_types_map=_response_types_map,
|
||||||
|
auth_settings=_auth_settings,
|
||||||
|
async_req=_params.get('async_req'),
|
||||||
|
_return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501
|
||||||
|
_preload_content=_params.get('_preload_content', True),
|
||||||
|
_request_timeout=_params.get('_request_timeout'),
|
||||||
|
collection_formats=_collection_formats,
|
||||||
|
_request_auth=_params.get('_request_auth'))
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,395 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
import re # noqa: F401
|
||||||
|
import io
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
from pydantic import validate_arguments, ValidationError
|
||||||
|
|
||||||
|
from pydantic import StrictBool, StrictInt, StrictStr
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
|
from openapi_client.api_client import ApiClient
|
||||||
|
from openapi_client.api_response import ApiResponse
|
||||||
|
from openapi_client.exceptions import ( # noqa: F401
|
||||||
|
ApiTypeError,
|
||||||
|
ApiValueError
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class FormApi:
|
||||||
|
"""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) -> None:
|
||||||
|
if api_client is None:
|
||||||
|
api_client = ApiClient.get_default()
|
||||||
|
self.api_client = api_client
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
def test_form_integer_boolean_string(self, integer_form : Optional[StrictInt] = None, boolean_form : Optional[StrictBool] = None, string_form : Optional[StrictStr] = None, **kwargs) -> str: # noqa: E501
|
||||||
|
"""Test form parameter(s) # noqa: E501
|
||||||
|
|
||||||
|
Test form parameter(s) # noqa: E501
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.test_form_integer_boolean_string(integer_form, boolean_form, string_form, async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
|
||||||
|
:param integer_form:
|
||||||
|
:type integer_form: int
|
||||||
|
:param boolean_form:
|
||||||
|
:type boolean_form: bool
|
||||||
|
:param string_form:
|
||||||
|
:type string_form: str
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: 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: str
|
||||||
|
"""
|
||||||
|
kwargs['_return_http_data_only'] = True
|
||||||
|
if '_preload_content' in kwargs:
|
||||||
|
message = "Error! Please call the test_form_integer_boolean_string_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501
|
||||||
|
raise ValueError(message)
|
||||||
|
return self.test_form_integer_boolean_string_with_http_info(integer_form, boolean_form, string_form, **kwargs) # noqa: E501
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
def test_form_integer_boolean_string_with_http_info(self, integer_form : Optional[StrictInt] = None, boolean_form : Optional[StrictBool] = None, string_form : Optional[StrictStr] = None, **kwargs) -> ApiResponse: # noqa: E501
|
||||||
|
"""Test form parameter(s) # noqa: E501
|
||||||
|
|
||||||
|
Test form parameter(s) # noqa: E501
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.test_form_integer_boolean_string_with_http_info(integer_form, boolean_form, string_form, async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
|
||||||
|
:param integer_form:
|
||||||
|
:type integer_form: int
|
||||||
|
:param boolean_form:
|
||||||
|
:type boolean_form: bool
|
||||||
|
:param string_form:
|
||||||
|
:type string_form: str
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: bool, optional
|
||||||
|
:param _preload_content: if False, the ApiResponse.data will
|
||||||
|
be set to none and raw_data will store the
|
||||||
|
HTTP response body without reading/decoding.
|
||||||
|
Default is True.
|
||||||
|
:type _preload_content: bool, optional
|
||||||
|
:param _return_http_data_only: response data instead of ApiResponse
|
||||||
|
object with status code, headers, etc
|
||||||
|
:type _return_http_data_only: 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
|
||||||
|
:type _content_type: string, optional: force content-type for the request
|
||||||
|
:return: Returns the result object.
|
||||||
|
If the method is called asynchronously,
|
||||||
|
returns the request thread.
|
||||||
|
:rtype: tuple(str, status_code(int), headers(HTTPHeaderDict))
|
||||||
|
"""
|
||||||
|
|
||||||
|
_params = locals()
|
||||||
|
|
||||||
|
_all_params = [
|
||||||
|
'integer_form',
|
||||||
|
'boolean_form',
|
||||||
|
'string_form'
|
||||||
|
]
|
||||||
|
_all_params.extend(
|
||||||
|
[
|
||||||
|
'async_req',
|
||||||
|
'_return_http_data_only',
|
||||||
|
'_preload_content',
|
||||||
|
'_request_timeout',
|
||||||
|
'_request_auth',
|
||||||
|
'_content_type',
|
||||||
|
'_headers'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# validate the arguments
|
||||||
|
for _key, _val in _params['kwargs'].items():
|
||||||
|
if _key not in _all_params:
|
||||||
|
raise ApiTypeError(
|
||||||
|
"Got an unexpected keyword argument '%s'"
|
||||||
|
" to method test_form_integer_boolean_string" % _key
|
||||||
|
)
|
||||||
|
_params[_key] = _val
|
||||||
|
del _params['kwargs']
|
||||||
|
|
||||||
|
_collection_formats = {}
|
||||||
|
|
||||||
|
# process the path parameters
|
||||||
|
_path_params = {}
|
||||||
|
|
||||||
|
# process the query parameters
|
||||||
|
_query_params = []
|
||||||
|
# process the header parameters
|
||||||
|
_header_params = dict(_params.get('_headers', {}))
|
||||||
|
# process the form parameters
|
||||||
|
_form_params = []
|
||||||
|
_files = {}
|
||||||
|
if _params['integer_form'] is not None:
|
||||||
|
_form_params.append(('integer_form', _params['integer_form']))
|
||||||
|
|
||||||
|
if _params['boolean_form'] is not None:
|
||||||
|
_form_params.append(('boolean_form', _params['boolean_form']))
|
||||||
|
|
||||||
|
if _params['string_form'] is not None:
|
||||||
|
_form_params.append(('string_form', _params['string_form']))
|
||||||
|
|
||||||
|
# process the body parameter
|
||||||
|
_body_params = None
|
||||||
|
# set the HTTP header `Accept`
|
||||||
|
_header_params['Accept'] = self.api_client.select_header_accept(
|
||||||
|
['text/plain']) # noqa: E501
|
||||||
|
|
||||||
|
# set the HTTP header `Content-Type`
|
||||||
|
_content_types_list = _params.get('_content_type',
|
||||||
|
self.api_client.select_header_content_type(
|
||||||
|
['application/x-www-form-urlencoded']))
|
||||||
|
if _content_types_list:
|
||||||
|
_header_params['Content-Type'] = _content_types_list
|
||||||
|
|
||||||
|
# authentication setting
|
||||||
|
_auth_settings = [] # noqa: E501
|
||||||
|
|
||||||
|
_response_types_map = {
|
||||||
|
'200': "str",
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.api_client.call_api(
|
||||||
|
'/form/integer/boolean/string', 'POST',
|
||||||
|
_path_params,
|
||||||
|
_query_params,
|
||||||
|
_header_params,
|
||||||
|
body=_body_params,
|
||||||
|
post_params=_form_params,
|
||||||
|
files=_files,
|
||||||
|
response_types_map=_response_types_map,
|
||||||
|
auth_settings=_auth_settings,
|
||||||
|
async_req=_params.get('async_req'),
|
||||||
|
_return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501
|
||||||
|
_preload_content=_params.get('_preload_content', True),
|
||||||
|
_request_timeout=_params.get('_request_timeout'),
|
||||||
|
collection_formats=_collection_formats,
|
||||||
|
_request_auth=_params.get('_request_auth'))
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
def test_form_oneof(self, form1 : Optional[StrictStr] = None, form2 : Optional[StrictInt] = None, form3 : Optional[StrictStr] = None, form4 : Optional[StrictBool] = None, id : Optional[StrictInt] = None, name : Optional[StrictStr] = None, **kwargs) -> str: # noqa: E501
|
||||||
|
"""Test form parameter(s) for oneOf schema # noqa: E501
|
||||||
|
|
||||||
|
Test form parameter(s) for oneOf schema # noqa: E501
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.test_form_oneof(form1, form2, form3, form4, id, name, async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
|
||||||
|
:param form1:
|
||||||
|
:type form1: str
|
||||||
|
:param form2:
|
||||||
|
:type form2: int
|
||||||
|
:param form3:
|
||||||
|
:type form3: str
|
||||||
|
:param form4:
|
||||||
|
:type form4: bool
|
||||||
|
:param id:
|
||||||
|
:type id: int
|
||||||
|
:param name:
|
||||||
|
:type name: str
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: 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: str
|
||||||
|
"""
|
||||||
|
kwargs['_return_http_data_only'] = True
|
||||||
|
if '_preload_content' in kwargs:
|
||||||
|
message = "Error! Please call the test_form_oneof_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501
|
||||||
|
raise ValueError(message)
|
||||||
|
return self.test_form_oneof_with_http_info(form1, form2, form3, form4, id, name, **kwargs) # noqa: E501
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
def test_form_oneof_with_http_info(self, form1 : Optional[StrictStr] = None, form2 : Optional[StrictInt] = None, form3 : Optional[StrictStr] = None, form4 : Optional[StrictBool] = None, id : Optional[StrictInt] = None, name : Optional[StrictStr] = None, **kwargs) -> ApiResponse: # noqa: E501
|
||||||
|
"""Test form parameter(s) for oneOf schema # noqa: E501
|
||||||
|
|
||||||
|
Test form parameter(s) for oneOf schema # noqa: E501
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.test_form_oneof_with_http_info(form1, form2, form3, form4, id, name, async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
|
||||||
|
:param form1:
|
||||||
|
:type form1: str
|
||||||
|
:param form2:
|
||||||
|
:type form2: int
|
||||||
|
:param form3:
|
||||||
|
:type form3: str
|
||||||
|
:param form4:
|
||||||
|
:type form4: bool
|
||||||
|
:param id:
|
||||||
|
:type id: int
|
||||||
|
:param name:
|
||||||
|
:type name: str
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: bool, optional
|
||||||
|
:param _preload_content: if False, the ApiResponse.data will
|
||||||
|
be set to none and raw_data will store the
|
||||||
|
HTTP response body without reading/decoding.
|
||||||
|
Default is True.
|
||||||
|
:type _preload_content: bool, optional
|
||||||
|
:param _return_http_data_only: response data instead of ApiResponse
|
||||||
|
object with status code, headers, etc
|
||||||
|
:type _return_http_data_only: 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
|
||||||
|
:type _content_type: string, optional: force content-type for the request
|
||||||
|
:return: Returns the result object.
|
||||||
|
If the method is called asynchronously,
|
||||||
|
returns the request thread.
|
||||||
|
:rtype: tuple(str, status_code(int), headers(HTTPHeaderDict))
|
||||||
|
"""
|
||||||
|
|
||||||
|
_params = locals()
|
||||||
|
|
||||||
|
_all_params = [
|
||||||
|
'form1',
|
||||||
|
'form2',
|
||||||
|
'form3',
|
||||||
|
'form4',
|
||||||
|
'id',
|
||||||
|
'name'
|
||||||
|
]
|
||||||
|
_all_params.extend(
|
||||||
|
[
|
||||||
|
'async_req',
|
||||||
|
'_return_http_data_only',
|
||||||
|
'_preload_content',
|
||||||
|
'_request_timeout',
|
||||||
|
'_request_auth',
|
||||||
|
'_content_type',
|
||||||
|
'_headers'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# validate the arguments
|
||||||
|
for _key, _val in _params['kwargs'].items():
|
||||||
|
if _key not in _all_params:
|
||||||
|
raise ApiTypeError(
|
||||||
|
"Got an unexpected keyword argument '%s'"
|
||||||
|
" to method test_form_oneof" % _key
|
||||||
|
)
|
||||||
|
_params[_key] = _val
|
||||||
|
del _params['kwargs']
|
||||||
|
|
||||||
|
_collection_formats = {}
|
||||||
|
|
||||||
|
# process the path parameters
|
||||||
|
_path_params = {}
|
||||||
|
|
||||||
|
# process the query parameters
|
||||||
|
_query_params = []
|
||||||
|
# process the header parameters
|
||||||
|
_header_params = dict(_params.get('_headers', {}))
|
||||||
|
# process the form parameters
|
||||||
|
_form_params = []
|
||||||
|
_files = {}
|
||||||
|
if _params['form1'] is not None:
|
||||||
|
_form_params.append(('form1', _params['form1']))
|
||||||
|
|
||||||
|
if _params['form2'] is not None:
|
||||||
|
_form_params.append(('form2', _params['form2']))
|
||||||
|
|
||||||
|
if _params['form3'] is not None:
|
||||||
|
_form_params.append(('form3', _params['form3']))
|
||||||
|
|
||||||
|
if _params['form4'] is not None:
|
||||||
|
_form_params.append(('form4', _params['form4']))
|
||||||
|
|
||||||
|
if _params['id'] is not None:
|
||||||
|
_form_params.append(('id', _params['id']))
|
||||||
|
|
||||||
|
if _params['name'] is not None:
|
||||||
|
_form_params.append(('name', _params['name']))
|
||||||
|
|
||||||
|
# process the body parameter
|
||||||
|
_body_params = None
|
||||||
|
# set the HTTP header `Accept`
|
||||||
|
_header_params['Accept'] = self.api_client.select_header_accept(
|
||||||
|
['text/plain']) # noqa: E501
|
||||||
|
|
||||||
|
# set the HTTP header `Content-Type`
|
||||||
|
_content_types_list = _params.get('_content_type',
|
||||||
|
self.api_client.select_header_content_type(
|
||||||
|
['application/x-www-form-urlencoded']))
|
||||||
|
if _content_types_list:
|
||||||
|
_header_params['Content-Type'] = _content_types_list
|
||||||
|
|
||||||
|
# authentication setting
|
||||||
|
_auth_settings = [] # noqa: E501
|
||||||
|
|
||||||
|
_response_types_map = {
|
||||||
|
'200': "str",
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.api_client.call_api(
|
||||||
|
'/form/oneof', 'POST',
|
||||||
|
_path_params,
|
||||||
|
_query_params,
|
||||||
|
_header_params,
|
||||||
|
body=_body_params,
|
||||||
|
post_params=_form_params,
|
||||||
|
files=_files,
|
||||||
|
response_types_map=_response_types_map,
|
||||||
|
auth_settings=_auth_settings,
|
||||||
|
async_req=_params.get('async_req'),
|
||||||
|
_return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501
|
||||||
|
_preload_content=_params.get('_preload_content', True),
|
||||||
|
_request_timeout=_params.get('_request_timeout'),
|
||||||
|
collection_formats=_collection_formats,
|
||||||
|
_request_auth=_params.get('_request_auth'))
|
@ -0,0 +1,201 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
import re # noqa: F401
|
||||||
|
import io
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
from pydantic import validate_arguments, ValidationError
|
||||||
|
|
||||||
|
from pydantic import StrictBool, StrictInt, StrictStr
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
|
from openapi_client.api_client import ApiClient
|
||||||
|
from openapi_client.api_response import ApiResponse
|
||||||
|
from openapi_client.exceptions import ( # noqa: F401
|
||||||
|
ApiTypeError,
|
||||||
|
ApiValueError
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class HeaderApi:
|
||||||
|
"""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) -> None:
|
||||||
|
if api_client is None:
|
||||||
|
api_client = ApiClient.get_default()
|
||||||
|
self.api_client = api_client
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
def test_header_integer_boolean_string(self, integer_header : Optional[StrictInt] = None, boolean_header : Optional[StrictBool] = None, string_header : Optional[StrictStr] = None, **kwargs) -> str: # noqa: E501
|
||||||
|
"""Test header parameter(s) # noqa: E501
|
||||||
|
|
||||||
|
Test header parameter(s) # noqa: E501
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.test_header_integer_boolean_string(integer_header, boolean_header, string_header, async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
|
||||||
|
:param integer_header:
|
||||||
|
:type integer_header: int
|
||||||
|
:param boolean_header:
|
||||||
|
:type boolean_header: bool
|
||||||
|
:param string_header:
|
||||||
|
:type string_header: str
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: 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: str
|
||||||
|
"""
|
||||||
|
kwargs['_return_http_data_only'] = True
|
||||||
|
if '_preload_content' in kwargs:
|
||||||
|
message = "Error! Please call the test_header_integer_boolean_string_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501
|
||||||
|
raise ValueError(message)
|
||||||
|
return self.test_header_integer_boolean_string_with_http_info(integer_header, boolean_header, string_header, **kwargs) # noqa: E501
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
def test_header_integer_boolean_string_with_http_info(self, integer_header : Optional[StrictInt] = None, boolean_header : Optional[StrictBool] = None, string_header : Optional[StrictStr] = None, **kwargs) -> ApiResponse: # noqa: E501
|
||||||
|
"""Test header parameter(s) # noqa: E501
|
||||||
|
|
||||||
|
Test header parameter(s) # noqa: E501
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.test_header_integer_boolean_string_with_http_info(integer_header, boolean_header, string_header, async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
|
||||||
|
:param integer_header:
|
||||||
|
:type integer_header: int
|
||||||
|
:param boolean_header:
|
||||||
|
:type boolean_header: bool
|
||||||
|
:param string_header:
|
||||||
|
:type string_header: str
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: bool, optional
|
||||||
|
:param _preload_content: if False, the ApiResponse.data will
|
||||||
|
be set to none and raw_data will store the
|
||||||
|
HTTP response body without reading/decoding.
|
||||||
|
Default is True.
|
||||||
|
:type _preload_content: bool, optional
|
||||||
|
:param _return_http_data_only: response data instead of ApiResponse
|
||||||
|
object with status code, headers, etc
|
||||||
|
:type _return_http_data_only: 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
|
||||||
|
:type _content_type: string, optional: force content-type for the request
|
||||||
|
:return: Returns the result object.
|
||||||
|
If the method is called asynchronously,
|
||||||
|
returns the request thread.
|
||||||
|
:rtype: tuple(str, status_code(int), headers(HTTPHeaderDict))
|
||||||
|
"""
|
||||||
|
|
||||||
|
_params = locals()
|
||||||
|
|
||||||
|
_all_params = [
|
||||||
|
'integer_header',
|
||||||
|
'boolean_header',
|
||||||
|
'string_header'
|
||||||
|
]
|
||||||
|
_all_params.extend(
|
||||||
|
[
|
||||||
|
'async_req',
|
||||||
|
'_return_http_data_only',
|
||||||
|
'_preload_content',
|
||||||
|
'_request_timeout',
|
||||||
|
'_request_auth',
|
||||||
|
'_content_type',
|
||||||
|
'_headers'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# validate the arguments
|
||||||
|
for _key, _val in _params['kwargs'].items():
|
||||||
|
if _key not in _all_params:
|
||||||
|
raise ApiTypeError(
|
||||||
|
"Got an unexpected keyword argument '%s'"
|
||||||
|
" to method test_header_integer_boolean_string" % _key
|
||||||
|
)
|
||||||
|
_params[_key] = _val
|
||||||
|
del _params['kwargs']
|
||||||
|
|
||||||
|
_collection_formats = {}
|
||||||
|
|
||||||
|
# process the path parameters
|
||||||
|
_path_params = {}
|
||||||
|
|
||||||
|
# process the query parameters
|
||||||
|
_query_params = []
|
||||||
|
# process the header parameters
|
||||||
|
_header_params = dict(_params.get('_headers', {}))
|
||||||
|
if _params['integer_header'] is not None:
|
||||||
|
_header_params['integer_header'] = _params['integer_header']
|
||||||
|
|
||||||
|
if _params['boolean_header'] is not None:
|
||||||
|
_header_params['boolean_header'] = _params['boolean_header']
|
||||||
|
|
||||||
|
if _params['string_header'] is not None:
|
||||||
|
_header_params['string_header'] = _params['string_header']
|
||||||
|
|
||||||
|
# process the form parameters
|
||||||
|
_form_params = []
|
||||||
|
_files = {}
|
||||||
|
# process the body parameter
|
||||||
|
_body_params = None
|
||||||
|
# set the HTTP header `Accept`
|
||||||
|
_header_params['Accept'] = self.api_client.select_header_accept(
|
||||||
|
['text/plain']) # noqa: E501
|
||||||
|
|
||||||
|
# authentication setting
|
||||||
|
_auth_settings = [] # noqa: E501
|
||||||
|
|
||||||
|
_response_types_map = {
|
||||||
|
'200': "str",
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.api_client.call_api(
|
||||||
|
'/header/integer/boolean/string', 'GET',
|
||||||
|
_path_params,
|
||||||
|
_query_params,
|
||||||
|
_header_params,
|
||||||
|
body=_body_params,
|
||||||
|
post_params=_form_params,
|
||||||
|
files=_files,
|
||||||
|
response_types_map=_response_types_map,
|
||||||
|
auth_settings=_auth_settings,
|
||||||
|
async_req=_params.get('async_req'),
|
||||||
|
_return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501
|
||||||
|
_preload_content=_params.get('_preload_content', True),
|
||||||
|
_request_timeout=_params.get('_request_timeout'),
|
||||||
|
collection_formats=_collection_formats,
|
||||||
|
_request_auth=_params.get('_request_auth'))
|
@ -0,0 +1,191 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
import re # noqa: F401
|
||||||
|
import io
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
from pydantic import validate_arguments, ValidationError
|
||||||
|
|
||||||
|
from pydantic import StrictInt, StrictStr
|
||||||
|
|
||||||
|
|
||||||
|
from openapi_client.api_client import ApiClient
|
||||||
|
from openapi_client.api_response import ApiResponse
|
||||||
|
from openapi_client.exceptions import ( # noqa: F401
|
||||||
|
ApiTypeError,
|
||||||
|
ApiValueError
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PathApi:
|
||||||
|
"""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) -> None:
|
||||||
|
if api_client is None:
|
||||||
|
api_client = ApiClient.get_default()
|
||||||
|
self.api_client = api_client
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
def tests_path_string_path_string_integer_path_integer(self, path_string : StrictStr, path_integer : StrictInt, **kwargs) -> str: # noqa: E501
|
||||||
|
"""Test path parameter(s) # noqa: E501
|
||||||
|
|
||||||
|
Test path parameter(s) # noqa: E501
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.tests_path_string_path_string_integer_path_integer(path_string, path_integer, async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
|
||||||
|
:param path_string: (required)
|
||||||
|
:type path_string: str
|
||||||
|
:param path_integer: (required)
|
||||||
|
:type path_integer: int
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: 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: str
|
||||||
|
"""
|
||||||
|
kwargs['_return_http_data_only'] = True
|
||||||
|
if '_preload_content' in kwargs:
|
||||||
|
message = "Error! Please call the tests_path_string_path_string_integer_path_integer_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501
|
||||||
|
raise ValueError(message)
|
||||||
|
return self.tests_path_string_path_string_integer_path_integer_with_http_info(path_string, path_integer, **kwargs) # noqa: E501
|
||||||
|
|
||||||
|
@validate_arguments
|
||||||
|
def tests_path_string_path_string_integer_path_integer_with_http_info(self, path_string : StrictStr, path_integer : StrictInt, **kwargs) -> ApiResponse: # noqa: E501
|
||||||
|
"""Test path parameter(s) # noqa: E501
|
||||||
|
|
||||||
|
Test path parameter(s) # noqa: E501
|
||||||
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
|
asynchronous HTTP request, please pass async_req=True
|
||||||
|
|
||||||
|
>>> thread = api.tests_path_string_path_string_integer_path_integer_with_http_info(path_string, path_integer, async_req=True)
|
||||||
|
>>> result = thread.get()
|
||||||
|
|
||||||
|
:param path_string: (required)
|
||||||
|
:type path_string: str
|
||||||
|
:param path_integer: (required)
|
||||||
|
:type path_integer: int
|
||||||
|
:param async_req: Whether to execute the request asynchronously.
|
||||||
|
:type async_req: bool, optional
|
||||||
|
:param _preload_content: if False, the ApiResponse.data will
|
||||||
|
be set to none and raw_data will store the
|
||||||
|
HTTP response body without reading/decoding.
|
||||||
|
Default is True.
|
||||||
|
:type _preload_content: bool, optional
|
||||||
|
:param _return_http_data_only: response data instead of ApiResponse
|
||||||
|
object with status code, headers, etc
|
||||||
|
:type _return_http_data_only: 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
|
||||||
|
:type _content_type: string, optional: force content-type for the request
|
||||||
|
:return: Returns the result object.
|
||||||
|
If the method is called asynchronously,
|
||||||
|
returns the request thread.
|
||||||
|
:rtype: tuple(str, status_code(int), headers(HTTPHeaderDict))
|
||||||
|
"""
|
||||||
|
|
||||||
|
_params = locals()
|
||||||
|
|
||||||
|
_all_params = [
|
||||||
|
'path_string',
|
||||||
|
'path_integer'
|
||||||
|
]
|
||||||
|
_all_params.extend(
|
||||||
|
[
|
||||||
|
'async_req',
|
||||||
|
'_return_http_data_only',
|
||||||
|
'_preload_content',
|
||||||
|
'_request_timeout',
|
||||||
|
'_request_auth',
|
||||||
|
'_content_type',
|
||||||
|
'_headers'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# validate the arguments
|
||||||
|
for _key, _val in _params['kwargs'].items():
|
||||||
|
if _key not in _all_params:
|
||||||
|
raise ApiTypeError(
|
||||||
|
"Got an unexpected keyword argument '%s'"
|
||||||
|
" to method tests_path_string_path_string_integer_path_integer" % _key
|
||||||
|
)
|
||||||
|
_params[_key] = _val
|
||||||
|
del _params['kwargs']
|
||||||
|
|
||||||
|
_collection_formats = {}
|
||||||
|
|
||||||
|
# process the path parameters
|
||||||
|
_path_params = {}
|
||||||
|
if _params['path_string'] is not None:
|
||||||
|
_path_params['path_string'] = _params['path_string']
|
||||||
|
|
||||||
|
if _params['path_integer'] is not None:
|
||||||
|
_path_params['path_integer'] = _params['path_integer']
|
||||||
|
|
||||||
|
|
||||||
|
# process the query parameters
|
||||||
|
_query_params = []
|
||||||
|
# process the header parameters
|
||||||
|
_header_params = dict(_params.get('_headers', {}))
|
||||||
|
# process the form parameters
|
||||||
|
_form_params = []
|
||||||
|
_files = {}
|
||||||
|
# process the body parameter
|
||||||
|
_body_params = None
|
||||||
|
# set the HTTP header `Accept`
|
||||||
|
_header_params['Accept'] = self.api_client.select_header_accept(
|
||||||
|
['text/plain']) # noqa: E501
|
||||||
|
|
||||||
|
# authentication setting
|
||||||
|
_auth_settings = [] # noqa: E501
|
||||||
|
|
||||||
|
_response_types_map = {
|
||||||
|
'200': "str",
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.api_client.call_api(
|
||||||
|
'/path/string/{path_string}/integer/{path_integer}', 'GET',
|
||||||
|
_path_params,
|
||||||
|
_query_params,
|
||||||
|
_header_params,
|
||||||
|
body=_body_params,
|
||||||
|
post_params=_form_params,
|
||||||
|
files=_files,
|
||||||
|
response_types_map=_response_types_map,
|
||||||
|
auth_settings=_auth_settings,
|
||||||
|
async_req=_params.get('async_req'),
|
||||||
|
_return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501
|
||||||
|
_preload_content=_params.get('_preload_content', True),
|
||||||
|
_request_timeout=_params.get('_request_timeout'),
|
||||||
|
collection_formats=_collection_formats,
|
||||||
|
_request_auth=_params.get('_request_auth'))
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,760 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
import atexit
|
||||||
|
import datetime
|
||||||
|
from dateutil.parser import parse
|
||||||
|
import json
|
||||||
|
import mimetypes
|
||||||
|
from multiprocessing.pool import ThreadPool
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
from openapi_client.configuration import Configuration
|
||||||
|
from openapi_client.api_response import ApiResponse
|
||||||
|
import openapi_client.models
|
||||||
|
from openapi_client import rest
|
||||||
|
from openapi_client.exceptions import ApiValueError, ApiException
|
||||||
|
|
||||||
|
|
||||||
|
class ApiClient:
|
||||||
|
"""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.
|
||||||
|
|
||||||
|
: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, str, int)
|
||||||
|
NATIVE_TYPES_MAPPING = {
|
||||||
|
'int': int,
|
||||||
|
'long': int, # TODO remove as only py3 is supported?
|
||||||
|
'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) -> None:
|
||||||
|
# use default configuration if none is provided
|
||||||
|
if configuration is None:
|
||||||
|
configuration = Configuration.get_default()
|
||||||
|
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 = 'OpenAPI-Generator/1.0.0/python'
|
||||||
|
self.client_side_validation = configuration.client_side_validation
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
_default = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_default(cls):
|
||||||
|
"""Return new instance of ApiClient.
|
||||||
|
|
||||||
|
This method returns newly created, based on default constructor,
|
||||||
|
object of ApiClient class or returns a copy of default
|
||||||
|
ApiClient.
|
||||||
|
|
||||||
|
:return: The ApiClient object.
|
||||||
|
"""
|
||||||
|
if cls._default is None:
|
||||||
|
cls._default = ApiClient()
|
||||||
|
return cls._default
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_default(cls, default):
|
||||||
|
"""Set default instance of ApiClient.
|
||||||
|
|
||||||
|
It stores default ApiClient.
|
||||||
|
|
||||||
|
:param default: object of ApiClient.
|
||||||
|
"""
|
||||||
|
cls._default = default
|
||||||
|
|
||||||
|
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)
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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,
|
||||||
|
resource_path, method, body,
|
||||||
|
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
|
||||||
|
|
||||||
|
# query parameters
|
||||||
|
if query_params:
|
||||||
|
query_params = self.sanitize_for_serialization(query_params)
|
||||||
|
url_query = self.parameters_to_url_query(query_params,
|
||||||
|
collection_formats)
|
||||||
|
url += "?" + url_query
|
||||||
|
|
||||||
|
try:
|
||||||
|
# perform request and return response
|
||||||
|
response_data = 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:
|
||||||
|
if e.body:
|
||||||
|
e.body = e.body.decode('utf-8')
|
||||||
|
raise e
|
||||||
|
|
||||||
|
self.last_response = response_data
|
||||||
|
|
||||||
|
return_data = None # assuming deserialization is not needed
|
||||||
|
# data needs deserialization or returns HTTP data (deserialized) only
|
||||||
|
if _preload_content or _return_http_data_only:
|
||||||
|
response_type = response_types_map.get(str(response_data.status), None)
|
||||||
|
if not response_type and isinstance(response_data.status, int) and 100 <= response_data.status <= 599:
|
||||||
|
# if not found, look for '1XX', '2XX', etc.
|
||||||
|
response_type = response_types_map.get(str(response_data.status)[0] + "XX", None)
|
||||||
|
|
||||||
|
if response_type == "bytearray":
|
||||||
|
response_data.data = response_data.data
|
||||||
|
else:
|
||||||
|
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 == "bytearray":
|
||||||
|
return_data = response_data.data
|
||||||
|
elif response_type:
|
||||||
|
return_data = self.deserialize(response_data, response_type)
|
||||||
|
else:
|
||||||
|
return_data = None
|
||||||
|
|
||||||
|
if _return_http_data_only:
|
||||||
|
return return_data
|
||||||
|
else:
|
||||||
|
return ApiResponse(status_code = response_data.status,
|
||||||
|
data = return_data,
|
||||||
|
headers = response_data.getheaders(),
|
||||||
|
raw_data = response_data.data)
|
||||||
|
|
||||||
|
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.to_dict()
|
||||||
|
|
||||||
|
return {key: self.sanitize_for_serialization(val)
|
||||||
|
for key, val in obj_dict.items()}
|
||||||
|
|
||||||
|
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 isinstance(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 data.items()}
|
||||||
|
|
||||||
|
# convert str to class
|
||||||
|
if klass in self.NATIVE_TYPES_MAPPING:
|
||||||
|
klass = self.NATIVE_TYPES_MAPPING[klass]
|
||||||
|
else:
|
||||||
|
klass = getattr(openapi_client.models, 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 instead of ApiResponse
|
||||||
|
object with status code, headers, etc
|
||||||
|
:param _preload_content: if False, the ApiResponse.data will
|
||||||
|
be set to none and raw_data will store the
|
||||||
|
HTTP response body without reading/decoding.
|
||||||
|
Default is True.
|
||||||
|
:param collection_formats: dict of collection formats for path, query,
|
||||||
|
header, and post parameters.
|
||||||
|
: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.
|
||||||
|
"""
|
||||||
|
args = (
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
if not async_req:
|
||||||
|
return self.__call_api(*args)
|
||||||
|
|
||||||
|
return self.pool.apply_async(self.__call_api, args)
|
||||||
|
|
||||||
|
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_request(url,
|
||||||
|
query_params=query_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
headers=headers)
|
||||||
|
elif method == "HEAD":
|
||||||
|
return self.rest_client.head_request(url,
|
||||||
|
query_params=query_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
|
headers=headers)
|
||||||
|
elif method == "OPTIONS":
|
||||||
|
return self.rest_client.options_request(url,
|
||||||
|
query_params=query_params,
|
||||||
|
headers=headers,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout)
|
||||||
|
elif method == "POST":
|
||||||
|
return self.rest_client.post_request(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_request(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_request(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_request(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 params.items() 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 parameters_to_url_query(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: URL query string (e.g. a=Hello%20World&b=123)
|
||||||
|
"""
|
||||||
|
new_params = []
|
||||||
|
if collection_formats is None:
|
||||||
|
collection_formats = {}
|
||||||
|
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
||||||
|
if isinstance(v, (int, float)):
|
||||||
|
v = str(v)
|
||||||
|
if isinstance(v, bool):
|
||||||
|
v = str(v).lower()
|
||||||
|
if isinstance(v, dict):
|
||||||
|
v = json.dumps(v)
|
||||||
|
|
||||||
|
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(quote(str(value)) for value in v)))
|
||||||
|
else:
|
||||||
|
new_params.append((k, quote(str(v))))
|
||||||
|
|
||||||
|
return "&".join(["=".join(item) for item in 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 files.items():
|
||||||
|
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
|
||||||
|
|
||||||
|
for accept in accepts:
|
||||||
|
if re.search('json', accept, re.IGNORECASE):
|
||||||
|
return accept
|
||||||
|
|
||||||
|
return accepts[0]
|
||||||
|
|
||||||
|
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 None
|
||||||
|
|
||||||
|
for content_type in content_types:
|
||||||
|
if re.search('json', content_type, re.IGNORECASE):
|
||||||
|
return content_type
|
||||||
|
|
||||||
|
return content_types[0]
|
||||||
|
|
||||||
|
def update_params_for_auth(self, headers, queries, auth_settings,
|
||||||
|
resource_path, method, body,
|
||||||
|
request_auth=None):
|
||||||
|
"""Updates header and query params based on authentication setting.
|
||||||
|
|
||||||
|
:param headers: Header parameters dict to be updated.
|
||||||
|
:param queries: Query parameters tuple list to be updated.
|
||||||
|
:param auth_settings: Authentication setting identifiers list.
|
||||||
|
:resource_path: A string representation of the HTTP request resource path.
|
||||||
|
:method: A string representation of the HTTP request method.
|
||||||
|
:body: A object representing the body of the HTTP request.
|
||||||
|
The object type is the return value of sanitize_for_serialization().
|
||||||
|
: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, queries,
|
||||||
|
resource_path, method, body,
|
||||||
|
request_auth)
|
||||||
|
return
|
||||||
|
|
||||||
|
for auth in auth_settings:
|
||||||
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
|
if auth_setting:
|
||||||
|
self._apply_auth_params(headers, queries,
|
||||||
|
resource_path, method, body,
|
||||||
|
auth_setting)
|
||||||
|
|
||||||
|
def _apply_auth_params(self, headers, queries,
|
||||||
|
resource_path, method, body,
|
||||||
|
auth_setting):
|
||||||
|
"""Updates the request parameters based on a single auth_setting
|
||||||
|
|
||||||
|
:param headers: Header parameters dict to be updated.
|
||||||
|
:param queries: Query parameters tuple list to be updated.
|
||||||
|
:resource_path: A string representation of the HTTP request resource path.
|
||||||
|
:method: A string representation of the HTTP request method.
|
||||||
|
:body: A object representing the body of the HTTP request.
|
||||||
|
The object type is the return value of sanitize_for_serialization().
|
||||||
|
:param auth_setting: auth settings for the endpoint
|
||||||
|
"""
|
||||||
|
if auth_setting['in'] == 'cookie':
|
||||||
|
headers['Cookie'] = auth_setting['value']
|
||||||
|
elif auth_setting['in'] == 'header':
|
||||||
|
if auth_setting['type'] != 'http-signature':
|
||||||
|
headers[auth_setting['key']] = auth_setting['value']
|
||||||
|
elif auth_setting['in'] == 'query':
|
||||||
|
queries.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 str(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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return klass.from_dict(data)
|
@ -0,0 +1,25 @@
|
|||||||
|
"""API response object."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
from typing import Any, Dict, Optional
|
||||||
|
from pydantic import Field, StrictInt, StrictStr
|
||||||
|
|
||||||
|
class ApiResponse:
|
||||||
|
"""
|
||||||
|
API response object
|
||||||
|
"""
|
||||||
|
|
||||||
|
status_code: Optional[StrictInt] = Field(None, description="HTTP status code")
|
||||||
|
headers: Optional[Dict[StrictStr, StrictStr]] = Field(None, description="HTTP headers")
|
||||||
|
data: Optional[Any] = Field(None, description="Deserialized data given the data type")
|
||||||
|
raw_data: Optional[Any] = Field(None, description="Raw data (HTTP response body)")
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
status_code=None,
|
||||||
|
headers=None,
|
||||||
|
data=None,
|
||||||
|
raw_data=None) -> None:
|
||||||
|
self.status_code = status_code
|
||||||
|
self.headers = headers
|
||||||
|
self.data = data
|
||||||
|
self.raw_data = raw_data
|
@ -0,0 +1,459 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
import copy
|
||||||
|
import logging
|
||||||
|
import multiprocessing
|
||||||
|
import sys
|
||||||
|
import urllib3
|
||||||
|
|
||||||
|
import http.client as httplib
|
||||||
|
|
||||||
|
JSON_SCHEMA_VALIDATION_KEYWORDS = {
|
||||||
|
'multipleOf', 'maximum', 'exclusiveMaximum',
|
||||||
|
'minimum', 'exclusiveMinimum', 'maxLength',
|
||||||
|
'minLength', 'pattern', 'maxItems', 'minItems'
|
||||||
|
}
|
||||||
|
|
||||||
|
class Configuration:
|
||||||
|
"""This class contains various settings of the API client.
|
||||||
|
|
||||||
|
:param host: Base url.
|
||||||
|
:param api_key: Dict to store API key(s).
|
||||||
|
Each entry in the dict specifies an API key.
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is the API key secret.
|
||||||
|
:param api_key_prefix: Dict to store API prefix (e.g. Bearer).
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is an API key prefix when generating the auth data.
|
||||||
|
:param username: Username for HTTP basic authentication.
|
||||||
|
:param password: Password for HTTP basic authentication.
|
||||||
|
:param access_token: Access token.
|
||||||
|
:param server_index: Index to servers configuration.
|
||||||
|
:param server_variables: Mapping with string values to replace variables in
|
||||||
|
templated server configuration. The validation of enums is performed for
|
||||||
|
variables with defined enum values before.
|
||||||
|
:param server_operation_index: Mapping from operation ID to an index to server
|
||||||
|
configuration.
|
||||||
|
:param server_operation_variables: Mapping from operation ID to a mapping with
|
||||||
|
string values to replace variables in templated server configuration.
|
||||||
|
The validation of enums is performed for variables with defined enum
|
||||||
|
values before.
|
||||||
|
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
||||||
|
in PEM format.
|
||||||
|
|
||||||
|
:Example:
|
||||||
|
|
||||||
|
HTTP Basic Authentication Example.
|
||||||
|
Given the following security scheme in the OpenAPI specification:
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
http_basic_auth:
|
||||||
|
type: http
|
||||||
|
scheme: basic
|
||||||
|
|
||||||
|
Configure API client with HTTP basic authentication:
|
||||||
|
|
||||||
|
conf = openapi_client.Configuration(
|
||||||
|
username='the-user',
|
||||||
|
password='the-password',
|
||||||
|
)
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
_default = None
|
||||||
|
|
||||||
|
def __init__(self, host=None,
|
||||||
|
api_key=None, api_key_prefix=None,
|
||||||
|
username=None, password=None,
|
||||||
|
access_token=None,
|
||||||
|
server_index=None, server_variables=None,
|
||||||
|
server_operation_index=None, server_operation_variables=None,
|
||||||
|
ssl_ca_cert=None,
|
||||||
|
) -> None:
|
||||||
|
"""Constructor
|
||||||
|
"""
|
||||||
|
self._base_path = "http://localhost:3000" if host is None else host
|
||||||
|
"""Default Base url
|
||||||
|
"""
|
||||||
|
self.server_index = 0 if server_index is None and host is None else server_index
|
||||||
|
self.server_operation_index = server_operation_index or {}
|
||||||
|
"""Default server index
|
||||||
|
"""
|
||||||
|
self.server_variables = server_variables or {}
|
||||||
|
self.server_operation_variables = server_operation_variables or {}
|
||||||
|
"""Default server variables
|
||||||
|
"""
|
||||||
|
self.temp_folder_path = None
|
||||||
|
"""Temp file folder for downloading files
|
||||||
|
"""
|
||||||
|
# Authentication Settings
|
||||||
|
self.api_key = {}
|
||||||
|
if api_key:
|
||||||
|
self.api_key = api_key
|
||||||
|
"""dict to store API key(s)
|
||||||
|
"""
|
||||||
|
self.api_key_prefix = {}
|
||||||
|
if api_key_prefix:
|
||||||
|
self.api_key_prefix = api_key_prefix
|
||||||
|
"""dict to store API prefix (e.g. Bearer)
|
||||||
|
"""
|
||||||
|
self.refresh_api_key_hook = None
|
||||||
|
"""function hook to refresh API key if expired
|
||||||
|
"""
|
||||||
|
self.username = username
|
||||||
|
"""Username for HTTP basic authentication
|
||||||
|
"""
|
||||||
|
self.password = password
|
||||||
|
"""Password for HTTP basic authentication
|
||||||
|
"""
|
||||||
|
self.access_token = access_token
|
||||||
|
"""Access token
|
||||||
|
"""
|
||||||
|
self.logger = {}
|
||||||
|
"""Logging Settings
|
||||||
|
"""
|
||||||
|
self.logger["package_logger"] = logging.getLogger("openapi_client")
|
||||||
|
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
|
||||||
|
self.logger_format = '%(asctime)s %(levelname)s %(message)s'
|
||||||
|
"""Log format
|
||||||
|
"""
|
||||||
|
self.logger_stream_handler = None
|
||||||
|
"""Log stream handler
|
||||||
|
"""
|
||||||
|
self.logger_file_handler = None
|
||||||
|
"""Log file handler
|
||||||
|
"""
|
||||||
|
self.logger_file = None
|
||||||
|
"""Debug file location
|
||||||
|
"""
|
||||||
|
self.debug = False
|
||||||
|
"""Debug switch
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.verify_ssl = True
|
||||||
|
"""SSL/TLS verification
|
||||||
|
Set this to false to skip verifying SSL certificate when calling API
|
||||||
|
from https server.
|
||||||
|
"""
|
||||||
|
self.ssl_ca_cert = ssl_ca_cert
|
||||||
|
"""Set this to customize the certificate file to verify the peer.
|
||||||
|
"""
|
||||||
|
self.cert_file = None
|
||||||
|
"""client certificate file
|
||||||
|
"""
|
||||||
|
self.key_file = None
|
||||||
|
"""client key file
|
||||||
|
"""
|
||||||
|
self.assert_hostname = None
|
||||||
|
"""Set this to True/False to enable/disable SSL hostname verification.
|
||||||
|
"""
|
||||||
|
self.tls_server_name = None
|
||||||
|
"""SSL/TLS Server Name Indication (SNI)
|
||||||
|
Set this to the SNI value expected by the server.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
|
||||||
|
"""urllib3 connection pool's maximum number of connections saved
|
||||||
|
per pool. urllib3 uses 1 connection as default value, but this is
|
||||||
|
not the best value when you are making a lot of possibly parallel
|
||||||
|
requests to the same host, which is often the case here.
|
||||||
|
cpu_count * 5 is used as default value to increase performance.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.proxy = None
|
||||||
|
"""Proxy URL
|
||||||
|
"""
|
||||||
|
self.proxy_headers = None
|
||||||
|
"""Proxy headers
|
||||||
|
"""
|
||||||
|
self.safe_chars_for_path_param = ''
|
||||||
|
"""Safe chars for path_param
|
||||||
|
"""
|
||||||
|
self.retries = None
|
||||||
|
"""Adding retries to override urllib3 default value 3
|
||||||
|
"""
|
||||||
|
# Enable client side validation
|
||||||
|
self.client_side_validation = True
|
||||||
|
|
||||||
|
self.socket_options = None
|
||||||
|
"""Options to pass down to the underlying urllib3 socket
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
|
||||||
|
"""datetime format
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.date_format = "%Y-%m-%d"
|
||||||
|
"""date format
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __deepcopy__(self, memo):
|
||||||
|
cls = self.__class__
|
||||||
|
result = cls.__new__(cls)
|
||||||
|
memo[id(self)] = result
|
||||||
|
for k, v in self.__dict__.items():
|
||||||
|
if k not in ('logger', 'logger_file_handler'):
|
||||||
|
setattr(result, k, copy.deepcopy(v, memo))
|
||||||
|
# shallow copy of loggers
|
||||||
|
result.logger = copy.copy(self.logger)
|
||||||
|
# use setters to configure loggers
|
||||||
|
result.logger_file = self.logger_file
|
||||||
|
result.debug = self.debug
|
||||||
|
return result
|
||||||
|
|
||||||
|
def __setattr__(self, name, value):
|
||||||
|
object.__setattr__(self, name, value)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_default(cls, default):
|
||||||
|
"""Set default instance of configuration.
|
||||||
|
|
||||||
|
It stores default configuration, which can be
|
||||||
|
returned by get_default_copy method.
|
||||||
|
|
||||||
|
:param default: object of Configuration
|
||||||
|
"""
|
||||||
|
cls._default = default
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_default_copy(cls):
|
||||||
|
"""Deprecated. Please use `get_default` instead.
|
||||||
|
|
||||||
|
Deprecated. Please use `get_default` instead.
|
||||||
|
|
||||||
|
:return: The configuration object.
|
||||||
|
"""
|
||||||
|
return cls.get_default()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_default(cls):
|
||||||
|
"""Return the default configuration.
|
||||||
|
|
||||||
|
This method returns newly created, based on default constructor,
|
||||||
|
object of Configuration class or returns a copy of default
|
||||||
|
configuration.
|
||||||
|
|
||||||
|
:return: The configuration object.
|
||||||
|
"""
|
||||||
|
if cls._default is None:
|
||||||
|
cls._default = Configuration()
|
||||||
|
return cls._default
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logger_file(self):
|
||||||
|
"""The logger file.
|
||||||
|
|
||||||
|
If the logger_file is None, then add stream handler and remove file
|
||||||
|
handler. Otherwise, add file handler and remove stream handler.
|
||||||
|
|
||||||
|
:param value: The logger_file path.
|
||||||
|
:type: str
|
||||||
|
"""
|
||||||
|
return self.__logger_file
|
||||||
|
|
||||||
|
@logger_file.setter
|
||||||
|
def logger_file(self, value):
|
||||||
|
"""The logger file.
|
||||||
|
|
||||||
|
If the logger_file is None, then add stream handler and remove file
|
||||||
|
handler. Otherwise, add file handler and remove stream handler.
|
||||||
|
|
||||||
|
:param value: The logger_file path.
|
||||||
|
:type: str
|
||||||
|
"""
|
||||||
|
self.__logger_file = value
|
||||||
|
if self.__logger_file:
|
||||||
|
# If set logging file,
|
||||||
|
# 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():
|
||||||
|
logger.addHandler(self.logger_file_handler)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def debug(self):
|
||||||
|
"""Debug status
|
||||||
|
|
||||||
|
:param value: The debug status, True or False.
|
||||||
|
:type: bool
|
||||||
|
"""
|
||||||
|
return self.__debug
|
||||||
|
|
||||||
|
@debug.setter
|
||||||
|
def debug(self, value):
|
||||||
|
"""Debug status
|
||||||
|
|
||||||
|
:param value: The debug status, True or False.
|
||||||
|
:type: bool
|
||||||
|
"""
|
||||||
|
self.__debug = value
|
||||||
|
if self.__debug:
|
||||||
|
# if debug status is True, turn on debug logging
|
||||||
|
for _, logger in self.logger.items():
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
# 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():
|
||||||
|
logger.setLevel(logging.WARNING)
|
||||||
|
# turn off httplib debug
|
||||||
|
httplib.HTTPConnection.debuglevel = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logger_format(self):
|
||||||
|
"""The logger format.
|
||||||
|
|
||||||
|
The logger_formatter will be updated when sets logger_format.
|
||||||
|
|
||||||
|
:param value: The format string.
|
||||||
|
:type: str
|
||||||
|
"""
|
||||||
|
return self.__logger_format
|
||||||
|
|
||||||
|
@logger_format.setter
|
||||||
|
def logger_format(self, value):
|
||||||
|
"""The logger format.
|
||||||
|
|
||||||
|
The logger_formatter will be updated when sets logger_format.
|
||||||
|
|
||||||
|
:param value: The format string.
|
||||||
|
:type: str
|
||||||
|
"""
|
||||||
|
self.__logger_format = value
|
||||||
|
self.logger_formatter = logging.Formatter(self.__logger_format)
|
||||||
|
|
||||||
|
def get_api_key_with_prefix(self, identifier, alias=None):
|
||||||
|
"""Gets API key (with prefix if set).
|
||||||
|
|
||||||
|
:param identifier: The identifier of apiKey.
|
||||||
|
:param alias: The alternative identifier of apiKey.
|
||||||
|
:return: The token for api key authentication.
|
||||||
|
"""
|
||||||
|
if self.refresh_api_key_hook is not None:
|
||||||
|
self.refresh_api_key_hook(self)
|
||||||
|
key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
|
||||||
|
if key:
|
||||||
|
prefix = self.api_key_prefix.get(identifier)
|
||||||
|
if prefix:
|
||||||
|
return "%s %s" % (prefix, key)
|
||||||
|
else:
|
||||||
|
return key
|
||||||
|
|
||||||
|
def get_basic_auth_token(self):
|
||||||
|
"""Gets HTTP basic authentication header (string).
|
||||||
|
|
||||||
|
:return: The token for basic HTTP authentication.
|
||||||
|
"""
|
||||||
|
username = ""
|
||||||
|
if self.username is not None:
|
||||||
|
username = self.username
|
||||||
|
password = ""
|
||||||
|
if self.password is not None:
|
||||||
|
password = self.password
|
||||||
|
return urllib3.util.make_headers(
|
||||||
|
basic_auth=username + ':' + password
|
||||||
|
).get('authorization')
|
||||||
|
|
||||||
|
def auth_settings(self):
|
||||||
|
"""Gets Auth Settings dict for api client.
|
||||||
|
|
||||||
|
:return: The Auth Settings information dict.
|
||||||
|
"""
|
||||||
|
auth = {}
|
||||||
|
if self.username is not None and self.password is not None:
|
||||||
|
auth['http_auth'] = {
|
||||||
|
'type': 'basic',
|
||||||
|
'in': 'header',
|
||||||
|
'key': 'Authorization',
|
||||||
|
'value': self.get_basic_auth_token()
|
||||||
|
}
|
||||||
|
return auth
|
||||||
|
|
||||||
|
def to_debug_report(self):
|
||||||
|
"""Gets the essential information for debugging.
|
||||||
|
|
||||||
|
:return: The report for debugging.
|
||||||
|
"""
|
||||||
|
return "Python SDK Debug Report:\n"\
|
||||||
|
"OS: {env}\n"\
|
||||||
|
"Python Version: {pyversion}\n"\
|
||||||
|
"Version of the API: 0.1.0\n"\
|
||||||
|
"SDK Package Version: 1.0.0".\
|
||||||
|
format(env=sys.platform, pyversion=sys.version)
|
||||||
|
|
||||||
|
def get_host_settings(self):
|
||||||
|
"""Gets an array of host settings
|
||||||
|
|
||||||
|
:return: An array of host settings
|
||||||
|
"""
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
'url': "http://localhost:3000",
|
||||||
|
'description': "No description provided",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_host_from_settings(self, index, variables=None, servers=None):
|
||||||
|
"""Gets host URL based on the index and variables
|
||||||
|
:param index: array index of the host settings
|
||||||
|
:param variables: hash of variable and the corresponding value
|
||||||
|
:param servers: an array of host settings or None
|
||||||
|
:return: URL based on host settings
|
||||||
|
"""
|
||||||
|
if index is None:
|
||||||
|
return self._base_path
|
||||||
|
|
||||||
|
variables = {} if variables is None else variables
|
||||||
|
servers = self.get_host_settings() if servers is None else servers
|
||||||
|
|
||||||
|
try:
|
||||||
|
server = servers[index]
|
||||||
|
except IndexError:
|
||||||
|
raise ValueError(
|
||||||
|
"Invalid index {0} when selecting the host settings. "
|
||||||
|
"Must be less than {1}".format(index, len(servers)))
|
||||||
|
|
||||||
|
url = server['url']
|
||||||
|
|
||||||
|
# go through variables and replace placeholders
|
||||||
|
for variable_name, variable in server.get('variables', {}).items():
|
||||||
|
used_value = variables.get(
|
||||||
|
variable_name, variable['default_value'])
|
||||||
|
|
||||||
|
if 'enum_values' in variable \
|
||||||
|
and used_value not in variable['enum_values']:
|
||||||
|
raise ValueError(
|
||||||
|
"The variable `{0}` in the host URL has invalid value "
|
||||||
|
"{1}. Must be {2}.".format(
|
||||||
|
variable_name, variables[variable_name],
|
||||||
|
variable['enum_values']))
|
||||||
|
|
||||||
|
url = url.replace("{" + variable_name + "}", used_value)
|
||||||
|
|
||||||
|
return url
|
||||||
|
|
||||||
|
@property
|
||||||
|
def host(self):
|
||||||
|
"""Return generated host."""
|
||||||
|
return self.get_host_from_settings(self.server_index, variables=self.server_variables)
|
||||||
|
|
||||||
|
@host.setter
|
||||||
|
def host(self, value):
|
||||||
|
"""Fix base path."""
|
||||||
|
self._base_path = value
|
||||||
|
self.server_index = None
|
@ -0,0 +1,167 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
class OpenApiException(Exception):
|
||||||
|
"""The base exception class for all OpenAPIExceptions"""
|
||||||
|
|
||||||
|
|
||||||
|
class ApiTypeError(OpenApiException, TypeError):
|
||||||
|
def __init__(self, msg, path_to_item=None, valid_classes=None,
|
||||||
|
key_type=None) -> None:
|
||||||
|
""" Raises an exception for TypeErrors
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): the exception message
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
path_to_item (list): a list of keys an indices to get to the
|
||||||
|
current_item
|
||||||
|
None if unset
|
||||||
|
valid_classes (tuple): the primitive classes that current item
|
||||||
|
should be an instance of
|
||||||
|
None if unset
|
||||||
|
key_type (bool): False if our value is a value in a dict
|
||||||
|
True if it is a key in a dict
|
||||||
|
False if our item is an item in a list
|
||||||
|
None if unset
|
||||||
|
"""
|
||||||
|
self.path_to_item = path_to_item
|
||||||
|
self.valid_classes = valid_classes
|
||||||
|
self.key_type = key_type
|
||||||
|
full_msg = msg
|
||||||
|
if path_to_item:
|
||||||
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||||
|
super(ApiTypeError, self).__init__(full_msg)
|
||||||
|
|
||||||
|
|
||||||
|
class ApiValueError(OpenApiException, ValueError):
|
||||||
|
def __init__(self, msg, path_to_item=None) -> None:
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
msg (str): the exception message
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
path_to_item (list) the path to the exception in the
|
||||||
|
received_data dict. None if unset
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.path_to_item = path_to_item
|
||||||
|
full_msg = msg
|
||||||
|
if path_to_item:
|
||||||
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||||
|
super(ApiValueError, self).__init__(full_msg)
|
||||||
|
|
||||||
|
|
||||||
|
class ApiAttributeError(OpenApiException, AttributeError):
|
||||||
|
def __init__(self, msg, path_to_item=None) -> None:
|
||||||
|
"""
|
||||||
|
Raised when an attribute reference or assignment fails.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg (str): the exception message
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
path_to_item (None/list) the path to the exception in the
|
||||||
|
received_data dict
|
||||||
|
"""
|
||||||
|
self.path_to_item = path_to_item
|
||||||
|
full_msg = msg
|
||||||
|
if path_to_item:
|
||||||
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||||
|
super(ApiAttributeError, self).__init__(full_msg)
|
||||||
|
|
||||||
|
|
||||||
|
class ApiKeyError(OpenApiException, KeyError):
|
||||||
|
def __init__(self, msg, path_to_item=None) -> None:
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
msg (str): the exception message
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
path_to_item (None/list) the path to the exception in the
|
||||||
|
received_data dict
|
||||||
|
"""
|
||||||
|
self.path_to_item = path_to_item
|
||||||
|
full_msg = msg
|
||||||
|
if path_to_item:
|
||||||
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||||
|
super(ApiKeyError, self).__init__(full_msg)
|
||||||
|
|
||||||
|
|
||||||
|
class ApiException(OpenApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> None:
|
||||||
|
if http_resp:
|
||||||
|
self.status = http_resp.status
|
||||||
|
self.reason = http_resp.reason
|
||||||
|
self.body = http_resp.data
|
||||||
|
self.headers = http_resp.getheaders()
|
||||||
|
else:
|
||||||
|
self.status = status
|
||||||
|
self.reason = reason
|
||||||
|
self.body = None
|
||||||
|
self.headers = None
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""Custom error messages for exception"""
|
||||||
|
error_message = "({0})\n"\
|
||||||
|
"Reason: {1}\n".format(self.status, self.reason)
|
||||||
|
if self.headers:
|
||||||
|
error_message += "HTTP response headers: {0}\n".format(
|
||||||
|
self.headers)
|
||||||
|
|
||||||
|
if self.body:
|
||||||
|
error_message += "HTTP response body: {0}\n".format(self.body)
|
||||||
|
|
||||||
|
return error_message
|
||||||
|
|
||||||
|
class BadRequestException(ApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> None:
|
||||||
|
super(BadRequestException, self).__init__(status, reason, http_resp)
|
||||||
|
|
||||||
|
class NotFoundException(ApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> None:
|
||||||
|
super(NotFoundException, self).__init__(status, reason, http_resp)
|
||||||
|
|
||||||
|
|
||||||
|
class UnauthorizedException(ApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> None:
|
||||||
|
super(UnauthorizedException, self).__init__(status, reason, http_resp)
|
||||||
|
|
||||||
|
|
||||||
|
class ForbiddenException(ApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> None:
|
||||||
|
super(ForbiddenException, self).__init__(status, reason, http_resp)
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceException(ApiException):
|
||||||
|
|
||||||
|
def __init__(self, status=None, reason=None, http_resp=None) -> 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):
|
||||||
|
result += "[{0}]".format(pth)
|
||||||
|
else:
|
||||||
|
result += "['{0}']".format(pth)
|
||||||
|
return result
|
@ -0,0 +1,28 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
# flake8: noqa
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
# import models into model package
|
||||||
|
from openapi_client.models.bird import Bird
|
||||||
|
from openapi_client.models.category import Category
|
||||||
|
from openapi_client.models.data_query import DataQuery
|
||||||
|
from openapi_client.models.default_value import DefaultValue
|
||||||
|
from openapi_client.models.number_properties_only import NumberPropertiesOnly
|
||||||
|
from openapi_client.models.pet import Pet
|
||||||
|
from openapi_client.models.query import Query
|
||||||
|
from openapi_client.models.string_enum_ref import StringEnumRef
|
||||||
|
from openapi_client.models.tag import Tag
|
||||||
|
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
|
||||||
|
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter
|
@ -0,0 +1,74 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
from pydantic import BaseModel, StrictStr
|
||||||
|
|
||||||
|
class Bird(BaseModel):
|
||||||
|
"""
|
||||||
|
Bird
|
||||||
|
"""
|
||||||
|
size: Optional[StrictStr] = None
|
||||||
|
color: Optional[StrictStr] = None
|
||||||
|
__properties = ["size", "color"]
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> Bird:
|
||||||
|
"""Create an instance of Bird from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> Bird:
|
||||||
|
"""Create an instance of Bird from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return Bird.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = Bird.parse_obj({
|
||||||
|
"size": obj.get("size"),
|
||||||
|
"color": obj.get("color")
|
||||||
|
})
|
||||||
|
return _obj
|
||||||
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
from pydantic import BaseModel, StrictInt, StrictStr
|
||||||
|
|
||||||
|
class Category(BaseModel):
|
||||||
|
"""
|
||||||
|
Category
|
||||||
|
"""
|
||||||
|
id: Optional[StrictInt] = None
|
||||||
|
name: Optional[StrictStr] = None
|
||||||
|
__properties = ["id", "name"]
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> Category:
|
||||||
|
"""Create an instance of Category from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> Category:
|
||||||
|
"""Create an instance of Category from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return Category.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = Category.parse_obj({
|
||||||
|
"id": obj.get("id"),
|
||||||
|
"name": obj.get("name")
|
||||||
|
})
|
||||||
|
return _obj
|
||||||
|
|
||||||
|
|
@ -0,0 +1,79 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
from pydantic import Field, StrictStr
|
||||||
|
from openapi_client.models.query import Query
|
||||||
|
|
||||||
|
class DataQuery(Query):
|
||||||
|
"""
|
||||||
|
DataQuery
|
||||||
|
"""
|
||||||
|
suffix: Optional[StrictStr] = Field(None, description="test suffix")
|
||||||
|
text: Optional[StrictStr] = Field(None, description="Some text containing white spaces")
|
||||||
|
var_date: Optional[datetime] = Field(None, alias="date", description="A date")
|
||||||
|
__properties = ["id", "outcomes", "suffix", "text", "date"]
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> DataQuery:
|
||||||
|
"""Create an instance of DataQuery from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> DataQuery:
|
||||||
|
"""Create an instance of DataQuery from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return DataQuery.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = DataQuery.parse_obj({
|
||||||
|
"id": obj.get("id"),
|
||||||
|
"outcomes": obj.get("outcomes"),
|
||||||
|
"suffix": obj.get("suffix"),
|
||||||
|
"text": obj.get("text"),
|
||||||
|
"var_date": obj.get("date")
|
||||||
|
})
|
||||||
|
return _obj
|
||||||
|
|
||||||
|
|
@ -0,0 +1,113 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import List, Optional
|
||||||
|
from pydantic import BaseModel, StrictInt, StrictStr, conlist, validator
|
||||||
|
from openapi_client.models.string_enum_ref import StringEnumRef
|
||||||
|
|
||||||
|
class DefaultValue(BaseModel):
|
||||||
|
"""
|
||||||
|
to test the default value of properties # noqa: E501
|
||||||
|
"""
|
||||||
|
array_string_enum_ref_default: Optional[conlist(StringEnumRef)] = None
|
||||||
|
array_string_enum_default: Optional[conlist(StrictStr)] = None
|
||||||
|
array_string_default: Optional[conlist(StrictStr)] = None
|
||||||
|
array_integer_default: Optional[conlist(StrictInt)] = None
|
||||||
|
array_string: Optional[conlist(StrictStr)] = None
|
||||||
|
array_string_nullable: Optional[conlist(StrictStr)] = None
|
||||||
|
array_string_extension_nullable: Optional[conlist(StrictStr)] = None
|
||||||
|
string_nullable: Optional[StrictStr] = None
|
||||||
|
__properties = ["array_string_enum_ref_default", "array_string_enum_default", "array_string_default", "array_integer_default", "array_string", "array_string_nullable", "array_string_extension_nullable", "string_nullable"]
|
||||||
|
|
||||||
|
@validator('array_string_enum_default')
|
||||||
|
def array_string_enum_default_validate_enum(cls, value):
|
||||||
|
"""Validates the enum"""
|
||||||
|
if value is None:
|
||||||
|
return value
|
||||||
|
|
||||||
|
for i in value:
|
||||||
|
if i not in ('success', 'failure', 'unclassified'):
|
||||||
|
raise ValueError("each list item must be one of ('success', 'failure', 'unclassified')")
|
||||||
|
return value
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> DefaultValue:
|
||||||
|
"""Create an instance of DefaultValue from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
# set to None if array_string_nullable (nullable) is None
|
||||||
|
# and __fields_set__ contains the field
|
||||||
|
if self.array_string_nullable is None and "array_string_nullable" in self.__fields_set__:
|
||||||
|
_dict['array_string_nullable'] = None
|
||||||
|
|
||||||
|
# set to None if array_string_extension_nullable (nullable) is None
|
||||||
|
# and __fields_set__ contains the field
|
||||||
|
if self.array_string_extension_nullable is None and "array_string_extension_nullable" in self.__fields_set__:
|
||||||
|
_dict['array_string_extension_nullable'] = None
|
||||||
|
|
||||||
|
# set to None if string_nullable (nullable) is None
|
||||||
|
# and __fields_set__ contains the field
|
||||||
|
if self.string_nullable is None and "string_nullable" in self.__fields_set__:
|
||||||
|
_dict['string_nullable'] = None
|
||||||
|
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> DefaultValue:
|
||||||
|
"""Create an instance of DefaultValue from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return DefaultValue.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = DefaultValue.parse_obj({
|
||||||
|
"array_string_enum_ref_default": obj.get("array_string_enum_ref_default"),
|
||||||
|
"array_string_enum_default": obj.get("array_string_enum_default"),
|
||||||
|
"array_string_default": obj.get("array_string_default"),
|
||||||
|
"array_integer_default": obj.get("array_integer_default"),
|
||||||
|
"array_string": obj.get("array_string"),
|
||||||
|
"array_string_nullable": obj.get("array_string_nullable"),
|
||||||
|
"array_string_extension_nullable": obj.get("array_string_extension_nullable"),
|
||||||
|
"string_nullable": obj.get("string_nullable")
|
||||||
|
})
|
||||||
|
return _obj
|
||||||
|
|
||||||
|
|
@ -0,0 +1,76 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import Optional, Union
|
||||||
|
from pydantic import BaseModel, StrictFloat, StrictInt, confloat, conint
|
||||||
|
|
||||||
|
class NumberPropertiesOnly(BaseModel):
|
||||||
|
"""
|
||||||
|
NumberPropertiesOnly
|
||||||
|
"""
|
||||||
|
number: Optional[Union[StrictFloat, StrictInt]] = None
|
||||||
|
float: Optional[Union[StrictFloat, StrictInt]] = None
|
||||||
|
double: Optional[Union[confloat(le=50.2, ge=0.8, strict=True), conint(le=50, ge=1, strict=True)]] = None
|
||||||
|
__properties = ["number", "float", "double"]
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> NumberPropertiesOnly:
|
||||||
|
"""Create an instance of NumberPropertiesOnly from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> NumberPropertiesOnly:
|
||||||
|
"""Create an instance of NumberPropertiesOnly from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return NumberPropertiesOnly.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = NumberPropertiesOnly.parse_obj({
|
||||||
|
"number": obj.get("number"),
|
||||||
|
"float": obj.get("float"),
|
||||||
|
"double": obj.get("double")
|
||||||
|
})
|
||||||
|
return _obj
|
||||||
|
|
||||||
|
|
@ -0,0 +1,104 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import List, Optional
|
||||||
|
from pydantic import BaseModel, Field, StrictInt, StrictStr, conlist, validator
|
||||||
|
from openapi_client.models.category import Category
|
||||||
|
from openapi_client.models.tag import Tag
|
||||||
|
|
||||||
|
class Pet(BaseModel):
|
||||||
|
"""
|
||||||
|
Pet
|
||||||
|
"""
|
||||||
|
id: Optional[StrictInt] = None
|
||||||
|
name: StrictStr = Field(...)
|
||||||
|
category: Optional[Category] = None
|
||||||
|
photo_urls: conlist(StrictStr) = Field(..., alias="photoUrls")
|
||||||
|
tags: Optional[conlist(Tag)] = None
|
||||||
|
status: Optional[StrictStr] = Field(None, description="pet status in the store")
|
||||||
|
__properties = ["id", "name", "category", "photoUrls", "tags", "status"]
|
||||||
|
|
||||||
|
@validator('status')
|
||||||
|
def status_validate_enum(cls, value):
|
||||||
|
"""Validates the enum"""
|
||||||
|
if value is None:
|
||||||
|
return value
|
||||||
|
|
||||||
|
if value not in ('available', 'pending', 'sold'):
|
||||||
|
raise ValueError("must be one of enum values ('available', 'pending', 'sold')")
|
||||||
|
return value
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> Pet:
|
||||||
|
"""Create an instance of Pet from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
# override the default output from pydantic by calling `to_dict()` of category
|
||||||
|
if self.category:
|
||||||
|
_dict['category'] = self.category.to_dict()
|
||||||
|
# override the default output from pydantic by calling `to_dict()` of each item in tags (list)
|
||||||
|
_items = []
|
||||||
|
if self.tags:
|
||||||
|
for _item in self.tags:
|
||||||
|
if _item:
|
||||||
|
_items.append(_item.to_dict())
|
||||||
|
_dict['tags'] = _items
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> Pet:
|
||||||
|
"""Create an instance of Pet from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return Pet.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = Pet.parse_obj({
|
||||||
|
"id": obj.get("id"),
|
||||||
|
"name": obj.get("name"),
|
||||||
|
"category": Category.from_dict(obj.get("category")) if obj.get("category") is not None else None,
|
||||||
|
"photo_urls": obj.get("photoUrls"),
|
||||||
|
"tags": [Tag.from_dict(_item) for _item in obj.get("tags")] if obj.get("tags") is not None else None,
|
||||||
|
"status": obj.get("status")
|
||||||
|
})
|
||||||
|
return _obj
|
||||||
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import List, Optional
|
||||||
|
from pydantic import BaseModel, Field, StrictInt, StrictStr, conlist, validator
|
||||||
|
|
||||||
|
class Query(BaseModel):
|
||||||
|
"""
|
||||||
|
Query
|
||||||
|
"""
|
||||||
|
id: Optional[StrictInt] = Field(None, description="Query")
|
||||||
|
outcomes: Optional[conlist(StrictStr)] = None
|
||||||
|
__properties = ["id", "outcomes"]
|
||||||
|
|
||||||
|
@validator('outcomes')
|
||||||
|
def outcomes_validate_enum(cls, value):
|
||||||
|
"""Validates the enum"""
|
||||||
|
if value is None:
|
||||||
|
return value
|
||||||
|
|
||||||
|
for i in value:
|
||||||
|
if i not in ('SUCCESS', 'FAILURE', 'SKIPPED'):
|
||||||
|
raise ValueError("each list item must be one of ('SUCCESS', 'FAILURE', 'SKIPPED')")
|
||||||
|
return value
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> Query:
|
||||||
|
"""Create an instance of Query from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> Query:
|
||||||
|
"""Create an instance of Query from a dict"""
|
||||||
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
import json
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
from aenum import Enum, no_arg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class StringEnumRef(str, Enum):
|
||||||
|
"""
|
||||||
|
StringEnumRef
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
allowed enum values
|
||||||
|
"""
|
||||||
|
SUCCESS = 'success'
|
||||||
|
FAILURE = 'failure'
|
||||||
|
UNCLASSIFIED = 'unclassified'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> StringEnumRef:
|
||||||
|
"""Create an instance of StringEnumRef from a JSON string"""
|
||||||
|
return StringEnumRef(json.loads(json_str))
|
||||||
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
from pydantic import BaseModel, StrictInt, StrictStr
|
||||||
|
|
||||||
|
class Tag(BaseModel):
|
||||||
|
"""
|
||||||
|
Tag
|
||||||
|
"""
|
||||||
|
id: Optional[StrictInt] = None
|
||||||
|
name: Optional[StrictStr] = None
|
||||||
|
__properties = ["id", "name"]
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> Tag:
|
||||||
|
"""Create an instance of Tag from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> Tag:
|
||||||
|
"""Create an instance of Tag from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return Tag.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = Tag.parse_obj({
|
||||||
|
"id": obj.get("id"),
|
||||||
|
"name": obj.get("name")
|
||||||
|
})
|
||||||
|
return _obj
|
||||||
|
|
||||||
|
|
@ -0,0 +1,78 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
Echo Server API
|
||||||
|
|
||||||
|
The version of the OpenAPI document: 0.1.0
|
||||||
|
Contact: team@openapitools.org
|
||||||
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
from pydantic import BaseModel, StrictInt, StrictStr
|
||||||
|
|
||||||
|
class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseModel):
|
||||||
|
"""
|
||||||
|
TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
|
||||||
|
"""
|
||||||
|
size: Optional[StrictStr] = None
|
||||||
|
color: Optional[StrictStr] = None
|
||||||
|
id: Optional[StrictInt] = None
|
||||||
|
name: Optional[StrictStr] = None
|
||||||
|
__properties = ["size", "color", "id", "name"]
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter:
|
||||||
|
"""Create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter:
|
||||||
|
"""Create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.parse_obj({
|
||||||
|
"size": obj.get("size"),
|
||||||
|
"color": obj.get("color"),
|
||||||
|
"id": obj.get("id"),
|
||||||
|
"name": obj.get("name")
|
||||||
|
})
|
||||||
|
return _obj
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user