Language-neutral JSON-RPC contracts for Smithy code generators
///|
test {
let loaded = @rpc.loader()
.add_idl(
"echo.smithy",
(
#|$version: "2"
#|namespace example
#|use smithy.rpc#jsonRpc
#|use smithy.rpc#method
#|@jsonRpc(versions: ["2.0"])
#|service Echo { version: "1", operations: [EchoValue] }
#|@method(name: "echo", params: "named", kind: "request")
#|operation EchoValue { input: Input, output: Input }
#|structure Input { @required text: String }
),
)
.assemble()
let description = @jsonrpc.Description::for_service(
loaded.model.unwrap(),
@smithy.ShapeId::parse("example#Echo").unwrap(),
@rpc.V2_0,
)
let peer = description.peer(@rpc.PeerName::parse("client").unwrap()).unwrap()
assert_eq(peer.accepts, None)
assert_eq(peer.calls.unwrap().methods[0].name.to_string(), "echo")
assert_eq(peer.calls.unwrap().methods[0].kind, @rpc.RequestOnly)
}pub struct Description {
protocol : ShapeId?
version : ProtocolVersion
peers : Array[PeerDescription]
session : SessionContract?
} derive(Eq, Debug)fn Description::for_protocol(model : Model, protocol : ShapeId, version : ProtocolVersion, config? : Config) -> Description raisefn Description::for_service(model : Model, service : ShapeId, version : ProtocolVersion, config? : Config) -> Description raisepub struct PeerSelection {
name : PeerName
accepts : ServiceDescription?
calls : ServiceDescription?
} derive(Eq, Debug)pub struct PeerSettings {
description : Description
peer : PeerSelection
transports : Array[Transport]
}fn PeerSettings::from_context(ctx : PluginContext, extra? : Array[String]) -> PeerSettings raise CodegenErrorpub struct ServiceDescription {
service : ShapeId
methods : Array[MethodContract]
shapes : Array[ShapeId]
values : Array[StructureContract]
value_config : Config
} derive(Eq, Debug)