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 :
@@ -153,70 +155,83 @@ class PulpDefaultRouter(routers.DefaultRouter):
153155 vs_tree .add_decendent (ViewSetNode (viewset ))
154156
155157special_views = [
156- path ("login/" , LoginViewSet .as_view ()),
157- path ("repair/" , RepairView .as_view ()),
158+ path ("login/" , LoginViewSet .as_view (), name = "login" ),
159+ path ("repair/" , RepairView .as_view (), name = "repair" ),
158160 path (
159161 "orphans/cleanup/" ,
160162 OrphansCleanupViewset .as_view (actions = {"post" : "cleanup" }),
163+ name = "orphan-cleanup" ,
161164 ),
162- path ("orphans/" , OrphansView .as_view ()),
165+ path ("orphans/" , OrphansView .as_view (), name = "orphans" ),
163166 path (
164167 "repository_versions/" ,
165168 ListRepositoryVersionViewSet .as_view (actions = {"get" : "list" }),
169+ name = "repository-versions" ,
166170 ),
167171 path (
168172 "repositories/reclaim_space/" ,
169173 ReclaimSpaceViewSet .as_view (actions = {"post" : "reclaim" }),
174+ name = "reclaim" ,
170175 ),
171176 path (
172177 "importers/core/pulp/import-check/" ,
173178 PulpImporterImportCheckView .as_view (),
179+ name = "pulp-importer-import-check" ,
174180 ),
175181]
176182
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" ,
183+
184+ def _docs_and_status (_api_root ):
185+ paths = [
186+ path (
187+ "docs/api.json" ,
188+ SpectacularJSONAPIView .as_view (authentication_classes = [], permission_classes = []),
189+ name = "schema" ,
196190 ),
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" ,
191+ path (
192+ "docs/api.yaml" ,
193+ SpectacularYAMLAPIView .as_view (authentication_classes = [], permission_classes = []),
194+ name = "schema-yaml" ,
205195 ),
206- name = "schema-swagger" ,
207- ),
208- ]
196+ path (
197+ "docs/" ,
198+ SpectacularRedocView .as_view (
199+ authentication_classes = [],
200+ permission_classes = [],
201+ url = f"{ _api_root } docs/api.json?include_html=1&pk_path=1" ,
202+ ),
203+ name = "schema-redoc" ,
204+ ),
205+ path (
206+ "swagger/" ,
207+ SpectacularSwaggerView .as_view (
208+ authentication_classes = [],
209+ permission_classes = [],
210+ url = f"{ _api_root } docs/api.json?include_html=1&pk_path=1" ,
211+ ),
212+ name = "schema-swagger" ,
213+ ),
214+ path ("livez/" , LivezView .as_view (), name = "livez" ),
215+ path ("status/" , StatusView .as_view (), name = "status" ),
216+ ]
217+
218+ return paths
219+
220+
221+ v3_docs_and_status = _docs_and_status (V3_API_ROOT )
222+ v4_docs_and_status = _docs_and_status (V4_API_ROOT )
209223
210224urlpatterns = [
211- path (API_ROOT , include (special_views )),
212225 path ("auth/" , include ("rest_framework.urls" )),
213- path (settings .V3_API_ROOT_NO_FRONT_SLASH , include (docs_and_status )),
226+ path (API_ROOT , include (special_views )),
227+ path (settings .V3_API_ROOT_NO_FRONT_SLASH , include (v3_docs_and_status )),
214228]
215229
230+
216231if settings .DOMAIN_ENABLED :
217232 # Ensure Docs and Status endpoints are available within domains, but are not shown in API schema
218233 docs_and_status_no_schema = []
219- for p in docs_and_status :
234+ for p in v3_docs_and_status :
220235
221236 @extend_schema (exclude = True )
222237 class NoSchema (p .callback .cls ):
@@ -227,6 +242,34 @@ class NoSchema(p.callback.cls):
227242 docs_and_status_no_schema .append (path (str (p .pattern ), view , name = name ))
228243 urlpatterns .insert (- 1 , path (API_ROOT , include (docs_and_status_no_schema )))
229244
245+
246+ if settings .ENABLE_V4_API :
247+ urlpatterns .extend (
248+ [
249+ path (V4_API_ROOT , include ((special_views , "core" ), namespace = "v4" )),
250+ path (
251+ settings .V4_API_ROOT_NO_FRONT_SLASH ,
252+ include ((v4_docs_and_status , "core" ), namespace = "v4" ),
253+ ),
254+ ]
255+ )
256+
257+
258+ if settings .DOMAIN_ENABLED :
259+ # Ensure Docs and Status endpoints are available within domains, but are not shown in API schema
260+ docs_and_status_no_schema = []
261+ for p in v4_docs_and_status :
262+
263+ @extend_schema (exclude = True )
264+ class NoSchema (p .callback .cls ):
265+ pass
266+
267+ view = NoSchema .as_view (** p .callback .initkwargs )
268+ name = p .name + "-domains" if p .name else None
269+ docs_and_status_no_schema .append (path (str (p .pattern ), view , name = name ))
270+ urlpatterns .insert (- 1 , path (API_ROOT , include (docs_and_status_no_schema )))
271+
272+
230273if "social_django" in settings .INSTALLED_APPS :
231274 urlpatterns .append (
232275 path ("" , include ("social_django.urls" , namespace = settings .SOCIAL_AUTH_URL_NAMESPACE ))
@@ -239,6 +282,10 @@ class NoSchema(p.callback.cls):
239282for router in all_routers :
240283 urlpatterns .append (path (API_ROOT , include (router .urls )))
241284
285+ if settings .ENABLE_V4_API :
286+ for router in all_routers :
287+ urlpatterns .append (path (V4_API_ROOT , include ((router .urls , "core" ), namespace = "v4" )))
288+
242289# If plugins define a urls.py, include them into the root namespace.
243290for plugin_pattern in plugin_patterns :
244291 urlpatterns .append (path ("" , include (plugin_pattern )))
0 commit comments