首页 > 解决方案 > Overloading validate in cerberus

问题描述

I'd like to overload validate in my custom validator class so that if the client only gives me text, I can convert it to yaml for validation.

I've tried the following:

import cerberus
from cerberus import Validator
from ruamel.yaml import YAML

class SchemaValidator(Validator):
    def _validate(self, schema_to_check_in_text, schema_from_catalog_in_yaml):
        ruamel_yaml = YAML()
        parsed_proposed_yaml = ruamel_yaml.load(schema_to_check_in_text)

        self.validate(parsed_proposed_yaml, schema_from_catalog_in_yaml)

But it doesn't work. Is this possible?

标签: pythonpython-3.xcerberus

解决方案


您不会重载任何东西,而是添加一个额外的方法,按照约定标记为私有。


推荐阅读