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

Import feature misidentifies root path for endpoint #102

Open
dkharlan opened this issue May 17, 2017 · 0 comments
Open

Import feature misidentifies root path for endpoint #102

dkharlan opened this issue May 17, 2017 · 0 comments

Comments

@dkharlan
Copy link

Given thing_doer.yml:

tags:
  - "thing_doer"
summary: "Do a thing"
description: ""
consumes:
  - "application/json"
produces:
  - "application/json"
parameters:
  - in: "body"
    name: "body"
    required: true
    schema:
      import: "models/stuff.yml"
responses:
  200:
    description: "The results of doing a thing"
    schema:
      type: "object"
      properties:
        whatever:
          type: "integer"

with a file structure as follows:

specs/
   thing_doer.yml
   models/
      stuff.yml

I get the following exception:

[2017-05-17 16:08:43,303] ERROR in app: Exception on /apispec_1.json [GET]
Traceback (most recent call last):
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flasgger/utils.py", line 294, in load_from_file
    with open(swag_path) as yaml_file:
FileNotFoundError: [Errno 2] No such file or directory: 'models/raw_text.yml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flask/views.py", line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flask/views.py", line 149, in dispatch_request
    return meth(*args, **kwargs)
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flasgger/base.py", line 229, in get
    endpoint=rule.endpoint, verb=verb
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flasgger/utils.py", line 338, in parse_docstring
    full_doc = parse_imports(full_doc, root_path)
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flasgger/utils.py", line 420, in parse_imports
    imported_doc = load_from_file(filepath, root_path=root_path)
  File "/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flasgger/utils.py", line 301, in load_from_file
    with open(swag_path) as yaml_file:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flasgger/models/raw_text.yml'

The culprit appears to be https://github.com/rochacbruno/flasgger/blob/master/flasgger/utils.py#L362 where obj.__globals__['__file__'] resolves to '/Users/dkharlan/venvs/myenv/lib/python3.6/site-packages/flasgger/utils.py'. I'm not really sure why this would happen (maybe the way the endpoint function is imported influences the value of __file__? I'm unclear on Python's semantics here).

Thank you -- please let me know if you need more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants