Skip to content

Commit

Permalink
Add missing description from OneOf type
Browse files Browse the repository at this point in the history
* Add missing description field from OneOf and OneOfBuilder types
  • Loading branch information
juhaku committed Apr 4, 2022
1 parent 0c43bff commit 4bc1b66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/openapi/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ builder! {
/// Components of _OneOf_ component.
#[serde(rename = "oneOf")]
pub items: Vec<Component>,

#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
}
}

Expand All @@ -208,6 +211,7 @@ impl OneOf {
pub fn with_capacity(capacity: usize) -> Self {
Self {
items: Vec::with_capacity(capacity),
description: None
}
}
}
Expand All @@ -222,6 +226,11 @@ impl OneOfBuilder {
self
}

/// Add or change optional description for `OneOf` component.
pub fn description<I: Into<String>>(mut self, description: Option<I>) -> Self {
set_value!(self description description.map(|description| description.into()))
}

to_array_builder!();
}

Expand Down
9 changes: 9 additions & 0 deletions utoipa-gen/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,15 @@ impl ToTokens for ComplexEnum<'_> {
.item(#inline_variant)
})
});

if let Some(comment) = CommentAttributes::from_attributes(self.attributes)
.0
.first()
{
tokens.extend(quote! {
.description(Some(#comment))
})
}
}
}

Expand Down

0 comments on commit 4bc1b66

Please sign in to comment.