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 /// Whether descriptions are removed from final output.
11 pub strip_descriptions: bool,
12 /// Whether redundant schema structure is minimized.
13 pub minimize: bool,
14}
15
16/// Input-loading policy for schema documents that must be prepared before
17/// final output transforms run.
18#[derive(Debug, Clone, Copy)]
19pub struct PolicyInputOptions {
20 /// Whether required remote documents may be fetched.
21 pub fetch_policy: FetchPolicy,
22 /// Byte and entry limits applied while loading documents.
23 pub load_budget: LoadBudget,
24}
25
26/// How final output should handle JSON Schema references.
27///
28/// This is an output concern only. It controls whether file/URL references are
29/// resolved into a self-contained schema or preserved literally for consumers
30/// that want to manage references themselves.
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum ReferencePolicy {
33 /// Bundle referenced schemas while retaining reusable local definitions.
34 SelfContained,
35 /// Resolve and inline every reachable reference for export.
36 FullyInlinedExport,
37 /// Preserve references exactly for the downstream consumer.
38 PreserveRefs,
39}
40
41impl ReferencePolicy {
42 pub(crate) const fn annotation_name(self) -> &'static str {
43 match self {
44 Self::SelfContained => "bundled",
45 Self::FullyInlinedExport => "fully-inlined",
46 Self::PreserveRefs => "preserved",
47 }
48 }
49
50 /// Resolves mutually exclusive CLI flags into one reference policy.
51 #[must_use]
52 pub fn from_flags(keep_refs: bool, inline_refs: bool) -> Self {
53 if keep_refs {
54 Self::PreserveRefs
55 } else if inline_refs {
56 Self::FullyInlinedExport
57 } else {
58 Self::SelfContained
59 }
60 }
61}
62
63/// One final-output request owning reference and output-transform policy.
64#[derive(Debug, Clone, Copy)]
65pub struct EmitRequest {
66 /// Reference preparation and final-output policy.
67 pub reference_policy: ReferencePolicy,
68 /// Output transforms independent of reference handling.
69 pub output: OutputPipelineOptions,
70}
71
72/// JSON serialization format for the final schema document.
73#[derive(Debug, Clone, Copy, PartialEq, Eq)]
74pub enum JsonOutputFormat {
75 /// Indented, human-readable JSON.
76 Pretty,
77 /// Whitespace-minimized JSON.
78 Compact,
79}
80
81impl JsonOutputFormat {
82 /// Selects compact or pretty JSON from the CLI flag.
83 #[must_use]
84 pub fn from_compact(compact: bool) -> Self {
85 if compact { Self::Compact } else { Self::Pretty }
86 }
87}
88
89#[cfg(test)]
90#[path = "tests/options.rs"]
91mod tests;