Skip to content
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
18 changes: 17 additions & 1 deletion backend/pyspur/utils/pydantic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,23 @@ def json_schema_to_model(
model_name = model_class_name

schema_defs = json_schema.get('$defs', {})
defs = {name: json_schema_to_model(definition, name) for name, definition in schema_defs.items()}
defs: Dict[str, Any] = {}
for name, definition in schema_defs.items():
if 'enum' in definition:
# Enum definitions should map to their base Python type, not a Pydantic model
base_type = definition.get('type', 'string')
if base_type == 'string':
defs[name] = str
elif base_type == 'integer':
defs[name] = int
elif base_type == 'number':
defs[name] = float
elif base_type == 'boolean':
defs[name] = bool
else:
defs[name] = Any
else:
defs[name] = json_schema_to_model(definition, name)

# Extract the field definitions from the schema properties.
field_definitions = {
Expand Down