Smithy model library for MoonBit
Dependencies
///|
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(_))
}///|
test {
let result = @smithy.Loader::new()
.add_idl(
"one.smithy", "$version: \"2\"\nnamespace example\nstructure One {}",
)
.assemble()
let model = result.model.unwrap()
let ids = @smithy.Selector::parse("structure[id|namespace=example]").select_ids(
model,
)
assert_eq(ids, ["example#One"])
}$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 LoadResult {
model : Model?
diagnostics : Array[ModelDiagnostic]
validation_findings : Array[ValidationEvent]
} derive(Debug)pub(all) struct ModelDiagnostic {
code : String
event_id : String
severity : Severity
message : String
source : SourceLocation
shape : ShapeId?
} derive(Eq, Debug)impl Eq for NodeNumberimpl ToJson for NodeNumberpub(all) struct ScopedAssertion {
left : ScopedValue
operator : String
right : Array[ScopedValue]
insensitive : Bool
} derive(Eq, Debug)pub(all) enum SelectorStep {
ShapeType(String)
AnyShape
Attribute(Array[String], String?, Array[String], Bool)
ScopedAttribute(Array[String], Array[ScopedAssertion])
Neighbor(String, Array[String])
Function(String, Array[Array[SelectorStep]])
VariableStore(String, Array[SelectorStep])
VariableGet(String)
} derive(Eq, Debug)pub(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)pub(all) struct ValidationEvent {
id : String
severity : String
shape : ShapeId?
message : String
source : SourceLocation?
suppression_reason : String?
} derive(Eq, Debug)let SMITHY_VERSION : Stringfn suppression_matches(rule_id : String, event_id : String) -> Bool