How do I create a validator for a single collection?

58 views Asked by At

I need to build a custom id validator that will apply to a single collection, whose id will always be pre-defined (won't need a generator).

In the docs about id generators, it's written:

Currently the configuration of the custom generator applies to every resources (buckets, groups, collections, records). This tiny limitation can easily be fixed, don’t hesitate to get in touch with us!

But there is nothing documented about id validation.

So, how do I:

  1. Implement an id validator, that
  2. Will apply to one collection only?
1

There are 1 answers

3
Alexis Métaireau On

By default cliquet uses a generator which accepts the following regular expression r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$' (All letters and numbers + underscore and "-").

Before you chose to have a different ID validation mechanism, ensure you really need to.

Now, if that's not enough, you would need to select the proper validator depending on some configuration or already existing values, but this is not implemented in cliquet / kinto.

https://github.com/mozilla-services/cliquet/blob/master/cliquet/resource/init.py#L147 is probably a good place to look at / start with.