Skip to main content

helm_schema/output_pipeline/
options.rs

1use crate::fetch_policy::FetchPolicy;
2use crate::load_budget::LoadBudget;
3
4/// Output-only schema transforms selected by CLI flags.
5///
6/// These transforms run after inference and override merging. They must not
7/// feed information back into template analysis.
8#[derive(Debug, Clone, Copy)]
9pub struct OutputPipelineOptions {
10    /// Reference-preservation or inlining policy.
11    pub reference_mode: ReferenceMode,
12    /// Whether descriptions are removed from final output.
13    pub strip_descriptions: bool,
14    /// Whether redundant schema structure is minimized.
15    pub minimize: bool,
16}
17
18/// Input-loading policy for schema documents that must be prepared before
19/// final output transforms run.
20#[derive(Debug, Clone, Copy)]
21pub struct PolicyInputOptions {
22    /// Reference policy that determines which documents must be loaded.
23    pub reference_mode: ReferenceMode,
24    /// Whether required remote documents may be fetched.
25    pub fetch_policy: FetchPolicy,
26    /// Byte and entry limits applied while loading documents.
27    pub load_budget: LoadBudget,
28}
29
30/// How final output should handle JSON Schema references.
31///
32/// This is an output concern only. It controls whether file/URL references are
33/// resolved into a self-contained schema or preserved literally for consumers
34/// that want to manage references themselves.
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub enum ReferenceMode {
37    /// Bundle referenced schemas while retaining reusable local definitions.
38    SelfContained,
39    /// Resolve and inline every reachable reference for export.
40    FullyInlinedExport,
41    /// Preserve references exactly for the downstream consumer.
42    PreserveRefs,
43}
44
45impl ReferenceMode {
46    /// Resolves mutually exclusive CLI flags into one reference policy.
47    #[must_use]
48    pub fn from_flags(keep_refs: bool, inline_refs: bool) -> Self {
49        if keep_refs {
50            Self::PreserveRefs
51        } else if inline_refs {
52            Self::FullyInlinedExport
53        } else {
54            Self::SelfContained
55        }
56    }
57}
58
59/// JSON serialization format for the final schema document.
60#[derive(Debug, Clone, Copy, PartialEq, Eq)]
61pub enum JsonOutputFormat {
62    /// Indented, human-readable JSON.
63    Pretty,
64    /// Whitespace-minimized JSON.
65    Compact,
66}
67
68impl JsonOutputFormat {
69    /// Selects compact or pretty JSON from the CLI flag.
70    #[must_use]
71    pub fn from_compact(compact: bool) -> Self {
72        if compact { Self::Compact } else { Self::Pretty }
73    }
74}
75
76#[cfg(test)]
77#[path = "tests/options.rs"]
78mod tests;