Evert Mouw - 2014-09-23

Disjunctional pattern matching with Kwalify

Evert Mouw, 2014-09-23

The first space

The first space after the colon is needed and also will be ignored for the pattern matching.

So this key-value pair will not be recognized:


But this one will work normally:

color: red

The key is "color" and the value is "red" (without the space).

Enum doesn't work for optional values

The enum operator does not validate empty values, even when the field is not required. This is a bug.

RegExp matching that doesn't work

If you want to only validate a value when the whole value matches your pattern, and not only a part of it, then you need to pay close attention.

E.g., you want to match "ant" or "dinosaur" or "dino" or "ant, dino" or "ant, dinosaur" or "ant, dino*" ...

You specify this pattern in schema.yaml:

pattern: /[ ]|ant,[ ]*elek\w*|ant|dinosaur|dino/

Then this will be validated, because a part of it matches!

producten: ank, dinosaur

But this one will not be validated, because no part matches:

producten: ank

Working whole value pattern matching

You need to make sure that the whole value, including the beginning (^) and the end ($), are matched.

pattern: /^$|^ant,[ ]*dino\w*$|^ant$|^dinosaur$|^elek$/

This works as expected.