question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Db Session Depends for a route showing func as query in swagger

See original GitHub issue

Code 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

image

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:closed
  • Created 3 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SebastianLuebkecommented, Oct 7, 2020

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

0reactions
github-actions[bot]commented, Nov 23, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found