Enable Pydantic's serialization mode for responses, add support for Pydantic's computed_field, better OpenAPI for response models, proper required attributes, better generated clients (#10011)

*  Enable Pydantic's serialization mode for responses

*  Update tests with new Pydantic v2 serialization mode

*  Add a test for Pydantic v2's computed_field
This commit is contained in:
Sebastián Ramírez
2023-08-04 22:47:07 +02:00
committed by GitHub
parent d943e02232
commit 19a2c3bb54
31 changed files with 1446 additions and 256 deletions

View File

@@ -1,3 +1,4 @@
from dirty_equals import IsOneOf
from fastapi.testclient import TestClient
from docs_src.extra_models.tutorial003 import app
@@ -76,7 +77,11 @@ def test_openapi_schema():
"schemas": {
"PlaneItem": {
"title": "PlaneItem",
"required": ["description", "size"],
"required": IsOneOf(
["description", "type", "size"],
# TODO: remove when deprecating Pydantic v1
["description", "size"],
),
"type": "object",
"properties": {
"description": {"title": "Description", "type": "string"},
@@ -86,7 +91,11 @@ def test_openapi_schema():
},
"CarItem": {
"title": "CarItem",
"required": ["description"],
"required": IsOneOf(
["description", "type"],
# TODO: remove when deprecating Pydantic v1
["description"],
),
"type": "object",
"properties": {
"description": {"title": "Description", "type": "string"},

View File

@@ -1,4 +1,5 @@
import pytest
from dirty_equals import IsOneOf
from fastapi.testclient import TestClient
from ...utils import needs_py310
@@ -86,7 +87,11 @@ def test_openapi_schema(client: TestClient):
"schemas": {
"PlaneItem": {
"title": "PlaneItem",
"required": ["description", "size"],
"required": IsOneOf(
["description", "type", "size"],
# TODO: remove when deprecating Pydantic v1
["description", "size"],
),
"type": "object",
"properties": {
"description": {"title": "Description", "type": "string"},
@@ -96,7 +101,11 @@ def test_openapi_schema(client: TestClient):
},
"CarItem": {
"title": "CarItem",
"required": ["description"],
"required": IsOneOf(
["description", "type"],
# TODO: remove when deprecating Pydantic v1
["description"],
),
"type": "object",
"properties": {
"description": {"title": "Description", "type": "string"},