@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,210 @@
1
+ # coding: utf-8
2
+
3
+ {{>partial_header}}
4
+
5
+ from typing import Any, Optional
6
+ from typing_extensions import Self
7
+
8
+ class OpenApiException(Exception):
9
+ """The base exception class for all OpenAPIExceptions"""
10
+
11
+
12
+ class ApiTypeError(OpenApiException, TypeError):
13
+ def __init__(self, msg, path_to_item=None, valid_classes=None,
14
+ key_type=None) -> None:
15
+ """ Raises an exception for TypeErrors
16
+
17
+ Args:
18
+ msg (str): the exception message
19
+
20
+ Keyword Args:
21
+ path_to_item (list): a list of keys an indices to get to the
22
+ current_item
23
+ None if unset
24
+ valid_classes (tuple): the primitive classes that current item
25
+ should be an instance of
26
+ None if unset
27
+ key_type (bool): False if our value is a value in a dict
28
+ True if it is a key in a dict
29
+ False if our item is an item in a list
30
+ None if unset
31
+ """
32
+ self.path_to_item = path_to_item
33
+ self.valid_classes = valid_classes
34
+ self.key_type = key_type
35
+ full_msg = msg
36
+ if path_to_item:
37
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
38
+ super(ApiTypeError, self).__init__(full_msg)
39
+
40
+
41
+ class ApiValueError(OpenApiException, ValueError):
42
+ def __init__(self, msg, path_to_item=None) -> None:
43
+ """
44
+ Args:
45
+ msg (str): the exception message
46
+
47
+ Keyword Args:
48
+ path_to_item (list) the path to the exception in the
49
+ received_data dict. None if unset
50
+ """
51
+
52
+ self.path_to_item = path_to_item
53
+ full_msg = msg
54
+ if path_to_item:
55
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
56
+ super(ApiValueError, self).__init__(full_msg)
57
+
58
+
59
+ class ApiAttributeError(OpenApiException, AttributeError):
60
+ def __init__(self, msg, path_to_item=None) -> None:
61
+ """
62
+ Raised when an attribute reference or assignment fails.
63
+
64
+ Args:
65
+ msg (str): the exception message
66
+
67
+ Keyword Args:
68
+ path_to_item (None/list) the path to the exception in the
69
+ received_data dict
70
+ """
71
+ self.path_to_item = path_to_item
72
+ full_msg = msg
73
+ if path_to_item:
74
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
75
+ super(ApiAttributeError, self).__init__(full_msg)
76
+
77
+
78
+ class ApiKeyError(OpenApiException, KeyError):
79
+ def __init__(self, msg, path_to_item=None) -> None:
80
+ """
81
+ Args:
82
+ msg (str): the exception message
83
+
84
+ Keyword Args:
85
+ path_to_item (None/list) the path to the exception in the
86
+ received_data dict
87
+ """
88
+ self.path_to_item = path_to_item
89
+ full_msg = msg
90
+ if path_to_item:
91
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
92
+ super(ApiKeyError, self).__init__(full_msg)
93
+
94
+
95
+ class ApiException(OpenApiException):
96
+
97
+ def __init__(
98
+ self,
99
+ status=None,
100
+ reason=None,
101
+ http_resp=None,
102
+ *,
103
+ body: Optional[str] = None,
104
+ data: Optional[Any] = None,
105
+ ) -> None:
106
+ self.status = status
107
+ self.reason = reason
108
+ self.body = body
109
+ self.data = data
110
+ self.headers = None
111
+
112
+ if http_resp:
113
+ if self.status is None:
114
+ self.status = http_resp.status
115
+ if self.reason is None:
116
+ self.reason = http_resp.reason
117
+ if self.body is None:
118
+ try:
119
+ self.body = http_resp.data.decode('utf-8')
120
+ except Exception:
121
+ pass
122
+ self.headers = http_resp.headers
123
+
124
+ @classmethod
125
+ def from_response(
126
+ cls,
127
+ *,
128
+ http_resp,
129
+ body: Optional[str],
130
+ data: Optional[Any],
131
+ ) -> Self:
132
+ if http_resp.status == 400:
133
+ raise BadRequestException(http_resp=http_resp, body=body, data=data)
134
+
135
+ if http_resp.status == 401:
136
+ raise UnauthorizedException(http_resp=http_resp, body=body, data=data)
137
+
138
+ if http_resp.status == 403:
139
+ raise ForbiddenException(http_resp=http_resp, body=body, data=data)
140
+
141
+ if http_resp.status == 404:
142
+ raise NotFoundException(http_resp=http_resp, body=body, data=data)
143
+
144
+ # Added new conditions for 409 and 422
145
+ if http_resp.status == 409:
146
+ raise ConflictException(http_resp=http_resp, body=body, data=data)
147
+
148
+ if http_resp.status == 422:
149
+ raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data)
150
+
151
+ if 500 <= http_resp.status <= 599:
152
+ raise ServiceException(http_resp=http_resp, body=body, data=data)
153
+ raise ApiException(http_resp=http_resp, body=body, data=data)
154
+
155
+ def __str__(self):
156
+ """Custom error messages for exception"""
157
+ error_message = "({0})\n"\
158
+ "Reason: {1}\n".format(self.status, self.reason)
159
+ if self.headers:
160
+ error_message += "HTTP response headers: {0}\n".format(
161
+ self.headers)
162
+
163
+ if self.body:
164
+ error_message += "HTTP response body: {0}\n".format(self.body)
165
+
166
+ if self.data:
167
+ error_message += "HTTP response data: {0}\n".format(self.data)
168
+
169
+ return error_message
170
+
171
+
172
+ class BadRequestException(ApiException):
173
+ pass
174
+
175
+
176
+ class NotFoundException(ApiException):
177
+ pass
178
+
179
+
180
+ class UnauthorizedException(ApiException):
181
+ pass
182
+
183
+
184
+ class ForbiddenException(ApiException):
185
+ pass
186
+
187
+
188
+ class ServiceException(ApiException):
189
+ pass
190
+
191
+
192
+ class ConflictException(ApiException):
193
+ """Exception for HTTP 409 Conflict."""
194
+ pass
195
+
196
+
197
+ class UnprocessableEntityException(ApiException):
198
+ """Exception for HTTP 422 Unprocessable Entity."""
199
+ pass
200
+
201
+
202
+ def render_path(path_to_item):
203
+ """Returns a string representation of a path"""
204
+ result = ""
205
+ for pth in path_to_item:
206
+ if isinstance(pth, int):
207
+ result += "[{0}]".format(pth)
208
+ else:
209
+ result += "['{0}']".format(pth)
210
+ return result
@@ -0,0 +1,3 @@
1
+ # import apis into api package
2
+ {{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}}
3
+ {{/apis}}{{/apiInfo}}
@@ -0,0 +1,3 @@
1
+ # import models into model package
2
+ {{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}}
3
+ {{/model}}{{/models}}
@@ -0,0 +1,20 @@
1
+ # import apis into sdk package
2
+ {{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}} as {{classname}}
3
+ {{/apis}}{{/apiInfo}}
4
+ # import ApiClient
5
+ from {{packageName}}.api_response import ApiResponse as ApiResponse
6
+ from {{packageName}}.api_client import ApiClient as ApiClient
7
+ from {{packageName}}.configuration import Configuration as Configuration
8
+ from {{packageName}}.exceptions import OpenApiException as OpenApiException
9
+ from {{packageName}}.exceptions import ApiTypeError as ApiTypeError
10
+ from {{packageName}}.exceptions import ApiValueError as ApiValueError
11
+ from {{packageName}}.exceptions import ApiKeyError as ApiKeyError
12
+ from {{packageName}}.exceptions import ApiAttributeError as ApiAttributeError
13
+ from {{packageName}}.exceptions import ApiException as ApiException
14
+ {{#hasHttpSignatureMethods}}
15
+ from {{packageName}}.signing import HttpSigningConfiguration as HttpSigningConfiguration
16
+ {{/hasHttpSignatureMethods}}
17
+
18
+ # import models into sdk package
19
+ {{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}} as {{classname}}
20
+ {{/model}}{{/models}}
@@ -0,0 +1,57 @@
1
+ #!/bin/sh
2
+ # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3
+ #
4
+ # Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
5
+
6
+ git_user_id=$1
7
+ git_repo_id=$2
8
+ release_note=$3
9
+ git_host=$4
10
+
11
+ if [ "$git_host" = "" ]; then
12
+ git_host="{{{gitHost}}}"
13
+ echo "[INFO] No command line input provided. Set \$git_host to $git_host"
14
+ fi
15
+
16
+ if [ "$git_user_id" = "" ]; then
17
+ git_user_id="{{{gitUserId}}}"
18
+ echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
19
+ fi
20
+
21
+ if [ "$git_repo_id" = "" ]; then
22
+ git_repo_id="{{{gitRepoId}}}"
23
+ echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
24
+ fi
25
+
26
+ if [ "$release_note" = "" ]; then
27
+ release_note="{{{releaseNote}}}"
28
+ echo "[INFO] No command line input provided. Set \$release_note to $release_note"
29
+ fi
30
+
31
+ # Initialize the local directory as a Git repository
32
+ git init
33
+
34
+ # Adds the files in the local repository and stages them for commit.
35
+ git add .
36
+
37
+ # Commits the tracked changes and prepares them to be pushed to a remote repository.
38
+ git commit -m "$release_note"
39
+
40
+ # Sets the new remote
41
+ git_remote=$(git remote)
42
+ if [ "$git_remote" = "" ]; then # git remote not defined
43
+
44
+ if [ "$GIT_TOKEN" = "" ]; then
45
+ echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
46
+ git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
47
+ else
48
+ git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
49
+ fi
50
+
51
+ fi
52
+
53
+ git pull origin master
54
+
55
+ # Pushes (Forces) the changes in the local repository up to the remote repository
56
+ echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
57
+ git push origin master 2>&1 | grep -v 'To https'
@@ -0,0 +1,35 @@
1
+ # NOTE: This file is auto generated by OpenAPI Generator.
2
+ # URL: https://openapi-generator.tech
3
+ #
4
+ # ref: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
5
+
6
+ name: {{packageName}} Python package
7
+
8
+
9
+ on: [push, pull_request]
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ build:
16
+
17
+ runs-on: ubuntu-latest
18
+ strategy:
19
+ matrix:
20
+ python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - name: Set up Python ${{ matrix.python-version }}
25
+ uses: actions/setup-python@v4
26
+ with:
27
+ python-version: ${{ matrix.python-version }}
28
+ - name: Install dependencies
29
+ run: |
30
+ python -m pip install --upgrade pip
31
+ pip install -r requirements.txt
32
+ pip install -r test-requirements.txt
33
+ - name: Test with pytest
34
+ run: |
35
+ pytest --cov={{packageName}}
@@ -0,0 +1,66 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ env/
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+
27
+ # PyInstaller
28
+ # Usually these files are written by a python script from a template
29
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
30
+ *.manifest
31
+ *.spec
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .coverage
41
+ .coverage.*
42
+ .cache
43
+ nosetests.xml
44
+ coverage.xml
45
+ *,cover
46
+ .hypothesis/
47
+ venv/
48
+ .venv/
49
+ .python-version
50
+ .pytest_cache
51
+
52
+ # Translations
53
+ *.mo
54
+ *.pot
55
+
56
+ # Django stuff:
57
+ *.log
58
+
59
+ # Sphinx documentation
60
+ docs/_build/
61
+
62
+ # PyBuilder
63
+ target/
64
+
65
+ # Ipython Notebook
66
+ .ipynb_checkpoints
@@ -0,0 +1,31 @@
1
+ # NOTE: This file is auto generated by OpenAPI Generator.
2
+ # URL: https://openapi-generator.tech
3
+ #
4
+ # ref: https://docs.gitlab.com/ee/ci/README.html
5
+ # ref: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml
6
+
7
+ stages:
8
+ - test
9
+
10
+ .pytest:
11
+ stage: test
12
+ script:
13
+ - pip install -r requirements.txt
14
+ - pip install -r test-requirements.txt
15
+ - pytest --cov={{{packageName}}}
16
+
17
+ pytest-3.9:
18
+ extends: .pytest
19
+ image: python:3.9-alpine
20
+ pytest-3.10:
21
+ extends: .pytest
22
+ image: python:3.10-alpine
23
+ pytest-3.11:
24
+ extends: .pytest
25
+ image: python:3.11-alpine
26
+ pytest-3.12:
27
+ extends: .pytest
28
+ image: python:3.12-alpine
29
+ pytest-3.13:
30
+ extends: .pytest
31
+ image: python:3.13-alpine
@@ -0,0 +1,190 @@
1
+ # coding: utf-8
2
+
3
+ {{>partial_header}}
4
+
5
+
6
+ import io
7
+ import json
8
+ import re
9
+ import ssl
10
+ from typing import Optional, Union
11
+
12
+ import httpx
13
+
14
+ from {{packageName}}.exceptions import ApiException, ApiValueError
15
+
16
+ RESTResponseType = httpx.Response
17
+
18
+ class RESTResponse(io.IOBase):
19
+
20
+ def __init__(self, resp) -> None:
21
+ self.response = resp
22
+ self.status = resp.status_code
23
+ self.reason = resp.reason_phrase
24
+ self.data = None
25
+
26
+ async def read(self):
27
+ if self.data is None:
28
+ self.data = await self.response.aread()
29
+ return self.data
30
+
31
+ @property
32
+ def headers(self):
33
+ """Returns a CIMultiDictProxy of response headers."""
34
+ return self.response.headers
35
+
36
+ def getheaders(self):
37
+ """Returns a CIMultiDictProxy of the response headers; use ``headers`` instead."""
38
+ return self.response.headers
39
+
40
+ def getheader(self, name, default=None):
41
+ """Returns a given response header; use ``headers`` instead."""
42
+ return self.response.headers.get(name, default)
43
+
44
+
45
+ class RESTClientObject:
46
+
47
+ def __init__(self, configuration) -> None:
48
+
49
+ # maxsize is number of requests to host that are allowed in parallel
50
+ self.maxsize = configuration.connection_pool_maxsize
51
+
52
+ self.ssl_context = ssl.create_default_context(
53
+ cafile=configuration.ssl_ca_cert,
54
+ cadata=configuration.ca_cert_data,
55
+ )
56
+ if configuration.cert_file:
57
+ self.ssl_context.load_cert_chain(
58
+ configuration.cert_file, keyfile=configuration.key_file
59
+ )
60
+
61
+ if not configuration.verify_ssl:
62
+ self.ssl_context.check_hostname = False
63
+ self.ssl_context.verify_mode = ssl.CERT_NONE
64
+
65
+ self.proxy = configuration.proxy
66
+ self.proxy_headers = configuration.proxy_headers
67
+
68
+ self.pool_manager: Optional[httpx.AsyncClient] = None
69
+
70
+ async def close(self):
71
+ if self.pool_manager is not None:
72
+ await self.pool_manager.aclose()
73
+
74
+ async def request(
75
+ self,
76
+ method,
77
+ url,
78
+ headers=None,
79
+ body=None,
80
+ post_params=None,
81
+ _request_timeout=None):
82
+ """Execute request
83
+
84
+ :param method: http request method
85
+ :param url: http request url
86
+ :param headers: http request headers
87
+ :param body: request json body, for `application/json`
88
+ :param post_params: request post parameters,
89
+ `application/x-www-form-urlencoded`
90
+ and `multipart/form-data`
91
+ :param _request_timeout: timeout setting for this request. If one
92
+ number provided, it will be total request
93
+ timeout. It can also be a pair (tuple) of
94
+ (connection, read) timeouts.
95
+ """
96
+ method = method.upper()
97
+ assert method in [
98
+ 'GET',
99
+ 'HEAD',
100
+ 'DELETE',
101
+ 'POST',
102
+ 'PUT',
103
+ 'PATCH',
104
+ 'OPTIONS'
105
+ ]
106
+
107
+ if post_params and body:
108
+ raise ApiValueError(
109
+ "body parameter cannot be used with post_params parameter."
110
+ )
111
+
112
+ post_params = post_params or {}
113
+ headers = headers or {}
114
+ timeout = _request_timeout or 5 * 60
115
+
116
+ if 'Content-Type' not in headers:
117
+ headers['Content-Type'] = 'application/json'
118
+
119
+ args = {
120
+ "method": method,
121
+ "url": url,
122
+ "timeout": timeout,
123
+ "headers": headers
124
+ }
125
+
126
+ # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
127
+ if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
128
+ if re.search('json', headers['Content-Type'], re.IGNORECASE):
129
+ if body is not None:
130
+ args["json"] = body
131
+ elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
132
+ args["data"] = dict(post_params)
133
+ elif headers['Content-Type'] == 'multipart/form-data':
134
+ # must del headers['Content-Type'], or the correct
135
+ # Content-Type which generated by httpx
136
+ del headers['Content-Type']
137
+
138
+ files = []
139
+ data = {}
140
+ for param in post_params:
141
+ k, v = param
142
+ if isinstance(v, tuple) and len(v) == 3:
143
+ files.append((k, v))
144
+ else:
145
+ # Ensures that dict objects are serialized
146
+ if isinstance(v, dict):
147
+ v = json.dumps(v)
148
+ elif isinstance(v, int):
149
+ v = str(v)
150
+ data[k] = v
151
+
152
+ if files:
153
+ args["files"] = files
154
+ if data:
155
+ args["data"] = data
156
+
157
+ # Pass a `bytes` parameter directly in the body to support
158
+ # other content types than Json when `body` argument is provided
159
+ # in serialized form
160
+ elif isinstance(body, str) or isinstance(body, bytes):
161
+ args["data"] = body
162
+ else:
163
+ # Cannot generate the request from given parameters
164
+ msg = """Cannot prepare a request message for provided
165
+ arguments. Please check that your arguments match
166
+ declared content type."""
167
+ raise ApiException(status=0, reason=msg)
168
+
169
+ if self.pool_manager is None:
170
+ self.pool_manager = self._create_pool_manager()
171
+
172
+ r = await self.pool_manager.request(**args)
173
+ return RESTResponse(r)
174
+
175
+ def _create_pool_manager(self) -> httpx.AsyncClient:
176
+ limits = httpx.Limits(max_connections=self.maxsize)
177
+
178
+ proxy = None
179
+ if self.proxy:
180
+ proxy = httpx.Proxy(
181
+ url=self.proxy,
182
+ headers=self.proxy_headers
183
+ )
184
+
185
+ return httpx.AsyncClient(
186
+ limits=limits,
187
+ proxy=proxy,
188
+ verify=self.ssl_context,
189
+ trust_env=True
190
+ )
@@ -0,0 +1,16 @@
1
+ # coding: utf-8
2
+
3
+ {{>partial_header}}
4
+
5
+
6
+ {{#models}}
7
+ {{#model}}
8
+ {{#isEnum}}
9
+ {{>model_enum}}
10
+
11
+ {{/isEnum}}
12
+ {{^isEnum}}
13
+ {{#oneOf}}{{#if @first}}{{>model_oneof}}{{/if}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#if @first}}{{>model_anyof}}{{/if}}{{/anyOf}}{{^anyOf}}{{>model_generic}}{{/anyOf}}{{/oneOf}}
14
+ {{/isEnum}}
15
+ {{/model}}
16
+ {{/models}}