Commit 1dd55d1b authored by M. de Verteuil's avatar M. de Verteuil
Browse files

Filter resources before trying to determine which are top-level.

By filtering before trying to determine the top-level resources, empty top-level
resources will be correctly ignored.
parent 0fd91e62
......@@ -100,14 +100,7 @@ class SwaggerResourcesView(APIDocView):
renderer_classes = (JSONRenderer, )
def get(self, request):
apis = []
resources = [resource for resource in self.get_resources()
if self.handle_resource_access(request, resource)]
for path in resources:
apis.append({'path': '/%s' % path, })
apis = [{'path': '/' + path} for path in self.get_resources()]
return Response({
'apiVersion': rfs.SWAGGER_SETTINGS.get('api_version', ''),
'swaggerVersion': '1.2',
......@@ -136,11 +129,10 @@ class SwaggerResourcesView(APIDocView):
def get_resources(self):
urlparser = UrlParser()
urlconf = getattr(self.request, "urlconf", None)
apis = urlparser.get_apis(
urlconf=urlconf,
exclude_namespaces=rfs.SWAGGER_SETTINGS.get('exclude_namespaces')
)
resources = urlparser.get_top_level_apis(apis)
exclude_namespaces = rfs.SWAGGER_SETTINGS.get('exclude_namespaces')
apis = urlparser.get_apis(urlconf=urlconf, exclude_namespaces=exclude_namespaces)
authorized_apis = filter(lambda a: self.handle_resource_access(self.request, a['pattern']), apis)
resources = urlparser.get_top_level_apis(authorized_apis)
return resources
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment