]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Add note in docs on order in Pydantic Unions (#1591)
authorKatherine Bancroft <katherine.bancroft@gmail.com>
Fri, 10 Jul 2020 09:16:46 +0000 (02:16 -0700)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 09:16:46 +0000 (11:16 +0200)
* Add note on order in Unions

* Add an example of Union order

Co-authored-by: kbanc <katherine.bancoft@gmail.com>
docs/en/docs/tutorial/extra-models.md

index 67d4ec473020a7f2183886f810aa2b2adaabc766..70f7aff4bb8377220a8645869cb2d20c794296d5 100644 (file)
@@ -162,6 +162,9 @@ It will be defined in OpenAPI with `anyOf`.
 
 To do that, use the standard Python type hint <a href="https://docs.python.org/3/library/typing.html#typing.Union" class="external-link" target="_blank">`typing.Union`</a>:
 
+!!! note
+    When defining a <a href="https://pydantic-docs.helpmanual.io/usage/types/#unions" class="external-link" target="_blank">`Union`</a>, 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!}
 ```