MediaWiki master
MediaWiki\Rest\Validator\Validator Class Reference

Wrapper for ParamValidator. More...

Public Member Functions

 __construct (ObjectFactory $objectFactory, RequestInterface $request, Authority $authority)
 
 validateBody (RequestInterface $request, Handler $handler)
 Validate the body of a request.
 
 validateParams (array $paramSettings)
 Validate parameters.
 

Static Public Member Functions

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 PARAM_DESCRIPTION = 'rest-param-description'
 Parameter description to use in generated documentation.
 
const PARAM_SOURCE = 'rest-param-source'
 (string) ParamValidator constant to specify the source of the parameter.
 

Detailed Description

Wrapper for ParamValidator.

It's intended to be used in the REST API classes by composition.

Since
1.34

Definition at line 32 of file Validator.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Rest\Validator\Validator::__construct ( ObjectFactory  $objectFactory,
RequestInterface  $request,
Authority  $authority 
)
Parameters
ObjectFactory$objectFactory
RequestInterface$request
Authority$authority
Access: internal

Definition at line 101 of file Validator.php.

Member Function Documentation

◆ getParameterSpec()

static MediaWiki\Rest\Validator\Validator::getParameterSpec ( string  $name,
array  $paramSetting 
)
static

Convert a param settings array into an OpenAPI Parameter Object specification structure.

See also
https://swagger.io/specification/#parameter-object
Parameters
string$name
array$paramSetting
Returns
array

Definition at line 226 of file Validator.php.

Referenced by MediaWiki\Rest\Validator\JsonBodyValidator\getOpenAPISpec().

◆ getParameterTypeSchemas()

static MediaWiki\Rest\Validator\Validator::getParameterTypeSchemas ( )
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.

See also
https://swagger.io/specification/#schema-object
self::TYPE_DEFS
Returns
array

Definition at line 213 of file Validator.php.

◆ validateBody()

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().

Parameters
RequestInterface$request
Handler$handlerUsed to call {
See also
Handler::getBodyValidator}
Returns
mixed|null Return value from {
See also
BodyValidator::validateBody}
Exceptions
HttpExceptionon validation failure

Definition at line 153 of file Validator.php.

References MediaWiki\Rest\RequestInterface\getBody(), MediaWiki\Rest\Handler\getBodyValidator(), MediaWiki\Rest\RequestInterface\getHeaderLine(), and MediaWiki\Rest\RequestInterface\getMethod().

Referenced by MediaWiki\Rest\Handler\validate().

◆ validateParams()

MediaWiki\Rest\Validator\Validator::validateParams ( array  $paramSettings)

Validate parameters.

Parameters
array[]$paramSettingsParameter settings
Returns
array Validated parameters
Exceptions
HttpExceptionon validation failure

Definition at line 121 of file Validator.php.

References Wikimedia\ParamValidator\ValidationException\getFailureMessage(), Wikimedia\ParamValidator\ValidationException\getParamName(), Wikimedia\ParamValidator\ValidationException\getParamValue(), and MediaWiki\Rest\Handler\PARAM_SOURCE.

Referenced by MediaWiki\Rest\Handler\validate().

Member Data Documentation

◆ PARAM_DESCRIPTION

const MediaWiki\Rest\Validator\Validator::PARAM_DESCRIPTION = 'rest-param-description'

Parameter description to use in generated documentation.

Definition at line 46 of file Validator.php.

◆ PARAM_SOURCE

const MediaWiki\Rest\Validator\Validator::PARAM_SOURCE = 'rest-param-source'

(string) ParamValidator constant to specify the source of the parameter.

Value must be 'path', 'query', or 'body' ('post' is accepted as an alias for 'body'). '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.

Definition at line 41 of file Validator.php.


The documentation for this class was generated from the following file: