Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

property missing reference fix #191

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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