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 always at "None" when swagger spec don't explicitly set it #101

Closed
Kyria opened this issue Jan 2, 2017 · 4 comments
Closed
Milestone

Comments

@Kyria
Copy link

Kyria commented Jan 2, 2017

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

@mission-liao
Copy link
Member

Yes, that's a bug and thanks for pointing it out.

  • the line in object.py should be
collectionFormat: 'csv' # instead of None
  • and the line in _array.py is meaningless since there would always a value for that field.
self.__collection_format = getattr(obj, 'collectionFormat', 'csv')

@mission-liao mission-liao added this to the v0.8.25 milestone Jan 3, 2017
@mission-liao
Copy link
Member

the fix is included in v0.8.25, please feel free to reopen this issue when anything goes wrong

@ghost
Copy link

ghost commented May 26, 2017

I am getting this error again in v0.8.29 with embedded arrays in response. Should I reopen this issue?

@mission-liao
Copy link
Member

@surajbarkale-dolby I prefer to open an new issue, which is easier for maintenance. Could you also provide a sample input / output of your problem if your case is not covered by this test case?

mission-liao added a commit to pyopenapi/pyopenapi that referenced this issue Aug 12, 2017
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

2 participants