Files
plainleaf/libraries/Library/Std/APIs/Schema.md
T
Zef Hemel 26d9d5bdf0 Restructure standard library and improve documentation
Refactor Library/Std into subfolders for APIs, Infrastructure, Editor,
Widgets, etc. Add more documentation and descriptions. Update references
throughout website and docs.
2025-10-01 11:22:31 +02:00

77 lines
1.1 KiB
Markdown

#meta/api
Utilities to succinctly define JSON schema types in Lua.
```space-lua
-- priority: 101
schema = schema or {}
function schema.string()
return { type = "string" }
end
function schema.number()
return { type = "number" }
end
function schema.boolean()
return { type = "boolean" }
end
function schema.array(typ)
if type(typ) == "string" then
return {
type = "array",
items = { type = typ }
}
else
return {
type = "array",
items = typ,
}
end
end
function schema.nullable(typ)
if type(typ) == "string" then
return {
anyOf = {
{ type = typ },
{ type = "null" },
}
}
else
return {
anyOf = {
typ,
{ type = "null" },
}
}
end
end
function schema.nullableArray(typ)
if type(typ) == "string" then
return {
anyOf = {
{ type = "array",
items = { type = typ } },
{ type = "null" },
}
}
else
return {
anyOf = {
{ type = "array",
items = typ, },
{ type = "null" },
}
}
end
end
function schema.func()
return {}
end
```