Open edelooff opened 3 years ago
Digging in to this a bit more, it seems as if the resolution_scope
of the RefResolver
provided by jsonschema
has the wrong scope to resolve the URL correctly. That said, I don't quite comprehend the entire path leading up to this point, so I'm not sure whether this is painfully obvious, a red herring, or actually of some use:
resolution_scope
and ref
in jsonschema.RefResolver.resolve
for various different schema references:
$ref: "../schemas.yaml#/Item"
resolution scope: file:///workdir/relative-reference/openapi.yaml
ref: ../schemas.yaml#/Item
$ref: "./schemas.yaml#/Item"
resolution scope: file:///workdir/relative-reference/sub/paths.yaml#/root
ref: ./schemas.yaml#/Item
$ref: "schemas.yaml#/Item"
resolution scope: file:///workdir/relative-reference/sub/paths.yaml#/root
ref: schemas.yaml#/Item
I have a schema with a reference graph that looks like
openapi.yaml
->sub/paths.yaml
->schemas.yaml
. The middle schema is in a subdirectory and the first and last schemas are in the same directory. This fails to resolve correctly when proving the spec_dict generated fromopenapi.yaml
tocreate_spec
in the following way:The three OpenAPI files are as follows:
relative-reference/openapi.yaml
:relative-reference/sub/paths.yaml
:relative-reference/schemas.yaml
:The error I get ends with
The path it tries to resolve lacks the
relative-reference
directory name.However, fixing it by adding the missing path portion in the reference does not help. When changing the parent-directory reference to
../relative-reference/schemas.yaml#/Item
, the error changes but remains:The 'base' directory was left on the path and now we have a failure because we try to access a directory that doesn't exist. Adding a differently named path portion here results in the same problem (except the failed path will be e.g.
/workdir/relative-reference/dummy/schemas.yaml
. This error happens on all Pythons 3.6 through 3.9.The full track trace:
Relevant package versions: