in runtool/runtool/transformations.py [0:0]
def apply_ref(node: dict, context: dict) -> Any:
"""
If the node contains a `$ref`, resolve any nested `$ref` which node["$ref"]
points to in the `context`. Thereafter replace the current node with the
resolved value.
In the below example, we want to replace the node with the value of
`context["some_node"][0]["some_val"]`. This, however references
`context["target"]` thus the value which the node will be replaced with
will be `1` when the nested references has been resolved.
>>> apply_ref(
... node={"$ref": "some_node.0.some_val"},
... context={
... "target": 1,
... "some_node": [
... {"some_val": {"$ref": "target"}},
... "ignored"
... ]
... }
... )
1
Parameters
----------
node
The node which should be processed.
context
The data which can be referenced using $ref
Returns
-------
Any
The data which is referenced
"""
if not (isinstance(node, dict) and "$ref" in node):
return node
assert len(node) == 1, "$ref needs to be the only value"
data = get_item_from_path(context, node["$ref"])
return recursive_apply(data, partial(apply_ref, context=context))