Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collectionFormat array list of lists #382

Open
abyssusj opened this issue Apr 8, 2021 · 0 comments
Open

collectionFormat array list of lists #382

abyssusj opened this issue Apr 8, 2021 · 0 comments

Comments

@abyssusj
Copy link

abyssusj commented Apr 8, 2021

Fails to marshal lists of list arrays.

{"description":"connected solar system pairs",
    "in":"query",
    "items": {
        "collectionFormat":"pipes",
        "items": {
            "format":"int32",
            "type":"integer"
        },
        "maxItems":2,
        "minItems":2,
        "type":"array",
        "uniqueItems":true},
        "maxItems":100,
        "name":"connections",
        "type":"array",
        "uniqueItems":true
    }
connections = [[30000142,30002801], [30002801,30002661]]

API response

error="failed to coerce value '[30000142' into type integer (format: int32)

Note presence of "[30000142" in integer.

Expected request

/?connections=30000142%7C30002801,30002801%7C30002661

marshal_collection_format() appears to fail marshalling the list of lists at

def marshal_collection_format(swagger_spec, param_spec, value):


Monkeypatched with the following

def mymarshal_collection_format(swagger_spec, param_spec, value):
    """For an array, apply the collection format and return the result.

    :type swagger_spec: :class:`bravado_core.spec.Spec`
    :param param_spec: spec of the parameter with 'type': 'array'
    :param value: array value of the parameter
    :return: transformed value as a string
    """
    result = []
    collection_format = swagger_spec.deref(param_spec).get('items').get('collectionFormat', 'csv')
    if collection_format == 'multi':
        # http client lib should handle this
        return value

    sep = param.COLLECTION_FORMATS[collection_format]

    if any(isinstance(i, list) for i in value):
        """ if list of lists, apply marshaling to each item in list"""
        for i in value:
            result.append( sep.join(str(element) for element in i) )

    else:
        result = sep.join(str(element) for element in value)
    return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant