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

Allow const static str's to be used as operation_id #471

Closed
djrenren opened this issue Feb 2, 2023 · 1 comment · Fixed by #472
Closed

Allow const static str's to be used as operation_id #471

djrenren opened this issue Feb 2, 2023 · 1 comment · Fixed by #472

Comments

@djrenren
Copy link
Contributor

djrenren commented Feb 2, 2023

TL;DR It would be useful if the operation_id option on the #[path] macro could be a const variable instead of just a static string like so:

const MY_ID: &str = "some_id";

#[utoipa::path(
    ...
    operation_id = MY_ID
)]
fn foo(...) { ... }

Why
I'm currently writing an API that runs on an AWS Lambda behind API Gateway. There's this really nice feature of API Gateways where you give it an openapi spec and when it invokes your lambda, it tells you the operation id that corresponds to this request. So you can easily write a router like so:

match request_context.operation_name.as_deref() {
   route::MY_ID => foo(...)
}

Currently, I have to keep the string id in sync between my const definition and the #[path] macro invocation. It would be nice to just have a single source of truth.

Is this something you'd be open to a PR for?

@juhaku
Copy link
Owner

juhaku commented Feb 2, 2023

Sure any contributions are welcome 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants