Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
be0d02d
Add test for `docs_src.body.tutorial002.py`
YuriiMotov Dec 15, 2025
d57d5af
Add test for `docs_src.body.tutorial003.py`
YuriiMotov Dec 15, 2025
5b097c2
Add test for `docs_src.body.tutorial004.py`
YuriiMotov Dec 15, 2025
c04e95a
Add test for `docs_src.body_multiple_params.tutorial002.py`
YuriiMotov Dec 15, 2025
6865d04
Add test for `docs_src.body_multiple_params.tutorial004.py`
YuriiMotov Dec 15, 2025
3740608
Add test for `docs_src.body_multiple_params.tutorial005.py`
YuriiMotov Dec 15, 2025
03d3a44
Add test for `docs_src.body_nested_models.tutorial00X.py` (X in (`001…
YuriiMotov Dec 15, 2025
0d95aa3
Add test for `docs_src.body_nested_models.tutorial004.py`
YuriiMotov Dec 15, 2025
aafa615
Add test for `docs_src.body_nested_models.tutorial005.py`
YuriiMotov Dec 15, 2025
738b632
Add test for `docs_src.body_nested_models.tutorial006.py`
YuriiMotov Dec 15, 2025
ad81261
Add test for `docs_src.body_nested_models.tutorial007.py`
YuriiMotov Dec 15, 2025
acb2d99
Add test for `docs_src.body_nested_models.tutorial008.py`
YuriiMotov Dec 15, 2025
ad98639
Add test for `docs_src.body_updates.tutorial002.py`
YuriiMotov Dec 16, 2025
94aa386
Add test for `docs_src.dependencies.tutorial001_02.py`
YuriiMotov Dec 16, 2025
8392414
Add test for `docs_src.dependencies.tutorial002.py` and `docs_src.dep…
YuriiMotov Dec 16, 2025
8f1e8b4
Add test for `docs_src.dependencies.tutorial005.py`
YuriiMotov Dec 16, 2025
b8e0e00
Add test for `docs_src.dependencies.tutorial011.py`
YuriiMotov Dec 16, 2025
9320b8e
Add test for `docs_src.debugging.tutorial001.py`
YuriiMotov Dec 16, 2025
9e1dddd
Add test for `docs_src.encoder.tutorial001.py`
YuriiMotov Dec 16, 2025
16a27a7
Add test for `docs_src.extra_models.tutorial001.py` and `docs_src.ext…
YuriiMotov Dec 16, 2025
ec9da27
Add test for `docs_src.first_steps.tutorial002.py` and `docs_src.firs…
YuriiMotov Dec 16, 2025
b5d21af
Add test for `docs_src.generate_clients.tutorial001.py`
YuriiMotov Dec 16, 2025
f1a8413
Add test for `docs_src.generate_clients.tutorial002.py`
YuriiMotov Dec 16, 2025
187ff73
Add test for `docs_src.generate_clients.tutorial004.py`
YuriiMotov Dec 16, 2025
d89c03b
Add test for `docs_src.graphql.tutorial001.py`
YuriiMotov Dec 16, 2025
7c9a4f6
Add test for `docs_src.metadata.tutorial002.py`
YuriiMotov Dec 16, 2025
0a96fcf
Add test for `docs_src.metadata.tutorial003.py`
YuriiMotov Dec 16, 2025
e7ca173
Add test for `docs_src.middleware.tutorial001.py`
YuriiMotov Dec 16, 2025
f0a8b80
Add test for `docs_src.path_operation_configuration.tutorial002.py`
YuriiMotov Dec 16, 2025
0d4c68f
Add test for `docs_src.path_operation_configuration.tutorial001.py`
YuriiMotov Dec 16, 2025
60b5481
Add test for `docs_src.path_operation_configuration.tutorial003.py` a…
YuriiMotov Dec 16, 2025
6b7be7d
Add test for `docs_src.path_params_numeric_validations.tutorial001.py`
YuriiMotov Dec 16, 2025
ebf7420
Add test for `docs_src.path_params_numeric_validations.tutorial002.py…
YuriiMotov Dec 16, 2025
ad53cc8
Add test for `docs_src.path_params_numeric_validations.tutorial004.py`
YuriiMotov Dec 16, 2025
7372c24
Add test for `docs_src.path_params_numeric_validations.tutorial005.py`
YuriiMotov Dec 16, 2025
b8fd318
Add test for `docs_src.path_params_numeric_validations.tutorial006.py`
YuriiMotov Dec 16, 2025
07dbe03
Add test for `docs_src.path_params.tutorial001.py`
YuriiMotov Dec 16, 2025
5503fe4
Add test for `docs_src.path_params.tutorial002.py`
YuriiMotov Dec 16, 2025
96cd0aa
Add test for `docs_src.path_params.tutorial003.py`
YuriiMotov Dec 16, 2025
dad82d1
Add test for `docs_src.path_params.tutorial003b.py`
YuriiMotov Dec 16, 2025
285205a
Add test for `docs_src.query_params.tutorial001.py`
YuriiMotov Dec 16, 2025
1d6a2f1
Add test for `docs_src.query_params.tutorial002.py`
YuriiMotov Dec 16, 2025
4d34fc6
Add test for `docs_src.query_params.tutorial003.py`
YuriiMotov Dec 16, 2025
fbbd3cc
Add test for `docs_src.query_params.tutorial004.py`
YuriiMotov Dec 16, 2025
15827e4
Add test for `docs_src.query_params_str_validations.tutorial009.py`
YuriiMotov Dec 17, 2025
3501c52
Add test for `docs_src.query_params_str_validations.tutorial008.py`
YuriiMotov Dec 17, 2025
de6508e
Add test for `docs_src.query_params_str_validations.tutorial007.py`
YuriiMotov Dec 17, 2025
4fea3b6
Add test for `docs_src.query_params_str_validations.tutorial006.py`
YuriiMotov Dec 17, 2025
db44555
Add test for `docs_src.query_params_str_validations.tutorial005.py`
YuriiMotov Dec 17, 2025
76443af
Add test for `docs_src.query_params_str_validations.tutorial004.py`
YuriiMotov Dec 17, 2025
8658e60
Add test for `docs_src.query_params_str_validations.tutorial003.py`
YuriiMotov Dec 17, 2025
ff81437
Add test for `docs_src.query_params_str_validations.tutorial002.py`
YuriiMotov Dec 17, 2025
cb54a92
Add test for `docs_src.query_params_str_validations.tutorial001.py`
YuriiMotov Dec 17, 2025
5fb2efd
Add test for `docs_src.response_directly.tutorial002.py`
YuriiMotov Dec 17, 2025
5e4da83
Add test for `docs_src.response_model.tutorial002.py`
YuriiMotov Dec 17, 2025
854e7c5
Add test for `docs_src.response_model.tutorial001.py` and `docs_src.r…
YuriiMotov Dec 17, 2025
e5a43bc
Add test for `docs_src.response_status_code.tutorial001.py` and `docs…
YuriiMotov Dec 17, 2025
67d64d8
Add test for `docs_src.schema_extra_example.tutorial002.py`
YuriiMotov Dec 18, 2025
7f58b6c
Add test for `docs_src.schema_extra_example.tutorial003.py`
YuriiMotov Dec 18, 2025
22a9890
Add test for `docs_src.security.tutorial002.py`
YuriiMotov Dec 18, 2025
d6b4eb6
Add test for `docs_src.security.tutorial004.py`
YuriiMotov Dec 18, 2025
830bc37
Add test for `docs_src.settings.app01.main.py`
YuriiMotov Dec 18, 2025
ad2bb69
Add test for `docs_src.static_files.tutorial001.py`
YuriiMotov Dec 18, 2025
875efcb
👷 Update github-actions user for GitHub Actions workflows (#14528)
tiangolo Dec 16, 2025
51476db
📝 Update release notes
github-actions[bot] Dec 16, 2025
a84bf80
👷 Update LLM translation CI, add language matrix and extra commands, …
tiangolo Dec 16, 2025
5018694
📝 Update release notes
github-actions[bot] Dec 16, 2025
396b3c6
👷 Fix Typer command for CI LLM translations (#14530)
tiangolo Dec 16, 2025
c983b03
📝 Update release notes
github-actions[bot] Dec 16, 2025
f0ddf5a
👷 Fix checkout GitHub Action fetch-depth for LLM translations, enable…
tiangolo Dec 16, 2025
2996c0b
📝 Update release notes
github-actions[bot] Dec 16, 2025
beb9440
🌐 Update translations for es (add-missing) (#14533)
tiangolo Dec 16, 2025
915b5c6
📝 Update release notes
github-actions[bot] Dec 16, 2025
8567ec2
🌐 Update translations for es (update-outdated) (#14532)
tiangolo Dec 16, 2025
197d404
📝 Update release notes
github-actions[bot] Dec 16, 2025
23ae6cb
👷 Make Pydantic versions customizable in CI (#14535)
tiangolo Dec 16, 2025
34f5969
📝 Update release notes
github-actions[bot] Dec 16, 2025
f3e5112
👷 Run Smokeshow always, even on test failures (#14538)
tiangolo Dec 16, 2025
9f26ed7
📝 Update release notes
github-actions[bot] Dec 16, 2025
5078240
👷 Configure coverage, error on main tests, don't wait for Smokeshow (…
tiangolo Dec 16, 2025
e398d76
📝 Update release notes
github-actions[bot] Dec 16, 2025
4b3c646
🔧 Update test workflow config, remove commented code (#14540)
tiangolo Dec 16, 2025
a645ca8
📝 Update release notes
github-actions[bot] Dec 16, 2025
dd21dd5
🌐 Update translations for pt (update-outdated) (#14537)
tiangolo Dec 16, 2025
be655ae
📝 Update release notes
github-actions[bot] Dec 16, 2025
4e68aeb
🔥 Remove translation to emoji to simplify the new setup with LLM auto…
tiangolo Dec 16, 2025
9dbf9f3
📝 Update release notes
github-actions[bot] Dec 16, 2025
1443b96
🔥 Remove inactive/scarce translations to Persian (#14542)
tiangolo Dec 16, 2025
edb032c
📝 Update release notes
github-actions[bot] Dec 16, 2025
de26a66
🔥 Remove inactive/scarce translations to Vietnamese (#14543)
tiangolo Dec 16, 2025
126b71f
📝 Update release notes
github-actions[bot] Dec 16, 2025
f674a6c
🌐 Sync German docs (#14519)
nilslindemann Dec 17, 2025
4ebc1fc
📝 Update release notes
github-actions[bot] Dec 17, 2025
0e03f56
🌐 Sync Spanish docs (outdated pages found with script) (#14553)
YuriiMotov Dec 17, 2025
f3ca336
📝 Update release notes
github-actions[bot] Dec 17, 2025
b60a8f7
🌐 Sync Portuguese docs (pages found with script) (#14554)
YuriiMotov Dec 17, 2025
8b1dfba
📝 Update release notes
github-actions[bot] Dec 17, 2025
46be810
🔧 Add LLM prompt file for French, generated from the existing French …
tiangolo Dec 17, 2025
536f183
📝 Update release notes
github-actions[bot] Dec 17, 2025
11a0f74
🔧 Temporarily disable translations still in progress, being migrated …
YuriiMotov Dec 17, 2025
cf5ea0f
📝 Update release notes
github-actions[bot] Dec 17, 2025
2c8ad5e
⬆ Bump `markdown-include-variants` from 0.0.7 to 0.0.8 (#14556)
YuriiMotov Dec 17, 2025
5da6d0f
📝 Update release notes
github-actions[bot] Dec 17, 2025
21dd9c0
🌐 Update translations for pt (add-missing) (#14539)
tiangolo Dec 17, 2025
b0e68fb
📝 Update release notes
github-actions[bot] Dec 17, 2025
696884e
⚰️ Remove Python 3.8 from CI and remove Python 3.8 examples from sour…
tiangolo Dec 17, 2025
10161ce
📝 Update release notes
github-actions[bot] Dec 17, 2025
49a7eb0
🔧 Drop support for Python 3.8 (#14563)
tiangolo Dec 17, 2025
03f5ad5
📝 Update release notes
github-actions[bot] Dec 17, 2025
a79431c
♻️ Upgrade internal syntax to Python 3.9+ 🎉 (#14564)
tiangolo Dec 17, 2025
a5e6f5b
📝 Update release notes
github-actions[bot] Dec 17, 2025
9f21611
📝 Update release notes
tiangolo Dec 17, 2025
c6482aa
🔖 Release version 0.125.0
tiangolo Dec 17, 2025
bed4fc1
Fix merge conflicts
YuriiMotov Dec 18, 2025
f24f82b
Fix coverage for `docs_src.path_params.tutorial003b`
YuriiMotov Dec 18, 2025
89244f6
Fix coverage for `docs_src.security.tutorial004`
YuriiMotov Dec 18, 2025
cfcd3e5
Fix coverage for `docs_src.debugging.tutorial001`
YuriiMotov Dec 18, 2025
b64d849
Add missing `__init__.py` files in `docs_src` sub-directories
YuriiMotov Dec 18, 2025
ac076dd
Rename `dataclasses` to `dataclasses_` and `graphql` to `graphql_` to…
YuriiMotov Dec 18, 2025
cb57435
Add tests for `docs_src.custom_response.tutorial002` and `docs_src.cu…
YuriiMotov Dec 18, 2025
010480b
Add tests for `docs_src.security.tutorial007`
YuriiMotov Dec 18, 2025
d57ba00
Add tests for `docs_src.custom_response.tutorial010`
YuriiMotov Dec 18, 2025
6b4017f
Add tests for `docs_src.dependencies.tutorial007`
YuriiMotov Dec 18, 2025
2b9d85a
Add tests for `docs_src.dependencies.tutorial008` (skipped for annota…
YuriiMotov Dec 18, 2025
00bca9d
Add tests for `docs_src.dependencies.tutorial010`
YuriiMotov Dec 18, 2025
1022dde
Add tests for `docs_src.python_types.**`
YuriiMotov Dec 18, 2025
32bd9ee
Add tests for `docs_src.query_params_str_validations.tutorial006c`
YuriiMotov Dec 18, 2025
e9aabb8
Exclude temporary code examples from coverage
YuriiMotov Dec 18, 2025
225a022
Merge remote-tracking branch 'upstream/master' into add-missing-tests…
YuriiMotov Dec 18, 2025
0c183ee
Add `pragma: no cover` in some tests
YuriiMotov Dec 18, 2025
871d207
Remove redundand `needs_py39` in test
YuriiMotov Dec 18, 2025
8c8addf
Fix applying `needs_pydanticv2` to modules
YuriiMotov Dec 18, 2025
5f3500d
Omit Pydantic V1 code examples in coverage config
YuriiMotov Dec 19, 2025
406de37
Merge remote-tracking branch 'upstream/master' into add-missing-tests…
YuriiMotov Dec 20, 2025
d4e7db0
UPdate test for `docs_src/python_types/tutorial005_py39.py` after fix…
YuriiMotov Dec 20, 2025
8e1aad2
💡 Tweak TODO comments to make them easier for me to find them
tiangolo Dec 26, 2025
90a9f04
✅ Tweak test, add xfail
tiangolo Dec 26, 2025
05ccdf3
⬆️ Upgrade Strawberry for tests
tiangolo Dec 26, 2025
e758f67
Merge branch 'master' into add-missing-tests-for-code-examples
tiangolo Dec 26, 2025
aae90fd
✅ Update tests, remove needs_pydanticv2
tiangolo Dec 26, 2025
bf44d37
⬇️ Downgrade Strawberry Python for Python 3.9
tiangolo Dec 26, 2025
d15b0f6
🔇 Add warning ignore for Strawberry
tiangolo Dec 26, 2025
824edd3
✅ Tweak test to filter warning
tiangolo Dec 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/de/docs/advanced/dataclasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FastAPI basiert auf **Pydantic**, und ich habe Ihnen gezeigt, wie Sie Pydantic-M

Aber FastAPI unterstützt auf die gleiche Weise auch die Verwendung von <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a>:

{* ../../docs_src/dataclasses/tutorial001_py310.py hl[1,6:11,18:19] *}
{* ../../docs_src/dataclasses_/tutorial001_py310.py hl[1,6:11,18:19] *}

Das ist dank **Pydantic** ebenfalls möglich, da es <a href="https://docs.pydantic.dev/latest/concepts/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">`dataclasses` intern unterstützt</a>.

Expand Down Expand Up @@ -32,7 +32,7 @@ Wenn Sie jedoch eine Menge Datenklassen herumliegen haben, ist dies ein guter Tr

Sie können `dataclasses` auch im Parameter `response_model` verwenden:

{* ../../docs_src/dataclasses/tutorial002_py310.py hl[1,6:12,18] *}
{* ../../docs_src/dataclasses_/tutorial002_py310.py hl[1,6:12,18] *}

Die Datenklasse wird automatisch in eine Pydantic-Datenklasse konvertiert.

Expand All @@ -48,7 +48,7 @@ In einigen Fällen müssen Sie möglicherweise immer noch Pydantics Version von

In diesem Fall können Sie einfach die Standard-`dataclasses` durch `pydantic.dataclasses` ersetzen, was einen direkten Ersatz darstellt:

{* ../../docs_src/dataclasses/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}
{* ../../docs_src/dataclasses_/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}

1. Wir importieren `field` weiterhin von Standard-`dataclasses`.

Expand Down
2 changes: 1 addition & 1 deletion docs/de/docs/how-to/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Abhängig von Ihrem Anwendungsfall könnten Sie eine andere Bibliothek vorziehen

Hier ist eine kleine Vorschau, wie Sie Strawberry mit FastAPI integrieren können:

{* ../../docs_src/graphql/tutorial001_py39.py hl[3,22,25] *}
{* ../../docs_src/graphql_/tutorial001_py39.py hl[3,22,25] *}

Weitere Informationen zu Strawberry finden Sie in der <a href="https://strawberry.rocks/" class="external-link" target="_blank">Strawberry-Dokumentation</a>.

Expand Down
6 changes: 3 additions & 3 deletions docs/en/docs/advanced/dataclasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FastAPI is built on top of **Pydantic**, and I have been showing you how to use

But FastAPI also supports using <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a> the same way:

{* ../../docs_src/dataclasses/tutorial001_py310.py hl[1,6:11,18:19] *}
{* ../../docs_src/dataclasses_/tutorial001_py310.py hl[1,6:11,18:19] *}

This is still supported thanks to **Pydantic**, as it has <a href="https://docs.pydantic.dev/latest/concepts/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">internal support for `dataclasses`</a>.

Expand Down Expand Up @@ -32,7 +32,7 @@ But if you have a bunch of dataclasses laying around, this is a nice trick to us

You can also use `dataclasses` in the `response_model` parameter:

{* ../../docs_src/dataclasses/tutorial002_py310.py hl[1,6:12,18] *}
{* ../../docs_src/dataclasses_/tutorial002_py310.py hl[1,6:12,18] *}

The dataclass will be automatically converted to a Pydantic dataclass.

Expand All @@ -48,7 +48,7 @@ In some cases, you might still have to use Pydantic's version of `dataclasses`.

In that case, you can simply swap the standard `dataclasses` with `pydantic.dataclasses`, which is a drop-in replacement:

{* ../../docs_src/dataclasses/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}
{* ../../docs_src/dataclasses_/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}

1. We still import `field` from standard `dataclasses`.

Expand Down
2 changes: 1 addition & 1 deletion docs/en/docs/how-to/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Depending on your use case, you might prefer to use a different library, but if

Here's a small preview of how you could integrate Strawberry with FastAPI:

{* ../../docs_src/graphql/tutorial001_py39.py hl[3,22,25] *}
{* ../../docs_src/graphql_/tutorial001_py39.py hl[3,22,25] *}

You can learn more about Strawberry in the <a href="https://strawberry.rocks/" class="external-link" target="_blank">Strawberry documentation</a>.

Expand Down
6 changes: 3 additions & 3 deletions docs/es/docs/advanced/dataclasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FastAPI está construido sobre **Pydantic**, y te he estado mostrando cómo usar

Pero FastAPI también soporta el uso de <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a> de la misma manera:

{* ../../docs_src/dataclasses/tutorial001_py310.py hl[1,6:11,18:19] *}
{* ../../docs_src/dataclasses_/tutorial001_py310.py hl[1,6:11,18:19] *}

Esto sigue siendo soportado gracias a **Pydantic**, ya que tiene <a href="https://docs.pydantic.dev/latest/concepts/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">soporte interno para `dataclasses`</a>.

Expand Down Expand Up @@ -32,7 +32,7 @@ Pero si tienes un montón de dataclasses por ahí, este es un buen truco para us

También puedes usar `dataclasses` en el parámetro `response_model`:

{* ../../docs_src/dataclasses/tutorial002_py310.py hl[1,6:12,18] *}
{* ../../docs_src/dataclasses_/tutorial002_py310.py hl[1,6:12,18] *}

El dataclass será automáticamente convertido a un dataclass de Pydantic.

Expand All @@ -48,7 +48,7 @@ En algunos casos, todavía podrías tener que usar la versión de `dataclasses`

En ese caso, simplemente puedes intercambiar los `dataclasses` estándar con `pydantic.dataclasses`, que es un reemplazo directo:

{* ../../docs_src/dataclasses/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}
{* ../../docs_src/dataclasses_/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}

1. Todavía importamos `field` de los `dataclasses` estándar.

Expand Down
2 changes: 1 addition & 1 deletion docs/es/docs/how-to/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Dependiendo de tu caso de uso, podrías preferir usar un paquete diferente, pero

Aquí tienes una pequeña vista previa de cómo podrías integrar Strawberry con FastAPI:

{* ../../docs_src/graphql/tutorial001_py39.py hl[3,22,25] *}
{* ../../docs_src/graphql_/tutorial001_py39.py hl[3,22,25] *}

Puedes aprender más sobre Strawberry en la <a href="https://strawberry.rocks/" class="external-link" target="_blank">documentación de Strawberry</a>.

Expand Down
6 changes: 3 additions & 3 deletions docs/pt/docs/advanced/dataclasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FastAPI é construído em cima do **Pydantic**, e eu tenho mostrado como usar mo

Mas o FastAPI também suporta o uso de <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a> da mesma forma:

{* ../../docs_src/dataclasses/tutorial001_py310.py hl[1,6:11,18:19] *}
{* ../../docs_src/dataclasses_/tutorial001_py310.py hl[1,6:11,18:19] *}

Isso ainda é suportado graças ao **Pydantic**, pois ele tem <a href="https://docs.pydantic.dev/latest/concepts/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">suporte interno para `dataclasses`</a>.

Expand Down Expand Up @@ -32,7 +32,7 @@ Mas se você tem um monte de dataclasses por aí, este é um truque legal para u

Você também pode usar `dataclasses` no parâmetro `response_model`:

{* ../../docs_src/dataclasses/tutorial002_py310.py hl[1,6:12,18] *}
{* ../../docs_src/dataclasses_/tutorial002_py310.py hl[1,6:12,18] *}

A dataclass será automaticamente convertida para uma dataclass Pydantic.

Expand All @@ -48,7 +48,7 @@ Em alguns casos, você ainda pode ter que usar a versão do Pydantic das `datacl

Nesse caso, você pode simplesmente trocar as `dataclasses` padrão por `pydantic.dataclasses`, que é um substituto direto:

{* ../../docs_src/dataclasses/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}
{* ../../docs_src/dataclasses_/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}

1. Ainda importamos `field` das `dataclasses` padrão.

Expand Down
2 changes: 1 addition & 1 deletion docs/pt/docs/how-to/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Dependendo do seu caso de uso, você pode preferir usar uma biblioteca diferente

Aqui está uma pequena prévia de como você poderia integrar Strawberry com FastAPI:

{* ../../docs_src/graphql/tutorial001_py39.py hl[3,22,25] *}
{* ../../docs_src/graphql_/tutorial001_py39.py hl[3,22,25] *}

Você pode aprender mais sobre Strawberry na <a href="https://strawberry.rocks/" class="external-link" target="_blank">documentação do Strawberry</a>.

Expand Down
6 changes: 3 additions & 3 deletions docs/ru/docs/advanced/dataclasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FastAPI построен поверх **Pydantic**, и я показывал в

Но FastAPI также поддерживает использование <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a> тем же способом:

{* ../../docs_src/dataclasses/tutorial001_py310.py hl[1,6:11,18:19] *}
{* ../../docs_src/dataclasses_/tutorial001_py310.py hl[1,6:11,18:19] *}

Это по-прежнему поддерживается благодаря **Pydantic**, так как в нём есть <a href="https://docs.pydantic.dev/latest/concepts/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">встроенная поддержка `dataclasses`</a>.

Expand Down Expand Up @@ -32,7 +32,7 @@ FastAPI построен поверх **Pydantic**, и я показывал в

Вы также можете использовать `dataclasses` в параметре `response_model`:

{* ../../docs_src/dataclasses/tutorial002_py310.py hl[1,6:12,18] *}
{* ../../docs_src/dataclasses_/tutorial002_py310.py hl[1,6:12,18] *}

Этот dataclass будет автоматически преобразован в Pydantic dataclass.

Expand All @@ -48,7 +48,7 @@ FastAPI построен поверх **Pydantic**, и я показывал в

В таком случае вы можете просто заменить стандартные `dataclasses` на `pydantic.dataclasses`, которая является полностью совместимой заменой (drop-in replacement):

{* ../../docs_src/dataclasses/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}
{* ../../docs_src/dataclasses_/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}

1. Мы по-прежнему импортируем `field` из стандартных `dataclasses`.

Expand Down
2 changes: 1 addition & 1 deletion docs/ru/docs/how-to/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

Вот небольшой пример того, как можно интегрировать Strawberry с FastAPI:

{* ../../docs_src/graphql/tutorial001_py39.py hl[3,22,25] *}
{* ../../docs_src/graphql_/tutorial001_py39.py hl[3,22,25] *}

Подробнее о Strawberry можно узнать в <a href="https://strawberry.rocks/" class="external-link" target="_blank">документации Strawberry</a>.

Expand Down
6 changes: 3 additions & 3 deletions docs/zh/docs/advanced/dataclasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FastAPI 基于 **Pydantic** 构建,前文已经介绍过如何使用 Pydantic

但 FastAPI 还可以使用数据类(<a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a>):

{* ../../docs_src/dataclasses/tutorial001.py hl[1,7:12,19:20] *}
{* ../../docs_src/dataclasses_/tutorial001.py hl[1,7:12,19:20] *}

这还是借助于 **Pydantic** 及其<a href="https://pydantic-docs.helpmanual.io/usage/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">内置的 `dataclasses`</a>。

Expand Down Expand Up @@ -32,7 +32,7 @@ FastAPI 基于 **Pydantic** 构建,前文已经介绍过如何使用 Pydantic

在 `response_model` 参数中使用 `dataclasses`:

{* ../../docs_src/dataclasses/tutorial002.py hl[1,7:13,19] *}
{* ../../docs_src/dataclasses_/tutorial002.py hl[1,7:13,19] *}

本例把数据类自动转换为 Pydantic 数据类。

Expand All @@ -49,7 +49,7 @@ API 文档中也会显示相关概图:
本例把标准的 `dataclasses` 直接替换为 `pydantic.dataclasses`:

```{ .python .annotate hl_lines="1 5 8-11 14-17 23-25 28" }
{!../../docs_src/dataclasses/tutorial003.py!}
{!../../docs_src/dataclasses_/tutorial003.py!}
```

1. 本例依然要从标准的 `dataclasses` 中导入 `field`;
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added docs_src/body/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added docs_src/cors/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added docs_src/debugging/__init__.py
Empty file.
Empty file.
Empty file.
Empty file added docs_src/encoder/__init__.py
Empty file.
Empty file added docs_src/events/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added docs_src/graphql_/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added docs_src/metadata/__init__.py
Empty file.
Empty file added docs_src/middleware/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added docs_src/security/__init__.py
Empty file.
Empty file.
Empty file added docs_src/settings/__init__.py
Empty file.
Empty file.
Empty file.
Empty file added docs_src/templates/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added docs_src/wsgi/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ dynamic_context = "test_function"
omit = [
"docs_src/response_model/tutorial003_04_py39.py",
"docs_src/response_model/tutorial003_04_py310.py",
"docs_src/dependencies/tutorial008_an_py39.py", # difficult to mock
"docs_src/dependencies/tutorial013_an_py310.py", # temporary code example?
"docs_src/dependencies/tutorial014_an_py310.py", # temporary code example?
# Pydantic V1
"docs_src/schema_extra_example/tutorial001_pv1_py310.py",
"docs_src/query_param_models/tutorial002_pv1_py310.py",
"docs_src/query_param_models/tutorial002_pv1_an_py310.py",
"docs_src/header_param_models/tutorial002_pv1_py310.py",
"docs_src/header_param_models/tutorial002_pv1_an_py310.py",
"docs_src/cookie_param_models/tutorial002_pv1_py310.py",
"docs_src/cookie_param_models/tutorial002_pv1_an_py310.py",
]

[tool.coverage.report]
Expand Down
1 change: 1 addition & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mypy ==1.14.1
dirty-equals ==0.9.0
sqlmodel==0.0.27
flask >=1.1.2,<4.0.0
strawberry-graphql >=0.200.0,< 1.0.0
anyio[trio] >=3.2.1,<5.0.0
PyJWT==2.9.0
pyyaml >=5.3.1,<7.0.0
Expand Down
161 changes: 161 additions & 0 deletions tests/test_tutorial/test_body/test_tutorial002.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import importlib
from typing import Union

import pytest
from fastapi.testclient import TestClient

from ...utils import needs_py310


@pytest.fixture(
name="client",
params=[
pytest.param("tutorial002_py39"),
pytest.param("tutorial002_py310", marks=needs_py310),
],
)
def get_client(request: pytest.FixtureRequest):
mod = importlib.import_module(f"docs_src.body.{request.param}")

client = TestClient(mod.app)
return client


@pytest.mark.parametrize("price", ["50.5", 50.5])
def test_post_with_tax(client: TestClient, price: Union[str, float]):
response = client.post(
"/items/",
json={"name": "Foo", "price": price, "description": "Some Foo", "tax": 0.3},
)
assert response.status_code == 200
assert response.json() == {
"name": "Foo",
"price": 50.5,
"description": "Some Foo",
"tax": 0.3,
"price_with_tax": 50.8,
}


@pytest.mark.parametrize("price", ["50.5", 50.5])
def test_post_without_tax(client: TestClient, price: Union[str, float]):
response = client.post(
"/items/", json={"name": "Foo", "price": price, "description": "Some Foo"}
)
assert response.status_code == 200
assert response.json() == {
"name": "Foo",
"price": 50.5,
"description": "Some Foo",
"tax": None,
}


def test_post_with_no_data(client: TestClient):
response = client.post("/items/", json={})
assert response.status_code == 422
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "name"],
"msg": "Field required",
"input": {},
},
{
"type": "missing",
"loc": ["body", "price"],
"msg": "Field required",
"input": {},
},
]
}


def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == {
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/items/": {
"post": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
},
},
},
"summary": "Create Item",
"operationId": "create_item_items__post",
"requestBody": {
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/Item"}
}
},
"required": True,
},
}
}
},
"components": {
"schemas": {
"Item": {
"title": "Item",
"required": ["name", "price"],
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"price": {"title": "Price", "type": "number"},
"description": {
"title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}],
},
"tax": {
"title": "Tax",
"anyOf": [{"type": "number"}, {"type": "null"}],
},
},
},
"ValidationError": {
"title": "ValidationError",
"required": ["loc", "msg", "type"],
"type": "object",
"properties": {
"loc": {
"title": "Location",
"type": "array",
"items": {
"anyOf": [{"type": "string"}, {"type": "integer"}]
},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
},
},
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"},
}
},
},
}
},
}
Loading