Yelp / bravado-core

Other
109 stars 98 forks source link

build_resource failure for root path with no tags #116

Open macisamuele opened 7 years ago

macisamuele commented 7 years ago

The issue is related to what is reported in bravado issue #239.

An small example of the issue is

Python 2.7.9 (default, Aug 23 2016, 10:24:57)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from bravado_core.spec import Spec
>>> import yaml
>>>
>>> spec_text = """
info:
...   version: 0.0.0
...   title: Simple API
... paths:
...   /:
...     get:
...       responses:
...         '200':
...           description: OK
... swagger: '2.0'
... """
>>> spec_dict = yaml.load(spec_text)
>>> print spec_dict
{'info': {'version': '0.0.0', 'title': 'Simple API'}, 'paths': {'/': {'get': {'responses': {'200': {'description': 'OK'}}}}}, 'swagger': '2.0'}
>>> swagger_spec = Spec.from_dict(spec_dict)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/maci/pg/bravado/.tox/py27/lib/python2.7/site-packages/bravado_core/spec.py", line 152, in from_dict
    spec.build()
  File "/Users/maci/pg/bravado/.tox/py27/lib/python2.7/site-packages/bravado_core/spec.py", line 175, in build
    self.resources = build_resources(self)
  File "/Users/maci/pg/bravado/.tox/py27/lib/python2.7/site-packages/bravado_core/resource.py", line 67, in build_resources
    tags.append(convert_path_to_resource(path_name))
  File "/Users/maci/pg/bravado/.tox/py27/lib/python2.7/site-packages/bravado_core/resource.py", line 31, in convert_path_to_resource
    raise SwaggerMappingError(err_msg.format(path_name))
bravado_core.exception.SwaggerMappingError: Could not extract resource name from path /

The issue seems caused by the assumption that the path will match the following regexp /.+ (resource.py)

jkrukoff commented 7 years ago

Just ran into this issue. Was fortunate enough to also be in control of the swagger spec, so as to be able to add a superfluous tag to my root path.