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

connexion does not parse simple reference links #967

Closed
larsks opened this issue May 30, 2019 · 13 comments · Fixed by #1648
Closed

connexion does not parse simple reference links #967

larsks opened this issue May 30, 2019 · 13 comments · Fixed by #1648

Comments

@larsks
Copy link

larsks commented May 30, 2019

Description

My OpenAPI 3.0.0 specification contains entries that look like this:

$ref: 'models/provider.yaml#/components/schemas/Provider'

This is "remote reference" as documented in the OpenAPI documentation.

Expected behaviour

I expect connexion to resolve the link and read the specified content from the specified file.

Actual behaviour

A positively ungodly traceback:

>>> app.add_api('api-marketplace.yaml')
Traceback (most recent call last):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 380, in resolve_from_url
    document = self.store[url]
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_utils.py", line 23, in __getitem__
    return self.store[self.normalize(uri)]
KeyError: 'models/provider.yaml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 383, in resolve_from_url
    document = self.resolve_remote(url)
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 474, in resolve_remote
    result = json.loads(urlopen(uri).read().decode("utf-8"))
  File "/usr/lib64/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python3.7/urllib/request.py", line 510, in open
    req = Request(fullurl, data)
  File "/usr/lib64/python3.7/urllib/request.py", line 328, in __init__
    self.full_url = url
  File "/usr/lib64/python3.7/urllib/request.py", line 354, in full_url
    self._parse()
  File "/usr/lib64/python3.7/urllib/request.py", line 383, in _parse
    raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: 'models/provider.yaml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lars/.local/lib/python3.7/site-packages/connexion/apps/flask_app.py", line 54, in add_api
    api = super(FlaskApp, self).add_api(specification, **kwargs)
  File "/home/lars/.local/lib/python3.7/site-packages/connexion/apps/abstract.py", line 155, in add_api
    options=api_options.as_dict())
  File "/home/lars/.local/lib/python3.7/site-packages/connexion/apis/abstract.py", line 73, in __init__
    self.specification = Specification.load(specification, arguments=arguments)
  File "/home/lars/.local/lib/python3.7/site-packages/connexion/spec.py", line 151, in load
    return cls.from_file(spec, arguments=arguments)
  File "/home/lars/.local/lib/python3.7/site-packages/connexion/spec.py", line 108, in from_file
    return cls.from_dict(spec)
  File "/home/lars/.local/lib/python3.7/site-packages/connexion/spec.py", line 146, in from_dict
    return OpenAPISpecification(spec)
  File "/home/lars/.local/lib/python3.7/site-packages/connexion/spec.py", line 39, in __init__
    self._validate_spec(raw_spec)
  File "/home/lars/.local/lib/python3.7/site-packages/connexion/spec.py", line 230, in _validate_spec
    validate_spec(spec)
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/shortcuts.py", line 7, in validate
    return validator_callable(spec, spec_url=spec_url)
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/validators.py", line 47, in validate
    for err in self.iter_errors(spec, spec_url=spec_url):
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 58, in wrapper
    for err in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/validators.py", line 56, in iter_errors
    for err in validator.iter_errors(spec):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 304, in properties_draft4
    schema_path=property,
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 216, in ref
    for error in validator.descend(instance, resolved):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 16, in patternProperties
    v, subschema, path=k, schema_path=pattern,
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 216, in ref
    for error in validator.descend(instance, resolved):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 304, in properties_draft4
    schema_path=property,
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 216, in ref
    for error in validator.descend(instance, resolved):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 304, in properties_draft4
    schema_path=property,
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 216, in ref
    for error in validator.descend(instance, resolved):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 16, in patternProperties
    v, subschema, path=k, schema_path=pattern,
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 216, in ref
    for error in validator.descend(instance, resolved):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 341, in oneOf_draft4
    errs = list(validator.descend(instance, subschema, schema_path=index))
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 216, in ref
    for error in validator.descend(instance, resolved):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 304, in properties_draft4
    schema_path=property,
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 216, in ref
    for error in validator.descend(instance, resolved):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 29, in additionalProperties
    for error in validator.descend(instance[extra], aP, path=extra):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 216, in ref
    for error in validator.descend(instance, resolved):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 22, in wrapped
    for res in func(validator, schema_element, instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/_validators.py", line 304, in properties_draft4
    schema_path=property,
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 121, in descend
    for error in self.iter_errors(instance, schema):
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 105, in iter_errors
    for error in errors:
  File "/home/lars/.local/lib/python3.7/site-packages/openapi_spec_validator/decorators.py", line 34, in wrapped
    with self.instance_resolver.resolving(ref) as target:
  File "/usr/lib64/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 366, in resolving
    url, resolved = self.resolve(ref)
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 375, in resolve
    return url, self._remote_cache(url)
  File "/home/lars/.local/lib/python3.7/site-packages/jsonschema/validators.py", line 385, in resolve_from_url
    raise RefResolutionError(exc)
jsonschema.exceptions.RefResolutionError: unknown url type: 'models/provider.yaml'

Additional info:

Output of the commands:

  • python --version: Python 3.7.3
  • pip show connexion | grep "^Version\:": Version: 2.2.0 (although this was in fact installed from 0a05243)
@jmitchellwf
Copy link

I have the exact same issue when trying to reference a yaml file that is in the same location as the current file. Is there any solution or workaround to this?

             schema:
                type: array
                items:
                  $ref: 'components.yaml#/components/schemas/Warehouse'
service_1            | 2020-01-22 14:05:38 [11] [DEBUG] connexion.apis.abstract Loading specification: /app/wms_automation_platform/services/specifications/api.yaml
service_1            | 2020-01-22 14:05:38 [12] [DEBUG] openapi_spec_validator.decorators Attaching x-scope to {'$ref': 'components.yaml#/components/schemas/Warehouse'}
service_1            | [2020-01-22 14:05:38 +0000] [12] [ERROR] Exception in worker process
service_1            | Traceback (most recent call last):
service_1            |   File "/pyenv/versions/wms-automation-platform/lib/python3.8/site-packages/jsonschema/validators.py", line 380, in resolve_from_url
service_1            |     document = self.store[url]
service_1            |   File "/pyenv/versions/wms-automation-platform/lib/python3.8/site-packages/jsonschema/_utils.py", line 23, in __getitem__
service_1            |     return self.store[self.normalize(uri)]
service_1            | KeyError: 'components.yaml'

@jmitchellwf
Copy link

If I prefix the URI with file: it gets closer

              schema:
                type: array
                items:
                  $ref: 'file:components.yaml#/components/schemas/Warehouse'
service_1            | 2020-01-22 14:19:52 [11] [DEBUG] connexion.apis.abstract Loading specification: /app/wms_automation_platform/services/specifications/api.yaml
service_1            | 2020-01-22 14:19:53 [10] [DEBUG] openapi_spec_validator.decorators Attaching x-scope to {'$ref': 'file:components.yaml#/components/schemas/Warehouse'}
service_1            | [2020-01-22 14:19:53 +0000] [10] [ERROR] Exception in worker process
service_1            | Traceback (most recent call last):
service_1            |   File "/pyenv/versions/wms-automation-platform/lib/python3.8/site-packages/jsonschema/validators.py", line 380, in resolve_from_url
service_1            |     document = self.store[url]
service_1            |   File "/pyenv/versions/wms-automation-platform/lib/python3.8/site-packages/jsonschema/_utils.py", line 23, in __getitem__
service_1            |     return self.store[self.normalize(uri)]
service_1            | KeyError: 'file:///components.yaml'
service_1            |
service_1            | During handling of the above exception, another exception occurred:
service_1            |
service_1            | Traceback (most recent call last):
service_1            |   File "/pyenv/versions/3.8.0/lib/python3.8/urllib/request.py", line 1474, in open_local_file
service_1            |     stats = os.stat(localfile)
service_1            | FileNotFoundError: [Errno 2] No such file or directory: '/components.yaml'

@adwhit
Copy link

adwhit commented Jul 7, 2020

This can be forced to work with

schema:
  type: array
  items:
    $ref: 'file:///full/path/to/the/components.yaml#/components/schemas/Warehouse'

But that is not really going to work on a server

@klorenz
Copy link

klorenz commented Jul 23, 2020

Hi all,

I could work around this issue by specifing handlers for "no scheme" as illustrated below (in my app.py):

# -------------------- workaround begin

# these handlers are used in RefResolver.resolve_remote()
from connexion.json_schema import default_handlers as json_schema_handlers
from openapi_spec_validator import default_handlers as spec_validator_handlers

# jsonschema does not handle relative file paths:
#  https://github.com/zalando/connexion/issues/967

#default_file_handler = default_handlers['file']
SPECIFICATION_DIR = dirname(__file__)

def my_local_file_handler(uri):
    '''return the parsed result'''
    import yaml
    with open(join(SPECIFICATION_DIR, uri), 'r') as f:
        return yaml.load(f, Loader=yaml.SafeLoader)

json_schema_handlers[''] = my_local_file_handler
spec_validator_handlers[''] = my_local_file_handler

# patch refresolver-bug: (does not handle relative refs correct in path scopes)
from jsonschema.validators import RefResolver

def myresolve(self, ref):
    url = self._urljoin_cache(self.resolution_scope, ref)
    return ref, self._remote_cache(url)

RefResolver.resolve = myresolve


# -------------------- workaround end

# ... later:
connexion_app = connexion.App("appname", specification_dir=SPECIFICATION_DIR)
api = connexion_app.add_api("OpenApi.yml")

when referring then a relative file like:

    $ref: 'securitySchemes.yml#/ApiKey'

it will open the local file as expected.

@klorenz
Copy link

klorenz commented Jul 24, 2020

If you want to use refs also in files, you have also to patch resolve_refs function from connexion.json_schema, because it does not resolve refs recursively. Actually it is only about changing:

    return resolved

to:

     return _do_resolve(resolved)

Here complete patch code:

from copy import deepcopy
from jsonschema import RefResolver
from connexion.utils import deep_get

try:
    from collections.abc import Mapping
except ImportError:
    from collections import Mapping

def my_resolve_refs(spec, store=None, handlers=None):
    """
    Resolve JSON references like {"$ref": <some URI>} in a spec.
    Optionally takes a store, which is a mapping from reference URLs to a
    dereferenced objects. Prepopulating the store can avoid network calls.
    """
    from connexion.json_schema import default_handlers
    spec = deepcopy(spec)
    store = store or {}
    handlers = handlers or default_handlers
    resolver = RefResolver('', spec, store, handlers=handlers)

    def _do_resolve(node):
        if isinstance(node, Mapping) and '$ref' in node:
            path = node['$ref'][2:].split("/")
            try:
                # resolve known references
                node.update(deep_get(spec, path))
                del node['$ref']
                return node
            except KeyError:
                # resolve external references
                with resolver.resolving(node['$ref']) as resolved:
                    # if not fixed:
                    #     return resolved
                    # else:
                    return _do_resolve(resolved)
                    # endfix
        elif isinstance(node, Mapping):
            for k, v in node.items():
                node[k] = _do_resolve(v)
        elif isinstance(node, (list, tuple)):
            for i, _ in enumerate(node):
                node[i] = _do_resolve(node[i])
        return node

    res = _do_resolve(spec)
    return res

from connexion import spec
spec.resolve_refs = my_resolve_refs

@n4rk0o
Copy link

n4rk0o commented Jun 8, 2021

Hello,

Any news on this issue? I'm interested in because we have huge YML file and we want to split it.

@brianthelion
Copy link

brianthelion commented Dec 21, 2021

I am on v2.9.0. It appears that @klorenz patch was adopted at some point, because it's now in the source.

If you want to use relative URLs without prefixing file:// (good portability), there are still a couple of issues you have to work around. Fortunately you can monkeypatch as follows:

import os
import pytest
import jsonschema
import openapi_spec_validator as oapi
import openapi_spec_validator.readers as oapi_readers

def _run(path):

    path = os.path.abspath(path)

    def _validate_spec(cls, spec):
        spec_dict, spec_url = oapi_readers.read_from_filename(path)
        oapi.openapi_v3_spec_validator.validate(spec, spec_url)

    class _RefResolver(jsonschema.RefResolver):
        def __init__(self, base_url, *args, **kwargs):
            if len(base_url) == 0:
                base_url = f"file:///{path}"
            super().__init__(base_url, *args, **kwargs)

    with pytest.MonkeyPatch().context() as m:
        m.setattr("connexion.spec.OpenAPISpecification._validate_spec", _validate_spec)
        m.setattr("connexion.json_schema.RefResolver", _RefResolver)
        from connexion.cli import run
        return run([path])

@MiltiadisKoutsokeras
Copy link

MiltiadisKoutsokeras commented Mar 28, 2022

Hi all,

It seems this issue persists in latest version. Looking at the code in connexion/json_schema.py we can see that the logic is not performed recursively when KeyError is thrown:

def resolve_refs(spec, store=None, handlers=None):
    """
    Resolve JSON references like {"$ref": <some URI>} in a spec.
    Optionally takes a store, which is a mapping from reference URLs to a
    dereferenced objects. Prepopulating the store can avoid network calls.
    """
    spec = deepcopy(spec)
    store = store or {}
    handlers = handlers or default_handlers
    resolver = RefResolver('', spec, store, handlers=handlers)

    def _do_resolve(node):
        if isinstance(node, Mapping) and '$ref' in node:
            path = node['$ref'][2:].split("/")
            try:
                # resolve known references
                node.update(deep_get(spec, path))
                del node['$ref']
                return node
            except KeyError:
                # resolve external references
                with resolver.resolving(node['$ref']) as resolved:
                    return resolved
        elif isinstance(node, Mapping):
            for k, v in node.items():
                node[k] = _do_resolve(v)
        elif isinstance(node, (list, tuple)):
            for i, _ in enumerate(node):
                node[i] = _do_resolve(node[i])
        return node

    res = _do_resolve(spec)
    return res

So in order to keep your OpenAPI specs in different files, you are obliged to perform some kind of hacking.

@rjkooijman
Copy link

rjkooijman commented Jun 22, 2022

I still experience this issue.

a.yaml:
test: type: string
b.yaml:
test2: $ref: 'test1.yaml#/test'

I keep getting the same exception as the issue starter.

unknown url type: 'test.yaml'

Should this be fixed by now and am I doing something wrong with my referencing or is this still not supported? Would be a bummer if this isn't supported.

version: 2.13.1

@trstickland
Copy link

I have had partial success.

I have to use the file:// prefix, and always to specify the full path to the file I am referencing.

So if the full path to your file was /foo/bar/test.yaml...

$ref: file:///foo/bar/test.yaml#/test

Note there are 3 slashes after file:.

When I say "partial" success, I cannot use a reference to an example. Also, a small number of other references just won't work (I still haven't figured out what the problem was -- if I can identify anything in common to the ones that fail, I'll post it here), though I was lucky that I could slightly tweak my spec. to work around it.

@meiswjn
Copy link

meiswjn commented Jan 25, 2023

This still only appears to work with FULL paths. This makes it very unpractical to use in a deployment scenario, since you must know the file system full path to your specification...

@brianthelion
Copy link

@meiswjn See my workaround above.

RobbeSneyders added a commit that referenced this issue Feb 22, 2023
Fixes #254 
Fixes #967 

This PR fixes the very long-standing issue of being able to handle
relative references, which allows users to split their specification
into multiple files.
@maddin1991
Copy link

Im still getting an error when i have a simple ref referencing a local file like this:

"$ref": "schemas.json#/components/schemas/ExperimentItem"

The error is _RefResolutionError: [Errno 2] No such file or directory: '\\\\\\schemas.json'

I thought it should be fixed with #1648?

connexion version: 3.0.5
python version: 3.11.3

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

Successfully merging a pull request may close this issue.