codecombat/treema

Support "autoPopulate" in addition to "default" and "required"

Opened this issue · 0 comments

For objects, it will be really handy to have an autoPopulate array so that one could do schemas like this:

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string",
        "default": "My Project"
      },
      "description": {
        "type": "string",
        "default": "A project I worked on.",
      },
      "picture": {
        "type": "string",
        "format": "image-file",
      },
      "link": {
        "type": "string",
        "default": "http://example.com"
      }
    },
    "required": [
      "name",
      "description",
      "picture"
    ],
    "autoPopulate": ['link']
  }
}

instead of like this:

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string",
        "default": "My Project"
      },
      "description": {
        "type": "string",
        "default": "A project I worked on.",
      },
      "picture": {
        "type": "string",
        "format": "image-file",
      },
      "link": {
        "type": "string",
        "default": "http://example.com"
      }
    },
    "required": [
      "name",
      "description",
      "picture"
    ],
    "default": {
      "name": "My Project",
      "description": "A project I worked on.",
      "link": "http://example.com",
      "picture": ""
    }
  }
}

The difference is that we don't need to mirror the default values in two places–the autoPopulate will specify that by default, we will include the link property, and the default value can be grabbed from the leaf just like when we auto-populate required properties.