Skip to content

fix(schema): allow empty array for required field with minItems#258

Open
spiderocious wants to merge 1 commit into
remoteoss:mainfrom
spiderocious:fix/247-empty-array-required
Open

fix(schema): allow empty array for required field with minItems#258
spiderocious wants to merge 1 commit into
remoteoss:mainfrom
spiderocious:fix/247-empty-array-required

Conversation

@spiderocious
Copy link
Copy Markdown

Fixes a bug where a required array property fails validation when given an
empty array, even though the schema explicitly allows it via minItems: 0.
A required group-array with min: 0 could never be submitted empty.

Changes Made

  • src/validation/schema.ts

    • In the required check, an empty array is no longer automatically treated
      as a missing value when the field schema declares minItems. In that case
      the array counts as present, and its length is validated by minItems
      (which runs separately) rather than by required.
    • Behaviour is unchanged for required arrays that do not declare
      minItems: an empty array is still treated as missing, preserving existing
      behaviour.
  • test/validation/required_field.test.ts

    • Added a test that a required array with minItems: 0 accepts an empty array.
    • Added a test that a required array with minItems: 1 reports a minItems
      error (not a required error) for an empty array, confirming length is
      still enforced by the right mechanism.
    • Added a test that a required array without minItems still treats an empty
      array as missing.

Related Issues/PRs

Fixes #247

Checklist

@spiderocious spiderocious marked this pull request as ready for review May 26, 2026 12:32
@spiderocious
Copy link
Copy Markdown
Author

@sandrina-p @danielcardoso5 please review

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.

group-array with required parent fails for empty array, despite minItems: 0

1 participant