jsonschema_annotator/annotator/
mod.rs1mod toml;
2mod yaml;
3
4pub use self::toml::TomlAnnotator;
5pub use self::yaml::YamlAnnotator;
6
7use crate::error::AnnotatorError;
8use crate::schema::AnnotationMap;
9
10#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
12pub enum ExistingCommentBehavior {
13 Skip,
15 #[default]
17 Prepend,
18 Append,
20 Replace,
22}
23
24#[derive(Debug, Clone)]
26pub struct AnnotatorConfig {
27 pub include_title: bool,
29 pub include_description: bool,
31 pub include_default: bool,
33 pub max_line_width: Option<usize>,
35 pub existing_comments: ExistingCommentBehavior,
37}
38
39impl Default for AnnotatorConfig {
40 fn default() -> Self {
41 Self {
42 include_title: true,
43 include_description: true,
44 include_default: false,
45 max_line_width: Some(80),
46 existing_comments: ExistingCommentBehavior::default(),
47 }
48 }
49}
50
51impl AnnotatorConfig {
52 pub fn titles_only() -> Self {
54 Self {
55 include_title: true,
56 include_description: false,
57 ..Default::default()
58 }
59 }
60
61 pub fn descriptions_only() -> Self {
63 Self {
64 include_title: false,
65 include_description: true,
66 ..Default::default()
67 }
68 }
69}
70
71pub trait Annotator {
73 fn annotate(
75 &self,
76 content: &str,
77 annotations: &AnnotationMap,
78 ) -> Result<String, AnnotatorError>;
79}