Skip to content

Commit 1773c0f

Browse files
committed
Jsonschema-path upgrade
1 parent c3c785b commit 1773c0f

File tree

4 files changed

+94
-40
lines changed

4 files changed

+94
-40
lines changed

openapi_spec_validator/validation/keywords.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ def _collect_properties(self, schema: SchemaPath) -> set[str]:
9696
def __call__(
9797
self, schema: SchemaPath, require_properties: bool = True
9898
) -> Iterator[ValidationError]:
99-
if not hasattr(schema.content(), "__getitem__"):
99+
schema_value = schema.read_value()
100+
if not hasattr(schema_value, "__getitem__"):
100101
return
101102

102103
assert self.schema_ids_registry is not None
103-
schema_id = id(schema.content())
104+
schema_id = id(schema_value)
104105
if schema_id in self.schema_ids_registry:
105106
return
106107
self.schema_ids_registry.append(schema_id)
@@ -151,8 +152,8 @@ def __call__(
151152
require_properties=False,
152153
)
153154

154-
required = schema.getkey("required", [])
155-
properties = schema.get("properties", {}).keys()
155+
required = "required" in schema and (schema / "required").read_value() or []
156+
properties = "properties" in schema and (schema / "properties").keys() or []
156157
if "allOf" in schema:
157158
extra_properties = list(
158159
set(required) - set(properties) - set(nested_properties)
@@ -166,10 +167,12 @@ def __call__(
166167
)
167168

168169
if "default" in schema:
169-
default = schema["default"]
170-
nullable = schema.get("nullable", False)
171-
if default is not None or nullable is not True:
172-
yield from self.default_validator(schema, default)
170+
default_value = (schema / "default").read_value()
171+
nullable_value = False
172+
if "nullable" in schema:
173+
nullable_value = (schema / "nullable").read_value()
174+
if default_value is not None or nullable_value is not True:
175+
yield from self.default_validator(schema, default_value)
173176

174177

175178
class SchemasValidator(KeywordValidator):
@@ -203,9 +206,9 @@ def __call__(self, parameter: SchemaPath) -> Iterator[ValidationError]:
203206

204207
if "default" in parameter:
205208
# only possible in swagger 2.0
206-
default = parameter.getkey("default")
207-
if default is not None:
208-
yield from self.default_validator(parameter, default)
209+
if "default" in parameter:
210+
default_value = (parameter / "default").read_value()
211+
yield from self.default_validator(parameter, default_value)
209212

210213

211214
class ParametersValidator(KeywordValidator):
@@ -317,15 +320,17 @@ def __call__(
317320
) -> Iterator[ValidationError]:
318321
assert self.operation_ids_registry is not None
319322

320-
operation_id = operation.getkey("operationId")
321-
if (
322-
operation_id is not None
323-
and operation_id in self.operation_ids_registry
324-
):
325-
yield DuplicateOperationIDError(
326-
f"Operation ID '{operation_id}' for '{name}' in '{url}' is not unique"
327-
)
328-
self.operation_ids_registry.append(operation_id)
323+
if "operationId" in operation:
324+
operation_id_value = (operation / "operationId").read_value()
325+
if (
326+
operation_id_value is not None
327+
and operation_id_value in self.operation_ids_registry
328+
):
329+
yield DuplicateOperationIDError(
330+
f"Operation ID '{operation_id_value}' for "
331+
f"'{name}' in '{url}' is not unique"
332+
)
333+
self.operation_ids_registry.append(operation_id_value)
329334

330335
if "responses" in operation:
331336
responses = operation / "responses"
@@ -416,8 +421,9 @@ def schemas_validator(self) -> SchemasValidator:
416421
return cast(SchemasValidator, self.registry["schemas"])
417422

418423
def __call__(self, components: SchemaPath) -> Iterator[ValidationError]:
419-
schemas = components.get("schemas", {})
420-
yield from self.schemas_validator(schemas)
424+
if "schemas" in components:
425+
schemas = components / "schemas"
426+
yield from self.schemas_validator(schemas)
421427

422428

423429
class RootValidator(KeywordValidator):

openapi_spec_validator/validation/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(
5353

5454
if isinstance(schema, SchemaPath):
5555
self.schema_path = schema
56-
self.schema = schema.contents()
56+
self.schema = schema.read_value()
5757
else:
5858
self.schema = schema
5959
self.schema_path = SchemaPath.from_dict(

poetry.lock

Lines changed: 64 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ include = [
5656
jsonschema = "^4.24.0"
5757
openapi-schema-validator = "^0.6.0"
5858
python = "^3.9.0"
59-
jsonschema-path = "^0.3.1"
59+
jsonschema-path = {version = "^0.4.0a1", allow-prereleases = true}
6060
lazy-object-proxy = "^1.7.1"
6161

6262
[tool.poetry.extras]

0 commit comments

Comments
 (0)