pyopenapi/pyswagger

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

pietroppeter opened this issue · 0 comments

Edit:

I realized the following is more suited as a stackoverflow question than a github issue, so I asked.

When I get a stackoverflow answer I will close this.


Hi,
I am having an issue with a simple body parsing.

Here is my script:

import os
import logging
from dotenv import load_dotenv, find_dotenv
from pyswagger import App, Security
from pyswagger.contrib.client.requests import Client

# set up logging
logger = logging.getLogger('pyswagger')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
console.setFormatter(formatter)
logger.addHandler(console)
logger.setLevel(logging.DEBUG)

# load my security token
load_dotenv(find_dotenv())
api_key = os.environ.get('HELLO_SWAGGER_API_KEY', 'xxx')
hello_swagger_json = 'https://europewest.services.azureml.net/subscriptions/300c8e706bdd414aa1c215ceb2b5a465/services/363818fa1c4a4d0b9d5c03a3dc6f1dfe/swagger.json'

# adapted from pyswagger quick start
app = App._create_(hello_swagger_json)
auth = Security(app)
auth.update_with('api_key', api_key)
client = Client(auth)

# this produces a dictionary exactly as in the schema example for 'execute' operation
hello_body = dict(Inputs=dict(input1=[dict(name="mission-liao")]), GlobalParameters=dict())

# submit execute post request
req, resp = app.op['execute'](body=hello_body)

which give me this error when executing last line:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\spec\v2_0\objects.py", line 283, in __call__
    _convert_parameter(final(p))
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\spec\v2_0\objects.py", line 264, in _convert_parameter
    c = p._prim_(v, self._prim_factory, ctx=dict(read=False))
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\spec\v2_0\objects.py", line 184, in _prim_
    return prim_factory.produce(self.schema, v, ctx) if i == 'body' else prim_factory.produce(self, v, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\__init__.py", line 200, in produce
    val = ret.apply_with(obj, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\__init__.py", line 196, in produce
    val = _2nd(obj, ret, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\__init__.py", line 196, in produce
    val = _2nd(obj, ret, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\_array.py", line 48, in apply_with
    self.extend(map(functools.partial(ctx['factory'].produce, obj.items), val))
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\__init__.py", line 200, in produce
    val = ret.apply_with(obj, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\__init__.py", line 192, in produce
    raise ValueError('Can\'t resolve type from:(' + str(obj.type) + ', ' + str(obj.format) + ')')
ValueError: Can't resolve type from:(String, )

I cannot really understand if there is something I am doing wrong or if this is a bug.
This is actually a very simple example I was trying to build because I am having an issue with authentication in a more complex example, but while in the more complex example the body parsing does not raise errors, here I am having problems even before sending a request!

The script should be reproducible (swagger.json should be accessible from the url in the script, if not I can attach it) and I have logging info only when running the command app = App._create_(hello_swagger_json) (so this too should be reproducible too using the above script).

The webservice that I am trying to test is a simple Web service built with Azure ML Studio (which provides a Swagger API, the reason why I found out about Swagger in the first place).

I am running with pyswagger version 0.8.39.