///|
struct UserInput {
name : String
age : Int?
} derive(@json.FromJson, ToJson)
///|
impl @schema.JsonSchema for UserInput with fn json_schema() {
@schema.Schema::object(
properties={
"name": @schema.Schema::string(min_length=1),
"age": @schema.Schema::integer(minimum=0),
},
required=["name"],
)
}// Validate & decode JSON into typed struct in one step
let input : UserInput = try! @schema.decode(json)
// Direct instance validation
let schema = @schema.Schema::string(min_length=3)
try! schema.validate(Json::string("hello"))impl JsonSchema for Boolimpl JsonSchema for Intimpl JsonSchema for Int64impl JsonSchema for Doubleimpl JsonSchema for Stringimpl JsonSchema for Option[T]impl JsonSchema for Array[T]impl JsonSchema for Jsonimpl Show for SchemaErrorimpl Show for ValidationIssuesimpl ToJson for ValidationIssuespub struct Schema {
// private fields
}fn Schema::array(items? : Schema, min_items? : Int, max_items? : Int, unique_items? : Bool, description? : String) -> Schema raise SchemaErrorfn[T : ToJson] Schema::enumeration(values : Array[T], description? : String) -> Schema raise SchemaErrorfn Schema::integer(minimum? : Int, maximum? : Int, description? : String) -> Schema raise SchemaErrorfn Schema::number(minimum? : Double, maximum? : Double, exclusive_minimum? : Double, exclusive_maximum? : Double, multiple_of? : Double, description? : String) -> Schema raise SchemaErrorfn Schema::string(min_length? : Int, max_length? : Int, description? : String) -> Schema raise SchemaErrorfn Schema::validate(self : Schema, instance : Json, max_depth? : Int) -> Unit raise ValidationIssuesimpl Show for ValidationIssueimpl ToJson for ValidationIssuelet DRAFT_2020_12 : StringInstall
Download zipA library for building Model Context Protocol servers and clients.