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
21 changes: 14 additions & 7 deletions codegen/parser/schemas/union_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ def build_union_schema(
)

types = data.type or (base_schema and base_schema.type)
can_be_object = bool(data.properties or data.allOf) and not bool(
data.anyOf or data.oneOf
)
if isinstance(types, list):
for type in types:
if type not in TYPES_MAP:
continue
types = TYPES_MAP[type]
if any(isinstance(shema, types) for shema in schemas):
schema_types = TYPES_MAP[type]
if any(isinstance(schema, schema_types) for schema in schemas):
continue
if type == "null":
schemas.append(build_none_schema(source))
Expand All @@ -109,11 +112,15 @@ def build_union_schema(
elif type == "array":
schemas.append(build_list_schema(source, class_name, base_source))
elif type == "object":
schema = build_model_schema(
source, class_name, base_source, prestore_schema=False
)
add_schema((source / "union_object").uri, schema)
schemas.append(schema)
can_be_object = True

# build the object schema finally
if can_be_object:
schema = build_model_schema(
source, class_name, base_source, prestore_schema=False
)
add_schema((source / "union_object").uri, schema)
schemas.append(schema)

if not schemas:
return AnySchema(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ ignore = [
"RUF002", # ambiguous-unicode-character-docstring
"RUF003", # ambiguous-unicode-character-comment
]
extend-safe-fixes = ["RUF036"]

[tool.ruff.lint.per-file-ignores]
"packages/githubkit-schemas-**/**" = ["E501", "PYI016", "TID", "UP007"]
Expand Down
Loading