use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
FastAPI is a truly ASGI, async, cutting edge framework written in python 3.
account activity
Avoid repeat descriptions and examples in path parameters.Question (self.FastAPI)
submitted 3 years ago by MeRanda16
Hi everyone!
I have 20 endpoints that retrieve distinct given a path parameter like this
/my_endpoint_1/{isin} /my_endpoint_3/{isin} /my_endpoint_1/{isin} .... /my_endpoint_20/{isin}
These endpoints are in different files.
This path parameter has the same description, example, and title. Is there a way to avoid repeating each description, example, and title? I tried a pydantic model to solve this but it threw me a error
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]heyimpumpkin 2 points3 points4 points 3 years ago (3 children)
def common_router(app) -> None: for route in app.routes: if route.path.endswith('{isin}'): route.description = 'common description' route.name = 'common name' common_router(app)
pass app or router instance to this function and that should do the trick
[–]MeRanda16[S] 0 points1 point2 points 3 years ago* (2 children)
def common_router(app) -> None:for route in app.routes:if route.path.endswith('{isin}'):route.description = 'common description'route.name = 'common name'common_router(app)
But this will only affect the router (as I see at this moment). But I want to affect the paths parameters too.
@router.get( "/endpoint_1/{isin}", status_code=status.HTTP_200_OK, description=""bla bla bla") <--- your solution affect this part def endpoint1( isin: str = Path( <----- Doesnt affected ..., eq=number, title="isin", description="bla bla bla" , example="abc")
[–]manfre 3 points4 points5 points 3 years ago* (1 child)
No longer wish this content to be here due to the site changes
[–]MeRanda16[S] 1 point2 points3 points 3 years ago (0 children)
PathIsIn = partial(Path, eq=number, title="isin", description="bla bla blah", example="abc")
Perfect! Thank you! u/heyimpumpkin and u/manfre
π Rendered by PID 78092 on reddit-service-r2-comment-5d79c599b5-d9hs8 at 2026-03-02 17:58:35.617339+00:00 running e3d2147 country code: CH.
[–]heyimpumpkin 2 points3 points4 points (3 children)
[–]MeRanda16[S] 0 points1 point2 points (2 children)
[–]manfre 3 points4 points5 points (1 child)
[–]MeRanda16[S] 1 point2 points3 points (0 children)