def required_validator(validator, req, instance, schema): """Swagger 1.2 expects `required` to be a bool in the Parameter object, but a list of properties in a Model object. """ if schema.get('paramType'): if req is True and not instance: return [ValidationError("%s is required" % schema['name'])] return [] return _validators.required_draft4(validator, req, instance, schema)
def required_validator(validator, required, instance, schema): """Swagger 2.0 expects `required` to be a bool in the Parameter object, but a list of properties everywhere else. :param validator: Validator class used to validate the object :type validator: :class:`Swagger20Validator` or :class:`jsonschema.validators.Draft4Validator` :param required: value of `required` field :type required: boolean or list or None :param instance: object instance value :param schema: swagger spec for the object :type schema: dict """ if is_param_spec(schema): if required and instance is None: return [ValidationError("%s is required" % schema['name'])] else: return _validators.required_draft4( validator, required, instance, schema)
def required_validator(validator, required, instance, schema): """Swagger 2.0 expects `required` to be a bool in the Parameter object, but a list of properties everywhere else. :param validator: Validator class used to validate the object :type validator: :class:`Swagger20Validator` or :class:`jsonschema.validators.Draft4Validator` :param required: value of `required` field :type required: boolean or list or None :param instance: object instance value :param schema: swagger spec for the object :type schema: dict """ if is_param_spec(schema): if required and instance is None: return [ValidationError("%s is required" % schema['name'])] else: return _validators.required_draft4(validator, required, instance, schema)
def required_validator(swagger_spec, validator, required, instance, schema): """Swagger 2.0 expects `required` to be a bool in the Parameter object, but a list of properties everywhere else. :param swagger_spec: needed for access to deref() :type swagger_spec: :class:`bravado_core.spec.Spec` :param validator: Validator class used to validate the object :type validator: :class:`Swagger20Validator` or :class:`jsonschema.validators.Draft4Validator` :param required: value of `required` field :type required: boolean or list or None :param instance: object instance value :param schema: swagger spec for the object :type schema: dict """ if is_param_spec(swagger_spec, schema): if required and instance is None: yield ValidationError('{0} is a required parameter.'.format( schema['name'])) else: for error in _validators.required_draft4(validator, required, instance, schema): yield error