MediaWiki master
|
Wrapper for ParamValidator. More...
Public Member Functions | |
__construct (ObjectFactory $objectFactory, RequestInterface $request, Authority $authority) | |
detectExtraneousBodyFields (array $paramSettings, array $parsedBody) | |
Throw an HttpException if there are unexpected body fields. | |
validateBody (RequestInterface $request, Handler $handler) | |
Validate the body of a request. | |
validateBodyParams (array $paramSettings, bool $enforceTypes=true) | |
Validate body fields. | |
validateParams (array $paramSettings) | |
Validate parameters. | |
Static Public Member Functions | |
static | getParameterSchema (array $paramSetting) |
Convert a param settings array into an OpenAPI schema structure. | |
static | getParameterSpec (string $name, array $paramSetting) |
Convert a param settings array into an OpenAPI Parameter Object specification structure. | |
static | getParameterTypeSchemas () |
Returns JSON Schema description of all known parameter types. | |
Public Attributes | |
const | KNOWN_PARAM_SOURCES = [ 'path', 'query', 'body', 'post' ] |
(array) ParamValidator array to specify the known sources of the parameter. | |
const | PARAM_DESCRIPTION = 'rest-param-description' |
Parameter description to use in generated documentation. | |
const | PARAM_SOURCE = 'rest-param-source' |
(string) ParamValidator constant for use as a key in a param settings array to specify the source of the parameter. | |
Wrapper for ParamValidator.
It's intended to be used in the REST API classes by composition.
Definition at line 37 of file Validator.php.
MediaWiki\Rest\Validator\Validator::__construct | ( | ObjectFactory | $objectFactory, |
RequestInterface | $request, | ||
Authority | $authority ) |
ObjectFactory | $objectFactory | |
RequestInterface | $request | |
Authority | $authority |
Definition at line 117 of file Validator.php.
MediaWiki\Rest\Validator\Validator::detectExtraneousBodyFields | ( | array | $paramSettings, |
array | $parsedBody ) |
Throw an HttpException if there are unexpected body fields.
Note that this will ignore all body fields if $paramSettings does not declare any body parameters, to avoid failures when clients send spurious data to handlers that do not support body validation at all. This behavior may change in the future.
array | $paramSettings | |
array | $parsedBody |
LocalizedHttpException | if there are unexpected body fields. |
Definition at line 180 of file Validator.php.
References $source, and MediaWiki\Rest\Handler\PARAM_SOURCE.
Referenced by MediaWiki\Rest\Handler\detectExtraneousBodyFields().
|
static |
Convert a param settings array into an OpenAPI schema structure.
array | $paramSetting |
Definition at line 390 of file Validator.php.
|
static |
Convert a param settings array into an OpenAPI Parameter Object specification structure.
string | $name | |
array | $paramSetting |
Definition at line 362 of file Validator.php.
Referenced by MediaWiki\Rest\Validator\JsonBodyValidator\getOpenAPISpec().
|
static |
Returns JSON Schema description of all known parameter types.
The name of the schema is the name of the parameter type with "-param" appended.
Definition at line 349 of file Validator.php.
MediaWiki\Rest\Validator\Validator::validateBody | ( | RequestInterface | $request, |
Handler | $handler ) |
Validate the body of a request.
This may return a data structure representing the parsed body. When used in the context of Handler::validateParams(), the returned value will be available to the handler via Handler::getValidatedBody().
RequestInterface | $request | |
Handler | $handler | Used to call { |
HttpException | on validation failure |
Definition at line 286 of file Validator.php.
References MediaWiki\Rest\RequestInterface\getBody(), MediaWiki\Rest\Handler\getBodyValidator(), MediaWiki\Rest\RequestInterface\getHeaderLine(), MediaWiki\Rest\RequestInterface\getMethod(), and wfDeprecated().
Referenced by MediaWiki\Rest\Handler\validate().
MediaWiki\Rest\Validator\Validator::validateBodyParams | ( | array | $paramSettings, |
bool | $enforceTypes = true ) |
Validate body fields.
Only params with the source specified as 'body' will be processed, use validateParams() for parameters coming from the path, from query, etc.
array[] | $paramSettings | Parameter settings. |
bool | $enforceTypes | $enforceTypes Whether the types of primitive values should be enforced. If set to false, parameters values are allowed to be strings. |
HttpException | on validation failure |
Definition at line 234 of file Validator.php.
References $source, Wikimedia\ParamValidator\ValidationException\getFailureMessage(), Wikimedia\ParamValidator\ValidationException\getParamName(), Wikimedia\ParamValidator\ValidationException\getParamValue(), Wikimedia\ParamValidator\TypeDef\OPT_ENFORCE_JSON_TYPES, and MediaWiki\Rest\Handler\PARAM_SOURCE.
Referenced by MediaWiki\Rest\Handler\validate().
MediaWiki\Rest\Validator\Validator::validateParams | ( | array | $paramSettings | ) |
Validate parameters.
Params with the source specified as 'body' will be ignored. Use validateBodyParams() for these.
array[] | $paramSettings | Parameter settings |
HttpException | on validation failure |
Definition at line 141 of file Validator.php.
References $source, Wikimedia\ParamValidator\ValidationException\getFailureMessage(), Wikimedia\ParamValidator\ValidationException\getParamName(), Wikimedia\ParamValidator\ValidationException\getParamValue(), and MediaWiki\Rest\Handler\PARAM_SOURCE.
Referenced by MediaWiki\Rest\Handler\validate().
const MediaWiki\Rest\Validator\Validator::KNOWN_PARAM_SOURCES = [ 'path', 'query', 'body', 'post' ] |
(array) ParamValidator array to specify the known sources of the parameter.
'post' refers to application/x-www-form-urlencoded or multipart/form-data encoded parameters in the body of a POST request (in other words, parameters in PHP's $_POST). For other kinds of POST parameters, such as JSON fields, use BodyValidator instead of ParamValidator. This list must correspond to the switch statement in ParamValidatorCallbacks::getParamsFromSource.
Definition at line 48 of file Validator.php.
const MediaWiki\Rest\Validator\Validator::PARAM_DESCRIPTION = 'rest-param-description' |
Parameter description to use in generated documentation.
Definition at line 60 of file Validator.php.
const MediaWiki\Rest\Validator\Validator::PARAM_SOURCE = 'rest-param-source' |
(string) ParamValidator constant for use as a key in a param settings array to specify the source of the parameter.
Value must be one of the values in KNOWN_PARAM_SOURCES.
Definition at line 55 of file Validator.php.