#[cfg(test)]
macro_rules! test_example {
{ $test_name:tt, $schema_name:ty, $text:expr } => {
#[test]
fn $test_name() {
let parsed = serde_json::from_str::<$schema_name>($text);
parsed.unwrap();
}
};
}
macro_rules! def_endpoint {
($doc:expr, $name:ident, $($param:ident, $ptype:ty,)*; $route:expr, $ret:ty) => {
#[doc = $doc]
pub fn $name<'api>(
&'api self
$(, $param: $ptype)*
) -> impl std::future::Future<Output = Result<$ret>> + Send + 'api {
let route = format!($route $(, $param = $param)*);
self.get_from_endpoint(&route)
}
};
}
macro_rules! def_endpoint_paginated {
($doc:expr, $all_doc:expr, $name:ident, $($param:ident, $ptype:ty,)*; $route:expr, $ret:ty) => {
def_endpoint!(
$doc,
$name,
$(
$param,
$ptype,
)*;
$route,
$ret
);
paste::paste! {
#[doc = $all_doc]
pub fn [<$name _all>]<'api>(
&'api self
$(, $param: $ptype)*
) -> $crate::stream::Lister<'api, $ret> {
let endpoint = format!($route $(, $param = $param)*);
$crate::stream::Lister::list_from_endpoint(self, endpoint)
}
}
};
}
macro_rules! endpoints {
($($(#[doc = $doc:expr])* $name:ident($($param:ident: $ptype:ty$(,)?)*) -> $ret:ty => $route:expr; ($link:tt)$(,)?)*) => {
$(
// Forward the above parameters to define a specific endpoint,
// expanding the URL and route into a reference to the OpenAPI docs.
def_endpoint_paginated! {
concat!(
$($doc,)*
"\n\nOpenAPI endpoint reference: [`", $route, "`].",
"\n\n[`", $route, "`]: ", $link
),
concat!(
$($doc,)*
"\n\nResults are paginated.",
"\n\nOpenAPI endpoint reference: [`", $route, "`].",
"\n\n[`", $route, "`]: ", $link
),
$name,
$(
$param,
$ptype,
)*;
$route,
$ret
})*
}
}
macro_rules! paged_endpoints {
($($(#[doc = $doc:expr])* $name:ident($($param:ident: $ptype:ty$(,)?)*) -> $ret:ty => $route:expr; ($link:tt)$(,)?)*) => {
$(
// Forward the above parameters to define a specific endpoint,
// expanding the URL and route into a reference to the OpenAPI docs.
def_endpoint_paginated! {
concat!(
$($doc,)*
"\n\nOpenAPI endpoint reference: [`", $route, "`].",
"\n\n[`", $route, "`]: ", $link
),
concat!(
$($doc,)*
"\n\nResults are paginated.",
"\n\nOpenAPI endpoint reference: [`", $route, "`].",
"\n\n[`", $route, "`]: ", $link
),
$name,
$(
$param,
$ptype,
)*;
$route,
$ret
})*
};
}