|
1 | 1 | """OpenAPI core validation request validators module"""
|
2 | 2 | from __future__ import division
|
3 | 3 | from itertools import chain
|
| 4 | +import warnings |
4 | 5 |
|
5 | 6 | from openapi_core.casting.schemas.exceptions import CastError
|
6 | 7 | from openapi_core.deserializing.exceptions import DeserializeError
|
@@ -160,41 +161,52 @@ def _get_parameters(self, request, params):
|
160 | 161 | continue
|
161 | 162 | seen.add((param_name, param_location))
|
162 | 163 | try:
|
163 |
| - raw_value = self._get_parameter_value(param, request) |
164 |
| - except MissingRequiredParameter as exc: |
165 |
| - errors.append(exc) |
166 |
| - continue |
| 164 | + value = self._get_parameter(param, request) |
167 | 165 | except MissingParameter:
|
168 |
| - if 'schema' not in param: |
169 |
| - continue |
170 |
| - schema = param / 'schema' |
171 |
| - if 'default' not in schema: |
172 |
| - continue |
173 |
| - casted = schema['default'] |
174 |
| - else: |
175 |
| - try: |
176 |
| - deserialised = self._deserialise_parameter( |
177 |
| - param, raw_value) |
178 |
| - except DeserializeError as exc: |
179 |
| - errors.append(exc) |
180 |
| - continue |
181 |
| - |
182 |
| - try: |
183 |
| - casted = self._cast(param, deserialised) |
184 |
| - except CastError as exc: |
185 |
| - errors.append(exc) |
186 |
| - continue |
187 |
| - |
188 |
| - try: |
189 |
| - unmarshalled = self._unmarshal(param, casted) |
190 |
| - except (ValidateError, UnmarshalError) as exc: |
| 166 | + continue |
| 167 | + except ( |
| 168 | + MissingRequiredParameter, DeserializeError, |
| 169 | + CastError, ValidateError, UnmarshalError, |
| 170 | + ) as exc: |
191 | 171 | errors.append(exc)
|
| 172 | + continue |
192 | 173 | else:
|
193 | 174 | locations.setdefault(param_location, {})
|
194 |
| - locations[param_location][param_name] = unmarshalled |
| 175 | + locations[param_location][param_name] = value |
195 | 176 |
|
196 | 177 | return RequestParameters(**locations), errors
|
197 | 178 |
|
| 179 | + def _get_parameter(self, param, request): |
| 180 | + if param.getkey('deprecated', False): |
| 181 | + warnings.warn( |
| 182 | + "{0} parameter is deprecated".format(param['name']), |
| 183 | + DeprecationWarning, |
| 184 | + ) |
| 185 | + |
| 186 | + try: |
| 187 | + raw_value = self._get_parameter_value(param, request) |
| 188 | + except MissingParameter: |
| 189 | + if 'schema' not in param: |
| 190 | + raise |
| 191 | + schema = param / 'schema' |
| 192 | + if 'default' not in schema: |
| 193 | + raise |
| 194 | + casted = schema['default'] |
| 195 | + else: |
| 196 | + # Simple scenario |
| 197 | + if 'content' not in param: |
| 198 | + deserialised = self._deserialise_parameter(param, raw_value) |
| 199 | + schema = param / 'schema' |
| 200 | + # Complex scenario |
| 201 | + else: |
| 202 | + content = param / 'content' |
| 203 | + mimetype, media_type = next(content.items()) |
| 204 | + deserialised = self._deserialise_data(mimetype, raw_value) |
| 205 | + schema = media_type / 'schema' |
| 206 | + casted = self._cast(schema, deserialised) |
| 207 | + unmarshalled = self._unmarshal(schema, casted) |
| 208 | + return unmarshalled |
| 209 | + |
198 | 210 | def _get_body(self, request, operation):
|
199 | 211 | if 'requestBody' not in operation:
|
200 | 212 | return None, []
|
@@ -224,8 +236,12 @@ def _get_body(self, request, operation):
|
224 | 236 | except CastError as exc:
|
225 | 237 | return None, [exc, ]
|
226 | 238 |
|
| 239 | + if 'schema' not in media_type: |
| 240 | + return casted, [] |
| 241 | + |
| 242 | + schema = media_type / 'schema' |
227 | 243 | try:
|
228 |
| - body = self._unmarshal(media_type, casted) |
| 244 | + body = self._unmarshal(schema, casted) |
229 | 245 | except (ValidateError, UnmarshalError) as exc:
|
230 | 246 | return None, [exc, ]
|
231 | 247 |
|
|
0 commit comments