<jupyter_start><jupyter_text>Internal - OpenAPI Parser This library leverages the [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification) to create a python client for the GitHub API.  The OpenAPI specification contains metadata on all of the endpoints and how to access them properly.  Using this metadata, we can construct a python client dynamically that updates automatically along with the OpenAPI Spec.<jupyter_code>#export
GH_OPENAPI_URL = 'https://github.com/github/rest-api-description/raw/main/descriptions/api.github.com/api.github.com.json?raw=true'
_DOC_URL = 'https://docs.github.com/'
#hide
if 0:
    s = urlread(GH_OPENAPI_URL)
    js = loads(s)['paths']
    sj = {o['operationId']:o for p in js.values() for o in p.values()}

    j = js['/repos/{owner}/{repo}/issues/{issue_number}/labels']['post']
    n = nested_idx(j, *'requestBody content application/json schema'.split())
#export
_lu_type = dict(zip(
    'NA string object array boolean integer'.split(),
    map(PrettyString,'object str dict list bool int'.split())
))

def _detls(k,v):
    res = [_lu_type[v.get('type', 'NA')]]
    try: res.append(v['default'])
    except KeyError: pass
    return [k]+res

def _find_data(d):
    if 'properties' in d: return d['properties']
    if 'oneOf' in d:
        for o in d['oneOf']:
            if 'properties' in o: return o['properties']
    return {}
#export
def build_funcs(nm='ghapi/metadata.py', url=GH_OPENAPI_URL, docurl=_DOC_URL):
    "Build module metadata.py from an Open API spec and optionally filter by a path `pre`"
    def _get_detls(o):
        data = nested_idx(o, *'requestBody content application/json schema'.split()) or {}
        data = _find_data(data)
        url = o['externalDocs']['url'][len(docurl):]
        params = o.get('parameters',None)
        qparams = [p['name'] for p in params if p['in']=='query'] if params else []
        d = [_detls(*o) for o in data.items()]
        preview = nested_idx(o, 'x-github','previews',0,'name') or ''
        return (o['operationId'], o['summary'], url, qparams, d, preview)

    js = loads(urlread(url))
    _funcs = [(path, verb) + _get_detls(detls)
              for path,verbs in js['paths'].items() for verb,detls in verbs.items()
              if 'externalDocs' in detls]
    Path(nm).write_text("funcs = " + pprint.pformat(_funcs, width=360))
#hide
build_funcs()<jupyter_output><empty_output><jupyter_text>This module created by `build_funcs` contains a list of metadata for each endpoint, containing the path, verb, operation id, summary, documentation relative URL, and list of parameters (if any), e.g:<jupyter_code>#export
GhMeta = namedtuple('GhMeta', 'path verb oper_id summary doc_url params data preview'.split())
from ghapi.metadata import funcs
GhMeta(*funcs[3])<jupyter_output><empty_output><jupyter_text>Export -<jupyter_code>#hide
from nbdev.export import notebook2script
notebook2script()<jupyter_output>Converted 000_core.ipynb.
Converted 01_actions.ipynb.
Converted 02_auth.ipynb.
Converted 03_page.ipynb.
Converted 04_event.ipynb.
Converted 10_cli.ipynb.
Converted 50_fullapi.ipynb.
Converted 80_tutorial_actions.ipynb.
Converted 90_build_lib.ipynb.
Converted ghapi_demo.ipynb.
Converted index.ipynb.
{'fraction_non_alphanumeric': 0.13170127052990394, 'fraction_numerical': 0.00836690424542919, 'mean_word_length': 4.416107382550336, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '181607', 'license': 'Apache-2.0', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1072, 'n_words': 288, 'path': '90_build_lib.ipynb', 'repo_name': 'lfdebrux/ghapi', 'size': '3227'}