Skip to content

fix: apply the additionalItems schema to extra tuple items - #924

Open
MaxFreedomPollard wants to merge 1 commit into
fastify:mainfrom
MaxFreedomPollard:fix/tuple-additional-items-schema
Open

MaxFreedomPollard wants to merge 1 commit into
fastify:mainfrom
MaxFreedomPollard:fix/tuple-additional-items-schema

Conversation

@MaxFreedomPollard

Copy link
Copy Markdown
Contributor

When items is an array (tuple validation) and additionalItems is a schema, the items past the tuple were written with JSON.stringify and the schema was never used. Extra items were not coerced (a number stayed a number under { type: 'string' }), formats were not applied, and objects kept the properties their schema does not declare.

Serialize them with buildValue() for the additionalItems location, as is done for items schemas, in both the function and the inlined buildArray paths. additionalItems: true still produces JSON.stringify output, since buildValue() emits that for boolean schemas.

Checklist

When `items` is an array (tuple validation) and `additionalItems` is a
schema, the items past the tuple were written with JSON.stringify and the
schema was never used. Extra items were not coerced (a number stayed a
number under `{ type: 'string' }`), formats were not applied, and objects
kept the properties their schema does not declare.

Serialize them with buildValue() for the additionalItems location, as is
done for `items` schemas, in both the function and the inlined buildArray
paths. `additionalItems: true` still produces JSON.stringify output, since
buildValue() emits that for boolean schemas.
@SameRainbows

Copy link
Copy Markdown

Tested locally on Node 24. All 703 unit tests pass with 100% c8 branch and line coverage, all 15 tstyche type checks pass, and eslint is clean.

Calling buildValue on additionalItemsLocation in both the standalone and inlined array paths ensures items beyond the tuple length respect schema formatting, coercion, and undeclared property pruning, while additionalItems: true continues to fall back to JSON.stringify via buildValue.

This branch has not been deployed

No deployments
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.

2 participants