sdml-generate 0.3.2

Simple Domain Modeling Language (SDML) generated Artifacts
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
/*!
This module provides generators that create documentation of a module given its in-memory representation.

More detailed description, with

# Example

End of file during parsingSymbol’s value as variable is void: rustEnd of file during parsing

 */

use crate::convert::doc::common::ArgumentType;
use crate::convert::doc::common::Formatter;
use crate::errors::into_generator_error;
use sdml_core::error::Error;
use sdml_core::load::ModuleLoader;
use sdml_core::model::identifiers::{Identifier, IdentifierReference};
use sdml_core::model::modules::Module;
use sdml_core::store::ModuleStore;
use serde::de::Visitor;
use serde::Deserializer;
use serde::Serializer;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::fs::read_to_string;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use tracing::error;

// ------------------------------------------------------------------------------------------------
// Public Macros
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Public Types
// ------------------------------------------------------------------------------------------------

///
/// This structure models a heading which has a level and a string title. The level is unsigned but
/// a value of `0` denotes a /pseudo-heading/ (see [common::BlockFormat]). Also the notion of a
/// document title is separately specified at the page level (see [common::PageFormat]).
///
/// A heading may also include a label string that acts as an identifier, or anchor, for the
/// heading.
///
#[derive(Clone, Debug)]
pub struct Heading {
    level: u8,
    title: String,
    label: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AnnotationCategories {
    labels: Vec<IdentifierReference>,
    definitions: Vec<IdentifierReference>,
    descriptions: Vec<IdentifierReference>,
    comments: Vec<IdentifierReference>,
    references: Vec<IdentifierReference>,
}

pub trait DocumentationWriter<TInclude, TSource, F>
where
    TInclude: ArgumentType,
    TSource: ArgumentType,
    F: Formatter<TInclude, TSource>,
{
    fn formatter() -> &'static F;

    fn write_book<T>(
        &mut self,
        loader: &mut T,
        cache: &mut impl ModuleStore,
        book_config: BookConfig,
    ) -> Result<(), Error>
    where
        T: ModuleLoader;

    fn write_preamble<W>(
        &mut self,
        title: &str,
        language: &str,
        include_toc: bool,
        writer: &mut W,
    ) -> Result<(), Error>
    where
        W: Write + Sized;

    fn write_module_uml_overview<W>(
        &mut self,
        module: &Module,
        cache: &impl ModuleStore,
        writer: &mut W,
    ) -> Result<(), Error>
    where
        W: Write + Sized;

    fn write_module_description<W>(
        &mut self,
        heading: Heading,
        module: &Module,
        cache: &impl ModuleStore,
        writer: &mut W,
    ) -> Result<(), Error>
    where
        W: Write + Sized;

    fn write_module_definitions<W>(
        &mut self,
        heading_level: u8,
        module: &Module,
        cache: &impl ModuleStore,
        writer: &mut W,
    ) -> Result<(), Error>
    where
        W: Write + Sized;

    fn write_module_sdml_listing<W>(
        &mut self,
        heading: Heading,
        module: &Module,
        writer: &mut W,
    ) -> Result<(), Error>
    where
        W: Write + Sized;

    fn write_module_rdf_listing<W>(
        &mut self,
        heading: Heading,
        module: &Module,
        cache: &impl ModuleStore,
        writer: &mut W,
    ) -> Result<(), Error>
    where
        W: Write + Sized;

    fn write_module_dependency_table<W>(
        &mut self,
        module: &Module,
        cache: &impl ModuleStore,
        writer: &mut W,
    ) -> Result<(), Error>
    where
        W: Write + Sized;

    fn write_module_dependency_graph<W>(
        &mut self,
        heading: Heading,
        module: &Module,
        cache: &impl ModuleStore,
        writer: &mut W,
    ) -> Result<(), Error>
    where
        W: Write + Sized;
}

/// A content section names a list of [`ContentItem`]s.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct ContentSection {
    /// The heading to display for this section.
    heading: String,
    /// The list of items contained in this section, including sub-sections.
    #[serde(default)]
    items: Vec<ContentItem>,
}

