Skip to content

Commit dcc431c

Browse files
authored
Merge pull request #472 from p1c2u/feature/rename-unmarshal-context-to-validation-context
Rename UnmarshalContext to ValidationContext
2 parents fd0a07d + e8c681b commit dcc431c

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

docs/customizations.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Here's how you could add support for a ``usdate`` format that handles dates of t
7272
schema_unmarshallers_factory = SchemaUnmarshallersFactory(
7373
OAS30Validator,
7474
custom_formatters=custom_formatters,
75-
context=UnmarshalContext.RESPONSE,
75+
context=ValidationContext.RESPONSE,
7676
)
7777
7878
result = validate_response(

openapi_core/unmarshalling/schemas/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from openapi_schema_validator import OAS30Validator
22
from openapi_schema_validator import OAS31Validator
33

4-
from openapi_core.unmarshalling.schemas.enums import UnmarshalContext
4+
from openapi_core.unmarshalling.schemas.enums import ValidationContext
55
from openapi_core.unmarshalling.schemas.factories import (
66
SchemaUnmarshallersFactory,
77
)
@@ -16,12 +16,12 @@
1616

1717
oas30_request_schema_unmarshallers_factory = SchemaUnmarshallersFactory(
1818
OAS30Validator,
19-
context=UnmarshalContext.REQUEST,
19+
context=ValidationContext.REQUEST,
2020
)
2121

2222
oas30_response_schema_unmarshallers_factory = SchemaUnmarshallersFactory(
2323
OAS30Validator,
24-
context=UnmarshalContext.RESPONSE,
24+
context=ValidationContext.RESPONSE,
2525
)
2626

2727
oas31_schema_unmarshallers_factory = SchemaUnmarshallersFactory(

openapi_core/unmarshalling/schemas/enums.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
from enum import Enum
33

44

5-
class UnmarshalContext(Enum):
5+
class ValidationContext(Enum):
66
REQUEST = "request"
77
RESPONSE = "response"

openapi_core/unmarshalling/schemas/factories.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from openapi_core.spec import Spec
1818
from openapi_core.unmarshalling.schemas.datatypes import CustomFormattersDict
1919
from openapi_core.unmarshalling.schemas.datatypes import FormattersDict
20-
from openapi_core.unmarshalling.schemas.enums import UnmarshalContext
20+
from openapi_core.unmarshalling.schemas.enums import ValidationContext
2121
from openapi_core.unmarshalling.schemas.exceptions import (
2222
FormatterNotFoundError,
2323
)
@@ -49,15 +49,15 @@
4949
class SchemaValidatorsFactory:
5050

5151
CONTEXTS = {
52-
UnmarshalContext.REQUEST: "write",
53-
UnmarshalContext.RESPONSE: "read",
52+
ValidationContext.REQUEST: "write",
53+
ValidationContext.RESPONSE: "read",
5454
}
5555

5656
def __init__(
5757
self,
5858
schema_validator_class: Type[Validator],
5959
custom_formatters: Optional[CustomFormattersDict] = None,
60-
context: Optional[UnmarshalContext] = None,
60+
context: Optional[ValidationContext] = None,
6161
):
6262
self.schema_validator_class = schema_validator_class
6363
if custom_formatters is None:
@@ -105,7 +105,7 @@ def __init__(
105105
self,
106106
schema_validator_class: Type[Validator],
107107
custom_formatters: Optional[CustomFormattersDict] = None,
108-
context: Optional[UnmarshalContext] = None,
108+
context: Optional[ValidationContext] = None,
109109
):
110110
self.schema_validator_class = schema_validator_class
111111
if custom_formatters is None:

openapi_core/unmarshalling/schemas/unmarshallers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from openapi_core.schema.schemas import get_properties
2525
from openapi_core.spec import Spec
2626
from openapi_core.unmarshalling.schemas.datatypes import FormattersDict
27-
from openapi_core.unmarshalling.schemas.enums import UnmarshalContext
27+
from openapi_core.unmarshalling.schemas.enums import ValidationContext
2828
from openapi_core.unmarshalling.schemas.exceptions import (
2929
FormatterNotFoundError,
3030
)
@@ -273,7 +273,7 @@ def __init__(
273273
formatter: Optional[Formatter],
274274
validators_factory: "SchemaValidatorsFactory",
275275
unmarshallers_factory: "SchemaUnmarshallersFactory",
276-
context: Optional[UnmarshalContext] = None,
276+
context: Optional[ValidationContext] = None,
277277
):
278278
super().__init__(
279279
schema,
@@ -360,10 +360,10 @@ def _unmarshal_properties(
360360

361361
for prop_name, prop_schema in get_properties(self.schema).items():
362362
read_only = prop_schema.getkey("readOnly", False)
363-
if self.context == UnmarshalContext.REQUEST and read_only:
363+
if self.context == ValidationContext.REQUEST and read_only:
364364
continue
365365
write_only = prop_schema.getkey("writeOnly", False)
366-
if self.context == UnmarshalContext.RESPONSE and write_only:
366+
if self.context == ValidationContext.RESPONSE and write_only:
367367
continue
368368
try:
369369
prop_value = value[prop_name]

tests/unit/unmarshalling/test_unmarshal.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from openapi_schema_validator import OAS31Validator
1010

1111
from openapi_core.spec.paths import Spec
12-
from openapi_core.unmarshalling.schemas.enums import UnmarshalContext
12+
from openapi_core.unmarshalling.schemas.enums import ValidationContext
1313
from openapi_core.unmarshalling.schemas.exceptions import (
1414
FormatterNotFoundError,
1515
)
@@ -866,9 +866,9 @@ def test_read_only_properties(self, unmarshaller_factory):
866866
spec = Spec.from_dict(schema, validator=None)
867867

868868
# readOnly properties may be admitted in a Response context
869-
result = unmarshaller_factory(spec, context=UnmarshalContext.RESPONSE)(
870-
{"id": 10}
871-
)
869+
result = unmarshaller_factory(
870+
spec, context=ValidationContext.RESPONSE
871+
)({"id": 10})
872872

873873
assert result == {
874874
"id": 10,
@@ -889,7 +889,7 @@ def test_read_only_properties_invalid(self, unmarshaller_factory):
889889

890890
# readOnly properties are not admitted on a Request context
891891
with pytest.raises(InvalidSchemaValue):
892-
unmarshaller_factory(spec, context=UnmarshalContext.REQUEST)(
892+
unmarshaller_factory(spec, context=ValidationContext.REQUEST)(
893893
{"id": 10}
894894
)
895895

@@ -907,7 +907,7 @@ def test_write_only_properties(self, unmarshaller_factory):
907907
spec = Spec.from_dict(schema, validator=None)
908908

909909
# readOnly properties may be admitted in a Response context
910-
result = unmarshaller_factory(spec, context=UnmarshalContext.REQUEST)(
910+
result = unmarshaller_factory(spec, context=ValidationContext.REQUEST)(
911911
{"id": 10}
912912
)
913913

@@ -930,17 +930,17 @@ def test_write_only_properties_invalid(self, unmarshaller_factory):
930930

931931
# readOnly properties are not admitted on a Request context
932932
with pytest.raises(InvalidSchemaValue):
933-
unmarshaller_factory(spec, context=UnmarshalContext.RESPONSE)(
933+
unmarshaller_factory(spec, context=ValidationContext.RESPONSE)(
934934
{"id": 10}
935935
)
936936

937937
def test_additional_properties_list(self, unmarshaller_factory):
938938
schema = {"type": "object"}
939939
spec = Spec.from_dict(schema, validator=None)
940940

941-
result = unmarshaller_factory(spec, context=UnmarshalContext.RESPONSE)(
942-
{"user_ids": [1, 2, 3, 4]}
943-
)
941+
result = unmarshaller_factory(
942+
spec, context=ValidationContext.RESPONSE
943+
)({"user_ids": [1, 2, 3, 4]})
944944

945945
assert result == {
946946
"user_ids": [1, 2, 3, 4],

0 commit comments

Comments
 (0)