Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions typify-impl/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl TypeSpace {

Ok(Variant::new(
variant_name.to_string(),
None,
metadata_title_and_description(metadata),
VariantDetails::Unit,
))
} else {
Expand Down Expand Up @@ -513,7 +513,11 @@ impl TypeSpace {
assert_eq!(tag_name, tag);
assert_eq!(validation.required.len(), 1);

let variant = Variant::new(variant_name.to_string(), None, VariantDetails::Unit);
let variant = Variant::new(
variant_name.to_string(),
metadata_title_and_description(metadata),
VariantDetails::Unit,
);
Ok((variant, false))
} else {
let tag_schema = validation.properties.get(tag).unwrap();
Expand Down
30 changes: 30 additions & 0 deletions typify/tests/schemas/various-enums-json-schema.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
#![deny(warnings)]
#[doc = "`AdjacentUnitDescription`"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug, schemars :: JsonSchema)]
#[serde(tag = "action", content = "seconds")]
pub enum AdjacentUnitDescription {
#[doc = "a unit variant"]
#[serde(rename = "off")]
Off,
#[doc = "a variant with content"]
#[serde(rename = "wait")]
Wait(u32),
}
impl ::std::convert::From<u32> for AdjacentUnitDescription {
fn from(value: u32) -> Self {
Self::Wait(value)
}
}
#[doc = "`AlternativeEnum`"]
#[derive(
:: serde :: Deserialize,
Expand Down Expand Up @@ -539,6 +555,20 @@ pub enum EnumAndConstant {
#[serde(rename = "fish")]
Fish { float: ::std::string::String },
}
#[doc = "`InternalUnitDescription`"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug, schemars :: JsonSchema)]
#[serde(tag = "kind")]
pub enum InternalUnitDescription {
#[doc = "a unit variant"]
#[serde(rename = "off")]
Off,
#[doc = "a struct variant"]
#[serde(rename = "wait")]
Wait {
reason: ::std::string::String,
seconds: u32,
},
}
#[doc = "`IpNet`"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug, schemars :: JsonSchema)]
#[serde(untagged)]
Expand Down
65 changes: 65 additions & 0 deletions typify/tests/schemas/various-enums.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,71 @@
"default": "widget"
}
}
},
"AdjacentUnitDescription": {
"oneOf": [
{
"description": "a unit variant",
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": ["off"]
}
},
"required": ["action"]
},
{
"description": "a variant with content",
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": ["wait"]
},
"seconds": {
"type": "integer",
"format": "uint32",
"minimum": 0
}
},
"required": ["action", "seconds"]
}
]
},
"InternalUnitDescription": {
"oneOf": [
{
"description": "a unit variant",
"type": "object",
"properties": {
"kind": {
"type": "string",
"enum": ["off"]
}
},
"required": ["kind"]
},
{
"description": "a struct variant",
"type": "object",
"properties": {
"kind": {
"type": "string",
"enum": ["wait"]
},
"seconds": {
"type": "integer",
"format": "uint32",
"minimum": 0
},
"reason": {
"type": "string"
}
},
"required": ["kind", "seconds", "reason"]
}
]
}
}
}
30 changes: 30 additions & 0 deletions typify/tests/schemas/various-enums.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
#![deny(warnings)]
#[doc = "`AdjacentUnitDescription`"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
#[serde(tag = "action", content = "seconds")]
pub enum AdjacentUnitDescription {
#[doc = "a unit variant"]
#[serde(rename = "off")]
Off,
#[doc = "a variant with content"]
#[serde(rename = "wait")]
Wait(u32),
}
impl ::std::convert::From<u32> for AdjacentUnitDescription {
fn from(value: u32) -> Self {
Self::Wait(value)
}
}
#[doc = "`AlternativeEnum`"]
#[derive(
:: serde :: Deserialize,
Expand Down Expand Up @@ -480,6 +496,20 @@ pub enum EnumAndConstant {
#[serde(rename = "fish")]
Fish { float: ::std::string::String },
}
#[doc = "`InternalUnitDescription`"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
#[serde(tag = "kind")]
pub enum InternalUnitDescription {
#[doc = "a unit variant"]
#[serde(rename = "off")]
Off,
#[doc = "a struct variant"]
#[serde(rename = "wait")]
Wait {
reason: ::std::string::String,
seconds: u32,
},
}
#[doc = "`IpNet`"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
#[serde(untagged)]
Expand Down
Loading