diff --git a/proxmox-api-macro/src/api/method.rs b/proxmox-api-macro/src/api/method.rs index 1d32c606..f3a108c6 100644 --- a/proxmox-api-macro/src/api/method.rs +++ b/proxmox-api-macro/src/api/method.rs @@ -12,6 +12,7 @@ use anyhow::Error; use proc_macro2::{Span, TokenStream}; use quote::{quote, quote_spanned}; +use syn::ext::IdentExt; use syn::spanned::Spanned; use syn::visit_mut::{self, VisitMut}; use syn::Ident; @@ -251,9 +252,10 @@ fn handle_function_signature( // // 5) Finally, if none of the above conditions are met, we do not know what to do and // bail out with an error. - let mut param_name: FieldName = pat.ident.clone().into(); + let pat_ident = pat.ident.unraw(); + let mut param_name: FieldName = pat_ident.clone().into(); let param_type = if let Some((name, optional, schema)) = - input_schema.find_obj_property_by_ident(&pat.ident.to_string()) + input_schema.find_obj_property_by_ident(&pat_ident.to_string()) { if let SchemaItem::Inferred(span) = &schema.item { bail!(*span, "failed to infer type"); @@ -280,7 +282,7 @@ fn handle_function_signature( value_param = Some(param_list.len()); ParameterType::Value } else { - bail!(&pat.ident => "unexpected parameter"); + bail!(&pat_ident => "unexpected parameter {:?}", pat_ident.to_string()); }; param_list.push((param_name, param_type)); diff --git a/proxmox-api-macro/tests/api2.rs b/proxmox-api-macro/tests/api2.rs index af7849ea..2344aad4 100644 --- a/proxmox-api-macro/tests/api2.rs +++ b/proxmox-api-macro/tests/api2.rs @@ -97,3 +97,39 @@ fn more_async_params_schema_check() { assert_eq!(TEST_METHOD, API_METHOD_MORE_ASYNC_PARAMS); } + +#[api( + input: { + properties: { + type: { + type: String, + description: "The great Foo", + }, + }, + }, +)] +/// Returns nothing. +pub async fn keyword_named_parameters(r#type: String) -> Result<(), Error> { + let _ = r#type; + Ok(()) +} + +#[test] +fn keyword_named_parameters_check() { + const TEST_METHOD: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new( + &::proxmox::api::ApiHandler::Async(&api_function_keyword_named_parameters), + &::proxmox::api::schema::ObjectSchema::new( + "Returns nothing.", + &[ + ( + "type", + false, + &::proxmox::api::schema::StringSchema::new("The great Foo").schema(), + ), + ], + ), + ) + .protected(false); + + assert_eq!(TEST_METHOD, API_METHOD_KEYWORD_NAMED_PARAMETERS); +}