Skip to content

Commit

Permalink
property missing reference fix
Browse files Browse the repository at this point in the history
  • Loading branch information
p1c2u committed Feb 1, 2023
1 parent 602ec11 commit a379748
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions openapi_spec_validator/validation/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def _iter_schema_errors(
if not hasattr(schema.content(), "__getitem__"):
return

schema_type = schema.getkey("type")
nested_properties = []
if "allOf" in schema:
all_of = schema / "allOf"
Expand Down Expand Up @@ -292,6 +293,14 @@ def _iter_schema_errors(
require_properties=False,
)

if "properties" in schema:
props = schema /"properties"
for _, prop_schema in props.items():
yield from self._iter_schema_errors(
prop_schema,
require_properties=False,
)

required = schema.getkey("required", [])
properties = schema.get("properties", {}).keys()
if "allOf" in schema:
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/data/v3.0/property-missing-reference.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
openapi: 3.0.0
info:
version: '1.0.0'
title: 'Some Schema'
paths: {}
components:
schemas:
SomeDataType:
type: object
properties:
id:
type: integer
prop1:
$ref: '<some-broken-uri>'
prop2:
type: string
14 changes: 14 additions & 0 deletions tests/integration/validation/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ def test_failed(self, factory, validator_v30, spec_file):
with pytest.raises(OpenAPIValidationError):
validator_v30.validate(spec, spec_url=spec_url)

@pytest.mark.parametrize(
"spec_file",
[
"property-missing-reference.yaml",
],
)
def test_ref_failed(self, factory, validator_v30, spec_file):
spec_path = self.local_test_suite_file_path(spec_file)
spec = factory.spec_from_file(spec_path)
spec_url = factory.spec_file_url(spec_path)

with pytest.raises(RefResolutionError):
validator_v30.validate(spec, spec_url=spec_url)


@pytest.mark.network
class TestRemoteOpenAPIv30Validator:
Expand Down

0 comments on commit a379748

Please sign in to comment.