Skip to content

Commit be9b815

Browse files
Craqmegamanics
authored andcommitted
fix(json schema): support recursive BaseModels in Pydantic v1 (openai#1623)
1 parent 76f00d1 commit be9b815

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Diff for: src/openai/lib/_pydantic.py

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def _ensure_strict_json_schema(
6262
for def_name, def_schema in defs.items():
6363
_ensure_strict_json_schema(def_schema, path=(*path, "$defs", def_name))
6464

65+
definitions = json_schema.get("definitions")
66+
if is_dict(definitions):
67+
for definition_name, definition_schema in definitions.items():
68+
_ensure_strict_json_schema(definition_schema, path=(*path, "definitions", definition_name))
69+
6570
return json_schema
6671

6772

Diff for: tests/lib/test_pydantic.py

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def test_most_types() -> None:
130130
"type": "object",
131131
"properties": {"column_name": {"title": "Column Name", "type": "string"}},
132132
"required": ["column_name"],
133+
"additionalProperties": False,
133134
},
134135
"Condition": {
135136
"title": "Condition",
@@ -147,6 +148,7 @@ def test_most_types() -> None:
147148
},
148149
},
149150
"required": ["column", "operator", "value"],
151+
"additionalProperties": False,
150152
},
151153
"OrderBy": {
152154
"title": "OrderBy",

0 commit comments

Comments
 (0)