Skip to content

fix(core): support tuple validation when schema items is an array (JSON Schema draft 07)#34636

Open
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-schema-validation-items
Open

fix(core): support tuple validation when schema items is an array (JSON Schema draft 07)#34636
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-schema-validation-items

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

validateProperty in params.ts did not handle the case where items is an array — the JSON Schema draft 07 tuple validation form. This caused false validation failures for schemas like Angular's @angular/build:unit-test, which uses tuple items to type reporter configurations:

{
  "type": "array",
  "minItems": 1,
  "maxItems": 2,
  "items": [
    { "anyOf": [{ "type": "string" }, { "enum": ["junit", "html", ...] }] },
    { "type": "object" }
  ]
}

Options like "reporters": [["junit", {"suiteName": "MyApp"}]] would incorrectly fail validation with "Property 'reporters' does not match the schema".

Changes

  • validateProperty: when schema.items is an array, validates each element against its positional schema instead of passing the whole array as a schema
  • minItems/maxItems enforcement: array length is now validated against minItems and maxItems constraints when present
  • additionalItems support: rejects extra items when additionalItems: false; validates against the additionalItems schema when present; otherwise allows additional items (spec-compliant default)
  • PropertyDescription type: added minItems, maxItems, additionalItems fields; narrowed items from any to PropertyDescription | PropertyDescription[]
  • Type guards: added guards in coerceType and getPromptsForSchema where items.enum was accessed without accounting for the array form
Original prompt

This section details on the original issue you should resolve

<issue_title>Schema validation fails when items is a list.</issue_title>
<issue_description>### Current Behavior

In JSON Schema draft 07 (2018), the "items" property can be a list and must be validated using tuple validation.

The validateProperty util in packages/nx/src/utils/params.ts currently does not support this, causing validation to fail with the error that the property does not match the schema (but it does).

Expected Behavior

A schema using JSON Schema draft 07 like https://github.com/angular/angular-cli/blob/15794dc101fffd49818545c4ab015a3bf238b14a/packages/angular/build/src/builders/unit-test/schema.json must be successfully parsed by the NX parser.

OR

The parser must give a clear error message that it does not support the given schema.

GitHub Repo

https://github.com/Ionaru/schema7fail

Steps to Reproduce

In https://github.com/Ionaru/schema7fail:

  1. Run npm install
  2. Run nx test my-app

Clean repro:

  1. Create an NX project with an Angular application
  2. In project.json add:
    "test": {
      "executor": "@angular/build:unit-test",
      "options": {
        "reporters": [["junit", {"suiteName": "MyApp"}]]
      }
    }
  1. Run nx test <app_name>

Nx Report

Node           : 24.14.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 11.11.0

nx                     : 22.3.3
@nx/js                 : 22.3.3
@nx/eslint             : 22.3.3
@nx/workspace          : 22.3.3
@nx/angular            : 22.3.3
@nx/devkit             : 22.3.3
@nx/eslint-plugin      : 22.3.3
@nx/module-federation  : 22.3.3
@nx/playwright         : 22.3.3
@nx/plugin             : 22.3.3
@nx/rspack             : 22.3.3
@nx/vite               : 22.3.3
@nx/vitest             : 22.3.3
@nx/web                : 22.3.3
@nx/webpack            : 22.3.3
typescript             : 5.9.3

Failure Logs

NX   Property 'reporters' does not match the schema.
{
  "oneOf": [
    {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "enum": [
            "default",
            "verbose",
            "dots",
            "json",
            "junit",
            "tap",
            "tap-flat",
            "html"
          ]
        }
      ]
    },
    {
      "type": "array",
      "minItems": 1,
      "maxItems": 2,
      "items": [
        {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "enum": [
                "default",
                "verbose",
                "dots",
                "json",
                "junit",
                "tap",
                "tap-flat",
                "html"
              ]
            }
          ]
        },
        {
          "type": "object"
        }
      ]
    }
  ]
}'

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Linked to angular/angular-cli#32618</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@netlify
Copy link

netlify bot commented Feb 27, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 41caeeb
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69a1fc1c11c1a90008c95081
😎 Deploy Preview https://deploy-preview-34636--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Feb 27, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 41caeeb
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69a1fc1ce2e3f800086e640c
😎 Deploy Preview https://deploy-preview-34636--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix schema validation failure for items list fix(core): support tuple validation when schema items is an array (JSON Schema draft 07) Feb 27, 2026
@nx-cloud
Copy link
Contributor

nx-cloud bot commented Feb 27, 2026

View your CI Pipeline Execution ↗ for commit 41caeeb

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 1h 16s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 31s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-27 21:23:23 UTC

@AgentEnder AgentEnder marked this pull request as ready for review February 27, 2026 12:34
@AgentEnder AgentEnder requested a review from a team as a code owner February 27, 2026 12:34
@AgentEnder AgentEnder requested a review from MaxKless February 27, 2026 12:34
@Ionaru
Copy link

Ionaru commented Feb 27, 2026

I would like to see tests that check these values:

  • a: ['junit']: exactly minItems, should pass
  • a: []: below minItems, should throw
  • a: ['junit', { suiteName: 'MyApp' }, 'html']: above maxItems, should throw

@AgentEnder
Copy link
Member

I would like to see tests that check these values:

  • a: ['junit']: exactly minItems, should pass
  • a: []: below minItems, should throw
  • a: ['junit', { suiteName: 'MyApp' }, 'html']: above maxItems, should throw

@copilot

Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 27, 2026

I would like to see tests that check these values:

  • a: ['junit']: exactly minItems, should pass...

Added all three test cases in 890177f, along with the actual minItems/maxItems enforcement in validateProperty (previously they were only defined in the type but not checked):

  • a: ['junit'] — exactly minItems, passes ✓
  • a: [] — below minItems, throws ✓
  • a: ['junit', { suiteName: 'MyApp' }, 'html'] — above maxItems, throws ✓

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • staging.nx.app
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node ./bin/post-install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

nx-cloud[bot]

This comment was marked as outdated.

Co-authored-by: Copilot <Copilot@users.noreply.github.com>
Copy link
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud has identified a possible root cause for your failed CI:

Our e2e-web test encountered an infrastructure failure where the local npm registry at http://localhost:4873 is missing the @swc/jest package, causing a pnpm install failure. This is unrelated to the schema validation changes in this PR, which only modify params.ts validation logic. The test environment's registry needs to be restored before this e2e test can pass.

No code changes were suggested for this issue.

🔂 A CI rerun has been triggered by adding an empty commit to this branch.

Nx Cloud View detailed reasoning on Nx Cloud ↗

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.


🎓 Learn more about Self-Healing CI on nx.dev

Co-authored-by: Copilot <Copilot@users.noreply.github.com> [Self-Healing CI Rerun]
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.

Schema validation fails when items is a list.

3 participants