Commit Graph

69 Commits

Author SHA1 Message Date
pre-commit-ci-lite[bot] d82a045a18
🎨 Auto format 2025-12-04 22:47:16 +00:00
g7azazlo d5268d7cf5 Enhance AST inference logging and handle multiple return statements
- Added detailed logging for various failure cases in the `infer_response_model_from_ast` function to aid debugging.
- Modified the logic to collect all return statements, ensuring that inference is skipped if multiple returns are detected.
- Introduced a new test case to verify that functions with multiple return statements correctly return None for inference.
2025-12-05 01:46:24 +03:00
g7azazlo b31dd81f48 Refactor import statements in utils for compatibility with Pydantic V2 2025-12-04 00:34:17 +03:00
g7azazlo bf90082191 Refactor type inference logic in utils for improved clarity
- Simplified the `_infer_type_from_ast` function by consolidating conditional checks for argument annotations, enhancing readability and maintainability.
- Updated test cases in `tests/test_ast_inference.py` to utilize parameterization for better organization and coverage of edge cases in response model inference.
2025-12-04 00:28:00 +03:00
g7azazlo e03e232c39 Enhance response model inference and add edge case tests
- Updated the `infer_response_model_from_ast` function to use `textwrap.dedent` for cleaner source code handling.
- Added multiple test cases in `tests/test_ast_inference.py` to cover various edge cases for response model inference, including functions with different return types and argument annotations.
- Improved type inference for functions returning lists and nested dictionaries, ensuring better schema generation.
2025-12-03 23:59:58 +03:00
g7azazlo 7e36726baa Enhance response model inference in APIRoute and utils
- Introduced a new helper function `_contains_response` to check for response types in return annotations, improving the inference logic in `APIRoute`.
- Updated the `infer_response_model_from_ast` function to prevent model creation when all fields are of type `Any`, ensuring better type information and avoiding unnecessary overrides.
2025-12-03 23:26:27 +03:00
g7azazlo 65a9b03c57 Enhance response model inference logic in APIRoute and utils
- Updated the response model inference in APIRoute to check for return annotations before inferring the model from the endpoint's source code.
- Added type ignore comments in utils for better type checking compatibility.
- Specified the type of nodes_to_visit in the infer_response_model_from_ast function for improved clarity.
2025-12-03 23:05:01 +03:00
pre-commit-ci-lite[bot] 95d5b080a2
🎨 Auto format 2025-12-03 19:19:46 +00:00
g7azazlo 40af1b90c3 Enhance response model inference and improve error handling
- Updated the response model inference logic in "APIRoute" to check for "None" before validating against "BaseModel".
- Refined the "infer_response_model_from_ast" function to handle nested function definitions and invalid dictionary keys, ensuring robust schema generation.
- Added new test cases for edge scenarios to validate the inference behavior.
2025-12-03 22:06:15 +03:00
g7azazlo 72b210209b Implement response model inference from endpoint function source code
- Added "infer_response_model_from_ast" function to analyze endpoint functions and infer Pydantic models from returned dictionary literals or variable assignments.

