How to use the connexion.utils.is_nullable function in connexion

To help you get started, we’ve selected a few connexion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zalando / connexion / connexion / decorators / validation.py View on Github external
def validate_parameter(parameter_type, value, param, param_name=None):
        if value is not None:
            if is_nullable(param) and is_null(value):
                return

            try:
                converted_value = coerce_type(param, value, parameter_type, param_name)
            except TypeValidationError as e:
                return str(e)

            param = copy.deepcopy(param)
            param = param.get('schema', param)
            if 'required' in param:
                del param['required']
            try:
                if parameter_type == 'formdata' and param.get('type') == 'file':
                    if _jsonschema_3_or_newer:
                        extend(
                            Draft4Validator,
github zalando / connexion / connexion / operations / openapi.py View on Github external
def _get_val_from_param(self, value, query_defn):
        query_schema = query_defn["schema"]

        if is_nullable(query_schema) and is_null(value):
            return None

        if query_schema["type"] == "array":
            return [make_type(part, query_schema["items"]["type"]) for part in value]
        elif query_schema["type"] == "object" and 'properties' in query_schema:
            return_dict = {}
            for prop_key in query_schema['properties'].keys():
                prop_value = value.get(prop_key, None)
                if prop_value is not None:  # False is a valid value for boolean values
                    try:
                        return_dict[prop_key] = make_type(value[prop_key],
                                                          query_schema['properties'][prop_key]['type'])
                    except (KeyError, TypeError):
                        return value
            return return_dict
        else:
github zalando / connexion / connexion / decorators / validation.py View on Github external
def coerce_type(param, value, parameter_type, parameter_name=None):

    def make_type(value, type_literal):
        type_func = TYPE_MAP.get(type_literal)
        return type_func(value)

    param_schema = param.get("schema", param)
    if is_nullable(param_schema) and is_null(value):
        return None

    param_type = param_schema.get('type')
    parameter_name = parameter_name if parameter_name else param.get('name')
    if param_type == "array":
        converted_params = []
        for v in value:
            try:
                converted = make_type(v, param_schema["items"]["type"])
            except (ValueError, TypeError):
                converted = v
            converted_params.append(converted)
        return converted_params
    elif param_type == 'object':
        if param_schema.get('properties'):
            def cast_leaves(d, schema):
github zalando / connexion / connexion / operation.py View on Github external
def __validation_decorators(self):
        """
        :rtype: types.FunctionType
        """
        ParameterValidator = self.validator_map['parameter']
        RequestBodyValidator = self.validator_map['body']
        if self.parameters:
            yield ParameterValidator(self.parameters,
                                     self.api,
                                     strict_validation=self.strict_validation)
        if self.body_schema:
            yield RequestBodyValidator(self.body_schema, self.consumes, self.api,
                                       is_nullable(self.body_definition))
github zalando / connexion / connexion / operations / abstract.py View on Github external
def __validation_decorators(self):
        """
        :rtype: types.FunctionType
        """
        ParameterValidator = self.validator_map['parameter']
        RequestBodyValidator = self.validator_map['body']
        if self.parameters:
            yield ParameterValidator(self.parameters,
                                     self.api,
                                     strict_validation=self.strict_validation)
        if self.body_schema:
            yield RequestBodyValidator(self.body_schema, self.consumes, self.api,
                                       is_nullable(self.body_definition),
                                       strict_validation=self.strict_validation)
github zalando / connexion / connexion / operations / openapi.py View on Github external
def _get_body_argument(self, body, arguments, has_kwargs, sanitize):
        x_body_name = sanitize(self.body_schema.get('x-body-name', 'body'))
        if is_nullable(self.body_schema) and is_null(body):
            return {x_body_name: None}

        default_body = self.body_schema.get('default', {})
        body_props = {k: {"schema": v} for k, v
                      in self.body_schema.get("properties", {}).items()}

        # by OpenAPI specification `additionalProperties` defaults to `true`
        # see: https://github.com/OAI/OpenAPI-Specification/blame/3.0.2/versions/3.0.2.md#L2305
        additional_props = self.body_schema.get("additionalProperties", True)

        if body is None:
            body = deepcopy(default_body)

        if self.body_schema.get("type") != "object":
            if x_body_name in arguments or has_kwargs:
                return {x_body_name: body}