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.
Goal
Add support for object-specific Draft 2020-12 validation keywords:
minPropertiesmaxPropertiespatternPropertiespropertyNamesMeanings
minPropertiesandmaxPropertiesconstrain how many keys an object may have.patternPropertiessays: for keys matching this pattern, their values must match this schema.propertyNamessays: every key name itself must validate against a schema.These last two are related, but not the same:
patternPropertiesvalidates values selected by matching key names.propertyNamesvalidates the key names themselves.Proposed DSL for property counts
Proposed DSL for
patternPropertiesThis means:
x-namemust have string valuescount_viewsmust have integer valuesOpen DSL question for
propertyNamesWe need a clear DSL for validating all key names.
key_pattern:may not be clear enough, especially next tokeys_matching.Possible options:
or:
Acceptance criteria
propertyNamesDSL is decided before implementation.