@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,182 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from inspect import getfullargspec
|
|
3
|
+
import json
|
|
4
|
+
import pprint
|
|
5
|
+
import re # noqa: F401
|
|
6
|
+
{{#vendorExtensions.x-py-other-imports}}
|
|
7
|
+
{{{.}}}
|
|
8
|
+
{{/vendorExtensions.x-py-other-imports}}
|
|
9
|
+
{{#vendorExtensions.x-py-model-imports}}
|
|
10
|
+
{{{.}}}
|
|
11
|
+
{{/vendorExtensions.x-py-model-imports}}
|
|
12
|
+
from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict
|
|
13
|
+
from typing_extensions import Literal, Self
|
|
14
|
+
from pydantic import Field
|
|
15
|
+
|
|
16
|
+
{{#uppercase}}{{{classname}}}{{/uppercase}}_ANY_OF_SCHEMAS = [{{#anyOf}}"{{.}}"{{#unless @last}}, {{/unless}}{{/anyOf}}]
|
|
17
|
+
|
|
18
|
+
class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}):
|
|
19
|
+
"""
|
|
20
|
+
{{{description}}}{{#unless description}}{{{classname}}}{{/unless}}
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
{{#composedSchemas.anyOf}}
|
|
24
|
+
# data type: {{{dataType}}}
|
|
25
|
+
{{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
|
|
26
|
+
{{/composedSchemas.anyOf}}
|
|
27
|
+
if TYPE_CHECKING:
|
|
28
|
+
actual_instance: Optional[Union[{{#anyOf}}{{{.}}}{{#unless @last}}, {{/unless}}{{/anyOf}}]] = None
|
|
29
|
+
else:
|
|
30
|
+
actual_instance: Any = None
|
|
31
|
+
any_of_schemas: Set[str] = { {{#anyOf}}"{{.}}"{{#unless @last}}, {{/unless}}{{/anyOf}} }
|
|
32
|
+
|
|
33
|
+
model_config = {
|
|
34
|
+
"validate_assignment": True,
|
|
35
|
+
"protected_namespaces": (),
|
|
36
|
+
}
|
|
37
|
+
{{#discriminator}}
|
|
38
|
+
|
|
39
|
+
discriminator_value_class_map: Dict[str, str] = {
|
|
40
|
+
{{#children}}
|
|
41
|
+
'{{^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}}
|
|
42
|
+
{{/children}}
|
|
43
|
+
}
|
|
44
|
+
{{/discriminator}}
|
|
45
|
+
|
|
46
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
47
|
+
if args:
|
|
48
|
+
if len(args) > 1:
|
|
49
|
+
raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
|
|
50
|
+
if kwargs:
|
|
51
|
+
raise ValueError("If a position argument is used, keyword arguments cannot be used.")
|
|
52
|
+
super().__init__(actual_instance=args[0])
|
|
53
|
+
else:
|
|
54
|
+
super().__init__(**kwargs)
|
|
55
|
+
|
|
56
|
+
@field_validator('actual_instance')
|
|
57
|
+
def actual_instance_must_validate_anyof(cls, v):
|
|
58
|
+
{{#isNullable}}
|
|
59
|
+
if v is None:
|
|
60
|
+
return v
|
|
61
|
+
|
|
62
|
+
{{/isNullable}}
|
|
63
|
+
instance = {{{classname}}}.model_construct()
|
|
64
|
+
error_messages = []
|
|
65
|
+
{{#composedSchemas.anyOf}}
|
|
66
|
+
# validate data type: {{{dataType}}}
|
|
67
|
+
{{#isContainer}}
|
|
68
|
+
try:
|
|
69
|
+
instance.{{vendorExtensions.x-py-name}} = v
|
|
70
|
+
return v
|
|
71
|
+
except (ValidationError, ValueError) as e:
|
|
72
|
+
error_messages.append(str(e))
|
|
73
|
+
{{/isContainer}}
|
|
74
|
+
{{^isContainer}}
|
|
75
|
+
{{#isPrimitiveType}}
|
|
76
|
+
try:
|
|
77
|
+
instance.{{vendorExtensions.x-py-name}} = v
|
|
78
|
+
return v
|
|
79
|
+
except (ValidationError, ValueError) as e:
|
|
80
|
+
error_messages.append(str(e))
|
|
81
|
+
{{/isPrimitiveType}}
|
|
82
|
+
{{^isPrimitiveType}}
|
|
83
|
+
if not isinstance(v, {{{dataType}}}):
|
|
84
|
+
error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`")
|
|
85
|
+
else:
|
|
86
|
+
return v
|
|
87
|
+
|
|
88
|
+
{{/isPrimitiveType}}
|
|
89
|
+
{{/isContainer}}
|
|
90
|
+
{{/composedSchemas.anyOf}}
|
|
91
|
+
if error_messages:
|
|
92
|
+
# no match
|
|
93
|
+
raise ValueError("No match found when setting the actual_instance in {{{classname}}} with anyOf schemas: {{#anyOf}}{{{.}}}{{#unless @last}}, {{/unless}}{{/anyOf}}. Details: " + ", ".join(error_messages))
|
|
94
|
+
else:
|
|
95
|
+
return v
|
|
96
|
+
|
|
97
|
+
@classmethod
|
|
98
|
+
def from_dict(cls, obj: Dict[str, Any]) -> Self:
|
|
99
|
+
return cls.from_json(json.dumps(obj))
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def from_json(cls, json_str: str) -> Self:
|
|
103
|
+
"""Returns the object represented by the json string"""
|
|
104
|
+
instance = cls.model_construct()
|
|
105
|
+
{{#isNullable}}
|
|
106
|
+
if json_str is None:
|
|
107
|
+
return instance
|
|
108
|
+
|
|
109
|
+
{{/isNullable}}
|
|
110
|
+
error_messages = []
|
|
111
|
+
{{#composedSchemas.anyOf}}
|
|
112
|
+
{{#isContainer}}
|
|
113
|
+
# deserialize data into {{{dataType}}}
|
|
114
|
+
try:
|
|
115
|
+
# validation
|
|
116
|
+
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
|
|
117
|
+
# assign value to actual_instance
|
|
118
|
+
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
|
|
119
|
+
return instance
|
|
120
|
+
except (ValidationError, ValueError) as e:
|
|
121
|
+
error_messages.append(str(e))
|
|
122
|
+
{{/isContainer}}
|
|
123
|
+
{{^isContainer}}
|
|
124
|
+
{{#isPrimitiveType}}
|
|
125
|
+
# deserialize data into {{{dataType}}}
|
|
126
|
+
try:
|
|
127
|
+
# validation
|
|
128
|
+
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
|
|
129
|
+
# assign value to actual_instance
|
|
130
|
+
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
|
|
131
|
+
return instance
|
|
132
|
+
except (ValidationError, ValueError) as e:
|
|
133
|
+
error_messages.append(str(e))
|
|
134
|
+
{{/isPrimitiveType}}
|
|
135
|
+
{{^isPrimitiveType}}
|
|
136
|
+
# {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
|
|
137
|
+
try:
|
|
138
|
+
instance.actual_instance = {{{dataType}}}.from_json(json_str)
|
|
139
|
+
return instance
|
|
140
|
+
except (ValidationError, ValueError) as e:
|
|
141
|
+
error_messages.append(str(e))
|
|
142
|
+
{{/isPrimitiveType}}
|
|
143
|
+
{{/isContainer}}
|
|
144
|
+
{{/composedSchemas.anyOf}}
|
|
145
|
+
|
|
146
|
+
if error_messages:
|
|
147
|
+
# no match
|
|
148
|
+
raise ValueError("No match found when deserializing the JSON string into {{{classname}}} with anyOf schemas: {{#anyOf}}{{{.}}}{{#unless @last}}, {{/unless}}{{/anyOf}}. Details: " + ", ".join(error_messages))
|
|
149
|
+
else:
|
|
150
|
+
return instance
|
|
151
|
+
|
|
152
|
+
def to_json(self) -> str:
|
|
153
|
+
"""Returns the JSON representation of the actual instance"""
|
|
154
|
+
if self.actual_instance is None:
|
|
155
|
+
return "null"
|
|
156
|
+
|
|
157
|
+
if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json):
|
|
158
|
+
return self.actual_instance.to_json()
|
|
159
|
+
else:
|
|
160
|
+
return json.dumps(self.actual_instance)
|
|
161
|
+
|
|
162
|
+
def to_dict(self) -> Optional[Union[Dict[str, Any], {{#anyOf}}{{.}}{{#unless @last}}, {{/unless}}{{/anyOf}}]]:
|
|
163
|
+
"""Returns the dict representation of the actual instance"""
|
|
164
|
+
if self.actual_instance is None:
|
|
165
|
+
return None
|
|
166
|
+
|
|
167
|
+
if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict):
|
|
168
|
+
return self.actual_instance.to_dict()
|
|
169
|
+
else:
|
|
170
|
+
return self.actual_instance
|
|
171
|
+
|
|
172
|
+
def to_str(self) -> str:
|
|
173
|
+
"""Returns the string representation of the actual instance"""
|
|
174
|
+
return pprint.pformat(self.model_dump())
|
|
175
|
+
|
|
176
|
+
{{#vendorExtensions.x-py-postponed-model-imports.size}}
|
|
177
|
+
{{#vendorExtensions.x-py-postponed-model-imports}}
|
|
178
|
+
{{{.}}}
|
|
179
|
+
{{/vendorExtensions.x-py-postponed-model-imports}}
|
|
180
|
+
# TODO: Rewrite to not use raise_errors
|
|
181
|
+
{{classname}}.model_rebuild(raise_errors=False)
|
|
182
|
+
{{/vendorExtensions.x-py-postponed-model-imports.size}}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{{#models}}{{#model}}# {{classname}}
|
|
2
|
+
|
|
3
|
+
{{#if description}}{{&description}}
|
|
4
|
+
{{/if}}
|
|
5
|
+
|
|
6
|
+
{{^isEnum}}
|
|
7
|
+
## Properties
|
|
8
|
+
|
|
9
|
+
Name | Type | Description | Notes
|
|
10
|
+
------------ | ------------- | ------------- | -------------
|
|
11
|
+
{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#if defaultValue}}[default to {{{defaultValue}}}]{{/if}}
|
|
12
|
+
{{/vars}}
|
|
13
|
+
|
|
14
|
+
## Example
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from {{modelPackage}}.{{#snakecase}}{{classname}}{{/snakecase}} import {{classname}}
|
|
18
|
+
|
|
19
|
+
# TODO update the JSON string below
|
|
20
|
+
json = "{}"
|
|
21
|
+
# create an instance of {{classname}} from a JSON string
|
|
22
|
+
{{#snakecase}}{{classname}}{{/snakecase}}_instance = {{classname}}.from_json(json)
|
|
23
|
+
# print the JSON string representation of the object
|
|
24
|
+
print({{classname}}.to_json())
|
|
25
|
+
|
|
26
|
+
# convert the object into a dict
|
|
27
|
+
{{#snakecase}}{{classname}}{{/snakecase}}_dict = {{#snakecase}}{{classname}}{{/snakecase}}_instance.to_dict()
|
|
28
|
+
# create an instance of {{classname}} from a dict
|
|
29
|
+
{{#snakecase}}{{classname}}{{/snakecase}}_from_dict = {{classname}}.from_dict({{#snakecase}}{{classname}}{{/snakecase}}_dict)
|
|
30
|
+
```
|
|
31
|
+
{{/isEnum}}
|
|
32
|
+
{{#isEnum}}
|
|
33
|
+
## Enum
|
|
34
|
+
{{#allowableValues}}{{#enumVars}}
|
|
35
|
+
* `{{name}}` (value: `{{{value}}}`)
|
|
36
|
+
{{/enumVars}}{{/allowableValues}}
|
|
37
|
+
{{/isEnum}}
|
|
38
|
+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
|
39
|
+
|
|
40
|
+
{{/model}}{{/models}}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import json
|
|
3
|
+
from enum import Enum
|
|
4
|
+
{{#vendorExtensions.x-py-other-imports}}
|
|
5
|
+
{{{.}}}
|
|
6
|
+
{{/vendorExtensions.x-py-other-imports}}
|
|
7
|
+
from typing_extensions import Self
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class {{classname}}({{vendorExtensions.x-py-enum-type}}, Enum):
|
|
11
|
+
"""
|
|
12
|
+
{{{description}}}{{#unless description}}{{{classname}}}{{/unless}}
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
allowed enum values
|
|
17
|
+
"""
|
|
18
|
+
{{#allowableValues}}
|
|
19
|
+
{{#enumVars}}
|
|
20
|
+
{{{name}}} = {{{value}}}
|
|
21
|
+
{{/enumVars}}
|
|
22
|
+
|
|
23
|
+
@classmethod
|
|
24
|
+
def from_json(cls, json_str: str) -> Self:
|
|
25
|
+
"""Create an instance of {{classname}} from a JSON string"""
|
|
26
|
+
return cls(json.loads(json_str))
|
|
27
|
+
|
|
28
|
+
{{#if defaultValue}}
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
@classmethod
|
|
32
|
+
def _missing_value_(cls, value):
|
|
33
|
+
if value is no_arg:
|
|
34
|
+
return cls.{{{defaultValue}}}
|
|
35
|
+
{{/if}}
|
|
36
|
+
{{/allowableValues}}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import pprint
|
|
3
|
+
import re # noqa: F401
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
{{#vendorExtensions.x-py-other-imports}}
|
|
7
|
+
{{{.}}}
|
|
8
|
+
{{/vendorExtensions.x-py-other-imports}}
|
|
9
|
+
{{#vendorExtensions.x-py-model-imports}}
|
|
10
|
+
{{{.}}}
|
|
11
|
+
{{/vendorExtensions.x-py-model-imports}}
|
|
12
|
+
from typing import Optional, Set
|
|
13
|
+
from typing_extensions import Self
|
|
14
|
+
|
|
15
|
+
{{#hasChildren}}
|
|
16
|
+
{{#discriminator}}
|
|
17
|
+
{{! If this model is a super class, importlib is used. So import the necessary modules for the type here. }}
|
|
18
|
+
from typing import TYPE_CHECKING
|
|
19
|
+
if TYPE_CHECKING:
|
|
20
|
+
{{#mappedModels}}
|
|
21
|
+
from {{packageName}}.models.{{model.classFilename}} import {{modelName}}
|
|
22
|
+
{{/mappedModels}}
|
|
23
|
+
|
|
24
|
+
{{/discriminator}}
|
|
25
|
+
{{/hasChildren}}
|
|
26
|
+
class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}):
|
|
27
|
+
"""
|
|
28
|
+
{{#if description}}{{{description}}}{{/if}}{{#unless description}}{{{classname}}}{{/unless}}
|
|
29
|
+
""" # noqa: E501
|
|
30
|
+
{{#vars}}
|
|
31
|
+
{{name}}: {{{vendorExtensions.x-py-typing}}}
|
|
32
|
+
{{/vars}}
|
|
33
|
+
{{#isAdditionalPropertiesTrue}}
|
|
34
|
+
additional_properties: Dict[str, Any] = {}
|
|
35
|
+
{{/isAdditionalPropertiesTrue}}
|
|
36
|
+
__properties: ClassVar[List[str]] = [{{#allVars}}"{{baseName}}"{{#unless @last}}, {{/unless}}{{/allVars}}]
|
|
37
|
+
{{#vars}}
|
|
38
|
+
{{#vendorExtensions.x-regex}}
|
|
39
|
+
|
|
40
|
+
@field_validator('{{{name}}}')
|
|
41
|
+
def {{{name}}}_validate_regular_expression(cls, value):
|
|
42
|
+
"""Validates the regular expression"""
|
|
43
|
+
{{^required}}
|
|
44
|
+
if value is None:
|
|
45
|
+
return value
|
|
46
|
+
|
|
47
|
+
{{/required}}
|
|
48
|
+
{{#required}}
|
|
49
|
+
{{#isNullable}}
|
|
50
|
+
if value is None:
|
|
51
|
+
return value
|
|
52
|
+
|
|
53
|
+
{{/isNullable}}
|
|
54
|
+
{{/required}}
|
|
55
|
+
if not re.match(r"{{{.}}}", value{{#vendorExtensions.x-modifiers}} ,re.{{{.}}}{{/vendorExtensions.x-modifiers}}):
|
|
56
|
+
raise ValueError(r"must validate the regular expression {{{vendorExtensions.x-pattern}}}")
|
|
57
|
+
return value
|
|
58
|
+
{{/vendorExtensions.x-regex}}
|
|
59
|
+
{{#isEnum}}
|
|
60
|
+
|
|
61
|
+
@field_validator('{{{name}}}')
|
|
62
|
+
def {{{name}}}_validate_enum(cls, value):
|
|
63
|
+
"""Validates the enum"""
|
|
64
|
+
{{^required}}
|
|
65
|
+
if value is None:
|
|
66
|
+
return value
|
|
67
|
+
|
|
68
|
+
{{/required}}
|
|
69
|
+
{{#required}}
|
|
70
|
+
{{#isNullable}}
|
|
71
|
+
if value is None:
|
|
72
|
+
return value
|
|
73
|
+
|
|
74
|
+
{{/isNullable}}
|
|
75
|
+
{{/required}}
|
|
76
|
+
{{#isContainer}}
|
|
77
|
+
{{#isArray}}
|
|
78
|
+
for i in value:
|
|
79
|
+
if i not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{#unless @last}}, {{/unless}}{{/enumVars}}{{/allowableValues}}]):
|
|
80
|
+
raise ValueError("each list item must be one of ({{#allowableValues}}{{#enumVars}}{{{value}}}{{#unless @last}}, {{/unless}}{{/enumVars}}{{/allowableValues}})")
|
|
81
|
+
{{/isArray}}
|
|
82
|
+
{{#isMap}}
|
|
83
|
+
for i in value.values():
|
|
84
|
+
if i not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{#unless @last}}, {{/unless}}{{/enumVars}}{{/allowableValues}}]):
|
|
85
|
+
raise ValueError("dict values must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{#unless @last}}, {{/unless}}{{/enumVars}}{{/allowableValues}})")
|
|
86
|
+
{{/isMap}}
|
|
87
|
+
{{/isContainer}}
|
|
88
|
+
{{^isContainer}}
|
|
89
|
+
if value not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{#unless @last}}, {{/unless}}{{/enumVars}}{{/allowableValues}}]):
|
|
90
|
+
raise ValueError("must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{#unless @last}}, {{/unless}}{{/enumVars}}{{/allowableValues}})")
|
|
91
|
+
{{/isContainer}}
|
|
92
|
+
return value
|
|
93
|
+
{{/isEnum}}
|
|
94
|
+
{{/vars}}
|
|
95
|
+
|
|
96
|
+
model_config = ConfigDict(
|
|
97
|
+
populate_by_name=True,
|
|
98
|
+
validate_assignment=True,
|
|
99
|
+
protected_namespaces=(),
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
{{#hasChildren}}
|
|
104
|
+
{{#discriminator}}
|
|
105
|
+
# JSON field name that stores the object type
|
|
106
|
+
__discriminator_property_name: ClassVar[str] = '{{discriminator.propertyBaseName}}'
|
|
107
|
+
|
|
108
|
+
# discriminator mappings
|
|
109
|
+
__discriminator_value_class_map: ClassVar[Dict[str, str]] = {
|
|
110
|
+
{{#mappedModels}}'{{{mappingName}}}': '{{{modelName}}}'{{#unless @last}},{{/unless}}{{/mappedModels}}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
|
|
115
|
+
"""Returns the discriminator value (object type) of the data"""
|
|
116
|
+
discriminator_value = obj[cls.__discriminator_property_name]
|
|
117
|
+
if discriminator_value:
|
|
118
|
+
return cls.__discriminator_value_class_map.get(discriminator_value)
|
|
119
|
+
else:
|
|
120
|
+
return None
|
|
121
|
+
|
|
122
|
+
{{/discriminator}}
|
|
123
|
+
{{/hasChildren}}
|
|
124
|
+
def to_str(self) -> str:
|
|
125
|
+
"""Returns the string representation of the model using alias"""
|
|
126
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
127
|
+
|
|
128
|
+
def to_json(self) -> str:
|
|
129
|
+
"""Returns the JSON representation of the model using alias"""
|
|
130
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
131
|
+
return json.dumps(self.to_dict())
|
|
132
|
+
|
|
133
|
+
@classmethod
|
|
134
|
+
def from_json(cls, json_str: str) -> Optional[{{^hasChildren}}Self{{/hasChildren}}{{#hasChildren}}{{#discriminator}}Union[{{#mappedModels}}{{{modelName}}}{{#unless @last}}, {{/unless}}{{/mappedModels}}]{{/discriminator}}{{^discriminator}}Self{{/discriminator}}{{/hasChildren}}]:
|
|
135
|
+
"""Create an instance of {{{classname}}} from a JSON string"""
|
|
136
|
+
return cls.from_dict(json.loads(json_str))
|
|
137
|
+
|
|
138
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
139
|
+
"""Return the dictionary representation of the model using alias.
|
|
140
|
+
|
|
141
|
+
This has the following differences from calling pydantic's
|
|
142
|
+
`self.model_dump(by_alias=True)`:
|
|
143
|
+
|
|
144
|
+
* `None` is only added to the output dict for nullable fields that
|
|
145
|
+
were set at model initialization. Other fields with value `None`
|
|
146
|
+
are ignored.
|
|
147
|
+
{{#vendorExtensions.x-py-readonly}}
|
|
148
|
+
* OpenAPI `readOnly` fields are excluded.
|
|
149
|
+
{{/vendorExtensions.x-py-readonly}}
|
|
150
|
+
{{#isAdditionalPropertiesTrue}}
|
|
151
|
+
* Fields in `self.additional_properties` are added to the output dict.
|
|
152
|
+
{{/isAdditionalPropertiesTrue}}
|
|
153
|
+
"""
|
|
154
|
+
excluded_fields: Set[str] = set([
|
|
155
|
+
{{#vendorExtensions.x-py-readonly}}
|
|
156
|
+
"{{{.}}}",
|
|
157
|
+
{{/vendorExtensions.x-py-readonly}}
|
|
158
|
+
{{#isAdditionalPropertiesTrue}}
|
|
159
|
+
"additional_properties",
|
|
160
|
+
{{/isAdditionalPropertiesTrue}}
|
|
161
|
+
])
|
|
162
|
+
|
|
163
|
+
_dict = self.model_dump(
|
|
164
|
+
by_alias=True,
|
|
165
|
+
exclude=excluded_fields,
|
|
166
|
+
exclude_none=True,
|
|
167
|
+
)
|
|
168
|
+
{{#allVars}}
|
|
169
|
+
{{#isContainer}}
|
|
170
|
+
{{#isArray}}
|
|
171
|
+
{{#items.isArray}}
|
|
172
|
+
{{^items.items.isPrimitiveType}}
|
|
173
|
+
# override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list of list)
|
|
174
|
+
_items = []
|
|
175
|
+
if self.{{{name}}}:
|
|
176
|
+
for _item_{{{name}}} in self.{{{name}}}:
|
|
177
|
+
if _item_{{{name}}}:
|
|
178
|
+
_items.append(
|
|
179
|
+
[_inner_item.to_dict() for _inner_item in _item_{{{name}}} if _inner_item is not None]
|
|
180
|
+
)
|
|
181
|
+
_dict['{{{baseName}}}'] = _items
|
|
182
|
+
{{/items.items.isPrimitiveType}}
|
|
183
|
+
{{/items.isArray}}
|
|
184
|
+
{{^items.isArray}}
|
|
185
|
+
{{^items.isPrimitiveType}}
|
|
186
|
+
{{^items.isEnumOrRef}}
|
|
187
|
+
# override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list)
|
|
188
|
+
_items = []
|
|
189
|
+
if self.{{{name}}}:
|
|
190
|
+
for _item_{{{name}}} in self.{{{name}}}:
|
|
191
|
+
if _item_{{{name}}}:
|
|
192
|
+
_items.append(_item_{{{name}}}.to_dict())
|
|
193
|
+
_dict['{{{baseName}}}'] = _items
|
|
194
|
+
{{/items.isEnumOrRef}}
|
|
195
|
+
{{/items.isPrimitiveType}}
|
|
196
|
+
{{/items.isArray}}
|
|
197
|
+
{{/isArray}}
|
|
198
|
+
{{#isMap}}
|
|
199
|
+
{{#items.isArray}}
|
|
200
|
+
{{^items.items.isPrimitiveType}}
|
|
201
|
+
# override the default output from pydantic by calling `to_dict()` of each value in {{{name}}} (dict of array)
|
|
202
|
+
_field_dict_of_array = {}
|
|
203
|
+
if self.{{{name}}}:
|
|
204
|
+
for _key_{{{name}}} in self.{{{name}}}:
|
|
205
|
+
if self.{{{name}}}[_key_{{{name}}}] is not None:
|
|
206
|
+
_field_dict_of_array[_key_{{{name}}}] = [
|
|
207
|
+
_item.to_dict() for _item in self.{{{name}}}[_key_{{{name}}}]
|
|
208
|
+
]
|
|
209
|
+
_dict['{{{baseName}}}'] = _field_dict_of_array
|
|
210
|
+
{{/items.items.isPrimitiveType}}
|
|
211
|
+
{{/items.isArray}}
|
|
212
|
+
{{^items.isArray}}
|
|
213
|
+
{{^items.isPrimitiveType}}
|
|
214
|
+
{{^items.isEnumOrRef}}
|
|
215
|
+
# override the default output from pydantic by calling `to_dict()` of each value in {{{name}}} (dict)
|
|
216
|
+
_field_dict = {}
|
|
217
|
+
if self.{{{name}}}:
|
|
218
|
+
for _key_{{{name}}} in self.{{{name}}}:
|
|
219
|
+
if self.{{{name}}}[_key_{{{name}}}]:
|
|
220
|
+
_field_dict[_key_{{{name}}}] = self.{{{name}}}[_key_{{{name}}}].to_dict()
|
|
221
|
+
_dict['{{{baseName}}}'] = _field_dict
|
|
222
|
+
{{/items.isEnumOrRef}}
|
|
223
|
+
{{/items.isPrimitiveType}}
|
|
224
|
+
{{/items.isArray}}
|
|
225
|
+
{{/isMap}}
|
|
226
|
+
{{/isContainer}}
|
|
227
|
+
{{^isContainer}}
|
|
228
|
+
{{^isPrimitiveType}}
|
|
229
|
+
{{^isEnumOrRef}}
|
|
230
|
+
# override the default output from pydantic by calling `to_dict()` of {{{name}}}
|
|
231
|
+
if self.{{{name}}}:
|
|
232
|
+
_dict['{{{baseName}}}'] = self.{{{name}}}.to_dict()
|
|
233
|
+
{{/isEnumOrRef}}
|
|
234
|
+
{{/isPrimitiveType}}
|
|
235
|
+
{{/isContainer}}
|
|
236
|
+
{{/allVars}}
|
|
237
|
+
{{#isAdditionalPropertiesTrue}}
|
|
238
|
+
# puts key-value pairs in additional_properties in the top level
|
|
239
|
+
if self.additional_properties is not None:
|
|
240
|
+
for _key, _value in self.additional_properties.items():
|
|
241
|
+
_dict[_key] = _value
|
|
242
|
+
|
|
243
|
+
{{/isAdditionalPropertiesTrue}}
|
|
244
|
+
{{#allVars}}
|
|
245
|
+
{{#isNullable}}
|
|
246
|
+
# set to None if {{{name}}} (nullable) is None
|
|
247
|
+
# and model_fields_set contains the field
|
|
248
|
+
if self.{{name}} is None and "{{{name}}}" in self.model_fields_set:
|
|
249
|
+
_dict['{{{baseName}}}'] = None
|
|
250
|
+
|
|
251
|
+
{{/isNullable}}
|
|
252
|
+
{{/allVars}}
|
|
253
|
+
return _dict
|
|
254
|
+
|
|
255
|
+
{{#hasChildren}}
|
|
256
|
+
@classmethod
|
|
257
|
+
def from_dict(cls, obj: Dict[str, Any]) -> Optional[{{#discriminator}}Union[{{#mappedModels}}{{{modelName}}}{{#unless @last}}, {{/unless}}{{/mappedModels}}]{{/discriminator}}{{^discriminator}}Self{{/discriminator}}]:
|
|
258
|
+
"""Create an instance of {{{classname}}} from a dict"""
|
|
259
|
+
{{#discriminator}}
|
|
260
|
+
# look up the object type based on discriminator mapping
|
|
261
|
+
object_type = cls.get_discriminator_value(obj)
|
|
262
|
+
{{#mappedModels}}
|
|
263
|
+
if object_type == '{{{modelName}}}':
|
|
264
|
+
return import_module("{{packageName}}.models.{{model.classFilename}}").{{modelName}}.from_dict(obj)
|
|
265
|
+
{{/mappedModels}}
|
|
266
|
+
|
|
267
|
+
raise ValueError("{{{classname}}} failed to lookup discriminator value from " +
|
|
268
|
+
json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name +
|
|
269
|
+
", mapping: " + json.dumps(cls.__discriminator_value_class_map))
|
|
270
|
+
{{/discriminator}}
|
|
271
|
+
{{/hasChildren}}
|
|
272
|
+
{{^hasChildren}}
|
|
273
|
+
@classmethod
|
|
274
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
275
|
+
"""Create an instance of {{{classname}}} from a dict"""
|
|
276
|
+
if obj is None:
|
|
277
|
+
return None
|
|
278
|
+
|
|
279
|
+
if not isinstance(obj, dict):
|
|
280
|
+
return cls.model_validate(obj)
|
|
281
|
+
|
|
282
|
+
{{#disallowAdditionalPropertiesIfNotPresent}}
|
|
283
|
+
{{^isAdditionalPropertiesTrue}}
|
|
284
|
+
# raise errors for additional fields in the input
|
|
285
|
+
for _key in obj.keys():
|
|
286
|
+
if _key not in cls.__properties:
|
|
287
|
+
raise ValueError("Error due to additional fields (not defined in {{classname}}) in the input: " + _key)
|
|
288
|
+
|
|
289
|
+
{{/isAdditionalPropertiesTrue}}
|
|
290
|
+
{{/disallowAdditionalPropertiesIfNotPresent}}
|
|
291
|
+
_obj = cls.model_validate({
|
|
292
|
+
{{#allVars}}
|
|
293
|
+
{{#isContainer}}
|
|
294
|
+
{{#isArray}}
|
|
295
|
+
{{#items.isArray}}
|
|
296
|
+
{{#items.items.isPrimitiveType}}
|
|
297
|
+
"{{{baseName}}}": obj.get("{{{baseName}}}"){{#unless @last}},{{/unless}}
|
|
298
|
+
{{/items.items.isPrimitiveType}}
|
|
299
|
+
{{^items.items.isPrimitiveType}}
|
|
300
|
+
"{{{baseName}}}": [
|
|
301
|
+
[{{{items.items.dataType}}}.from_dict(_inner_item) for _inner_item in _item]
|
|
302
|
+
for _item in obj["{{{baseName}}}"]
|
|
303
|
+
] if obj.get("{{{baseName}}}") is not None else None{{#unless @last}},{{/unless}}
|
|
304
|
+
{{/items.items.isPrimitiveType}}
|
|
305
|
+
{{/items.isArray}}
|
|
306
|
+
{{^items.isArray}}
|
|
307
|
+
{{^items.isPrimitiveType}}
|
|
308
|
+
{{#items.isEnumOrRef}}
|
|
309
|
+
"{{{baseName}}}": obj.get("{{{baseName}}}"){{#unless @last}},{{/unless}}
|
|
310
|
+
{{/items.isEnumOrRef}}
|
|
311
|
+
{{^items.isEnumOrRef}}
|
|
312
|
+
"{{{baseName}}}": [{{{items.dataType}}}.from_dict(_item) for _item in obj["{{{baseName}}}"]] if obj.get("{{{baseName}}}") is not None else None{{#unless @last}},{{/unless}}
|
|
313
|
+
{{/items.isEnumOrRef}}
|
|
314
|
+
{{/items.isPrimitiveType}}
|
|
315
|
+
{{#items.isPrimitiveType}}
|
|
316
|
+
"{{{baseName}}}": obj.get("{{{baseName}}}"){{#unless @last}},{{/unless}}
|
|
317
|
+
{{/items.isPrimitiveType}}
|
|
318
|
+
{{/items.isArray}}
|
|
319
|
+
{{/isArray}}
|
|
320
|
+
{{#isMap}}
|
|
321
|
+
{{^items.isPrimitiveType}}
|
|
322
|
+
{{^items.isEnumOrRef}}
|
|
323
|
+
{{#items.isContainer}}
|
|
324
|
+
{{#items.isMap}}
|
|
325
|
+
"{{{baseName}}}": dict(
|
|
326
|
+
(_k, dict(
|
|
327
|
+
(_ik, {{{items.items.dataType}}}.from_dict(_iv))
|
|
328
|
+
for _ik, _iv in _v.items()
|
|
329
|
+
)
|
|
330
|
+
if _v is not None
|
|
331
|
+
else None
|
|
332
|
+
)
|
|
333
|
+
for _k, _v in obj.get("{{{baseName}}}").items()
|
|
334
|
+
)
|
|
335
|
+
if obj.get("{{{baseName}}}") is not None
|
|
336
|
+
else None{{#unless @last}},{{/unless}}
|
|
337
|
+
{{/items.isMap}}
|
|
338
|
+
{{#items.isArray}}
|
|
339
|
+
"{{{baseName}}}": dict(
|
|
340
|
+
(_k,
|
|
341
|
+
[{{{items.items.dataType}}}.from_dict(_item) for _item in _v]
|
|
342
|
+
if _v is not None
|
|
343
|
+
else None
|
|
344
|
+
)
|
|
345
|
+
for _k, _v in obj.get("{{{baseName}}}", {}).items()
|
|
346
|
+
){{#unless @last}},{{/unless}}
|
|
347
|
+
{{/items.isArray}}
|
|
348
|
+
{{/items.isContainer}}
|
|
349
|
+
{{^items.isContainer}}
|
|
350
|
+
"{{{baseName}}}": dict(
|
|
351
|
+
(_k, {{{items.dataType}}}.from_dict(_v))
|
|
352
|
+
for _k, _v in obj["{{{baseName}}}"].items()
|
|
353
|
+
)
|
|
354
|
+
if obj.get("{{{baseName}}}") is not None
|
|
355
|
+
else None{{#unless @last}},{{/unless}}
|
|
356
|
+
{{/items.isContainer}}
|
|
357
|
+
{{/items.isEnumOrRef}}
|
|
358
|
+
{{#items.isEnumOrRef}}
|
|
359
|
+
"{{{baseName}}}": dict((_k, _v) for _k, _v in obj.get("{{{baseName}}}").items()) if obj.get("{{{baseName}}}") is not None else None{{#unless @last}},{{/unless}}
|
|
360
|
+
{{/items.isEnumOrRef}}
|
|
361
|
+
{{/items.isPrimitiveType}}
|
|
362
|
+
{{#items.isPrimitiveType}}
|
|
363
|
+
"{{{baseName}}}": obj.get("{{{baseName}}}"){{#unless @last}},{{/unless}}
|
|
364
|
+
{{/items.isPrimitiveType}}
|
|
365
|
+
{{/isMap}}
|
|
366
|
+
{{/isContainer}}
|
|
367
|
+
{{^isContainer}}
|
|
368
|
+
{{^isPrimitiveType}}
|
|
369
|
+
{{^isEnumOrRef}}
|
|
370
|
+
"{{{baseName}}}": {{{dataType}}}.from_dict(obj["{{{baseName}}}"]) if obj.get("{{{baseName}}}") is not None else None{{#unless @last}},{{/unless}}
|
|
371
|
+
{{/isEnumOrRef}}
|
|
372
|
+
{{#isEnumOrRef}}
|
|
373
|
+
"{{{baseName}}}": obj.get("{{{baseName}}}"){{#if defaultValue}} if obj.get("{{baseName}}") is not None else {{{defaultValue}}}{{/if}}{{#unless @last}},{{/unless}}
|
|
374
|
+
{{/isEnumOrRef}}
|
|
375
|
+
{{/isPrimitiveType}}
|
|
376
|
+
{{#isPrimitiveType}}
|
|
377
|
+
{{#if defaultValue}}
|
|
378
|
+
"{{{baseName}}}": obj.get("{{{baseName}}}") if obj.get("{{{baseName}}}") is not None else {{{defaultValue}}}{{#unless @last}},{{/unless}}
|
|
379
|
+
{{/if}}
|
|
380
|
+
{{#unless defaultValue}}
|
|
381
|
+
"{{{baseName}}}": obj.get("{{{baseName}}}"){{#unless @last}},{{/unless}}
|
|
382
|
+
{{/unless}}
|
|
383
|
+
{{/isPrimitiveType}}
|
|
384
|
+
{{/isContainer}}
|
|
385
|
+
{{/allVars}}
|
|
386
|
+
})
|
|
387
|
+
{{#isAdditionalPropertiesTrue}}
|
|
388
|
+
# store additional fields in additional_properties
|
|
389
|
+
for _key in obj.keys():
|
|
390
|
+
if _key not in cls.__properties:
|
|
391
|
+
_obj.additional_properties[_key] = obj.get(_key)
|
|
392
|
+
|
|
393
|
+
{{/isAdditionalPropertiesTrue}}
|
|
394
|
+
return _obj
|
|
395
|
+
{{/hasChildren}}
|
|
396
|
+
|
|
397
|
+
{{#vendorExtensions.x-py-postponed-model-imports.size}}
|
|
398
|
+
{{#vendorExtensions.x-py-postponed-model-imports}}
|
|
399
|
+
{{{.}}}
|
|
400
|
+
{{/vendorExtensions.x-py-postponed-model-imports}}
|
|
401
|
+
# TODO: Rewrite to not use raise_errors
|
|
402
|
+
{{classname}}.model_rebuild(raise_errors=False)
|
|
403
|
+
{{/vendorExtensions.x-py-postponed-model-imports.size}}
|