Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4153

Set default limit value on FastAPI Swagger UI only, but don't affect programmatic calls

$
0
0

I want to be able to provide my team with a Swagger UI for my FastAPI application to explore the results of each endpoint.

I want to keep the syntax-highlighting on, and want the UI to default to a limit value of 100 (this is part of the function being called)

I don't want calls to the GET endpoint to default to 100 objects when making the call without providing any limit value (in code)

For example:

@router.get("/some_endpoint", response_model=List[SomeSchema])def read_some_endpoint(    name: str,    limit: Optional[int] = Query(100, description="Limit the number of results to return"),    db: Session = Depends(get_db),):"""    Query database """    query = db.query(SomeModel).filter(SomeModel.name == name)    if limit:        query = query.limit(limit)    results = query.all()    return results

This sets the default in the Swagger UI (desired), but when I make a call through the requests package, I only get 100 rows (undesired).

My use-case seems reasonable, so I'm wondering if there's a way to do this.

Basically when "Try It Out" is pressed, have the limit parameter populated in the Swagger UI and let me set the function default to Query(None, description="...")


Viewing all articles
Browse latest Browse all 4153

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>