Skip to content

Commit 20cfcda

Browse files
committed
Fixed nested resources in api-python-client-doc
1 parent 0198590 commit 20cfcda

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

apiclient/discovery.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def method(self):
168168
methodName, self._developerKey, methodDesc, futureDesc)
169169

170170
setattr(method, '__doc__', 'A description of how to use this function')
171+
setattr(method, '__is_resource__', True)
171172
setattr(theclass, methodName, method)
172173

173174
for methodName, methodDesc in resources.iteritems():
@@ -328,6 +329,7 @@ def method(self):
328329
methodName, self._developerKey, methodDesc, futureDesc)
329330

330331
setattr(method, '__doc__', 'A description of how to use this function')
332+
setattr(method, '__is_resource__', True)
331333
setattr(theclass, methodName, method)
332334

333335
for methodName, methodDesc in resourceDesc['resources'].iteritems():

samples/api-python-client-doc/main.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,24 @@ class CollectionHandler(webapp.RequestHandler):
9090

9191
def get(self, service_name, version, collection):
9292
service = build(service_name, version)
93-
page = "<p><a href='/'>Home</a></p><pre>%s</pre>" % pydoc.plain(render_doc(getattr(service, collection)()))
93+
# descend the object path
94+
path = collection.split("/")
95+
if path:
96+
for method in path[:-1]:
97+
service = getattr(service, method)()
98+
method = getattr(service, path[-1])
99+
obj = method()
100+
page = "<p><a href='/'>Home</a></p><pre>%s</pre>" % pydoc.plain(render_doc(obj))
101+
102+
if hasattr(method, '__is_resource__'):
103+
collections = []
104+
for name in dir(obj):
105+
if not "_" in name and callable(getattr(obj, name)) and hasattr(getattr(obj, name), '__is_resource__'):
106+
collections.append(name)
107+
108+
for name in collections:
109+
page = re.sub('(%s) =' % name, r'<a href="/%s/%s/%s">\1</a> =' % (service_name, version, collection + "/" + name), page)
110+
94111
self.response.out.write(page)
95112

96113

@@ -99,7 +116,7 @@ def main():
99116
[
100117
(r'/', MainHandler),
101118
(r'/(\w*)/(\w*)', ServiceHandler),
102-
(r'/(\w*)/(\w*)/(\w*)', CollectionHandler),
119+
(r'/(\w*)/(\w*)/(.*)', CollectionHandler),
103120
],
104121
debug=True)
105122
util.run_wsgi_app(application)

0 commit comments

Comments
 (0)