@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.
Files changed (290) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +189 -0
  3. package/dist/cli/commands/generate.d.ts +23 -0
  4. package/dist/cli/commands/generate.d.ts.map +1 -0
  5. package/dist/cli/commands/generate.js +116 -0
  6. package/dist/cli/commands/generate.js.map +1 -0
  7. package/dist/cli/commands/list.d.ts +2 -0
  8. package/dist/cli/commands/list.d.ts.map +1 -0
  9. package/dist/cli/commands/list.js +26 -0
  10. package/dist/cli/commands/list.js.map +1 -0
  11. package/dist/cli/commands/validate.d.ts +6 -0
  12. package/dist/cli/commands/validate.d.ts.map +1 -0
  13. package/dist/cli/commands/validate.js +80 -0
  14. package/dist/cli/commands/validate.js.map +1 -0
  15. package/dist/cli/convert-template.d.ts +31 -0
  16. package/dist/cli/convert-template.d.ts.map +1 -0
  17. package/dist/cli/convert-template.js +204 -0
  18. package/dist/cli/convert-template.js.map +1 -0
  19. package/dist/cli/convert-template.test.d.ts +2 -0
  20. package/dist/cli/convert-template.test.d.ts.map +1 -0
  21. package/dist/cli/convert-template.test.js +74 -0
  22. package/dist/cli/convert-template.test.js.map +1 -0
  23. package/dist/cli/index.d.ts +3 -0
  24. package/dist/cli/index.d.ts.map +1 -0
  25. package/dist/cli/index.js +246 -0
  26. package/dist/cli/index.js.map +1 -0
  27. package/dist/core/config.d.ts +252 -0
  28. package/dist/core/config.d.ts.map +1 -0
  29. package/dist/core/config.js +31 -0
  30. package/dist/core/config.js.map +1 -0
  31. package/dist/core/generator.d.ts +99 -0
  32. package/dist/core/generator.d.ts.map +1 -0
  33. package/dist/core/generator.js +492 -0
  34. package/dist/core/generator.js.map +1 -0
  35. package/dist/core/index.d.ts +4 -0
  36. package/dist/core/index.d.ts.map +1 -0
  37. package/dist/core/index.js +4 -0
  38. package/dist/core/index.js.map +1 -0
  39. package/dist/core/types.d.ts +47 -0
  40. package/dist/core/types.d.ts.map +1 -0
  41. package/dist/core/types.js +5 -0
  42. package/dist/core/types.js.map +1 -0
  43. package/dist/generators/generators.test.d.ts +6 -0
  44. package/dist/generators/generators.test.d.ts.map +1 -0
  45. package/dist/generators/generators.test.js +247 -0
  46. package/dist/generators/generators.test.js.map +1 -0
  47. package/dist/generators/go.d.ts +10 -0
  48. package/dist/generators/go.d.ts.map +1 -0
  49. package/dist/generators/go.js +327 -0
  50. package/dist/generators/go.js.map +1 -0
  51. package/dist/generators/index.d.ts +29 -0
  52. package/dist/generators/index.d.ts.map +1 -0
  53. package/dist/generators/index.js +58 -0
  54. package/dist/generators/index.js.map +1 -0
  55. package/dist/generators/php.d.ts +14 -0
  56. package/dist/generators/php.d.ts.map +1 -0
  57. package/dist/generators/php.js +241 -0
  58. package/dist/generators/php.js.map +1 -0
  59. package/dist/generators/python.d.ts +10 -0
  60. package/dist/generators/python.d.ts.map +1 -0
  61. package/dist/generators/python.js +273 -0
  62. package/dist/generators/python.js.map +1 -0
  63. package/dist/generators/typescript-fetch.d.ts +14 -0
  64. package/dist/generators/typescript-fetch.d.ts.map +1 -0
  65. package/dist/generators/typescript-fetch.js +217 -0
  66. package/dist/generators/typescript-fetch.js.map +1 -0
  67. package/dist/index.d.ts +14 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +16 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/models/codegen-model.d.ts +123 -0
  72. package/dist/models/codegen-model.d.ts.map +1 -0
  73. package/dist/models/codegen-model.js +64 -0
  74. package/dist/models/codegen-model.js.map +1 -0
  75. package/dist/models/codegen-model.test.d.ts +6 -0
  76. package/dist/models/codegen-model.test.d.ts.map +1 -0
  77. package/dist/models/codegen-model.test.js +143 -0
  78. package/dist/models/codegen-model.test.js.map +1 -0
  79. package/dist/models/codegen-operation.d.ts +95 -0
  80. package/dist/models/codegen-operation.d.ts.map +1 -0
  81. package/dist/models/codegen-operation.js +54 -0
  82. package/dist/models/codegen-operation.js.map +1 -0
  83. package/dist/models/codegen-parameter.d.ts +86 -0
  84. package/dist/models/codegen-parameter.d.ts.map +1 -0
  85. package/dist/models/codegen-parameter.js +47 -0
  86. package/dist/models/codegen-parameter.js.map +1 -0
  87. package/dist/models/codegen-property.d.ts +95 -0
  88. package/dist/models/codegen-property.d.ts.map +1 -0
  89. package/dist/models/codegen-property.js +47 -0
  90. package/dist/models/codegen-property.js.map +1 -0
  91. package/dist/models/codegen-response.d.ts +64 -0
  92. package/dist/models/codegen-response.d.ts.map +1 -0
  93. package/dist/models/codegen-response.js +42 -0
  94. package/dist/models/codegen-response.js.map +1 -0
  95. package/dist/models/codegen-security.d.ts +34 -0
  96. package/dist/models/codegen-security.d.ts.map +1 -0
  97. package/dist/models/codegen-security.js +18 -0
  98. package/dist/models/codegen-security.js.map +1 -0
  99. package/dist/models/index.d.ts +8 -0
  100. package/dist/models/index.d.ts.map +1 -0
  101. package/dist/models/index.js +7 -0
  102. package/dist/models/index.js.map +1 -0
  103. package/dist/parser/index.d.ts +4 -0
  104. package/dist/parser/index.d.ts.map +1 -0
  105. package/dist/parser/index.js +4 -0
  106. package/dist/parser/index.js.map +1 -0
  107. package/dist/parser/openapi-parser.d.ts +71 -0
  108. package/dist/parser/openapi-parser.d.ts.map +1 -0
  109. package/dist/parser/openapi-parser.js +195 -0
  110. package/dist/parser/openapi-parser.js.map +1 -0
  111. package/dist/parser/openapi-parser.test.d.ts +6 -0
  112. package/dist/parser/openapi-parser.test.d.ts.map +1 -0
  113. package/dist/parser/openapi-parser.test.js +238 -0
  114. package/dist/parser/openapi-parser.test.js.map +1 -0
  115. package/dist/parser/operation-transformer.d.ts +95 -0
  116. package/dist/parser/operation-transformer.d.ts.map +1 -0
  117. package/dist/parser/operation-transformer.js +634 -0
  118. package/dist/parser/operation-transformer.js.map +1 -0
  119. package/dist/parser/schema-transformer.d.ts +134 -0
  120. package/dist/parser/schema-transformer.d.ts.map +1 -0
  121. package/dist/parser/schema-transformer.js +557 -0
  122. package/dist/parser/schema-transformer.js.map +1 -0
  123. package/dist/template/engine-adapter.d.ts +55 -0
  124. package/dist/template/engine-adapter.d.ts.map +1 -0
  125. package/dist/template/engine-adapter.js +178 -0
  126. package/dist/template/engine-adapter.js.map +1 -0
  127. package/dist/template/engine-adapter.test.d.ts +6 -0
  128. package/dist/template/engine-adapter.test.d.ts.map +1 -0
  129. package/dist/template/engine-adapter.test.js +186 -0
  130. package/dist/template/engine-adapter.test.js.map +1 -0
  131. package/dist/template/index.d.ts +5 -0
  132. package/dist/template/index.d.ts.map +1 -0
  133. package/dist/template/index.js +5 -0
  134. package/dist/template/index.js.map +1 -0
  135. package/dist/template/lambdas/indent-lambdas.d.ts +40 -0
  136. package/dist/template/lambdas/indent-lambdas.d.ts.map +1 -0
  137. package/dist/template/lambdas/indent-lambdas.js +98 -0
  138. package/dist/template/lambdas/indent-lambdas.js.map +1 -0
  139. package/dist/template/lambdas/index.d.ts +44 -0
  140. package/dist/template/lambdas/index.d.ts.map +1 -0
  141. package/dist/template/lambdas/index.js +79 -0
  142. package/dist/template/lambdas/index.js.map +1 -0
  143. package/dist/template/lambdas/string-lambdas.d.ts +78 -0
  144. package/dist/template/lambdas/string-lambdas.d.ts.map +1 -0
  145. package/dist/template/lambdas/string-lambdas.js +148 -0
  146. package/dist/template/lambdas/string-lambdas.js.map +1 -0
  147. package/dist/template/lambdas/string-lambdas.test.d.ts +6 -0
  148. package/dist/template/lambdas/string-lambdas.test.d.ts.map +1 -0
  149. package/dist/template/lambdas/string-lambdas.test.js +158 -0
  150. package/dist/template/lambdas/string-lambdas.test.js.map +1 -0
  151. package/dist/template/template-locator.d.ts +72 -0
  152. package/dist/template/template-locator.d.ts.map +1 -0
  153. package/dist/template/template-locator.js +173 -0
  154. package/dist/template/template-locator.js.map +1 -0
  155. package/dist/template/template-manager.d.ts +65 -0
  156. package/dist/template/template-manager.d.ts.map +1 -0
  157. package/dist/template/template-manager.js +185 -0
  158. package/dist/template/template-manager.js.map +1 -0
  159. package/package.json +67 -0
  160. package/templates/go/.travis.yml +8 -0
  161. package/templates/go/README.mustache +236 -0
  162. package/templates/go/api.mustache +452 -0
  163. package/templates/go/api_doc.mustache +92 -0
  164. package/templates/go/api_test.mustache +59 -0
  165. package/templates/go/client.mustache +761 -0
  166. package/templates/go/configuration.mustache +332 -0
  167. package/templates/go/git_push.sh.mustache +57 -0
  168. package/templates/go/gitignore.mustache +24 -0
  169. package/templates/go/go.mod.mustache +16 -0
  170. package/templates/go/go.sum.mustache +19 -0
  171. package/templates/go/model.mustache +21 -0
  172. package/templates/go/model_anyof.mustache +93 -0
  173. package/templates/go/model_doc.mustache +97 -0
  174. package/templates/go/model_enum.mustache +101 -0
  175. package/templates/go/model_oneof.mustache +160 -0
  176. package/templates/go/model_simple.mustache +572 -0
  177. package/templates/go/nullable_model.mustache +35 -0
  178. package/templates/go/openapi.mustache +1 -0
  179. package/templates/go/partial_header.mustache +18 -0
  180. package/templates/go/response.mustache +38 -0
  181. package/templates/go/signing.mustache +453 -0
  182. package/templates/go/utils.mustache +352 -0
  183. package/templates/php/.php-cs-fixer.dist.php +29 -0
  184. package/templates/php/.travis.yml +8 -0
  185. package/templates/php/ApiException.mustache +111 -0
  186. package/templates/php/Configuration.mustache +606 -0
  187. package/templates/php/FormDataProcessor.mustache +238 -0
  188. package/templates/php/HeaderSelector.mustache +265 -0
  189. package/templates/php/ModelInterface.mustache +103 -0
  190. package/templates/php/ObjectSerializer.mustache +591 -0
  191. package/templates/php/README.mustache +151 -0
  192. package/templates/php/api.mustache +891 -0
  193. package/templates/php/api_doc.mustache +105 -0
  194. package/templates/php/api_test.mustache +80 -0
  195. package/templates/php/composer.mustache +44 -0
  196. package/templates/php/git_push.sh.mustache +57 -0
  197. package/templates/php/gitignore +15 -0
  198. package/templates/php/libraries/psr-18/ApiException.mustache +114 -0
  199. package/templates/php/libraries/psr-18/DebugPlugin.mustache +93 -0
  200. package/templates/php/libraries/psr-18/README.mustache +161 -0
  201. package/templates/php/libraries/psr-18/api.mustache +833 -0
  202. package/templates/php/libraries/psr-18/api_doc.mustache +79 -0
  203. package/templates/php/libraries/psr-18/composer.mustache +56 -0
  204. package/templates/php/model.mustache +47 -0
  205. package/templates/php/model_doc.mustache +10 -0
  206. package/templates/php/model_enum.mustache +33 -0
  207. package/templates/php/model_generic.mustache +565 -0
  208. package/templates/php/model_test.mustache +88 -0
  209. package/templates/php/partial_header.mustache +18 -0
  210. package/templates/php/php_doc_auth_partial.mustache +23 -0
  211. package/templates/php/phpunit.xml.mustache +18 -0
  212. package/templates/python/README.mustache +60 -0
  213. package/templates/python/README_onlypackage.mustache +50 -0
  214. package/templates/python/__init__.mustache +1 -0
  215. package/templates/python/__init__api.mustache +19 -0
  216. package/templates/python/__init__model.mustache +22 -0
  217. package/templates/python/__init__package.mustache +49 -0
  218. package/templates/python/api.mustache +244 -0
  219. package/templates/python/api_client.mustache +822 -0
  220. package/templates/python/api_doc.mustache +81 -0
  221. package/templates/python/api_doc_example.mustache +38 -0
  222. package/templates/python/api_response.mustache +21 -0
  223. package/templates/python/api_test.mustache +48 -0
  224. package/templates/python/asyncio/rest.mustache +209 -0
  225. package/templates/python/common_README.mustache +85 -0
  226. package/templates/python/configuration.mustache +806 -0
  227. package/templates/python/exceptions.mustache +210 -0
  228. package/templates/python/exports_api.mustache +3 -0
  229. package/templates/python/exports_model.mustache +3 -0
  230. package/templates/python/exports_package.mustache +20 -0
  231. package/templates/python/git_push.sh.mustache +57 -0
  232. package/templates/python/github-workflow.mustache +35 -0
  233. package/templates/python/gitignore.mustache +66 -0
  234. package/templates/python/gitlab-ci.mustache +31 -0
  235. package/templates/python/httpx/rest.mustache +190 -0
  236. package/templates/python/model.mustache +16 -0
  237. package/templates/python/model_anyof.mustache +182 -0
  238. package/templates/python/model_doc.mustache +40 -0
  239. package/templates/python/model_enum.mustache +36 -0
  240. package/templates/python/model_generic.mustache +403 -0
  241. package/templates/python/model_oneof.mustache +209 -0
  242. package/templates/python/model_test.mustache +60 -0
  243. package/templates/python/partial_api.mustache +52 -0
  244. package/templates/python/partial_api_args.mustache +18 -0
  245. package/templates/python/partial_header.mustache +19 -0
  246. package/templates/python/py.typed.mustache +1 -0
  247. package/templates/python/pyproject.mustache +172 -0
  248. package/templates/python/python_doc_auth_partial.mustache +108 -0
  249. package/templates/python/requirements.mustache +23 -0
  250. package/templates/python/rest.mustache +254 -0
  251. package/templates/python/setup.mustache +60 -0
  252. package/templates/python/setup_cfg.mustache +2 -0
  253. package/templates/python/signing.mustache +422 -0
  254. package/templates/python/test-requirements.mustache +6 -0
  255. package/templates/python/tornado/rest.mustache +148 -0
  256. package/templates/python/tox.mustache +9 -0
  257. package/templates/python/travis.mustache +17 -0
  258. package/templates/typescript-fetch/ApiEntitiesRecord.mustache +26 -0
  259. package/templates/typescript-fetch/ApiEntitiesReducer.mustache +21 -0
  260. package/templates/typescript-fetch/ApiEntitiesSelectors.mustache +5 -0
  261. package/templates/typescript-fetch/README.mustache +127 -0
  262. package/templates/typescript-fetch/allSagas.mustache +19 -0
  263. package/templates/typescript-fetch/api_doc.mustache +63 -0
  264. package/templates/typescript-fetch/api_example.mustache +44 -0
  265. package/templates/typescript-fetch/apis.index.mustache +16 -0
  266. package/templates/typescript-fetch/apis.mustache +483 -0
  267. package/templates/typescript-fetch/apisAssignQueryParam.mustache +12 -0
  268. package/templates/typescript-fetch/gitignore +4 -0
  269. package/templates/typescript-fetch/index.mustache +17 -0
  270. package/templates/typescript-fetch/licenseInfo.mustache +11 -0
  271. package/templates/typescript-fetch/modelEnum.mustache +28 -0
  272. package/templates/typescript-fetch/modelEnumInterfaces.mustache +37 -0
  273. package/templates/typescript-fetch/modelGeneric.mustache +261 -0
  274. package/templates/typescript-fetch/modelGenericInterfaces.mustache +50 -0
  275. package/templates/typescript-fetch/modelOneOf.mustache +255 -0
  276. package/templates/typescript-fetch/modelOneOfInterfaces.mustache +6 -0
  277. package/templates/typescript-fetch/model_doc.mustache +41 -0
  278. package/templates/typescript-fetch/models.index.mustache +32 -0
  279. package/templates/typescript-fetch/models.mustache +24 -0
  280. package/templates/typescript-fetch/npmignore.mustache +1 -0
  281. package/templates/typescript-fetch/package.mustache +43 -0
  282. package/templates/typescript-fetch/recordGeneric.mustache +295 -0
  283. package/templates/typescript-fetch/records.mustache +17 -0
  284. package/templates/typescript-fetch/runtime.mustache +424 -0
  285. package/templates/typescript-fetch/runtimeSagasAndRecords.mustache +120 -0
  286. package/templates/typescript-fetch/sagaApiManager.mustache +28 -0
  287. package/templates/typescript-fetch/sagas.mustache +245 -0
  288. package/templates/typescript-fetch/sourceLibraryIndex.mustache +1 -0
  289. package/templates/typescript-fetch/tsconfig.esm.mustache +7 -0
  290. package/templates/typescript-fetch/tsconfig.mustache +25 -0
