Skip to content

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

Description

@mariada-ta

Description:
I’m using remotess json-schema-form in my vue project. The schema I created has a parent array property ("inputType": "group-array") which is required, but the array itself can be empty (minItems: 0).

Look here:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "sources": {
      "title": "Sources",
      "type": "array",
      "x-jsf-presentation": {
        "inputType": "group-array",
        "min": 0,
        "max": 61
      },
      "items": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer",
            "title": "index",
            "minimum": 1,
            "maximum": 62,
            "x-jsf-presentation": {
              "inputType": "number",
              "min": 1,
              "max": 62
            }
          },
          "device": {
            "type": "integer",
            "title": "Device",
            "minimum": 1,
            "maximum": 62,
            "x-jsf-presentation": {
              "inputType": "number",
              "default": 1,
              "min": 1,
              "max": 62
            }
          }
        },
        "required": [
          "device",
          "index"
        ],
        "additionalProperties": false
      },
      "minItems": 0,
      "maxItems": 61,
      "uniqueItems": true
    }
  },
  "required": [
    "sources"
  ],
  "additionalProperties": false
}

Problem:
When I validate the following json: {"sources":[]} it always says {"sources":"Required field"} and the problem is only gone, when I remove the "required": [
"sources"
]

I added a small vue example showing my issue, I would appreciate every bit of help.

bug_empty_required_json.zip

Activity

  1. added theissue type on Jan 16, 2026
  2. sandrina-p commented on Jan 16, 2026

    @sandrina-p
    Collaborator

    Hi @mariada-ta! That's indeed a bug. We currently don't have bandwidth to fix but, could you give it a try? It's somewhere in the validateSchema function

  3. mariada-ta commented on Jan 22, 2026

    @mariada-ta
    Author

    I looked into the problem and would have fixed it like this:
    File: src/validation/schema.ts
    Line: 241 - 263

     if (schema.required && isObjectValue(value)) {
        const missingKeys = schema.required.filter((key: string) => {
          const fieldValue = value[key]
          const fieldSchema = schema.properties?.[key]
          // Field is considered missing if:
          // - it's undefined OR
          // - it's null AND treatNullAsUndefined option is true
          // - it's an array/object and it's empty
          if (Array.isArray(fieldValue)) {
            if (fieldSchema && getSchemaType(fieldSchema) === 'array') {
              const minItems = (fieldSchema as any).minItems ?? 0
              return fieldValue.length < minItems
            }
            return fieldValue.length === 0
          }
    
          if (isObjectValue(fieldValue)) {
            return Object.keys(fieldValue).length === 0
          }
    
          return fieldValue === undefined || (fieldValue === null && options.treatNullAsUndefined)
        })
    

    I added a check that looks to see if there is a minItems attribute in the property and, if so, whether the element meets the length requirement. This means that an empty array with minItems: 0 is now correct.

  4. spiderocious commented on May 26, 2026

    @spiderocious

    Hi
    I'd like to take a crack at this one. I see @mariada-ta proposed a fix back in January but there's no PR open yet. @mariada-ta are you still working on it? If not, I'll pick it up. My plan is to fix the required check in validateSchema so an empty array no longer counts as a missing field (array length should be governed by minItems/maxItems, not required), and add tests covering the group-array + minItems: 0 case from the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions