Beispiel #1
0
def build_swagger_spec(user, repo, sha, serverName):
    """Build grlc specification for the given github user / repo in swagger format """
    if user and repo:
        # Init provenance recording
        prov_g = grlcPROV(user, repo)
    else:
        prov_g = None

    swag = swagger.get_blank_spec()
    swag['host'] = serverName

    try:
        loader = getLoader(user, repo, sha, prov_g)
    except Exception as e:
        # If repo does not exits
        swag['info'] = {'title': 'ERROR!', 'description': str(e)}
        swag['paths'] = {}
        return swag

    prev_commit, next_commit, info, basePath = \
        swagger.get_repo_info(loader, sha, prov_g)
    swag['prev_commit'] = prev_commit
    swag['next_commit'] = next_commit
    swag['info'] = info
    swag['basePath'] = basePath

    # TODO: can we pass loader to build_spec ?
    spec = swagger.build_spec(user, repo, sha, prov_g)
    for item in spec:
        swag['paths'][item['call_name']] = swagger.get_path_for_item(item)

    if prov_g:
        prov_g.end_prov_graph()
        swag['prov'] = prov_g.serialize(format='turtle')
    return swag
Beispiel #2
0
def build_swagger_spec(user, repo, subdir, spec_url, sha, serverName):
    """Build grlc specification for the given github user / repo in swagger format."""
    if user and repo:
        # Init provenance recording
        prov_g = grlcPROV(user, repo)
    else:
        prov_g = None

    swag = swagger.get_blank_spec()
    swag['host'] = serverName

    try:
        loader = getLoader(user, repo, subdir, spec_url, sha, prov_g)
    except Exception as e:
        # If repo does not exits
        swag['info'] = {'title': 'ERROR!', 'description': str(e)}
        swag['paths'] = {}
        return swag

    prev_commit, next_commit, info, basePath = \
        swagger.get_repo_info(loader, sha, prov_g)
    swag['prev_commit'] = prev_commit
    swag['next_commit'] = next_commit
    swag['info'] = info
    swag['basePath'] = basePath

    # TODO: can we pass loader to build_spec ? --> Ideally yes!
    spec, warnings = swagger.build_spec(user, repo, subdir, spec_url, sha,
                                        prov_g)
    # Use items to build API paths
    for item in spec:
        swag['paths'][item['call_name']] = swagger.get_path_for_item(item)

    # TODO: Add bootstrap style to top level HTML
    # Without a better place to display warnings, we can make them part of the description.
    if 'description' not in swag['info']:
        swag['info']['description'] = ''
    for warn in warnings:
        swag['info']['description'] += swagger.get_warning_div(warn)

    if prov_g:
        prov_g.end_prov_graph()
        swag['prov'] = prov_g.serialize(format='turtle')
    return swag