|
2 | 2 | import attr |
3 | 3 | import functools |
4 | 4 | import logging |
5 | | -from base64 import b64decode, b64encode |
6 | 5 | from collections import defaultdict |
7 | 6 | from datetime import date, datetime |
8 | 7 | from uuid import UUID |
@@ -229,6 +228,9 @@ def _unmarshal_string(self, value, custom_formatters=None, strict=True): |
229 | 228 | else: |
230 | 229 | raise InvalidSchemaValue(msg, value, self.format) |
231 | 230 | else: |
| 231 | + if self.enum and value not in self.enum: |
| 232 | + raise InvalidSchemaValue( |
| 233 | + "Value {value} not in enum choices: {type}", value, self.enum) |
232 | 234 | formatstring = self.STRING_FORMAT_CALLABLE_GETTER[schema_format] |
233 | 235 |
|
234 | 236 | try: |
@@ -278,13 +280,30 @@ def _unmarshal_any(self, value, custom_formatters=None, strict=True): |
278 | 280 | SchemaType.INTEGER, SchemaType.NUMBER, SchemaType.STRING, |
279 | 281 | ] |
280 | 282 | cast_mapping = self.get_cast_mapping() |
281 | | - for schema_type in types_resolve_order: |
282 | | - cast_callable = cast_mapping[schema_type] |
283 | | - try: |
284 | | - return cast_callable(value) |
285 | | - # @todo: remove ValueError when validation separated |
286 | | - except (OpenAPISchemaError, TypeError, ValueError): |
287 | | - continue |
| 283 | + if self.one_of: |
| 284 | + result = None |
| 285 | + for subschema in self.one_of: |
| 286 | + try: |
| 287 | + casted = subschema.cast(value, custom_formatters) |
| 288 | + except (OpenAPISchemaError, TypeError, ValueError): |
| 289 | + continue |
| 290 | + else: |
| 291 | + if result is not None: |
| 292 | + raise MultipleOneOfSchema(self.type) |
| 293 | + result = casted |
| 294 | + |
| 295 | + if result is None: |
| 296 | + raise NoOneOfSchema(self.type) |
| 297 | + |
| 298 | + return result |
| 299 | + else: |
| 300 | + for schema_type in types_resolve_order: |
| 301 | + cast_callable = cast_mapping[schema_type] |
| 302 | + try: |
| 303 | + return cast_callable(value) |
| 304 | + # @todo: remove ValueError when validation separated |
| 305 | + except (OpenAPISchemaError, TypeError, ValueError): |
| 306 | + continue |
288 | 307 |
|
289 | 308 | raise NoValidSchema(value) |
290 | 309 |
|
|
0 commit comments