helm-schema-k8s 0.0.4

Generate an accurate JSON schema for any helm chart
Documentation
use super::provider_schema_fragment::ProviderSchemaFragment;

/// Result of a single provider answering "do you own this resource,
/// and if so, can you resolve this path?". Provider-local: emits no
/// diagnostics directly. The chain ([`crate::lookup::Chain`])
/// records these outcomes in a lookup trace, projects diagnostics
/// from final misses, and returns the public
/// [`crate::lookup::ChainLookupOutcome`].
// Transient by-value result; the `Found` variant's size does not justify
// boxing the other (unit) variants.
#[expect(
    clippy::large_enum_variant,
    reason = "this transient result avoids a heap allocation on every successful lookup"
)]
#[derive(Clone, Debug)]
pub enum ProviderLookupResult {
    /// Provider owns the resource AND resolved the requested path.
    /// `resolved_k8s_version` is `Some(...)` when the K8s provider
    /// answered via a non-primary (fallback) version; the chain uses
    /// it to emit `ResolvedFromFallbackVersion`.
    Found {
        /// Materialized schema at the requested resource path.
        schema: ProviderSchemaFragment,
        /// Fallback Kubernetes release that supplied the schema, if any.
        resolved_k8s_version: Option<String>,
    },

    /// Provider owns the resource AND found the resource doc, but the
    /// requested YAML path is not present in it. NOT a missing-schema
    /// situation — preserves the intentional "silent coverage gap"
    /// behaviour: a chart referencing `.foo.bar.baz` where the schema
    /// only documents `.foo.bar` produces no warning. The chain treats
    /// this exactly like `Found { schema: null }` for diagnostic
    /// purposes.
    PathUnresolved,

    /// Provider owns the resource (claimed it in `has_resource`) but
    /// its expected source file is genuinely missing — e.g. a transient
    /// fetch error in `schema_fragment_for_resource_path` after `has_resource`
    /// returned true. Rare; the chain treats this as equivalent to
    /// `NotOwned` and moves on (since some other provider may still
    /// have it). Local overrides are the exception: see the chain's
    /// origin-specific handling.
    ///
    /// `source_path` is the filesystem path the provider tried to read
    /// (when applicable — non-local providers may leave it empty).
    /// Threaded to `Diagnostic::LocalOverrideUnreadable.override_path`
    /// when the local override layer is the one reporting.
    ResourceDocMissing {
        /// Human-readable I/O or transport failure.
        io_error: String,
        /// Filesystem path or URL that could not be loaded.
        source_path: String,
    },

    /// Provider does not own the resource at any configured version.
    /// Chain moves on to the next provider.
    NotOwned,
}

impl ProviderLookupResult {
    /// Returns the found schema fragment and discards non-success outcomes.
    #[must_use]
    pub fn into_schema_fragment(self) -> Option<ProviderSchemaFragment> {
        match self {
            Self::Found { schema, .. } => Some(schema),
            Self::PathUnresolved | Self::ResourceDocMissing { .. } | Self::NotOwned => None,
        }
    }
}