Skip to content

Conversation

@dmosorast
Copy link
Contributor

@dmosorast dmosorast commented Nov 16, 2018

JSON Schema supports object schemas having the keys additionalProperties and patternProperties described in the Draft 4 validation document here.

Maintained

  • Empty object schemas still validate against anything

Added

patternProperties

PatternProperties are a JSON object of the form {"regex_pattern": {...schema...}}. For example, a simple "catch-all" schema would look like this:

{
    "type": "object",
    "patternProperties": {
        ".+": {},
        ...
    }
}

This is useful in the event that you want the schema to validate against all keys, but override using properties for more specific types (like date-times).

Principles

  • properties takes precedence
  • An empty properties and patternProperties is treated as an empty schema and validates against all
  • Regex ordering cannot be guaranteed (since the JSON Schema spec says "object" explicitly), so regexes should be distinct as possible for mixing types, to be deterministic

@dmosorast dmosorast changed the title Support additional properties and pattern properties in object schemas Support pattern properties in object schemas Nov 16, 2018
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

Successfully merging this pull request may close these issues.

3 participants