Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple context_path #1163

Open
Trevypants opened this issue Oct 24, 2024 · 1 comment
Open

Multiple context_path #1163

Trevypants opened this issue Oct 24, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Trevypants
Copy link

Currently, the context_path field in the path attribute macro can accept a string or a variable. However, one feature that I am missing is being able to specify multiple context paths. My particular use case is that I have a single handler function that I want available via two different routes (the function itself examines the path and alters its execution based on the location). This is ideal for when I want my code to be in a 'test' mode or not ('test' is in the path).

Is there a solution to make my use case work?

Thanks in advance!

@juhaku
Copy link
Owner

juhaku commented Oct 24, 2024

I am afraid that there is no current solution for this. This sounds a bit of a niche requirement. Even if this functionality was provided users still would need to register the handler twice in their appropriate locations. Only by giving multiple context paths, it just would end up being rendered in OpenAPI with 2 or more different paths.

What framework are you using for the web? If you are using axum or actix-web then utoipa-axum and utoipa-actix-web can help you with this. They allow you to register handlers just as they were registered normally to their Router or ServiceConfig which allow nesting or scoping in actix-web terms. For what comes to other frameworks, you are on your own.

Nevertheless perhaps this is something that can be considered in future if there is enough demand for it.

@juhaku juhaku added the enhancement New feature or request label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants