21 private $bodyParamSettings;
29 __CLASS__ .
' is deprecated.',
32 $this->bodyParamSettings = $bodyParamSettings;
40 $jsonStream = $request->
getBody();
41 $status = FormatJson::parse(
"$jsonStream", FormatJson::FORCE_ASSOC );
43 if ( !$status->isOK() ) {
45 new MessageValue(
'rest-json-body-parse-error', [
"$status" ] ),
50 $data = $status->value;
52 if ( !is_array( $data ) ) {
56 $uncheckedBodyKeys = array_fill_keys( array_keys( $data ),
true );
57 foreach ( $this->bodyParamSettings as $name => $settings ) {
58 if ( !empty( $settings[ParamValidator::PARAM_REQUIRED] ) && !isset( $data[$name] ) ) {
60 new MessageValue(
'rest-missing-body-field', [ $name ] ), 400
64 if ( !isset( $data[$name] ) ) {
65 $data[$name] = $settings[ParamValidator::PARAM_DEFAULT] ??
null;
68 unset( $uncheckedBodyKeys[$name] );
71 if ( $uncheckedBodyKeys ) {
74 'rest-extraneous-body-fields',
75 [
new ListParam( ListType::COMMA, array_keys( $uncheckedBodyKeys ) ) ]
100 foreach ( $this->bodyParamSettings as $name => $paramSetting ) {
106 $body[
'properties'][$name] = $param[
'schema'];
108 if ( isset( $param[
'description'] ) ) {
109 $body[
'properties'][$name][
'description'] = $param[
'description'];
112 if ( $param[
'required'] ??
false ) {
113 $required[] = $param[
'name'];
118 $body[
'required'] = $required;
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
__construct(array $bodyParamSettings)
validateBody(RequestInterface $request)
Validate the body of a request.This may return a data structure representing the parsed body....
getOpenAPISpec()
Returns an OpenAPI Schema Object specification structure as an associative array.
Interface for validating a request body.