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

Generate a schema_views per version #126

Closed
Amoki opened this issue May 16, 2018 · 4 comments
Closed

Generate a schema_views per version #126

Amoki opened this issue May 16, 2018 · 4 comments

Comments

@Amoki
Copy link
Contributor

Amoki commented May 16, 2018

Is there a way to limit a schema_view to a version ? In order to generate a v1.json and a v2.json.
Using patterns in get_schema_view() seems really complicated for this use case.

If there is currently no way to do that, I'm able to spent some time in the implementation :D

@axnsan12
Copy link
Owner

axnsan12 commented May 16, 2018

Which kind of versions are you referring to? If you are talking about Django Rest Framework versioning, in theory the schema_view will adapt itself based on the API version you are accesing it with.

e.g. with URLPathVersioning, and a schema_view used like so

url(r'^(?P<version>v1|v2)/swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=None), name='schema-json'),

, /v1/swagger.json and /v2/swagger.json should both include only their respective endpoints.

Please clarify if I'm not correctly understanding your issue.

@Amoki
Copy link
Contributor Author

Amoki commented May 17, 2018

This is exactly what I want!
I'm using NamespaceVersioning so it's totally implicit (when REST Framework is correctly configured...).
Dunno why, but I thought I had something to do... This lib is really awesome :D

@paunovic
Copy link

paunovic commented Jun 17, 2019

hey @axnsan12 I am trying to also do this, however we use custom versioning implementation (not URLPathVersioning), where our views inherit from APIVersionMixin custom class which has version and versions attributes. Do you know if it's possible? Let me know if you need more information.

I have tried advice above, but it generates same schema for both versions that we have in our app. By the looks of it, we need to implement some of the attributes that URLPathVersioning has, in our custom API versioning class, to make it compatible with drf-yasg? Thanks!

@neilfrndes
Copy link

neilfrndes commented Aug 29, 2019

I tried implementing different schemas for different versions. However, I was unsuccessful. After investigating drf_yasg code for a couple of hours, it looks like this particular snippet is the problem.

if versioning_class is not None and issubclass(versioning_class, versioning.NamespaceVersioning):
if version and version not in namespace.split(':'):
return False

the should_include_endpoint function always returns False because the namespace argument is None even when every URL has a namespace.

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

4 participants