-
Notifications
You must be signed in to change notification settings - Fork 205
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
Support arbitrary exprs in operation_id #472
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good, one thing though is to add a test for a path operation to test whether it really uses value of the const as operation id.
You can see some help for creating test here
utoipa/utoipa-gen/tests/path_derive.rs
Lines 1186 to 1225 in 96acebf
fn derive_path_params_into_params_with_raw_identifier() { | |
#[derive(IntoParams)] | |
#[into_params(parameter_in = Path)] | |
struct Filter { | |
#[allow(unused)] | |
r#in: String, | |
} | |
#[utoipa::path( | |
get, | |
path = "foo", | |
responses( | |
(status = 200, description = "success response") | |
), | |
params( | |
Filter | |
) | |
)] | |
#[allow(unused)] | |
fn get_foo(query: Filter) {} | |
#[derive(OpenApi, Default)] | |
#[openapi(paths(get_foo))] | |
struct ApiDoc; | |
let doc = serde_json::to_value(ApiDoc::openapi()).unwrap(); | |
let parameters = doc.pointer("/paths/foo/get/parameters").unwrap(); | |
assert_json_eq!( | |
parameters, | |
json!([{ | |
"in": "path", | |
"name": "in", | |
"required": true, | |
"schema": { | |
"type": "string" | |
} | |
}]) | |
) | |
} |
You can basically create a similar test but ignore all the parameter releated things etc and only test the path attribute macro and it's generated output including the operation id.
dbg!(..)
macro is handy in examining path operation content.
Added one! Rather than doing a simple const identifier I went for a full expression since I figured it demonstrates the full power more clearly |
Awesome! 👍 One more thing, let's update the docs for the Line 621 in 96acebf
We could add here a mention that This value can be rust macro expression or a literal value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect 💯
Fixes #471