@@ -0,0 +1,806 @@
1
+ # coding: utf-8
2
+
3
+ {{>partial_header}}
4
+
5
+
6
+ {{#async}}
7
+ import base64
8
+ {{/async}}
9
+ import copy
10
+ import http.client as httplib
11
+ import logging
12
+ from logging import FileHandler
13
+ {{^async}}
14
+ import multiprocessing
15
+ {{/async}}
16
+ import sys
17
+ from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
18
+ from typing_extensions import NotRequired, Self
19
+
20
+ {{^async}}
21
+ import urllib3
22
+ {{/async}}
23
+
24
+ {{#hasHttpSignatureMethods}}
25
+ from {{packageName}}.signing import HttpSigningConfiguration
26
+ {{/hasHttpSignatureMethods}}
27
+
28
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
29
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
30
+ 'minimum', 'exclusiveMinimum', 'maxLength',
31
+ 'minLength', 'pattern', 'maxItems', 'minItems'
32
+ }
33
+
34
+ ServerVariablesT = Dict[str, str]
35
+
36
+ GenericAuthSetting = TypedDict(
37
+ "GenericAuthSetting",
38
+ {
39
+ "type": str,
40
+ "in": str,
41
+ "key": str,
42
+ "value": str,
43
+ },
44
+ )
45
+
46
+
47
+ OAuth2AuthSetting = TypedDict(
48
+ "OAuth2AuthSetting",
49
+ {
50
+ "type": Literal["oauth2"],
51
+ "in": Literal["header"],
52
+ "key": Literal["Authorization"],
53
+ "value": str,
54
+ },
55
+ )
56
+
57
+
58
+ APIKeyAuthSetting = TypedDict(
59
+ "APIKeyAuthSetting",
60
+ {
61
+ "type": Literal["api_key"],
62
+ "in": str,
63
+ "key": str,
64
+ "value": Optional[str],
65
+ },
66
+ )
67
+
68
+
69
+ BasicAuthSetting = TypedDict(
70
+ "BasicAuthSetting",
71
+ {
72
+ "type": Literal["basic"],
73
+ "in": Literal["header"],
74
+ "key": Literal["Authorization"],
75
+ "value": Optional[str],
76
+ },
77
+ )
78
+
79
+
80
+ BearerFormatAuthSetting = TypedDict(
81
+ "BearerFormatAuthSetting",
82
+ {
83
+ "type": Literal["bearer"],
84
+ "in": Literal["header"],
85
+ "format": Literal["JWT"],
86
+ "key": Literal["Authorization"],
87
+ "value": str,
88
+ },
89
+ )
90
+
91
+
92
+ BearerAuthSetting = TypedDict(
93
+ "BearerAuthSetting",
94
+ {
95
+ "type": Literal["bearer"],
96
+ "in": Literal["header"],
97
+ "key": Literal["Authorization"],
98
+ "value": str,
99
+ },
100
+ )
101
+
102
+
103
+ HTTPSignatureAuthSetting = TypedDict(
104
+ "HTTPSignatureAuthSetting",
105
+ {
106
+ "type": Literal["http-signature"],
107
+ "in": Literal["header"],
108
+ "key": Literal["Authorization"],
109
+ "value": None,
110
+ },
111
+ )
112
+
113
+
114
+ AuthSettings = TypedDict(
115
+ "AuthSettings",
116
+ {
117
+ {{#authMethods}}
118
+ {{#isOAuth}}
119
+ "{{name}}": OAuth2AuthSetting,
120
+ {{/isOAuth}}
121
+ {{#isApiKey}}
122
+ "{{name}}": APIKeyAuthSetting,
123
+ {{/isApiKey}}
124
+ {{#isBasic}}
125
+ {{#isBasicBasic}}
126
+ "{{name}}": BasicAuthSetting,
127
+ {{/isBasicBasic}}
128
+ {{#isBasicBearer}}
129
+ {{#bearerFormat}}
130
+ "{{name}}": BearerFormatAuthSetting,
131
+ {{/bearerFormat}}
132
+ {{^bearerFormat}}
133
+ "{{name}}": BearerAuthSetting,
134
+ {{/bearerFormat}}
135
+ {{/isBasicBearer}}
136
+ {{#isHttpSignature}}
137
+ "{{name}}": HTTPSignatureAuthSetting,
138
+ {{/isHttpSignature}}
139
+ {{/isBasic}}
140
+ {{/authMethods}}
141
+ },
142
+ total=False,
143
+ )
144
+
145
+
146
+ class HostSettingVariable(TypedDict):
147
+ description: str
148
+ default_value: str
149
+ enum_values: List[str]
150
+
151
+
152
+ class HostSetting(TypedDict):
153
+ url: str
154
+ description: str
155
+ variables: NotRequired[Dict[str, HostSettingVariable]]
156
+
157
+
158
+ class Configuration:
159
+ """This class contains various settings of the API client.
160
+
161
+ :param host: Base url.
162
+ :param ignore_operation_servers
163
+ Boolean to ignore operation servers for the API client.
164
+ Config will use `host` as the base url regardless of the operation servers.
165
+ :param api_key: Dict to store API key(s).
166
+ Each entry in the dict specifies an API key.
167
+ The dict key is the name of the security scheme in the OAS specification.
168
+ The dict value is the API key secret.
169
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
170
+ The dict key is the name of the security scheme in the OAS specification.
171
+ The dict value is an API key prefix when generating the auth data.
172
+ :param username: Username for HTTP basic authentication.
173
+ :param password: Password for HTTP basic authentication.
174
+ :param access_token: Access token.
175
+ {{#hasHttpSignatureMethods}}
176
+ :param signing_info: Configuration parameters for the HTTP signature security scheme.
177
+ Must be an instance of {{{packageName}}}.signing.HttpSigningConfiguration
178
+ {{/hasHttpSignatureMethods}}
179
+ :param server_index: Index to servers configuration.
180
+ :param server_variables: Mapping with string values to replace variables in
181
+ templated server configuration. The validation of enums is performed for
182
+ variables with defined enum values before.
183
+ :param server_operation_index: Mapping from operation ID to an index to server
184
+ configuration.
185
+ :param server_operation_variables: Mapping from operation ID to a mapping with
186
+ string values to replace variables in templated server configuration.
187
+ The validation of enums is performed for variables with defined enum
188
+ values before.
189
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
190
+ in PEM format.
191
+ :param retries: Number of retries for API requests.
192
+ :param ca_cert_data: verify the peer using concatenated CA certificate data
193
+ in PEM (str) or DER (bytes) format.
194
+ :param cert_file: the path to a client certificate file, for mTLS.
195
+ :param key_file: the path to a client key file, for mTLS.
196
+
197
+ {{#hasAuthMethods}}
198
+ :Example:
199
+ {{#hasApiKeyMethods}}
200
+
201
+ API Key Authentication Example.
202
+ Given the following security scheme in the OpenAPI specification:
203
+ components:
204
+ securitySchemes:
205
+ cookieAuth: # name for the security scheme
206
+ type: apiKey
207
+ in: cookie
208
+ name: JSESSIONID # cookie name
209
+
210
+ You can programmatically set the cookie:
211
+
212
+ conf = {{{packageName}}}.Configuration(
213
+ api_key={'cookieAuth': 'abc123'}
214
+ api_key_prefix={'cookieAuth': 'JSESSIONID'}
215
+ )
216
+
217
+ The following cookie will be added to the HTTP request:
218
+ Cookie: JSESSIONID abc123
219
+ {{/hasApiKeyMethods}}
220
+ {{#hasHttpBasicMethods}}
221
+
222
+ HTTP Basic Authentication Example.
223
+ Given the following security scheme in the OpenAPI specification:
224
+ components:
225
+ securitySchemes:
226
+ http_basic_auth:
227
+ type: http
228
+ scheme: basic
229
+
230
+ Configure API client with HTTP basic authentication:
231
+
232
+ conf = {{{packageName}}}.Configuration(
233
+ username='the-user',
234
+ password='the-password',
235
+ )
236
+
237
+ {{/hasHttpBasicMethods}}
238
+ {{#hasHttpSignatureMethods}}
239
+
240
+ HTTP Signature Authentication Example.
241
+ Given the following security scheme in the OpenAPI specification:
242
+ components:
243
+ securitySchemes:
244
+ http_basic_auth:
245
+ type: http
246
+ scheme: signature
247
+
248
+ Configure API client with HTTP signature authentication. Use the 'hs2019' signature scheme,
249
+ sign the HTTP requests with the RSA-SSA-PSS signature algorithm, and set the expiration time
250
+ of the signature to 5 minutes after the signature has been created.
251
+ Note you can use the constants defined in the {{{packageName}}}.signing module, and you can
252
+ also specify arbitrary HTTP headers to be included in the HTTP signature, except for the
253
+ 'Authorization' header, which is used to carry the signature.
254
+
255
+ One may be tempted to sign all headers by default, but in practice it rarely works.
256
+ This is because explicit proxies, transparent proxies, TLS termination endpoints or
257
+ load balancers may add/modify/remove headers. Include the HTTP headers that you know
258
+ are not going to be modified in transit.
259
+
260
+ conf = {{{packageName}}}.Configuration(
261
+ signing_info = {{{packageName}}}.signing.HttpSigningConfiguration(
262
+ key_id = 'my-key-id',
263
+ private_key_path = 'rsa.pem',
264
+ signing_scheme = {{{packageName}}}.signing.SCHEME_HS2019,
265
+ signing_algorithm = {{{packageName}}}.signing.ALGORITHM_RSASSA_PSS,
266
+ signed_headers = [{{{packageName}}}.signing.HEADER_REQUEST_TARGET,
267
+ {{{packageName}}}.signing.HEADER_CREATED,
268
+ {{{packageName}}}.signing.HEADER_EXPIRES,
269
+ {{{packageName}}}.signing.HEADER_HOST,
270
+ {{{packageName}}}.signing.HEADER_DATE,
271
+ {{{packageName}}}.signing.HEADER_DIGEST,
272
+ 'Content-Type',
273
+ 'User-Agent'
274
+ ],
275
+ signature_max_validity = datetime.timedelta(minutes=5)
276
+ )
277
+ )
278
+ {{/hasHttpSignatureMethods}}
279
+ {{/hasAuthMethods}}
280
+ """
281
+
282
+ _default: ClassVar[Optional[Self]] = None
283
+
284
+ def __init__(
285
+ self,
286
+ host: Optional[str]=None,
287
+ api_key: Optional[Dict[str, str]]=None,
288
+ api_key_prefix: Optional[Dict[str, str]]=None,
289
+ username: Optional[str]=None,
290
+ password: Optional[str]=None,
291
+ access_token: Optional[str]=None,
292
+ {{#hasHttpSignatureMethods}}
293
+ signing_info: Optional[HttpSigningConfiguration]=None,
294
+ {{/hasHttpSignatureMethods}}
295
+ server_index: Optional[int]=None,
296
+ server_variables: Optional[ServerVariablesT]=None,
297
+ server_operation_index: Optional[Dict[int, int]]=None,
298
+ server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None,
299
+ ignore_operation_servers: bool=False,
300
+ ssl_ca_cert: Optional[str]=None,
301
+ retries: Optional[int] = None,
302
+ ca_cert_data: Optional[Union[str, bytes]] = None,
303
+ cert_file: Optional[str]=None,
304
+ key_file: Optional[str]=None,
305
+ *,
306
+ debug: Optional[bool] = None,
307
+ ) -> None:
308
+ """Constructor
309
+ """
310
+ self._base_path = "{{{basePath}}}" if host is None else host
311
+ """Default Base url
312
+ """
313
+ self.server_index = 0 if server_index is None and host is None else server_index
314
+ self.server_operation_index = server_operation_index or {}
315
+ """Default server index
316
+ """
317
+ self.server_variables = server_variables or {}
318
+ self.server_operation_variables = server_operation_variables or {}
319
+ """Default server variables
320
+ """
321
+ self.ignore_operation_servers = ignore_operation_servers
322
+ """Ignore operation servers
323
+ """
324
+ self.temp_folder_path = None
325
+ """Temp file folder for downloading files
326
+ """
327
+ # Authentication Settings
328
+ self.api_key = {}
329
+ if api_key:
330
+ self.api_key = api_key
331
+ """dict to store API key(s)
332
+ """
333
+ self.api_key_prefix = {}
334
+ if api_key_prefix:
335
+ self.api_key_prefix = api_key_prefix
336
+ """dict to store API prefix (e.g. Bearer)
337
+ """
338
+ self.refresh_api_key_hook = None
339
+ """function hook to refresh API key if expired
340
+ """
341
+ self.username = username
342
+ """Username for HTTP basic authentication
343
+ """
344
+ self.password = password
345
+ """Password for HTTP basic authentication
346
+ """
347
+ self.access_token = access_token
348
+ """Access token
349
+ """
350
+ {{#hasHttpSignatureMethods}}
351
+ if signing_info is not None:
352
+ signing_info.host = host
353
+ self.signing_info = signing_info
354
+ """The HTTP signing configuration
355
+ """
356
+ {{/hasHttpSignatureMethods}}
357
+ self.logger = {}
358
+ """Logging Settings
359
+ """
360
+ self.logger["package_logger"] = logging.getLogger("{{packageName}}")
361
+ {{^async}}
362
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
363
+ {{/async}}
364
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
365
+ """Log format
366
+ """
367
+ self.logger_stream_handler = None
368
+ """Log stream handler
369
+ """
370
+ self.logger_file_handler: Optional[FileHandler] = None
371
+ """Log file handler
372
+ """
373
+ self.logger_file = None
374
+ """Debug file location
375
+ """
376
+ if debug is not None:
377
+ self.debug = debug
378
+ else:
379
+ self.__debug = False
380
+ """Debug switch
381
+ """
382
+
383
+ self.verify_ssl = True
384
+ """SSL/TLS verification
385
+ Set this to false to skip verifying SSL certificate when calling API
386
+ from https server.
387
+ """
388
+ self.ssl_ca_cert = ssl_ca_cert
389
+ """Set this to customize the certificate file to verify the peer.
390
+ """
391
+ self.ca_cert_data = ca_cert_data
392
+ """Set this to verify the peer using PEM (str) or DER (bytes)
393
+ certificate data.
394
+ """
395
+ self.cert_file = cert_file
396
+ """client certificate file
397
+ """
398
+ self.key_file = key_file
399
+ """client key file
400
+ """
401
+ self.assert_hostname = None
402
+ """Set this to True/False to enable/disable SSL hostname verification.
403
+ """
404
+ self.tls_server_name = None
405
+ """SSL/TLS Server Name Indication (SNI)
406
+ Set this to the SNI value expected by the server.
407
+ """
408
+
409
+ {{#async}}
410
+ self.connection_pool_maxsize = 100
411
+ """This value is passed to the aiohttp to limit simultaneous connections.
412
+ Default values is 100, None means no-limit.
413
+ """
414
+ {{/async}}
415
+ {{^async}}
416
+ self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
417
+ """urllib3 connection pool's maximum number of connections saved
418
+ per pool. urllib3 uses 1 connection as default value, but this is
419
+ not the best value when you are making a lot of possibly parallel
420
+ requests to the same host, which is often the case here.
421
+ cpu_count * 5 is used as default value to increase performance.
422
+ """
423
+ {{/async}}
424
+
425
+ self.proxy: Optional[str] = None
426
+ """Proxy URL
427
+ """
428
+ self.proxy_headers = None
429
+ """Proxy headers
430
+ """
431
+ self.safe_chars_for_path_param = ''
432
+ """Safe chars for path_param
433
+ """
434
+ self.retries = retries
435
+ """Adding retries to override urllib3 default value 3
436
+ """
437
+ # Enable client side validation
438
+ self.client_side_validation = True
439
+
440
+ self.socket_options = None
441
+ """Options to pass down to the underlying urllib3 socket
442
+ """
443
+
444
+ self.datetime_format = "{{{datetimeFormat}}}"
445
+ """datetime format
446
+ """
447
+
448
+ self.date_format = "{{{dateFormat}}}"
449
+ """date format
450
+ """
451
+
452
+ def __deepcopy__(self, memo: Dict[int, Any]) -> Self:
453
+ cls = self.__class__
454
+ result = cls.__new__(cls)
455
+ memo[id(self)] = result
456
+ for k, v in self.__dict__.items():
457
+ if k not in ('logger', 'logger_file_handler'):
458
+ setattr(result, k, copy.deepcopy(v, memo))
459
+ # shallow copy of loggers
460
+ result.logger = copy.copy(self.logger)
461
+ # use setters to configure loggers
462
+ result.logger_file = self.logger_file
463
+ result.debug = self.debug
464
+ return result
465
+
466
+ def __setattr__(self, name: str, value: Any) -> None:
467
+ object.__setattr__(self, name, value)
468
+ {{#hasHttpSignatureMethods}}
469
+ if name == "signing_info" and value is not None:
470
+ # Ensure the host parameter from signing info is the same as
471
+ # Configuration.host.
472
+ value.host = self.host
473
+ {{/hasHttpSignatureMethods}}
474
+
475
+ @classmethod
476
+ def set_default(cls, default: Optional[Self]) -> None:
477
+ """Set default instance of configuration.
478
+
479
+ It stores default configuration, which can be
480
+ returned by get_default_copy method.
481
+
482
+ :param default: object of Configuration
483
+ """
484
+ cls._default = default
485
+
486
+ @classmethod
487
+ def get_default_copy(cls) -> Self:
488
+ """Deprecated. Please use `get_default` instead.
489
+
490
+ Deprecated. Please use `get_default` instead.
491
+
492
+ :return: The configuration object.
493
+ """
494
+ return cls.get_default()
495
+
496
+ @classmethod
497
+ def get_default(cls) -> Self:
498
+ """Return the default configuration.
499
+
500
+ This method returns newly created, based on default constructor,
501
+ object of Configuration class or returns a copy of default
502
+ configuration.
503
+
504
+ :return: The configuration object.
505
+ """
506
+ if cls._default is None:
507
+ cls._default = cls()
508
+ return cls._default
509
+
510
+ @property
511
+ def logger_file(self) -> Optional[str]:
512
+ """The logger file.
513
+
514
+ If the logger_file is None, then add stream handler and remove file
515
+ handler. Otherwise, add file handler and remove stream handler.
516
+
517
+ :param value: The logger_file path.
518
+ :type: str
519
+ """
520
+ return self.__logger_file
521
+
522
+ @logger_file.setter
523
+ def logger_file(self, value: Optional[str]) -> None:
524
+ """The logger file.
525
+
526
+ If the logger_file is None, then add stream handler and remove file
527
+ handler. Otherwise, add file handler and remove stream handler.
528
+
529
+ :param value: The logger_file path.
530
+ :type: str
531
+ """
532
+ self.__logger_file = value
533
+ if self.__logger_file:
534
+ # If set logging file,
535
+ # then add file handler and remove stream handler.
536
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
537
+ self.logger_file_handler.setFormatter(self.logger_formatter)
538
+ for _, logger in self.logger.items():
539
+ logger.addHandler(self.logger_file_handler)
540
+
541
+ @property
542
+ def debug(self) -> bool:
543
+ """Debug status
544
+
545
+ :param value: The debug status, True or False.
546
+ :type: bool
547
+ """
548
+ return self.__debug
549
+
550
+ @debug.setter
551
+ def debug(self, value: bool) -> None:
552
+ """Debug status
553
+
554
+ :param value: The debug status, True or False.
555
+ :type: bool
556
+ """
557
+ self.__debug = value
558
+ if self.__debug:
559
+ # if debug status is True, turn on debug logging
560
+ for _, logger in self.logger.items():
561
+ logger.setLevel(logging.DEBUG)
562
+ # turn on httplib debug
563
+ httplib.HTTPConnection.debuglevel = 1
564
+ else:
565
+ # if debug status is False, turn off debug logging,
566
+ # setting log level to default `logging.WARNING`
567
+ for _, logger in self.logger.items():
568
+ logger.setLevel(logging.WARNING)
569
+ # turn off httplib debug
570
+ httplib.HTTPConnection.debuglevel = 0
571
+
572
+ @property
573
+ def logger_format(self) -> str:
574
+ """The logger format.
575
+
576
+ The logger_formatter will be updated when sets logger_format.
577
+
578
+ :param value: The format string.
579
+ :type: str
580
+ """
581
+ return self.__logger_format
582
+
583
+ @logger_format.setter
584
+ def logger_format(self, value: str) -> None:
585
+ """The logger format.
586
+
587
+ The logger_formatter will be updated when sets logger_format.
588
+
589
+ :param value: The format string.
590
+ :type: str
591
+ """
592
+ self.__logger_format = value
593
+ self.logger_formatter = logging.Formatter(self.__logger_format)
594
+
595
+ def get_api_key_with_prefix(self, identifier: str, alias: Optional[str]=None) -> Optional[str]:
596
+ """Gets API key (with prefix if set).
597
+
598
+ :param identifier: The identifier of apiKey.
599
+ :param alias: The alternative identifier of apiKey.
600
+ :return: The token for api key authentication.
601
+ """
602
+ if self.refresh_api_key_hook is not None:
603
+ self.refresh_api_key_hook(self)
604
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
605
+ if key:
606
+ prefix = self.api_key_prefix.get(identifier)
607
+ if prefix:
608
+ return "%s %s" % (prefix, key)
609
+ else:
610
+ return key
611
+
612
+ return None
613
+
614
+ def get_basic_auth_token(self) -> Optional[str]:
615
+ """Gets HTTP basic authentication header (string).
616
+
617
+ :return: The token for basic HTTP authentication.
618
+ """
619
+ username = ""
620
+ if self.username is not None:
621
+ username = self.username
622
+ password = ""
623
+ if self.password is not None:
624
+ password = self.password
625
+
626
+ {{#async}}
627
+ return "Basic " + base64.b64encode(
628
+ (username + ":" + password).encode('utf-8')
629
+ ).decode('utf-8')
630
+ {{/async}}
631
+ {{^async}}
632
+ return urllib3.util.make_headers(
633
+ basic_auth=username + ':' + password
634
+ ).get('authorization')
635
+ {{/async}}
636
+
637
+ def auth_settings(self)-> AuthSettings:
638
+ """Gets Auth Settings dict for api client.
639
+
640
+ :return: The Auth Settings information dict.
641
+ """
642
+ auth: AuthSettings = {}
643
+ {{#authMethods}}
644
+ {{#isApiKey}}
645
+ if '{{name}}' in self.api_key{{#vendorExtensions.x-auth-id-alias}} or '{{.}}' in self.api_key{{/vendorExtensions.x-auth-id-alias}}:
646
+ auth['{{name}}'] = {
647
+ 'type': 'api_key',
648
+ 'in': {{#isKeyInCookie}}'cookie'{{/isKeyInCookie}}{{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}},
649
+ 'key': '{{keyParamName}}',
650
+ 'value': self.get_api_key_with_prefix(
651
+ '{{name}}',{{#vendorExtensions.x-auth-id-alias}}
652
+ alias='{{.}}',{{/vendorExtensions.x-auth-id-alias}}
653
+ ),
654
+ }
655
+ {{/isApiKey}}
656
+ {{#isBasic}}
657
+ {{#isBasicBasic}}
658
+ if self.username is not None and self.password is not None:
659
+ auth['{{name}}'] = {
660
+ 'type': 'basic',
661
+ 'in': 'header',
662
+ 'key': 'Authorization',
663
+ 'value': self.get_basic_auth_token()
664
+ }
665
+ {{/isBasicBasic}}
666
+ {{#isBasicBearer}}
667
+ if self.access_token is not None:
668
+ auth['{{name}}'] = {
669
+ 'type': 'bearer',
670
+ 'in': 'header',
671
+ {{#bearerFormat}}
672
+ 'format': '{{{.}}}',
673
+ {{/bearerFormat}}
674
+ 'key': 'Authorization',
675
+ 'value': 'Bearer ' + self.access_token
676
+ }
677
+ {{/isBasicBearer}}
678
+ {{#isHttpSignature}}
679
+ if self.signing_info is not None:
680
+ auth['{{name}}'] = {
681
+ 'type': 'http-signature',
682
+ 'in': 'header',
683
+ 'key': 'Authorization',
684
+ 'value': None # Signature headers are calculated for every HTTP request
685
+ }
686
+ {{/isHttpSignature}}
687
+ {{/isBasic}}
688
+ {{#isOAuth}}
689
+ if self.access_token is not None:
690
+ auth['{{name}}'] = {
691
+ 'type': 'oauth2',
692
+ 'in': 'header',
693
+ 'key': 'Authorization',
694
+ 'value': 'Bearer ' + self.access_token
695
+ }
696
+ {{/isOAuth}}
697
+ {{/authMethods}}
698
+ return auth
699
+
700
+ def to_debug_report(self) -> str:
701
+ """Gets the essential information for debugging.
702
+
703
+ :return: The report for debugging.
704
+ """
705
+ return "Python SDK Debug Report:\n"\
706
+ "OS: {env}\n"\
707
+ "Python Version: {pyversion}\n"\
708
+ "Version of the API: {{version}}\n"\
709
+ "SDK Package Version: {{packageVersion}}".\
710
+ format(env=sys.platform, pyversion=sys.version)
711
+
712
+ def get_host_settings(self) -> List[HostSetting]:
713
+ """Gets an array of host settings
714
+
715
+ :return: An array of host settings
716
+ """
717
+ return [
718
+ {{#servers}}
719
+ {
720
+ 'url': "{{{url}}}",
721
+ 'description': "{{{description}}}{{#unless description}}No description provided{{/unless}}",
722
+ {{#variables}}
723
+ {{#if @first}}
724
+ 'variables': {
725
+ {{/if}}
726
+ '{{{name}}}': {
727
+ 'description': "{{{description}}}{{#unless description}}No description provided{{/unless}}",
728
+ 'default_value': "{{{defaultValue}}}",
729
+ {{#enumValues}}
730
+ {{#if @first}}
731
+ 'enum_values': [
732
+ {{/if}}
733
+ "{{{.}}}"{{#unless @last}},{{/unless}}
734
+ {{#if @last}}
735
+ ]
736
+ {{/if}}
737
+ {{/enumValues}}
738
+ {{^enumValues}}
739
+ {{#async}}
740
+ 'enum_values': []
741
+ {{/async}}
742
+ {{/enumValues}}
743
+ }{{#unless @last}},{{/unless}}
744
+ {{#if @last}}
745
+ }
746
+ {{/if}}
747
+ {{/variables}}
748
+ }{{#unless @last}},{{/unless}}
749
+ {{/servers}}
750
+ ]
751
+
752
+ def get_host_from_settings(
753
+ self,
754
+ index: Optional[int],
755
+ variables: Optional[ServerVariablesT]=None,
756
+ servers: Optional[List[HostSetting]]=None,
757
+ ) -> str:
758
+ """Gets host URL based on the index and variables
759
+ :param index: array index of the host settings
760
+ :param variables: hash of variable and the corresponding value
761
+ :param servers: an array of host settings or None
762
+ :return: URL based on host settings
763
+ """
764
+ if index is None:
765
+ return self._base_path
766
+
767
+ variables = {} if variables is None else variables
768
+ servers = self.get_host_settings() if servers is None else servers
769
+
770
+ try:
771
+ server = servers[index]
772
+ except IndexError:
773
+ raise ValueError(
774
+ "Invalid index {0} when selecting the host settings. "
775
+ "Must be less than {1}".format(index, len(servers)))
776
+
777
+ url = server['url']
778
+
779
+ # go through variables and replace placeholders
780
+ for variable_name, variable in server.get('variables', {}).items():
781
+ used_value = variables.get(
782
+ variable_name, variable['default_value'])
783
+
784
+ if 'enum_values' in variable \
785
+ and variable['enum_values'] \
786
+ and used_value not in variable['enum_values']:
787
+ raise ValueError(
788
+ "The variable `{0}` in the host URL has invalid value "
789
+ "{1}. Must be {2}.".format(
790
+ variable_name, variables[variable_name],
791
+ variable['enum_values']))
792
+
793
+ url = url.replace("{" + variable_name + "}", used_value)
794
+
795
+ return url
796
+
797
+ @property
798
+ def host(self) -> str:
799
+ """Return generated host."""
800
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
801
+
802
+ @host.setter
803
+ def host(self, value: str) -> None:
804
+ """Fix base path."""
805
+ self._base_path = value
806
+ self.server_index = None