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 pattern properties in object schemas #92

Merged
merged 6 commits into from Nov 26, 2018

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.

None yet

2 participants