Module moonwalk.validator
Type conversion and validation
Functions
failure (reason, status) | Creates an object representing failure. |
Validation functions
check_object (value, info) | Validate a string containing a JSON object or array. |
check_string (value, info) | Validate a string. |
check_number (value, info) | Validate a number. |
Functions
- failure (reason, status)
-
Creates an object representing failure.
a connection instance.
Parameters:
- reason Human-readable reason why the request failed.
- status
Optional HTTP status code and reason, like
400 Bad Request
Returns:
-
An object with a
.fail
method taking one argument,
Validation functions
For each of these functions,value
is a
string passed in by the API consumer containing JSON data. The
info
argument should be a table of parameter or property
validation rules extracted from a doc block or model definition.
- check_object (value, info)
-
Validate a string containing a JSON object or array.
Parameters:
- value String value to check.
- info Validation info.
Returns:
-
A table representing
value
, ornil
on failure. -
A failure object if validation failed, else
nil
.
- check_string (value, info)
-
Validate a string.
Parameters:
- value String value to check.
- info Validation info.
Returns:
-
The
value
, ornil
on failure. -
A failure object if validation failed, else
nil
.
- check_number (value, info)
-
Validate a number.
Parameters:
- value String value to check.
- info Validation info.
Returns:
-
A number representing
value
, ornil
on failure. -
A failure object if validation failed, else
nil
.