Can we have DRYer patternProperties keys? #150
reitzig
started this conversation in
Specification
Replies: 1 comment 1 reply
-
|
If you want to reuse the pattern that you would otherwise use in i.e. this: is equivalent to this: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Say I want to refactor the not-nice(TM)
into the nicer(TM) (more idiomatic, anyway?)
I would change the schema of
thingsfromarray+itemstoobject+patternProperties, moving the pattern fromthings.items.properties.idtothings.patternProperties.Now, for
things.items.properties.id, I could use$refto point toward a central definition.For
things.patternProperties.$pattern, though, I can't.That's unfortunate; I have to choose between repeating the same pattern over and over, no doubt introducing inconsistencies at some point, and having those rather useless array layers around.
How about handing two schemas
keyandvaluetopatternProperties2, with some restrictions onkey(admissible values must be a subset of valid JSON keys), as an alternative to the currentpatternProperties? Might look something like this:Now, we could use
$refinsidekey, but alsoenumwhich I imagine to be useful in some cases.The current
patternPropertieswould be a special case; it'd translate to something similar to the example above, providing a clear migration path if need be.Beta Was this translation helpful? Give feedback.
All reactions