Exemplo n.º 1
0
    def listResources(self, params):
        # Paths Object
        paths = {}

        # Definitions Object
        definitions = dict(**docs.models[None])

        # List of Tag Objects
        tags = []

        routeMap = _apiRouteMap()

        for resource in sorted(six.viewkeys(docs.routes), key=str):
            # Update Definitions Object
            if resource in docs.models:
                for name, model in six.viewitems(docs.models[resource]):
                    definitions[name] = model

            prefixPath = None
            tag = resource
            if isinstance(resource, Resource):
                if resource not in routeMap:
                    raise RestException('Resource not mounted: %s' % resource)
                prefixPath = routeMap[resource]
                tag = prefixPath[0]

            # Tag Object
            tags.append({'name': tag})

            for route, methods in six.viewitems(docs.routes[resource]):
                # Path Item Object
                pathItem = {}
                for method, operation in six.viewitems(methods):
                    # Operation Object
                    pathItem[method.lower()] = operation
                    if prefixPath:
                        operation['tags'] = prefixPath[:1]

                if prefixPath:
                    route = '/'.join([''] + prefixPath + [route[1:]])

                paths[route] = pathItem

        apiUrl = getApiUrl(preferReferer=True)
        urlParts = getUrlParts(apiUrl)
        host = urlParts.netloc
        basePath = urlParts.path

        return {
            'swagger': SWAGGER_VERSION,
            'info': {
                'title': 'Girder REST API',
                'version': API_VERSION
            },
            'host': host,
            'basePath': basePath,
            'tags': tags,
            'paths': paths,
            'definitions': definitions
        }
Exemplo n.º 2
0
    def listResources(self, params):
        # Paths Object
        paths = {}

        # Definitions Object
        definitions = dict(**docs.models[None])

        # List of Tag Objects
        tags = []

        routeMap = _apiRouteMap()

        for resource in sorted(six.viewkeys(docs.routes), key=str):
            # Update Definitions Object
            if resource in docs.models:
                for name, model in six.viewitems(docs.models[resource]):
                    definitions[name] = model

            prefixPath = None
            tag = resource
            if isinstance(resource, Resource):
                if resource not in routeMap:
                    raise RestException('Resource not mounted: %s' % resource)
                prefixPath = routeMap[resource]
                tag = prefixPath[0]

            # Tag Object
            tags.append({
                'name': tag
            })

            for route, methods in six.viewitems(docs.routes[resource]):
                # Path Item Object
                pathItem = {}
                for method, operation in six.viewitems(methods):
                    # Operation Object
                    pathItem[method.lower()] = operation
                    if prefixPath:
                        operation['tags'] = prefixPath[:1]

                if prefixPath:
                    route = '/'.join([''] + prefixPath + [route[1:]])

                paths[route] = pathItem

        apiUrl = getApiUrl(preferReferer=True)
        urlParts = getUrlParts(apiUrl)
        host = urlParts.netloc
        basePath = urlParts.path

        return {
            'swagger': SWAGGER_VERSION,
            'info': {
                'title': 'Girder REST API',
                'version': VERSION['release']
            },
            'host': host,
            'basePath': basePath,
            'tags': tags,
            'paths': paths,
            'definitions': definitions
        }