mirror of https://github.com/tiangolo/fastapi.git
📝 Update includes for `docs/en/docs/tutorial/schema-extra-example.md` (#12822)
This commit is contained in:
parent
636171ce31
commit
5c080d81ae
|
|
@ -8,35 +8,15 @@ Hier sind mehrere Möglichkeiten, das zu tun.
|
||||||
|
|
||||||
Sie können `examples` („Beispiele“) für ein Pydantic-Modell deklarieren, welche dem generierten JSON-Schema hinzugefügt werden.
|
Sie können `examples` („Beispiele“) für ein Pydantic-Modell deklarieren, welche dem generierten JSON-Schema hinzugefügt werden.
|
||||||
|
|
||||||
//// tab | Python 3.10+ Pydantic v2
|
//// tab | Pydantic v2
|
||||||
|
|
||||||
```Python hl_lines="13-24"
|
{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[13:24] *}
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
//// tab | Python 3.10+ Pydantic v1
|
//// tab | Pydantic v1
|
||||||
|
|
||||||
```Python hl_lines="13-23"
|
{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[13:23] *}
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001_py310_pv1.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ Pydantic v2
|
|
||||||
|
|
||||||
```Python hl_lines="15-26"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ Pydantic v1
|
|
||||||
|
|
||||||
```Python hl_lines="15-25"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001_pv1.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
@ -80,21 +60,7 @@ Mehr erfahren Sie am Ende dieser Seite.
|
||||||
|
|
||||||
Wenn Sie `Field()` mit Pydantic-Modellen verwenden, können Sie ebenfalls zusätzliche `examples` deklarieren:
|
Wenn Sie `Field()` mit Pydantic-Modellen verwenden, können Sie ebenfalls zusätzliche `examples` deklarieren:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:11] *}
|
||||||
|
|
||||||
```Python hl_lines="2 8-11"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial002_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="4 10-13"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial002.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
## `examples` im JSON-Schema – OpenAPI
|
## `examples` im JSON-Schema – OpenAPI
|
||||||
|
|
||||||
|
|
@ -114,57 +80,7 @@ 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:
|
Hier übergeben wir `examples`, welches ein einzelnes Beispiel für die in `Body()` erwarteten Daten enthält:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[22:29] *}
|
||||||
|
|
||||||
```Python hl_lines="22-29"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_an_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
|
||||||
|
|
||||||
```Python hl_lines="22-29"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_an_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="23-30"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_an.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.10+ nicht annotiert
|
|
||||||
|
|
||||||
/// tip | "Tipp"
|
|
||||||
|
|
||||||
Bevorzugen Sie die `Annotated`-Version, falls möglich.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="18-25"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ nicht annotiert
|
|
||||||
|
|
||||||
/// tip | "Tipp"
|
|
||||||
|
|
||||||
Bevorzugen Sie die `Annotated`-Version, falls möglich.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="20-27"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
### Beispiel in der Dokumentations-Benutzeroberfläche
|
### Beispiel in der Dokumentations-Benutzeroberfläche
|
||||||
|
|
||||||
|
|
@ -176,57 +92,7 @@ Mit jeder der oben genannten Methoden würde es in `/docs` so aussehen:
|
||||||
|
|
||||||
Sie können natürlich auch mehrere `examples` übergeben:
|
Sie können natürlich auch mehrere `examples` übergeben:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[23:38] *}
|
||||||
|
|
||||||
```Python hl_lines="23-38"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_an_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
|
||||||
|
|
||||||
```Python hl_lines="23-38"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_an_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="24-39"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_an.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.10+ nicht annotiert
|
|
||||||
|
|
||||||
/// tip | "Tipp"
|
|
||||||
|
|
||||||
Bevorzugen Sie die `Annotated`-Version, falls möglich.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="19-34"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ nicht annotiert
|
|
||||||
|
|
||||||
/// tip | "Tipp"
|
|
||||||
|
|
||||||
Bevorzugen Sie die `Annotated`-Version, falls möglich.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="21-36"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
Wenn Sie das tun, werden die Beispiele Teil des internen **JSON-Schemas** für diese Body-Daten.
|
Wenn Sie das tun, werden die Beispiele Teil des internen **JSON-Schemas** für diese Body-Daten.
|
||||||
|
|
||||||
|
|
@ -267,57 +133,7 @@ Jedes spezifische Beispiel-`dict` in den `examples` kann Folgendes enthalten:
|
||||||
|
|
||||||
Sie können es so verwenden:
|
Sie können es so verwenden:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[23:49] *}
|
||||||
|
|
||||||
```Python hl_lines="23-49"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_an_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
|
||||||
|
|
||||||
```Python hl_lines="23-49"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_an_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="24-50"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_an.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.10+ nicht annotiert
|
|
||||||
|
|
||||||
/// tip | "Tipp"
|
|
||||||
|
|
||||||
Bevorzugen Sie die `Annotated`-Version, falls möglich.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="19-45"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ nicht annotiert
|
|
||||||
|
|
||||||
/// tip | "Tipp"
|
|
||||||
|
|
||||||
Bevorzugen Sie die `Annotated`-Version, falls möglich.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="21-47"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
### OpenAPI-Beispiele in der Dokumentations-Benutzeroberfläche
|
### OpenAPI-Beispiele in der Dokumentations-Benutzeroberfläche
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,35 +8,15 @@ Here are several ways to do it.
|
||||||
|
|
||||||
You can declare `examples` for a Pydantic model that will be added to the generated JSON Schema.
|
You can declare `examples` for a Pydantic model that will be added to the generated JSON Schema.
|
||||||
|
|
||||||
//// tab | Python 3.10+ Pydantic v2
|
//// tab | Pydantic v2
|
||||||
|
|
||||||
```Python hl_lines="13-24"
|
{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[13:24] *}
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
//// tab | Python 3.10+ Pydantic v1
|
//// tab | Pydantic v1
|
||||||
|
|
||||||
```Python hl_lines="13-23"
|
{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[13:23] *}
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001_py310_pv1.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ Pydantic v2
|
|
||||||
|
|
||||||
```Python hl_lines="15-26"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ Pydantic v1
|
|
||||||
|
|
||||||
```Python hl_lines="15-25"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001_pv1.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
@ -80,21 +60,7 @@ You can read more at the end of this page.
|
||||||
|
|
||||||
When using `Field()` with Pydantic models, you can also declare additional `examples`:
|
When using `Field()` with Pydantic models, you can also declare additional `examples`:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:11] *}
|
||||||
|
|
||||||
```Python hl_lines="2 8-11"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial002_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="4 10-13"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial002.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
## `examples` in JSON Schema - OpenAPI
|
## `examples` in JSON Schema - OpenAPI
|
||||||
|
|
||||||
|
|
@ -114,57 +80,7 @@ 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()`:
|
Here we pass `examples` containing one example of the data expected in `Body()`:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[22:29] *}
|
||||||
|
|
||||||
```Python hl_lines="22-29"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_an_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
|
||||||
|
|
||||||
```Python hl_lines="22-29"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_an_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="23-30"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_an.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.10+ non-Annotated
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
Prefer to use the `Annotated` version if possible.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="18-25"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ non-Annotated
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
Prefer to use the `Annotated` version if possible.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="20-27"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
### Example in the docs UI
|
### Example in the docs UI
|
||||||
|
|
||||||
|
|
@ -176,57 +92,7 @@ With any of the methods above it would look like this in the `/docs`:
|
||||||
|
|
||||||
You can of course also pass multiple `examples`:
|
You can of course also pass multiple `examples`:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[23:38] *}
|
||||||
|
|
||||||
```Python hl_lines="23-38"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_an_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
|
||||||
|
|
||||||
```Python hl_lines="23-38"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_an_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="24-39"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_an.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.10+ non-Annotated
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
Prefer to use the `Annotated` version if possible.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="19-34"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ non-Annotated
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
Prefer to use the `Annotated` version if possible.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="21-36"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
When you do this, the examples will be part of the internal **JSON Schema** for that body data.
|
When you do this, the examples will be part of the internal **JSON Schema** for that body data.
|
||||||
|
|
||||||
|
|
@ -267,57 +133,7 @@ Each specific example `dict` in the `examples` can contain:
|
||||||
|
|
||||||
You can use it like this:
|
You can use it like this:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[23:49] *}
|
||||||
|
|
||||||
```Python hl_lines="23-49"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_an_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
|
||||||
|
|
||||||
```Python hl_lines="23-49"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_an_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="24-50"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_an.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.10+ non-Annotated
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
Prefer to use the `Annotated` version if possible.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="19-45"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ non-Annotated
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
Prefer to use the `Annotated` version if possible.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="21-47"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
### OpenAPI Examples in the Docs UI
|
### OpenAPI Examples in the Docs UI
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,35 +8,15 @@
|
||||||
|
|
||||||
생성된 JSON 스키마에 추가될 Pydantic 모델을 위한 `examples`을 선언할 수 있습니다.
|
생성된 JSON 스키마에 추가될 Pydantic 모델을 위한 `examples`을 선언할 수 있습니다.
|
||||||
|
|
||||||
//// tab | Python 3.10+ Pydantic v2
|
//// tab | Pydantic v2
|
||||||
|
|
||||||
```Python hl_lines="13-24"
|
{* ../../docs_src/schema_extra_example/tutorial001_py310.py hl[13:24] *}
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
//// tab | Python 3.10+ Pydantic v1
|
//// tab | Pydantic v1
|
||||||
|
|
||||||
```Python hl_lines="13-23"
|
{* ../../docs_src/schema_extra_example/tutorial001_pv1_py310.py hl[13:23] *}
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001_py310_pv1.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ Pydantic v2
|
|
||||||
|
|
||||||
```Python hl_lines="15-26"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ Pydantic v1
|
|
||||||
|
|
||||||
```Python hl_lines="15-25"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial001_pv1.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
@ -80,21 +60,7 @@ JSON 스키마를 확장하고 여러분의 별도의 자체 데이터를 추가
|
||||||
|
|
||||||
Pydantic 모델과 같이 `Field()`를 사용할 때 추가적인 `examples`를 선언할 수 있습니다:
|
Pydantic 모델과 같이 `Field()`를 사용할 때 추가적인 `examples`를 선언할 수 있습니다:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial002_py310.py hl[2,8:11] *}
|
||||||
|
|
||||||
```Python hl_lines="2 8-11"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial002_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="4 10-13"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial002.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
## JSON Schema에서의 `examples` - OpenAPI
|
## JSON Schema에서의 `examples` - OpenAPI
|
||||||
|
|
||||||
|
|
@ -114,57 +80,7 @@ Pydantic 모델과 같이 `Field()`를 사용할 때 추가적인 `examples`를
|
||||||
|
|
||||||
여기, `Body()`에 예상되는 예제 데이터 하나를 포함한 `examples`를 넘겼습니다:
|
여기, `Body()`에 예상되는 예제 데이터 하나를 포함한 `examples`를 넘겼습니다:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial003_an_py310.py hl[22:29] *}
|
||||||
|
|
||||||
```Python hl_lines="22-29"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_an_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
|
||||||
|
|
||||||
```Python hl_lines="22-29"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_an_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="23-30"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_an.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.10+ Annotated가 없는 경우
|
|
||||||
|
|
||||||
/// tip | "팁"
|
|
||||||
|
|
||||||
가능하다면 `Annotated`가 달린 버전을 권장합니다.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="18-25"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ Annotated가 없는 경우
|
|
||||||
|
|
||||||
/// tip | "팁"
|
|
||||||
|
|
||||||
가능하다면 `Annotated`가 달린 버전을 권장합니다.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="20-27"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial003.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
### 문서 UI 예시
|
### 문서 UI 예시
|
||||||
|
|
||||||
|
|
@ -176,57 +92,7 @@ Pydantic 모델과 같이 `Field()`를 사용할 때 추가적인 `examples`를
|
||||||
|
|
||||||
물론 여러 `examples`를 넘길 수 있습니다:
|
물론 여러 `examples`를 넘길 수 있습니다:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial004_an_py310.py hl[23:38] *}
|
||||||
|
|
||||||
```Python hl_lines="23-38"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_an_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
|
||||||
|
|
||||||
```Python hl_lines="23-38"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_an_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="24-39"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_an.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.10+ Annotated가 없는 경우
|
|
||||||
|
|
||||||
/// tip | "팁"
|
|
||||||
|
|
||||||
가능하다면 `Annotated`가 달린 버전을 권장합니다.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="19-34"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ Annotated가 없는 경우
|
|
||||||
|
|
||||||
/// tip | "팁"
|
|
||||||
|
|
||||||
가능하다면 `Annotated`가 달린 버전을 권장합니다.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="21-36"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial004.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
이와 같이 하면 이 예제는 그 본문 데이터를 위한 내부 **JSON 스키마**의 일부가 될 것입니다.
|
이와 같이 하면 이 예제는 그 본문 데이터를 위한 내부 **JSON 스키마**의 일부가 될 것입니다.
|
||||||
|
|
||||||
|
|
@ -267,57 +133,7 @@ Pydantic 모델과 같이 `Field()`를 사용할 때 추가적인 `examples`를
|
||||||
|
|
||||||
이를 다음과 같이 사용할 수 있습니다:
|
이를 다음과 같이 사용할 수 있습니다:
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/schema_extra_example/tutorial005_an_py310.py hl[23:49] *}
|
||||||
|
|
||||||
```Python hl_lines="23-49"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_an_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
|
||||||
|
|
||||||
```Python hl_lines="23-49"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_an_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="24-50"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_an.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.10+ Annotated가 없는 경우
|
|
||||||
|
|
||||||
/// tip | "팁"
|
|
||||||
|
|
||||||
가능하다면 `Annotated`가 달린 버전을 권장합니다.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="19-45"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ Annotated가 없는 경우
|
|
||||||
|
|
||||||
/// tip | "팁"
|
|
||||||
|
|
||||||
가능하다면 `Annotated`가 달린 버전을 권장합니다.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="21-47"
|
|
||||||
{!> ../../docs_src/schema_extra_example/tutorial005.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
### 문서 UI에서의 OpenAPI 예시
|
### 문서 UI에서의 OpenAPI 예시
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from ...utils import needs_py310, needs_pydanticv1
|
||||||
|
|
||||||
@pytest.fixture(name="client")
|
@pytest.fixture(name="client")
|
||||||
def get_client():
|
def get_client():
|
||||||
from docs_src.schema_extra_example.tutorial001_py310_pv1 import app
|
from docs_src.schema_extra_example.tutorial001_pv1_py310 import app
|
||||||
|
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
return client
|
return client
|
||||||
Loading…
Reference in New Issue