Commit Graph

429 Commits

Author SHA1 Message Date
Sebastián Ramírez 4881d1e225
📝 Update docs for `fastapi-cli` (#13031)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-12-04 15:38:39 +01:00
Abdullah Hashim 4f8157588e
🐛 Preserve traceback when exception is raised in sync dependency with `yield` (#5823)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-12-03 23:37:12 +01:00
Tamir Duberstein bf4fad1fda
♻️ Update tests and internals for compatibility with Pydantic >=2.10 (#12971)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-11-22 18:09:25 +01:00
Sebastián Ramírez 5c080d81ae
📝 Update includes for `docs/en/docs/tutorial/schema-extra-example.md` (#12822) 2024-11-09 16:00:17 +00:00
Sebastián Ramírez b31cbbf5f5
♻️ Update logic to import and check `python-multipart` for compatibility with newer version (#12627) 2024-10-27 21:46:26 +00:00
Felix Fanghaenel e049fc4ea1
🐛 Fix openapi generation with responses kwarg (#10895)
Co-authored-by: flxdot <felix.fanghaenel@nitrex.com>
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
Co-authored-by: Sławek Ehlert <slawomir.ehlert@gmail.com>
2024-10-12 11:44:57 +02:00
Sebastián Ramírez 7daaac2bc3
Add new tutorial for SQL databases with SQLModel (#12285) 2024-10-09 21:44:42 +02:00
Sebastián Ramírez 55035f440b
Add support for Pydantic models for parameters using `Query`, `Cookie`, `Header` (#12199) 2024-09-17 20:54:10 +02:00
Nico Tonnhofer 88d4f2cb18
🐛 Fix form field regression (#12194) 2024-09-13 11:51:00 +02:00
Sebastián Ramírez b0eedbb580
️ Improve performance in request body parsing with a cache for internal model fields (#12184) 2024-09-11 09:45:30 +02:00
Sebastián Ramírez 4633b1bca9
Add support for forbidding extra form fields with Pydantic models (#12134)
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
2024-09-06 19:31:18 +02:00
Sebastián Ramírez c411b81c29
Update internal tests for latest Pydantic, including CI tweaks to install the latest Pydantic (#12147) 2024-09-06 15:57:43 +00:00
Sebastián Ramírez 7bad7c0975
Add support for Pydantic models in `Form` parameters (#12129)
Revert "️ Temporarily revert " Add support for Pydantic models in `Form` pa…"

This reverts commit 8e6cf9ee9c.
2024-09-05 17:16:50 +02:00
Sebastián Ramírez 8e6cf9ee9c
️ Temporarily revert " Add support for Pydantic models in `Form` parameters" to make a checkpoint release (#12128)
Revert " Add support for Pydantic models in `Form` parameters (#12127)"

This reverts commit 0f3e65b007.
2024-09-05 16:55:44 +02:00
Sebastián Ramírez 0f3e65b007
Add support for Pydantic models in `Form` parameters (#12127) 2024-09-05 16:40:48 +02:00
Sebastián Ramírez aa21814a89
♻️ Refactor deciding if `embed` body fields, do not overwrite fields, compute once per router, refactor internals in preparation for Pydantic models in `Form`, `Query` and others (#12117) 2024-09-05 13:24:36 +02:00
Giunio 51b625e127
🐛 Fix `allow_inf_nan` option for Param and Body classes (#11867)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: svlandeg <svlandeg@github.com>
2024-08-24 14:27:37 -05:00
Pastukhov Nikita 3a4ac24675
🐛 Ensure that `app.include_router` merges nested lifespans (#9630)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2024-08-24 14:09:52 -05:00
Sebastián Ramírez 3a3ad5d66d
⬆️ Upgrade version of Ruff and reformat (#12032)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-08-16 23:13:50 -05:00
Sebastián Ramírez a25c92ceb9
♻️ Add support for `pip install "fastapi[standard]"` with standard dependencies and `python -m fastapi` (#11935)
* ♻️ Add support for `pip install "fastapi[standard]"` and make `fastapi` not include the optional standard dependencies

* 📝 Update docs to include new fastapi[standard]

*  Add new stub fastapi command that tells people to install fastapi[standard]

*  Add tests for new stub CLI

* 🔧 Add new command fastapi in main fastapi project, for when fastapi-cli is not installed

* ✏️ Fix types

* 📝 Add note about quotes when installing fastapi[standard]

* 📝 Update docs about standard extra dependencies

* ⬆️ Upgrade fastapi-cli
2024-08-02 01:03:05 -05:00
jianghuyiyuan 2e35b176cf
✏️ Fix typos in docs (#11926) 2024-07-31 09:09:15 -05:00
Nir Schulman a69f38340f
📝 Restored Swagger-UI links to use the latest version possible. (#11459) 2024-05-23 17:59:02 -05:00
Nils Lindemann 6d523d62d0
📝 Fix types in examples under `docs_src/extra_data_types` (#10535)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2024-04-18 19:11:40 -05:00
arjwilliams 09e4859cab
🐛 Fix support for query parameters with list types, handle JSON encoding Pydantic `UndefinedType` (#9929)
Co-authored-by: Andrew Williams <Andrew.Williams@contemi.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2024-04-18 16:56:59 -05:00
Sebastián Ramírez 27da0d02a7
Add support for Pydantic's 2.7 new deprecated Field parameter, remove URL from validation errors response (#11461) 2024-04-18 14:40:57 -05:00
Nadav Zingerman eec612ca8d
🐛 Fix parameterless `Depends()` with generics (#9479)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2024-04-01 21:52:56 -05:00
Charlie Marsh 5ccc869fee
⬆️ Upgrade configuration for Ruff v0.2.0 (#11075) 2024-03-26 11:56:53 -05:00
Alejandra 93034fea48
📝 Update links to Pydantic docs to point to new website (#11328) 2024-03-21 20:42:11 -05:00
bebop 478288700a
📝 Update examples for tests to replace "inexistent" for "nonexistent" (#11220) 2024-03-13 20:07:10 +01:00
Sebastián Ramírez bf771bd781
🐛 Fix unhandled growing memory for internal server errors, refactor dependencies with `yield` and `except` to require raising again as in regular Python (#11191)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-02-25 00:06:37 +01:00
Emmett Butler f18eadb7de
Refactor tests for duplicate operation ID generation for compatibility with other tools running the FastAPI test suite (#10876)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2024-01-13 16:10:26 +01:00
ooknimm be0bd34446
Re-enable test in `tests/test_tutorial/test_header_params/test_tutorial003.py` after fix in Starlette (#10904)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-01-12 15:52:00 +01:00
Ezzeddin Abdullah 0c796747a3
📝 Update template docs with more info about `url_for` (#5937)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2024-01-11 23:25:37 +01:00
Sebastián Ramírez dd790c34ff
✏️ Fix typo in dependencies with yield source examples (#10847) 2023-12-26 21:37:34 +01:00
Sebastián Ramírez a4aa79e0b4
Add support for raising exceptions (including `HTTPException`) in dependencies with `yield` in the exit code, do not support them in background tasks (#10831)
* ♻️ Refactor dependency AsyncExitStack logic, exit dependencies after creating the response, before sending it

*  Update tests for dependencies exit, check they are finished before the response is sent

* 🔥 Remove ExitAsyncStackMiddleware as it's no longer needed

* 📝 Update docs for dependencies with yield

* 📝 Update release notes

* 📝 Add source examples for new dependencies with yield raising

*  Add tests for new dependencies raising after yield

* 📝 Update release notes
2023-12-25 18:57:35 +01:00
Sebastián Ramírez 6f5aa81c07
Add support for multiple Annotated annotations, e.g. `Annotated[str, Field(), Query()]` (#10773) 2023-12-12 00:22:47 +00:00
Alejandra Klachquin 758a8f29e1
📌 Pin Swagger UI version to 5.9.0 temporarily to handle a bug crashing it in 5.9.1 (#10529)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-10-30 13:58:58 +04:00
Sebastián Ramírez 2e14c69c31
👷 Adopt Ruff format (#10517)
* 🔧 Update pre-commit, use ruff format

* ⬆️ Upgrade dependencies, use Ruff for formatting

* 🔧 Update Ruff config

* 🔨 Update lint and format scripts, use Ruff

* 🎨 Format internals with Ruff

* 🎨 Format docs scripts

* 🎨 Format tests

* 🎨 Format extra commas in src for docs

* 📝 Update docs mentioning `@lru_cache()`, use `@lru_cache` instead to keep consistency with the format

* 🎨 Update src for docs, use plain `@lru_cache`

* 🎨 Update src for docs format and docs references
2023-10-25 00:26:06 +04:00
Heinz-Alexander Fuetterer ae84ff6e44
✏️ Fix typos in emoji docs and in some source examples (#10438) 2023-10-20 13:00:44 +04:00
Sebastián Ramírez 05ca41cfd1
Add reference (code API) docs with PEP 727, add subclass with custom docstrings for `BackgroundTasks`, refactor docs structure (#10392)
*  Add mkdocstrings and griffe-typingdoc to dependencies

* 🔧 Add mkdocstrings configs to MkDocs

* 📝 Add first WIP reference page

* ⬆️ Upgrade typing-extensions to the minimum version including Doc()

* 📝 Add docs to FastAPI parameters

* 📝 Add docstrings for OpenAPI docs utils

* 📝 Add docstrings for security utils

* 📝 Add docstrings for UploadFile

* 📝 Update docstrings in FastAPI class

* 📝 Add docstrings for path operation methods

* 📝 Add docstring for jsonable_encoder

* 📝 Add docstrings for exceptions

* 📝 Add docstsrings for parameter functions

* 📝 Add docstrings for responses

* 📝 Add docstrings for APIRouter

* ♻️ Sub-class BackgroundTasks to document it with docstrings

* 📝 Update usage of background tasks in dependencies

*  Update tests with new deprecation warnings

* 📝 Add new reference docs

* 🔧 Update MkDocs with new reference docs

*  Update pytest fixture, deprecation is raised only once

* 🎨 Update format for types in exceptions.py

* ♻️ Update annotations in BackgroundTask, `Annotated` can't take ParamSpec's P.args or P.kwargs

* ✏️ Fix typos caught by @pawamoy

* 🔧 Update and fix MkDocstrings configs from @pawamoy tips

* 📝 Update reference docs

* ✏️ Fix typos found by @pawamoy

*  Add HTTPX as a dependency for docs, for the TestClient

* 🔧 Update MkDocs config, rename websockets reference

* 🔇 Add type-ignores for Doc as the stubs haven't been released for mypy

* 🔥 Remove duplicated deprecated notice

* 🔇 Remove typing error for unreleased stub in openapi/docs.py

*  Add tests for UploadFile for coverage

* ⬆️ Upgrade griffe-typingdoc==0.2.2

* 📝 Refactor docs structure

* 🔨 Update README generation with new index frontmatter and style

* 🔨 Update generation of languages, remove from top menu, keep in lang menu

* 📝 Add OpenAPI Pydantic models

* 🔨 Update docs script to not translate Reference and Release Notes

* 🔧 Add reference for OpenAPI models

* 🔧 Update MkDocs config for mkdocstrings insiders

* 👷 Install mkdocstring insiders in CI for docs

* 🐛 Fix MkDocstrings insiders install URL

*  Move dependencies shared by docs and tests to its own requirements file

* 👷 Update cache keys for test and docs dependencies

* 📝 Remove no longer needed __init__ placeholder docstrings

* 📝 Move docstring for APIRouter to the class level (not __init__ level)

* 🔥 Remove no longer needed dummy placeholder __init__ docstring
2023-10-18 16:36:40 +04:00
Sebastián Ramírez bc935e08b6
⬆️ Upgrade compatibility with Pydantic v2.4, new renamed functions and JSON Schema input/output models with default values (#10344)
* 🚚 Refactor deprecated import general_plain_validator_function to with_info_plain_validator_function

* 🚚 Rename deprecated FieldValidationInfo to ValidationInfo

*  Update tests with new defaults for JSON Schema for default values

* ♻️ Add Pydantic v1 version of with_info_plain_validator_function

* 👷 Invalidate cache

*  Fix tests for Pydantic v1

*  Tweak tests coverage for older Pydantic v2 versions
2023-09-27 23:14:40 -05:00
Sebastián Ramírez 37d46e6b6c
Add missing test for OpenAPI examples, it was missing in coverage (#10188)
 Add missing test for OpenAPI examples, it seems it was discovered in coverage by an upgrade in AnyIO
2023-09-01 23:36:08 +02:00
Sebastián Ramírez 1b714b3177
Add support for `openapi_examples` in all FastAPI parameters (#10152)
* ♻️ Refactor model for OpenAPI Examples to use a reusable TypedDict

*  Add support for openapi_examples in parameters

* 📝 Add new docs examples for new parameter openapi_examples

* 📝 Update docs for Schema Extra to include OpenAPI examples

*  Add tests for new source examples, for openapi_examples

*  Add tests for openapi_examples corner cases and all parameters

* 💡 Tweak and ignore type annotation checks for custom TypedDict
2023-08-26 20:03:13 +02:00
Sebastián Ramírez ea43f227e5
Add support for disabling the separation of input and output JSON Schemas in OpenAPI with Pydantic v2 (#10145)
* 📝 Add docs for Separate OpenAPI Schemas for Input and Output

* 🔧 Add new docs page to MkDocs config

*  Add separate_input_output_schemas parameter to FastAPI class

* 📝 Add source examples for separating OpenAPI schemas

*  Add tests for separated OpenAPI schemas

* 📝 Add source examples for Python 3.10, 3.9, and 3.7+

* 📝 Update docs for Separate OpenAPI Schemas with new multi-version examples

*  Add and update tests for different Python versions

*  Add tests for corner cases with separate_input_output_schemas

* 📝 Update tutorial to use Union instead of Optional

* 🐛 Fix type annotations

* 🐛 Fix correct import in test

* 💄 Add CSS to simulate browser windows for screenshots

*  Add playwright as a dev dependency to automate generating screenshots

* 🔨 Add Playwright scripts to generate screenshots for new docs

* 📝 Update docs, tweak text to match screenshots

* 🍱 Add screenshots for new docs
2023-08-25 21:10:22 +02:00
Sebastián Ramírez 8cd7cfc2b6
📝 Add new docs section, How To - Recipes, move docs that don't have to be read by everyone to How To (#10114)
* 📝 Start How To docs section, move Peewee, remove Peewee from dependencies

* 🚚 Move em files to new locations

* 🚚 Move and re-structure advanced docs, move relevant to How To

* 🔧 Update MkDocs config, new files in How To

* 📝 Move docs for Conditional OpenAPI for Japanese to How To

* 📝 Move example source files for Extending OpenAPI into each of the new sections

*  Update tests with new locations for source files

* 🔥 Remove init from Peewee examples
2023-08-19 21:54:04 +02:00
Sebastián Ramírez 7a06de2bb9
♻️ Refactor tests for new Pydantic 2.2.1 (#10115) 2023-08-19 20:47:59 +02:00
Sebastián Ramírez 5e8f7f13d7
Add `ResponseValidationError` printable details, to show up in server error logs (#10078) 2023-08-14 11:49:57 +02:00
Sebastián Ramírez 19a2c3bb54
Enable Pydantic's serialization mode for responses, add support for Pydantic's `computed_field`, better OpenAPI for response models, proper required attributes, better generated clients (#10011)
*  Enable Pydantic's serialization mode for responses

*  Update tests with new Pydantic v2 serialization mode

*  Add a test for Pydantic v2's computed_field
2023-08-04 22:47:07 +02:00
David Montague 25694f5ae1
Fix tests for compatibility with pydantic 2.1.1 (#9943)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-08-03 17:46:57 +02:00
Irfanuddin Shafi Ahmed 37818f553d
Fix test error in Windows for `jsonable_encoder` (#9840)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-08-02 17:28:34 +02:00
Sebastián Ramírez 0976185af9
Add support for Pydantic v2 (#9816)
*  Pydantic v2 migration, initial implementation (#9500)

*  Add compat layer, for Pydantic v1 and v2

*  Re-export Pydantic needed internals from compat, to later patch them for v1

* ♻️ Refactor internals to use new compatibility layers and run with Pydantic v2

* 📝 Update examples to run with Pydantic v2

*  Update tests to use Pydantic v2

* 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

*  Temporarily disable Peewee tests, afterwards I'll enable them only for Pydantic v1

* 🐛 Fix JSON Schema generation and OpenAPI ref template

* 🐛 Fix model field creation with defaults from Pydantic v2

* 🐛 Fix body field creation, with new FieldInfo

*  Use and check new ResponseValidationError for server validation errors

*  Fix test_schema_extra_examples tests with ResponseValidationError

*  Add dirty-equals to tests for compatibility with Pydantic v1 and v2

*  Add util to regenerate errors with custom loc

*  Generate validation errors with loc

*  Update tests for compatibility with Pydantic v1 and v2

*  Update tests for Pydantic v2 in tests/test_filter_pydantic_sub_model.py

*  Refactor tests in tests/test_dependency_overrides.py for Pydantic v2, separate parameterized into independent tests to use insert_assert

*  Refactor OpenAPI test for tests/test_infer_param_optionality.py for consistency, and make it compatible with Pydantic v1 and v2

*  Update tests for tests/test_multi_query_errors.py for Pydantic v1 and v2

*  Update tests for tests/test_multi_body_errors.py for Pydantic v1 and v2

*  Update tests for tests/test_multi_body_errors.py for Pydantic v1 and v2

* 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

* ♻️ Refactor tests for tests/test_path.py to inline pytest parameters, to make it easier to make them compatible with Pydantic v2

*  Refactor and udpate tests for tests/test_path.py for Pydantic v1 and v2

* ♻️ Refactor and update tests for tests/test_query.py with compatibility for Pydantic v1 and v2

*  Fix test with optional field without default None

*  Update tests for compatibility with Pydantic v2

*  Update tutorial tests for Pydantic v2

* ♻️ Update OAuth2 dependencies for Pydantic v2

* ♻️ Refactor str check when checking for sequence types

* ♻️ Rename regex to pattern to keep in sync with Pydantic v2

* ♻️ Refactor _compat.py, start moving conditional imports and declarations to specifics of Pydantic v1 or v2

*  Update tests for OAuth2 security optional

*  Refactor tests for OAuth2 optional for Pydantic v2

*  Refactor tests for OAuth2 security for compatibility with Pydantic v2

* 🐛 Fix location in compat layer for Pydantic v2 ModelField

*  Refactor tests for Pydantic v2 in tests/test_tutorial/test_bigger_applications/test_main_an_py39.py

* 🐛 Add missing markers in Python 3.9 tests

*  Refactor tests for bigger apps for consistency with annotated ones and with support for Pydantic v2

* 🐛 Fix jsonable_encoder with new Pydantic v2 data types and Url

* 🐛 Fix invalid JSON error for compatibility with Pydantic v2

*  Update tests for behind_a_proxy for Pydantic v2

*  Update tests for tests/test_tutorial/test_body/test_tutorial001_py310.py for Pydantic v2

*  Update tests for tests/test_tutorial/test_body/test_tutorial001.py with Pydantic v2 and consistency with Python 3.10 tests

*  Fix tests for tutorial/body_fields for Pydantic v2

*  Refactor tests for tutorial/body_multiple_params with Pydantic v2

*  Update tests for tutorial/body_nested_models for Pydantic v2

*  Update tests for tutorial/body_updates for Pydantic v2

*  Update test for tutorial/cookie_params for Pydantic v2

*  Fix tests for tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py for Pydantic v2

*  Update tests for tutorial/dataclasses for Pydantic v2

*  Update tests for tutorial/dependencies for Pydantic v2

*  Update tests for tutorial/extra_data_types for Pydantic v2

*  Update tests for tutorial/handling_errors for Pydantic v2

*  Fix test markers for Python 3.9

*  Update tests for tutorial/header_params for Pydantic v2

*  Update tests for Pydantic v2 in tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py

*  Fix extra tests for Pydantic v2

*  Refactor test for parameters, to later fix Pydantic v2

*  Update tests for tutorial/query_params for Pydantic v2

* ♻️ Update examples in docs to use new pattern instead of the old regex

*  Fix several tests for Pydantic v2

*  Update and fix test for ResponseValidationError

* 🐛 Fix check for sequences vs scalars, include bytes as scalar

* 🐛 Fix check for complex data types, include UploadFile

* 🐛 Add list to sequence annotation types

* 🐛 Fix checks for uploads and add utils to find if an annotation is an upload (or bytes)

*  Add UnionType and NoneType to compat layer

*  Update tests for request_files for compatibility with Pydantic v2 and consistency with other tests

*  Fix testsw for request_forms for Pydantic v2

*  Fix tests for request_forms_and_files for Pydantic v2

*  Fix tests in tutorial/security for compatibility with Pydantic v2

* ⬆️ Upgrade required version of email_validator

*  Fix tests for params repr

*  Add Pydantic v2 pytest markers

* Use match_pydantic_error_url

* 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

* Use field_serializer instead of encoders in some tests

* Show Undefined as ... in repr

* Mark custom encoders test with xfail

* Update test to reflect new serialization of Decimal as str

* Use `model_validate` instead of `from_orm`

* Update JSON schema to reflect required nullable

* Add dirty-equals to pyproject.toml

* Fix locs and error creation for use with pydantic 2.0a4

* Use the type adapter for serialization. This is hacky.

* 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

*  Refactor test_multi_body_errors for compatibility with Pydantic v1 and v2

*  Refactor test_custom_encoder for Pydantic v1 and v2

*  Set input to None for now, for compatibility with current tests

* 🐛 Fix passing serialization params to model field when handling the response

* ♻️ Refactor exceptions to not depend on Pydantic ValidationError class

* ♻️ Revert/refactor params to simplify repr

*  Tweak tests for custom class encoders for Pydantic v1 and v2

*  Tweak tests for jsonable_encoder for Pydantic v1 and v2

*  Tweak test for compatibility with Pydantic v1 and v2

* 🐛 Fix filtering data with subclasses

* 🐛 Workaround examples in OpenAPI schema

*  Add skip marker for SQL tutorial, needs to be updated either way

*  Update test for broken JSON

*  Fix test for broken JSON

*  Update tests for timedeltas

*  Fix test for plain text validation errors

*  Add markers for Pydantic v1 exclusive tests (for now)

*  Update test for path_params with enums for compatibility with Pydantic v1 and v2

*  Update tests for extra examples in OpenAPI

*  Fix tests for response_model with compatibility with Pydantic v1 and v2

* 🐛 Fix required double serialization for different types of models

*  Fix tests for response model with compatibility with new Pydantic v2

* 🐛 Import Undefined from compat layer

*  Fix tests for response_model for Pydantic v2

*  Fix tests for schema_extra for Pydantic v2

*  Add markers and update tests for Pydantic v2

* 💡 Comment out logic for double encoding that breaks other usecases

*  Update errors for int parsing

* ♻️ Refactor re-enabling compatibility for Pydantic v1

* ♻️ Refactor OpenAPI utils to re-enable support for Pydantic v1

* ♻️ Refactor dependencies/utils and _compat for compatibility with Pydantic v1

* 🐛 Fix and tweak compatibility with Pydantic v1 and v2 in dependencies/utils

*  Tweak tests and examples for Pydantic v1

* ♻️ Tweak call to ModelField.validate for compatibility with Pydantic v1

*  Use new global override TypeAdapter from_attributes

*  Update tests after updating from_attributes

* 🔧 Update pytest config to avoid collecting tests from docs, useful for editor-integrated tests

*  Add test for data filtering, including inheritance and models in fields or lists of models

* ♻️ Make OpenAPI models compatible with both Pydantic v1 and v2

* ♻️ Fix compatibility for Pydantic v1 and v2 in jsonable_encoder

* ♻️ Fix compatibility in params with Pydantic v1 and v2

* ♻️ Fix compatibility when creating a FieldInfo in Pydantic v1 and v2 in utils.py

* ♻️ Fix generation of flat_models and JSON Schema definitions in _compat.py for Pydantic v1 and v2

* ♻️ Update handling of ErrorWrappers for Pydantic v1

* ♻️ Refactor checks and handling of types an sequences

* ♻️ Refactor and cleanup comments with compatibility for Pydantic v1 and v2

* ♻️ Update UploadFile for compatibility with both Pydantic v1 and v2

* 🔥 Remove commented out unneeded code

* 🐛 Fix mock of get_annotation_from_field_info for Pydantic v1 and v2

* 🐛 Fix params with compatibility for Pydantic v1 and v2, with schemas and new pattern vs regex

* 🐛 Fix check if field is sequence for Pydantic v1

*  Fix tests for custom_schema_fields, for compatibility with Pydantic v1 and v2

*  Simplify and fix tests for jsonable_encoder with compatibility for Pydantic v1 and v2

*  Fix tests for orm_mode with Pydantic v1 and compatibility with Pydantic v2

* ♻️ Refactor logic for normalizing Pydantic v1 ErrorWrappers

* ♻️ Workaround for params with examples, before defining what to deprecate in Pydantic v1 and v2 for examples with JSON Schema vs OpenAPI

*  Fix tests for Pydantic v1 and v2 for response_by_alias

*  Fix test for schema_extra with compatibility with Pydantic v1 and v2

* ♻️ Tweak error regeneration with loc

* ♻️ Update error handling and serializationwith compatibility for Pydantic v1 and v2

* ♻️ Re-enable custom encoders for Pydantic v1

* ♻️ Update ErrorWrapper reserialization in Pydantic v1, do it outside of FastAPI ValidationExceptions

*  Update test for filter_submodel, re-structure to simplify testing while keeping division of Pydantic v1 and v2

*  Refactor Pydantic v1 only test that requires modifying environment variables

* 🔥 Update test for plaintext error responses, for Pydantic v1 and v2

* ️ Revert changes in DB tutorial to use Pydantic v1 (the new guide will have SQLModel)

*  Mark current SQL DB tutorial tests as Pydantic only

* ♻️ Update datastructures for compatibility with Pydantic v1, not requiring pydantic-core

* ♻️ Update encoders.py for compatibility with Pydantic v1

* ️ Revert changes to Peewee, the docs for that are gonna live in a new HowTo section, not in the main tutorials

* ♻️ Simplify response body kwargs generation

* 🔥 Clean up comments

* 🔥 Clean some tests and comments

*  Refactor tests to match new Pydantic error string URLs

*  Refactor tests for recursive models for Pydantic v1 and v2

*  Update tests for Peewee, re-enable, Pydantic-v1-only

* ♻️ Update FastAPI params to take regex and pattern arguments

* ️ Revert tutorial examples for pattern, it will be done in a subsequent PR

* ️ Revert changes in schema extra examples, it will be added later in a docs-specific PR

* 💡 Add TODO comment to document str validations with pattern

* 🔥 Remove unneeded comment

* 📌 Upgrade Pydantic pin dependency

* ⬆️ Upgrade email_validator dependency

* 🐛 Tweak type annotations in _compat.py

* 🔇 Tweak mypy errors for compat, for Pydantic v1 re-imports

* 🐛 Tweak and fix type annotations

*  Update requirements-test.txt, re-add dirty-equals

* 🔥 Remove unnecessary config

* 🐛 Tweak type annotations

* 🔥 Remove unnecessary type in dependencies/utils.py

* 💡 Update comment in routing.py

---------

Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* 👷 Add CI for both Pydantic v1 and v2 (#9688)

* 👷 Test and install Pydantic v1 and v2 in CI

* 💚 Tweak CI config for Pydantic v1 and v2

* 💚 Fix Pydantic v2 specification in CI

* 🐛 Fix type annotations for compatibility with Python 3.7

* 💚 Install Pydantic v2 for lints

* 🐛 Fix type annotations for Pydantic v2

* 💚 Re-use test cache for lint

* ♻️ Refactor internals for test coverage and performance (#9691)

* ♻️ Tweak import of Annotated from typing_extensions, they are installed anyway

* ♻️ Refactor _compat to define functions for Pydantic v1 or v2 once instead of checking inside

*  Add test for UploadFile for Pydantic v2

* ♻️ Refactor types and remove logic for impossible cases

*  Add missing tests from test refactor for path params

*  Add tests for new decimal encoder

* 💡 Add TODO comment for decimals in encoders

* 🔥 Remove unneeded dummy function

* 🔥 Remove section of code in field_annotation_is_scalar covered by sub-call to field_annotation_is_complex

* ♻️ Refactor and tweak variables and types in _compat

*  Add tests for corner cases and compat with Pydantic v1 and v2

* ♻️ Refactor type annotations

* 🔖 Release version 0.100.0-beta1

* ♻️ Refactor parts that use optional requirements to make them compatible with installations without them (#9707)

* ♻️ Refactor parts that use optional requirements to make them compatible with installations without them

* ♻️ Update JSON Schema for email field without email-validator installed

* 🐛 Fix support for Pydantic v2.0, small changes in their final release (#9771)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

* 🔖 Release version 0.100.0-beta2

*  OpenAPI 3.1.0 with Pydantic v2, merge `master` (#9773)

*  Add dirty-equals as a testing dependency (#9778)

 Add dirty-equals as a testing dependency, it seems it got lsot at some point

* 🔀 Merge master, fix valid JSON Schema accepting bools (#9782)

* ️ Revert usage of custom logic for TypeAdapter JSON Schema, solved on the Pydantic side (#9787)

️ Revert usage of custom logic for TypeAdapter JSON Schema, solved on Pydantic side

* ♻️ Deprecate parameter `regex`, use `pattern` instead (#9786)

* 📝 Update docs to deprecate regex, recommend pattern

* ♻️ Update examples to use new pattern instead of regex

* 📝 Add new example with deprecated regex

* ♻️ Add deprecation notes and warnings for regex

*  Add tests for regex deprecation

*  Update tests for compatibility with Pydantic v1

*  Update docs to use Pydantic v2 settings and add note and example about v1 (#9788)

*  Add pydantic-settings to all extras

* 📝 Update docs for Pydantic settings

* 📝 Update Settings source examples to use Pydantic v2, and add a Pydantic v1 version

*  Add tests for settings with Pydantic v1 and v2

* 🔥 Remove solved TODO comment

* ♻️ Update conditional OpenAPI to use new Pydantic v2 settings

*  Update tests to import Annotated from typing_extensions for Python < 3.9 (#9795)

*  Add pydantic-extra-types to fastapi[extra]

*  temp: Install Pydantic from source to test JSON Schema metadata fixes (#9777)

*  Install Pydantic from source, from branch for JSON Schema with metadata

*  Update dependencies, install Pydantic main

*  Fix dependency URL for Pydantic from source

*  Add pydantic-settings for test requirements

* 💡 Add TODO comments to re-enable Pydantic main (not from source) (#9796)

*  Add new Pydantic Field param options to Query, Cookie, Body, etc. (#9797)

* 📝 Add docs for Pydantic v2 for `docs/en/docs/advanced/path-operation-advanced-configuration.md` (#9798)

* 📝 Update docs in examples for settings with Pydantic v2 (#9799)

* 📝 Update JSON Schema `examples` docs with Pydantic v2 (#9800)

* ♻️ Use new Pydantic v2 JSON Schema generator (#9813)

Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>

* ♻️ Tweak type annotations and Pydantic version range (#9801)

* 📌 Re-enable GA Pydantic, for v2, require minimum 2.0.2 (#9814)

* 🔖 Release version 0.100.0-beta3

* 🔥 Remove duplicate type declaration from merge conflicts (#9832)

* 👷‍♂️ Run tests with Pydantic v2 GA (#9830)

👷 Run tests for Pydantic v2 GA

* 📝 Add notes to docs expecting Pydantic v2 and future updates (#9833)

* 📝 Update index with new extras

* 📝 Update release notes

---------

Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Pastukhov Nikita <diementros@yandex.ru>
2023-07-07 19:12:13 +02:00
Sebastián Ramírez 07e1dea467
🐛 Fix JSON Schema accepting bools as valid JSON Schemas, e.g. `additionalProperties: false` (#9781)
* 🐛 Fix JSON Schema accepting bools as valid JSON Schemas, e.g. additionalProperties: false

*  Add test to ensure additionalProperties can be false

* ♻️ Tweak OpenAPI models to support Pydantic v1's JSON Schema for tuples
2023-07-02 17:58:23 +02:00
Sebastián Ramírez 4d83f984cc
📝 Update source examples to use new JSON Schema examples field (#9776)
* 📝 Update source examples to use new JSON Schema examples field

*  Update tests for JSON Schema examples

* 📝 Update highlights in JSON Schema examples
2023-07-01 18:43:29 +02:00
Sebastián Ramírez 7dad5a820b
Add support for OpenAPI 3.1.0 (#9770)
*  Update OpenAPI models for JSON Schema 2020-12 and OpenAPI 3.1.0

*  Add support for summary and webhooks

*  Update JSON Schema for UploadFiles

* ️ Revert making paths optional, to ensure always correctness

* ️ Keep UploadFile as format: binary for compatibility with the rest of Pydantic bytes fields in v1

*  Update version of OpenAPI generated to 3.1.0

*  Update the version of Swagger UI

* 📝 Update docs about extending OpenAPI

* 📝 Update docs and links to refer to OpenAPI 3.1.0

*  Update logic for handling webhooks

* ♻️ Update parameter functions and classes, deprecate example and make examples the main field

*  Update tests for OpenAPI 3.1.0

* 📝 Update examples for OpenAPI metadata

*  Add and update tests for OpenAPI metadata

* 📝 Add source example for webhooks

* 📝 Update docs for metadata

* 📝 Update docs for Schema extra

* 📝 Add docs for webhooks

* 🔧 Add webhooks docs to MkDocs

*  Update tests for extending OpenAPI

*  Add tests for webhooks

* ♻️ Refactor generation of OpenAPI and JSON Schema with params

* 📝 Update source examples for field examples

*  Update tests for examples

*  Make sure the minimum version of typing-extensions installed has deprecated() (already a dependency of Pydantic)

* ✏️ Fix typo in Webhooks example code

* 🔥 Remove commented out code of removed nullable field

* 🗑️ Add deprecation warnings for example argument

*  Update tests to check for deprecation warnings

*  Add test for webhooks with security schemes, for coverage

* 🍱 Update image for metadata, with new summary

* 🍱 Add docs image for Webhooks

* 📝 Update docs for webhooks, add docs UI image
2023-06-30 20:25:16 +02:00
Carson Crane 1f21b16e03
Add support for `deque` objects and children in `jsonable_encoder` (#9433)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-06-28 18:39:10 +02:00
Ryan Russell b4b39d3359
✏️ Fix typos in data for tests (#4958)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-06-22 11:26:11 +00:00
cyberlis e94c13ce74
Add allow disabling `redirect_slashes` at the FastAPI app level (#3432)
Co-authored-by: Denis Lisovik <ckyberlis@gmail.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-06-22 10:37:50 +00:00
Sebastián Ramírez 7167c77a18
⬆️ Upgrade and fully migrate to Ruff, remove isort, includes a couple of tweaks suggested by the new version of Ruff (#9660) 2023-06-12 00:37:34 +02:00
Paulo Costa d8b8f211e8
Add support for `dependencies` in WebSocket routes (#4534)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-06-11 20:35:39 +00:00
Kristján Valur Jónsson ab03f22635
Add exception handler for `WebSocketRequestValidationError` (which also allows to override it) (#6030)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-06-11 21:08:14 +02:00
Sebastián Ramírez f00f0de9ca
Refactor 2 tests, for consistency and simplification (#9504)
 Refactor tests, for consistency and simplification
2023-05-08 23:36:13 +02:00
Sebastián Ramírez 50c1a928fb
Refactor OpenAPI tests, prepare for Pydantic v2 (#9503)
*  Refactor OpenAPI tests, move inline, prepare for Pydantic v2 tests

*  Fix test module loading for conditional OpenAPI

* 🐛 Fix missing pytest marker

*  Fix test for coverage
2023-05-08 23:07:32 +02:00
Sharon Yogev fdf66c825e
🐛 Fix using `Annotated` in routers or path operations decorated multiple times (#9315)
* Fix: copy FieldInfo from Annotated arguments

We need to copy the field_info to prevent ourselves from
mutating it.  This allows multiple path or nested routers ,etc.

* 📝 Add comment in fastapi/dependencies/utils.py

Co-authored-by: Nadav Zingerman <7372858+nzig@users.noreply.github.com>

*  Extend and tweak tests for Annotated

*  Tweak coverage, it's probably covered by a different version of Python

---------

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: Nadav Zingerman <7372858+nzig@users.noreply.github.com>
2023-04-13 10:49:22 -07:00
Sebastián Ramírez 9eaed2eb37
📝 Update all docs to use `Annotated` as the main recommendation, with new examples and tests (#9268)
* 🍱 Add new source examples with Annotated for Query Params and String Validations

* 📝 Add new docs with Annotated for Query Params and String Validations

* 🚚 Rename incorrectly named tests for Query Params and str validations

*  Add new tests with Annotated for Query Params and Sring Validations examples

* 🍱 Add new examples with Annotated for Intro to Python Types

* 📝 Update Python Types Intro, include Annotated

* 🎨 Fix formatting in Query params and string validation, and highlight

* 🍱 Add new Annotated source examples for Path Params and Numeric Validations

* 📝 Update docs for Path Params and Numeric Validations with Annotated

* 🍱 Add new source examples with Annotated for Body - Multiple Params

* 📝 Update docs with Annotated for Body - Multiple Parameters

*  Add test for new Annotated examples in Body - Multiple Parameters

* 🍱 Add new Annotated source examples for Body Fields

* 📝 Update docs for Body Fields with new Annotated examples

*  Add new tests for new Annotated examples for Body Fields

* 🍱 Add new Annotated source examples for Schema Extra (Example Data)

* 📝 Update docs for Schema Extra with Annotated

*  Add tests for new Annotated examples for Schema Extra

* 🍱 Add new Annnotated source examples for Extra Data Types

* 📝 Update docs with Annotated for Extra Data Types

*  Add tests for new Annotated examples for Extra Data Types

* 🍱 Add new Annotated source examples for Cookie Parameters

* 📝 Update docs for Cookie Parameters with Annotated examples

*  Add tests for new Annotated source examples in Cookie Parameters

* 🍱 Add new Annotated examples for Header Params

* 📝 Update docs with Annotated examples for Header Parameters

*  Add tests for new Annotated examples for Header Params

* 🍱 Add new Annotated examples for Form Data

* 📝 Update Annotated docs for Form Data

*  Add tests for new Annotated examples in Form Data

* 🍱 Add new Annotated source examples for Request Files

* 📝 Update Annotated docs for Request Files

*  Test new Annotated examples for Request Files

* 🍱 Add new Annotated source examples for Request Forms and Files

*  Add tests for new Anotated examples for Request Forms and Files

* 🍱 Add new Annotated source examples for Dependencies and Advanced Dependencies

*  Add tests for new Annotated dependencies

* 📝 Add new docs for using Annotated with dependencies including type aliases

* 📝 Update docs for Classes as Dependencies with Annotated

* 📝 Update docs for Sub-dependencies with Annotated

* 📝 Update docs for Dependencies in path operation decorators with Annotated

* 📝 Update docs for Global Dependencies with Annotated

* 📝 Update docs for Dependencies with yield with Annotated

* 🎨 Update format in example for dependencies with Annotated

* 🍱 Add source examples with Annotated for Security

*  Add tests for new Annotated examples for security

* 📝 Update docs for Security - First Steps with Annotated

* 📝 Update docs for Security: Get Current User with Annotated

* 📝 Update docs for Simple OAuth2 with Password and Bearer with Annotated

* 📝 Update docs for OAuth2 with Password (and hashing), Bearer with JWT tokens with Annotated

* 📝 Update docs for Request Forms and Files with Annotated

* 🍱 Add new source examples for Bigger Applications with Annotated

*  Add new tests for Bigger Applications with Annotated

* 📝 Update docs for Bigger Applications - Multiple Files with Annotated

* 🍱 Add source examples for background tasks with Annotated

* 📝 Update docs for Background Tasks with Annotated

*  Add test for Background Tasks with Anotated

* 🍱 Add new source examples for docs for Testing with Annotated

* 📝 Update docs for Testing with Annotated

*  Add tests for Annotated examples for Testing

* 🍱 Add new source examples for Additional Status Codes with Annotated

*  Add tests for new Annotated examples for Additional Status Codes

* 📝 Update docs for Additional Status Codes with Annotated

* 📝 Update docs for Advanced Dependencies with Annotated

* 📝 Update docs for OAuth2 scopes with Annotated

* 📝 Update docs for HTTP Basic Auth with Annotated

* 🍱 Add source examples with Annotated for WebSockets

*  Add tests for new Annotated examples for WebSockets

* 📝 Update docs for WebSockets with new Annotated examples

* 🍱 Add source examples with Annotated for Settings and Environment Variables

* 📝 Update docs for Settings and Environment Variables with Annotated

* 🍱 Add new source examples for testing dependencies with Annotated

*  Add tests for new examples for testing dependencies

* 📝 Update docs for testing dependencies with new Annotated examples

*  Update and fix marker for Python 3.9 test

* 🔧 Update Ruff ignores for source examples in docs

*  Fix some tests in the grid for Python 3.9 (incorrectly testing 3.10)

* 🔥 Remove source examples and tests for (non existent) docs section about Annotated, as it's covered in all the rest of the docs
2023-03-18 13:29:59 +01:00
Nadav Zingerman 375513f114
Add support for PEP-593 `Annotated` for specifying dependencies and parameters (#4871)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-03-17 21:35:45 +01:00
pre-commit-ci[bot] f04b61bd16
⬆ [pre-commit.ci] pre-commit autoupdate (#5709)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-03-10 19:49:18 +01:00
Jordan Speicher cc9a73c3f8
Add support for `lifespan` async context managers (superseding `startup` and `shutdown` events) (#2944)
Co-authored-by: Mike Shantz <mshantz@coldstorage.com>
Co-authored-by: Jonathan Plasse <13716151+JonathanPlasse@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-03-07 16:46:00 +01:00
Yasser Tahiri 99deead7fc
✏ Update Pydantic GitHub URLs (#5952) 2023-02-09 20:28:54 +01:00
Marcelo Trylesinski 9293795e99
⬆️ Bump Starlette from 0.22.0 to 0.23.0 (#5739)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-02-08 11:23:07 +01:00
Sebastián Ramírez fb8e9083f4
📝 Update docs and examples for Response Model with Return Type Annotations, and update runtime error (#5873) 2023-01-10 16:22:47 +00:00
Marcelo Trylesinski fba7493042
🐛 Ignore Response classes on return annotation (#5855)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-01-10 12:45:18 +00:00
Yurii Karabas d0573f5713
Add support for function return type annotations to declare the `response_model` (#1436)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-01-07 17:45:48 +04:00
Eugenio Panadero 46974c510e
⬆ Bump Starlette to version `0.22.0` to fix bad encoding for query parameters in `TestClient` (#5659)
closes https://github.com/tiangolo/fastapi/issues/5646
2022-11-27 15:46:06 +01:00
Sebastián Ramírez fa74093440
Use Ruff for linting (#5630) 2022-11-13 19:19:04 +01:00
Sebastián Ramírez f92f87d379
📝 Update references to Requests for tests to HTTPX, and add HTTPX to extras (#5628) 2022-11-13 16:20:05 +01:00
Paweł Rubin fdbd48be5f
⬆ Upgrade Starlette to `0.21.0`, including the new [`TestClient` based on HTTPX](https://github.com/encode/starlette/releases/tag/0.21.0) (#5471)
Co-authored-by: Paweł Rubin <pawel.rubin@ocado.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-11-13 15:26:09 +01:00
Irfanuddin Shafi Ahmed 5cd99a9517
🎨 Format OpenAPI JSON in `test_starlette_exception.py` (#5379) 2022-11-03 21:06:00 +01:00
Adrian Garcia Badaracco ac9f56ea5e
🐛 Close FormData (uploaded files) after the request is done (#5465)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-11-03 13:06:52 +01:00
Jarro van Ginkel 0ae8db447a
🐛 Fix support for strings in OpenAPI status codes: `default`, `1XX`, `2XX`, `3XX`, `4XX`, `5XX` (#5187)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-10-14 22:44:22 +02:00
Marcelo Trylesinski adcf03f2bc
⬆ Upgrade version required of Starlette from `0.19.1` to `0.20.4` (#4820)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-09-15 14:32:05 +02:00
Irfanuddin Shafi Ahmed 4d270463af
🐛Fix `RuntimeError` raised when `HTTPException` has a status code with no content (#5365)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-09-11 16:13:36 +00:00
Thomas Meckel 0b4fe10c8f
🐛 Fix empty reponse body when default `status_code` is empty but the a `Response` parameter with `response.status_code` is set (#5360)
Co-authored-by: Thomas Meckel <tmeckel@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-09-08 15:02:59 +00:00
DCsunset 3ec498af63
Add support in `jsonable_encoder` for include and exclude with dataclasses (#4923)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-09-08 16:29:23 +02:00
Charlie DiGiovanna 56f887de15
🐛 Make sure a parameter defined as required is kept required in OpenAPI even if defined as optional in another dependency (#4319)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-09-03 17:12:41 +00:00
abc.zxy 7250c194da
Update `ORJSONResponse` to support non `str` keys and serializing Numpy arrays (#3892)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-09-02 10:17:31 +00:00
Sebastián Ramírez 356a57daa8
📝 Add docs for creating a custom Response class (#5331) 2022-09-01 09:32:30 +00:00
David Brochart d8b6aa630c
🐛 Fix support for path parameters in WebSockets (#3879)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-09-01 10:50:47 +02:00
supraaxdd 5e34cb1868
✏ Fix typos in `tests/test_schema_extra_examples.py` (#5126) 2022-08-26 16:36:41 +02:00
Seungho Kim d86b54e79b
🔥 Delete duplicated tests in `tests/test_tutorial/test_sql_databases/test_sql_databases.py` (#5040) 2022-08-26 16:08:45 +02:00
Luis R 22bed0008c
🐛 Fix `jsonable_encoder` for dataclasses with pydantic-compatible fields (#3607)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-26 15:56:47 +02:00
Ori Levari 880c8b37cf
🐛 Fix support for extending `openapi_extras` with parameter lists (#4267)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-08-26 09:26:20 +00:00
juntatalor ca2fae0588
Add support for `FrozenSet` in parameters (e.g. query) (#2938)
Co-authored-by: saborisov <borisov_s@tass.ru>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-08-25 23:52:53 +02:00
Andy Challis eb3ab337ab
Allow custom middlewares to raise `HTTPException`s and propagate them (#2036)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-25 23:44:40 +02:00
Andrey Semakin f6808e76dc
♻ Strip empty whitespace from description extracted from docstrings (#2821)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-08-23 13:47:19 +00:00
laggardkernel b993b4af28
🐛 Fix cached dependencies when using a dependency in `Security()` and other places (e.g. `Depends()`) with different OAuth2 scopes (#2945)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-08-23 13:30:24 +00:00
Taneli Hukkinen 634cf22584
🐛 Fix `response_model` not invalidating `None` (#2725)
Co-authored-by: Taneli Hukkinen <hukkinj1@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-08-22 19:17:45 +00:00
Xavi Moreno eb2e183361
🐛 Fix `jsonable_encoder` using `include` and `exclude` parameters for non-Pydantic objects (#2606)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-08-18 22:48:21 +02:00
Luca Repetti e88089ec21
🐛 Fix edge case with repeated aliases names not shown in OpenAPI (#2351)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-08-18 20:31:19 +00:00
Sebastián Ramírez c43120258f
🐛 Fix removing body from status codes that do not support it (#5145) 2022-07-14 13:19:42 +02:00
Sebastián Ramírez acab64b3c3
Add tests for required nonable parameters and body fields (#4907) 2022-05-14 19:08:31 +00:00
Sebastián Ramírez 9262fa8362
Add support for not needing `...` as default value in required Query(), Path(), Header(), etc. (#4906)
*  Do not require default value in Query(), Path(), Header(), etc

* 📝 Update source examples for docs with default and required values

*  Update tests with new default values and not required Ellipsis

* 📝 Update docs for Query params and update info about default value, required, Ellipsis
2022-05-13 18:38:22 -05:00
Marcelo Trylesinski 86fa3cb24f
⬆ Upgrade Starlette from 0.18.0 to 0.19.0 (#4488)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-05-09 13:06:42 -05:00
Sebastián Ramírez ddd9da3db4
Fix new/recent tests with new fixed `ValidationError` JSON Schema (#4806) 2022-04-17 20:55:36 +00:00
dconathan c449ae5c74
🐛 Fix JSON Schema for `ValidationError` at field `loc` (#3810)
Co-authored-by: Devin Conathan <dconatha@amfam.com>
2022-04-17 19:41:46 +02:00
Marcelo Trylesinski d81c908132
🐛 Fix support for prefix on APIRouter WebSockets (#2640)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-04-17 19:21:53 +02:00
Sebastián Ramírez e1d0e3874b
Temporarily remove typer-cli from dependencies and upgrade Black (#4754) 2022-04-01 23:01:51 +00:00
Sebastián Ramírez 8a0d4c79c1
Add support for custom `generate_unique_id_function` and docs for generating clients (#4650) 2022-03-04 23:02:18 +01:00
Sebastián Ramírez f5d7df3c6c
Include route in scope to allow middleware and other tools to extract its information (#4603) 2022-02-21 16:51:26 +01:00
Sebastián Ramírez 9d56a3cb59
Update internal `AsyncExitStack` to fix context for dependencies with `yield` (#4575) 2022-02-17 13:40:12 +01:00
Victor Benichoux a698908ed6
🐛 Fix bug preventing to use OpenAPI when using tuples (#3874)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-01-23 23:13:55 +01:00
Sebastián Ramírez 1bf55200a9
Add support for declaring `UploadFile` parameters without explicit `File()` (#4469) 2022-01-23 19:14:13 +00:00
Sebastián Ramírez 569afb4378
Add support for tags with Enums (#4468) 2022-01-23 18:43:04 +01:00
Sebastián Ramírez d4608a00cf
🐛 Prefer custom encoder over defaults if specified in `jsonable_encoder` (#4467)
Co-authored-by: Vivek Sunder <sviveksunder@gmail.com>
2022-01-23 17:32:04 +01:00
Mark ca5d57ea79
Allow hiding from OpenAPI (and Swagger UI) `Query`, `Cookie`, `Header`, and `Path` parameters (#3144)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-01-23 16:54:59 +01:00
John Riebold a85aa125d2
Enable configuring Swagger UI parameters (#2568)
Co-authored-by: Artem Ivanov <artem@worklife.io>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-01-16 20:26:24 +01:00
Sebastián Ramírez d08a062ee2
Add docs and tests for Python 3.9 and Python 3.10 (#3712)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
2022-01-07 15:11:31 +01:00
Eric Jolibois b0cd4d7e7e
🐛 Fix JSON Schema for dataclasses, supporting the fixes in Pydantic 1.9 (#4272)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-12-12 12:28:35 +01:00
Thomas Grainger 11d0a08acd
Add support for Trio via AnyIO (#3372)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-10-06 17:32:11 +02:00
Sebastián Ramírez 20d4834546
Add support for `read_with_orm_mode`, to support SQLModel relationship attributes (#3757) 2021-08-24 10:21:05 +00:00
Marcelo Trylesinski ab33ba27af
⬆ Add support for Python 3.9 (#2298)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-08-02 16:02:34 +02:00
Edouard Lavery-Plante 836bb97a2d
Add support for extensions and updates to the OpenAPI schema in path operations (#1922)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-07-29 22:01:13 +02:00
dkreeft 6f45f43709
Add additonal OpenAPI metadata parameters to `FastAPI` class, shown on the automatic API docs UI (#1812)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: dkreeft <dkreeft@xccelerated.io>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-07-29 17:10:22 +02:00
Hylke Postma 3b2e891917
Add `description` parameter to all the security scheme classes, e.g. `APIKeyQuery(name="key", description="A very cool API key")` (#1757)
Co-authored-by: Hylke Postma <h.postma@docuwork.nl>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-07-29 12:30:48 +02:00
Marcelo Trylesinski fa2c750443
Add the `docs_src` directory to test coverage and update tests (#1904)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-07-29 11:26:07 +02:00
Sebastián Ramírez 684c0077cc
Add support for `dataclasses` in request bodies and `response_model` (#3577) 2021-07-21 19:54:08 +02:00
Sebastián Ramírez 96fdfc53cc
Support `dataclasses` in responses (#3576)
Co-authored-by: amit lissack <amit@opentrons.com>
2021-07-21 14:39:12 +00:00
Thomas Grainger 2d296c5d07
🔧 Configure strict pytest options and update/refactor tests (#2790)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-07-19 21:14:58 +02:00
Rubikoid 0e0931d308
🐛 Fix include/exclude for dicts in `jsonable_encoder` (#2016)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-07-04 20:53:40 +02:00
Sebastián Ramírez dc5a966548
Allow setting the `response_class` to `RedirectResponse` and returning the URL from the function (#3457) 2021-07-03 21:51:28 +02:00
Jacob Magnusson 0ed6c92341
🐛 Support custom OpenAPI / JSON Schema fields in the generated output OpenAPI (#1429)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-07-03 19:15:59 +02:00
Sebastián Ramírez edf6b2d61f
♻ Assume request bodies contain JSON when no Content-Type header is provided (#3456) 2021-07-03 18:25:12 +02:00
Patrick Wang fa7e3c996e
🐛 Check Content-Type request header before assuming JSON (#2118)
Co-authored-by: Patrick Wang <patrickkwang@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-06-07 12:46:18 +02:00
Hannes Küttner 4aed0411e9
⬆️ Upgrade Starlette to 0.14.2, including internal UJSONResponse migrated from Starlette (#2335) 2021-05-10 16:09:04 +02:00
Austin Orr e10a4375f9
Add support for adding multiple examples in request bodies and path, query, cookie, and header params (#1267)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2021-05-05 20:20:56 +02:00
Sebastián Ramírez fdb6c9ccc5
Improve type annotations, add support for mypy --strict, internally and for external packages (#2547) 2020-12-20 19:50:00 +01:00
Sebastián Ramírez 313bbe802f
Add support for shared/top-level parameters (dependencies, tags, etc) (#2434)
*  Add Default and DefaultPlaceholder data structures

to handle defaults and overrides

*  Add utils to get values by priority handling DefaultPlaceholders

*  Add support for top-level parameters in FastAPI, APIRouter, include_router

including: prefix, tags, dependencies, deprecated, include_in_schema, responses, default_response_class, callbacks

* ♻️ Update openapi utils to handle DefaultPlaceholder for response_class

* 📝 Update bigger-application example code to use top-level params

and showcase them in APIRouter, FastAPI, include_router

* 📝 Update docs for Bigger Applications, include diagrams, top-level params

* 🔥 Simplify code and docs for callbacks as default_response_class is no longer required

* 📝 Add docs for top-level dependencies, in FastAPI()

* 📝 Add docs reference to top-level dependencies in docs for decorator

*  Update/increase tests for Bigger Applications including shared parameters

*  Add tests for top-level dependencies in FastAPI()

*  Add tests for internal DefaultPlaceholder

*  Update/increase tests for callbacks with top-level parameters

*  Add LOTS of tests covering branches and cases for shared parameters

in top-level FastAPI, path operations, include_router, APIRouter, its path operations, nested include_router, nested APIRouter, and its path operations

* 🎨 Format/reorder parameters for consistency in FastAPI, APIRouter, include_router
2020-11-29 18:32:18 +01:00
nukopy 22a5960d36
📝 Fix code consistency in examples for Tutorial - User Guide - Path Parameters (#2158) 2020-11-05 23:30:09 +01:00
Adrian 75c64b6e4c
✏ Fix typos in docs and source examples (#2102)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-11-05 23:14:17 +01:00
Yurii Karabas 4ce18167e7
🐛 Fix bug overriding custom HTTPException and RequestValidationError from exception_handlers (#1924) 2020-11-05 22:21:40 +01:00
Sebastián Ramírez e1758d107e
⬆ Require Pydantic > 1.0 (#1862)
* 🔥 Remove support for Pydantic < 1.0

* 🔥 Remove deprecated skip_defaults from jsonable_encoder and set default for exclude to None, as in Pydantic

* ♻️ Set default of response_model_exclude=None as in Pydantic

* ⬆️ Require Pydantic >=1.0.0 in requirements
2020-08-09 22:17:08 +02:00
Nik b9a0179a03
Add support for injecting HTTPConnection (#1827) 2020-08-09 15:56:41 +02:00
Rupsi Kaushik 5ed48ccdc8
Export WebSocketDisconnect and add example handling disconnections to docs (#1822)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-08-09 15:52:19 +02:00
Nima Mashhadi M. Reza da9b5201c4
🔧 Add Flake8 linting (#1774)
Co-authored-by: nimashadix <nimashadix@pop-os.localdomain>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-08-09 12:54:05 +02:00
Felix Böhm 2fd28434dd
📝 Add documentation about async tests (pytest-asyncio and httpx) (#1619)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-08-08 20:01:18 +02:00
Sebastián Ramírez 38d8bab770
Raise early when using form data without installing python-multipart (#1851)
* Check if Form exists and multipart is in virtual environment

* Remove unused import

* Move BodyFieldInfo check to separate helper function

* Fix type UploadFile to File for BodyFieldInfo check

* Working solution. Kind of nasty though.

* Use better method of determing if correct package imported

* Use better method of determing if correct package imported

* Add raising exceptions, update error messages

* Check if Form exists and multipart is in virtual environment

* Move BodyFieldInfo check to separate helper function

* Fix type UploadFile to File for BodyFieldInfo check

* Use better method of determing if correct package imported

* Add raising exceptions, update error messages
* Removed unused import, added comments

Co-authored-by: Christopher Nguyen <chrisngyn99@gmail.com>

* Updated what kind of exception will be thrown

* Add type annotations

Adds annotations to is_form_data

* Fix import order

* Add basic tests

* Fixed Travis tests

* Replace logging with fastapi logger

* Change AttributeError to ImportError to fix exception handling

* Fixing tests

* Catch ModuleNotFoundError first

Fix code coverage

* Update fastapi/dependencies/utils.py

Remove error spaces when printing

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Update fastapi/dependencies/utils.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Removed spaces in error printing

* ♻️ Refactor form data detection

*  Update/increase tests for incorrect multipart install

* 🔥 Remove deprecated Travis (moved to GitHub Actions)

Co-authored-by: yk396 <yk396@cornell.edu>
Co-authored-by: Christopher Nguyen <chrisngyn99@gmail.com>
Co-authored-by: Kai Chen <kaichen120@gmail.com>
Co-authored-by: Chris N <hello@chris-nguyen.me>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2020-08-08 09:14:10 +02:00
Henry Betts 7fbe3737bc
🐛 Fix encoding a Pydantic model that inherits from another with json_encoders (#1769) 2020-08-03 17:24:29 +02:00
Nima Mashhadi M. Reza 3223de5598
🎨 Add typing.Optional to variables that accept None as value (#1731)
Co-authored-by: nimashadix <nimashadix@pop-os.localdomain>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-08-03 14:29:07 +02:00
JAYATI SHRIVASTAVA 2b47f3e56b
Add support for adding OpenAPI schema for GET requests with a body (#1626)
* add test for get request body's openapi schema

* 📝 Update docs note for GET requests with body

*  Update test for GET request with body, test it receives the body

* 🔇 Temporary type ignore while it's handled in Pydantic

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-07-19 12:17:50 +02:00
Rupsi Kaushik 70a51b3aff
Auto-generate OpenAPI servers from root_path (#1596)
* root_path included in servers object instead of path prefix

* ♻️ Refactor implementation of auto-including root_path in OpenAPI servers

* 📝 Update docs and examples for Behind a Proxy, including servers

* 📝 Update Extending OpenAPI as openapi_prefix is no longer needed

*  Add extra tests for root_path in servers and root_path_in_servers=False

* 🍱 Update security docs images with relative token URL

* 📝 Update security docs with relative token URL

* 📝 Update example sources with relative token URLs

*  Update tests with relative tokens

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-07-10 19:28:18 +02:00
Sebastián Ramírez 600f15faa0
✔ Improve support for tests in editor (#1699)
* ♻️ Remove required extra steps to test in editor

* 🎨 Format lint script

* 📝 Remove obsolete extra steps required to test in editor from docs

* 🐛 Fix coverage
2020-07-10 11:08:19 +02:00