34
34
API_ROOT = settings .V3_API_ROOT_NO_FRONT_SLASH
35
35
if settings .API_ROOT_REWRITE_HEADER :
36
36
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 )
37
38
else :
38
39
V3_API_ROOT = settings .V3_API_ROOT
40
+ V4_API_ROOT = settings .V4_API_ROOT
39
41
40
42
41
43
class ViewSetNode :
@@ -153,70 +155,83 @@ class PulpDefaultRouter(routers.DefaultRouter):
153
155
vs_tree .add_decendent (ViewSetNode (viewset ))
154
156
155
157
special_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" ),
158
160
path (
159
161
"orphans/cleanup/" ,
160
162
OrphansCleanupViewset .as_view (actions = {"post" : "cleanup" }),
163
+ name = "orphan-cleanup" ,
161
164
),
162
- path ("orphans/" , OrphansView .as_view ()),
165
+ path ("orphans/" , OrphansView .as_view (), name = "orphans" ),
163
166
path (
164
167
"repository_versions/" ,
165
168
ListRepositoryVersionViewSet .as_view (actions = {"get" : "list" }),
169
+ name = "repository-versions" ,
166
170
),
167
171
path (
168
172
"repositories/reclaim_space/" ,
169
173
ReclaimSpaceViewSet .as_view (actions = {"post" : "reclaim" }),
174
+ name = "reclaim" ,
170
175
),
171
176
path (
172
177
"importers/core/pulp/import-check/" ,
173
178
PulpImporterImportCheckView .as_view (),
179
+ name = "pulp-importer-import-check" ,
174
180
),
175
181
]
176
182
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" ,
196
190
),
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" ,
205
195
),
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 )
209
223
210
224
urlpatterns = [
211
- path (API_ROOT , include (special_views )),
212
225
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 )),
214
228
]
215
229
230
+
216
231
if settings .DOMAIN_ENABLED :
217
232
# Ensure Docs and Status endpoints are available within domains, but are not shown in API schema
218
233
docs_and_status_no_schema = []
219
- for p in docs_and_status :
234
+ for p in v3_docs_and_status :
220
235
221
236
@extend_schema (exclude = True )
222
237
class NoSchema (p .callback .cls ):
@@ -227,6 +242,34 @@ class NoSchema(p.callback.cls):
227
242
docs_and_status_no_schema .append (path (str (p .pattern ), view , name = name ))
228
243
urlpatterns .insert (- 1 , path (API_ROOT , include (docs_and_status_no_schema )))
229
244
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
+
230
273
if "social_django" in settings .INSTALLED_APPS :
231
274
urlpatterns .append (
232
275
path ("" , include ("social_django.urls" , namespace = settings .SOCIAL_AUTH_URL_NAMESPACE ))
@@ -239,6 +282,10 @@ class NoSchema(p.callback.cls):
239
282
for router in all_routers :
240
283
urlpatterns .append (path (API_ROOT , include (router .urls )))
241
284
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
+
242
289
# If plugins define a urls.py, include them into the root namespace.
243
290
for plugin_pattern in plugin_patterns :
244
291
urlpatterns .append (path ("" , include (plugin_pattern )))
0 commit comments