Smithy model library for MoonBit
///|
test {
let result = @smithy.Loader::new()
.add_idl(
"city.smithy",
(
#|$version: "2"
#|namespace example.weather
#|structure City {
#| @required
#| name: String
#|}
),
)
.assemble()
assert_true(!result.has_errors())
let model = result.model.unwrap()
let name = model.get("example.weather#City$name").unwrap()
guard name.body is Member(target~) else { fail("expected a member") }
assert_eq(target.to_string(), "smithy.api#String")
assert_true(name.trait_value("smithy.api#required") is Some(_))
}$version: "2"
namespace example.logs
use smithy.contracts#conditions
@conditions({
StartBeforeEnd: {
expression: "start < end"
documentation: "The start time must be strictly less than the end time."
}
})
structure FetchLogsInput {
@required
start: Timestamp
@required
end: Timestamp
}///|
test {
let result = @smithy.Loader::new()
.add_json(
"name.json", "{\"smithy\":\"2\",\"shapes\":{\"example.weather#Name\":{\"type\":\"string\"}}}",
)
.assemble()
let document = result.model.unwrap().to_json_ast()
assert_eq(document.smithy, "2.0")
assert_eq(document.shapes.unwrap().length(), 1)
}///|
test {
let model = @smithy.Loader::new()
.add_idl("name.smithy", "$version: \"2\"\nnamespace example\nstring Name")
.assemble().model.unwrap()
let files = model.to_idl()
let again = @smithy.Loader::new()
for ns, text in files {
again.add_idl(ns + ".smithy", text) |> ignore
}
assert_true(!again.assemble().has_errors())
}pub(all) struct ModelDiagnostic {
code : String
severity : Severity
message : String
source : SourceLocation
shape : ShapeId?
} derive(Eq, Debug)impl Eq for NodeNumberimpl ToJson for NodeNumberpub(all) enum ShapeBody {
Simple(SimpleType)
List(ShapeId)
Map(key~ : ShapeId, value~ : ShapeId)
Structure(Array[ShapeId])
Union(Array[ShapeId])
Enum(Array[ShapeId])
IntEnum(Array[ShapeId])
Member(target~ : ShapeId)
Operation(input~ : ShapeId, output~ : ShapeId, errors~ : Array[ShapeId])
Service(version~ : String, operations~ : Array[ShapeId], resources~ : Array[ShapeId], errors~ : Array[ShapeId], rename~ : Map[ShapeId, String])
Resource(identifiers~ : Map[String, ShapeId], properties~ : Map[String, ShapeId], create~ : ShapeId?, put~ : ShapeId?, read~ : ShapeId?, update~ : ShapeId?, delete~ : ShapeId?, list~ : ShapeId?, operations~ : Array[ShapeId], collectionOperations~ : Array[ShapeId], resources~ : Array[ShapeId])
} derive(Eq, Debug)let SMITHY_VERSION : String