You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/swagger-codegen/src/main/resources/python/api.mustache
+13-13
Original file line number
Diff line number
Diff line change
@@ -100,44 +100,44 @@ class {{classname}}(object):
100
100
{{#allParams}}
101
101
{{#required}}
102
102
# verify the required parameter '{{paramName}}' is set
103
-
if ('{{paramName}}' not in params or
104
-
params['{{paramName}}'] is None):
103
+
if self.api_client.client_side_validation and ('{{paramName}}' not in params or
104
+
params['{{paramName}}'] is None): # noqa: E501
105
105
raise ValueError("Missing the required parameter `{{paramName}}` when calling `{{operationId}}`") # noqa: E501
106
106
{{/required}}
107
107
{{/allParams}}
108
108
109
109
{{#allParams}}
110
110
{{#hasValidation}}
111
111
{{#maxLength}}
112
-
if ('{{paramName}}' in params and
113
-
len(params['{{paramName}}']) > {{maxLength}}):
112
+
if self.api_client.client_side_validation and ('{{paramName}}' in params and
113
+
len(params['{{paramName}}']) > {{maxLength}}):
114
114
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501
115
115
{{/maxLength}}
116
116
{{#minLength}}
117
-
if ('{{paramName}}' in params and
118
-
len(params['{{paramName}}']) < {{minLength}}):
117
+
if self.api_client.client_side_validation and ('{{paramName}}' in params and
118
+
len(params['{{paramName}}']) < {{minLength}}):
119
119
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501
120
120
{{/minLength}}
121
121
{{#maximum}}
122
-
if '{{paramName}}' in params and params['{{paramName}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}: # noqa: E501
122
+
if self.api_client.client_side_validation and ('{{paramName}}' in params and params['{{paramName}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}): # noqa: E501
123
123
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501
124
124
{{/maximum}}
125
125
{{#minimum}}
126
-
if '{{paramName}}' in params and params['{{paramName}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}: # noqa: E501
126
+
if self.api_client.client_side_validation and ('{{paramName}}' in params and params['{{paramName}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}): # noqa: E501
127
127
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501
128
128
{{/minimum}}
129
129
{{#pattern}}
130
-
if '{{paramName}}' in params and not re.search(r'{{{vendorExtensions.x-regex}}}', params['{{paramName}}']{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}): # noqa: E501
130
+
if self.api_client.client_side_validation and ('{{paramName}}' in params and not re.search(r'{{{vendorExtensions.x-regex}}}', params['{{paramName}}']{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}})): # noqa: E501
131
131
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must conform to the pattern `{{{pattern}}}`") # noqa: E501
132
132
{{/pattern}}
133
133
{{#maxItems}}
134
-
if ('{{paramName}}' in params and
135
-
len(params['{{paramName}}']) > {{maxItems}}):
134
+
if self.api_client.client_side_validation and ('{{paramName}}' in params and
135
+
len(params['{{paramName}}']) > {{maxItems}}):
136
136
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501
137
137
{{/maxItems}}
138
138
{{#minItems}}
139
-
if ('{{paramName}}' in params and
140
-
len(params['{{paramName}}']) < {{minItems}}):
139
+
if self.api_client.client_side_validation and ('{{paramName}}' in params and
140
+
len(params['{{paramName}}']) < {{minItems}}):
141
141
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501
if (self._configuration.client_side_validation and
130
+
{{{name}}} not in allowed_values):
123
131
raise ValueError(
124
132
"Invalid value for `{{{name}}}` ({0}), must be one of {1}" # noqa: E501
125
133
.format({{{name}}}, allowed_values)
@@ -129,31 +137,38 @@ class {{classname}}(object):
129
137
{{^isEnum}}
130
138
{{#hasValidation}}
131
139
{{#maxLength}}
132
-
if {{name}} is not None and len({{name}}) > {{maxLength}}:
140
+
if (self._configuration.client_side_validation and
141
+
{{name}} is not None and len({{name}}) > {{maxLength}}):
133
142
raise ValueError("Invalid value for `{{name}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501
134
143
{{/maxLength}}
135
144
{{#minLength}}
136
-
if {{name}} is not None and len({{name}}) < {{minLength}}:
145
+
if (self._configuration.client_side_validation and
146
+
{{name}} is not None and len({{name}}) < {{minLength}}):
137
147
raise ValueError("Invalid value for `{{name}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501
138
148
{{/minLength}}
139
149
{{#maximum}}
140
-
if {{name}} is not None and {{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}: # noqa: E501
150
+
if (self._configuration.client_side_validation and
151
+
{{name}} is not None and {{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}): # noqa: E501
141
152
raise ValueError("Invalid value for `{{name}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501
142
153
{{/maximum}}
143
154
{{#minimum}}
144
-
if {{name}} is not None and {{name}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}: # noqa: E501
155
+
if (self._configuration.client_side_validation and
156
+
{{name}} is not None and {{name}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}): # noqa: E501
145
157
raise ValueError("Invalid value for `{{name}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501
146
158
{{/minimum}}
147
159
{{#pattern}}
148
-
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
160
+
if (self._configuration.client_side_validation and
161
+
{{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
149
162
raise ValueError(r"Invalid value for `{{name}}`, must be a follow pattern or equal to `{{{pattern}}}`") # noqa: E501
150
163
{{/pattern}}
151
164
{{#maxItems}}
152
-
if {{name}} is not None and len({{name}}) > {{maxItems}}:
165
+
if (self._configuration.client_side_validation and
166
+
{{name}} is not None and len({{name}}) > {{maxItems}}):
153
167
raise ValueError("Invalid value for `{{name}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501
154
168
{{/maxItems}}
155
169
{{#minItems}}
156
-
if {{name}} is not None and len({{name}}) < {{minItems}}:
170
+
if (self._configuration.client_side_validation and
171
+
{{name}} is not None and len({{name}}) < {{minItems}}):
157
172
raise ValueError("Invalid value for `{{name}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501
158
173
{{/minItems}}
159
174
{{/hasValidation}}
@@ -209,10 +224,13 @@ class {{classname}}(object):
[[Back to Model list]](../README.md#documentation-for-models)[[Back to API list]](../README.md#documentation-for-api-endpoints)[[Back to README]](../README.md)
[[Back to Model list]](../README.md#documentation-for-models)[[Back to API list]](../README.md#documentation-for-api-endpoints)[[Back to README]](../README.md)
[[Back to Model list]](../README.md#documentation-for-models)[[Back to API list]](../README.md#documentation-for-api-endpoints)[[Back to README]](../README.md)
0 commit comments