From: Katherine Bancroft Date: Fri, 10 Jul 2020 09:16:46 +0000 (-0700) Subject: 📝 Add note in docs on order in Pydantic Unions (#1591) X-Git-Tag: 0.59.0~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d0e739d8f25fa28a10963c9fd81ebb699b874034;p=thirdparty%2Ffastapi%2Ffastapi.git 📝 Add note in docs on order in Pydantic Unions (#1591) * Add note on order in Unions * Add an example of Union order Co-authored-by: kbanc --- diff --git a/docs/en/docs/tutorial/extra-models.md b/docs/en/docs/tutorial/extra-models.md index 67d4ec4730..70f7aff4bb 100644 --- a/docs/en/docs/tutorial/extra-models.md +++ b/docs/en/docs/tutorial/extra-models.md @@ -162,6 +162,9 @@ It will be defined in OpenAPI with `anyOf`. To do that, use the standard Python type hint `typing.Union`: +!!! note + When defining a `Union`, include the most specific type first, followed by the less specific type. In the example below, the more specific `PlaneItem` comes before `CarItem` in `Union[PlaneItem, CarItem]`. + ```Python hl_lines="1 14 15 18 19 20 33" {!../../../docs_src/extra_models/tutorial003.py!} ```