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

Get versioned schema ui #71

Closed
MissiaL opened this issue May 29, 2020 · 9 comments
Closed

Get versioned schema ui #71

MissiaL opened this issue May 29, 2020 · 9 comments
Assignees

Comments

@MissiaL
Copy link
Contributor

MissiaL commented May 29, 2020

I have several versioned schemas. How can I get schema-ui views for each version?

@tfranzel
Copy link
Owner

that is i think the only thing that the tests do not explicitly cover. congratulations on finding the hole 😄

it should be possible though. the SpectacularAPIView honors the same versioning as the regular views (based on the request and the default versioning class). have you tested this?

urlpatterns = [
    re_path(r'^(?P<version>[v1|v2]+)/schema', SpectacularAPIView.as_view(), name='schema')),
    re_path(r'^(?P<version>[v1|v2]+)/schema/swagger', SpectacularSwaggerView.as_view(url_name='schema'))
]

otherwise you could always do it explicitly with

path('api/v2/schema/', SpectacularAPIView.as_view(api_version='v2'), name='schema_v2'),
path('api/v2/schema/swagger', SpectacularSwaggerView.as_view(url_name='schema_v2'))

i believe the first one works. the second definitely works.

@tfranzel
Copy link
Owner

correction. the first one cannot work. its needs to be explicit as in the second example i'm afraid. at least currently.

@MissiaL
Copy link
Contributor Author

MissiaL commented May 30, 2020

Yes. You right
But I think we can update base template, which will proxifying request version
@tsouvarev What do you think about it?

@tsouvarev
Copy link
Contributor

tsouvarev commented May 31, 2020

What if we move reverse of URL for scheme to view from template? It will allow you to add version to args of reverse easily via subclassing. Template will be the same for versioned and unversioned UIs.

Another approach is to make scheme URL relative to UI URL. But it will require to change current template too.

@tfranzel
Copy link
Owner

i think its a reasonable addition to make that work. the idea for implementation does go in the right direction. on first glace i saw that the TemplateView is coming from Django, which means there are no DRF versioning mechanics present. its true that the template is agnostic of the versioning, but the enclosing view has to deal with that fact. so this might have to be solved differently. would have to investigate further.

tfranzel added a commit that referenced this issue May 31, 2020
@tfranzel
Copy link
Owner

that should do it. was easier than expected. could have been even easier without that DRF "bug".

I discovered that DRF has its own reverse() that honors versioning. unfortunately, DRF's TemplateHTMLRenderer does not use it though. 😕 had to call it explicitly.

that should fix this for all supported versioning types. close the issue if it works as expected.

@tfranzel
Copy link
Owner

tfranzel commented Jun 2, 2020

@MissiaL could you check if that works for you?

@MissiaL
Copy link
Contributor Author

MissiaL commented Jun 2, 2020

Yes. I will check

@MissiaL
Copy link
Contributor Author

MissiaL commented Jun 5, 2020

It works! Thanks!

@MissiaL MissiaL closed this as completed Jun 5, 2020
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

3 participants