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

[Q] Unversioned endpoints appearing below versioned endpoint #926

Closed
ronaldho opened this issue Jan 31, 2023 · 2 comments
Closed

[Q] Unversioned endpoints appearing below versioned endpoint #926

ronaldho opened this issue Jan 31, 2023 · 2 comments

Comments

@ronaldho
Copy link

I've addressed most of the egregious errors after importing drf-spectacular to my project. I've tried looking extensively in all the github issues (#253, #22, #367, #420) to see if I can find a solution, but I've come up empty thus far...

Potentially releveant info:

  • We use a custom regex that looks like this:
    url(r'^api/(?P<version>(v?\d\.\d+))/', include("braintest.api.urls", namespace="apiv")),

  • We also have a corresponding middleware that overrides URLPathVersioning to handle the incoming versioning in the URL. We need it as a bunch of serializers depend on a float to check versioning
    eg:

    class CustomVersioning(URLPathVersioning):
      def determine_version(self, request, *args, **kwargs):
          version = super(CustomVersioning, self).determine_version(request, *args, **kwargs) or "1.0"
          version = float(version)
          return version
    

After these two changes above, when I hit my Swagger UI at localhost/api/schema/swagger-ui/?version=1.6/ it groups all the endpoints under 1.6, and then below that, all the endpoints in their respective classes, but without versioning. I attached a screenshot below to illustrate the issue.

1 6 section
unversioned

Is this expected behaviour? I feel like all the versioned endpoints shouldn't duplicate themselves again without their versions though. Thank you in advance!

@tfranzel
Copy link
Owner

Potentially releveant info:

shouldn't be an issue given that this is all based on a supported versioning class (URLPathVersioning)

Is this expected behaviour? I feel like all the versioned endpoints shouldn't duplicate themselves again without their versions though.

I think not. There shouldn't be duplication unless you add include("braintest.api.urls",...) twice into the urlpatterns. this is the expected behavior:

no version given: unversioned endpoints
explicit version like you did or DEFAULT_VERSION: unversioned endpoints + versioned endpoints (for that version)

All the endpoints are iterated ONCE, so they should fall in one category and thats it. no duplication. at least that is the intended funtionality.

FYI: you should set SCHEMA_PATH_PREFIX so your tag/operation_id naming is nicer. This is not really fixing your problem, but definitely a cosmetic improvement.

# A regex specifying the common denominator for all operation paths. If
# SCHEMA_PATH_PREFIX is set to None, drf-spectacular will attempt to estimate
# a common prefix. Use '' to disable.
# Mainly used for tag extraction, where paths like '/api/v1/albums' with
# a SCHEMA_PATH_PREFIX regex '/api/v[0-9]' would yield the tag 'albums'.
'SCHEMA_PATH_PREFIX': None,

@tfranzel
Copy link
Owner

tfranzel commented Feb 7, 2023

closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up.

@tfranzel tfranzel closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2023
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

No branches or pull requests

2 participants