/// An item within a [`ContentSection`].
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum ContentItem {
    /// Include a module by file path.
    SourceFile { module_path: PathBuf },
    /// Include a module by module name.
    SourceModule {
        #[serde(serialize_with = "identifier_to_string")]
        #[serde(deserialize_with = "identifier_from_string")]
        module: Identifier,
    },
    /// Include a file's content by file path.
    Include { include_file_path: PathBuf },
    /// Include a sub-section.
    Section { sub_section: ContentSection },
}

/// The generated document format.
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum DocumentFormat {
    /// Emacs Org-Mode
    #[default]
    OrgMode,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BookConfig {
    /// Title to generate for the book as a whole.
    title: String,
    /// An optional file to include between the page front-matter and the first content.
    #[serde(skip_serializing_if = "Option::is_none")]
    introduction: Option<PathBuf>,
    /// The first content section, this
    content: ContentSection,
    /// The format of the document itself, usually a markup language. The default value is
    /// [`DocumentFormat::OrgMode`].
    #[serde(default)]
    output_format: DocumentFormat,
    /// The name of the root document. Default is `"index.org"`.
    output_file: PathBuf,
    /// A BCP-47 language-tag to identify the output language.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    language: Option<String>,
    /// The set of boolean options for document generation.
    #[serde(flatten)]
    options: BookOptions,
    /// Mapping from a category to a set of annotation Identifier references.
    #[serde(skip)]
    annotation_categories: AnnotationCategories,
}

#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
pub struct BookOptions {
    /// If `true`, include a Table of Contents in the root document. Default is `true`.
    #[serde(default = "default_to_true")]
    include_toc: bool,
    /// If `true`, attempt to construct the root document as a link-only file. Default is `true`.
    #[serde(default = "default_to_true")]
    multi_part: bool,
    /// If `true`, attempt to copy any included file into the directory of the root file.
    /// Default is `false`.
    #[serde(default)]
    copy_includes: bool,
    /// If `true`, the appendix containing a module's dependency graph will not be generated.
    /// Default is `false`.
    #[serde(default)]
    skip_dependency_graphs: bool,
    /// If `true`, the appendix containing a module's source listing will not be generated.
    /// Default is `false`.
    #[serde(default)]
    skip_sdml_listings: bool,
    /// If `true`, the appendix containing a module's RDF representation listing will not be
    /// generated. Default is `false`.
    #[serde(default)]
    skip_rdf_listings: bool,
}

// ------------------------------------------------------------------------------------------------
// Public Functions
// ------------------------------------------------------------------------------------------------

#[inline(always)]
fn default_to_true() -> bool {
    true
}

// ------------------------------------------------------------------------------------------------
// Private Macros
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Private Types
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Implementations
// ------------------------------------------------------------------------------------------------

impl Default for AnnotationCategories {
    fn default() -> Self {
        Self {
            labels: vec![
                // prefLabel is required.
                IdentifierReference::from_str("skos:altLabel").unwrap(),
                IdentifierReference::from_str("rdfs:label").unwrap(),
                IdentifierReference::from_str("sdml:srcLabel").unwrap(),
            ],
            definitions: vec![IdentifierReference::from_str("skos:definition").unwrap()],
            descriptions: vec![
                IdentifierReference::from_str("dc:description").unwrap(),
                IdentifierReference::from_str("dc_terms:description").unwrap(),
            ],
            comments: vec![
                IdentifierReference::from_str("rdfs:comment").unwrap(),
                IdentifierReference::from_str("skos:note").unwrap(),
                IdentifierReference::from_str("skos:changeNote").unwrap(),
                IdentifierReference::from_str("skos:editorialNote").unwrap(),
                IdentifierReference::from_str("skos:historyNote").unwrap(),
                IdentifierReference::from_str("skos:scopeNote").unwrap(),
                IdentifierReference::from_str("skos:example").unwrap(),
            ],
            references: vec![
                IdentifierReference::from_str("rdfs:seeAlso").unwrap(),
                IdentifierReference::from_str("rdfs:isDefinedBy").unwrap(),
                IdentifierReference::from_str("dc_terms:alternative").unwrap(),
                IdentifierReference::from_str("dc_terms:isFormatOf").unwrap(),
                IdentifierReference::from_str("dc_terms:isPartOf").unwrap(),
                IdentifierReference::from_str("dc_terms:isReferencedBy").unwrap(),
                IdentifierReference::from_str("dc_terms:isReplacedBy").unwrap(),
                IdentifierReference::from_str("dc_terms:isRequiredBy").unwrap(),
                IdentifierReference::from_str("dc_terms:isRequiredBy").unwrap(),
                IdentifierReference::from_str("dc_terms:isVersionOf").unwrap(),
            ],
        }
    }
}

impl AnnotationCategories {
    pub const fn label_properties(&self) -> &Vec<IdentifierReference> {
        &self.labels
    }

    pub const fn definition_properties(&self) -> &Vec<IdentifierReference> {
        &self.definitions
    }

    pub const fn description_properties(&self) -> &Vec<IdentifierReference> {
        &self.descriptions
    }

    pub const fn comment_properties(&self) -> &Vec<IdentifierReference> {
        &self.comments
    }

    pub const fn reference_properties(&self) -> &Vec<IdentifierReference> {
        &self.references
    }
}

// ------------------------------------------------------------------------------------------------

impl Heading {
    const LEVEL_SECTION: u8 = 1;
    const LEVEL_SUBSECTION: u8 = 2;
    const LEVEL_SUBSUBSECTION: u8 = 3;

    pub fn new<S>(level: u8, title: S) -> Self
    where
        S: Into<String>,
    {
        Self {
            level,
            title: title.into(),
            label: Default::default(),
        }
    }

    pub fn with_label<S>(mut self, label: S) -> Self
    where
        S: Into<String>,
    {
        self.label = Some(label.into());
        self
    }

    pub fn new_section<S>(title: S) -> Self
    where
        S: Into<String>,
    {
        Self::new(Self::LEVEL_SECTION, title)
    }

    pub fn new_subsection<S>(title: S) -> Self
    where
        S: Into<String>,
    {
        Self::new(Self::LEVEL_SUBSECTION, title)
    }

    pub fn new_subsubsection<S>(title: S) -> Self
    where
        S: Into<String>,
    {
        Self::new(Self::LEVEL_SUBSUBSECTION, title)
    }

    pub const fn level(&self) -> u8 {
        self.level
    }

    pub const fn is_section(&self) -> bool {
        self.level == Self::LEVEL_SECTION
    }

    pub const fn is_subsection(&self) -> bool {
        self.level == Self::LEVEL_SUBSECTION
    }

    pub const fn is_subsubsection(&self) -> bool {
        self.level == Self::LEVEL_SUBSUBSECTION
    }

    pub fn title(&self) -> &str {
        self.title.as_ref()
    }

    pub const fn label(&self) -> Option<&String> {
        self.label.as_ref()
    }
}

// ------------------------------------------------------------------------------------------------

impl Default for BookOptions {
    fn default() -> Self {
        Self {
            include_toc: true,
            multi_part: true,
            copy_includes: Default::default(),
            skip_dependency_graphs: Default::default(),
            skip_sdml_listings: Default::default(),
            skip_rdf_listings: Default::default(),
        }
    }
}

impl BookOptions {
    pub const fn with_toc(self, include_toc: bool) -> Self {
        let mut self_mut = self;
        self_mut.include_toc = include_toc;
        self_mut
    }

    pub const fn include_toc(&self) -> bool {
        self.include_toc
    }

    pub const fn with_multi_part(self, multi_part: bool) -> Self {
        let mut self_mut = self;
        self_mut.multi_part = multi_part;
        self_mut
    }

    pub const fn multi_part(&self) -> bool {
        self.multi_part
    }

    pub const fn with_copy_includes(self, copy_includes: bool) -> Self {
        let mut self_mut = self;
        self_mut.copy_includes = !copy_includes;
        self_mut
    }

    pub const fn copy_includes(&self) -> bool {
        self.copy_includes
    }

    pub const fn with_dependency_graphs(self, dependency_graphs: bool) -> Self {
        let mut self_mut = self;
        self_mut.skip_dependency_graphs = !dependency_graphs;
        self_mut
    }

    pub const fn skip_dependency_graphs(&self) -> bool {
        self.skip_dependency_graphs
    }

    pub const fn with_sdml_listings(self, sdml_listings: bool) -> Self {
        let mut self_mut = self;
        self_mut.skip_sdml_listings = !sdml_listings;
        self_mut
    }

    pub const fn skip_sdml_listings(&self) -> bool {
        self.skip_sdml_listings
    }

    pub const fn with_rdf_listings(self, rdf_listings: bool) -> Self {
        let mut self_mut = self;
        self_mut.skip_rdf_listings = !rdf_listings;
        self_mut
    }

    pub const fn skip_rdf_listings(&self) -> bool {
        self.skip_rdf_listings
    }
}

// ------------------------------------------------------------------------------------------------

impl Default for BookConfig {
    fn default() -> Self {
        Self {
            title: Default::default(),
            introduction: Default::default(),
            content: Default::default(),
            output_format: DocumentFormat::OrgMode,
            output_file: "index.org".into(),
            language: Default::default(),
            options: Default::default(),
            annotation_categories: Default::default(),
        }
    }
}

impl FromStr for BookConfig {
    type Err = Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match serde_json::from_str(s) {
            Ok(config) => Ok(config),
            Err(err) => {
                error!(
                    ?s,
                    ?err,
                    "Could not de-serialize BookConfig from provided string"
                );
                Err(into_generator_error("doc-book", err))
            }
        }
    }
}

