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

SwaggerMappingError when trying to load spec with root path. #239

Open
bxm156 opened this issue Aug 16, 2016 · 4 comments
Open

SwaggerMappingError when trying to load spec with root path. #239

bxm156 opened this issue Aug 16, 2016 · 4 comments

Comments

@bxm156
Copy link
Member

bxm156 commented Aug 16, 2016

I'm trying to write a spec that will perform a POST on a url like "domain.com/", note that the url is at the root.

In the online Swagger Editor, this schema correctly validates and performs a POST, but when using bravado, I'm unable to load the schema json.

I get "bravado_core.exception.SwaggerMappingError: Could not extract resource name from path /"

Here is an example part of my 2.0 spec:
...

    "host": "example.com",
    "schemes": [
        "https"
    ],
    "basePath": "/",
    "produces": [
        "application/json"
    ],
    "paths": {
        "/": {
            "post": {

...

In the online swagger editor, this will correctly POST to "https://example.com/", but I get an error trying to load the spec in bravado. My code is on:
bravado==7.0.0
bravado-core==4.0.0

@bxm156
Copy link
Member Author

bxm156 commented Aug 16, 2016

So I discovered I have to add a "tag" and "operationId", then reference it by:

client.<tag>.<operationId>()

pretty confusing, not sure if thats documented anywhere. Perhaps we could add this to the documentation.

@striglia
Copy link

Can you post your full traceback and precisely what line of code produces it? I think this isn't the first time working with semi-complete specs caused a low-level error....shouldn't spec validation be catching this?

@bxm156
Copy link
Member Author

bxm156 commented Aug 16, 2016

Traceback (most recent call last):
  File "test_forward.py", line 4, in <module>
    'file://localhost/nail/home/bmarty/services/scrubbed/forwarding.json'
  File "/nail/home/bmarty/pg/scrubbed/virtualenv_run/local/lib/python2.7/site-packages/bravado/client.py", line 110, in from_url
    return cls.from_spec(spec_dict, spec_url, http_client, config)
  File "/nail/home/bmarty/pg/scrubbed/virtualenv_run/local/lib/python2.7/site-packages/bravado/client.py", line 129, in from_spec
    spec_dict, origin_url, http_client, config)
  File "/nail/home/bmarty/pg/scrubbed/virtualenv_run/local/lib/python2.7/site-packages/bravado_core/spec.py", line 104, in from_dict
    spec.build()
  File "/nail/home/bmarty/pg/scrubbed/virtualenv_run/local/lib/python2.7/site-packages/bravado_core/spec.py", line 127, in build
    self.resources = build_resources(self)
  File "/nail/home/bmarty/pg/scrubbed/virtualenv_run/local/lib/python2.7/site-packages/bravado_core/resource.py", line 67, in build_resources
    tags.append(convert_path_to_resource(path_name))
  File "/nail/home/bmarty/pg/scrubbed/virtualenv_run/local/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 /

@macisamuele
Copy link
Collaborator

Reading the specs I haven't found any constraint about the presence of the tag and operationId into the operation object. I have checked the minimal specs and there is no information about tag and operationId.
The issue seems caused by bravado-core which assumes that the path will match the following regex /.+.
I'm going to open an issue in the bravado-core project.
Thanks!

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

3 participants