From 0ce4c9eeb8729b648edc1acecb0295bc9dbd5b56 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 10 Jul 2020 10:39:49 +0200 Subject: [PATCH] api-macro: reference consistency API_RETURN_* and API_PARAMETER_* schemas are no references anymore to allow using them as external schemas via the `"schema"` key inside object schemas inside the `#[api]` macro. Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/api.rs | 8 ++++---- proxmox-api-macro/src/api/enums.rs | 4 ++-- proxmox-api-macro/src/api/method.rs | 10 +++++----- proxmox-api-macro/src/api/structs.rs | 2 +- proxmox-api-macro/tests/int-limits.rs | 24 ++++++++++++------------ proxmox-api-macro/tests/types.rs | 20 ++++++++++---------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/proxmox-api-macro/src/api.rs b/proxmox-api-macro/src/api.rs index 8beafed0..6bd9f604 100644 --- a/proxmox-api-macro/src/api.rs +++ b/proxmox-api-macro/src/api.rs @@ -318,7 +318,7 @@ impl SchemaItem { let mut items = TokenStream::new(); array.to_schema(&mut items)?; ts.extend(quote! { - ::proxmox::api::schema::ArraySchema::new(#description, #items) + ::proxmox::api::schema::ArraySchema::new(#description, &#items) }); } SchemaItem::ExternType(path) => { @@ -332,7 +332,7 @@ impl SchemaItem { if !properties.is_empty() { bail!(&properties[0].0 => "additional properties not allowed on schema ref"); } - ts.extend(quote_spanned! { path.span() => &#path }); + ts.extend(quote_spanned! { path.span() => #path }); return Ok(true); } SchemaItem::Inferred(span) => { @@ -367,7 +367,7 @@ impl SchemaItem { if self.to_inner_schema(&mut inner_ts, description, span, properties)? { ts.extend(inner_ts); } else { - ts.extend(quote! { & #inner_ts .schema() }); + ts.extend(quote! { #inner_ts .schema() }); } Ok(()) } @@ -432,7 +432,7 @@ impl SchemaObject { let optional = element.1; let mut schema = TokenStream::new(); element.2.to_schema(&mut schema)?; - ts.extend(quote! { (#key, #optional, #schema), }); + ts.extend(quote! { (#key, #optional, &#schema), }); } Ok(()) } diff --git a/proxmox-api-macro/src/api/enums.rs b/proxmox-api-macro/src/api/enums.rs index f2ff0e71..9322f01c 100644 --- a/proxmox-api-macro/src/api/enums.rs +++ b/proxmox-api-macro/src/api/enums.rs @@ -76,8 +76,8 @@ pub fn handle_enum( Ok(quote_spanned! { name.span() => #enum_ty impl #name { - pub const API_SCHEMA: &'static ::proxmox::api::schema::Schema = - & #schema + pub const API_SCHEMA: ::proxmox::api::schema::Schema = + #schema .format(&::proxmox::api::schema::ApiStringFormat::Enum(&[#variants])) .schema(); } diff --git a/proxmox-api-macro/src/api/method.rs b/proxmox-api-macro/src/api/method.rs index 580b95ac..cdadb6f0 100644 --- a/proxmox-api-macro/src/api/method.rs +++ b/proxmox-api-macro/src/api/method.rs @@ -127,9 +127,9 @@ pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result - pub const #return_schema_name: &'static ::proxmox::api::schema::Schema = #inner; + pub const #return_schema_name: ::proxmox::api::schema::Schema = #inner; }; - returns_schema_setter = quote! { .returns(#return_schema_name) }; + returns_schema_setter = quote! { .returns(&#return_schema_name) }; } let api_handler = if is_async { @@ -141,13 +141,13 @@ pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result #returns_schema_definition - pub const #input_schema_name: &'static ::proxmox::api::schema::ObjectSchema = - &#input_schema; + pub const #input_schema_name: ::proxmox::api::schema::ObjectSchema = + #input_schema; #vis const #api_method_name: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new( &#api_handler, - #input_schema_name, + &#input_schema_name, ) #returns_schema_setter #access_setter diff --git a/proxmox-api-macro/src/api/structs.rs b/proxmox-api-macro/src/api/structs.rs index 93b1786b..f6167753 100644 --- a/proxmox-api-macro/src/api/structs.rs +++ b/proxmox-api-macro/src/api/structs.rs @@ -78,7 +78,7 @@ fn finish_schema( Ok(quote_spanned! { name.span() => #stru impl #name { - pub const API_SCHEMA: &'static ::proxmox::api::schema::Schema = #schema; + pub const API_SCHEMA: ::proxmox::api::schema::Schema = #schema; } }) } diff --git a/proxmox-api-macro/tests/int-limits.rs b/proxmox-api-macro/tests/int-limits.rs index 61e630f5..70f19108 100644 --- a/proxmox-api-macro/tests/int-limits.rs +++ b/proxmox-api-macro/tests/int-limits.rs @@ -8,8 +8,8 @@ pub struct AnI16(i16); #[test] fn test_an_i16_schema() { - const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema = - &::proxmox::api::schema::IntegerSchema::new("An i16: -32768 to 32767.") + const TEST_SCHEMA: ::proxmox::api::schema::Schema = + ::proxmox::api::schema::IntegerSchema::new("An i16: -32768 to 32767.") .minimum(-32768) .maximum(32767) .schema(); @@ -23,8 +23,8 @@ pub struct I16G50(i16); #[test] fn test_i16g50_schema() { - const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema = - &::proxmox::api::schema::IntegerSchema::new("Already limited on one side.") + const TEST_SCHEMA: ::proxmox::api::schema::Schema = + ::proxmox::api::schema::IntegerSchema::new("Already limited on one side.") .minimum(-50) .maximum(32767) .schema(); @@ -38,8 +38,8 @@ pub struct AnI32(i32); #[test] fn test_an_i32_schema() { - const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema = - &::proxmox::api::schema::IntegerSchema::new("An i32: -0x8000_0000 to 0x7fff_ffff.") + const TEST_SCHEMA: ::proxmox::api::schema::Schema = + ::proxmox::api::schema::IntegerSchema::new("An i32: -0x8000_0000 to 0x7fff_ffff.") .minimum(-0x8000_0000) .maximum(0x7fff_ffff) .schema(); @@ -53,8 +53,8 @@ pub struct AnU32(u32); #[test] fn test_an_u32_schema() { - const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema = - &::proxmox::api::schema::IntegerSchema::new("Unsigned implies a minimum of zero.") + const TEST_SCHEMA: ::proxmox::api::schema::Schema = + ::proxmox::api::schema::IntegerSchema::new("Unsigned implies a minimum of zero.") .minimum(0) .maximum(0xffff_ffff) .schema(); @@ -68,8 +68,8 @@ pub struct AnI64(i64); #[test] fn test_an_i64_schema() { - const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema = - &::proxmox::api::schema::IntegerSchema::new("An i64: this is left unlimited.") + const TEST_SCHEMA: ::proxmox::api::schema::Schema = + ::proxmox::api::schema::IntegerSchema::new("An i64: this is left unlimited.") .schema(); assert_eq!(TEST_SCHEMA, AnI64::API_SCHEMA); @@ -81,8 +81,8 @@ pub struct AnU64(u64); #[test] fn test_an_u64_schema() { - const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema = - &::proxmox::api::schema::IntegerSchema::new("Unsigned implies a minimum of zero.") + const TEST_SCHEMA: ::proxmox::api::schema::Schema = + ::proxmox::api::schema::IntegerSchema::new("Unsigned implies a minimum of zero.") .minimum(0) .schema(); diff --git a/proxmox-api-macro/tests/types.rs b/proxmox-api-macro/tests/types.rs index a7d3c0f0..a85971d6 100644 --- a/proxmox-api-macro/tests/types.rs +++ b/proxmox-api-macro/tests/types.rs @@ -23,8 +23,8 @@ pub struct OkString(String); #[test] fn ok_string() { - const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema = - &::proxmox::api::schema::StringSchema::new("A string") + const TEST_SCHEMA: ::proxmox::api::schema::Schema = + ::proxmox::api::schema::StringSchema::new("A string") .format(&schema::ApiStringFormat::Enum(&[ EnumEntry::new("ok", "Ok"), EnumEntry::new("not-ok", "Not OK"), @@ -45,8 +45,8 @@ pub struct TestStruct { #[test] fn test_struct() { - pub const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema = - &::proxmox::api::schema::ObjectSchema::new( + pub const TEST_SCHEMA: ::proxmox::api::schema::Schema = + ::proxmox::api::schema::ObjectSchema::new( "An example of a simple struct type.", &[ ( @@ -84,8 +84,8 @@ pub struct RenamedStruct { #[test] fn renamed_struct() { - const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema = - &::proxmox::api::schema::ObjectSchema::new( + const TEST_SCHEMA: ::proxmox::api::schema::Schema = + ::proxmox::api::schema::ObjectSchema::new( "An example of a struct with renamed fields.", &[ ( @@ -124,8 +124,8 @@ pub enum Selection { #[test] fn selection_test() { - const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema = - &::proxmox::api::schema::StringSchema::new( + const TEST_SCHEMA: ::proxmox::api::schema::Schema = + ::proxmox::api::schema::StringSchema::new( "A selection of either \'onekind\', \'another-kind\' or \'selection-number-three\'.", ) .format(&::proxmox::api::schema::ApiStringFormat::Enum(&[ @@ -164,8 +164,8 @@ fn string_check_schema_test() { &::proxmox::api::schema::ObjectSchema::new( "Check a string.", &[ - ("arg", false, OkString::API_SCHEMA), - ("selection", false, Selection::API_SCHEMA), + ("arg", false, &OkString::API_SCHEMA), + ("selection", false, &Selection::API_SCHEMA), ], ), )