What is the purpose of "additionalItems" property on arrays in rjsf?

Viewed 94

I'm studying rjsf documentation and I'm confused about the additionalItems section of array docs.

Here is the example code from the docs:

const Form = JSONSchemaForm.default;

const schema = {
  type: "array",
  items: {
    type: "string"
  },
  additionalItems: {
    type: "boolean"
  }
};

ReactDOM.render((
  <Form schema={schema} />
), document.getElementById("app"));

and here is the official codepen

The rendered form seems to behave exactly the same if I remove the additionalItems, so what is the purpose? I guess it has one, since it's explicitly brought up in the docs, but I can't figure it out :)

1 Answers

additionalItems: <schema> is used to indicate how items are treated beyond the enumerated items you specify in the schema, or even if they are allowed at all.

In this schema, the first array item must be a string, the second must be a number, but any additional items beyond that are allowed and can be anything:

{
  "type": "array",
  "items": [
    { "type": "string" },
    { "type": "number" }
  ]
}

In this schema, the first item must be a string, the second must be a number, and all items after that must be booleans:

{
  "type": "array",
  "items": [
    { "type": "string" },
    { "type": "number" }
  ],
  "additionalItems": { "type": "boolean" }
}

And in this schema, there are no more items permitted at all after the first two:

{
  "type": "array",
  "items": [
    { "type": "string" },
    { "type": "number" }
  ],
  "additionalItems": false
}

You can read more about this keyword in the documentation: https://json-schema.org/understanding-json-schema/reference/array.html

Related