From 0df272049041773ba6b56e8947166b749f2eb84c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 15 Dec 2018 14:49:02 +0400 Subject: [PATCH] :memo: Add docs for advanced path operation configs --- .../path-operation-advanced-configuration.md | 20 +++++++++++++++++++ .../tutorial001.py | 8 ++++++++ .../tutorial002.py | 8 ++++++++ mkdocs.yml | 1 + 4 files changed, 37 insertions(+) create mode 100644 docs/tutorial/path-operation-advanced-configuration.md create mode 100644 docs/tutorial/src/path-operation-advanced-configuration/tutorial001.py create mode 100644 docs/tutorial/src/path-operation-advanced-configuration/tutorial002.py diff --git a/docs/tutorial/path-operation-advanced-configuration.md b/docs/tutorial/path-operation-advanced-configuration.md new file mode 100644 index 000000000..f88a640ac --- /dev/null +++ b/docs/tutorial/path-operation-advanced-configuration.md @@ -0,0 +1,20 @@ +## OpenAPI operationId + +!!! danger + If you are not an "expert" in OpenAPI, you probably don't need this. + +You can set the OpenAPI `operationId` to be used in your path operation with the parameter `operation_id`. + +You would have to make sure that it is unique for each operation. + +```Python hl_lines="6" +{!./tutorial/src/path-operation-advanced-configuration/tutorial001.py!} +``` + +## Exclude from OpenAPI + +To exclude a path operation from the generated OpenAPI schema (and thus, from the automatic documentation systems), use the parameter `include_in_schema` and set it to `False`; + +```Python hl_lines="6" +{!./tutorial/src/path-operation-advanced-configuration/tutorial002.py!} +``` diff --git a/docs/tutorial/src/path-operation-advanced-configuration/tutorial001.py b/docs/tutorial/src/path-operation-advanced-configuration/tutorial001.py new file mode 100644 index 000000000..fafa8ffb8 --- /dev/null +++ b/docs/tutorial/src/path-operation-advanced-configuration/tutorial001.py @@ -0,0 +1,8 @@ +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/items/", operation_id="some_specific_id_you_define") +async def read_items(): + return [{"item_id": "Foo"}] diff --git a/docs/tutorial/src/path-operation-advanced-configuration/tutorial002.py b/docs/tutorial/src/path-operation-advanced-configuration/tutorial002.py new file mode 100644 index 000000000..dcc358e32 --- /dev/null +++ b/docs/tutorial/src/path-operation-advanced-configuration/tutorial002.py @@ -0,0 +1,8 @@ +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/items/", include_in_schema=False) +async def read_items(): + return [{"item_id": "Foo"}] diff --git a/mkdocs.yml b/mkdocs.yml index 9ec1dbbef..1f2b89311 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -35,6 +35,7 @@ nav: - Request Files: 'tutorial/request-files.md' - Request Forms and Files: 'tutorial/request-forms-and-files.md' - Path Operation Configuration: 'tutorial/path-operation-configuration.md' + - Path Operation Advanced Configuration: 'tutorial/path-operation-advanced-configuration.md' - Concurrency and async / await: 'async.md' - Deployment: 'deployment.md'