-
Notifications
You must be signed in to change notification settings - Fork 122
Open
Description
If I want to specify the full path to endpoints in openapi_get_routes_spec (or any other macro), I get the expected identifier error from Rust-analyzer. The Rust compiler itself doesn't complain, though.
Basically, the following should both work but it doesn't:
use inner::{delay, okapi_add_operation_for_delay_};
let _ = rocket_okapi::openapi_get_routes_spec![delay];
let _ = rocket_okapi::openapi_get_routes_spec![inner::delay]; // expected identifier [rust analyzer(macro-error)]Some code to illustrate the problem
macro_rules! collect_http_endpoints {
// this macro uses `path`
(path: $($route:path),* $(,)*) => {{
let spec = rocket_okapi::openapi_spec![$($route),*];
let routes = rocket_okapi::openapi_routes![$($route),*];
(routes, spec)
}};
// this macro uses `expr`
(expr: $($route:expr),* $(,)*) => {{
let spec = rocket_okapi::openapi_spec![$($route),*];
let routes = rocket_okapi::openapi_routes![$($route),*];
(routes, spec)
}};
}
pub fn collect_endpoints() -> (Vec<rocket::Route>, OpenApi) {
use inner::{delay, okapi_add_operation_for_delay_};
// with `path` both imports work well
let _ = collect_http_endpoints![path: inner::check, delay];
// with `expr` it works if you import both `endpoint` and `okapi_add_operation_for_endpoint_`
let _ = collect_http_endpoints![expr: delay];
// but fails if you want to specify the full path:
let _ = collect_http_endpoints![expr: inner::check];
// `rocket_okapi::openapi_get_routes_spec` fails with full path:
let _ = rocket_okapi::openapi_get_routes_spec![delay];
let _ = rocket_okapi::openapi_get_routes_spec![inner::check];
todo!()
}
mod inner {
use rocket_okapi::openapi;
#[openapi]
#[get("/check")]
pub async fn check() {}
/// Delay the response by the `ms` milliseconds (up to 10 seconds).
#[openapi]
#[get("/delay?<ms>")]
pub async fn delay(ms: u64) {}
}Metadata
Metadata
Assignees
Labels
No labels