Skip to content

collectionFormat always at "None" when swagger spec don't explicitly set it #101

@Kyria

Description

@Kyria

The swagger spec I'm calling don't define "collectionFormat" as the default value, according to OAI spec, is "csv".

But, currently, when i'm doing call with arrays, pyswagger always return "None" for the collectionFormat instead of "csv" and I have this error:

>>> from pyswagger import App
>>> app = App.create('https://esi.tech.ccp.is/latest/swagger.json')
>>> app.op['get_characters_names'](character_ids=[90000001])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "F:\Code\LazyBlacksmith\env\lib\site-packages\pyswagger\spec\v2_0\objects.py", line 283, in __call__
    _convert_parameter(final(p))
  File "F:\Code\LazyBlacksmith\env\lib\site-packages\pyswagger\spec\v2_0\objects.py", line 274, in _convert_parameter
    params[i].extend([tuple([p.name, v]) for v in c.to_url()])
  File "F:\Code\LazyBlacksmith\env\lib\site-packages\pyswagger\primitives\_array.py", line 79, in to_url
    return [str(self)]
  File "F:\Code\LazyBlacksmith\env\lib\site-packages\pyswagger\primitives\_array.py", line 70, in __str__
    raise SchemaError('Unsupported collection format when converting to str: {0}'.format(self.__collection_format))
pyswagger.errs.SchemaError: Unsupported collection format when converting to str: None

After digging a little in pyswagger code, what i've found is that this line https://github.com/mission-liao/pyswagger/blob/master/pyswagger/primitives/_array.py#L20 always return "None" instead of "csv".
So i checked that value, and no matter what it's always at "None".

So far, i've found a way to avoid this issue ( but I don't actually know if there will be some impacts on the other endpoints) by adding this before I create my App object :

from pyswagger.spec.v2_0.objects import Parameter
Parameter.__swagger_fields__['collectionFormat']='csv'

So it gives:

>>> from pyswagger.spec.v2_0.objects import Parameter
>>> Parameter.__swagger_fields__['collectionFormat']='csv'
>>>
>>> from pyswagger import App
>>> app = App.create('https://esi.tech.ccp.is/latest/swagger.json')
>>> app.op['get_characters_names'](character_ids=[90000001])
(<pyswagger.io.Request object at 0x0468CA50>, <pyswagger.io.Response object at 0x04E4A4B0>)

Thank you for your help and answers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions