MediaWiki master
MediaWiki\Api\ApiRestHelper Class Reference

Helper for action API modules that support the REST paradigm. More...

Inherited by MediaWiki\Api\ApiListRestHelper.

Public Member Functions

 __construct (protected readonly ApiRestHelperContext $context, protected readonly ?string $responseBodySchemaFileName=null,)
 getResponseBodySchema ()
 Returns an OpenAPI Schema Object specification structure as an associative array.
 getResponseBodySchemaFileName ()
 Returns the absolute path of a JSON file containing an OpenAPI Schema Object specification structure describing the response body.
 getStatusForErrorMessage (IApiMessage $msg)
 Returns the HTTP status code that should be returned to the client along with the given message.

Detailed Description

Helper for action API modules that support the REST paradigm.

This is used as glue by the ActionModuleBasedHandler in the REST framework to help with translating an action API result to a REST response.

Stability: unstable
since 1.47, will become stable to extend

Definition at line 15 of file ApiRestHelper.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Api\ApiRestHelper::__construct ( protected readonly ApiRestHelperContext $context,
protected readonly ?string $responseBodySchemaFileName = null )
Parameters
ApiRestHelperContext$contextprovides information about the REST route definition. Typically passed through from ApiRestHybrid::initRestMode().
?string$responseBodySchemaFileNameFile path of a response body schema. May be null if getResponseBodySchemaFileName() or getResponseBodySchema() are overridden.
Stability: stable
to call

Definition at line 26 of file ApiRestHelper.php.

Member Function Documentation

◆ getResponseBodySchema()

MediaWiki\Api\ApiRestHelper::getResponseBodySchema ( )

Returns an OpenAPI Schema Object specification structure as an associative array.

Note
This method does not take a $method parameter like its pendant in Handler, because action API modules don't vary behavior on method. REST Handlers can (though probably shouldn't either).
See also
\MediaWiki\Rest\Handler::getResponseBodySchema() for details.
Stability: stable
to override
Returns
array

Reimplemented in MediaWiki\Api\ApiListRestHelper.

Definition at line 57 of file ApiRestHelper.php.

References getResponseBodySchemaFileName().

◆ getResponseBodySchemaFileName()

MediaWiki\Api\ApiRestHelper::getResponseBodySchemaFileName ( )

Returns the absolute path of a JSON file containing an OpenAPI Schema Object specification structure describing the response body.

See also
\MediaWiki\Rest\Handler::getResponseBodySchema() for details.
Stability: stable
to override
Returns
string

Definition at line 70 of file ApiRestHelper.php.

References if.

Referenced by getResponseBodySchema().

◆ getStatusForErrorMessage()

MediaWiki\Api\ApiRestHelper::getStatusForErrorMessage ( IApiMessage $msg)

Returns the HTTP status code that should be returned to the client along with the given message.

If 0 is returned, it is left to ActionModuleBasedHandler to determine the status code. This will generally result in status 400 being returned, except for some well known kinds of errors such as 'badtoken' (401) or 'ratelimited' (429).

Stability: stable
to override

Definition at line 41 of file ApiRestHelper.php.

References return.


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