diff --git a/docs/de/docs/tutorial/schema-extra-example.md b/docs/de/docs/tutorial/schema-extra-example.md index e2ffed292..3890f4898 100644 --- a/docs/de/docs/tutorial/schema-extra-example.md +++ b/docs/de/docs/tutorial/schema-extra-example.md @@ -10,13 +10,13 @@ Sie können `examples` („Beispiele“) für ein Pydantic-Modell deklarieren, w //// tab | Pydantic v2 -{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[13:24] *} +{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[14:26] *} //// //// tab | Pydantic v1 -{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[13:23] *} +{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[14:25] *} //// @@ -60,7 +60,7 @@ Mehr erfahren Sie am Ende dieser Seite. Wenn Sie `Field()` mit Pydantic-Modellen verwenden, können Sie ebenfalls zusätzliche `examples` deklarieren: -{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:11] *} +{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:12] *} ## `examples` im JSON-Schema – OpenAPI { #examples-in-json-schema-openapi } @@ -80,19 +80,19 @@ können Sie auch eine Gruppe von `examples` mit zusätzlichen Informationen dekl Hier übergeben wir `examples`, welches ein einzelnes Beispiel für die in `Body()` erwarteten Daten enthält: -{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[22:29] *} +{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[23:31] *} ### Beispiel in der Dokumentations-Benutzeroberfläche { #example-in-the-docs-ui } Mit jeder der oben genannten Methoden würde es in `/docs` so aussehen: - + ### `Body` mit mehreren `examples` { #body-with-multiple-examples } Sie können natürlich auch mehrere `examples` übergeben: -{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[23:38] *} +{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[24:40] *} Wenn Sie das tun, werden die Beispiele Teil des internen **JSON-Schemas** für diese Body-Daten. @@ -133,13 +133,13 @@ Jedes spezifische Beispiel-`dict` in den `examples` kann Folgendes enthalten: Sie können es so verwenden: -{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[23:49] *} +{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[24:51] *} ### OpenAPI-Beispiele in der Dokumentations-Benutzeroberfläche { #openapi-examples-in-the-docs-ui } Wenn `openapi_examples` zu `Body()` hinzugefügt wird, würde `/docs` so aussehen: - + ## Technische Details { #technical-details } diff --git a/docs/en/docs/img/tutorial/schema-extra-example/image01.png b/docs/en/docs/img/tutorial/schema-extra-example/image01.png new file mode 100644 index 000000000..3b6d982dc Binary files /dev/null and b/docs/en/docs/img/tutorial/schema-extra-example/image01.png differ diff --git a/docs/en/docs/img/tutorial/schema-extra-example/image02.png b/docs/en/docs/img/tutorial/schema-extra-example/image02.png new file mode 100644 index 000000000..b12e7827d Binary files /dev/null and b/docs/en/docs/img/tutorial/schema-extra-example/image02.png differ diff --git a/docs/en/docs/tutorial/schema-extra-example.md b/docs/en/docs/tutorial/schema-extra-example.md index f3ddaf369..fb9ea278d 100644 --- a/docs/en/docs/tutorial/schema-extra-example.md +++ b/docs/en/docs/tutorial/schema-extra-example.md @@ -10,13 +10,13 @@ You can declare `examples` for a Pydantic model that will be added to the genera //// tab | Pydantic v2 -{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[13:24] *} +{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[14:26] *} //// //// tab | Pydantic v1 -{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[13:23] *} +{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[14:25] *} //// @@ -60,7 +60,7 @@ You can read more at the end of this page. When using `Field()` with Pydantic models, you can also declare additional `examples`: -{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:11] *} +{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:12] *} ## `examples` in JSON Schema - OpenAPI { #examples-in-json-schema-openapi } @@ -80,19 +80,19 @@ you can also declare a group of `examples` with additional information that will Here we pass `examples` containing one example of the data expected in `Body()`: -{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[22:29] *} +{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[23:31] *} ### Example in the docs UI { #example-in-the-docs-ui } With any of the methods above it would look like this in the `/docs`: - + ### `Body` with multiple `examples` { #body-with-multiple-examples } You can of course also pass multiple `examples`: -{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[23:38] *} +{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[24:40] *} When you do this, the examples will be part of the internal **JSON Schema** for that body data. @@ -133,13 +133,13 @@ Each specific example `dict` in the `examples` can contain: You can use it like this: -{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[23:49] *} +{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[24:51] *} ### OpenAPI Examples in the Docs UI { #openapi-examples-in-the-docs-ui } With `openapi_examples` added to `Body()` the `/docs` would look like: - + ## Technical Details { #technical-details } diff --git a/docs/pt/docs/tutorial/schema-extra-example.md b/docs/pt/docs/tutorial/schema-extra-example.md index bddd320cd..625da4576 100644 --- a/docs/pt/docs/tutorial/schema-extra-example.md +++ b/docs/pt/docs/tutorial/schema-extra-example.md @@ -10,13 +10,13 @@ Você pode declarar `examples` para um modelo Pydantic que serão adicionados ao //// tab | Pydantic v2 -{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[13:24] *} +{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[14:26] *} //// //// tab | Pydantic v1 -{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[13:23] *} +{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[14:25] *} //// @@ -60,7 +60,7 @@ Você pode ler mais no final desta página. Ao usar `Field()` com modelos Pydantic, você também pode declarar `examples` adicionais: -{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:11] *} +{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:12] *} ## `examples` no JSON Schema - OpenAPI { #examples-in-json-schema-openapi } @@ -80,19 +80,19 @@ você também pode declarar um grupo de `examples` com informações adicionais Aqui passamos `examples` contendo um exemplo dos dados esperados em `Body()`: -{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[22:29] *} +{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[23:31] *} ### Exemplo na UI da documentação { #example-in-the-docs-ui } Com qualquer um dos métodos acima, ficaria assim em `/docs`: - + ### `Body` com vários `examples` { #body-with-multiple-examples } Você também pode, é claro, passar vários `examples`: -{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[23:38] *} +{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[24:40] *} Quando fizer isso, os exemplos farão parte do **JSON Schema** interno para esses dados do body. @@ -133,13 +133,13 @@ Cada `dict` de exemplo específico em `examples` pode conter: Você pode usá-lo assim: -{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[23:49] *} +{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[24:51] *} ### Exemplos do OpenAPI na UI da documentação { #openapi-examples-in-the-docs-ui } Com `openapi_examples` adicionado a `Body()`, o `/docs` ficaria assim: - + ## Detalhes Técnicos { #technical-details } diff --git a/docs/ru/docs/tutorial/schema-extra-example.md b/docs/ru/docs/tutorial/schema-extra-example.md index 5891f0d12..868b38d5e 100644 --- a/docs/ru/docs/tutorial/schema-extra-example.md +++ b/docs/ru/docs/tutorial/schema-extra-example.md @@ -10,13 +10,13 @@ //// tab | Pydantic v2 -{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[13:24] *} +{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[14:26] *} //// //// tab | Pydantic v1 -{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[13:23] *} +{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[14:25] *} //// @@ -60,7 +60,7 @@ OpenAPI 3.1.0 (используется начиная с FastAPI 0.99.0) доб При использовании `Field()` с моделями Pydantic вы также можете объявлять дополнительные `examples`: -{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:11] *} +{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:12] *} ## `examples` в JSON Schema — OpenAPI { #examples-in-json-schema-openapi } @@ -80,19 +80,19 @@ OpenAPI 3.1.0 (используется начиная с FastAPI 0.99.0) доб Здесь мы передаём `examples`, содержащий один пример данных, ожидаемых в `Body()`: -{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[22:29] *} +{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[23:31] *} ### Пример в UI документации { #example-in-the-docs-ui } С любым из перечисленных выше методов это будет выглядеть так в `/docs`: - + ### `Body` с несколькими `examples` { #body-with-multiple-examples } Конечно, вы можете передать и несколько `examples`: -{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[23:38] *} +{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[24:40] *} Когда вы делаете это, примеры становятся частью внутренней **JSON Schema** для данных тела запроса. @@ -133,13 +133,13 @@ OpenAPI 3.1.0 (используется начиная с FastAPI 0.99.0) доб Использовать это можно так: -{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[23:49] *} +{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[24:51] *} ### OpenAPI-примеры в UI документации { #openapi-examples-in-the-docs-ui } С `openapi_examples`, добавленным в `Body()`, страница `/docs` будет выглядеть так: - + ## Технические детали { #technical-details } diff --git a/docs_src/schema_extra_example/tutorial001.py b/docs_src/schema_extra_example/tutorial001.py index 32a66db3a..e67f17dd3 100644 --- a/docs_src/schema_extra_example/tutorial001.py +++ b/docs_src/schema_extra_example/tutorial001.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None model_config = { "json_schema_extra": { @@ -20,6 +21,7 @@ class Item(BaseModel): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, } ] } diff --git a/docs_src/schema_extra_example/tutorial001_pv1.py b/docs_src/schema_extra_example/tutorial001_pv1.py index 6ab96ff85..48ad66d71 100644 --- a/docs_src/schema_extra_example/tutorial001_pv1.py +++ b/docs_src/schema_extra_example/tutorial001_pv1.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None class Config: schema_extra = { @@ -20,6 +21,7 @@ class Item(BaseModel): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, } ] } diff --git a/docs_src/schema_extra_example/tutorial001_pv1_py310.py b/docs_src/schema_extra_example/tutorial001_pv1_py310.py index ec83f1112..55b086355 100644 --- a/docs_src/schema_extra_example/tutorial001_pv1_py310.py +++ b/docs_src/schema_extra_example/tutorial001_pv1_py310.py @@ -9,6 +9,7 @@ class Item(BaseModel): description: str | None = None price: float tax: float | None = None + extra: str | None = None class Config: schema_extra = { @@ -18,6 +19,7 @@ class Item(BaseModel): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, } ] } diff --git a/docs_src/schema_extra_example/tutorial001_py310.py b/docs_src/schema_extra_example/tutorial001_py310.py index 84aa5fc12..727b6303a 100644 --- a/docs_src/schema_extra_example/tutorial001_py310.py +++ b/docs_src/schema_extra_example/tutorial001_py310.py @@ -9,6 +9,7 @@ class Item(BaseModel): description: str | None = None price: float tax: float | None = None + extra: str | None = None model_config = { "json_schema_extra": { @@ -18,6 +19,7 @@ class Item(BaseModel): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, } ] } diff --git a/docs_src/schema_extra_example/tutorial002.py b/docs_src/schema_extra_example/tutorial002.py index 70f06567c..3246ecfb4 100644 --- a/docs_src/schema_extra_example/tutorial002.py +++ b/docs_src/schema_extra_example/tutorial002.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: Union[str, None] = Field(default=None, examples=["A very nice Item"]) price: float = Field(examples=[35.4]) tax: Union[float, None] = Field(default=None, examples=[3.2]) + extra: Union[str, None] = Field(default=None, examples=[None]) @app.put("/items/{item_id}") diff --git a/docs_src/schema_extra_example/tutorial002_py310.py b/docs_src/schema_extra_example/tutorial002_py310.py index 27d786867..c08964f81 100644 --- a/docs_src/schema_extra_example/tutorial002_py310.py +++ b/docs_src/schema_extra_example/tutorial002_py310.py @@ -9,6 +9,7 @@ class Item(BaseModel): description: str | None = Field(default=None, examples=["A very nice Item"]) price: float = Field(examples=[35.4]) tax: float | None = Field(default=None, examples=[3.2]) + extra: str | None = Field(default=None, examples=[None]) @app.put("/items/{item_id}") diff --git a/docs_src/schema_extra_example/tutorial003.py b/docs_src/schema_extra_example/tutorial003.py index 385f3de8a..84cb73ae5 100644 --- a/docs_src/schema_extra_example/tutorial003.py +++ b/docs_src/schema_extra_example/tutorial003.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None @app.put("/items/{item_id}") @@ -23,6 +24,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, } ], ), diff --git a/docs_src/schema_extra_example/tutorial003_an.py b/docs_src/schema_extra_example/tutorial003_an.py index 23675aba1..d9c2ba603 100644 --- a/docs_src/schema_extra_example/tutorial003_an.py +++ b/docs_src/schema_extra_example/tutorial003_an.py @@ -12,6 +12,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None @app.put("/items/{item_id}") @@ -26,6 +27,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, } ], ), diff --git a/docs_src/schema_extra_example/tutorial003_an_py310.py b/docs_src/schema_extra_example/tutorial003_an_py310.py index bbd2e171e..b29cd1ea9 100644 --- a/docs_src/schema_extra_example/tutorial003_an_py310.py +++ b/docs_src/schema_extra_example/tutorial003_an_py310.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: str | None = None price: float tax: float | None = None + extra: str | None = None @app.put("/items/{item_id}") @@ -25,6 +26,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, } ], ), diff --git a/docs_src/schema_extra_example/tutorial003_an_py39.py b/docs_src/schema_extra_example/tutorial003_an_py39.py index 472808561..45b69a7f9 100644 --- a/docs_src/schema_extra_example/tutorial003_an_py39.py +++ b/docs_src/schema_extra_example/tutorial003_an_py39.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None @app.put("/items/{item_id}") @@ -25,6 +26,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, } ], ), diff --git a/docs_src/schema_extra_example/tutorial003_py310.py b/docs_src/schema_extra_example/tutorial003_py310.py index 2d31619be..1c7a3a8de 100644 --- a/docs_src/schema_extra_example/tutorial003_py310.py +++ b/docs_src/schema_extra_example/tutorial003_py310.py @@ -9,6 +9,7 @@ class Item(BaseModel): description: str | None = None price: float tax: float | None = None + extra: str | None = None @app.put("/items/{item_id}") @@ -21,6 +22,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, } ], ), diff --git a/docs_src/schema_extra_example/tutorial004.py b/docs_src/schema_extra_example/tutorial004.py index 75514a3e9..4b283d2c6 100644 --- a/docs_src/schema_extra_example/tutorial004.py +++ b/docs_src/schema_extra_example/tutorial004.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None @app.put("/items/{item_id}") @@ -24,6 +25,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, { "name": "Bar", diff --git a/docs_src/schema_extra_example/tutorial004_an.py b/docs_src/schema_extra_example/tutorial004_an.py index e817302a2..c0b477ad5 100644 --- a/docs_src/schema_extra_example/tutorial004_an.py +++ b/docs_src/schema_extra_example/tutorial004_an.py @@ -12,6 +12,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None @app.put("/items/{item_id}") @@ -27,6 +28,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, { "name": "Bar", diff --git a/docs_src/schema_extra_example/tutorial004_an_py310.py b/docs_src/schema_extra_example/tutorial004_an_py310.py index 650da3187..e54957aa7 100644 --- a/docs_src/schema_extra_example/tutorial004_an_py310.py +++ b/docs_src/schema_extra_example/tutorial004_an_py310.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: str | None = None price: float tax: float | None = None + extra: str | None = None @app.put("/items/{item_id}") @@ -26,6 +27,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, { "name": "Bar", diff --git a/docs_src/schema_extra_example/tutorial004_an_py39.py b/docs_src/schema_extra_example/tutorial004_an_py39.py index dc5a8fe49..8f5cf0e8f 100644 --- a/docs_src/schema_extra_example/tutorial004_an_py39.py +++ b/docs_src/schema_extra_example/tutorial004_an_py39.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None @app.put("/items/{item_id}") @@ -26,6 +27,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, { "name": "Bar", diff --git a/docs_src/schema_extra_example/tutorial004_py310.py b/docs_src/schema_extra_example/tutorial004_py310.py index 05996ac2a..a84bbce1f 100644 --- a/docs_src/schema_extra_example/tutorial004_py310.py +++ b/docs_src/schema_extra_example/tutorial004_py310.py @@ -9,6 +9,7 @@ class Item(BaseModel): description: str | None = None price: float tax: float | None = None + extra: str | None = None @app.put("/items/{item_id}") @@ -22,6 +23,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, { "name": "Bar", diff --git a/docs_src/schema_extra_example/tutorial005.py b/docs_src/schema_extra_example/tutorial005.py index b8217c27e..7541e562c 100644 --- a/docs_src/schema_extra_example/tutorial005.py +++ b/docs_src/schema_extra_example/tutorial005.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None @app.put("/items/{item_id}") @@ -27,6 +28,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, }, "converted": { diff --git a/docs_src/schema_extra_example/tutorial005_an.py b/docs_src/schema_extra_example/tutorial005_an.py index 4b2d9c662..8516527ee 100644 --- a/docs_src/schema_extra_example/tutorial005_an.py +++ b/docs_src/schema_extra_example/tutorial005_an.py @@ -12,6 +12,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None @app.put("/items/{item_id}") @@ -30,6 +31,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, }, "converted": { diff --git a/docs_src/schema_extra_example/tutorial005_an_py310.py b/docs_src/schema_extra_example/tutorial005_an_py310.py index 64dc2cf90..a43b5e93e 100644 --- a/docs_src/schema_extra_example/tutorial005_an_py310.py +++ b/docs_src/schema_extra_example/tutorial005_an_py310.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: str | None = None price: float tax: float | None = None + extra: str | None = None @app.put("/items/{item_id}") @@ -29,6 +30,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, }, "converted": { diff --git a/docs_src/schema_extra_example/tutorial005_an_py39.py b/docs_src/schema_extra_example/tutorial005_an_py39.py index edeb1affc..326837eae 100644 --- a/docs_src/schema_extra_example/tutorial005_an_py39.py +++ b/docs_src/schema_extra_example/tutorial005_an_py39.py @@ -11,6 +11,7 @@ class Item(BaseModel): description: Union[str, None] = None price: float tax: Union[float, None] = None + extra: Union[str, None] = None @app.put("/items/{item_id}") @@ -29,6 +30,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, }, "converted": { diff --git a/docs_src/schema_extra_example/tutorial005_py310.py b/docs_src/schema_extra_example/tutorial005_py310.py index eef973343..5ae6159ca 100644 --- a/docs_src/schema_extra_example/tutorial005_py310.py +++ b/docs_src/schema_extra_example/tutorial005_py310.py @@ -9,6 +9,7 @@ class Item(BaseModel): description: str | None = None price: float tax: float | None = None + extra: str | None = None @app.put("/items/{item_id}") @@ -25,6 +26,7 @@ async def update_item( "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, }, "converted": { diff --git a/tests/test_tutorial/test_schema_extra_example/test_tutorial001.py b/tests/test_tutorial/test_schema_extra_example/test_tutorial001.py index c21cbb4bc..1be2d9e92 100644 --- a/tests/test_tutorial/test_schema_extra_example/test_tutorial001.py +++ b/tests/test_tutorial/test_schema_extra_example/test_tutorial001.py @@ -29,6 +29,7 @@ def test_post_body_example(client: TestClient): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, ) assert response.status_code == 200 @@ -107,6 +108,10 @@ def test_openapi_schema(client: TestClient): "anyOf": [{"type": "number"}, {"type": "null"}], "title": "Tax", }, + "extra": { + "anyOf": [{"type": "string"}, {"type": "null"}], + "title": "Extra", + }, }, "type": "object", "required": ["name", "price"], @@ -117,6 +122,7 @@ def test_openapi_schema(client: TestClient): "name": "Foo", "price": 35.4, "tax": 3.2, + "extra": None, } ], }, diff --git a/tests/test_tutorial/test_schema_extra_example/test_tutorial001_pv1.py b/tests/test_tutorial/test_schema_extra_example/test_tutorial001_pv1.py index b79f42e64..70d84cab9 100644 --- a/tests/test_tutorial/test_schema_extra_example/test_tutorial001_pv1.py +++ b/tests/test_tutorial/test_schema_extra_example/test_tutorial001_pv1.py @@ -29,6 +29,7 @@ def test_post_body_example(client: TestClient): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, ) assert response.status_code == 200 @@ -101,6 +102,7 @@ def test_openapi_schema(client: TestClient): "description": {"type": "string", "title": "Description"}, "price": {"type": "number", "title": "Price"}, "tax": {"type": "number", "title": "Tax"}, + "extra": {"type": "string", "title": "Extra"}, }, "type": "object", "required": ["name", "price"], @@ -111,6 +113,7 @@ def test_openapi_schema(client: TestClient): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, } ], }, diff --git a/tests/test_tutorial/test_schema_extra_example/test_tutorial004.py b/tests/test_tutorial/test_schema_extra_example/test_tutorial004.py index 61aefd12a..421c083da 100644 --- a/tests/test_tutorial/test_schema_extra_example/test_tutorial004.py +++ b/tests/test_tutorial/test_schema_extra_example/test_tutorial004.py @@ -32,6 +32,7 @@ def test_post_body_example(client: TestClient): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, ) assert response.status_code == 200 @@ -68,6 +69,7 @@ def test_openapi_schema(client: TestClient): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, {"name": "Bar", "price": "35.4"}, { @@ -90,6 +92,7 @@ def test_openapi_schema(client: TestClient): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, {"name": "Bar", "price": "35.4"}, { @@ -162,6 +165,16 @@ def test_openapi_schema(client: TestClient): # TODO: remove when deprecating Pydantic v1 {"title": "Tax", "type": "number"} ), + "extra": IsDict( + { + "title": "Extra", + "anyOf": [{"type": "string"}, {"type": "null"}], + }, + ) + | IsDict( + # TODO: remove when deprecating Pydantic v1 + {"title": "Extra", "type": "string"} + ), }, }, "ValidationError": { diff --git a/tests/test_tutorial/test_schema_extra_example/test_tutorial005.py b/tests/test_tutorial/test_schema_extra_example/test_tutorial005.py index 12859227b..f083f5c7a 100644 --- a/tests/test_tutorial/test_schema_extra_example/test_tutorial005.py +++ b/tests/test_tutorial/test_schema_extra_example/test_tutorial005.py @@ -32,6 +32,7 @@ def test_post_body_example(client: TestClient): "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, ) assert response.status_code == 200 @@ -78,6 +79,7 @@ def test_openapi_schema(client: TestClient) -> None: "description": "A very nice Item", "price": 35.4, "tax": 3.2, + "extra": None, }, }, "converted": { @@ -156,6 +158,16 @@ def test_openapi_schema(client: TestClient) -> None: # TODO: remove when deprecating Pydantic v1 {"title": "Tax", "type": "number"} ), + "extra": IsDict( + { + "title": "Extra", + "anyOf": [{"type": "string"}, {"type": "null"}], + } + ) + | IsDict( + # TODO: remove when deprecating Pydantic v1 + {"title": "Extra", "type": "string"} + ), }, }, "ValidationError": {