Page MenuHomePhabricator

Improve example quality for MW REST APIs
Open, LowPublic5 Estimated Story Points

Description

Description

Today, the example requests and responses simply reflect the type designations. For example, all integers show as 0, and all strings display "string" as the value. While this is a good starting point, this is insufficient in many cases to prepare users for what is expected or should be provided. For example, timestamps reflect "string" which does not reflect the specific format of the timestamp that needs to be provided or is expected to be returned (eg: "2020-06-20T20:05:55Z"), which frequently results in users guessing and struggling to submit a valid request. Providing users with more representative, real world examples will improve users' ability to discover the correct endpoints and execute requests through the Sandbox.

Conditions of acceptance

For all MediaWiki REST API endpoints:

  • Update the JSON responses to better reflect what is actually expected in the response. (@apaskulin)
  • Update placeholder text in sample request bodies to reflect the format of what is expected in an actual request.
  • Update parameter placeholder text in the "Try it" workflows to reflect helpful examples. (Depends on T420988: Support examples for request parameters in OpenAPI descriptions)
  • (Optional/Open for discussion) In cases where the request or response is a translatable object (for example, the content of a page), make it translatable via the translatewiki workflow.

Implementation Notes
In most cases, there are already detailed examples present in the MediaWiki reference documentation here: https://www.mediawiki.org/wiki/API:REST_API/Reference# . These may be used directly. In cases where examples do not exist or do not match current behavior, consult with Halley for recommendations on new examples.

Event Timeline

OWresch-WMF set the point value for this task to 5.

Is the ability to add examples to an OpenAPI description already available in MediaWiki or does this capability need to be created? This applies to both to request parameter examples and response property examples.

After talking to @BPirkle and doing some local testing, it seems that examples for request bodies and response bodies can be added by adding example fields to the schemas. This is a simple enough process, however it doesn't fulfill the use case of making examples translatable. I'm not sure what the process would be to enable that, but since we can already add examples, I assume we could use the same pattern as we use to translate the description fields.

For path parameters and query parameters (in the "Try it out" workflows), I don't believe there is a system in place to support adding examples. I've opened T420988: Support examples for request parameters in OpenAPI descriptions to track that feature request.

edit: Request bodies don't use schemas so don't currently support examples.

Change #1268628 had a related patch set uploaded (by Alex Paskulin; author: Alex Paskulin):

[mediawiki/core@master] docs: Add examples to REST schemas

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

Change #1268628 merged by jenkins-bot:

[mediawiki/core@master] docs: Add examples to REST schemas

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

I've gone ahead and started adding examples to the response schemas using the approach in this initial patch. My plan is to add the examples in English for now. Then later on we can look at which examples could be translated and make a decision about where and how to do that and how it fits in to the broader translation strategy for the API docs.

apaskulin updated the task description. (Show Details)

Change #1271873 had a related patch set uploaded (by Alex Paskulin; author: Alex Paskulin):

[mediawiki/core@master] api-docs: Add examples to page and revision schemas

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

Change #1275490 had a related patch set uploaded (by Alex Paskulin; author: Alex Paskulin):

[mediawiki/core@master] api-docs: Add examples

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

Change #1271873 merged by jenkins-bot:

[mediawiki/core@master] api-docs: Add examples to page and revision schemas

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

Change #1276753 had a related patch set uploaded (by Alex Paskulin; author: Alex Paskulin):

[mediawiki/core@master] api-docs: Document diff object

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

Change #1275490 merged by jenkins-bot:

[mediawiki/core@master] api-docs: Add examples

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

Change #1276753 merged by jenkins-bot:

[mediawiki/core@master] api-docs: Document diff object

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