|
1 |
| -from openapi_schema_validator import OAS30Validator |
2 |
| -from openapi_schema_validator import OAS31Validator |
| 1 | +from collections import OrderedDict |
| 2 | +from functools import partial |
| 3 | + |
| 4 | +from isodate.isodatetime import parse_datetime |
3 | 5 |
|
4 | 6 | from openapi_core.unmarshalling.schemas.enums import ValidationContext
|
5 | 7 | from openapi_core.unmarshalling.schemas.factories import (
|
6 | 8 | SchemaUnmarshallersFactory,
|
7 | 9 | )
|
| 10 | +from openapi_core.unmarshalling.schemas.unmarshallers import AnyUnmarshaller |
| 11 | +from openapi_core.unmarshalling.schemas.unmarshallers import ArrayUnmarshaller |
| 12 | +from openapi_core.unmarshalling.schemas.unmarshallers import FormatUnmarshaller |
| 13 | +from openapi_core.unmarshalling.schemas.unmarshallers import ( |
| 14 | + MultiTypeUnmarshaller, |
| 15 | +) |
| 16 | +from openapi_core.unmarshalling.schemas.unmarshallers import ObjectUnmarshaller |
| 17 | +from openapi_core.unmarshalling.schemas.unmarshallers import TypesUnmarshaller |
| 18 | +from openapi_core.unmarshalling.schemas.util import format_byte |
| 19 | +from openapi_core.unmarshalling.schemas.util import format_date |
| 20 | +from openapi_core.unmarshalling.schemas.util import format_uuid |
| 21 | +from openapi_core.validation.schemas import ( |
| 22 | + oas30_read_schema_validators_factory, |
| 23 | +) |
| 24 | +from openapi_core.validation.schemas import ( |
| 25 | + oas30_write_schema_validators_factory, |
| 26 | +) |
| 27 | +from openapi_core.validation.schemas import oas31_schema_validators_factory |
8 | 28 |
|
9 | 29 | __all__ = [
|
| 30 | + "oas30_format_unmarshallers", |
| 31 | + "oas31_format_unmarshallers", |
10 | 32 | "oas30_request_schema_unmarshallers_factory",
|
11 | 33 | "oas30_response_schema_unmarshallers_factory",
|
12 | 34 | "oas31_request_schema_unmarshallers_factory",
|
13 | 35 | "oas31_response_schema_unmarshallers_factory",
|
14 | 36 | "oas31_schema_unmarshallers_factory",
|
15 | 37 | ]
|
16 | 38 |
|
17 |
| -oas30_request_schema_unmarshallers_factory = SchemaUnmarshallersFactory( |
18 |
| - OAS30Validator, |
| 39 | +oas30_unmarshallers_dict = OrderedDict( |
| 40 | + [ |
| 41 | + ("string", FormatUnmarshaller), |
| 42 | + ("integer", FormatUnmarshaller), |
| 43 | + ("number", FormatUnmarshaller), |
| 44 | + ("boolean", FormatUnmarshaller), |
| 45 | + ("array", ArrayUnmarshaller), |
| 46 | + ("object", ObjectUnmarshaller), |
| 47 | + ] |
| 48 | +) |
| 49 | +oas31_unmarshallers_dict = oas30_unmarshallers_dict.copy() |
| 50 | +oas31_unmarshallers_dict.update( |
| 51 | + { |
| 52 | + "null": FormatUnmarshaller, |
| 53 | + } |
| 54 | +) |
| 55 | + |
| 56 | +oas30_types_unmarshaller = TypesUnmarshaller( |
| 57 | + oas30_unmarshallers_dict, |
| 58 | + AnyUnmarshaller, |
| 59 | +) |
| 60 | +oas31_types_unmarshaller = TypesUnmarshaller( |
| 61 | + oas31_unmarshallers_dict, |
| 62 | + AnyUnmarshaller, |
| 63 | + multi=MultiTypeUnmarshaller, |
| 64 | +) |
| 65 | + |
| 66 | +oas30_format_unmarshallers = { |
| 67 | + # string compatible |
| 68 | + "date": format_date, |
| 69 | + "date-time": parse_datetime, |
| 70 | + "binary": bytes, |
| 71 | + "uuid": format_uuid, |
| 72 | + "byte": format_byte, |
| 73 | +} |
| 74 | +oas31_format_unmarshallers = oas30_format_unmarshallers |
| 75 | + |
| 76 | +oas30_write_schema_unmarshallers_factory = SchemaUnmarshallersFactory( |
| 77 | + oas30_write_schema_validators_factory, |
| 78 | + oas30_types_unmarshaller, |
| 79 | + format_unmarshallers=oas30_format_unmarshallers, |
19 | 80 | context=ValidationContext.REQUEST,
|
20 | 81 | )
|
21 | 82 |
|
22 |
| -oas30_response_schema_unmarshallers_factory = SchemaUnmarshallersFactory( |
23 |
| - OAS30Validator, |
| 83 | +oas30_read_schema_unmarshallers_factory = SchemaUnmarshallersFactory( |
| 84 | + oas30_read_schema_validators_factory, |
| 85 | + oas30_types_unmarshaller, |
| 86 | + format_unmarshallers=oas30_format_unmarshallers, |
24 | 87 | context=ValidationContext.RESPONSE,
|
25 | 88 | )
|
26 | 89 |
|
27 | 90 | oas31_schema_unmarshallers_factory = SchemaUnmarshallersFactory(
|
28 |
| - OAS31Validator, |
| 91 | + oas31_schema_validators_factory, |
| 92 | + oas31_types_unmarshaller, |
| 93 | + format_unmarshallers=oas31_format_unmarshallers, |
29 | 94 | )
|
30 | 95 |
|
31 | 96 | # alias to v31 version (request/response are the same bcs no context needed)
|
|
0 commit comments