Skip to content

Commit b7a118f

Browse files
committed
Fix constructing an OpenAPI with both extracted and explicit schemas.
Until now, the explicit list of schemas replaced rather than expanded the extracted schemas because we were calling _handle_pydantic_schema() twice. The first time, it was mutating the schema and leaving no info that the second call would find. Solution: call _handle_pydantic_schema() only once, which is more efficient anyway.
1 parent df7e330 commit b7a118f

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

openapi_pydantic/util.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ def construct_open_api_with_schema_class(
7171
if scan_for_pydantic_schema_reference:
7272
extracted_schema_classes = _handle_pydantic_schema(new_open_api)
7373
if schema_classes:
74-
schema_classes = list(
75-
{*schema_classes, *_handle_pydantic_schema(new_open_api)}
76-
)
74+
schema_classes = list({*schema_classes, *extracted_schema_classes})
7775
else:
7876
schema_classes = extracted_schema_classes
7977

openapi_pydantic/v3/v3_0_3/util.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ def construct_open_api_with_schema_class(
142142
if scan_for_pydantic_schema_reference:
143143
extracted_schema_classes = _handle_pydantic_schema(new_open_api)
144144
if schema_classes:
145-
schema_classes = list(
146-
{*schema_classes, *_handle_pydantic_schema(new_open_api)}
147-
)
145+
schema_classes = list({*schema_classes, *extracted_schema_classes})
148146
else:
149147
schema_classes = extracted_schema_classes
150148

0 commit comments

Comments
 (0)