Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyaml/validation/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def model_schema(self, schema: core_schema.ModelSchema) -> dict[str, Any]:
subschemas = [self.generate_inner(item.__pydantic_core_schema__) for item in subclasses]

# TODO: get the schemas to work when using oneOf instead
merged: dict[str, Any] = {"anyOf": subschemas}
merged: dict[str, Any] = {"oneOf": subschemas}

for key in METADATA_KEYS:
if key in base_schema and key not in merged:
Expand Down
12 changes: 6 additions & 6 deletions tests/validation/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ def test_generate_replaces_parent_schema_with_registered_subclasses(

schema = SchemaGenerator.generate("pkg.module.Parent")

anyof = schema.get("anyOf", [])
refs = {item["$ref"] for item in anyof if "$ref" in item}
oneof = schema.get("oneOf", [])
refs = {item["$ref"] for item in oneof if "$ref" in item}
if refs:
assert "#/$defs/ChildSchemaA" in refs
assert "#/$defs/ChildSchemaB" in refs
else:
class_paths = {item["properties"]["class"]["const"] for item in anyof if "properties" in item}
class_paths = {item["properties"]["class"]["const"] for item in oneof if "properties" in item}
assert "pkg.module.ChildA" in class_paths
assert "pkg.module.ChildB" in class_paths

Expand All @@ -151,13 +151,13 @@ def test_generate_includes_real_and_virtual_subclasses(

schema = SchemaGenerator.generate("pkg.module.Parent")

anyof = schema.get("anyOf", [])
refs = {item["$ref"] for item in anyof if "$ref" in item}
oneof = schema.get("oneOf", [])
refs = {item["$ref"] for item in oneof if "$ref" in item}
if refs:
assert "#/$defs/ChildSchemaA" in refs
assert "#/$defs/VirtualChildSchema" in refs
else:
class_paths = {item["properties"]["class"]["const"] for item in anyof if "properties" in item}
class_paths = {item["properties"]["class"]["const"] for item in oneof if "properties" in item}
assert "pkg.module.ChildA" in class_paths
assert "pkg.module.VirtualChild" in class_paths

Expand Down
Loading