Skip to content

Not handling "type: integer" without a corresponding "format:"  #128

@MartinDelVecchio

Description

@MartinDelVecchio

I am using pyswagger to execute an API call that returns an object with several integer properties. The Swagger for each property specifies only "type: integer"; it does not specify a format (int32 or int64).

When I execute the API, pyswagger raises an exception:

  File "/usr/lib/python2.7/site-packages/pyswagger/primitives/__init__.py", line 182, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/usr/lib/python2.7/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/usr/lib/python2.7/site-packages/pyswagger/primitives/_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "/usr/lib/python2.7/site-packages/pyswagger/primitives/__init__.py", line 178, in produce
    raise ValueError('Can\'t resolve type from:(' + str(obj.type) + ', ' + str(obj.format) + ')')
ValueError: Can't resolve type from:(integer, None)

I tracked this down to this code in the Primitives constructor (primitives/init.py):

    self._map = {
        # int
        'integer': {
            'int32': (create_int, validate_int),
            'int64': (create_int, validate_int),
        },

It seems that pyswagger requires a format, either 'int32' or 'int64', and fails when no format is specified.

I solved my problem by adding a new entry to the map:

    self._map = {
        # int
        'integer': {
            'int32': (create_int, validate_int),
            'int64': (create_int, validate_int),
            None: (create_int, validate_int),
        },

It does not appear to me that the Swagger specification requires a "format" for an integer type. In addition, the above code shows that pyswagger doesn't treat int32 and int64 differently.

Is there a reason why pyswagger is insisting on a format for an integer type?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions