Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nwinter opened this issue Apr 10, 2014 · 0 comments
Open

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

nwinter opened this issue Apr 10, 2014 · 0 comments

Comments

@nwinter
Copy link
Contributor

nwinter commented Apr 10, 2014

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.

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

No branches or pull requests

1 participant