Skip to content

Commit fbbdc38

Browse files
committed
Pass just url from SchemaGenerator to descriptor
1 parent f589c74 commit fbbdc38

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

rest_framework/schemas.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,17 @@ def __get__(self, instance, owner):
267267
self.view = instance
268268
return self
269269

270-
def get_link(self, path, method, generator):
270+
def get_link(self, path, method, base_url):
271271
"""
272272
Generate `coreapi.Link` for self.view, path and method.
273273
274274
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
275281
"""
276282
# TODO: make `view` a property: move this check to getter.
277283
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):
289295

290296
description = self.get_description(path, method)
291297

292-
if generator.url and path.startswith('/'):
298+
if base_url and path.startswith('/'):
293299
path = path[1:]
294300

295301
return coreapi.Link(
296-
url=urlparse.urljoin(generator.url, path),
302+
url=urlparse.urljoin(base_url, path),
297303
action=method.lower(),
298304
encoding=encoding,
299305
fields=fields,
@@ -481,6 +487,7 @@ def get_encoding(self, path, method):
481487
# - We import APIView here. So we can't import the descriptor into `views`
482488
# - APIView is only used by SchemaView.
483489
# - ???: Make `schemas` a package and move SchemaView to `schema.views`
490+
# - That way the schema attribute could be set in the class definition.
484491
APIView.schema = APIViewSchemaDescriptor()
485492

486493

@@ -569,7 +576,7 @@ def get_links(self, request=None):
569576
for path, method, view in view_endpoints:
570577
if not self.has_view_permissions(path, method, view):
571578
continue
572-
link = view.schema.get_link(path, method, self)
579+
link = view.schema.get_link(path, method, base_url=self.url)
573580
subpath = path[len(prefix):]
574581
keys = self.get_keys(subpath, method, view)
575582
insert_into(links, keys, link)

0 commit comments

Comments
 (0)