schemadoc_diff/exporters/
mod.rs

1pub mod markdown;
2
3use indexmap::IndexMap;
4
5use crate::checker::ValidationIssue;
6use crate::path_pointer::{PathPointer, PathPointerScope};
7
8pub struct Text(String, bool);
9
10impl Text {
11    pub fn new(text: String, is_empty: bool) -> Self {
12        Text(text, is_empty)
13    }
14    pub fn inner(&self) -> &str {
15        &self.0
16    }
17    pub fn is_empty(&self) -> bool {
18        self.1
19    }
20}
21
22pub struct Markdown(String, bool);
23
24impl Markdown {
25    pub fn new(text: String, is_empty: bool) -> Self {
26        Markdown(text, is_empty)
27    }
28    pub fn as_str(&self) -> &str {
29        &self.0
30    }
31    pub fn is_empty(&self) -> bool {
32        self.1
33    }
34}
35
36pub trait Exporter<R> {
37    fn export(
38        &self,
39        info: IndexMap<&str, &str>,
40        version_url: &str,
41        invalid_only: bool,
42        path_filters: Option<&[String]>,
43        validations: Option<&[ValidationIssue]>,
44    ) -> R;
45}
46
47pub fn display_uri(pointer: &PathPointer) -> String {
48    if let Some(component) = pointer.get(PathPointerScope::Path) {
49        component
50            .path
51            .as_ref()
52            .map_or_else(|| "".to_string(), |x| x.clone())
53    } else {
54        "".to_string()
55    }
56}
57
58pub fn display_method(pointer: &PathPointer) -> String {
59    if let Some(component) = pointer.get(PathPointerScope::Operation) {
60        component
61            .path
62            .as_ref()
63            .map_or_else(|| "".to_string(), |x| x.clone())
64    } else {
65        "".to_string()
66    }
67}