impl BookConfig {
    pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
        let content = read_to_string(path)?;
        Self::from_str(&content)
    }

    pub fn item_count(&self) -> usize {
        self.introduction.as_ref().map(|_| 1).unwrap_or_default() + self.content.item_count()
    }

    pub fn with_title<S>(self, title: S) -> Self
    where
        S: Into<String>,
    {
        let mut self_mut = self;
        self_mut.title = title.into();
        self_mut
    }

    pub const fn title(&self) -> &String {
        &self.title
    }

    pub fn with_introduction<P>(self, introduction_file: P) -> Self
    where
        P: Into<PathBuf>,
    {
        let mut self_mut = self;
        self_mut.introduction = Some(introduction_file.into());
        self_mut
    }

    pub const fn introduction(&self) -> Option<&PathBuf> {
        self.introduction.as_ref()
    }

    pub fn with_content(self, content: ContentSection) -> Self {
        let mut self_mut = self;
        self_mut.content = content;
        self_mut
    }

    pub const fn content(&self) -> &ContentSection {
        &self.content
    }

    pub fn with_output_format<S>(self, output_format: DocumentFormat) -> Self {
        let mut self_mut = self;
        self_mut.output_format = output_format;
        self_mut
    }

    pub const fn output_format(&self) -> DocumentFormat {
        self.output_format
    }

    pub fn with_output_file<P>(self, output_file: P) -> Self
    where
        P: Into<PathBuf>,
    {
        let mut self_mut = self;
        self_mut.output_file = output_file.into();
        self_mut
    }

    pub const fn output_file(&self) -> &PathBuf {
        &self.output_file
    }

    pub fn with_language<S>(self, language: S) -> Self
    where
        S: Into<String>,
    {
        let mut self_mut = self;
        self_mut.language = Some(language.into());
        self_mut
    }

    pub const fn language(&self) -> Option<&String> {
        self.language.as_ref()
    }

    pub fn with_options(self, options: BookOptions) -> Self {
        let mut self_mut = self;
        self_mut.options = options;
        self_mut
    }

    pub const fn options(&self) -> &BookOptions {
        &self.options
    }

    pub fn with_annotation_categories(self, annotation_categories: AnnotationCategories) -> Self {
        let mut self_mut = self;
        self_mut.annotation_categories = annotation_categories;
        self_mut
    }

    pub const fn annotation_categories(&self) -> &AnnotationCategories {
        &self.annotation_categories
    }
}

