mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Pass the the "title" attribute from each view when constructing Link instances.
This is part of a proposed solution to core-api/python-openapi-codec#28
This commit is contained in:
parent
2a1fd3b45a
commit
57eae7b315
|
@ -454,7 +454,10 @@ class SchemaGenerator(object):
|
||||||
if self.url and path.startswith('/'):
|
if self.url and path.startswith('/'):
|
||||||
path = path[1:]
|
path = path[1:]
|
||||||
|
|
||||||
|
title = self.get_title(view)
|
||||||
|
|
||||||
return coreapi.Link(
|
return coreapi.Link(
|
||||||
|
title=title,
|
||||||
url=urlparse.urljoin(self.url, path),
|
url=urlparse.urljoin(self.url, path),
|
||||||
action=method.lower(),
|
action=method.lower(),
|
||||||
encoding=encoding,
|
encoding=encoding,
|
||||||
|
@ -462,6 +465,18 @@ class SchemaGenerator(object):
|
||||||
description=description
|
description=description
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_title(self, view):
|
||||||
|
"""
|
||||||
|
Determine a title from a view instance.
|
||||||
|
|
||||||
|
If the 'title' attribute is not set on the view, then an empty title is returned.
|
||||||
|
"""
|
||||||
|
title = ""
|
||||||
|
if hasattr(view, "title"):
|
||||||
|
title = view.title
|
||||||
|
|
||||||
|
return title
|
||||||
|
|
||||||
def get_description(self, path, method, view):
|
def get_description(self, path, method, view):
|
||||||
"""
|
"""
|
||||||
Determine a link description.
|
Determine a link description.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user