balena-io-modules / jellyschema

JellySchema - data validation, UI form generation
Apache License 2.0
4 stars 2 forks source link

Change array items semantics #27

Closed zrzka closed 5 years ago

zrzka commented 5 years ago

Current status

Following DSL ...

properties:
  - foo:
      type: array
      items:
        - schemaA
        - schemaB

... is transformed to a JSON Schema like this one ...

{
  "properties": {
    "foo": {
      "type": "array",
      "items": [
        { schemaA },
        { schemaB }
      ]
    }
  }
}

And it says - array instance is valid if the first item validates against schemaA, second item validates against schemaB, etc.

Change

items shouldn't enforce order of items.

New semantics - an array instance is valid if every single array instance item is valid against ANY schema from items.

Transformation after change

Following DSL ...

properties:
  - foo:
      type: array
      items:
        - schemaA
        - schemaB

... is transformed to a JSON Schema like this one ...

{
  "properties": {
    "foo": {
      "type": "array",
      "items": {
        "anyOf": [
          { schemaA },
          { schemaB }
        ]
      }
    }
  }
}

Example

---
version: 1
title: WiFis
properties:
  - networks:
      type: array
      items:
        - title: WPA2 Personal
          properties:
            - ssid:
                type: string
            - password:
                type: password
        - title: WPA2 Enterprise
          properties:
            - ssid:
                type: string
            - username:
                type: string
            - password:
                type: password

Should generate a form which allows to add multiple WiFi networks where each network can be WPA2 Personal or WPA2 Enterprise.

Rendition notes

We should:

Specification notes

cyplo commented 5 years ago

The spec has been updated