Skip to content

Commit ac91417

Browse files
committed
Move to jsonschema-path
1 parent 4fac4d1 commit ac91417

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+418
-379
lines changed

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ Firstly create your specification object.
6161

6262
.. code-block:: python
6363
64-
from openapi_core import Spec
64+
from jsonschema_path import SchemaPath
6565
66-
spec = Spec.from_file_path('openapi.json')
66+
spec = SchemaPath.from_file_path('openapi.json')
6767
6868
Now you can use it to validate and unmarshal against requests and/or responses.
6969

docs/index.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ Firstly create your specification object.
4949

5050
.. code-block:: python
5151
52-
from openapi_core import Spec
52+
from jsonschema_path import SchemaPath
5353
54-
spec = Spec.from_file_path('openapi.json')
54+
spec = SchemaPath.from_file_path('openapi.json')
5555
5656
Now you can use it to validate and unmarshal your requests and/or responses.
5757

docs/integrations.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,29 @@ Django can be integrated by middleware. Add ``DjangoOpenAPIMiddleware`` to your
5454
:emphasize-lines: 6,9
5555
5656
# settings.py
57-
from openapi_core import Spec
57+
from jsonschema_path import SchemaPath
5858
5959
MIDDLEWARE = [
6060
# ...
6161
'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware',
6262
]
6363
64-
OPENAPI_SPEC = Spec.from_dict(spec_dict)
64+
OPENAPI_SPEC = SchemaPath.from_dict(spec_dict)
6565
6666
You can skip response validation process: by setting ``OPENAPI_RESPONSE_CLS`` to ``None``
6767

6868
.. code-block:: python
6969
:emphasize-lines: 10
7070
7171
# settings.py
72-
from openapi_core import Spec
72+
from jsonschema_path import SchemaPath
7373
7474
MIDDLEWARE = [
7575
# ...
7676
'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware',
7777
]
7878
79-
OPENAPI_SPEC = Spec.from_dict(spec_dict)
79+
OPENAPI_SPEC = SchemaPath.from_dict(spec_dict)
8080
OPENAPI_RESPONSE_CLS = None
8181
8282
After that you have access to unmarshal result object with all validated request data from Django view through request object.

openapi_core/casting/schemas/casters.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
from typing import Callable
44
from typing import List
55

6+
from jsonschema_path import SchemaPath
7+
68
from openapi_core.casting.schemas.datatypes import CasterCallable
79
from openapi_core.casting.schemas.exceptions import CastError
8-
from openapi_core.spec import Spec
910

1011
if TYPE_CHECKING:
1112
from openapi_core.casting.schemas.factories import SchemaCastersFactory
1213

1314

1415
class BaseSchemaCaster:
15-
def __init__(self, schema: Spec):
16+
def __init__(self, schema: SchemaPath):
1617
self.schema = schema
1718

1819
def __call__(self, value: Any) -> Any:
@@ -26,7 +27,7 @@ def cast(self, value: Any) -> Any:
2627

2728

2829
class CallableSchemaCaster(BaseSchemaCaster):
29-
def __init__(self, schema: Spec, caster_callable: CasterCallable):
30+
def __init__(self, schema: SchemaPath, caster_callable: CasterCallable):
3031
super().__init__(schema)
3132
self.caster_callable = caster_callable
3233

@@ -43,7 +44,7 @@ def cast(self, value: Any) -> Any:
4344

4445

4546
class ComplexCaster(BaseSchemaCaster):
46-
def __init__(self, schema: Spec, casters_factory: "SchemaCastersFactory"):
47+
def __init__(self, schema: SchemaPath, casters_factory: "SchemaCastersFactory"):
4748
super().__init__(schema)
4849
self.casters_factory = casters_factory
4950

openapi_core/casting/schemas/factories.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Dict
22

3+
from jsonschema_path import SchemaPath
4+
35
from openapi_core.casting.schemas.casters import ArrayCaster
46
from openapi_core.casting.schemas.casters import BaseSchemaCaster
57
from openapi_core.casting.schemas.casters import CallableSchemaCaster
68
from openapi_core.casting.schemas.casters import DummyCaster
79
from openapi_core.casting.schemas.datatypes import CasterCallable
8-
from openapi_core.spec import Spec
910
from openapi_core.util import forcebool
1011

