How to use the bravado.mapping.exception.SwaggerMappingError function in bravado

To help you get started, we’ve selected a few bravado 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 Yelp / bravado / bravado / mapping / marshal.py View on Github external
# Allow models to be passed in as dicts for flexibility.
        if is_dict_like(value):
            return marshal_object(swagger_spec, schema_object_spec, value)

        # It is important that the 'model' check comes before 'object' check
        # below. Model specs are of type 'object' but also have a MODEL_MARKER
        # key for identification.
        return marshal_model(swagger_spec, schema_object_spec, value)

    if obj_type == 'object':
        return marshal_object(swagger_spec, schema_object_spec, value)

    if obj_type == 'file':
        return value

    raise SwaggerMappingError('Unknown type {0} for value {1}'.format(
        obj_type, value))
github Yelp / bravado / bravado / mapping / param.py View on Github external
def get_param_type_spec(param):
    """
    The spec for the parameter 'type' is not always in the same place for a
    parameter. The notable exception is when the location is 'body' and the
    schema for the type is in param_spec['schema']

    :rtype: dict
    :return: the param spec that contains 'type'
    :raises: SwaggerMappingError when param location is not valid
    """
    location = param.location
    if location in ('path', 'query', 'header', 'formData'):
        return param.param_spec
    if location == 'body':
        return param.param_spec['schema']
    raise SwaggerMappingError(
        "Don't know how to handle location {0}".format(location))
github Yelp / bravado / bravado / mapping / docstring.py View on Github external
# TODO: If the type is not specified, isn't it assumed to be 'object'? Find
    #       docs where this is stated. #/definitions/{def_name}/ don't have
    #       a 'type' but it always seems to be assumed as 'object'
    obj_type = spec.get('type')
    obj_format = spec.get('format')
    ref = spec.get('$ref')
    if obj_format and obj_type:
        return "{0}:{1}".format(obj_type, obj_format)
    elif obj_type == 'array':
        return "{0}:{1}".format(obj_type, formatted_type(spec["items"]))
    elif ref:
        return ref
    elif obj_type:
        return obj_type
    else:
        raise SwaggerMappingError(
            "No proper type could be found from {0}".format(spec))
github Yelp / bravado / bravado / mapping / unmarshal.py View on Github external
if obj_type == 'array':
        return unmarshal_array(swagger_spec, schema_object_spec, value)

    if is_model(schema_object_spec):
        # It is important that the 'model' check comes before 'object' check.
        # Model specs also have type 'object' but also have the additional
        # MODEL_MARKER key for identification.
        return unmarshal_model(swagger_spec, schema_object_spec, value)

    if obj_type == 'object':
        return unmarshal_object(swagger_spec, schema_object_spec, value)

    if obj_type == 'file':
        return value

    raise SwaggerMappingError(
        "Don't know how to unmarshal value {0} with a value of {1}"
        .format(value, obj_type))
github Yelp / bravado / bravado / mapping / operation.py View on Github external
{response}

    :type status_code: int
    :type op: :class:`bravado.mapping.operation.Operation`
    :return: response specification
    :rtype: dict
    :raises: SwaggerMappingError when the status_code could not be mapped to
        a response specification.
    """
    # We don't need to worry about checking #/responses/ because jsonref has
    # already inlined the $refs
    response_specs = op.op_spec.get('responses')
    default_response_spec = response_specs.get('default', None)
    response_spec = response_specs.get(str(status_code), default_response_spec)
    if response_spec is None:
        raise SwaggerMappingError(
            "Response specification matching http status_code {0} not found "
            "for {1}. Either add a response specifiction for the status_code "
            "or use a `default` response.".format(op, status_code))
    return response_spec
github Yelp / bravado / bravado / mapping / param.py View on Github external
:type param: :class;`bravado.mapping.param.Param`
    :param value: The raw content of the file to be uploaded
    :type request: dict
    """
    if request.get('files') is None:
        # support multiple files by default by setting to an empty array
        request['files'] = []

        # The http client should take care of setting the content-type header
        # to 'multipart/form-data'. Just verify that the swagger spec is
        # conformant
        expected_mime_type = 'multipart/form-data'

        # TODO: Remove after https://github.com/Yelp/swagger_spec_validator/issues/22 is implemented  # noqa
        if expected_mime_type not in param.op.consumes:
            raise SwaggerMappingError((
                "Mime-type '{0}' not found in list of supported mime-types for "
                "parameter '{1}' on operation '{2}': {3}").format(
                    expected_mime_type,
                    param.name,
                    param.op.operation_id,
                    param.op.consumes
                ))

    file_tuple = ('file', (param.name, value))
    request['files'].append(file_tuple)