3434 API_ROOT = settings .V3_API_ROOT_NO_FRONT_SLASH
3535if settings .API_ROOT_REWRITE_HEADER :
3636 V3_API_ROOT = settings .V3_API_ROOT .replace ("/<path:api_root>/" , settings .API_ROOT )
37+ V4_API_ROOT = settings .V4_API_ROOT .replace ("/<path:api_root>/" , settings .API_ROOT )
3738else :
3839 V3_API_ROOT = settings .V3_API_ROOT
40+ V4_API_ROOT = settings .V4_API_ROOT
3941
4042
4143class ViewSetNode :
@@ -174,45 +176,64 @@ class PulpDefaultRouter(routers.DefaultRouter):
174176 ),
175177]
176178
177- docs_and_status = [
178- path ("livez/" , LivezView .as_view ()),
179- path ("status/" , StatusView .as_view ()),
180- path (
181- "docs/api.json" ,
182- SpectacularJSONAPIView .as_view (authentication_classes = [], permission_classes = []),
183- name = "schema" ,
184- ),
185- path (
186- "docs/api.yaml" ,
187- SpectacularYAMLAPIView .as_view (authentication_classes = [], permission_classes = []),
188- name = "schema-yaml" ,
189- ),
190- path (
191- "docs/" ,
192- SpectacularRedocView .as_view (
193- authentication_classes = [],
194- permission_classes = [],
195- url = f"{ V3_API_ROOT } docs/api.json?include_html=1&pk_path=1" ,
179+
180+ def _docs_and_status (_api_root ):
181+ paths = [
182+ path (
183+ "docs/api.json" ,
184+ SpectacularJSONAPIView .as_view (authentication_classes = [], permission_classes = []),
185+ name = "schema" ,
196186 ),
197- name = "schema-redoc" ,
198- ),
199- path (
200- "swagger/" ,
201- SpectacularSwaggerView .as_view (
202- authentication_classes = [],
203- permission_classes = [],
204- url = f"{ V3_API_ROOT } docs/api.json?include_html=1&pk_path=1" ,
187+ path (
188+ "docs/api.yaml" ,
189+ SpectacularYAMLAPIView .as_view (authentication_classes = [], permission_classes = []),
190+ name = "schema-yaml" ,
205191 ),
206- name = "schema-swagger" ,
207- ),
208- ]
192+ path (
193+ "docs/" ,
194+ SpectacularRedocView .as_view (
195+ authentication_classes = [],
196+ permission_classes = [],
197+ url = f"{ _api_root } docs/api.json?include_html=1&pk_path=1" ,
198+ ),
199+ name = "schema-redoc" ,
200+ ),
201+ path (
202+ "swagger/" ,
203+ SpectacularSwaggerView .as_view (
204+ authentication_classes = [],
205+ permission_classes = [],
206+ url = f"{ _api_root } docs/api.json?include_html=1&pk_path=1" ,
207+ ),
208+ name = "schema-swagger" ,
209+ ),
210+ path ("livez/" , LivezView .as_view (), name = "livez" ),
211+ path ("status/" , StatusView .as_view (), name = "status" ),
212+ ]
213+
214+ return paths
215+
216+
217+ v3_docs_and_status = _docs_and_status (V3_API_ROOT )
218+ v4_docs_and_status = _docs_and_status (V4_API_ROOT )
209219
210220urlpatterns = [
211- path (API_ROOT , include (special_views )),
212221 path ("auth/" , include ("rest_framework.urls" )),
213- path (settings .V3_API_ROOT_NO_FRONT_SLASH , include (docs_and_status )),
222+ path (API_ROOT , include (special_views )),
223+ path (settings .V3_API_ROOT_NO_FRONT_SLASH , include (v3_docs_and_status )),
214224]
215225
226+ if settings .ENABLE_V4_API :
227+ urlpatterns .extend (
228+ [
229+ path (V4_API_ROOT , include ((special_views , "core" ), namespace = "v4" )),
230+ path (
231+ settings .V4_API_ROOT_NO_FRONT_SLASH ,
232+ include ((v4_docs_and_status , "core" ), namespace = "v4" ),
233+ ),
234+ ]
235+ )
236+
216237if settings .DOMAIN_ENABLED :
217238 # Ensure Docs and Status endpoints are available within domains, but are not shown in API schema
218239 docs_and_status_no_schema = []
@@ -239,6 +260,10 @@ class NoSchema(p.callback.cls):
239260for router in all_routers :
240261 urlpatterns .append (path (API_ROOT , include (router .urls )))
241262
263+ if settings .ENABLE_V4_API :
264+ for router in all_routers :
265+ urlpatterns .append (path (V4_API_ROOT , include ((router .urls , "core" ), namespace = "v4" )))
266+
242267# If plugins define a urls.py, include them into the root namespace.
243268for plugin_pattern in plugin_patterns :
244269 urlpatterns .append (path ("" , include (plugin_pattern )))
0 commit comments