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 <w.bumiller@proxmox.com>
This commit is contained in:
parent
7609cf2bd4
commit
f9d775924d
@ -9,7 +9,7 @@ use syn::punctuated::Punctuated;
|
|||||||
use syn::Token;
|
use syn::Token;
|
||||||
|
|
||||||
use super::Schema;
|
use super::Schema;
|
||||||
use crate::util::{JSONObject, JSONValue, FieldName};
|
use crate::util::{self, FieldName, JSONObject, JSONValue};
|
||||||
|
|
||||||
/// `parse_macro_input!` expects a TokenStream_1
|
/// `parse_macro_input!` expects a TokenStream_1
|
||||||
struct AttrArgs {
|
struct AttrArgs {
|
||||||
@ -44,7 +44,13 @@ pub fn handle_enum(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let schema = {
|
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();
|
let mut ts = TokenStream::new();
|
||||||
schema.to_typed_schema(&mut ts)?;
|
schema.to_typed_schema(&mut ts)?;
|
||||||
ts
|
ts
|
||||||
|
@ -23,8 +23,9 @@ impl OkString {
|
|||||||
.schema();
|
.schema();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(description: "A selection of either a, B or C")]
|
#[api]
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
/// A selection of either a, B or C
|
||||||
pub enum Selection {
|
pub enum Selection {
|
||||||
#[serde(rename = "a")]
|
#[serde(rename = "a")]
|
||||||
A,
|
A,
|
||||||
|
Loading…
Reference in New Issue
Block a user