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 :
@@ -174,45 +176,57 @@ class PulpDefaultRouter(routers.DefaultRouter):
174
176
),
175
177
]
176
178
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
+ def _docs_and_status (_api_root ):
180
+ paths = [
181
+ path (
182
+ "docs/api.json" ,
183
+ SpectacularJSONAPIView .as_view (authentication_classes = [], permission_classes = []),
184
+ name = "schema" ,
196
185
),
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" ,
186
+ path (
187
+ "docs/api.yaml" ,
188
+ SpectacularYAMLAPIView .as_view (authentication_classes = [], permission_classes = []),
189
+ name = "schema-yaml" ,
205
190
),
206
- name = "schema-swagger" ,
207
- ),
208
- ]
191
+ path (
192
+ "docs/" ,
193
+ SpectacularRedocView .as_view (
194
+ authentication_classes = [],
195
+ permission_classes = [],
196
+ url = f"{ _api_root } docs/api.json?include_html=1&pk_path=1" ,
197
+ ),
198
+ name = "schema-redoc" ,
199
+ ),
200
+ path (
201
+ "swagger/" ,
202
+ SpectacularSwaggerView .as_view (
203
+ authentication_classes = [],
204
+ permission_classes = [],
205
+ url = f"{ _api_root } docs/api.json?include_html=1&pk_path=1" ,
206
+ ),
207
+ name = "schema-swagger" ,
208
+ ),
209
+ path ("livez/" , LivezView .as_view (), name = "livez" ),
210
+ path ("status/" , StatusView .as_view (), name = "status" ),
211
+ ]
212
+
213
+ return paths
214
+
215
+ v3_docs_and_status = _docs_and_status (V3_API_ROOT )
216
+ v4_docs_and_status = _docs_and_status (V4_API_ROOT )
209
217
210
218
urlpatterns = [
211
- path (API_ROOT , include (special_views )),
212
219
path ("auth/" , include ("rest_framework.urls" )),
213
- path (settings .V3_API_ROOT_NO_FRONT_SLASH , include (docs_and_status )),
220
+ path (API_ROOT , include (special_views )),
221
+ path (settings .V3_API_ROOT_NO_FRONT_SLASH , include (v3_docs_and_status )),
214
222
]
215
223
224
+ if settings .ENABLE_V4_API :
225
+ urlpatterns .extend ([
226
+ path (V4_API_ROOT , include ((special_views , "core" ), namespace = "v4" )),
227
+ path (settings .V4_API_ROOT_NO_FRONT_SLASH , include ((v4_docs_and_status , "core" ), namespace = "v4" )),
228
+ ])
229
+
216
230
if settings .DOMAIN_ENABLED :
217
231
# Ensure Docs and Status endpoints are available within domains, but are not shown in API schema
218
232
docs_and_status_no_schema = []
@@ -239,6 +253,10 @@ class NoSchema(p.callback.cls):
239
253
for router in all_routers :
240
254
urlpatterns .append (path (API_ROOT , include (router .urls )))
241
255
256
+ if settings .ENABLE_V4_API :
257
+ for router in all_routers :
258
+ urlpatterns .append (path (V4_API_ROOT , include ((router .urls , "core" ), namespace = "v4" )))
259
+
242
260
# If plugins define a urls.py, include them into the root namespace.
243
261
for plugin_pattern in plugin_patterns :
244
262
urlpatterns .append (path ("" , include (plugin_pattern )))
0 commit comments