1112

@@ -24,7 +25,7 @@ class SchemaCastersFactory:
2425
"array": ArrayCaster,
2526
}
2627

27-
def create(self, schema: Spec) -> BaseSchemaCaster:
28+
def create(self, schema: SchemaPath) -> BaseSchemaCaster:
2829
schema_type = schema.getkey("type", "any")
2930

3031
if schema_type in self.DUMMY_CASTERS:

openapi_core/contrib/falcon/middlewares.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
from falcon.request import Request
77
from falcon.response import Response
8+
from jsonschema_path import SchemaPath
89

910
from openapi_core.contrib.falcon.handlers import FalconOpenAPIErrorsHandler
1011
from openapi_core.contrib.falcon.handlers import (
1112
FalconOpenAPIValidRequestHandler,
1213
)
1314
from openapi_core.contrib.falcon.requests import FalconOpenAPIRequest
1415
from openapi_core.contrib.falcon.responses import FalconOpenAPIResponse
15-
from openapi_core.spec import Spec
1616
from openapi_core.unmarshalling.processors import UnmarshallingProcessor
1717
from openapi_core.unmarshalling.request.types import RequestUnmarshallerType
1818
from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType
@@ -28,7 +28,7 @@ class FalconOpenAPIMiddleware(UnmarshallingProcessor[Request, Response]):
2828

