From 5a2fe67cd8e66d34431ae566ebbf3c46e1501e37 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 26 Nov 2019 12:16:05 +0100 Subject: [PATCH] api-macro: rename elements to properties Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/api.rs | 24 ++++++++++++------------ proxmox-api-macro/src/lib.rs | 4 ++-- proxmox-api-macro/tests/api1.rs | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/proxmox-api-macro/src/api.rs b/proxmox-api-macro/src/api.rs index 0f2cd863..3a3bde79 100644 --- a/proxmox-api-macro/src/api.rs +++ b/proxmox-api-macro/src/api.rs @@ -208,7 +208,7 @@ impl Parse for JSONMapEntry { /// type: Object, /// description: "text", /// foo: bar, // "unknown", will be added as a builder-pattern method -/// elements: { ... } +/// properties: { ... } /// } /// ``` /// @@ -343,21 +343,21 @@ impl SchemaItem { } } -/// Contains a sorted list of elements: +/// Contains a sorted list of properties: struct SchemaObject { - elements: Vec<(String, bool, Schema)>, + properties: Vec<(String, bool, Schema)>, } impl SchemaObject { fn try_extract_from(obj: &mut JSONObject) -> Result { Ok(Self { - elements: obj - .remove_required_element("elements")? + properties: obj + .remove_required_element("properties")? .into_object("object field definition")? .into_iter() .try_fold( Vec::new(), - |mut elements, (key, value)| -> Result<_, syn::Error> { + |mut properties, (key, value)| -> Result<_, syn::Error> { let mut schema: JSONObject = value.into_object("schema definition for field")?; let optional: bool = schema @@ -368,20 +368,20 @@ impl SchemaObject { }) .transpose()? .unwrap_or(false); - elements.push((key.to_string(), optional, schema.try_into()?)); - Ok(elements) + properties.push((key.to_string(), optional, schema.try_into()?)); + Ok(properties) }, ) // This must be kept sorted! - .map(|mut elements| { - elements.sort_by(|a, b| (a.0).cmp(&b.0)); - elements + .map(|mut properties| { + properties.sort_by(|a, b| (a.0).cmp(&b.0)); + properties })?, }) } fn to_schema_inner(&self, ts: &mut TokenStream) -> Result<(), Error> { - for element in self.elements.iter() { + for element in self.properties.iter() { let key = &element.0; let optional = element.1; let mut schema = TokenStream::new(); diff --git a/proxmox-api-macro/src/lib.rs b/proxmox-api-macro/src/lib.rs index 2ac4b93b..438c1a4f 100644 --- a/proxmox-api-macro/src/lib.rs +++ b/proxmox-api-macro/src/lib.rs @@ -73,7 +73,7 @@ fn router_do(item: TokenStream) -> Result { #[api] #[input({ type: Object, - elements: { + properties: { username: { type: String, description: "User name", @@ -88,7 +88,7 @@ fn router_do(item: TokenStream) -> Result { #[returns({ type: Object, description: "Returns a ticket", - elements: { + properties: { "username": { type: String, description: "User name.", diff --git a/proxmox-api-macro/tests/api1.rs b/proxmox-api-macro/tests/api1.rs index fa9e9355..34b1a11a 100644 --- a/proxmox-api-macro/tests/api1.rs +++ b/proxmox-api-macro/tests/api1.rs @@ -9,7 +9,7 @@ use serde_json::Value; #[api] #[input({ type: Object, - elements: { + properties: { username: { type: String, description: "User name", @@ -24,7 +24,7 @@ use serde_json::Value; #[returns({ type: Object, description: "Returns a ticket", - elements: { + properties: { "username": { type: String, description: "User name.",