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
-
Say I want to refactor the not-nice(TM)
into the nicer(TM) (more idiomatic, anyway?)
I would change the schema of
things
fromarray
+items
toobject
+patternProperties
, moving the pattern fromthings.items.properties.id
tothings.patternProperties
.Now, for
things.items.properties.id
, I could use$ref
to 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
key
andvalue
topatternProperties2
, 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
$ref
insidekey
, but alsoenum
which I imagine to be useful in some cases.The current
patternProperties
would 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