diff --git a/src/openapi/ref_or.rs b/src/openapi/ref_or.rs index 778efaa..81d4ae4 100644 --- a/src/openapi/ref_or.rs +++ b/src/openapi/ref_or.rs @@ -104,6 +104,9 @@ pub struct Ref { #[serde(rename = "$ref")] target: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + description: Option, + /// YAML fields we want to pass through blindly. #[serde(flatten)] unknown_fields: BTreeMap, @@ -111,9 +114,10 @@ pub struct Ref { impl Ref { /// Construct a ref pointing to `target`. - pub(crate) fn new>(target: S) -> Ref { + pub(crate) fn new>(target: S, description: Option) -> Ref { Ref { target: target.into(), + description, unknown_fields: Default::default(), } } @@ -124,7 +128,7 @@ impl Transpile for Ref { fn transpile(&self, _scope: &Scope) -> anyhow::Result { if !self.unknown_fields.is_empty() { - return Err(format_err!("`$ref:` must not have any sibling values")); + return Err(format_err!("`$ref:` no unknown sibling values allowed")); } Ok(self.clone()) @@ -139,6 +143,9 @@ pub struct InterfaceRef { #[serde(rename = "$interface")] target: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + description: Option, + /// YAML fields we want to pass through blindly. #[serde(flatten)] unknown_fields: BTreeMap, @@ -151,7 +158,9 @@ impl Transpile for InterfaceRef { fn transpile(&self, scope: &Scope) -> anyhow::Result { // This type is defined by us, so let's enforce this rule. if !self.unknown_fields.is_empty() { - return Err(format_err!("`$include:` must not have any sibling values")); + return Err(format_err!( + "`$interface:` no unknown sibling values allowed" + )); } // Figure out which interface variant to use. @@ -171,10 +180,13 @@ impl Transpile for InterfaceRef { }; // Build our ref. - Ok(Ref::new(format!( - "#/components/schemas/{}{}", - &self.target[..fragment_pos], - variety.to_schema_suffix_str() - ))) + Ok(Ref::new( + format!( + "#/components/schemas/{}{}", + &self.target[..fragment_pos], + variety.to_schema_suffix_str() + ), + self.description.clone(), + )) } } diff --git a/src/openapi/schema.rs b/src/openapi/schema.rs index 12ffc92..bebef6e 100644 --- a/src/openapi/schema.rs +++ b/src/openapi/schema.rs @@ -73,7 +73,8 @@ impl Nullable for Schema { fn allowing_null_turns_refs_into_oneof() { use super::ref_or::Ref; - let schema = RefOr::::Ref(Ref::new("#/components/schemas/widget")); + let schema = + RefOr::::Ref(Ref::new("#/components/schemas/widget", None)); assert_eq!( schema.allowing_null(), RefOr::Value(BasicSchema::OneOf(OneOf::new(