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/// How to handle fields that already have comments
11#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
12pub enum ExistingCommentBehavior {
13    /// Skip annotating fields that already have comments
14    Skip,
15    /// Add annotation before existing comment
16    #[default]
17    Prepend,
18    /// Add annotation after existing comment
19    Append,
20    /// Replace existing comment with annotation
21    Replace,
22}
23
24/// Configuration for annotation behavior
25#[derive(Debug, Clone)]
26pub struct AnnotatorConfig {
27    /// Include title in comments
28    pub include_title: bool,
29    /// Include description in comments
30    pub include_description: bool,
31    /// Include default value in comments
32    pub include_default: bool,
33    /// Maximum line width for wrapping descriptions (None = no wrap)
34    pub max_line_width: Option<usize>,
35    /// How to handle fields that already have comments
36    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    /// Create a config that only includes titles
53    pub fn titles_only() -> Self {
54        Self {
55            include_title: true,
56            include_description: false,
57            ..Default::default()
58        }
59    }
60
61    /// Create a config that only includes descriptions
62    pub fn descriptions_only() -> Self {
63        Self {
64            include_title: false,
65            include_description: true,
66            ..Default::default()
67        }
68    }
69}
70
71/// Common interface for format-specific annotators
72pub trait Annotator {
73    /// Annotate a document with comments from the annotation map
74    fn annotate(
75        &self,
76        content: &str,
77        annotations: &AnnotationMap,
78    ) -> Result<String, AnnotatorError>;
79}