pyopenapi / pyswagger

An OpenAPI (fka Swagger) client & converter in python, which is type-safe, dynamic, spec-compliant.
MIT License
384 stars 88 forks source link

ValueError: Can't resolve type from:(string, string) #152

Closed jeremyschulman closed 6 years ago

jeremyschulman commented 6 years ago

Hi,

First let me thank you for making this library - it is quite amazing. I am just getting started with this, and I am presuming I am doing something wrong, or missing a step. But my scenario is this: I have an API that take a string parameter. But when I attempt to pass the parameter value into the Operation object, I get and error.

The code, for example:

>>> op = app.s('/api/blueprints/{blueprint_id}/racks').get
>>> op
<pyswagger.spec.v2_0.objects.Operation object at 0x106518a90>
>>> op.parameters
[<pyswagger.spec.v2_0.objects.Parameter object at 0x10abddb10>]
>>> op.parameters[0]
<pyswagger.spec.v2_0.objects.Parameter object at 0x10abddb10>
>>> op.parameters[0].name
u'blueprint_id'
>>> op.parameters[0].type
u'string'
>>> op.parameters[0].format
u'string'

Issuing the call to create the request, response objects:

>>> op(blueprint_id="123")

results in this error:

ValueError: Can't resolve type from:(string, string)

As a workaround, I created a primitive factory to add the "string"->"string" mapping. And then I am A-OK.

prim_factory = SwaggerPrimitive()
prim_factory.register('string', 'string', create_str, validate_str)

I am curious if I am simply missing something so that I can avoid creating this factory. I appreciate your time to answer this question.

Cheers, -- Jeremy

mission-liao commented 6 years ago

@jeremyschulman The primitive map is created based on this table. If I missed anything and (string, string) should be added, please feel free to let me know.