Skip to content

Commit

Permalink
fix(json schema): support recursive BaseModels in Pydantic v1 (#1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
Craq authored and stainless-app[bot] committed Aug 8, 2024
1 parent a9b8aa8 commit ef859c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/openai/lib/_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def _ensure_strict_json_schema(
for def_name, def_schema in defs.items():
_ensure_strict_json_schema(def_schema, path=(*path, "$defs", def_name))

definitions = json_schema.get("definitions")
if is_dict(definitions):
for definition_name, definition_schema in definitions.items():
_ensure_strict_json_schema(definition_schema, path=(*path, "definitions", definition_name))

return json_schema


Expand Down
2 changes: 2 additions & 0 deletions tests/lib/test_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def test_most_types() -> None:
"type": "object",
"properties": {"column_name": {"title": "Column Name", "type": "string"}},
"required": ["column_name"],
"additionalProperties": False,
},
"Condition": {
"title": "Condition",
Expand All @@ -147,6 +148,7 @@ def test_most_types() -> None:
},
},
"required": ["column", "operator", "value"],
"additionalProperties": False,
},
"OrderBy": {
"title": "OrderBy",
Expand Down

0 comments on commit ef859c8

Please sign in to comment.