diff --git a/tests/test_pydantic_v1_v2_01.py b/tests/test_pydantic_v1_v2_01.py index ae893eeb5..91f071ef1 100644 --- a/tests/test_pydantic_v1_v2_01.py +++ b/tests/test_pydantic_v1_v2_01.py @@ -222,7 +222,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/SubItem" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/SubItem"} ), @@ -263,7 +272,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/SubItem" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/SubItem"} ), @@ -304,7 +322,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Item" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/Item"} ), @@ -343,7 +370,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Item" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/Item"} ), diff --git a/tests/test_pydantic_v1_v2_list.py b/tests/test_pydantic_v1_v2_list.py index 73a50b3b4..35f0238c3 100644 --- a/tests/test_pydantic_v1_v2_list.py +++ b/tests/test_pydantic_v1_v2_list.py @@ -351,7 +351,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Item" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/Item"} ), @@ -396,7 +405,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Item" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/Item"} ), diff --git a/tests/test_pydantic_v1_v2_mixed.py b/tests/test_pydantic_v1_v2_mixed.py index cce1d873b..1f866088d 100644 --- a/tests/test_pydantic_v1_v2_mixed.py +++ b/tests/test_pydantic_v1_v2_mixed.py @@ -665,7 +665,22 @@ def test_v2_to_v1_validation_error(): assert response.json() == snapshot( { "detail": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + [ + { + "type": "missing", + "loc": ["body", "new_size"], + "msg": "Field required", + "input": {"new_title": "Missing fields"}, + }, + { + "type": "missing", + "loc": ["body", "new_sub"], + "msg": "Field required", + "input": {"new_title": "Missing fields"}, + }, + ] + ), v1=snapshot( [ { @@ -699,7 +714,14 @@ def test_v2_to_v1_nested_validation_error(): { "detail": [ pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "type": "missing", + "loc": ["body", "new_sub", "new_sub_name"], + "msg": "Field required", + "input": {"wrong_field": "value"}, + } + ), v1=snapshot( { "loc": ["body", "new_sub", "new_sub_name"], @@ -752,7 +774,22 @@ def test_v2_list_validation_error(): assert response.json() == snapshot( { "detail": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + [ + { + "type": "missing", + "loc": ["body", 1, "new_size"], + "msg": "Field required", + "input": {"new_title": "Invalid"}, + }, + { + "type": "missing", + "loc": ["body", 1, "new_sub"], + "msg": "Field required", + "input": {"new_title": "Invalid"}, + }, + ] + ), v1=snapshot( [ { @@ -804,7 +841,20 @@ def test_invalid_list_structure_v2(): assert response.json() == snapshot( { "detail": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + [ + { + "type": "list_type", + "loc": ["body"], + "msg": "Input should be a valid list", + "input": { + "new_title": "Not a list", + "new_size": 100, + "new_sub": {"new_sub_name": "Sub"}, + }, + } + ] + ), v1=snapshot( [ { @@ -835,7 +885,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Item" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/Item"} ), @@ -876,7 +935,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Item" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/Item"} ), @@ -985,7 +1053,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Item" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/Item"} ), @@ -1360,7 +1437,12 @@ def test_openapi_schema(): "new_title": {"type": "string", "title": "New Title"}, "new_size": {"type": "integer", "title": "New Size"}, "new_description": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "anyOf": [{"type": "string"}, {"type": "null"}], + "title": "New Description", + } + ), v1=snapshot( {"type": "string", "title": "New Description"} ), diff --git a/tests/test_pydantic_v1_v2_noneable.py b/tests/test_pydantic_v1_v2_noneable.py index 9e1f1fce1..137d164be 100644 --- a/tests/test_pydantic_v1_v2_noneable.py +++ b/tests/test_pydantic_v1_v2_noneable.py @@ -309,7 +309,22 @@ def test_v2_to_v1_validation_error(): assert response.json() == snapshot( { "detail": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + [ + { + "type": "missing", + "loc": ["body", "new_size"], + "msg": "Field required", + "input": {"new_title": "Missing fields"}, + }, + { + "type": "missing", + "loc": ["body", "new_sub"], + "msg": "Field required", + "input": {"new_title": "Missing fields"}, + }, + ] + ), v1=snapshot( [ { @@ -343,7 +358,14 @@ def test_v2_to_v1_nested_validation_error(): { "detail": [ pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "type": "missing", + "loc": ["body", "new_sub", "new_sub_name"], + "msg": "Field required", + "input": {"wrong_field": "value"}, + } + ), v1=snapshot( { "loc": ["body", "new_sub", "new_sub_name"], @@ -371,7 +393,14 @@ def test_v2_to_v1_type_validation_error(): { "detail": [ pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "type": "int_parsing", + "loc": ["body", "new_size"], + "msg": "Input should be a valid integer, unable to parse string as an integer", + "input": "not_a_number", + } + ), v1=snapshot( { "loc": ["body", "new_size"], @@ -451,7 +480,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Item" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/Item"} ), @@ -466,7 +504,17 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "anyOf": [ + { + "$ref": "#/components/schemas/NewItem" + }, + {"type": "null"}, + ], + "title": "Response Handle V1 Item To V2 V1 To V2 Post", + } + ), v1=snapshot( {"$ref": "#/components/schemas/NewItem"} ), @@ -495,7 +543,16 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "allOf": [ + { + "$ref": "#/components/schemas/Item" + } + ], + "title": "Data", + } + ), v1=snapshot( {"$ref": "#/components/schemas/Item"} ), @@ -510,7 +567,17 @@ def test_openapi_schema(): "content": { "application/json": { "schema": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "anyOf": [ + { + "$ref": "#/components/schemas/NewItem" + }, + {"type": "null"}, + ], + "title": "Response Handle V1 Item To V2 Filter V1 To V2 Item Filter Post", + } + ), v1=snapshot( {"$ref": "#/components/schemas/NewItem"} ), @@ -637,7 +704,12 @@ def test_openapi_schema(): "new_title": {"type": "string", "title": "New Title"}, "new_size": {"type": "integer", "title": "New Size"}, "new_description": pydantic_snapshot( - v2=snapshot(), + v2=snapshot( + { + "anyOf": [{"type": "string"}, {"type": "null"}], + "title": "New Description", + } + ), v1=snapshot( {"type": "string", "title": "New Description"} ),