Skip to main content

Module validation

Module validation 

Source
Expand description

The validation engine as the server uses it: compiled schemas for route input declarations, text coercion, the error shape, and the nitr.File handle for validated uploads.

Structs§

CompiledSchema
A compiled schema as the server sees it: the handle route input declarations are compiled into.
CustomFormatInfo
What the document says about a script-defined format.
ErrorEntry
One failed rule.
FileInfo
What the spooler learned about an upload.
LuaFile
The nitr.File userdata.
MediaType
One entry of the media-type table.
ValidationError
The verdict when validation fails: the summary, and every failing path with its message and rule.

Enums§

Detection
What the prefix of an upload says about it.
DocSchema
A documentation-only schema, as a route’s doc.responses[n].schema may give it: a compiled schema, a table of fields, or one rule table ({ type = "array", items = Note }). Never enforced; exported like a request schema so the document reads the same on both halves.
TextValue
One text-part value: a string field, or a spooled upload.

Constants§

MEDIA_TYPES
Every type a types list may name.
SNIFF_BYTES
How many bytes detection reads.

Functions§

compile_doc_schema
Compiles a documentation schema: a compiled schema or a table of fields as compile_schema takes them, or a single rule table recognised by its type key.
compile_file_rule
Compiles one file rule for a "raw" body (input.body = { file = … }) as a one-field schema whose field is named file.
compile_schema
Compiles a schema from what a script may hand a route: a field table (rules as tables, shorthand strings or compiled schemas), or a compiled nitr.validate.schema value. what names the site for errors.
compile_text_schema
Like compile_schema, for a part whose values arrive as text (query, params, headers): nested kinds are refused, since a query string has no nesting.
custom_formats
Every custom format registered in this state, sorted by name, for the document’s x-nitr-formats vocabulary.
detect
Sniffs the prefix.
dimensions
Header-only image dimensions, or None when the header does not carry them (or is truncated).
executable_extension
Whether a filename extension marks an executable regardless of bytes.
fmt_size
Byte counts print in the unit a person would pick: 512 B, 2 KB, 1.5 MB, 3 GB.
freeze_messages
Marks the state’s app-wide messages as frozen: the application has compiled, and a nitr.validate.messages call from a handler raises.
is_active_content
Types a browser runs script from when it opens them. A family wildcard (image/*, text/*) never matches one; a rule has to name it, and naming it logs a warning at load.
is_text
Whether the prefix is UTF-8 text without NUL or stray control bytes.
lookup
Looks a media type up by name.
regex_escape
Escapes every regex metacharacter so a literal stays a literal.
rule_codes
Every rule code a messages table may name. Unknown codes fail at load like unknown rule keys do: a typo must not silently override nothing. Every rule code an errors[].rule may carry, for the document’s ValidationError component.
text_subtype_matches
For a text-tier declared type, whether the prefix has the structure the subtype implies ({/[ for JSON, < for XML and HTML, <svg for SVG); plain text subtypes accept anything the sniffer accepted.

Type Aliases§

Components
Named component schemas collected while exporting: a titled schema is emitted once under components/schemas/<title> and referenced everywhere else.
SaveResolver
Resolves a Lua-supplied relative path to the file save may rename the temporary to — the server’s containment rule, injected so this module knows nothing about upload roots.