Skip to content

chore: add linting for dataValue in example#2945

Open
Daryna-del wants to merge 4 commits into
mainfrom
chore/lint-dataValue-examples
Open

chore: add linting for dataValue in example#2945
Daryna-del wants to merge 4 commits into
mainfrom
chore/lint-dataValue-examples

Conversation

@Daryna-del

@Daryna-del Daryna-del commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What/Why/How?

OpenAPI 3.2 introduced dataValue as the schema-checked example field, but the linter never validated it, so invalid dataValue examples passed silently. This adds linting for dataValue against its schema, matching how value is linted.

Reference

Comment in the issue #919

Testing

Tests passed successfully on monorepo.

Screenshots (optional)

Check yourself

  • This PR follows the contributing guide
  • All new/updated code is covered by tests
  • Core code changed? - Tested with other Redocly products (internal contributions only)
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update has been considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

Note

Low Risk
Targeted extension of existing example validation with backward-compatible value handling; no auth, runtime API, or data-path changes.

Overview
OpenAPI 3.2 Example objects can put schema-checked payloads in dataValue, but no-invalid-parameter-examples and no-invalid-media-type-examples only validated value, so bad dataValue examples could pass lint.

This PR adds getExampleValueToValidate in rule utils: prefer dataValue when set, otherwise value, and skip when neither is present. Both rules run the same AJV validateExample flow on the chosen field. no-invalid-media-type-examples also adjusts example $ref resolution and error locations so diagnostics point at dataValue (or value) under the resolved example.

Docs for both rules document dataValue behavior; tests cover invalid/valid cases, **$ref**d examples, binary dataValue, serializedValue ignored for schema checks, and legacy value on 3.2. @redocly/openapi-core gets a minor changeset entry.

Reviewed by Cursor Bugbot for commit 4398fb7. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4398fb7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/openapi-core Minor
@redocly/cli Minor
@redocly/respect-core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Daryna-del Daryna-del self-assigned this Jul 10, 2026
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 69.48% (🎯 69%) 7648 / 11006
🔵 Statements 69.22% (🎯 69%) 7964 / 11505
🔵 Functions 73.87% (🎯 73%) 1538 / 2082
🔵 Branches 61.27% (🎯 61%) 5163 / 8426
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/rules/utils.ts 92.68% 89.7% 100% 91.78% 67, 101, 111-115, 131, 142-146, 248
packages/core/src/rules/common/no-invalid-parameter-examples.ts 100% 100% 100% 100%
packages/core/src/rules/oas3/no-invalid-media-type-examples.ts 96.29% 91.66% 100% 100% 41
Generated in workflow #10684 for commit 4398fb7 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark (Lower is Faster)

CLI Version Bundle Lint Check Config
cli-latest ▓ 1.00x ± 0.01 ▓ 1.00x (Fastest) ▓ 1.00x (Fastest)
cli-next ▓ 1.00x (Fastest) ▓ 1.01x ± 0.01 ▓ 1.01x ± 0.01

@Daryna-del Daryna-del added the snapshot Create experimental release PR label Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1783680915 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1783680915

⚠️ Note: This is a development build and may contain unstable features.

@Daryna-del Daryna-del marked this pull request as ready for review July 10, 2026 15:18
@Daryna-del Daryna-del requested review from a team as code owners July 10, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snapshot Create experimental release PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants