How to hide input param in fastapi?

Member

by domenico , in category: Javascript , 5 months ago

How to hide input param in fastapi?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 5 months 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.

Related Threads:

How to get multiple form input field as dictionary in fastapi?
How to send list of ids as param with graphql?
How to find param of child route in ember.js?
How to call procedure with package type param in oracle?
How to add decorator to args param in graphql?
How to replace request param name using .htaccess?