def validate_default_value(cls, v, values): """Validate default value against spec if provided.""" try: type_ = values['type'] except KeyError: raise ValueError(f'Input with missing type: {cls.__name__}') if type_ != cls.__name__: # this is a check to ensure the default value only gets validated againt the # correct class type. The reason we need to do this is that Pydantic doesn't # support discriminators (https://github.com/samuelcolvin/pydantic/issues/619). # As a result in case of checking for Union it checks every possible item # from the start until it finds one. For inputs it causes this check to fail # on a string before it gets to the integer class for an integer input. return v try: default = values['default'] except KeyError: # spec is not set return v if v is not None and default is not None: json_schema_validator(default, v) return v
def validate_spec(self, value): """Validate an input value against specification. Use this for validating workflow inputs against a recipe. """ if self.spec: spec = dict(self.spec) json_schema_validator(value, spec) return value
def validate_spec(self, value): """Validate an input value against specification. Use this for validating workflow inputs against a recipe. """ if self.spec: spec = dict(self.spec) spec['type'] = 'array' spec['items'] = self.items_type.lower() json_schema_validator(value, spec)
def validate_spec(self, value): """Validate an input value against specification. Use this for validating workflow inputs against a recipe. """ assert os.path.isdir(value), f'There is no folder at {value}' if self.spec: spec = dict(self.spec) spec['type'] = 'string' json_schema_validator(value, spec) return value
def validate_spec(self, value): """Validate an input value against specification. Use this for validating workflow inputs against a recipe. """ assert os.path.isfile(value), f'There is no file at {value}' if self.extensions: assert value.lower().endswith(self.extension.lower()), \ f'Input file extension for {value} must be {self.extensions}' if self.spec: spec = dict(self.spec) spec['type'] = 'string' json_schema_validator(value, spec)
def validate_spec(self, value): """Validate an input value against specification. Use this for validating workflow inputs against a recipe. """ if os.path.isfile(value): if self.extensions: assert value.lower().endswith(self.extension.lower()), \ f'Input file extension for {value} must be {self.extensions}' elif not os.path.isdir(value): raise ValueError(f'{value} is not a valid file or folder.') if self.spec: spec = dict(self.spec) spec['type'] = 'string' json_schema_validator(value, spec)