// ------------------------------------------------------------------------------------------------

impl ContentSection {
    pub fn new<S, I>(heading: S, items: Vec<I>) -> Self
    where
        S: Into<String>,
        I: Into<ContentItem>,
    {
        Self {
            heading: heading.into(),
            items: items.into_iter().map(|i| i.into()).collect(),
        }
    }

    pub fn item_count(&self) -> usize {
        self.items
            .iter()
            .map(|item| match item {
                ContentItem::SourceFile { .. } => 1,
                ContentItem::SourceModule { .. } => 1,
                ContentItem::Include { .. } => 1,
                ContentItem::Section { sub_section } => sub_section.item_count(),
            })
            .sum()
    }

    pub fn with_heading<S>(self, heading: S) -> Self
    where
        S: Into<String>,
    {
        let mut self_mut = self;
        self_mut.heading = heading.into();
        self_mut
    }

    pub fn heading(&self) -> &String {
        &self.heading
    }

    pub fn with_items<I>(self, items: Vec<I>) -> Self
    where
        I: Into<ContentItem>,
    {
        let mut self_mut = self;
        self_mut.items = items.into_iter().map(|i| i.into()).collect();
        self_mut
    }

    pub fn with_item<I>(self, item: I) -> Self
    where
        I: Into<ContentItem>,
    {
        let mut self_mut = self;
        self_mut.items.push(item.into());
        self_mut
    }