2929
def __init__(
3030
self,
31-
spec: Spec,
31+
spec: SchemaPath,
3232
request_unmarshaller_cls: Optional[RequestUnmarshallerType] = None,
3333
response_unmarshaller_cls: Optional[ResponseUnmarshallerType] = None,
3434
request_cls: Type[FalconOpenAPIRequest] = FalconOpenAPIRequest,
@@ -51,7 +51,7 @@ def __init__(
5151
@classmethod
5252
def from_spec(
5353
cls,
54-
spec: Spec,
54+
spec: SchemaPath,
5555
request_unmarshaller_cls: Optional[RequestUnmarshallerType] = None,
5656
response_unmarshaller_cls: Optional[ResponseUnmarshallerType] = None,
5757
request_cls: Type[FalconOpenAPIRequest] = FalconOpenAPIRequest,

openapi_core/contrib/flask/decorators.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
from flask.globals import request
99
from flask.wrappers import Request
1010
from flask.wrappers import Response
11+
from jsonschema_path import SchemaPath
1112

1213
from openapi_core.contrib.flask.handlers import FlaskOpenAPIErrorsHandler
1314
from openapi_core.contrib.flask.handlers import FlaskOpenAPIValidRequestHandler
1415
from openapi_core.contrib.flask.providers import FlaskRequestProvider
1516
from openapi_core.contrib.flask.requests import FlaskOpenAPIRequest
1617
from openapi_core.contrib.flask.responses import FlaskOpenAPIResponse
17-
from openapi_core.spec import Spec
1818
from openapi_core.unmarshalling.processors import UnmarshallingProcessor
1919
from openapi_core.unmarshalling.request.types import RequestUnmarshallerType
2020
from openapi_core.unmarshalling.response.types import ResponseUnmarshallerType
@@ -28,7 +28,7 @@ class FlaskOpenAPIViewDecorator(UnmarshallingProcessor[Request, Response]):
2828

2929
def __init__(
3030
self,
31-
spec: Spec,
31+
spec: SchemaPath,
3232
request_unmarshaller_cls: Optional[RequestUnmarshallerType] = None,
3333
response_unmarshaller_cls: Optional[ResponseUnmarshallerType] = None,
3434
request_cls: Type[FlaskOpenAPIRequest] = FlaskOpenAPIRequest,
@@ -85,7 +85,7 @@ def _validate_response(self) -> bool:
8585
@classmethod
8686
def from_spec(
8787
cls,
88-
spec: Spec,
88+
spec: SchemaPath,
8989
request_unmarshaller_cls: Optional[RequestUnmarshallerType] = None,
9090
response_unmarshaller_cls: Optional[ResponseUnmarshallerType] = None,
9191
request_cls: Type[FlaskOpenAPIRequest] = FlaskOpenAPIRequest,

openapi_core/contrib/flask/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
from typing import Any
33

44
from flask.views import MethodView
5+
from jsonschema_path import SchemaPath
56

67
from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator
78
from openapi_core.contrib.flask.handlers import FlaskOpenAPIErrorsHandler
8-
from openapi_core.spec import Spec
99

1010

1111
class FlaskOpenAPIView(MethodView):
1212
"""Brings OpenAPI specification validation and unmarshalling for views."""
1313

1414
openapi_errors_handler = FlaskOpenAPIErrorsHandler
1515

16-
def __init__(self, spec: Spec, **unmarshaller_kwargs: Any):
16+
def __init__(self, spec: SchemaPath, **unmarshaller_kwargs: Any):
1717
super().__init__()
1818

1919
self.decorator = FlaskOpenAPIViewDecorator(

openapi_core/deserializing/styles/deserializers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44
from typing import List
55
from typing import Optional
66

7+
from jsonschema_path import SchemaPath
8+
79
from openapi_core.deserializing.exceptions import DeserializeError
810
from openapi_core.deserializing.styles.datatypes import DeserializerCallable
911
from openapi_core.deserializing.styles.exceptions import (
1012
EmptyQueryParameterValue,
1113
)
1214
from openapi_core.schema.parameters import get_aslist
1315
from openapi_core.schema.parameters import get_explode
14-
from openapi_core.spec import Spec
1516

1617

1718
class CallableStyleDeserializer:
1819
def __init__(
1920
self,
20-
param_or_header: Spec,
21+
param_or_header: SchemaPath,
2122
style: str,
2223
deserializer_callable: Optional[DeserializerCallable] = None,
2324
):

openapi_core/deserializing/styles/factories.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from functools import partial
33
from typing import Dict
44

5+
from jsonschema_path import SchemaPath
6+
57
from openapi_core.deserializing.styles.datatypes import DeserializerCallable
68
from openapi_core.deserializing.styles.deserializers import (
79
CallableStyleDeserializer,
810
)
911
from openapi_core.deserializing.styles.util import split
1012
from openapi_core.schema.parameters import get_style
11-
from openapi_core.spec import Spec
1213

1314

1415
class StyleDeserializersFactory:
@@ -20,7 +21,7 @@ class StyleDeserializersFactory:
2021
"deepObject": partial(re.split, pattern=r"\[|\]"),
2122
}
2223

23-
def create(self, param_or_header: Spec) -> CallableStyleDeserializer:
24+
def create(self, param_or_header: SchemaPath) -> CallableStyleDeserializer:
2425
style = get_style(param_or_header)
2526

2627
deserialize_callable = self.STYLE_DESERIALIZERS.get(style)

openapi_core/extensions/models/factories.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@
88
from typing import Optional
99
from typing import Type
1010

11+
from jsonschema_path import SchemaPath
12+
1113
from openapi_core.extensions.models.types import Field
12-
from openapi_core.spec import Spec
1314

1415

1516
class DictFactory:
1617
base_class = dict
1718

1819
def create(
19-
self, schema: Spec, fields: Iterable[Field]
20+
self, schema: SchemaPath, fields: Iterable[Field]
2021
) -> Type[Dict[Any, Any]]:
2122
return self.base_class
2223

2324

2425
class ModelFactory(DictFactory):
2526
def create(
2627
self,
27-
schema: Spec,
28+
schema: SchemaPath,
2829
fields: Iterable[Field],
2930
) -> Type[Any]:
3031
name = schema.getkey("x-model")
@@ -37,7 +38,7 @@ def create(
3738
class ModelPathFactory(ModelFactory):
3839
def create(
3940
self,
40-
schema: Spec,
41+
schema: SchemaPath,
4142
fields: Iterable[Field],
4243
) -> Any:
4344
model_class_path = schema.getkey("x-model-path")

openapi_core/finders.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from typing import Optional
44
from typing import Type
55

6+
from jsonschema_path import SchemaPath
7+
68
from openapi_core.exceptions import SpecError
7-
from openapi_core.spec import Spec
89
from openapi_core.unmarshalling.request.types import RequestUnmarshallerType
910
from openapi_core.unmarshalling.request.types import (
1011
WebhookRequestUnmarshallerType,
@@ -42,7 +43,7 @@ class SpecFinder:
4243
def __init__(self, specs: Mapping[SpecVersion, SpecClasses]) -> None:
4344
self.specs = specs
4445

45-
def get_classes(self, spec: Spec) -> SpecClasses:
46+
def get_classes(self, spec: SchemaPath) -> SpecClasses:
4647
for v, classes in self.specs.items():
4748
if v.name in spec and spec[v.name].startswith(v.version):
4849
return classes

openapi_core/schema/parameters.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
from typing import Mapping
55
from typing import Optional
66

7+
from jsonschema_path import SchemaPath
8+
79
from openapi_core.schema.protocols import SuportsGetAll
810
from openapi_core.schema.protocols import SuportsGetList
9-
from openapi_core.spec import Spec
1011

1112

12-
def get_aslist(param_or_header: Spec) -> bool:
13+
def get_aslist(param_or_header: SchemaPath) -> bool:
1314
"""Checks if parameter/header is described as list for simpler scenarios"""
1415
# if schema is not defined it's a complex scenario
1516
if "schema" not in param_or_header:
@@ -21,7 +22,7 @@ def get_aslist(param_or_header: Spec) -> bool:
2122
return schema_type in ["array", "object"]
2223

2324

24-
def get_style(param_or_header: Spec) -> str:
25+
def get_style(param_or_header: SchemaPath) -> str:
2526
"""Checks parameter/header style for simpler scenarios"""
2627
if "style" in param_or_header:
2728
assert isinstance(param_or_header["style"], str)
@@ -34,7 +35,7 @@ def get_style(param_or_header: Spec) -> str:
3435
return "simple" if location in ["path", "header"] else "form"
3536

3637

37-
def get_explode(param_or_header: Spec) -> bool:
38+
def get_explode(param_or_header: SchemaPath) -> bool:
3839
"""Checks parameter/header explode for simpler scenarios"""
3940
if "explode" in param_or_header:
4041
assert isinstance(param_or_header["explode"], bool)

openapi_core/schema/schemas.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Any
22
from typing import Dict
33

4-
from openapi_core.spec import Spec
4+
from jsonschema_path import SchemaPath
55

66

7-
def get_properties(schema: Spec) -> Dict[str, Any]:
7+
def get_properties(schema: SchemaPath) -> Dict[str, Any]:
88
properties = schema.get("properties", {})
99
properties_dict = dict(list(properties.items()))
1010
return properties_dict

openapi_core/schema/servers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from typing import Any
22
from typing import Dict
33

4-
from openapi_core.spec import Spec
4+
from jsonschema_path import SchemaPath
55

66

77
def is_absolute(url: str) -> bool:
88
return url.startswith("//") or "://" in url
99

1010

11-
def get_server_default_variables(server: Spec) -> Dict[str, Any]:
11+
def get_server_default_variables(server: SchemaPath) -> Dict[str, Any]:
1212
if "variables" not in server:
1313
return {}
1414

@@ -19,7 +19,7 @@ def get_server_default_variables(server: Spec) -> Dict[str, Any]:
1919
return defaults
2020

2121

22-
def get_server_url(server: Spec, **variables: Any) -> str:
22+
def get_server_url(server: SchemaPath, **variables: Any) -> str:
2323
if not variables:
2424
variables = get_server_default_variables(server)
2525
assert isinstance(server["url"], str)

openapi_core/schema/specs.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from jsonschema_path import SchemaPath
2+
13
from openapi_core.schema.servers import get_server_url
2-
from openapi_core.spec import Spec
34

45

5-
def get_spec_url(spec: Spec, index: int = 0) -> str:
6+
def get_spec_url(spec: SchemaPath, index: int = 0) -> str:
67
servers = spec / "servers"
78
return get_server_url(servers / 0)

0 commit comments

Comments
 (0)