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,4 +1,4 @@
from dirty_equals import IsDict
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient
from docs_src.security.tutorial005 import (
@@ -267,7 +267,11 @@ def test_openapi_schema():
"schemas": {
"User": {
"title": "User",
"required": ["username"],
"required": IsOneOf(
["username", "email", "full_name", "disabled"],
# TODO: remove when deprecating Pydantic v1
["username"],
),
"type": "object",
"properties": {
"username": {"title": "Username", "type": "string"},

View File

@@ -1,4 +1,4 @@
from dirty_equals import IsDict
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient
from docs_src.security.tutorial005_an import (
@@ -267,7 +267,11 @@ def test_openapi_schema():
"schemas": {
"User": {
"title": "User",
"required": ["username"],
"required": IsOneOf(
["username", "email", "full_name", "disabled"],
# TODO: remove when deprecating Pydantic v1
["username"],
),
"type": "object",
"properties": {
"username": {"title": "Username", "type": "string"},

View File

@@ -1,5 +1,5 @@
import pytest
from dirty_equals import IsDict
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient
from ...utils import needs_py310
@@ -295,7 +295,11 @@ def test_openapi_schema(client: TestClient):
"schemas": {
"User": {
"title": "User",
"required": ["username"],
"required": IsOneOf(
["username", "email", "full_name", "disabled"],
# TODO: remove when deprecating Pydantic v1
["username"],
),
"type": "object",
"properties": {
"username": {"title": "Username", "type": "string"},

View File

@@ -1,5 +1,5 @@
import pytest
from dirty_equals import IsDict
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient
from ...utils import needs_py39
@@ -295,7 +295,11 @@ def test_openapi_schema(client: TestClient):
"schemas": {
"User": {
"title": "User",
"required": ["username"],
"required": IsOneOf(
["username", "email", "full_name", "disabled"],
# TODO: remove when deprecating Pydantic v1
["username"],
),
"type": "object",
"properties": {
"username": {"title": "Username", "type": "string"},

View File

@@ -1,5 +1,5 @@
import pytest
from dirty_equals import IsDict
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient
from ...utils import needs_py310
@@ -295,7 +295,11 @@ def test_openapi_schema(client: TestClient):
"schemas": {
"User": {
"title": "User",
"required": ["username"],
"required": IsOneOf(
["username", "email", "full_name", "disabled"],
# TODO: remove when deprecating Pydantic v1
["username"],
),
"type": "object",
"properties": {
"username": {"title": "Username", "type": "string"},

View File

@@ -1,5 +1,5 @@
import pytest
from dirty_equals import IsDict
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient
from ...utils import needs_py39
@@ -295,7 +295,11 @@ def test_openapi_schema(client: TestClient):
"schemas": {
"User": {
"title": "User",
"required": ["username"],
"required": IsOneOf(
["username", "email", "full_name", "disabled"],
# TODO: remove when deprecating Pydantic v1
["username"],
),
"type": "object",
"properties": {
"username": {"title": "Username", "type": "string"},