Migrating 0.3.9 typesystem extensions to 0.4.3 Validators


I’m working through migrating an app in development from 0.3.9 to 0.4.3.

Previously, I had created classes for fields that popped up enough. For example

class SearchField(typesystem.String):
    min_length = 5
    description = 'Search string. Minimum of 5 characters'

With validators, it would appear that I would extend init instead and set the appropriate kwargs

class SearchField(apistar.validators.String):
    def __init__(self, **kwargs):
        super(SearchField, self).__init__(min_length=5, description='Search string. Minimum of 5 characters', **kwargs)

or thereabouts.

Is that the intended usage for creating custom validators?

Update: A better way might be as follows if I definitely wanted to enforce my min_length and description, and not let anyone change it on the fly

class SearchField(apistar.validators.String):
    def __init__(self, **kwargs):
        kwargs['min_length] = 5
        kwargs['description'] = 'Search string. Minimum of 5 characters'
        super(SearchField, self).__init__(**kwargs)