Module:Schema/Documentation

A schema is a structure for documenting and validating Lua data. Without schemas, it can be difficult for others to know what input a module expects, given Lua's dynamic type system. This is especially true when modules have configuration data or   arguments.

A similar but distinct solution exists for documenting and validating template input.

This module is heavily inspired by JSON Schema. As such, Understanding JSON Schema is a useful resource for understanding how this module works.

Usage
Schemas integrate with Module:Documentation for documenting function parameters, like so:

Schemas can also be made for Module Data like so:

The first invocation generates schema documentation for. The second validates the data against the  schema. Any validation errors that occur will be shown as warnings in the edit preview. Data pages that fail validation are placed in Category:Modules with invalid data.

Examples
Altogether the following modules use every available schema feature:
 * Module:Game Rating
 * Module:Documentation
 * Module:UtilsArg

Module:UtilsSchema has test cases that show how the validation works.

Types
The types defined in schemas generally correspond to the Lua types, with an additional  type. The  type, however, does not exist as a concept in schemas. Instead, there are more specific types which indicate the kind of table in question:


 * — A table with consecutive integer keys starting from 1.
 * — A table with fixed set of string keys.
 * — A table with any amount of keys, all of the same type. All values are of the same type, but possibly a different type from the keys.

Combining Schemas
It is possible to combine schemas using  and.

The combination keywords are often used along with references to maximize reusability.