Skip to content

Commit

Permalink
bug(docs): stale reference to pydantic signature models (#3697)
Browse files Browse the repository at this point in the history
Fixes #3259
  • Loading branch information
cofin authored Aug 25, 2024
1 parent b1f7134 commit e4d1fd3
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions docs/usage/routing/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Currently, the following types are supported:
* :class:`int`: Accepts ints and floats.
* :class:`path`: Accepts valid POSIX paths.
* :class:`str`: Accepts all string values.
* ``time``: Accepts time strings with optional timezone compatible with pydantic formats.
* ``timedelta``: Accepts duration strings compatible with the pydantic formats.
* ``time``: Accepts time strings with optional timezone compatible with standard (Pydantic/Msgspec) datetime formats.
* ``timedelta``: Accepts duration strings compatible with the standard (Pydantic/Msgspec) timedelta formats.
* ``uuid``: Accepts all uuid values.

The types declared in the path :term:`parameter` and the function do not need to match 1:1 - as long as
Expand All @@ -47,8 +47,7 @@ The :term:`parameter` defined inside the ``path`` :term:`kwarg <argument>` is ty
passed as part of the request will be a timestamp in milliseconds without any decimals. The parameter in
the function declaration though is typed as :class:`datetime.datetime`.

This works because the int value will be passed to a pydantic model representing the function signature, which will
coerce the :class:`int` into a :class:`~datetime.datetime`.
This works because the int value will be automatically coerced from an :class:`int` into a :class:`~datetime.datetime`.

Thus, when the function is called it will be called with a :class:`~datetime.datetime`-typed parameter.

Expand Down Expand Up @@ -89,11 +88,11 @@ Every :term:`keyword argument <argument>` that is not otherwise specified (for e
.. admonition:: Technical details
:class: info

These :term:`parameters <parameter>` will be parsed from the function signature and used to generate a Pydantic model.
These :term:`parameters <parameter>` will be parsed from the function signature and used to generate an internal data model.
This model in turn will be used to validate the parameters and generate the OpenAPI schema.

This means that you can also use any pydantic type in the signature, and it will
follow the same kind of validation and parsing as you would get from pydantic.
This ability allows you to use any number of schema/modelling libraries, including Pydantic, Msgspec, Attrs, and Dataclasses, and it will
follow the same kind of validation and parsing as you would get from these libraries.

Query :term:`parameters <parameter>` come in three basic types:

Expand Down Expand Up @@ -133,8 +132,6 @@ Type coercion
It is possible to coerce query :term:`parameters <parameter>` into different types.
A query starts out as a :class:`string <str>`, but its values can be parsed into all kinds of types.

Since this is done by Pydantic, everything that works there will work for query parameters as well.

.. literalinclude:: /examples/parameters/query_params_types.py
:caption: Coercing query parameters into different types

Expand Down

0 comments on commit e4d1fd3

Please sign in to comment.