@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,209 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import json
|
|
3
|
+
import pprint
|
|
4
|
+
{{#vendorExtensions.x-py-other-imports}}
|
|
5
|
+
{{{.}}}
|
|
6
|
+
{{/vendorExtensions.x-py-other-imports}}
|
|
7
|
+
{{#vendorExtensions.x-py-model-imports}}
|
|
8
|
+
{{{.}}}
|
|
9
|
+
{{/vendorExtensions.x-py-model-imports}}
|
|
10
|
+
from pydantic import StrictStr, Field
|
|
11
|
+
from typing import Union, List, Set, Optional, Dict
|
|
12
|
+
from typing_extensions import Literal, Self
|
|
13
|
+
|
|
14
|
+
{{#uppercase}}{{{classname}}}{{/uppercase}}_ONE_OF_SCHEMAS = [{{#oneOf}}"{{.}}"{{#unless @last}}, {{/unless}}{{/oneOf}}]
|
|
15
|
+
|
|
16
|
+
class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}):
|
|
17
|
+
"""
|
|
18
|
+
{{{description}}}{{#unless description}}{{{classname}}}{{/unless}}
|
|
19
|
+
"""
|
|
20
|
+
{{#composedSchemas.oneOf}}
|
|
21
|
+
# data type: {{{dataType}}}
|
|
22
|
+
{{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
|
|
23
|
+
{{/composedSchemas.oneOf}}
|
|
24
|
+
actual_instance: Optional[Union[{{#oneOf}}{{{.}}}{{#unless @last}}, {{/unless}}{{/oneOf}}]] = None
|
|
25
|
+
one_of_schemas: Set[str] = { {{#oneOf}}"{{.}}"{{#unless @last}}, {{/unless}}{{/oneOf}} }
|
|
26
|
+
|
|
27
|
+
model_config = ConfigDict(
|
|
28
|
+
validate_assignment=True,
|
|
29
|
+
protected_namespaces=(),
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
{{#discriminator}}
|
|
33
|
+
|
|
34
|
+
discriminator_value_class_map: Dict[str, str] = {
|
|
35
|
+
{{#children}}
|
|
36
|
+
'{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': '{{{classname}}}'{{#unless @last}},{{/unless}}
|
|
37
|
+
{{/children}}
|
|
38
|
+
}
|
|
39
|
+
{{/discriminator}}
|
|
40
|
+
|
|
41
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
42
|
+
if args:
|
|
43
|
+
if len(args) > 1:
|
|
44
|
+
raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
|
|
45
|
+
if kwargs:
|
|
46
|
+
raise ValueError("If a position argument is used, keyword arguments cannot be used.")
|
|
47
|
+
super().__init__(actual_instance=args[0])
|
|
48
|
+
else:
|
|
49
|
+
super().__init__(**kwargs)
|
|
50
|
+
|
|
51
|
+
@field_validator('actual_instance')
|
|
52
|
+
def actual_instance_must_validate_oneof(cls, v):
|
|
53
|
+
{{#isNullable}}
|
|
54
|
+
if v is None:
|
|
55
|
+
return v
|
|
56
|
+
|
|
57
|
+
{{/isNullable}}
|
|
58
|
+
instance = {{{classname}}}.model_construct()
|
|
59
|
+
error_messages = []
|
|
60
|
+
match = 0
|
|
61
|
+
{{#composedSchemas.oneOf}}
|
|
62
|
+
# validate data type: {{{dataType}}}
|
|
63
|
+
{{#isContainer}}
|
|
64
|
+
try:
|
|
65
|
+
instance.{{vendorExtensions.x-py-name}} = v
|
|
66
|
+
match += 1
|
|
67
|
+
except (ValidationError, ValueError) as e:
|
|
68
|
+
error_messages.append(str(e))
|
|
69
|
+
{{/isContainer}}
|
|
70
|
+
{{^isContainer}}
|
|
71
|
+
{{#isPrimitiveType}}
|
|
72
|
+
try:
|
|
73
|
+
instance.{{vendorExtensions.x-py-name}} = v
|
|
74
|
+
match += 1
|
|
75
|
+
except (ValidationError, ValueError) as e:
|
|
76
|
+
error_messages.append(str(e))
|
|
77
|
+
{{/isPrimitiveType}}
|
|
78
|
+
{{^isPrimitiveType}}
|
|
79
|
+
if not isinstance(v, {{{dataType}}}):
|
|
80
|
+
error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`")
|
|
81
|
+
else:
|
|
82
|
+
match += 1
|
|
83
|
+
{{/isPrimitiveType}}
|
|
84
|
+
{{/isContainer}}
|
|
85
|
+
{{/composedSchemas.oneOf}}
|
|
86
|
+
if match > 1:
|
|
87
|
+
# more than 1 match
|
|
88
|
+
raise ValueError("Multiple matches found when setting `actual_instance` in {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{#unless @last}}, {{/unless}}{{/oneOf}}. Details: " + ", ".join(error_messages))
|
|
89
|
+
elif match == 0:
|
|
90
|
+
# no match
|
|
91
|
+
raise ValueError("No match found when setting `actual_instance` in {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{#unless @last}}, {{/unless}}{{/oneOf}}. Details: " + ", ".join(error_messages))
|
|
92
|
+
else:
|
|
93
|
+
return v
|
|
94
|
+
|
|
95
|
+
@classmethod
|
|
96
|
+
def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
|
|
97
|
+
return cls.from_json(json.dumps(obj))
|
|
98
|
+
|
|
99
|
+
@classmethod
|
|
100
|
+
{{#isNullable}}
|
|
101
|
+
def from_json(cls, json_str: Optional[str]) -> Self:
|
|
102
|
+
{{/isNullable}}
|
|
103
|
+
{{^isNullable}}
|
|
104
|
+
def from_json(cls, json_str: str) -> Self:
|
|
105
|
+
{{/isNullable}}
|
|
106
|
+
"""Returns the object represented by the json string"""
|
|
107
|
+
instance = cls.model_construct()
|
|
108
|
+
{{#isNullable}}
|
|
109
|
+
if json_str is None:
|
|
110
|
+
return instance
|
|
111
|
+
|
|
112
|
+
{{/isNullable}}
|
|
113
|
+
error_messages = []
|
|
114
|
+
match = 0
|
|
115
|
+
|
|
116
|
+
{{#useOneOfDiscriminatorLookup}}
|
|
117
|
+
{{#discriminator}}
|
|
118
|
+
{{#mappedModels}}
|
|
119
|
+
{{#if @first}}
|
|
120
|
+
# use oneOf discriminator to lookup the data type
|
|
121
|
+
_data_type = json.loads(json_str).get("{{{propertyBaseName}}}")
|
|
122
|
+
if not _data_type:
|
|
123
|
+
raise ValueError("Failed to lookup data type from the field `{{{propertyBaseName}}}` in the input.")
|
|
124
|
+
|
|
125
|
+
{{/if}}
|
|
126
|
+
# check if data type is `{{{modelName}}}`
|
|
127
|
+
if _data_type == "{{{mappingName}}}":
|
|
128
|
+
instance.actual_instance = {{{modelName}}}.from_json(json_str)
|
|
129
|
+
return instance
|
|
130
|
+
|
|
131
|
+
{{/mappedModels}}
|
|
132
|
+
{{/discriminator}}
|
|
133
|
+
{{/useOneOfDiscriminatorLookup}}
|
|
134
|
+
{{#composedSchemas.oneOf}}
|
|
135
|
+
{{#isContainer}}
|
|
136
|
+
# deserialize data into {{{dataType}}}
|
|
137
|
+
try:
|
|
138
|
+
# validation
|
|
139
|
+
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
|
|
140
|
+
# assign value to actual_instance
|
|
141
|
+
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
|
|
142
|
+
match += 1
|
|
143
|
+
except (ValidationError, ValueError) as e:
|
|
144
|
+
error_messages.append(str(e))
|
|
145
|
+
{{/isContainer}}
|
|
146
|
+
{{^isContainer}}
|
|
147
|
+
{{#isPrimitiveType}}
|
|
148
|
+
# deserialize data into {{{dataType}}}
|
|
149
|
+
try:
|
|
150
|
+
# validation
|
|
151
|
+
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
|
|
152
|
+
# assign value to actual_instance
|
|
153
|
+
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
|
|
154
|
+
match += 1
|
|
155
|
+
except (ValidationError, ValueError) as e:
|
|
156
|
+
error_messages.append(str(e))
|
|
157
|
+
{{/isPrimitiveType}}
|
|
158
|
+
{{^isPrimitiveType}}
|
|
159
|
+
# deserialize data into {{{dataType}}}
|
|
160
|
+
try:
|
|
161
|
+
instance.actual_instance = {{{dataType}}}.from_json(json_str)
|
|
162
|
+
match += 1
|
|
163
|
+
except (ValidationError, ValueError) as e:
|
|
164
|
+
error_messages.append(str(e))
|
|
165
|
+
{{/isPrimitiveType}}
|
|
166
|
+
{{/isContainer}}
|
|
167
|
+
{{/composedSchemas.oneOf}}
|
|
168
|
+
|
|
169
|
+
if match > 1:
|
|
170
|
+
# more than 1 match
|
|
171
|
+
raise ValueError("Multiple matches found when deserializing the JSON string into {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{#unless @last}}, {{/unless}}{{/oneOf}}. Details: " + ", ".join(error_messages))
|
|
172
|
+
elif match == 0:
|
|
173
|
+
# no match
|
|
174
|
+
raise ValueError("No match found when deserializing the JSON string into {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{#unless @last}}, {{/unless}}{{/oneOf}}. Details: " + ", ".join(error_messages))
|
|
175
|
+
else:
|
|
176
|
+
return instance
|
|
177
|
+
|
|
178
|
+
def to_json(self) -> str:
|
|
179
|
+
"""Returns the JSON representation of the actual instance"""
|
|
180
|
+
if self.actual_instance is None:
|
|
181
|
+
return "null"
|
|
182
|
+
|
|
183
|
+
if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json):
|
|
184
|
+
return self.actual_instance.to_json()
|
|
185
|
+
else:
|
|
186
|
+
return json.dumps(self.actual_instance)
|
|
187
|
+
|
|
188
|
+
def to_dict(self) -> Optional[Union[Dict[str, Any], {{#oneOf}}{{{.}}}{{#unless @last}}, {{/unless}}{{/oneOf}}]]:
|
|
189
|
+
"""Returns the dict representation of the actual instance"""
|
|
190
|
+
if self.actual_instance is None:
|
|
191
|
+
return None
|
|
192
|
+
|
|
193
|
+
if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict):
|
|
194
|
+
return self.actual_instance.to_dict()
|
|
195
|
+
else:
|
|
196
|
+
# primitive type
|
|
197
|
+
return self.actual_instance
|
|
198
|
+
|
|
199
|
+
def to_str(self) -> str:
|
|
200
|
+
"""Returns the string representation of the actual instance"""
|
|
201
|
+
return pprint.pformat(self.model_dump())
|
|
202
|
+
|
|
203
|
+
{{#vendorExtensions.x-py-postponed-model-imports.size}}
|
|
204
|
+
{{#vendorExtensions.x-py-postponed-model-imports}}
|
|
205
|
+
{{{.}}}
|
|
206
|
+
{{/vendorExtensions.x-py-postponed-model-imports}}
|
|
207
|
+
# TODO: Rewrite to not use raise_errors
|
|
208
|
+
{{classname}}.model_rebuild(raise_errors=False)
|
|
209
|
+
{{/vendorExtensions.x-py-postponed-model-imports.size}}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
{{>partial_header}}
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import unittest
|
|
7
|
+
|
|
8
|
+
{{#models}}
|
|
9
|
+
{{#model}}
|
|
10
|
+
from {{modelPackage}}.{{classFilename}} import {{classname}}
|
|
11
|
+
|
|
12
|
+
class Test{{classname}}(unittest.TestCase):
|
|
13
|
+
"""{{classname}} unit test stubs"""
|
|
14
|
+
|
|
15
|
+
def setUp(self):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
def tearDown(self):
|
|
19
|
+
pass
|
|
20
|
+
{{^isEnum}}
|
|
21
|
+
|
|
22
|
+
def make_instance(self, include_optional) -> {{classname}}:
|
|
23
|
+
"""Test {{classname}}
|
|
24
|
+
include_optional is a boolean, when False only required
|
|
25
|
+
params are included, when True both required and
|
|
26
|
+
optional params are included """
|
|
27
|
+
# uncomment below to create an instance of `{{{classname}}}`
|
|
28
|
+
"""
|
|
29
|
+
model = {{classname}}()
|
|
30
|
+
if include_optional:
|
|
31
|
+
return {{classname}}(
|
|
32
|
+
{{#vars}}
|
|
33
|
+
{{name}} = {{{example}}}{{#unless example}}None{{/unless}}{{#unless @last}},{{/unless}}
|
|
34
|
+
{{/vars}}
|
|
35
|
+
)
|
|
36
|
+
else:
|
|
37
|
+
return {{classname}}(
|
|
38
|
+
{{#vars}}
|
|
39
|
+
{{#required}}
|
|
40
|
+
{{name}} = {{{example}}}{{#unless example}}None{{/unless}},
|
|
41
|
+
{{/required}}
|
|
42
|
+
{{/vars}}
|
|
43
|
+
)
|
|
44
|
+
"""
|
|
45
|
+
{{/isEnum}}
|
|
46
|
+
|
|
47
|
+
def test{{classname}}(self):
|
|
48
|
+
"""Test {{classname}}"""
|
|
49
|
+
{{^isEnum}}
|
|
50
|
+
# inst_req_only = self.make_instance(include_optional=False)
|
|
51
|
+
# inst_req_and_optional = self.make_instance(include_optional=True)
|
|
52
|
+
{{/isEnum}}
|
|
53
|
+
{{#isEnum}}
|
|
54
|
+
# inst = {{{classname}}}()
|
|
55
|
+
{{/isEnum}}
|
|
56
|
+
{{/model}}
|
|
57
|
+
{{/models}}
|
|
58
|
+
|
|
59
|
+
if __name__ == '__main__':
|
|
60
|
+
unittest.main()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""{{#isDeprecated}}(Deprecated) {{/isDeprecated}}{{{summary}}}{{#unless summary}}{{operationId}}{{/unless}}
|
|
2
|
+
|
|
3
|
+
{{#if notes}}
|
|
4
|
+
{{{notes}}}
|
|
5
|
+
{{/if}}
|
|
6
|
+
|
|
7
|
+
{{#allParams}}
|
|
8
|
+
:param {{paramName}}:{{#if description}} {{{description}}}{{/if}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
|
|
9
|
+
:type {{paramName}}: {{dataType}}{{#optional}}, optional{{/optional}}
|
|
10
|
+
{{/allParams}}
|
|
11
|
+
:param _request_timeout: timeout setting for this request. If one
|
|
12
|
+
number provided, it will be total request
|
|
13
|
+
timeout. It can also be a pair (tuple) of
|
|
14
|
+
(connection, read) timeouts.
|
|
15
|
+
:type _request_timeout: int, tuple(int, int), optional
|
|
16
|
+
:param _request_auth: set to override the auth_settings for an a single
|
|
17
|
+
request; this effectively ignores the
|
|
18
|
+
authentication in the spec for a single request.
|
|
19
|
+
:type _request_auth: dict, optional
|
|
20
|
+
:param _content_type: force content-type for the request.
|
|
21
|
+
:type _content_type: str, Optional
|
|
22
|
+
:param _headers: set to override the headers for a single
|
|
23
|
+
request; this effectively ignores the headers
|
|
24
|
+
in the spec for a single request.
|
|
25
|
+
:type _headers: dict, optional
|
|
26
|
+
:param _host_index: set to override the host_index for a single
|
|
27
|
+
request; this effectively ignores the host_index
|
|
28
|
+
in the spec for a single request.
|
|
29
|
+
:type _host_index: int, optional
|
|
30
|
+
:return: Returns the result object.
|
|
31
|
+
""" # noqa: E501
|
|
32
|
+
{{#isDeprecated}}
|
|
33
|
+
warnings.warn("{{{httpMethod}}} {{{path}}} is deprecated.", DeprecationWarning)
|
|
34
|
+
{{/isDeprecated}}
|
|
35
|
+
|
|
36
|
+
_param = self._{{operationId}}_serialize(
|
|
37
|
+
{{#allParams}}
|
|
38
|
+
{{paramName}}={{paramName}},
|
|
39
|
+
{{/allParams}}
|
|
40
|
+
_request_auth=_request_auth,
|
|
41
|
+
_content_type=_content_type,
|
|
42
|
+
_headers=_headers,
|
|
43
|
+
_host_index=_host_index
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
_response_types_map: Dict[str, Optional[str]] = {
|
|
47
|
+
{{#responses}}
|
|
48
|
+
{{^isWildcard}}
|
|
49
|
+
'{{code}}': {{#dataType}}"{{.}}"{{/dataType}}{{^dataType}}None{{/dataType}},
|
|
50
|
+
{{/isWildcard}}
|
|
51
|
+
{{/responses}}
|
|
52
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
(
|
|
2
|
+
self,
|
|
3
|
+
{{#allParams}}
|
|
4
|
+
{{paramName}}: {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}},
|
|
5
|
+
{{/allParams}}
|
|
6
|
+
_request_timeout: Union[
|
|
7
|
+
None,
|
|
8
|
+
Annotated[StrictFloat, Field(gt=0)],
|
|
9
|
+
Tuple[
|
|
10
|
+
Annotated[StrictFloat, Field(gt=0)],
|
|
11
|
+
Annotated[StrictFloat, Field(gt=0)]
|
|
12
|
+
]
|
|
13
|
+
] = None,
|
|
14
|
+
_request_auth: Optional[Dict[StrictStr, Any]] = None,
|
|
15
|
+
_content_type: Optional[StrictStr] = None,
|
|
16
|
+
_headers: Optional[Dict[StrictStr, Any]] = None,
|
|
17
|
+
_host_index: Annotated[StrictInt, Field(ge=0, le={{#servers.size}}{{servers.size}}{{/servers.size}}{{^servers.size}}1{{/servers.size}})] = 0,
|
|
18
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
{{#if appName}}
|
|
3
|
+
{{{appName}}}
|
|
4
|
+
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#if appDescription}}
|
|
7
|
+
{{{appDescription}}}
|
|
8
|
+
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#if version}}
|
|
11
|
+
The version of the OpenAPI document: {{{version}}}
|
|
12
|
+
{{/if}}
|
|
13
|
+
{{#if infoEmail}}
|
|
14
|
+
Contact: {{{infoEmail}}}
|
|
15
|
+
{{/if}}
|
|
16
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
17
|
+
|
|
18
|
+
Do not edit the class manually.
|
|
19
|
+
""" # noqa: E501
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
{{#poetry1}}
|
|
2
|
+
[tool.poetry]
|
|
3
|
+
{{/poetry1}}
|
|
4
|
+
{{^poetry1}}
|
|
5
|
+
[project]
|
|
6
|
+
{{/poetry1}}
|
|
7
|
+
name = "{{{packageName}}}"
|
|
8
|
+
version = "{{{packageVersion}}}"
|
|
9
|
+
description = "{{{appName}}}"
|
|
10
|
+
{{#poetry1}}
|
|
11
|
+
authors = ["{{infoName}}{{^infoName}}OpenAPI Generator Community{{/infoName}} <{{infoEmail}}{{#unless infoEmail}}team@openapitools.org{{/unless}}>"]
|
|
12
|
+
{{/poetry1}}
|
|
13
|
+
{{^poetry1}}
|
|
14
|
+
authors = [
|
|
15
|
+
{name = "{{infoName}}{{^infoName}}OpenAPI Generator Community{{/infoName}}",email = "{{infoEmail}}{{#unless infoEmail}}team@openapitools.org{{/unless}}"},
|
|
16
|
+
]
|
|
17
|
+
{{/poetry1}}
|
|
18
|
+
{{#if licenseInfo}}
|
|
19
|
+
{{#poetry1}}
|
|
20
|
+
license = "{{{licenseInfo}}}"
|
|
21
|
+
{{/poetry1}}
|
|
22
|
+
{{^poetry1}}
|
|
23
|
+
license = { text = "{{{licenseInfo}}}" }
|
|
24
|
+
{{/poetry1}}
|
|
25
|
+
{{/if}}
|
|
26
|
+
readme = "README.md"
|
|
27
|
+
{{#poetry1}}
|
|
28
|
+
repository = "https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}"
|
|
29
|
+
{{/poetry1}}
|
|
30
|
+
keywords = ["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"]
|
|
31
|
+
{{#poetry1}}
|
|
32
|
+
include = ["{{packageName}}/py.typed"]
|
|
33
|
+
|
|
34
|
+
[tool.poetry.dependencies]
|
|
35
|
+
python = "^3.9"
|
|
36
|
+
{{^async}}
|
|
37
|
+
urllib3 = ">= 2.[1].0, < 3.[0].0"
|
|
38
|
+
{{/async}}
|
|
39
|
+
python-dateutil = ">= 2.[8].2"
|
|
40
|
+
{{#asyncio}}
|
|
41
|
+
aiohttp = ">= 3.[8].4"
|
|
42
|
+
aiohttp-retry = ">= 2.[8].3"
|
|
43
|
+
{{/asyncio}}
|
|
44
|
+
{{#httpx}}
|
|
45
|
+
httpx = ">= 0.[28].1"
|
|
46
|
+
{{/httpx}}
|
|
47
|
+
{{#tornado}}
|
|
48
|
+
tornado = ">=4.2, <5"
|
|
49
|
+
{{/tornado}}
|
|
50
|
+
{{#hasHttpSignatureMethods}}
|
|
51
|
+
pem = ">= 19.[3].0"
|
|
52
|
+
pycryptodome = ">= 3.[9].0"
|
|
53
|
+
{{/hasHttpSignatureMethods}}
|
|
54
|
+
pydantic = ">= 2"
|
|
55
|
+
typing-extensions = ">= 4.[7].1"
|
|
56
|
+
{{#lazyImports}}
|
|
57
|
+
lazy-imports = ">= 1, < 2"
|
|
58
|
+
{{/lazyImports}}
|
|
59
|
+
{{/poetry1}}
|
|
60
|
+
{{^poetry1}}
|
|
61
|
+
requires-python = ">=3.9"
|
|
62
|
+
|
|
63
|
+
dependencies = [
|
|
64
|
+
{{^async}}
|
|
65
|
+
"urllib3 (>=2.[1].0,<3.[0].0)",
|
|
66
|
+
{{/async}}
|
|
67
|
+
"python-dateutil (>=2.[8].2)",
|
|
68
|
+
{{#httpx}}
|
|
69
|
+
"httpx (>=0.[28].1)",
|
|
70
|
+
{{/httpx}}
|
|
71
|
+
{{#asyncio}}
|
|
72
|
+
"aiohttp (>=3.[8].4)",
|
|
73
|
+
"aiohttp-retry (>=2.[8].3)",
|
|
74
|
+
{{/asyncio}}
|
|
75
|
+
{{#tornado}}
|
|
76
|
+
"tornado (>=4.2,<5)",
|
|
77
|
+
{{/tornado}}
|
|
78
|
+
{{#hasHttpSignatureMethods}}
|
|
79
|
+
"pem (>=19.[3].0)",
|
|
80
|
+
"pycryptodome (>=3.[9].0)",
|
|
81
|
+
{{/hasHttpSignatureMethods}}
|
|
82
|
+
"pydantic (>=2)",
|
|
83
|
+
"typing-extensions (>=4.[7].1)",
|
|
84
|
+
{{#lazyImports}}
|
|
85
|
+
"lazy-imports (>=1,<2)"
|
|
86
|
+
{{/lazyImports}}
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
[project.urls]
|
|
90
|
+
Repository = "https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}"
|
|
91
|
+
|
|
92
|
+
{{/poetry1}}
|
|
93
|
+
{{^poetry1}}
|
|
94
|
+
[tool.poetry]
|
|
95
|
+
requires-poetry = ">=2.0"
|
|
96
|
+
{{/poetry1}}
|
|
97
|
+
|
|
98
|
+
{{#poetry1}}
|
|
99
|
+
[tool.poetry.dev-dependencies]
|
|
100
|
+
{{/poetry1}}
|
|
101
|
+
{{^poetry1}}
|
|
102
|
+
[tool.poetry.group.dev.dependencies]
|
|
103
|
+
{{/poetry1}}
|
|
104
|
+
pytest = ">= 7.[2].1"
|
|
105
|
+
pytest-cov = ">= 2.[8].1"
|
|
106
|
+
tox = ">= 3.[9].0"
|
|
107
|
+
flake8 = ">= 4.[0].0"
|
|
108
|
+
types-python-dateutil = ">= 2.[8].19.14"
|
|
109
|
+
mypy = ">= 1.5"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
[build-system]
|
|
113
|
+
requires = ["setuptools"]
|
|
114
|
+
build-backend = "setuptools.build_meta"
|
|
115
|
+
|
|
116
|
+
[tool.pylint.'MESSAGES CONTROL']
|
|
117
|
+
extension-pkg-whitelist = "pydantic"
|
|
118
|
+
|
|
119
|
+
[tool.mypy]
|
|
120
|
+
files = [
|
|
121
|
+
"{{{packageName}}}",
|
|
122
|
+
#"test", # auto-generated tests
|
|
123
|
+
"tests", # hand-written tests
|
|
124
|
+
]
|
|
125
|
+
# TODO: enable "strict" once all these individual checks are passing
|
|
126
|
+
# strict = true
|
|
127
|
+
|
|
128
|
+
# List from: https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options
|
|
129
|
+
warn_unused_configs = true
|
|
130
|
+
warn_redundant_casts = true
|
|
131
|
+
warn_unused_ignores = true
|
|
132
|
+
|
|
133
|
+
## Getting these passing should be easy
|
|
134
|
+
strict_equality = true
|
|
135
|
+
extra_checks = true
|
|
136
|
+
|
|
137
|
+
## Strongly recommend enabling this one as soon as you can
|
|
138
|
+
check_untyped_defs = true
|
|
139
|
+
|
|
140
|
+
## These shouldn't be too much additional work, but may be tricky to
|
|
141
|
+
## get passing if you use a lot of untyped libraries
|
|
142
|
+
disallow_subclassing_any = true
|
|
143
|
+
disallow_untyped_decorators = true
|
|
144
|
+
disallow_any_generics = true
|
|
145
|
+
|
|
146
|
+
### These next few are various gradations of forcing use of type annotations
|
|
147
|
+
#disallow_untyped_calls = true
|
|
148
|
+
#disallow_incomplete_defs = true
|
|
149
|
+
#disallow_untyped_defs = true
|
|
150
|
+
#
|
|
151
|
+
### This one isn't too hard to get passing, but return on investment is lower
|
|
152
|
+
#no_implicit_reexport = true
|
|
153
|
+
#
|
|
154
|
+
### This one can be tricky to get passing if you use a lot of untyped libraries
|
|
155
|
+
#warn_return_any = true
|
|
156
|
+
|
|
157
|
+
[[tool.mypy.overrides]]
|
|
158
|
+
module = [
|
|
159
|
+
"{{{packageName}}}.configuration",
|
|
160
|
+
]
|
|
161
|
+
warn_unused_ignores = true
|
|
162
|
+
strict_equality = true
|
|
163
|
+
extra_checks = true
|
|
164
|
+
check_untyped_defs = true
|
|
165
|
+
disallow_subclassing_any = true
|
|
166
|
+
disallow_untyped_decorators = true
|
|
167
|
+
disallow_any_generics = true
|
|
168
|
+
disallow_untyped_calls = true
|
|
169
|
+
disallow_incomplete_defs = true
|
|
170
|
+
disallow_untyped_defs = true
|
|
171
|
+
no_implicit_reexport = true
|
|
172
|
+
warn_return_any = true
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Defining the host is optional and defaults to {{{basePath}}}
|
|
2
|
+
# See configuration.py for a list of all supported configuration parameters.
|
|
3
|
+
configuration = {{{packageName}}}.Configuration(
|
|
4
|
+
host = "{{{basePath}}}"
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
{{#hasAuthMethods}}
|
|
8
|
+
# The client must configure the authentication and authorization parameters
|
|
9
|
+
# in accordance with the API server security policy.
|
|
10
|
+
# Examples for each auth method are provided below, use the example that
|
|
11
|
+
# satisfies your auth use case.
|
|
12
|
+
{{#authMethods}}
|
|
13
|
+
{{#isBasic}}
|
|
14
|
+
{{#isBasicBasic}}
|
|
15
|
+
|
|
16
|
+
# Configure HTTP basic authorization: {{{name}}}
|
|
17
|
+
configuration = {{{packageName}}}.Configuration(
|
|
18
|
+
username = os.environ["USERNAME"],
|
|
19
|
+
password = os.environ["PASSWORD"]
|
|
20
|
+
)
|
|
21
|
+
{{/isBasicBasic}}
|
|
22
|
+
{{#isBasicBearer}}
|
|
23
|
+
|
|
24
|
+
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
|
|
25
|
+
configuration = {{{packageName}}}.Configuration(
|
|
26
|
+
access_token = os.environ["BEARER_TOKEN"]
|
|
27
|
+
)
|
|
28
|
+
{{/isBasicBearer}}
|
|
29
|
+
{{#isHttpSignature}}
|
|
30
|
+
|
|
31
|
+
# Configure HTTP message signature: {{{name}}}
|
|
32
|
+
# The HTTP Signature Header mechanism that can be used by a client to
|
|
33
|
+
# authenticate the sender of a message and ensure that particular headers
|
|
34
|
+
# have not been modified in transit.
|
|
35
|
+
#
|
|
36
|
+
# You can specify the signing key-id, private key path, signing scheme,
|
|
37
|
+
# signing algorithm, list of signed headers and signature max validity.
|
|
38
|
+
# The 'key_id' parameter is an opaque string that the API server can use
|
|
39
|
+
# to lookup the client and validate the signature.
|
|
40
|
+
# The 'private_key_path' parameter should be the path to a file that
|
|
41
|
+
# contains a DER or base-64 encoded private key.
|
|
42
|
+
# The 'private_key_passphrase' parameter is optional. Set the passphrase
|
|
43
|
+
# if the private key is encrypted.
|
|
44
|
+
# The 'signed_headers' parameter is used to specify the list of
|
|
45
|
+
# HTTP headers included when generating the signature for the message.
|
|
46
|
+
# You can specify HTTP headers that you want to protect with a cryptographic
|
|
47
|
+
# signature. Note that proxies may add, modify or remove HTTP headers
|
|
48
|
+
# for legitimate reasons, so you should only add headers that you know
|
|
49
|
+
# will not be modified. For example, if you want to protect the HTTP request
|
|
50
|
+
# body, you can specify the Digest header. In that case, the client calculates
|
|
51
|
+
# the digest of the HTTP request body and includes the digest in the message
|
|
52
|
+
# signature.
|
|
53
|
+
# The 'signature_max_validity' parameter is optional. It is configured as a
|
|
54
|
+
# duration to express when the signature ceases to be valid. The client calculates
|
|
55
|
+
# the expiration date every time it generates the cryptographic signature
|
|
56
|
+
# of an HTTP request. The API server may have its own security policy
|
|
57
|
+
# that controls the maximum validity of the signature. The client max validity
|
|
58
|
+
# must be lower than the server max validity.
|
|
59
|
+
# The time on the client and server must be synchronized, otherwise the
|
|
60
|
+
# server may reject the client signature.
|
|
61
|
+
#
|
|
62
|
+
# The client must use a combination of private key, signing scheme,
|
|
63
|
+
# signing algorithm and hash algorithm that matches the security policy of
|
|
64
|
+
# the API server.
|
|
65
|
+
#
|
|
66
|
+
# See {{{packageName}}}.signing for a list of all supported parameters.
|
|
67
|
+
from {{{packageName}}} import signing
|
|
68
|
+
import datetime
|
|
69
|
+
|
|
70
|
+
configuration = {{{packageName}}}.Configuration(
|
|
71
|
+
host = "{{{basePath}}}",
|
|
72
|
+
signing_info = {{{packageName}}}.HttpSigningConfiguration(
|
|
73
|
+
key_id = 'my-key-id',
|
|
74
|
+
private_key_path = 'private_key.pem',
|
|
75
|
+
private_key_passphrase = 'YOUR_PASSPHRASE',
|
|
76
|
+
signing_scheme = {{{packageName}}}.signing.SCHEME_HS2019,
|
|
77
|
+
signing_algorithm = {{{packageName}}}.signing.ALGORITHM_ECDSA_MODE_FIPS_186_3,
|
|
78
|
+
hash_algorithm = {{{packageName}}}.signing.SCHEME_RSA_SHA256,
|
|
79
|
+
signed_headers = [
|
|
80
|
+
{{{packageName}}}.signing.HEADER_REQUEST_TARGET,
|
|
81
|
+
{{{packageName}}}.signing.HEADER_CREATED,
|
|
82
|
+
{{{packageName}}}.signing.HEADER_EXPIRES,
|
|
83
|
+
{{{packageName}}}.signing.HEADER_HOST,
|
|
84
|
+
{{{packageName}}}.signing.HEADER_DATE,
|
|
85
|
+
{{{packageName}}}.signing.HEADER_DIGEST,
|
|
86
|
+
'Content-Type',
|
|
87
|
+
'Content-Length',
|
|
88
|
+
'User-Agent'
|
|
89
|
+
],
|
|
90
|
+
signature_max_validity = datetime.timedelta(minutes=5)
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
{{/isHttpSignature}}
|
|
94
|
+
{{/isBasic}}
|
|
95
|
+
{{#isApiKey}}
|
|
96
|
+
|
|
97
|
+
# Configure API key authorization: {{{name}}}
|
|
98
|
+
configuration.api_key['{{{name}}}'] = os.environ["API_KEY"]
|
|
99
|
+
|
|
100
|
+
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
|
101
|
+
# configuration.api_key_prefix['{{name}}'] = 'Bearer'
|
|
102
|
+
{{/isApiKey}}
|
|
103
|
+
{{#isOAuth}}
|
|
104
|
+
|
|
105
|
+
configuration.access_token = os.environ["ACCESS_TOKEN"]
|
|
106
|
+
{{/isOAuth}}
|
|
107
|
+
{{/authMethods}}
|
|
108
|
+
{{/hasAuthMethods}}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{{^async}}
|
|
2
|
+
urllib3 >= 2.[1].0, < 3.[0].0
|
|
3
|
+
{{/async}}
|
|
4
|
+
python_dateutil >= 2.[8].2
|
|
5
|
+
{{#asyncio}}
|
|
6
|
+
aiohttp >= 3.[8].4
|
|
7
|
+
aiohttp-retry >= 2.[8].3
|
|
8
|
+
{{/asyncio}}
|
|
9
|
+
{{#httpx}}
|
|
10
|
+
httpx = ">= 0.[28].1"
|
|
11
|
+
{{/httpx}}
|
|
12
|
+
{{#tornado}}
|
|
13
|
+
tornado = ">= 4.2, < 5"
|
|
14
|
+
{{/tornado}}
|
|
15
|
+
{{#hasHttpSignatureMethods}}
|
|
16
|
+
pem >= 19.[3].0
|
|
17
|
+
pycryptodome >= 3.[9].0
|
|
18
|
+
{{/hasHttpSignatureMethods}}
|
|
19
|
+
pydantic >= 2
|
|
20
|
+
typing-extensions >= 4.[7].1
|
|
21
|
+
{{#lazyImports}}
|
|
22
|
+
lazy-imports >= 1, < 2
|
|
23
|
+
{{/lazyImports}}
|