Skip to content
This repository was archived by the owner on Nov 19, 2023. It is now read-only.
This repository was archived by the owner on Nov 19, 2023. It is now read-only.

The default 'basePath' value doesn't work on Windows. #294

@Axonny

Description

@Axonny

I use:

  • django
  • djangorestframework
  • drf-spectacular

I'm trying to test my openapi scheme, but It's not working.
Exploring the source code, I found some problem.

If my schema does not have the basePath parameter, it takes the default value /.
Then RefResolver (from prance) calls to_posix before urlparse.

In fs.py file:

def to_posix(fname):
    """
    Convert a path to posix-like format.

    :param str fname: The filename to convert to posix format.
    :return: The filename in posix-like format.
    :rtype: str
    """
    import sys

    if sys.platform == "win32":  # pragma: nocover
        import os.path

        if os.path.isabs(fname):
            fname = "/" + fname
        fname = fname.replace("\\", "/")
    return fname

If you call to_posix("/") on Windows, it will return "//".
Then urlparse will not be able to parse this value. And... this happened:
prance.util.url.ResolutionError: Cannot build an absolute file URL from a fragment without a reference with path!

As a temporary solution I use:

@pytest.fixture
def open_api_client(schema_tester):
    with patch("prance.util.fs.from_posix", wraps=lambda x: x):
        with patch("prance.util.fs.to_posix", wraps=lambda x: x):
            client = OpenAPIClient(schema_tester=schema_tester)
            yield client

But it can lead to other errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions