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

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

Open
Axonny opened this issue Feb 1, 2023 · 3 comments
Open

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

Axonny opened this issue Feb 1, 2023 · 3 comments

Comments

@Axonny
Copy link

Axonny commented Feb 1, 2023

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.

@sondrelg
Copy link
Member

sondrelg commented Feb 1, 2023

This seems like a prance issue, no?

@Axonny
Copy link
Author

Axonny commented Feb 2, 2023

This is probably a feature of prance that you haven't considered. 'basePath' is your parameter and its default value doesn't work on Windows. If you think prance is the problem, create a new issue!

@sondrelg
Copy link
Member

sondrelg commented Feb 2, 2023

It's been a while since I've used this package myself, and I don't have the capacity to fix this in the short term. PRs are welcome 👍

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

No branches or pull requests

2 participants