json_utils/schema/
schema_description.rs1use crate::json::JsValue;
2
3use super::ExtraProps;
4
5const KEY: &'static str = "description";
6
7pub trait SchemaDescription {
8 fn description(&self) -> Option<&str>;
9 fn with_description(self, description: &str) -> Self;
10}
11
12impl<S: ExtraProps> SchemaDescription for S {
13 fn description(&self) -> Option<&str> {
14 self.extra_props().get(KEY).and_then(JsValue::as_str)
15 }
16 fn with_description(mut self, description: &str) -> Self {
17 let extra_props = self.extra_props_mut();
18 let _ = extra_props.insert(KEY.to_owned(), JsValue::String(description.to_owned()));
19 self
20 }
21}