Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(json schema): support recursive BaseModels in Pydantic v1 (#1623)
Browse files Browse the repository at this point in the history
Craq authored and RobertCraigie committed Aug 8, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
jgonggrijp Julian Gonggrijp
1 parent d34a081 commit 43e10c0
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
@@ -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


2 changes: 2 additions & 0 deletions tests/lib/test_pydantic.py
Original file line number Diff line number Diff line change
@@ -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",
@@ -147,6 +148,7 @@ def test_most_types() -> None:
},
},
"required": ["column", "operator", "value"],
"additionalProperties": False,
},
"OrderBy": {
"title": "OrderBy",

0 comments on commit 43e10c0

Please sign in to comment.