|
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 ( |
| 13 | + MultiTypeUnmarshaller, |
| 14 | +) |
| 15 | +from openapi_core.unmarshalling.schemas.unmarshallers import ( |
| 16 | + ObjectReadUnmarshaller, |
| 17 | +) |
| 18 | +from openapi_core.unmarshalling.schemas.unmarshallers import ObjectUnmarshaller |
| 19 | +from openapi_core.unmarshalling.schemas.unmarshallers import ( |
| 20 | + ObjectWriteUnmarshaller, |
| 21 | +) |
| 22 | +from openapi_core.unmarshalling.schemas.unmarshallers import ( |
| 23 | + PrimitiveUnmarshaller, |
| 24 | +) |
| 25 | +from openapi_core.unmarshalling.schemas.unmarshallers import TypesUnmarshaller |
| 26 | +from openapi_core.unmarshalling.schemas.util import format_byte |
| 27 | +from openapi_core.unmarshalling.schemas.util import format_date |
| 28 | +from openapi_core.unmarshalling.schemas.util import format_uuid |
| 29 | +from openapi_core.validation.schemas import ( |
| 30 | + oas30_read_schema_validators_factory, |
| 31 | +) |
| 32 | +from openapi_core.validation.schemas import ( |
| 33 | + oas30_write_schema_validators_factory, |
| 34 | +) |
| 35 | +from openapi_core.validation.schemas import oas31_schema_validators_factory |
8 | 36 |
|
9 | 37 | __all__ = [
|
10 |
| - "oas30_request_schema_unmarshallers_factory", |
11 |
| - "oas30_response_schema_unmarshallers_factory", |
12 |
| - "oas31_request_schema_unmarshallers_factory", |
13 |
| - "oas31_response_schema_unmarshallers_factory", |
| 38 | + "oas30_format_unmarshallers", |
| 39 | + "oas31_format_unmarshallers", |
| 40 | + "oas30_write_schema_unmarshallers_factory", |
| 41 | + "oas30_read_schema_unmarshallers_factory", |
14 | 42 | "oas31_schema_unmarshallers_factory",
|
15 | 43 | ]
|
16 | 44 |
|
17 |
| -oas30_request_schema_unmarshallers_factory = SchemaUnmarshallersFactory( |
18 |
| - OAS30Validator, |
19 |
| - context=ValidationContext.REQUEST, |
| 45 | +oas30_unmarshallers_dict = OrderedDict( |
| 46 | + [ |
| 47 | + ("string", PrimitiveUnmarshaller), |
| 48 | + ("integer", PrimitiveUnmarshaller), |
| 49 | + ("number", PrimitiveUnmarshaller), |
| 50 | + ("boolean", PrimitiveUnmarshaller), |
| 51 | + ("array", ArrayUnmarshaller), |
| 52 | + ("object", ObjectUnmarshaller), |
| 53 | + ] |
| 54 | +) |
| 55 | +oas30_write_unmarshallers_dict = oas30_unmarshallers_dict.copy() |
| 56 | +oas30_write_unmarshallers_dict.update( |
| 57 | + { |
| 58 | + "object": ObjectWriteUnmarshaller, |
| 59 | + } |
| 60 | +) |
| 61 | +oas30_read_unmarshallers_dict = oas30_unmarshallers_dict.copy() |
| 62 | +oas30_read_unmarshallers_dict.update( |
| 63 | + { |
| 64 | + "object": ObjectReadUnmarshaller, |
| 65 | + } |
| 66 | +) |
| 67 | +oas31_unmarshallers_dict = oas30_unmarshallers_dict.copy() |
| 68 | +oas31_unmarshallers_dict.update( |
| 69 | + { |
| 70 | + "null": PrimitiveUnmarshaller, |
| 71 | + } |
| 72 | +) |
| 73 | + |
| 74 | +oas30_write_types_unmarshaller = TypesUnmarshaller( |
| 75 | + oas30_unmarshallers_dict, |
| 76 | + AnyUnmarshaller, |
| 77 | +) |
| 78 | +oas30_read_types_unmarshaller = TypesUnmarshaller( |
| 79 | + oas30_unmarshallers_dict, |
| 80 | + AnyUnmarshaller, |
| 81 | +) |
| 82 | +oas31_types_unmarshaller = TypesUnmarshaller( |
| 83 | + oas31_unmarshallers_dict, |
| 84 | + AnyUnmarshaller, |
| 85 | + multi=MultiTypeUnmarshaller, |
| 86 | +) |
| 87 | + |
| 88 | +oas30_format_unmarshallers = { |
| 89 | + # string compatible |
| 90 | + "date": format_date, |
| 91 | + "date-time": parse_datetime, |
| 92 | + "binary": bytes, |
| 93 | + "uuid": format_uuid, |
| 94 | + "byte": format_byte, |
| 95 | +} |
| 96 | +oas31_format_unmarshallers = oas30_format_unmarshallers |
| 97 | + |
| 98 | +oas30_write_schema_unmarshallers_factory = SchemaUnmarshallersFactory( |
| 99 | + oas30_write_schema_validators_factory, |
| 100 | + oas30_write_types_unmarshaller, |
| 101 | + format_unmarshallers=oas30_format_unmarshallers, |
20 | 102 | )
|
21 | 103 |
|
22 |
| -oas30_response_schema_unmarshallers_factory = SchemaUnmarshallersFactory( |
23 |
| - OAS30Validator, |
24 |
| - context=ValidationContext.RESPONSE, |
| 104 | +oas30_read_schema_unmarshallers_factory = SchemaUnmarshallersFactory( |
| 105 | + oas30_read_schema_validators_factory, |
| 106 | + oas30_read_types_unmarshaller, |
| 107 | + format_unmarshallers=oas30_format_unmarshallers, |
25 | 108 | )
|
26 | 109 |
|
27 | 110 | oas31_schema_unmarshallers_factory = SchemaUnmarshallersFactory(
|
28 |
| - OAS31Validator, |
| 111 | + oas31_schema_validators_factory, |
| 112 | + oas31_types_unmarshaller, |
| 113 | + format_unmarshallers=oas31_format_unmarshallers, |
29 | 114 | )
|
30 | 115 |
|
31 | 116 | # alias to v31 version (request/response are the same bcs no context needed)
|
|
0 commit comments