Page MenuHomePhabricator

Support requestBody content examples in MediaWiki REST Framework OAD generation
Closed, ResolvedPublic2 Estimated Story Points

Description

The Wikimedia OpenAPI linter requires at least one example or examples field under each media type in a requestBody (wikimedia-requestbody-example-exists rule, severity: warn). The framework never generates these fields and provides no mechanism to set them.

Context

Handler::getRequestSpec() only generates schema under each media type in the request body content. There is no hook for example or examples:

'content' => [
    'application/json' => [
        'schema' => [ ... ]
        // ← no 'example' or 'examples'
    ]
]

For path/query *parameters*, PARAM_EXAMPLE was added in T420988. The same pattern is needed for request body content.

32 warnings across all REST modules.

Conditions of acceptance

  • Add a way to supply one or more examples for the request body — for example a getRequestBodyExamples() method on the Handler base class (returning null by default, overridable by subclasses).
  • When non-null, include the result as example or examples under each media type in the requestBody.content object generated by getRequestSpec().
  • Add a unit test verifying examples appear in the generated spec when provided.

Related tasks

  • T425942 (spike that identified this gap)
  • T420988 (added PARAM_EXAMPLE for parameters — same pattern to follow)

Event Timeline

KBach triaged this task as High priority.May 27 2026, 11:49 AM
KBach lowered the priority of this task from High to Medium.

Since this task follows the pattern of T420988: Support examples for request parameters in OpenAPI descriptions, you may want to check whether a similar allowance to https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1301299 (Change-Id: I26318f) will be necessary to prevent problems in this task. It is possible that the allowance is not applicable to this task, but I will let you confirm.

Change #1304621 had a related patch set uploaded (by Aghirelli; author: Aghirelli):

[mediawiki/core@master] Rest: Add getRequestBodyExample() to Handler base class

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

aaron changed the task status from Open to In Progress.Tue, Jun 30, 3:41 PM

Change #1304621 merged by jenkins-bot:

[mediawiki/core@master] Rest: Add getRequestBodyExample() to Handler base class

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