Compare assembled Smithy models for compatibility
///|
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()
}///|
test "compare an old and a new weather model" {
let old_model = @smithy.Loader::new()
.add_idl(
"old-weather.smithy",
(
#|$version: "2"
#|
#|namespace example.weather
#|
#|service Weather {
#| version: "2026-10-01"
#| operations: [GetForecast]
#|}
#|
#|operation GetForecast {
#| input := {
#| @required
#| city: String
#|
#| days: Integer
#| }
#|
#| output := {
#| @required
#| summary: String
#|
#| celsius: Integer
#| }
#|}
),
)
.assemble().model.unwrap()
let new_model = @smithy.Loader::new()
.add_idl(
"new-weather.smithy",
(
#|$version: "2"
#|
#|namespace example.weather
#|
#|service Weather {
#| version: "2026-10-01"
#| operations: [GetForecast]
#|}
#|
#|operation GetForecast {
#| input := {
#| @required
#| city: String
#| }
#|
#| output := {
#| @required
#| summary: String
#|
#| celsius: Integer
#|
#| humidity: Integer
#| }
#|}
),
)
.assemble().model.unwrap()
let result = @diff.compare(old_model, new_model)
let keys = result.events.map(event => {
let shape = event.shape.map(id => id.to_string()).unwrap_or("-")
event.id + "|" + event.severity + "|" + shape
})
assert_eq(keys.length(), 2)
assert_eq(
keys[0],
"AddedShape|NOTE|example.weather#GetForecastOutput$humidity",
)
assert_eq(keys[1], "RemovedShape|ERROR|example.weather#GetForecastInput$days")
assert_true(result.is_breaking())
}smithy diff --old old-model.smithy --new new-model.smithy
smithy diff --old old-models/ --new new-models/ --output changes.txt