-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Invalid URL (jsonschema RefResolutionError) #74
Comments
Tried a quick-fix by providing a # spec_uri is set to /home/spec/
/home/
|- spec/
|- common/
|- schemas.yaml
|- service/
|- responses.yaml
- $ref: '../common/schemas.yaml#/PermissionDenied' The ref will be looked for at |
Working on a solution, but I think the bug is with jsonschema. While it stores the referring document, it is never passed to the resolving handler. It's only stored on the object and not used or referenced anywhere else it seems. |
The |
I have ran into another related problem: if a remote has internal references, the validator tries to locate it on the main document. For example, with the main spec: openapi: 3.0.2
info:
title: FooBar
version: 1.0.0
paths:
/foo/{id}:
summary: Path used to retrieve a single Foo.
get:
summary: Get a Foo
description: Gets the details of a single instance of a `Foo`.
operationId: getFoo
responses:
'200':
$ref: '#/components/responses/FooResponse'
'404':
$ref: 'foo-global-schemas.yaml#/components/responses/NotFoundError'
components:
responses:
FooResponse:
description: Successful response - returns a single foo.
content:
application/json:
schema:
$ref: '#/components/schemas/Foo'
schemas:
Foo:
type: object
properties:
bar:
type: string And the remote spec components:
responses:
NotFoundError:
description: Resource not found.
content:
application/json:
schema:
$ref: '#/components/schemas/NotFoundError' And this very basic Python code: from pathlib import Path
import yaml
from dli.client.openapi import create_spec
path = Path(__file__).parent / 'openapi.yaml'
path = path.resolve()
with open(path) as f:
spec_dict = yaml.safe_load(f)
spec = create_spec(spec_dict, spec_url=f'file://{path}')
print(spec) The resulting error will be:
However, when all the internal references in the
After digging through the code a little bit it seems like the issue is related to |
We probably should install an extra handler for jsonschema, one that prepends
file://
and resolves the current directory to all relative file name references. The relevant code that errors out:The code in question:
I have also tried
file://./paths.yaml
, which then results in it looking for/paths.yaml
, which is an error of the file resolver jsonschema is using. Either way, we currently cannot resolve any relative file references, which are allowed and correctly working in other tools, includingopenapi-spec-validator
. The latter is a bit odd, since it should be resolving references and validating them.The text was updated successfully, but these errors were encountered: