Skip to content

fix: avoid Ajv strict warnings for propertyNames schemas - #897

Merged
Tony133 merged 3 commits into
fastify:mainfrom
Vansh1811:fix/property-names-ajv-strict-warnings-gh-896
Oct 24, 2026
Merged

Tony133 merged 3 commits into
fastify:mainfrom
Vansh1811:fix/property-names-ajv-strict-warnings-gh-896

Conversation

@Vansh1811

Copy link
Copy Markdown
Contributor

Summary

Fixes Ajv strict-mode warnings when propertyNames appears inside nested anyOf/oneOf schemas.

The validator's recursive schema conversion was applying the fjs_type transformation to propertyNames, even though it validates property keys rather than arbitrary object values. This could cause unnecessary Ajv strict-mode warnings.

Changes

  • Skip the propertyNames keyword during recursive schema conversion.
  • Preserve conversion of nested schemas under properties, patternProperties, and definitions.
  • Add regression tests for nested combinators and user-defined fields named propertyNames.

Testing

  • npm run test:unit — 588 tests passed.
  • npm run test:typescript — 15 assertions passed.
  • npm run lint — passed with no errors or warnings.

Closes #896

@Tony133

Tony133 commented Oct 24, 2026

Copy link
Copy Markdown
Member

Thanks for the fix, and for going further than the one-liner in the issue by handling user-defined fields named propertyNames.

I pushed a commit on top that fixes a case the new skip missed: an entry literally named propertyNames inside $defs or dependentSchemas was no longer converted, since those keywords were recursed into as schemas rather than maps of schemas. A Date reaching such an entry through a $ref then failed validation:

const build = require('fast-json-stringify')
const s = build({
  type: 'object',
  $defs: { propertyNames: { type: 'string', format: 'date-time' } },
  properties: { data: { anyOf: [{ $ref: '#/$defs/propertyNames' }, { type: 'null' }] } }
})
s({ data: new Date('2026-01-01T00:00:00Z') })
// before: TypeError: The value of '#/properties/data' does not match schema definition.
// after:  {"data":"2026-01-01T00:00:00.000Z"}

The commit adds a SCHEMA_MAP_KEYWORDS set covering all the map-valued keywords, plus a regression test. CI is green.

Merging, thanks again!

@Tony133
Tony133 merged commit 8ee09fe into fastify:main Oct 24, 2026
17 checks passed
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.

Ajv strict-mode warnings for propertyNames inside anyOf/oneOf (fjs_type added to propertyNames)

2 participants