Page MenuHomePhabricator

Fix schema property example validation
Closed, ResolvedPublic3 Estimated Story PointsBUG REPORT

Description

The current version of schema property example validation is too permissive and only reports issues when examples for all schema properties are missing. Assuming examples aren't present in any other locations as described in T423411, the linter should report an issue when at least one property example is missing in the schema.

To fix, change the validation mechanism to be more restrictive (i.e. raise an issue when at least one schema property example is missing) for the following rules:

  • wikimedia-paths-parameter-example-exists
  • wikimedia-paths-parameter-example-only-ref
  • wikimedia-requestbody-example-exists
  • wikimedia-requestbody-example-only-ref
  • wikimedia-response-example-exists
  • wikimedia-response-example-only-ref
  • wikimedia-schema-example-recommended

Other notes:

  • Be sure to adjust linter messages accordingly.
  • Make sure that the top-level example for a schema isn't treated in the same way (that is, when the top-level example isn't present but all properties in the schema have examples, the linter shouldn't raise an issue).
  • This task can likely be completed together with T424002.

To replicate

  1. Start with the OAD example.
  2. Modify the example: under the NewPet component in line 1018, remove one of the two example fields in the properties object.
  3. Lint the modified OAD. Notice that the linting results don't display an issue for the wikimedia-requestbody-example-only-ref rule.
  4. Modify the example: under the same component, remove the other example field so that there are no examples for any properties listed in the NewPet component.
  5. Lint the modified OAD again. Notice that wikimedia-requestbody-example-only-ref now appears on the list of issues and the linter now displays the correct message: "Request body schema uses a $ref without explicit examples. Verify that the referenced schema defines examples." (In fact this happens twice because the OAD references the same component in two places).

Event Timeline

KBach triaged this task as Medium priority.
KBach renamed this task from Fix property example validation to Fix schema property example validation.May 21 2026, 8:16 AM
KBach updated the task description. (Show Details)

Notes for estimation:
The fix requires inverting the logic in schemaExampleUtils.js: findNestedExamples currently passes if any property has an example; it needs to fail if at least one is missing ("all" check instead of "any").

Changes needed:

  • New utility function in schemaExampleUtils.js
  • Update validateExampleExists.js, validateParameterExampleExists.js,validateSchemaExampleRecommended.js to use it (the *-only-ref variants are fixed transitively)
  • Linter messages need rewording in all affected validators
  • At least 4 existing test cases flip from pass to fail (one per test file); new edge case tests needed
HCoplin-WMF set the point value for this task to 3.May 21 2026, 3:17 PM
MGoncalves-WMF changed the task status from Open to In Progress.Jun 2 2026, 2:19 PM

kineticpelagic updated https://gitlab.wikimedia.org/repos/ci-tools/wikimedia-spectral-ruleset/-/merge_requests/11

feat(linter): Improve linting by validating examples in nested schemas (T424002)

HCoplin-WMF changed the task status from Declined to Resolved.Mon, Jun 29, 3:19 PM
HCoplin-WMF subscribed.

Resolving tasks as part of closing the sprint.