fireproofsocks / dto

Data Transfer Object (DTO) in PHP using JSON Schema
77 stars 12 forks source link

Support for regular expressions in key names #2

Closed fireproofsocks closed 7 years ago

fireproofsocks commented 8 years ago

As a developer, I would like support in my meta definitions to be able to specify a simple regular expression that could be used to enforce key names (in the isValidTargetLocation() method).

Perhaps:

$meta = [
    '.myhash' => [
        'ambiguous' => true,
        'regex' => '/A-Z/';
    ]
];

Better name maybe "key_regex"? Or key->regex ? See the "patternProperties" http://json-schema.org/example2.html and "additionalProperties"

This feature would only make sense for hashes with ambiguous keys, unless you were sort of deferring validation of an object against an arbitrary schema, but we have objects and schemas in one, so it's not exactly the same problem.

fireproofsocks commented 7 years ago

v3 implements the "patternProperties" keyword. See http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.17