Db Session Depends for a route showing func as query in swagger
See original GitHub issueCode Block
from fastapi import FastAPI
from pydantic import BaseModel
from typing import List, Optional
from datetime import datetime
app = FastAPI()
class LoginRequest(BaseModel):
username: str
password: str
class LoginResponse(BaseModel):
access_token: str
refresh_token: str
status_code: int
class LoginError(BaseModel):
status_code: int
message: str
@r.post("/login", response_model=LoginResponse, responses={400: {"model": LoginError}}, status_code=200)
async def login(
*,db: Session = Depends(get_db("base")), data: LoginRequest) -> t.Any:
return {"Hello": "World"}
Description
After running the above code i see the following query as part of the swagger docs
Environment
- OS: [e.g. Linux / Windows / macOS]: Linux
- FastAPI Version [e.g. 0.3.0]: 0.61.0
- Python version: 3.8.6
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Db Session Depends for a route showing func as query in swagger ...
FastAPI framework, high performance, easy to learn, fast to code, ready for production - Db Session Depends for a route showing func as...
Read more >AttributeError: 'Depends' object has no attribute 'query' FastAPI
What I do is get the DB session from the route and then pass it down through every layer and function. I believe...
Read more >tiangolo/fastapi - Gitter
Hi everyone, I am trying to seperate data logic, with requests, so I am trying to run dependency of db to always close...
Read more >Dependencies - First Steps - FastAPI - tiangolo
Declare the dependency, in the "dependant" Although you use Depends in the parameters of your function the same way you use Body ,...
Read more >Swagger RESTful API Documentation Specification
The Swagger specification defines a set of files required to describe such an API. These files can then be used by the Swagger-UI...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
im hoping to get that,too.
currently i have 5 get_current_user functions would be much easier with
current_user: User = Depends(get_current_user(roles=["Admin", "Moderator"]))
or maybe something like
current_user: User = Depends(get_current_user, ["Admin", "Moderator"])
Edit: this is already possible using Security instead of Depends
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.