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

Unable to resolve local relative file references #3

Closed
CloudNiner opened this issue Jan 5, 2017 · 5 comments
Closed

Unable to resolve local relative file references #3

CloudNiner opened this issue Jan 5, 2017 · 5 comments
Assignees
Labels

Comments

@CloudNiner
Copy link
Contributor

I have two yml files that define my Swagger specification:

# api_spec.yml
...
paths:
  /foo:
    get:
      summary: Foo List
      description: Lists all foos
      produces:
        - application/json
      responses:
        "200":
          description: A list of Foo objects
          schema:
            type: array
            items:
              $ref: ./definitions/foo.yml#/Foo
...

and

# definitions/foo.yml
Foo:
  type: object
  properties:
    id:
      type: string
      description: Unique id for foo
    label:
      type: string
      description: Human-readable description of foo

When I attempt to build my sphinx docs, I get the following error:

building [html]: targets for 13 source files that are out of date
updating environment: 13 added, 0 changed, 0 removed
reading sources... [  7%] api_reference                                                                                                           
Exception occurred:
  File "/usr/local/lib/python2.7/site-packages/jsonschema/validators.py", line 346, in resolve_from_url
    raise RefResolutionError(exc)
RefResolutionError: unknown url type: ./definitions/scenario.yml
The full traceback has been saved in /tmp/sphinx-err-7U659m.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
Makefile:58: recipe for target 'html' failed
make: *** [html] Error 1

It appears that jsonschema.RefResolver is always instantiated with base_uri = '', which would break local refs. Is it possible to have an option on the openapi directive that would allow local file refs in the Swagger definition somehow?

It appears that some workarounds are being explored here: python-jsonschema/jsonschema#313 (comment)

@ikalnytskyi
Copy link
Member

Seems like the bug indeed. I'll take a look on the weekend. Thanks for the reporting!

@CloudNiner
Copy link
Contributor Author

Sure thing. Happy to help if additional implementation is necessary.

@ikalnytskyi
Copy link
Member

@CloudNiner Well, I have both good and bad news for you. :)

[GOOD] I've managed to fix the issue, and once I finish writing tests I'll push it.

[BAD] Unfortunately, jsonschema tries to load referred documents as JSON, so trying to load YAMLs as JSON will obviously fail. :(

@CloudNiner
Copy link
Contributor Author

Awesome. Thanks for taking a look! I expected yaml would be trouble, no worries there.

@ikalnytskyi ikalnytskyi self-assigned this Jan 10, 2017
@ikalnytskyi
Copy link
Member

ikalnytskyi commented Jan 10, 2017

UPD: sphinxcontrib-openapi v0.2.1 with the fix has been released on PyPI.

https://pypi.python.org/pypi/sphinxcontrib-openapi/0.2.1

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

No branches or pull requests

2 participants