#3: Allow the "properties" attribute to take an array (or an object like
normal), and the array would be an array of schemas that specify the
property name (as regex) to apply to. Each property in the instance
would have to match and validate against at least one property definition.
"properties": [
{"name":"s\d+","type":"string"},
{"name":"n\d+","type":"number"}
]
One possibility in conjunction with #3 is that we could move union
capabilities to the properties array, since this effectively provides
unioning (when the same name is used multiple times), which could
eliminate the issue with primitive types mixing with referenced schemas
in "type".
#3b: We could vary this a little and the array could contain "name" and
"type" that refers to the schema, and possibly also "requires" (since it
doesn't apply directly to the value):
"properties": [
{"name":"s\d+","type":{"type":"string"}},
{"name":"n\d+","type":{"type":"number"}, "requires":"s1"}
]
#4: Use regular expressions as the property names in the "properties".
"properties": {
"s\d+": {"type":"string"},
"n\d+": {"type":"number"}
}
This has the advantage of being more succint, but would have some
backwards compatibility issues (although the problematic property names
would probably be relatively rare).
Both of these approaches would allow us to eliminate
additionalProperties altogether (a nice simplification).
Kris
--
Thanks,
Kris
Option #5 - Introduce a new attribute that provides a property name
pattern to schema association like:
"otherProperties": {
"s\d+": {"type":"string"},
"n\d+": {"type":"number"}
}
This is essentially the same as option #4, except it does not change
the signature of "properties". Properties that don't match those
defined in the "properties" attribute would then be compared to this
new attribute. This keeps simple properties easy to write, multiple
properties condensed, backward compatible, prevents referencing
problems, and allows validators to do hash lookups first before moving
to slower search and compare.
This new attribute could also be merged with option #1, providing an
easy and more complex way of validating property names.
-Gary
> --
> You received this message because you are subscribed to the Google Groups "JSON Schema" group.
> To post to this group, send email to json-...@googlegroups.com.
> To unsubscribe from this group, send email to json-schema...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/json-schema?hl=en.
>
>
Also, after some thinking, merging with option #1 doesn't really
simplify things, so I would ignore that suggestion.
-Gary
patternProperties : {
"^[a-z]{2,10}$" : {}
}
-Gary
You assume that regular exceptions are slow to use, which is not the
case for good implementations (available for most common platforms).
Compilation of expression only need to be done once per schema
instance, and comparisons are typically very fast; commonly faster
than naive hand-written checks.
Further, regex compiler can obviously optimize for simple cases where
value is constant string.
So trying to avoid use of regexps seems a lot like premature
optimization; especially if it adds complexity.
-+ Tatu +-
I agree. It has been my experience as well that regular expressions
are faster at multi-step text comparison then any hand-written
JavaScript.
-Gary