jacquard_api/pub_leaflet/blocks/
header.rs1use jacquard_common::CowStr;
9
10#[allow(unused_imports)]
11use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
12use jacquard_derive::{IntoStatic, lexicon};
13use jacquard_lexicon::lexicon::LexiconDoc;
14use jacquard_lexicon::schema::LexiconSchema;
15
16#[allow(unused_imports)]
17use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
18use serde::{Serialize, Deserialize};
19use crate::pub_leaflet::richtext::facet::Facet;
20
21#[lexicon]
22#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
23#[serde(rename_all = "camelCase")]
24pub struct Header<'a> {
25 #[serde(skip_serializing_if = "Option::is_none")]
26 #[serde(borrow)]
27 pub facets: Option<Vec<Facet<'a>>>,
28 #[serde(skip_serializing_if = "Option::is_none")]
29 pub level: Option<i64>,
30 #[serde(borrow)]
31 pub plaintext: CowStr<'a>,
32}
33
34impl<'a> LexiconSchema for Header<'a> {
35 fn nsid() -> &'static str {
36 "pub.leaflet.blocks.header"
37 }
38 fn def_name() -> &'static str {
39 "main"
40 }
41 fn lexicon_doc() -> LexiconDoc<'static> {
42 lexicon_doc_pub_leaflet_blocks_header()
43 }
44 fn validate(&self) -> Result<(), ConstraintError> {
45 if let Some(ref value) = self.level {
46 if *value > 6i64 {
47 return Err(ConstraintError::Maximum {
48 path: ValidationPath::from_field("level"),
49 max: 6i64,
50 actual: *value,
51 });
52 }
53 }
54 if let Some(ref value) = self.level {
55 if *value < 1i64 {
56 return Err(ConstraintError::Minimum {
57 path: ValidationPath::from_field("level"),
58 min: 1i64,
59 actual: *value,
60 });
61 }
62 }
63 Ok(())
64 }
65}
66
67fn lexicon_doc_pub_leaflet_blocks_header() -> LexiconDoc<'static> {
68 #[allow(unused_imports)]
69 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
70 use jacquard_lexicon::lexicon::*;
71 use alloc::collections::BTreeMap;
72 LexiconDoc {
73 lexicon: Lexicon::Lexicon1,
74 id: CowStr::new_static("pub.leaflet.blocks.header"),
75 defs: {
76 let mut map = BTreeMap::new();
77 map.insert(
78 SmolStr::new_static("main"),
79 LexUserType::Object(LexObject {
80 required: Some(vec![SmolStr::new_static("plaintext")]),
81 properties: {
82 #[allow(unused_mut)]
83 let mut map = BTreeMap::new();
84 map.insert(
85 SmolStr::new_static("facets"),
86 LexObjectProperty::Array(LexArray {
87 items: LexArrayItem::Ref(LexRef {
88 r#ref: CowStr::new_static("pub.leaflet.richtext.facet"),
89 ..Default::default()
90 }),
91 ..Default::default()
92 }),
93 );
94 map.insert(
95 SmolStr::new_static("level"),
96 LexObjectProperty::Integer(LexInteger {
97 minimum: Some(1i64),
98 maximum: Some(6i64),
99 ..Default::default()
100 }),
101 );
102 map.insert(
103 SmolStr::new_static("plaintext"),
104 LexObjectProperty::String(LexString { ..Default::default() }),
105 );
106 map
107 },
108 ..Default::default()
109 }),
110 );
111 map
112 },
113 ..Default::default()
114 }
115}