Drf-yasg: Generate a schema_views per version

Created on 16 May 2018  路  4Comments  路  Source: axnsan12/drf-yasg

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

question

Most helpful comment

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

All 4 comments

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.

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

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!

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.

https://github.com/axnsan12/drf-yasg/blob/ab6444a32e222a4b9df12620fc484814c165f701/src/drf_yasg/generators.py#L52-L54

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mkurnikov picture mkurnikov  路  4Comments

Safrone picture Safrone  路  3Comments

phihag picture phihag  路  5Comments

beaugunderson picture beaugunderson  路  5Comments

phihag picture phihag  路  3Comments