diff --git a/typify-impl/src/enums.rs b/typify-impl/src/enums.rs index 9f657d9b..7a3ea4b3 100644 --- a/typify-impl/src/enums.rs +++ b/typify-impl/src/enums.rs @@ -387,7 +387,7 @@ impl TypeSpace { Ok(Variant::new( variant_name.to_string(), - None, + metadata_title_and_description(metadata), VariantDetails::Unit, )) } else { @@ -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(); diff --git a/typify/tests/schemas/various-enums-json-schema.rs b/typify/tests/schemas/various-enums-json-schema.rs index 5307883e..0d0c3967 100644 --- a/typify/tests/schemas/various-enums-json-schema.rs +++ b/typify/tests/schemas/various-enums-json-schema.rs @@ -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 for AdjacentUnitDescription { + fn from(value: u32) -> Self { + Self::Wait(value) + } +} #[doc = "`AlternativeEnum`"] #[derive( :: serde :: Deserialize, @@ -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)] diff --git a/typify/tests/schemas/various-enums.json b/typify/tests/schemas/various-enums.json index 4379a4d6..7a8cf63a 100644 --- a/typify/tests/schemas/various-enums.json +++ b/typify/tests/schemas/various-enums.json @@ -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"] + } + ] } } } diff --git a/typify/tests/schemas/various-enums.rs b/typify/tests/schemas/various-enums.rs index 16cc30e2..9fc357f4 100644 --- a/typify/tests/schemas/various-enums.rs +++ b/typify/tests/schemas/various-enums.rs @@ -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 for AdjacentUnitDescription { + fn from(value: u32) -> Self { + Self::Wait(value) + } +} #[doc = "`AlternativeEnum`"] #[derive( :: serde :: Deserialize, @@ -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)]