Beispiel #1
0
def loadfile_with_jsonref(ref):
    if "#/" not in ref:
        return loading.loadfile(ref)

    filename, query = ref.split("#")
    doc = loading.loadfile(filename)
    return access_by_json_pointer(doc, query)
Beispiel #2
0
def examples(
    *,
    src: str,
    dst: str = None,
    ref: str,
    limit: int,
    input_format: str,
    output_format: str,
    format: str,
    use_expand: bool = False,
):
    """output sample value from swagger's spec"""
    from dictknife.jsonknife import extract_example
    from dictknife.jsonknife.accessor import access_by_json_pointer

    if use_expand:
        from dictknife.jsonknife import bundle, expand

        if ref is not None:
            src = "{prefix}#/{name}".format(prefix=src, name=ref.lstrip("#/"))
        data = bundle(src, format=input_format or format)
        data = expand(None, doc=data)
    else:
        data = loading.loadfile(src, format=input_format or format)

    if src and "#/" in src:
        _, ref = src.split("#/", 1)
    if ref is not None:
        data = access_by_json_pointer(data, ref)
    d = extract_example(data, limit=limit)
    loading.dumpfile(d, dst, format=output_format or format or "json")
Beispiel #3
0
def inherit(ref, context, **kwargs):
    data = context.loader.data
    if ref.startswith("#/"):
        parent = access_by_json_pointer(data, ref[1:])
        parent = context.evaluator.eval(context, parent)
    else:
        parent = unquote(load(ref, context))
    return quote(deepmerge(parent, kwargs, override=True))
Beispiel #4
0
    def emit_ref(self, ref):
        if ref in self.defined:
            return self.defined[ref]

        d = access_by_json_pointer(self.doc, ref[1:])
        self.nullable[ref] = self.is_nullable(d)
        name = ref.rsplit("/", 1)[-1]
        typename = self.defined[ref] = PreString("")
        typename.append(self.emit(d, name=name))
        return typename
Beispiel #5
0
    def emit_ref(self, ref):
        if ref in self.defined:
            return self.defined[ref]

        d = access_by_json_pointer(self.doc, ref[1:])
        self.nullable[ref] = self.is_nullable(d)
        name = ref.rsplit("/", 1)[-1]
        typename = self.defined[ref] = PreString("")
        typename.append(self.emit(d, name=name))
        return typename
Beispiel #6
0
    def walk_ref(self, ref):
        if ref in self.defined:
            return self.defined[ref]

        d = access_by_json_pointer(self.doc, ref[1:])
        self.nullable[ref] = self.is_pointer(d)
        name = ref.rsplit("/", 1)[-1]
        sentinel = self.defined[ref] = _Sentinel()
        typ = self.defined[ref] = self.walk(d, name=name)
        sentinel._configure(typ)
        return typ
Beispiel #7
0
    def _callFUT(self, *args, **kwargs):
        from dictknife.jsonknife.accessor import access_by_json_pointer

        return access_by_json_pointer(*args, **kwargs)
Beispiel #8
0
 def onload(d, subresolver):
     for path, sd in precompile_ref_walker.walk(d):
         sdoc, query = subresolver.resolve(sd.pop("$precompile-ref"))
         sresolved = access_by_json_pointer(sdoc.doc, query)
         accessor.assign(d, path[:-1], sresolved)
Beispiel #9
0
 def wrap(d):
     if args.select is None:
         return d
     return access_by_json_pointer(d, args.select.split("#")[-1])