Generate ordinary mttp_core JSON codecs from annotated MoonBit types.
moonx gaato/mttp_schemagen@0.1.0 model_schema.mbt model.mbt
moon check --deny-warn
moonx gaato/mttp_schemagen@0.1.0 --check model_schema.mbt model.mbtrule(
name: "schema",
command: "moonx gaato/mttp_schemagen@0.1.0 $output $input",
)
dev_build(rule: "schema", input: "model.mbt", output: "model_schema.mbt")command: "moon -C /absolute/path/to/mttp_schemagen run src --target wasm -- \"$mod_dir/$output\" \"$mod_dir/$input\""///|
#mttp.schema
struct Note {
/// A title of at most 20 characters.
#mttp.codec(title_codec)
title : String
#mttp.nullable
rating : Int32?
}| Syntax | Codec |
|---|---|
| Int / Int32, Int64, Double, Bool, String, Json | jint, jint64, jdouble, jbool, jstring, jvalue |
| Array[T], Map[String,T] | array, map_of |
| T? | option: absent/null both None; None is omitted in objects |
| #mttp.omittable on T? | omittable: absent is None; null goes to the child codec |
| #mttp.nullable on T? | nullable: key required, null is None, None encodes as null |
| @jsonkit.Presence[T] | presence: absent and null stay distinct |
| Annotated same-package U | u_codec |
///|
#mttp.schema
#mttp.discriminator("kind")
enum Response {
#mttp.tag("note-v1")
Note(Note)
#mttp.unknown
Unknown(Json)
}moon -C mttp_schemagen test --target wasm --deny-warn
moon run scripts/check_schemagen.mbtx
moon run scripts/check_schemagen.mbtx -- --updateInstall
Download zipGenerate ordinary mttp_core JSON codecs from annotated MoonBit types.