1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-22 20:52:27 +00:00

add debug option to endpoint macro

This commit is contained in:
Dominic 2021-01-18 18:50:26 +01:00
parent 70914d107b
commit 681ef5d894
Signed by: msrd0
GPG key ID: DCC8C247452E98F9

View file

@ -348,12 +348,15 @@ fn expand_endpoint_type(mut ty: EndpointType, attrs: AttributeArgs, fun: &ItemFn
}
// parse arguments
let mut debug: bool = false;
let mut operation_id: Option<LitStr> = None;
let mut wants_auth: Option<LitBool> = None;
for meta in attrs {
match meta {
NestedMeta::Meta(Meta::NameValue(kv)) => {
if kv.path.ends_with("operation_id") {
if kv.path.ends_with("debug") {
debug = kv.lit.expect_bool()?.value;
} else if kv.path.ends_with("operation_id") {
operation_id = Some(kv.lit.expect_str()?);
} else if kv.path.ends_with("wants_auth") {
wants_auth = Some(kv.lit.expect_bool()?);
@ -517,7 +520,7 @@ fn expand_endpoint_type(mut ty: EndpointType, attrs: AttributeArgs, fun: &ItemFn
};
let operation_id = expand_operation_id(operation_id);
let wants_auth = expand_wants_auth(wants_auth, args.iter().any(|arg| arg.ty.is_auth_status()));
Ok(quote! {
let code = quote! {
#[doc(hidden)]
/// `gotham_restful` implementation detail
#[allow(non_camel_case_types)]
@ -564,7 +567,11 @@ fn expand_endpoint_type(mut ty: EndpointType, attrs: AttributeArgs, fun: &ItemFn
#wants_auth
}
};
})
};
if debug {
eprintln!("{}", code);
}
Ok(code)
}
pub fn expand_endpoint(ty: EndpointType, attrs: AttributeArgs, fun: ItemFn) -> Result<TokenStream> {