-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathmodel.mustache
More file actions
195 lines (175 loc) · 7.08 KB
/
model.mustache
File metadata and controls
195 lines (175 loc) · 7.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from {{modelPackage}}.base_model import Model
{{#models}}
{{#model}}
{{#pyImports}}
{{import}}
{{/pyImports}}
{{/model}}
{{/models}}
from {{packageName}} import util
{{#imports}}
{{{import}}} # noqa: E501
{{/imports}}
{{#models}}
{{#model}}
class {{classname}}(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
{{#allowableValues}}
"""
allowed enum values
"""
{{#enumVars}}
{{{name}}} = {{{value}}}{{^-last}}
{{/-last}}
{{/enumVars}}
{{/allowableValues}}
def __init__(self{{#vars}}, {{name}}={{{defaultValue}}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}): # noqa: E501
"""{{classname}} - a model defined in OpenAPI
{{#vars}}
:param {{name}}: The {{name}} of this {{classname}}. # noqa: E501
:type {{name}}: {{dataType}}
{{/vars}}
"""
self.openapi_types = {
{{#vars}}
'{{name}}': {{{dataType}}}{{^-last}},{{/-last}}
{{/vars}}
}
self.attribute_map = {
{{#vars}}
'{{name}}': '{{baseName}}'{{^-last}},{{/-last}}
{{/vars}}
}
{{#vars}}{{#-first}}
{{/-first}}
self._{{name}} = {{name}}
{{/vars}}
@classmethod
def from_dict(cls, dikt) -> '{{classname}}':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The {{name}} of this {{classname}}. # noqa: E501
:rtype: {{classname}}
"""
return util.deserialize_model(dikt, cls){{#vars}}{{#-first}}
{{/-first}}
@property
def {{name}}(self) -> {{dataType}}:
"""Gets the {{name}} of this {{classname}}.
{{#description}}
{{{.}}} # noqa: E501
{{/description}}
:return: The {{name}} of this {{classname}}.
:rtype: {{dataType}}
"""
return self._{{name}}
@{{name}}.setter
def {{name}}(self, {{name}}: {{dataType}}):
"""Sets the {{name}} of this {{classname}}.
{{#description}}
{{{.}}} # noqa: E501
{{/description}}
:param {{name}}: The {{name}} of this {{classname}}.
:type {{name}}: {{dataType}}
"""
{{#isEnum}}
{{#isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#items.isString}}"{{/items.isString}}{{{this}}}{{#items.isString}}"{{/items.isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
{{#isArray}}
if not set({{{name}}}).issubset(set(allowed_values)):
raise ValueError(
"Invalid values for `{{{name}}}` [{0}], must be a subset of [{1}]" # noqa: E501
.format(", ".join(map(str, set({{{name}}}) - set(allowed_values))), # noqa: E501
", ".join(map(str, allowed_values)))
)
{{/isArray}}
{{#isMap}}
if not set({{{name}}}.keys()).issubset(set(allowed_values)):
raise ValueError(
"Invalid keys in `{{{name}}}` [{0}], must be a subset of [{1}]" # noqa: E501
.format(", ".join(map(str, set({{{name}}}.keys()) - set(allowed_values))), # noqa: E501
", ".join(map(str, allowed_values)))
)
{{/isMap}}
{{/isContainer}}
{{^isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#isString}}"{{/isString}}{{{this}}}{{#isString}}"{{/isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
if {{{name}}} not in allowed_values:
raise ValueError(
"Invalid value for `{{{name}}}` ({0}), must be one of {1}"
.format({{{name}}}, allowed_values)
)
{{/isContainer}}
{{/isEnum}}
{{^isEnum}}
{{#required}}
if {{name}} is None:
raise ValueError("Invalid value for `{{name}}`, must not be `None`") # noqa: E501
{{/required}}
{{#hasValidation}}
{{#maxLength}}
{{#isByteArray}}
if {{name}} is not None:
import base64
try:
decoded_length = len(base64.b64decode({{name}}))
if decoded_length > {{maxLength}}:
raise ValueError("Invalid value for `{{name}}`, byte length must be less than or equal to `{{maxLength}}`") # noqa: E501
except (TypeError, ValueError, base64.binascii.Error):
# If it's not valid base64, other validation will catch it
pass
{{/isByteArray}}
{{^isByteArray}}
if {{name}} is not None and len({{name}}) > {{maxLength}}:
raise ValueError("Invalid value for `{{name}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501
{{/isByteArray}}
{{/maxLength}}
{{#minLength}}
{{#isByteArray}}
if {{name}} is not None:
import base64
try:
decoded_length = len(base64.b64decode({{name}}))
if decoded_length < {{minLength}}:
raise ValueError("Invalid value for `{{name}}`, byte length must be greater than or equal to `{{minLength}}`") # noqa: E501
except (TypeError, ValueError, base64.binascii.Error):
# If it's not valid base64, other validation will catch it
pass
{{/isByteArray}}
{{^isByteArray}}
if {{name}} is not None and len({{name}}) < {{minLength}}:
raise ValueError("Invalid value for `{{name}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501
{{/isByteArray}}
{{/minLength}}
{{#maximum}}
if {{name}} is not None and {{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}: # noqa: E501
raise ValueError("Invalid value for `{{name}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501
{{/maximum}}
{{#minimum}}
if {{name}} is not None and {{name}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}: # noqa: E501
raise ValueError("Invalid value for `{{name}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501
{{/minimum}}
{{#pattern}}
if {{name}} is not None and not re.search(r'{{{vendorExtensions.x-regex}}}', {{name}}{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}): # noqa: E501
raise ValueError(r"Invalid value for `{{name}}`, must be a follow pattern or equal to `{{{pattern}}}`") # noqa: E501
{{/pattern}}
{{#maxItems}}
if {{name}} is not None and len({{name}}) > {{maxItems}}:
raise ValueError("Invalid value for `{{name}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501
{{/maxItems}}
{{#minItems}}
if {{name}} is not None and len({{name}}) < {{minItems}}:
raise ValueError("Invalid value for `{{name}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501
{{/minItems}}
{{/hasValidation}}
{{/isEnum}}
self._{{name}} = {{name}}{{^-last}}
{{/-last}}
{{/vars}}
{{/model}}
{{/models}}