]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Add documentation for redefined path operations (#4864)
authorMichael Adkins <madkinszane@gmail.com>
Thu, 12 May 2022 16:16:16 +0000 (11:16 -0500)
committerGitHub <noreply@github.com>
Thu, 12 May 2022 16:16:16 +0000 (11:16 -0500)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
docs/en/docs/tutorial/path-params.md
docs_src/path_params/tutorial003b.py [new file with mode: 0644]

index 9c458844d37cbac5b78f025ed02640a59cdbde8a..a0d70692e556bd85619eda95f2d980ca258c582f 100644 (file)
@@ -115,6 +115,14 @@ Because *path operations* are evaluated in order, you need to make sure that the
 
 Otherwise, the path for `/users/{user_id}` would match also for `/users/me`, "thinking" that it's receiving a parameter `user_id` with a value of `"me"`.
 
+Similarly, you cannot redefine a path operation:
+
+```Python hl_lines="6  11"
+{!../../../docs_src/path_params/tutorial003b.py!}
+```
+
+The first one will always be used since the path matches first.
+
 ## Predefined values
 
 If you have a *path operation* that receives a *path parameter*, but you want the possible valid *path parameter* values to be predefined, you can use a standard Python <abbr title="Enumeration">`Enum`</abbr>.
diff --git a/docs_src/path_params/tutorial003b.py b/docs_src/path_params/tutorial003b.py
new file mode 100644 (file)
index 0000000..822d373
--- /dev/null
@@ -0,0 +1,13 @@
+from fastapi import FastAPI
+
+app = FastAPI()
+
+
+@app.get("/users")
+async def read_users():
+    return ["Rick", "Morty"]
+
+
+@app.get("/users")
+async def read_users2():
+    return ["Bean", "Elfo"]