Skip to content

Add object validation keywords #35

Description

@crmne

Goal

Add support for object-specific Draft 2020-12 validation keywords:

  • minProperties
  • maxProperties
  • patternProperties
  • propertyNames

Meanings

minProperties and maxProperties constrain how many keys an object may have.

patternProperties says: for keys matching this pattern, their values must match this schema.

propertyNames says: every key name itself must validate against a schema.

These last two are related, but not the same:

  • patternProperties validates values selected by matching key names.
  • propertyNames validates the key names themselves.

Proposed DSL for property counts

object :metadata, min_properties: 1, max_properties: 5 do
  string :name
end

Proposed DSL for patternProperties

object :metadata do
  keys_matching /^x-/ do
    string
  end

  keys_matching /^count_/ do
    integer minimum: 0
  end
end

This means:

  • keys like x-name must have string values
  • keys like count_views must have integer values

Open DSL question for propertyNames

We need a clear DSL for validating all key names. key_pattern: may not be clear enough, especially next to keys_matching.

Possible options:

object :metadata do
  keys do
    string pattern: "^[a-z_]+$"
  end
end

or:

object :metadata, keys: { pattern: "^[a-z_]+$" } do
  string :name
end

Acceptance criteria

  • Exact generation tests for all supported object keywords.
  • Behavior tests for valid and invalid objects.
  • Generated schemas validate against Draft 2020-12.
  • Final propertyNames DSL is decided before implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions