openapiv3_1/
tag.rs

1//! Implements [OpenAPI Tag Object][tag] types.
2//!
3//! [tag]: https://spec.openapis.org/oas/latest.html#tag-object
4use serde_derive::{Deserialize, Serialize};
5
6use super::extensions::Extensions;
7use super::external_docs::ExternalDocs;
8
9/// Implements [OpenAPI Tag Object][tag].
10///
11/// Tag can be used to provide additional metadata for tags used by path operations.
12///
13/// [tag]: https://spec.openapis.org/oas/latest.html#tag-object
14#[non_exhaustive]
15#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq, bon::Builder)]
16#[cfg_attr(feature = "debug", derive(Debug))]
17#[serde(rename_all = "camelCase")]
18#[builder(on(_, into))]
19pub struct Tag {
20    /// Name of the tag. Should match to tag of **operation**.
21    pub name: String,
22
23    /// Additional description for the tag shown in the document.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub description: Option<String>,
26
27    /// Additional external documentation for the tag.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub external_docs: Option<ExternalDocs>,
30
31    /// Optional extensions "x-something".
32    #[serde(skip_serializing_if = "Option::is_none", flatten)]
33    pub extensions: Option<Extensions>,
34}
35
36impl Tag {
37    /// Construct a new [`Tag`] with given name.
38    pub fn new<S: AsRef<str>>(name: S) -> Self {
39        Self {
40            name: name.as_ref().to_string(),
41            ..Default::default()
42        }
43    }
44}