- Updated "APIRoute" to utilize the new inference method when the specified response model is not a subclass of "BaseModel"
2025-12-03 21:44:57 +03:00
Alex Colby cb3792d39e
🐛 Fix unformatted `{type_}` in FastAPIError (#14416)
Co-authored-by: Alex Colby <alex.colby@intellisense.io>
2025-12-02 06:01:11 +01:00
Sofie Van Landeghem d8c691f7f0
🐛 Fix internal Pydantic v1 compatibility (warnings) for Python 3.14 and Pydantic 2.12.1 (#14186)
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>
2025-10-20 13:26:49 +02:00
Sebastián Ramírez d34918abf0
Add support for `from pydantic.v1 import BaseModel`, mixed Pydantic v1 and v2 models in the same app (#14168)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-10-11 18:45:54 +02:00
vvanglro f1e6f978ce
️ Fix `default_factory` for response model field with Pydantic V1 (#9704)
Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
2025-09-20 20:51:40 +02:00
Sebastián Ramírez d08b95ea57
♻️ Rename internal `create_response_field()` to `create_model_field()` as it's used for more than response models (#12103) 2024-09-01 01:46:03 +02: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 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
Sebastián Ramírez dcc952d699
Include HTTP 205 in status codes with no body (#10969) 2024-01-15 11:32:16 +01:00
Evgenii de0126d145
♻️ Simplify string format with f-strings in `fastapi/utils.py` (#10576)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2024-01-13 15:31:38 +01: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 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
Zanie Adkins 27618aa2e8
Update `create_cloned_field` to use a global cache and improve startup performance (#4645)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: Huon Wilson <wilson.huon@gmail.com>
2023-06-03 13:37:41 +00: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
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
Sebastián Ramírez 7c5626bef7
⬆️ Upgrade Ruff (#5698) 2022-11-27 14:59:32 +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 30b3905ef3
Support Python internal description on Pydantic model's docstring (#3032)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-09-02 14:43:21 +02:00
pylounge dc10b81d05
♻ Simplify internal RegEx in `fastapi/utils.py` (#5057)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-26 15:46:22 +02:00
Shahriyar Rzayev 00bdf533ef
♻ Change a `dict()` for `{}` in `fastapi/utils.py` (#3138) 2022-08-26 15:23:25 +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
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
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 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
Shahriyar Rzayev 82775f7cd0
♻ Refactor dict value extraction to minimize key lookups `fastapi/utils.py` (#3139)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-05-12 20:38:30 +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 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
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
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
Brian Mboya fe453f80ed
⬆ Upgrade isort to version 5.x.x (#1670)
* Update isort script to match changes in the new release, isort v5.0.2

* Downgrade isort to version v4.3.21

* Add an alternative flag to --recursive in isort v5.0.2

* Add isort config file

* 🚚 Import from docs_src for tests

* 🎨 Format dependencies.utils

* 🎨 Remove isort combine_as_imports, keep black profile

* 🔧 Update isort config, use pyproject.toml, Black profile

* 🔧 Update format scripts to use explicit directories to format

otherwise it would try to format venv env directories, I have several with different Python versions

* 🎨 Format NoSQL tutorial after re-sorting imports

* 🎨 Fix format for __init__.py

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-07-09 20:06:12 +02:00
Sebastián Ramírez 181a32236a
Deep merge OpenAPI responses (#1577)
* override successful response

*  Add deep_dict_udpate

*  Merge additional responses with generated responses

* 🍱 Update docs screenshot

Co-authored-by: rkbeatss <rkaus053@uottawa.ca>
2020-06-15 13:12:12 +02:00
Kazantcev Andrey 434d32b891
Optimize regexp pattern in get_path_param_names (#1243) 2020-06-12 21:59:32 +02:00
Sebastián Ramírez 5984233223
🐛 Fix Enum handling with their own schema definitions (#1463)
* 🐛 Fix extra support for enum with its own schema

*  Fix/update test for enum with its own schema

* 🐛 Fix type declarations

* 🔧 Update format and lint scripts to support locally installed Pydantic and Starlette

* 🐛 Add temporary type ignores while enum schemas are merged
2020-05-23 18:56:18 +02:00
voegtlel 0f152b4e97
🐛 Check already cloned fields in create_cloned_field to support recursive models (#1164)
* FIX: #894
Include recursion check for create_cloned_field.
Added test for recursive model.

* ♻️ Refactor and format create_cloned_field()

Co-authored-by: Lukas Voegtle <lukas.voegtle@sick.de>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-03-29 19:26:29 +02:00
Patrick McKenna afad59dfbb
🐛 Admit valid types for Pydantic fields as responses models (#1017) 2020-02-29 14:04:35 +01:00
Andy Smith 70bdade23b
🐛 Fix Pydantic field clone logic with validators (#899) 2020-02-04 04:03:51 +01:00
Sebastián Ramírez 75a07f24bf
🔒 Fix clone field implementation to handle sub-models in response_model (#889) 2020-01-18 18:03:51 +01:00
Ben Dayan 73260971b5 Add support for OpenAPI Callbacks (#722) 2019-12-11 17:58:00 +01:00
Sebastián Ramírez 83d04df8a6
🔊 Refactor logging (#781) 2019-12-09 20:02:44 +01:00