cerberus icon indicating copy to clipboard operation
cerberus copied to clipboard

Consider JMESPath as option to express fields

Open funkyfuture opened this issue 7 years ago • 0 comments

the JMESPath has a simple and straight-forward way to address values in a JSON-document. if we allowed that as an optional way to write schemas ('dot-lookup' is supported in some parts anyway), this could be benefitical especially for schemas that check only few values that are scattered around a document:

foo.bar.peng:
  type: integer

instead of

foo:
  schema:
    bar:
      schema:
        peng:
           type: integer

it also has a syntax to address values in sequences by index (a.b[1]).

however, there'd be a lot of detailed design questions to settle and it would require some work. so, if we'd decided to try this path, i'd pledge fot the next major version to include it.

one noteworthy problems to anticipate is the mixing the different addressing options that would propably lead to confusion, esp. when the 'classic' way defines something like allow_unknown on a higher level than a JMESPath expression.

an important question is also when Cerberus would resolve such notations. my guess is that it's propably better to resolve during validation with regards to registries and reusability. but that'd make it impossible to define normalization rules, for that an expansion like the *of-shortcuts would be needed.

i don't think that the trouble for supporting JMESPath's function capabilities would be worth it.

funkyfuture avatar Jan 25 '18 13:01 funkyfuture