-
Notifications
You must be signed in to change notification settings - Fork 357
Mixing properties and patternProperties fails for properties not matching the patternProperties definition #705
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
Comments
This isn't a bug; it's how the spec says it should behave 🙂
Your understanding is incorrect. According to the spec, The relevant spec wording is:
A contrasting example is
|
Edit: My advice below is incorrect, as the second Discussion of this limitation following the release of draft-06 was inconclusive, and the proposed addition of
{
"type": "object",
"anyOf": [
{
"properties": {...},
"additionalProperties": false
{,
{
"patternProperties": {...}
}
]
}
|
Thanks for the quick reply and clarification. It seems like PHPStorm's implementation is wrong. Sadly, I cannot make this work using anyOf like this results - it results in errors as well: "title": {
"type": "object",
"anyOf": [
{
"properties": {
"controller": {
"type": "string",
"pattern": "^[A-Z][a-zA-Z0-9]+$"
},
"action": {
"type": "string",
"pattern": "^[a-z][a-z0-9-]+$"
}
},
"additionalProperties": false
},
{
"patternProperties": {
"^[a-z][a-z0-9-]+$": {"pattern": "^[a-z0-9-]+$"}
}
}
]
}
I was able to make it work using a negative lookahead in the patternProperties: Thanks again and sorry for any inconvenience. |
Good call on the regex change - I clearly did not think the implications of what I was suggesting through properly! My apologies, and please ignore my advice from earlier to use At this point, your workaround using the regex exclusion may be the best path forward - I cannot think of another sane way to do what you need within the confines of the draft-06 spec, which is the newest version that this library supports. |
Schema (incomplete, just the important part):
Data:
Validating this data will result in an error:
Violations: [link.controller] Does not match the regex pattern ^[a-z0-9-]+$
Maybe I am the problem here, but I understand the "patternProperties" to only require validation for properties that aren't explicitly defined.
Since "controller" already is set, no validation with the regex pattern in
patternProperties
should occur.I already found a fix, but I'd like to wait with a PR until someone can tell me whether this is, indeed, a bug or just my misunderstanding of how
properties
&patternProperties
work.The text was updated successfully, but these errors were encountered: