Browse Source

Update code examples in docs

pull/14411/head
Yurii Motov 8 months ago
parent
commit
af0204416f
  1. 16
      docs/de/docs/tutorial/schema-extra-example.md
  2. BIN
      docs/en/docs/img/tutorial/schema-extra-example/image01.png
  3. BIN
      docs/en/docs/img/tutorial/schema-extra-example/image02.png
  4. 16
      docs/en/docs/tutorial/schema-extra-example.md
  5. 16
      docs/pt/docs/tutorial/schema-extra-example.md
  6. 16
      docs/ru/docs/tutorial/schema-extra-example.md
  7. 2
      docs_src/schema_extra_example/tutorial001.py
  8. 2
      docs_src/schema_extra_example/tutorial001_pv1.py
  9. 2
      docs_src/schema_extra_example/tutorial001_pv1_py310.py
  10. 2
      docs_src/schema_extra_example/tutorial001_py310.py
  11. 1
      docs_src/schema_extra_example/tutorial002.py
  12. 1
      docs_src/schema_extra_example/tutorial002_py310.py
  13. 2
      docs_src/schema_extra_example/tutorial003.py
  14. 2
      docs_src/schema_extra_example/tutorial003_an.py
  15. 2
      docs_src/schema_extra_example/tutorial003_an_py310.py
  16. 2
      docs_src/schema_extra_example/tutorial003_an_py39.py
  17. 2
      docs_src/schema_extra_example/tutorial003_py310.py
  18. 2
      docs_src/schema_extra_example/tutorial004.py
  19. 2
      docs_src/schema_extra_example/tutorial004_an.py
  20. 2
      docs_src/schema_extra_example/tutorial004_an_py310.py
  21. 2
      docs_src/schema_extra_example/tutorial004_an_py39.py
  22. 2
      docs_src/schema_extra_example/tutorial004_py310.py
  23. 2
      docs_src/schema_extra_example/tutorial005.py
  24. 2
      docs_src/schema_extra_example/tutorial005_an.py
  25. 2
      docs_src/schema_extra_example/tutorial005_an_py310.py
  26. 2
      docs_src/schema_extra_example/tutorial005_an_py39.py
  27. 2
      docs_src/schema_extra_example/tutorial005_py310.py
  28. 6
      tests/test_tutorial/test_schema_extra_example/test_tutorial001.py
  29. 3
      tests/test_tutorial/test_schema_extra_example/test_tutorial001_pv1.py
  30. 13
      tests/test_tutorial/test_schema_extra_example/test_tutorial004.py
  31. 12
      tests/test_tutorial/test_schema_extra_example/test_tutorial005.py

16
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:
<img src="/img/tutorial/body-fields/image01.png">
<img src="/img/tutorial/schema-extra-example/image01.png">
### `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:
<img src="/img/tutorial/body-fields/image02.png">
<img src="/img/tutorial/schema-extra-example/image02.png">
## Technische Details { #technical-details }

BIN
docs/en/docs/img/tutorial/schema-extra-example/image01.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
docs/en/docs/img/tutorial/schema-extra-example/image02.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

16
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`:
<img src="/img/tutorial/body-fields/image01.png">
<img src="/img/tutorial/schema-extra-example/image01.png">
### `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:
<img src="/img/tutorial/body-fields/image02.png">
<img src="/img/tutorial/schema-extra-example/image02.png">
## Technical Details { #technical-details }

16
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`:
<img src="/img/tutorial/body-fields/image01.png">
<img src="/img/tutorial/schema-extra-example/image01.png">
### `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:
<img src="/img/tutorial/body-fields/image02.png">
<img src="/img/tutorial/schema-extra-example/image02.png">
## Detalhes Técnicos { #technical-details }

16
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`:
<img src="/img/tutorial/body-fields/image01.png">
<img src="/img/tutorial/schema-extra-example/image01.png">
### `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` будет выглядеть так:
<img src="/img/tutorial/body-fields/image02.png">
<img src="/img/tutorial/schema-extra-example/image02.png">
## Технические детали { #technical-details }

2
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,
}
]
}

2
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,
}
]
}

2
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,
}
]
}

2
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,
}
]
}

1
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}")

1
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}")

2
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,
}
],
),

2
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,
}
],
),

2
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,
}
],
),

2
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,
}
],
),

2
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,
}
],
),

2
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",

2
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",

2
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",

2
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",

2
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",

2
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": {

2
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": {

2
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": {

2
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": {

2
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": {

6
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,
}
],
},

3
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,
}
],
},

13
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": {

12
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": {

Loading…
Cancel
Save