    pub fn with_source_file(self, module_path: PathBuf) -> Self {
        Self::with_item(self, ContentItem::SourceFile { module_path })
    }

    pub fn with_source_module(self, module: Identifier) -> Self {
        Self::with_item(self, ContentItem::SourceModule { module })
    }

    pub fn with_include(self, include_file_path: PathBuf) -> Self {
        Self::with_item(self, ContentItem::Include { include_file_path })
    }

    pub fn with_sub_section(self, sub_section: ContentSection) -> Self {
        Self::with_item(self, ContentItem::Section { sub_section })
    }

    pub fn items(&self) -> &Vec<ContentItem> {
        &self.items
    }
}

// ------------------------------------------------------------------------------------------------

impl From<ContentSection> for ContentItem {
    fn from(sub_section: ContentSection) -> Self {
        Self::Section { sub_section }
    }
}

impl From<Identifier> for ContentItem {
    fn from(module: Identifier) -> Self {
        Self::SourceModule { module }
    }
}

// ------------------------------------------------------------------------------------------------
// Private Functions
// ------------------------------------------------------------------------------------------------

fn identifier_to_string<S>(name: &Identifier, se: S) -> Result<S::Ok, S::Error>
where
    S: Serializer,
{
    se.serialize_str(name.as_ref())
}

struct IdentifierVisitor;

impl Visitor<'_> for IdentifierVisitor {
    type Value = Identifier;

    fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        formatter.write_str("a string representing an SDML Identifier")
    }

    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
    where
        E: serde::de::Error,
    {
        Identifier::from_str(v).map_err(|e| E::custom(e))
    }
}

fn identifier_from_string<'de, D>(de: D) -> Result<Identifier, D::Error>
where
    D: Deserializer<'de>,
{
    let visitor = IdentifierVisitor;
    de.deserialize_str(visitor)
}

// ------------------------------------------------------------------------------------------------
// Modules
// ------------------------------------------------------------------------------------------------

pub mod markdown;

pub mod org_mode;

pub mod common;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_config_json_writer() {
        let config = BookConfig::default()
            .with_title("My Project")
            .with_options(BookOptions::default().with_toc(false))
            .with_introduction(PathBuf::from("./introduction.org"))
            .with_content(
                ContentSection::default()
                    .with_heading("Content Heading")
                    .with_include(PathBuf::from("./accounts.org"))
                    .with_source_module(Identifier::new_unchecked("account"))
                    .with_source_module(Identifier::new_unchecked("customer"))
                    .with_source_file(PathBuf::from("./account_enums.sdml")),
            );
        let json = serde_json::to_string_pretty(&config).unwrap();
        println!("{json}");
    }

    #[test]
    fn test_config_json_reader() {
        const JSON: &str = r##"{
  "title": "My Project",
  "introduction": "./introduction.org",
  "content": {
    "heading": "Content Heading",
    "items": [
      { "include_file_path": "./accounts.org" },
      {  "module": "account" },
      { "module": "customer" },
      { "module_path": "./account_enums.sdml" }
    ]
  },
  "output_format": "org-mode",
  "output_file": "index.org",
  "options": {
    "include_toc": false,
    "multi_part": false,
    "copy_includes": false
  }
}"##;
        let config: BookConfig = serde_json::from_str(JSON).unwrap();
        println!("{config:?}");
    }
}