Skip to content

馃敡 enable ajv strict mode and fix view schema type declaration - #366

Merged
BenoitZugmeyer merged 1 commit into
masterfrom
benoit/ajv-strict-mode
Mar 17, 2026
Merged

馃敡 enable ajv strict mode and fix view schema type declaration#366
BenoitZugmeyer merged 1 commit into
masterfrom
benoit/ajv-strict-mode

Conversation

@BenoitZugmeyer

@BenoitZugmeyer BenoitZugmeyer commented Mar 13, 2026

Copy link
Copy Markdown
Member

Motivation

Previously, ajv was logging strict mode issues to the console but validate.mjs
was not returning a non-zero exit code, so CI would pass silently despite schema
problems. This PR makes the script fail properly when schema issues are detected.

Changes

  • Enable strict: true in Ajv so schema issues throw instead of just logging
  • Add allowUnionTypes: true to allow the union types used intentionally
    across our schemas
  • Wrap ajv.validate() in a try/catch so thrown errors are reported cleanly
    and set a non-zero exit code
  • Add "type": "object" to the view property in view-schema.json, which
    strict mode requires

- Add `strict: true` to Ajv options to surface schema issues earlier
- Add `allowUnionTypes: true` to relax the strict mode rule disallowing union
  types, since the schemas use them intentionally
- Wrap `ajv.validate()` in a try/catch to report schema-level errors (e.g.
  unknown keywords) without crashing, since strict mode can throw instead of
  returning false
- Add `"type": "object"` to the `view` property in view-schema.json, which
  strict mode now requires
@BenoitZugmeyer
BenoitZugmeyer marked this pull request as ready for review March 13, 2026 11:48
@BenoitZugmeyer
BenoitZugmeyer requested review from a team as code owners March 13, 2026 11:48
@BenoitZugmeyer
BenoitZugmeyer merged commit c141e3b into master Mar 17, 2026
15 checks passed
@BenoitZugmeyer
BenoitZugmeyer deleted the benoit/ajv-strict-mode branch March 17, 2026 13:41
BenoitZugmeyer added a commit to DataDog/browser-sdk that referenced this pull request Mar 17, 2026
Running the unit tests is spamming a *lot* of logs, because of ajv
printing warnings about a missing type property.

This was fixed in DataDog/rum-events-format#366.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants