[QUESTION] How can I attach a dependency outside function parameters?
See original GitHub issueDescription
Is it possible to attach a dependency outside function parameters??
Additional context
For example, I want to move this “UserCan” dependency in a decorator somehow, because I would not use the user_id it returns while it must enforce the security policies it implements.
The reason is because linters will warn about unused variables…
@router.get('/{username}', summary='Get user profile details',
response_model=UserProfileResponse)
async def get_user_profile(username: str,
user_id: str = Depends(UserCan('do_ordinary_stuff'))):
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
How to share the same parameters between dependencies ...
I'm trying to use the same parameters in my endpoint functions and dependencies. ... But this will work incorrectly. If we pass 'swearing'...
Read more >Dependencies - First Steps - FastAPI - tiangolo
Let's first focus on the dependency. It is just a function that can take all the same parameters that a path operation function...
Read more >Dependency Injection and Default Parameters - Kyle Shevlin
Learn how to increase the flexibility and testability of your programs by passing dependencies in as function arguments alongside default ...
Read more >Dependency Walker Frequently Asked Questions (FAQ)
To do this, start a command prompt. Type "SET _NO_DEBUG_HEAP=1". Then start Dependency Walker from that command line. This should disable the debug...
Read more >Dependency injection in Android
Have it supplied as a parameter. The app can provide these dependencies when the class is constructed or pass them in to the...
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 FreeTop 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
Top GitHub Comments
This is now implemented in version
0.22.0
🎉You can do:
The new docs are here: https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-in-path-operation-decorators/
And you can also use it in routers, like:
The relevant docs are here: https://fastapi.tiangolo.com/tutorial/bigger-applications/#include-an-apirouter-with-a-prefix-tags-responses-and-dependencies
(This should solve your use case @cjw296 )
Oh, gosh, I love you.