jsonschema_annotator/annotator/
mod.rs

1mod 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/// Configuration for annotation behavior
11#[derive(Debug, Clone)]
12pub struct AnnotatorConfig {
13    /// Include title in comments
14    pub include_title: bool,
15    /// Include description in comments
16    pub include_description: bool,
17    /// Maximum line width for wrapping descriptions (None = no wrap)
18    pub max_line_width: Option<usize>,
19    /// Preserve existing comments in the document
20    pub preserve_existing: bool,
21}
22
23impl Default for AnnotatorConfig {
24    fn default() -> Self {
25        Self {
26            include_title: true,
27            include_description: true,
28            max_line_width: Some(80),
29            preserve_existing: true,
30        }
31    }
32}
33
34impl AnnotatorConfig {
35    /// Create a config that only includes titles
36    pub fn titles_only() -> Self {
37        Self {
38            include_title: true,
39            include_description: false,
40            ..Default::default()
41        }
42    }
43
44    /// Create a config that only includes descriptions
45    pub fn descriptions_only() -> Self {
46        Self {
47            include_title: false,
48            include_description: true,
49            ..Default::default()
50        }
51    }
52}
53
54/// Common interface for format-specific annotators
55pub trait Annotator {
56    /// Annotate a document with comments from the annotation map
57    fn annotate(
58        &self,
59        content: &str,
60        annotations: &AnnotationMap,
61    ) -> Result<String, AnnotatorError>;
62}