Page MenuHomePhabricator

Rest: Deprecate BodyValidator
Open, In Progress, MediumPublic

Description

BodyValidator is ill-conceived, we should replace it entirely with the mechanism introduced by T358558, namely overriding getBodyParamSettings and, if needed, parseBodyData.

Rationale

BodyValidator currently conflates several concerns:

  • parsing the request body stream (deserializing)
  • validating the schema of the request body
  • validating parts of the request body semantically
  • constructing a domain specific representation of the request body (validateBody and getValidatedBody return mixed)

The only implementation of BodyValidator is JsonBodyValidator, which implements parsing and incomplete schema validation (see T305973). It always returns an array. Handlers that use JsonBodyValidator implement higher level validation and domain specific logic based on that array.

BodyValidator seems overly generic: callers of validateBody cannot make use of the return valus, unless they know the concrete type of the validator. If they know the concrete type of the validator, they could just as well apply validation diretly.

Proposal

Do address this, we should:

See also the discussion recorded at https://drive.google.com/file/d/1rwM9TqjliJcJwj5XIg22gD8mfqVdHcdH/view

NOTE: Once BodyValidator is gone, getValidatedBody() should be declared to return an array.

Related Objects

StatusSubtypeAssignedTask
In Progresscodebug
In ProgressNone
OpenNone
In Progressdaniel
Resolvedcodebug
Resolveddaniel
Resolveddaniel
In Progressdaniel
ResolvedAtieno
ResolvedAtieno
Resolvedcodebug
Resolvedcodebug
Resolvedcodebug
ResolvedFGoodwin
ResolvedAtieno
In ProgressAtieno
In ProgressAtieno
OpenNone
DuplicateNone

Event Timeline

daniel triaged this task as Medium priority.
daniel moved this task from Incoming (Needs Triage) to In Progress on the MW-Interfaces-Team board.
FJoseph-WMF changed the task status from Open to In Progress.Apr 5 2024, 2:42 PM

Change #1017491 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] REST: Deprecate using "post" as the parameter source

https://gerrit.wikimedia.org/r/1017491

Change #1017491 merged by jenkins-bot:

[mediawiki/core@master] REST: Deprecate using "post" as the parameter source

https://gerrit.wikimedia.org/r/1017491

Change #1025150 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] REST: Fix body validation errors

https://gerrit.wikimedia.org/r/1025150

Change #1025150 merged by jenkins-bot:

[mediawiki/core@master] REST: Fix body validation errors

https://gerrit.wikimedia.org/r/1025150

Change #1028885 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] DNM: REST: Deprecate using "post" as the parameter source

https://gerrit.wikimedia.org/r/1028885

daniel renamed this task from Rest: Replace BodyValidator with JSON schema based validation to Rest: Deprecate BodyValidator .May 23 2024, 7:22 PM
daniel updated the task description. (Show Details)

Change #1028885 merged by jenkins-bot:

[mediawiki/core@master] REST: Deprecate using "post" as the parameter source

https://gerrit.wikimedia.org/r/1028885