Page MenuHomePhabricator

Support operation IDs in MediaWiki REST API OpenAPI descriptions
Closed, ResolvedPublic2 Estimated Story Points

Description

The Wikimedia OpenAPI Linter requires that each operation (unique method and path combination) have an operation ID, so the MediaWiki REST API OpenAPI docs should include operation IDs. These IDs can be generated using the operation summary instead of being manually created. IDs do not need to be translatable.

From the on-wiki docs:

"Operation identifier is a string that uniquely identifies an operation.

  • OpenAPI field: paths.[path].[operation].operationId
  • This field is required for every operation in the OpenAPI description.
  • This field must have a unique value.

When defining the operationId field, follow common programming naming conventions. One way to create this identifier is to convert the operation summary into a single word in camel case, snake case, or similar - for example, "verifyCustomer", "getPetById"."

Example:

...
  "paths": {
    "/v1/linkrecommendations/{project}/{domain}/{page_title}": {
      "get": {
        "description": "Returns a set of possible links that can be added to improve an article on Wikipedia.",
        "operationId": "getLinkRecommendations",
...

Details

Event Timeline

BPirkle triaged this task as Medium priority.May 5 2026, 4:45 PM
HCoplin-WMF set the point value for this task to 2.May 7 2026, 2:28 PM
HCoplin-WMF subscribed.

Notes from estimation:

  • Level of unique needs to be within a rest module; not necessarily across the entire code base.
    • We cannot enforce global uniqueness from the linter, as it is only run against the scope of a given module definition.
  • If operationIds repeat within a given file when working under this structure, that means that we likely have duplicative summaries as well, which is confusing for users.
  • This is at the operation level; this likely means that it will be added to the openApiInfo in the moduleDefinition file. May be as simple as adding a single value to an array (but have to confirm).
  • Allow manual definition, with automatic generation as a fallback.
  • Add testing for both manual definition & auto generation code paths.
  • Summaries are currently i18n'd --> it is indirect to pull the values because of that.

Estimation currently assumes adding a field for a manually entered value exclusively; we will create a follow-up task for auto-generation.

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

[mediawiki/core@master] Rest: Auto-generate operationId in OpenAPI spec output

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

Hi,
I submitted the patch that adds support for operationId in two ways:

  1. Manual definition: operationId is now included in the $oasKeys whitelist in SpecBasedModule::makeRouteInfo(), so it can be explicitly set in module definition files and will be passed through to the generated spec.
  2. Auto-generation: ModuleSpecHandler now automatically generates an operationId for any operation that doesn't have one set manually. The ID is derived from the HTTP method and the operation summary in camelCase (e.g. GET + "Search pages" → getSearchPages). When no summary is available, the route path is used as a fallback. Collisions within a module are resolved by appending a numeric suffix.

I only noticed when I was about to commit that auto-generation was meant to be a separate follow-up task — but since it was already done, two birds, one stone. 😄

Not that it hurts anything, as these strings are technically arbitrary, but this does lead to some slightly odd operationId names, such as:

  • getGetRevisionSource
  • getGetRevisionHtml
  • getGetRevisionInformationWithHtml
  • getGetRevisionLintErrors
  • postCreatePage (which makes sense if you know it's an HTML method, but if you don't it sounds a little like "after a page is created"

(and so on)

Just want to make sure no one is surprised when these show up in specs.

Change #1294353 merged by jenkins-bot:

[mediawiki/core@master] Rest: Auto-generate operationId in OpenAPI spec output

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

Resolving tasks as part of closing the sprint.