mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-02 10:20:50 +00:00
api-macro: understand a 'Returns:' section in function doc comments
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
b899c3e9ee
commit
366b50dee7
@ -506,8 +506,32 @@ pub(crate) fn api(_attr: TokenStream, item: TokenStream) -> Result<TokenStream,
|
|||||||
let mut input_schema =
|
let mut input_schema =
|
||||||
input_schema.ok_or_else(|| format_err!(sig_span, "missing input schema"))?;
|
input_schema.ok_or_else(|| format_err!(sig_span, "missing input schema"))?;
|
||||||
|
|
||||||
|
let mut returns_schema =
|
||||||
|
returns_schema.ok_or_else(|| format_err!(sig_span, "missing returns schema"))?;
|
||||||
|
|
||||||
|
// If we have a doc comment, allow automatically inferring the description for the input and
|
||||||
|
// output objects:
|
||||||
|
if !doc_comment.is_empty() {
|
||||||
|
let mut parts = doc_comment.splitn(2, "\nReturns:");
|
||||||
|
|
||||||
|
if let Some(first) = parts.next() {
|
||||||
if input_schema.description.is_none() {
|
if input_schema.description.is_none() {
|
||||||
input_schema.description = Some(syn::LitStr::new(&doc_comment, doc_span));
|
input_schema.description = Some(syn::LitStr::new(first.trim(), doc_span));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(second) = parts.next() {
|
||||||
|
if returns_schema.description.is_none() {
|
||||||
|
returns_schema.description = Some(syn::LitStr::new(second.trim(), doc_span));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if parts.next().is_some() {
|
||||||
|
bail!(
|
||||||
|
doc_span,
|
||||||
|
"multiple 'Returns:' sections found in doc comment!"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let input_schema = {
|
let input_schema = {
|
||||||
@ -516,9 +540,6 @@ pub(crate) fn api(_attr: TokenStream, item: TokenStream) -> Result<TokenStream,
|
|||||||
ts
|
ts
|
||||||
};
|
};
|
||||||
|
|
||||||
let returns_schema =
|
|
||||||
returns_schema.ok_or_else(|| format_err!(sig_span, "missing returns schema"))?;
|
|
||||||
|
|
||||||
let returns_schema = {
|
let returns_schema = {
|
||||||
let mut ts = TokenStream::new();
|
let mut ts = TokenStream::new();
|
||||||
returns_schema.to_schema(&mut ts)?;
|
returns_schema.to_schema(&mut ts)?;
|
||||||
|
@ -21,7 +21,6 @@ use serde_json::Value;
|
|||||||
}
|
}
|
||||||
})]
|
})]
|
||||||
#[returns({
|
#[returns({
|
||||||
description: "Returns a ticket",
|
|
||||||
properties: {
|
properties: {
|
||||||
"username": {
|
"username": {
|
||||||
type: String,
|
type: String,
|
||||||
@ -39,7 +38,7 @@ use serde_json::Value;
|
|||||||
})]
|
})]
|
||||||
/// Create or verify authentication ticket.
|
/// Create or verify authentication ticket.
|
||||||
///
|
///
|
||||||
/// Returns: ...
|
/// Returns: A ticket.
|
||||||
fn create_ticket(
|
fn create_ticket(
|
||||||
_param: Value,
|
_param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
|
Loading…
Reference in New Issue
Block a user