Skip to content

fix: extract extra options recursively #391

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions openapi_spec_validator/validation/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ def __init__(self, registry: "KeywordValidatorRegistry"):
def default_validator(self) -> ValueValidator:
return cast(ValueValidator, self.registry["default"])

def _collect_properties(self, schema) -> set[str]:
"""Return *all* property names reachable from this schema."""
props: set[str] = set()

if "properties" in schema:
props.update((schema / "properties").keys())

for kw in ("allOf", "anyOf", "oneOf"):
if kw in schema:
for sub in schema / kw:
props.update(self._collect_properties(sub))

if "items" in schema:
props.update(self._collect_properties(schema / "items"))

if "not" in schema:
props.update(self._collect_properties(schema / "not"))

return props

def __call__(
self, schema: SchemaPath, require_properties: bool = True
) -> Iterator[ValidationError]:
Expand All @@ -89,15 +109,9 @@ def __call__(
if "allOf" in schema:
all_of = schema / "allOf"
for inner_schema in all_of:
yield from self(
inner_schema,
require_properties=False,
)
if "properties" not in inner_schema:
continue
inner_schema_props = inner_schema / "properties"
inner_schema_props_keys = inner_schema_props.keys()
nested_properties += list(inner_schema_props_keys)
yield from self(inner_schema, require_properties=False)
nested_properties += list(self._collect_properties(inner_schema))


if "anyOf" in schema:
any_of = schema / "anyOf"
Expand Down
Loading