Sign in

    smithy-diff

    Compare assembled Smithy models for compatibility

    smithy
    diff
    moonbit
    Download zip
    Author
    Version
    0.5.0
    License
    Apache-2.0
    Last updated
    2 days ago
    Downloads
    16

    #Model compatibility differences

    Compare assembled models without filesystem or network access:

    ///|
    pub fn compare_models(
    old_model : @smithy.Model,
    new_model : @smithy.Model,
    ) -> Bool {
    let result = @diff.compare(old_model, new_model)
    for event in result.events {
    println(event.id + ": " + event.message)
    }
    result.is_breaking()
    }

    Differences::detect exposes added and removed shapes, changed shapes with their trait changes, and metadata changes. Source locations and assembly provenance do not cause differences. Container changes include changes to their member shapes.

    compare evaluates the built-in compatibility rules from the pinned Smithy reference, including member targets, constraints, nullability, defaults, entity bindings, trait breaking-change definitions and legacy diff tags. It applies the new model's suppressions and severity overrides, then preview-feature downgrades. The reference's authentication-scheme evaluator currently emits no events.

    Events use the shared smithy.ValidationEvent type. events includes suppressed events and has deterministic order by event ID, shape ID, severity and message. is_breaking() is true when an event has ERROR or DANGER severity.

    The constraint evaluators preserve two quirks of the pinned reference. They compare @length and @range bounds only when the trait exists in both models; adding either trait uses the generic NOTE event. Both evaluators substitute zero for an absent minimum, including @range. Introducing a nonpositive range minimum therefore produces no constraint ERROR, while removing a negative minimum can produce one. The local constraint-boundary reference cases record these behaviors. is_breaking() follows the reference's event severities.

    smithy diff --old old-model.smithy --new new-model.smithy smithy diff --old old-models/ --new new-models/ --output changes.txt

    The CLI assembles each file or directory independently using local resource discovery, including JAR manifests. It prints each unsuppressed difference on one line, escaping message newlines as \n. Breaking changes or invalid models exit with status 1; invalid arguments exit with status 2. Unchanged or compatible models exit with status 0. Git and project comparison modes are not implemented.

    The committed reference event manifest is generated by mise run tck:reference:diff. Regeneration requires the pinned upstream source snapshot and a JDK. --check verifies it without rewriting. Normal tests read the committed expectations and require neither Java nor network access.

    ValidationEvent

    A Smithy validation finding after configured severity and suppression rules.

    Differences

    Semantic changes ignore source locations and assembly provenance. Container changes include changes to their first-class members.

    Differences::detect

    MetadataChange

    pub struct MetadataChange {
    key : String
    old_value :
    NodeValue
    ?
    new_value :
    NodeValue
    ?
    } derive(Eq,
    Debug
    )

    Result

    Result::is_breaking

    fn Result::is_breaking(self : Result) -> Bool

    ShapeChange

    pub struct ShapeChange {
    old_shape :
    Shape

    new_shape :
    Shape

    traits : Array[TraitChange]
    } derive(Eq,
    Debug
    )

    TraitChange

    A changed applied trait, including additions and removals.

    compare

    fn compare(old_model :
    Model
    , new_model :
    Model
    ) -> Result

    Compare two assembled models using the built-in Smithy compatibility rules. Events retain suppressions and are sorted by ID, shape, severity and message.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io