def _resolve_ref()

in src/rpdk/core/jsonutils/utils.py [0:0]


def _resolve_ref(sub_schema: dict, definitions: dict, last_step: bool = False):
    # resolve $ref
    ref = nested_lookup(REF, sub_schema)  # should be safe (always single value)
    # bc sub_schema is always per paranet property
    # (taken from definitions)

    if last_step and REF not in sub_schema:  # dont traverse deeper than requested
        # check if $ref is used directly ->
        # means that we need to check definition
        # otherwise it's an array and return subschema
        return sub_schema

    if ref:
        # [0] should be a single $ref in subschema on the top level
        # [-1] $ref must follow #/definitions/object
        sub_schema = definitions[fragment_decode(ref[0])[-1]]
    # resolve properties
    properties = nested_lookup("properties", sub_schema)
    if properties:
        sub_schema = properties[0]
    return sub_schema