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

Support arbitrary exprs in operation_id #472

Merged
merged 3 commits into from
Feb 2, 2023

Conversation

djrenren
Copy link
Contributor

@djrenren djrenren commented Feb 2, 2023

Fixes #471

Copy link
Owner

@juhaku juhaku left a 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

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.

@djrenren
Copy link
Contributor Author

djrenren commented Feb 2, 2023

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

@juhaku
Copy link
Owner

juhaku commented Feb 2, 2023

Awesome! 👍 One more thing, let's update the docs for the operation_id.

/// * `operation_id = "..."` Unique operation id for the endpoint. By default this is mapped to function name.

We could add here a mention that This value can be rust macro expression or a literal value.

Copy link
Owner

@juhaku juhaku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect 💯

@juhaku juhaku merged commit 9124559 into juhaku:master Feb 2, 2023
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 this pull request may close these issues.

Allow const static str's to be used as operation_id
2 participants