From aaad3c88feccb9ec5fc2f226188d7047c9f0cb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 9 Oct 2025 18:42:11 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Tweak=20tests=20for=20OpenAPI=20sch?= =?UTF-8?q?ema,=20for=20compatibility=20with=20Pydantic=20v1=20and=20v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_compat_params_v1.py | 133 ++++++++++++++++++++++++--------- 1 file changed, 98 insertions(+), 35 deletions(-) diff --git a/tests/test_compat_params_v1.py b/tests/test_compat_params_v1.py index 10adeb34f..521db3e72 100644 --- a/tests/test_compat_params_v1.py +++ b/tests/test_compat_params_v1.py @@ -7,6 +7,8 @@ from fastapi._compat.v1 import BaseModel from fastapi.testclient import TestClient from inline_snapshot import snapshot +from tests.utils import pydantic_snapshot + class Item(BaseModel): name: str @@ -571,14 +573,23 @@ def test_openapi_schema(): "required": True, "content": { "application/json": { - "schema": { - "title": "Body", - "allOf": [ + "schema": pydantic_snapshot( + v1=snapshot( { "$ref": "#/components/schemas/Body_update_item_items__item_id__put" } - ], - } + ), + v2=snapshot( + { + "title": "Body", + "allOf": [ + { + "$ref": "#/components/schemas/Body_update_item_items__item_id__put" + } + ], + } + ), + ), } }, }, @@ -783,14 +794,23 @@ def test_openapi_schema(): "requestBody": { "content": { "application/json": { - "schema": { - "allOf": [ + "schema": pydantic_snapshot( + v1=snapshot( { "$ref": "#/components/schemas/Body_create_item_embed_items_embed__post" } - ], - "title": "Body", - } + ), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Body_create_item_embed_items_embed__post" + } + ], + "title": "Body", + } + ), + ), } }, "required": True, @@ -820,14 +840,23 @@ def test_openapi_schema(): "requestBody": { "content": { "application/x-www-form-urlencoded": { - "schema": { - "allOf": [ + "schema": pydantic_snapshot( + v1=snapshot( { "$ref": "#/components/schemas/Body_submit_form_form_data__post" } - ], - "title": "Body", - } + ), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Body_submit_form_form_data__post" + } + ], + "title": "Body", + } + ), + ), } }, "required": True, @@ -857,14 +886,23 @@ def test_openapi_schema(): "requestBody": { "content": { "multipart/form-data": { - "schema": { - "allOf": [ + "schema": pydantic_snapshot( + v1=snapshot( { "$ref": "#/components/schemas/Body_upload_file_upload__post" } - ], - "title": "Body", - } + ), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Body_upload_file_upload__post" + } + ], + "title": "Body", + } + ), + ), } }, "required": True, @@ -894,14 +932,23 @@ def test_openapi_schema(): "requestBody": { "content": { "multipart/form-data": { - "schema": { - "allOf": [ + "schema": pydantic_snapshot( + v1=snapshot( { "$ref": "#/components/schemas/Body_upload_multiple_files_upload_multiple__post" } - ], - "title": "Body", - } + ), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Body_upload_multiple_files_upload_multiple__post" + } + ], + "title": "Body", + } + ), + ), } }, "required": True, @@ -928,12 +975,21 @@ def test_openapi_schema(): "components": { "schemas": { "Body_create_item_embed_items_embed__post": { - "properties": { - "item": { - "allOf": [{"$ref": "#/components/schemas/Item"}], - "title": "Item", - } - }, + "properties": pydantic_snapshot( + v1=snapshot( + {"item": {"$ref": "#/components/schemas/Item"}} + ), + v2=snapshot( + { + "item": { + "allOf": [ + {"$ref": "#/components/schemas/Item"} + ], + "title": "Item", + } + } + ), + ), "type": "object", "required": ["item"], "title": "Body_create_item_embed_items_embed__post", @@ -959,10 +1015,17 @@ def test_openapi_schema(): }, "Body_update_item_items__item_id__put": { "properties": { - "item": { - "allOf": [{"$ref": "#/components/schemas/Item"}], - "title": "Item", - }, + "item": pydantic_snapshot( + v1=snapshot({"$ref": "#/components/schemas/Item"}), + v2=snapshot( + { + "allOf": [ + {"$ref": "#/components/schemas/Item"} + ], + "title": "Item", + } + ), + ), "importance": { "type": "integer", "maximum": 10.0,