@kattebak/openapi-generator-ts 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +189 -0
- package/dist/cli/commands/generate.d.ts +23 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +116 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/list.d.ts +2 -0
- package/dist/cli/commands/list.d.ts.map +1 -0
- package/dist/cli/commands/list.js +26 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +6 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +80 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/convert-template.d.ts +31 -0
- package/dist/cli/convert-template.d.ts.map +1 -0
- package/dist/cli/convert-template.js +204 -0
- package/dist/cli/convert-template.js.map +1 -0
- package/dist/cli/convert-template.test.d.ts +2 -0
- package/dist/cli/convert-template.test.d.ts.map +1 -0
- package/dist/cli/convert-template.test.js +74 -0
- package/dist/cli/convert-template.test.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +246 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/config.d.ts +252 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +31 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/generator.d.ts +99 -0
- package/dist/core/generator.d.ts.map +1 -0
- package/dist/core/generator.js +492 -0
- package/dist/core/generator.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +47 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/generators/generators.test.d.ts +6 -0
- package/dist/generators/generators.test.d.ts.map +1 -0
- package/dist/generators/generators.test.js +247 -0
- package/dist/generators/generators.test.js.map +1 -0
- package/dist/generators/go.d.ts +10 -0
- package/dist/generators/go.d.ts.map +1 -0
- package/dist/generators/go.js +327 -0
- package/dist/generators/go.js.map +1 -0
- package/dist/generators/index.d.ts +29 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +58 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/php.d.ts +14 -0
- package/dist/generators/php.d.ts.map +1 -0
- package/dist/generators/php.js +241 -0
- package/dist/generators/php.js.map +1 -0
- package/dist/generators/python.d.ts +10 -0
- package/dist/generators/python.d.ts.map +1 -0
- package/dist/generators/python.js +273 -0
- package/dist/generators/python.js.map +1 -0
- package/dist/generators/typescript-fetch.d.ts +14 -0
- package/dist/generators/typescript-fetch.d.ts.map +1 -0
- package/dist/generators/typescript-fetch.js +217 -0
- package/dist/generators/typescript-fetch.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/models/codegen-model.d.ts +123 -0
- package/dist/models/codegen-model.d.ts.map +1 -0
- package/dist/models/codegen-model.js +64 -0
- package/dist/models/codegen-model.js.map +1 -0
- package/dist/models/codegen-model.test.d.ts +6 -0
- package/dist/models/codegen-model.test.d.ts.map +1 -0
- package/dist/models/codegen-model.test.js +143 -0
- package/dist/models/codegen-model.test.js.map +1 -0
- package/dist/models/codegen-operation.d.ts +95 -0
- package/dist/models/codegen-operation.d.ts.map +1 -0
- package/dist/models/codegen-operation.js +54 -0
- package/dist/models/codegen-operation.js.map +1 -0
- package/dist/models/codegen-parameter.d.ts +86 -0
- package/dist/models/codegen-parameter.d.ts.map +1 -0
- package/dist/models/codegen-parameter.js +47 -0
- package/dist/models/codegen-parameter.js.map +1 -0
- package/dist/models/codegen-property.d.ts +95 -0
- package/dist/models/codegen-property.d.ts.map +1 -0
- package/dist/models/codegen-property.js +47 -0
- package/dist/models/codegen-property.js.map +1 -0
- package/dist/models/codegen-response.d.ts +64 -0
- package/dist/models/codegen-response.d.ts.map +1 -0
- package/dist/models/codegen-response.js +42 -0
- package/dist/models/codegen-response.js.map +1 -0
- package/dist/models/codegen-security.d.ts +34 -0
- package/dist/models/codegen-security.d.ts.map +1 -0
- package/dist/models/codegen-security.js +18 -0
- package/dist/models/codegen-security.js.map +1 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +7 -0
- package/dist/models/index.js.map +1 -0
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +4 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/openapi-parser.d.ts +71 -0
- package/dist/parser/openapi-parser.d.ts.map +1 -0
- package/dist/parser/openapi-parser.js +195 -0
- package/dist/parser/openapi-parser.js.map +1 -0
- package/dist/parser/openapi-parser.test.d.ts +6 -0
- package/dist/parser/openapi-parser.test.d.ts.map +1 -0
- package/dist/parser/openapi-parser.test.js +238 -0
- package/dist/parser/openapi-parser.test.js.map +1 -0
- package/dist/parser/operation-transformer.d.ts +95 -0
- package/dist/parser/operation-transformer.d.ts.map +1 -0
- package/dist/parser/operation-transformer.js +634 -0
- package/dist/parser/operation-transformer.js.map +1 -0
- package/dist/parser/schema-transformer.d.ts +134 -0
- package/dist/parser/schema-transformer.d.ts.map +1 -0
- package/dist/parser/schema-transformer.js +557 -0
- package/dist/parser/schema-transformer.js.map +1 -0
- package/dist/template/engine-adapter.d.ts +55 -0
- package/dist/template/engine-adapter.d.ts.map +1 -0
- package/dist/template/engine-adapter.js +178 -0
- package/dist/template/engine-adapter.js.map +1 -0
- package/dist/template/engine-adapter.test.d.ts +6 -0
- package/dist/template/engine-adapter.test.d.ts.map +1 -0
- package/dist/template/engine-adapter.test.js +186 -0
- package/dist/template/engine-adapter.test.js.map +1 -0
- package/dist/template/index.d.ts +5 -0
- package/dist/template/index.d.ts.map +1 -0
- package/dist/template/index.js +5 -0
- package/dist/template/index.js.map +1 -0
- package/dist/template/lambdas/indent-lambdas.d.ts +40 -0
- package/dist/template/lambdas/indent-lambdas.d.ts.map +1 -0
- package/dist/template/lambdas/indent-lambdas.js +98 -0
- package/dist/template/lambdas/indent-lambdas.js.map +1 -0
- package/dist/template/lambdas/index.d.ts +44 -0
- package/dist/template/lambdas/index.d.ts.map +1 -0
- package/dist/template/lambdas/index.js +79 -0
- package/dist/template/lambdas/index.js.map +1 -0
- package/dist/template/lambdas/string-lambdas.d.ts +78 -0
- package/dist/template/lambdas/string-lambdas.d.ts.map +1 -0
- package/dist/template/lambdas/string-lambdas.js +148 -0
- package/dist/template/lambdas/string-lambdas.js.map +1 -0
- package/dist/template/lambdas/string-lambdas.test.d.ts +6 -0
- package/dist/template/lambdas/string-lambdas.test.d.ts.map +1 -0
- package/dist/template/lambdas/string-lambdas.test.js +158 -0
- package/dist/template/lambdas/string-lambdas.test.js.map +1 -0
- package/dist/template/template-locator.d.ts +72 -0
- package/dist/template/template-locator.d.ts.map +1 -0
- package/dist/template/template-locator.js +173 -0
- package/dist/template/template-locator.js.map +1 -0
- package/dist/template/template-manager.d.ts +65 -0
- package/dist/template/template-manager.d.ts.map +1 -0
- package/dist/template/template-manager.js +185 -0
- package/dist/template/template-manager.js.map +1 -0
- package/package.json +67 -0
- package/templates/go/.travis.yml +8 -0
- package/templates/go/README.mustache +236 -0
- package/templates/go/api.mustache +452 -0
- package/templates/go/api_doc.mustache +92 -0
- package/templates/go/api_test.mustache +59 -0
- package/templates/go/client.mustache +761 -0
- package/templates/go/configuration.mustache +332 -0
- package/templates/go/git_push.sh.mustache +57 -0
- package/templates/go/gitignore.mustache +24 -0
- package/templates/go/go.mod.mustache +16 -0
- package/templates/go/go.sum.mustache +19 -0
- package/templates/go/model.mustache +21 -0
- package/templates/go/model_anyof.mustache +93 -0
- package/templates/go/model_doc.mustache +97 -0
- package/templates/go/model_enum.mustache +101 -0
- package/templates/go/model_oneof.mustache +160 -0
- package/templates/go/model_simple.mustache +572 -0
- package/templates/go/nullable_model.mustache +35 -0
- package/templates/go/openapi.mustache +1 -0
- package/templates/go/partial_header.mustache +18 -0
- package/templates/go/response.mustache +38 -0
- package/templates/go/signing.mustache +453 -0
- package/templates/go/utils.mustache +352 -0
- package/templates/php/.php-cs-fixer.dist.php +29 -0
- package/templates/php/.travis.yml +8 -0
- package/templates/php/ApiException.mustache +111 -0
- package/templates/php/Configuration.mustache +606 -0
- package/templates/php/FormDataProcessor.mustache +238 -0
- package/templates/php/HeaderSelector.mustache +265 -0
- package/templates/php/ModelInterface.mustache +103 -0
- package/templates/php/ObjectSerializer.mustache +591 -0
- package/templates/php/README.mustache +151 -0
- package/templates/php/api.mustache +891 -0
- package/templates/php/api_doc.mustache +105 -0
- package/templates/php/api_test.mustache +80 -0
- package/templates/php/composer.mustache +44 -0
- package/templates/php/git_push.sh.mustache +57 -0
- package/templates/php/gitignore +15 -0
- package/templates/php/libraries/psr-18/ApiException.mustache +114 -0
- package/templates/php/libraries/psr-18/DebugPlugin.mustache +93 -0
- package/templates/php/libraries/psr-18/README.mustache +161 -0
- package/templates/php/libraries/psr-18/api.mustache +833 -0
- package/templates/php/libraries/psr-18/api_doc.mustache +79 -0
- package/templates/php/libraries/psr-18/composer.mustache +56 -0
- package/templates/php/model.mustache +47 -0
- package/templates/php/model_doc.mustache +10 -0
- package/templates/php/model_enum.mustache +33 -0
- package/templates/php/model_generic.mustache +565 -0
- package/templates/php/model_test.mustache +88 -0
- package/templates/php/partial_header.mustache +18 -0
- package/templates/php/php_doc_auth_partial.mustache +23 -0
- package/templates/php/phpunit.xml.mustache +18 -0
- package/templates/python/README.mustache +60 -0
- package/templates/python/README_onlypackage.mustache +50 -0
- package/templates/python/__init__.mustache +1 -0
- package/templates/python/__init__api.mustache +19 -0
- package/templates/python/__init__model.mustache +22 -0
- package/templates/python/__init__package.mustache +49 -0
- package/templates/python/api.mustache +244 -0
- package/templates/python/api_client.mustache +822 -0
- package/templates/python/api_doc.mustache +81 -0
- package/templates/python/api_doc_example.mustache +38 -0
- package/templates/python/api_response.mustache +21 -0
- package/templates/python/api_test.mustache +48 -0
- package/templates/python/asyncio/rest.mustache +209 -0
- package/templates/python/common_README.mustache +85 -0
- package/templates/python/configuration.mustache +806 -0
- package/templates/python/exceptions.mustache +210 -0
- package/templates/python/exports_api.mustache +3 -0
- package/templates/python/exports_model.mustache +3 -0
- package/templates/python/exports_package.mustache +20 -0
- package/templates/python/git_push.sh.mustache +57 -0
- package/templates/python/github-workflow.mustache +35 -0
- package/templates/python/gitignore.mustache +66 -0
- package/templates/python/gitlab-ci.mustache +31 -0
- package/templates/python/httpx/rest.mustache +190 -0
- package/templates/python/model.mustache +16 -0
- package/templates/python/model_anyof.mustache +182 -0
- package/templates/python/model_doc.mustache +40 -0
- package/templates/python/model_enum.mustache +36 -0
- package/templates/python/model_generic.mustache +403 -0
- package/templates/python/model_oneof.mustache +209 -0
- package/templates/python/model_test.mustache +60 -0
- package/templates/python/partial_api.mustache +52 -0
- package/templates/python/partial_api_args.mustache +18 -0
- package/templates/python/partial_header.mustache +19 -0
- package/templates/python/py.typed.mustache +1 -0
- package/templates/python/pyproject.mustache +172 -0
- package/templates/python/python_doc_auth_partial.mustache +108 -0
- package/templates/python/requirements.mustache +23 -0
- package/templates/python/rest.mustache +254 -0
- package/templates/python/setup.mustache +60 -0
- package/templates/python/setup_cfg.mustache +2 -0
- package/templates/python/signing.mustache +422 -0
- package/templates/python/test-requirements.mustache +6 -0
- package/templates/python/tornado/rest.mustache +148 -0
- package/templates/python/tox.mustache +9 -0
- package/templates/python/travis.mustache +17 -0
- package/templates/typescript-fetch/ApiEntitiesRecord.mustache +26 -0
- package/templates/typescript-fetch/ApiEntitiesReducer.mustache +21 -0
- package/templates/typescript-fetch/ApiEntitiesSelectors.mustache +5 -0
- package/templates/typescript-fetch/README.mustache +127 -0
- package/templates/typescript-fetch/allSagas.mustache +19 -0
- package/templates/typescript-fetch/api_doc.mustache +63 -0
- package/templates/typescript-fetch/api_example.mustache +44 -0
- package/templates/typescript-fetch/apis.index.mustache +16 -0
- package/templates/typescript-fetch/apis.mustache +483 -0
- package/templates/typescript-fetch/apisAssignQueryParam.mustache +12 -0
- package/templates/typescript-fetch/gitignore +4 -0
- package/templates/typescript-fetch/index.mustache +17 -0
- package/templates/typescript-fetch/licenseInfo.mustache +11 -0
- package/templates/typescript-fetch/modelEnum.mustache +28 -0
- package/templates/typescript-fetch/modelEnumInterfaces.mustache +37 -0
- package/templates/typescript-fetch/modelGeneric.mustache +261 -0
- package/templates/typescript-fetch/modelGenericInterfaces.mustache +50 -0
- package/templates/typescript-fetch/modelOneOf.mustache +255 -0
- package/templates/typescript-fetch/modelOneOfInterfaces.mustache +6 -0
- package/templates/typescript-fetch/model_doc.mustache +41 -0
- package/templates/typescript-fetch/models.index.mustache +32 -0
- package/templates/typescript-fetch/models.mustache +24 -0
- package/templates/typescript-fetch/npmignore.mustache +1 -0
- package/templates/typescript-fetch/package.mustache +43 -0
- package/templates/typescript-fetch/recordGeneric.mustache +295 -0
- package/templates/typescript-fetch/records.mustache +17 -0
- package/templates/typescript-fetch/runtime.mustache +424 -0
- package/templates/typescript-fetch/runtimeSagasAndRecords.mustache +120 -0
- package/templates/typescript-fetch/sagaApiManager.mustache +28 -0
- package/templates/typescript-fetch/sagas.mustache +245 -0
- package/templates/typescript-fetch/sourceLibraryIndex.mustache +1 -0
- package/templates/typescript-fetch/tsconfig.esm.mustache +7 -0
- package/templates/typescript-fetch/tsconfig.mustache +25 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
{{>partial_header}}
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import io
|
|
7
|
+
import json
|
|
8
|
+
import re
|
|
9
|
+
import ssl
|
|
10
|
+
|
|
11
|
+
import urllib3
|
|
12
|
+
|
|
13
|
+
from {{packageName}}.exceptions import ApiException, ApiValueError
|
|
14
|
+
|
|
15
|
+
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
|
16
|
+
RESTResponseType = urllib3.HTTPResponse
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def is_socks_proxy_url(url):
|
|
20
|
+
if url is None:
|
|
21
|
+
return False
|
|
22
|
+
split_section = url.split("://")
|
|
23
|
+
if len(split_section) < 2:
|
|
24
|
+
return False
|
|
25
|
+
else:
|
|
26
|
+
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class RESTResponse(io.IOBase):
|
|
30
|
+
|
|
31
|
+
def __init__(self, resp) -> None:
|
|
32
|
+
self.response = resp
|
|
33
|
+
self.status = resp.status
|
|
34
|
+
self.reason = resp.reason
|
|
35
|
+
self.data = None
|
|
36
|
+
|
|
37
|
+
def read(self):
|
|
38
|
+
if self.data is None:
|
|
39
|
+
self.data = self.response.data
|
|
40
|
+
return self.data
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def headers(self):
|
|
44
|
+
"""Returns a dictionary of response headers."""
|
|
45
|
+
return self.response.headers
|
|
46
|
+
|
|
47
|
+
def getheaders(self):
|
|
48
|
+
"""Returns a dictionary of the response headers; use ``headers`` instead."""
|
|
49
|
+
return self.response.headers
|
|
50
|
+
|
|
51
|
+
def getheader(self, name, default=None):
|
|
52
|
+
"""Returns a given response header; use ``headers.get()`` instead."""
|
|
53
|
+
return self.response.headers.get(name, default)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class RESTClientObject:
|
|
57
|
+
|
|
58
|
+
def __init__(self, configuration) -> None:
|
|
59
|
+
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
|
60
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
|
|
61
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
|
|
62
|
+
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
|
|
63
|
+
|
|
64
|
+
# cert_reqs
|
|
65
|
+
if configuration.verify_ssl:
|
|
66
|
+
cert_reqs = ssl.CERT_REQUIRED
|
|
67
|
+
else:
|
|
68
|
+
cert_reqs = ssl.CERT_NONE
|
|
69
|
+
|
|
70
|
+
pool_args = {
|
|
71
|
+
"cert_reqs": cert_reqs,
|
|
72
|
+
"ca_certs": configuration.ssl_ca_cert,
|
|
73
|
+
"cert_file": configuration.cert_file,
|
|
74
|
+
"key_file": configuration.key_file,
|
|
75
|
+
"ca_cert_data": configuration.ca_cert_data,
|
|
76
|
+
}
|
|
77
|
+
if configuration.assert_hostname is not None:
|
|
78
|
+
pool_args['assert_hostname'] = (
|
|
79
|
+
configuration.assert_hostname
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if configuration.retries is not None:
|
|
83
|
+
pool_args['retries'] = configuration.retries
|
|
84
|
+
|
|
85
|
+
if configuration.tls_server_name:
|
|
86
|
+
pool_args['server_hostname'] = configuration.tls_server_name
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if configuration.socket_options is not None:
|
|
90
|
+
pool_args['socket_options'] = configuration.socket_options
|
|
91
|
+
|
|
92
|
+
if configuration.connection_pool_maxsize is not None:
|
|
93
|
+
pool_args['maxsize'] = configuration.connection_pool_maxsize
|
|
94
|
+
|
|
95
|
+
# https pool manager
|
|
96
|
+
self.pool_manager: urllib3.PoolManager
|
|
97
|
+
|
|
98
|
+
if configuration.proxy:
|
|
99
|
+
if is_socks_proxy_url(configuration.proxy):
|
|
100
|
+
from urllib3.contrib.socks import SOCKSProxyManager
|
|
101
|
+
pool_args["proxy_url"] = configuration.proxy
|
|
102
|
+
pool_args["headers"] = configuration.proxy_headers
|
|
103
|
+
self.pool_manager = SOCKSProxyManager(**pool_args)
|
|
104
|
+
else:
|
|
105
|
+
pool_args["proxy_url"] = configuration.proxy
|
|
106
|
+
pool_args["proxy_headers"] = configuration.proxy_headers
|
|
107
|
+
self.pool_manager = urllib3.ProxyManager(**pool_args)
|
|
108
|
+
else:
|
|
109
|
+
self.pool_manager = urllib3.PoolManager(**pool_args)
|
|
110
|
+
|
|
111
|
+
def request(
|
|
112
|
+
self,
|
|
113
|
+
method,
|
|
114
|
+
url,
|
|
115
|
+
headers=None,
|
|
116
|
+
body=None,
|
|
117
|
+
post_params=None,
|
|
118
|
+
_request_timeout=None
|
|
119
|
+
):
|
|
120
|
+
"""Perform requests.
|
|
121
|
+
|
|
122
|
+
:param method: http request method
|
|
123
|
+
:param url: http request url
|
|
124
|
+
:param headers: http request headers
|
|
125
|
+
:param body: request json body, for `application/json`
|
|
126
|
+
:param post_params: request post parameters,
|
|
127
|
+
`application/x-www-form-urlencoded`
|
|
128
|
+
and `multipart/form-data`
|
|
129
|
+
:param _request_timeout: timeout setting for this request. If one
|
|
130
|
+
number provided, it will be total request
|
|
131
|
+
timeout. It can also be a pair (tuple) of
|
|
132
|
+
(connection, read) timeouts.
|
|
133
|
+
"""
|
|
134
|
+
method = method.upper()
|
|
135
|
+
assert method in [
|
|
136
|
+
'GET',
|
|
137
|
+
'HEAD',
|
|
138
|
+
'DELETE',
|
|
139
|
+
'POST',
|
|
140
|
+
'PUT',
|
|
141
|
+
'PATCH',
|
|
142
|
+
'OPTIONS'
|
|
143
|
+
]
|
|
144
|
+
|
|
145
|
+
if post_params and body:
|
|
146
|
+
raise ApiValueError(
|
|
147
|
+
"body parameter cannot be used with post_params parameter."
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
post_params = post_params or {}
|
|
151
|
+
headers = headers or {}
|
|
152
|
+
|
|
153
|
+
timeout = None
|
|
154
|
+
if _request_timeout:
|
|
155
|
+
if isinstance(_request_timeout, (int, float)):
|
|
156
|
+
timeout = urllib3.Timeout(total=_request_timeout)
|
|
157
|
+
elif (
|
|
158
|
+
isinstance(_request_timeout, tuple)
|
|
159
|
+
and len(_request_timeout) == 2
|
|
160
|
+
):
|
|
161
|
+
timeout = urllib3.Timeout(
|
|
162
|
+
connect=_request_timeout[0],
|
|
163
|
+
read=_request_timeout[1]
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
try:
|
|
167
|
+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
|
168
|
+
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
|
|
169
|
+
|
|
170
|
+
# no content type provided or payload is json
|
|
171
|
+
content_type = headers.get('Content-Type')
|
|
172
|
+
if (
|
|
173
|
+
not content_type
|
|
174
|
+
or re.search('json', content_type, re.IGNORECASE)
|
|
175
|
+
):
|
|
176
|
+
request_body = None
|
|
177
|
+
if body is not None:
|
|
178
|
+
request_body = json.dumps(body{{#setEnsureAsciiToFalse}}, ensure_ascii=False{{/setEnsureAsciiToFalse}})
|
|
179
|
+
r = self.pool_manager.request(
|
|
180
|
+
method,
|
|
181
|
+
url,
|
|
182
|
+
body=request_body,
|
|
183
|
+
timeout=timeout,
|
|
184
|
+
headers=headers,
|
|
185
|
+
preload_content=False
|
|
186
|
+
)
|
|
187
|
+
elif content_type == 'application/x-www-form-urlencoded':
|
|
188
|
+
r = self.pool_manager.request(
|
|
189
|
+
method,
|
|
190
|
+
url,
|
|
191
|
+
fields=post_params,
|
|
192
|
+
encode_multipart=False,
|
|
193
|
+
timeout=timeout,
|
|
194
|
+
headers=headers,
|
|
195
|
+
preload_content=False
|
|
196
|
+
)
|
|
197
|
+
elif content_type == 'multipart/form-data':
|
|
198
|
+
# must del headers['Content-Type'], or the correct
|
|
199
|
+
# Content-Type which generated by urllib3 will be
|
|
200
|
+
# overwritten.
|
|
201
|
+
del headers['Content-Type']
|
|
202
|
+
# Ensures that dict objects are serialized
|
|
203
|
+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
|
|
204
|
+
r = self.pool_manager.request(
|
|
205
|
+
method,
|
|
206
|
+
url,
|
|
207
|
+
fields=post_params,
|
|
208
|
+
encode_multipart=True,
|
|
209
|
+
timeout=timeout,
|
|
210
|
+
headers=headers,
|
|
211
|
+
preload_content=False
|
|
212
|
+
)
|
|
213
|
+
# Pass a `string` parameter directly in the body to support
|
|
214
|
+
# other content types than JSON when `body` argument is
|
|
215
|
+
# provided in serialized form.
|
|
216
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
|
217
|
+
r = self.pool_manager.request(
|
|
218
|
+
method,
|
|
219
|
+
url,
|
|
220
|
+
body=body,
|
|
221
|
+
timeout=timeout,
|
|
222
|
+
headers=headers,
|
|
223
|
+
preload_content=False
|
|
224
|
+
)
|
|
225
|
+
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
|
|
226
|
+
request_body = "true" if body else "false"
|
|
227
|
+
r = self.pool_manager.request(
|
|
228
|
+
method,
|
|
229
|
+
url,
|
|
230
|
+
body=request_body,
|
|
231
|
+
preload_content=False,
|
|
232
|
+
timeout=timeout,
|
|
233
|
+
headers=headers)
|
|
234
|
+
else:
|
|
235
|
+
# Cannot generate the request from given parameters
|
|
236
|
+
msg = """Cannot prepare a request message for provided
|
|
237
|
+
arguments. Please check that your arguments match
|
|
238
|
+
declared content type."""
|
|
239
|
+
raise ApiException(status=0, reason=msg)
|
|
240
|
+
# For `GET`, `HEAD`
|
|
241
|
+
else:
|
|
242
|
+
r = self.pool_manager.request(
|
|
243
|
+
method,
|
|
244
|
+
url,
|
|
245
|
+
fields={},
|
|
246
|
+
timeout=timeout,
|
|
247
|
+
headers=headers,
|
|
248
|
+
preload_content=False
|
|
249
|
+
)
|
|
250
|
+
except urllib3.exceptions.SSLError as e:
|
|
251
|
+
msg = "\n".join([type(e).__name__, str(e)])
|
|
252
|
+
raise ApiException(status=0, reason=msg)
|
|
253
|
+
|
|
254
|
+
return RESTResponse(r)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
{{>partial_header}}
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from setuptools import setup, find_packages # noqa: H301
|
|
7
|
+
|
|
8
|
+
# To install the library, run the following
|
|
9
|
+
#
|
|
10
|
+
# python setup.py install
|
|
11
|
+
#
|
|
12
|
+
# prerequisite: setuptools
|
|
13
|
+
# http://pypi.python.org/pypi/setuptools
|
|
14
|
+
NAME = "{{{projectName}}}"
|
|
15
|
+
VERSION = "{{packageVersion}}"
|
|
16
|
+
PYTHON_REQUIRES = ">= 3.9"
|
|
17
|
+
REQUIRES = [
|
|
18
|
+
{{^async}}
|
|
19
|
+
"urllib3 >= 2.[1].0, < 3.[0].0",
|
|
20
|
+
{{/async}}
|
|
21
|
+
"python-dateutil >= 2.[8].2",
|
|
22
|
+
{{#asyncio}}
|
|
23
|
+
"aiohttp >= 3.[8].4",
|
|
24
|
+
"aiohttp-retry >= 2.[8].3",
|
|
25
|
+
{{/asyncio}}
|
|
26
|
+
{{#httpx}}
|
|
27
|
+
"httpx >= 0.[28].1",
|
|
28
|
+
{{/httpx}}
|
|
29
|
+
{{#tornado}}
|
|
30
|
+
"tornado>=4.2, < 5",
|
|
31
|
+
{{/tornado}}
|
|
32
|
+
{{#hasHttpSignatureMethods}}
|
|
33
|
+
"pem >= 19.[3].0",
|
|
34
|
+
"pycryptodome >= 3.[9].0",
|
|
35
|
+
{{/hasHttpSignatureMethods}}
|
|
36
|
+
"pydantic >= 2",
|
|
37
|
+
"typing-extensions >= 4.[7].1",
|
|
38
|
+
{{#lazyImports}}
|
|
39
|
+
"lazy-imports >= 1, < 2",
|
|
40
|
+
{{/lazyImports}}
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
setup(
|
|
44
|
+
name=NAME,
|
|
45
|
+
version=VERSION,
|
|
46
|
+
description="{{appName}}",
|
|
47
|
+
author="{{infoName}}{{^infoName}}OpenAPI Generator community{{/infoName}}",
|
|
48
|
+
author_email="{{infoEmail}}{{#unless infoEmail}}team@openapitools.org{{/unless}}",
|
|
49
|
+
url="{{packageUrl}}",
|
|
50
|
+
keywords=["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"],
|
|
51
|
+
install_requires=REQUIRES,
|
|
52
|
+
packages=find_packages(exclude=["test", "tests"]),
|
|
53
|
+
include_package_data=True,
|
|
54
|
+
{{#if licenseInfo}}license="{{licenseInfo}}",
|
|
55
|
+
{{/if}}long_description_content_type='text/markdown',
|
|
56
|
+
long_description="""\
|
|
57
|
+
{{appDescription}}
|
|
58
|
+
""", # noqa: E501
|
|
59
|
+
package_data={"{{{packageName}}}": ["py.typed"]},
|
|
60
|
+
)
|