I have an application that uses AcceptHeaderVersioning in production but it has been migrated from no versioning at all.
In order to not break existing clients, we have the following REST_FRAMEWORK settings:
'DEFAULT_VERSION': '1',
'ALLOWED_VERSIONS': ('1', '2'),
Some endpoints are available in version 1 and 2 and some are only available in version 1 (or no version given) and if the client always sends version 2, it will receive version 1 for endpoints that only support version 1. (And yes, since you'll be asking, the plan is to migrate those version 1 views directly to version 3 in case we want to change them... So each client expects "their" api version.)
I've tried to migrate that application from drf-yasg to drf-spectacular, since we already use JSONSchema for some views so support for openapi 3 would be a definite win for us. (Our JSON Schemata are even displayed in the swagger ui with drf-spectacular, but at the end of the page, and not at all in redoc... I think some other issue points that out as well.)
Unfortunately setting DEFAULT_VERSION is not compatible with the fix for #637, as the OP has pointed out.
Since giving an Accept Header is pretty inconvient in the browser (in redoc as well as the browsable DRF API), we have a custom versioning class that accepts QueryParameterVersioning as well as AcceptHeaderVersioning although the latter is required in production. This just works in drf_yasg (although we had problems customising the documentation for other parts of the api which may be easier in drf-spectacular).
If I disable the custom class and just use AcceptHeaderVersioning, I can generate the correct schema for each version on the command line and in the schema view, if I monkey-patch modify_media_types_for_versioning to change the media type for the default version as well, however it's not clear to me how to switch versions in swagger or redoc. (But maybe I simply overlooked something.)
Also probably being able to override a workflow method on a subclass would be a cleaner approach than having to monkey patch a function in plumbing.py.
So what are your thoughts on this?
I have an application that uses AcceptHeaderVersioning in production but it has been migrated from no versioning at all.
In order to not break existing clients, we have the following
REST_FRAMEWORKsettings:Some endpoints are available in version 1 and 2 and some are only available in version 1 (or no version given) and if the client always sends version 2, it will receive version 1 for endpoints that only support version 1. (And yes, since you'll be asking, the plan is to migrate those version 1 views directly to version 3 in case we want to change them... So each client expects "their" api version.)
I've tried to migrate that application from drf-yasg to drf-spectacular, since we already use JSONSchema for some views so support for openapi 3 would be a definite win for us. (Our JSON Schemata are even displayed in the swagger ui with drf-spectacular, but at the end of the page, and not at all in redoc... I think some other issue points that out as well.)
Unfortunately setting
DEFAULT_VERSIONis not compatible with the fix for #637, as the OP has pointed out.Since giving an Accept Header is pretty inconvient in the browser (in redoc as well as the browsable DRF API), we have a custom versioning class that accepts
QueryParameterVersioningas well asAcceptHeaderVersioningalthough the latter is required in production. This just works indrf_yasg(although we had problems customising the documentation for other parts of the api which may be easier in drf-spectacular).If I disable the custom class and just use
AcceptHeaderVersioning, I can generate the correct schema for each version on the command line and in the schema view, if I monkey-patchmodify_media_types_for_versioningto change the media type for the default version as well, however it's not clear to me how to switch versions in swagger or redoc. (But maybe I simply overlooked something.)Also probably being able to override a workflow method on a subclass would be a cleaner approach than having to monkey patch a function in
plumbing.py.So what are your thoughts on this?