From f9d775924d43d5cc78cffa29848034b19b55ace4 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 4 Dec 2019 11:52:03 +0100 Subject: [PATCH] api-macro: get enum description from doc comments instead of: #[api(description: "Some description.")] pub enum { ... } support: #[api] /// Some description. pub enum { ... } Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/api/enums.rs | 10 ++++++++-- proxmox-api-macro/tests/types.rs | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/proxmox-api-macro/src/api/enums.rs b/proxmox-api-macro/src/api/enums.rs index 0cc22517..4ffb7a9a 100644 --- a/proxmox-api-macro/src/api/enums.rs +++ b/proxmox-api-macro/src/api/enums.rs @@ -9,7 +9,7 @@ use syn::punctuated::Punctuated; use syn::Token; use super::Schema; -use crate::util::{JSONObject, JSONValue, FieldName}; +use crate::util::{self, FieldName, JSONObject, JSONValue}; /// `parse_macro_input!` expects a TokenStream_1 struct AttrArgs { @@ -44,7 +44,13 @@ pub fn handle_enum( } let schema = { - let schema: Schema = attribs.try_into()?; + let mut schema: Schema = attribs.try_into()?; + + if schema.description.is_none() { + let (comment, span) = util::get_doc_comments(&enum_ty.attrs)?; + schema.description = Some(syn::LitStr::new(comment.trim(), span)); + } + let mut ts = TokenStream::new(); schema.to_typed_schema(&mut ts)?; ts diff --git a/proxmox-api-macro/tests/types.rs b/proxmox-api-macro/tests/types.rs index e6ceacf8..9400a331 100644 --- a/proxmox-api-macro/tests/types.rs +++ b/proxmox-api-macro/tests/types.rs @@ -23,8 +23,9 @@ impl OkString { .schema(); } -#[api(description: "A selection of either a, B or C")] +#[api] #[derive(Deserialize)] +/// A selection of either a, B or C pub enum Selection { #[serde(rename = "a")] A,