How to hide input param in fastapi?

Member

by domenico , in category: Javascript , 14 days ago

How to hide input param in fastapi?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 13 days ago

@domenico 

In FastAPI, you can hide input parameters by using the Query or Path function along with the ellipsis (...) symbol. Here's how you can do it:

  1. Query parameters: You can hide query parameters by using the ellipsis (...) symbol in the definition of the parameter. By doing this, the parameter will not be included in the OpenAPI documentation.
1
2
3
4
5
6
7
from fastapi import FastAPI, Query

app = FastAPI()

@app.get("/items/")
async def read_items(q: str = Query(..., description="Query parameter")):
    return {"q": q}


  1. Path parameters: You can hide path parameters in a similar way by using the ellipsis (...) symbol in the definition of the parameter. This will prevent the parameter from being included in the OpenAPI documentation.
1
2
3
4
5
6
7
from fastapi import FastAPI, Path

app = FastAPI()

@app.get("/items/{item_id}")
async def read_item(item_id: int = Path(..., description="Item ID")):
    return {"item_id": item_id}


By using the ellipsis (...) symbol in the parameter definition, you can effectively hide input parameters in FastAPI while still being able to use them in your API endpoints.