Builtin Library
README.md
validate
Pure validator for asset.create opts — checks a creation opts table against the schema produced by asset.createSchema(typeName). Schema in, validated opts (or a teaching error string) out. Consumed by asset.create, which calls M.validate before forwarding opts to the type's onCreate. No FFI, no VFS.
Errors are teaching errors: they state what was wrong at which path (opts.cfg.size), what was expected, and then render the full creation-parameter contract so the caller can fix the call without reading the type's behavior.luau. Unknown parameter names get an edit-distance "did you mean" suggestion.
Types
ValidatorShape—{ kind, literals?, item?, members?, fields?, indexer? }, the recursive shape encoding.ValidatorParam—{ name, shape?, optional?, default?, desc? }.ValidatorSchema—{ kind, desc?, example?, open?, error?, params?, indexer? }.
Exports
M.validate(schema, opts?) -> (validatedOpts?, err?)— validate and default-fill anoptstable against anasset.createSchemaresult. Returns(validatedOpts, nil)on success (a new table forschema-kind schemas) or(nil, err)whereerris a bare teaching error string. The caller owns presentation. Handles thelegacy,error,none, andschemaschema kinds.M.shapeName(shape) -> string— render a single parameter shape (literal unions as"png" | "jpg", arrays as{ T }, tables astable, primitives as their kind, nil/malformed asany). Used byasset.describe.M.renderContract(schema) -> string— render a schema's creation-parameter contract as one aligned line per parameter, with an[extra keys]line for open schemas.
Usage
local V = require("@builtin::assetTypes.assetType.shared.create.validate")
local out, err = V.validate(schema, { bytes = png })
if err then error("asset.create: " .. err) end