@@ -267,11 +267,17 @@ def __get__(self, instance, owner):
267
267
self .view = instance
268
268
return self
269
269
270
- def get_link (self , path , method , generator ):
270
+ def get_link (self , path , method , base_url ):
271
271
"""
272
272
Generate `coreapi.Link` for self.view, path and method.
273
273
274
274
This is the main _public_ access point.
275
+
276
+ Parameters:
277
+
278
+ * path: Route path for view from URLConf.
279
+ * method: The HTTP request method.
280
+ * base_url: The project "mount point" as given to SchemaGenerator
275
281
"""
276
282
# TODO: make `view` a property: move this check to getter.
277
283
assert self .view is not None , "Schema generation REQUIRES a view instance. (Hint: you accessed `schema` from the view CLASS rather than an instance.)"
@@ -289,11 +295,11 @@ def get_link(self, path, method, generator):
289
295
290
296
description = self .get_description (path , method )
291
297
292
- if generator . url and path .startswith ('/' ):
298
+ if base_url and path .startswith ('/' ):
293
299
path = path [1 :]
294
300
295
301
return coreapi .Link (
296
- url = urlparse .urljoin (generator . url , path ),
302
+ url = urlparse .urljoin (base_url , path ),
297
303
action = method .lower (),
298
304
encoding = encoding ,
299
305
fields = fields ,
@@ -481,6 +487,7 @@ def get_encoding(self, path, method):
481
487
# - We import APIView here. So we can't import the descriptor into `views`
482
488
# - APIView is only used by SchemaView.
483
489
# - ???: Make `schemas` a package and move SchemaView to `schema.views`
490
+ # - That way the schema attribute could be set in the class definition.
484
491
APIView .schema = APIViewSchemaDescriptor ()
485
492
486
493
@@ -569,7 +576,7 @@ def get_links(self, request=None):
569
576
for path , method , view in view_endpoints :
570
577
if not self .has_view_permissions (path , method , view ):
571
578
continue
572
- link = view .schema .get_link (path , method , self )
579
+ link = view .schema .get_link (path , method , base_url = self . url )
573
580
subpath = path [len (prefix ):]
574
581
keys = self .get_keys (subpath , method , view )
575
582
insert_into (links , keys , link )
0 commit comments