def remove_non_root_reusables()

in scripts/generators/intermediate_files.py [0:0]


def remove_non_root_reusables(fields_nested: Dict[str, FieldEntry]) -> Dict[str, FieldEntry]:
    """
    Remove field sets that have top_level=false from the root of the field definitions.

    This attribute means they're only meant to be in the "reusable/expected" locations
    and not at the root of user's events.

    This is only relevant for the 'flat' field representation. The nested one
    still needs to keep all field sets at the root of the YAML file, as it
    the official information about each field set. It's the responsibility of
    users consuming ecs_nested.yml to skip the field sets with top_level=false.
    """
    fields: Dict[str, FieldEntry] = {}
    for (name, field) in fields_nested.items():
        if 'reusable' not in field['schema_details'] or field['schema_details']['reusable']['top_level']:
            fields[name] = field
    return fields