h2o-bindings/bin/gen_thrift.py
def add_schema_to_dependency_array(schema, ordered_schemas, schemas_map):
    """
    This is a helper function to order all schemas according to their usage. For example, if schema A uses schemas B
    and C, then they should be reordered as {B, C, A}.
      :param schema: schema object that we are processing right now
      :param ordered_schemas: an OrderedDict of schemas that were already encountered. This is also the "output"
        variable -- all schemas/enums that are needed will be recorded here in the correct order of their supposed
        declaration.
      :param schemas_map: dictionary(schemaname => schemaobject)
    """
    ordered_schemas[schema["name"]] = schema
    for field in schema["fields"]:
        field_schema_name = field["schema_name"]
        if field_schema_name is None: continue
        if field_schema_name in ordered_schemas: continue
        if field["type"].startswith("enum"):
            ordered_schemas[field_schema_name] = field["values"]
        else:
            field_schema = schemas_map[field_schema_name]
            if field_schema["name"] not in ordered_schemas:
                add_schema_to_dependency_array(field_schema, ordered_schemas, schemas_map)
def add_schema_to_dependency_array(schema, ordered_schemas, schemas_map):
    """
    This is a helper function to order all schemas according to their usage. For example, if schema A uses schemas B
    and C, then they should be reordered as {B, C, A}.
      :param schema: schema object that we are processing right now
      :param ordered_schemas: an OrderedDict of schemas that were already encountered. This is also the "output"
        variable -- all schemas/enums that are needed will be recorded here in the correct order of their supposed
        declaration.
      :param schemas_map: dictionary(schemaname => schemaobject)
    """
    ordered_schemas[schema["name"]] = schema
    for field in schema["fields"]:
        field_schema_name = field["schema_name"]
        if field_schema_name is None: continue
        if field_schema_name in ordered_schemas: continue
        if field["type"].startswith("enum"):
            ordered_schemas[field_schema_name] = field["values"]
        else:
            field_schema = schemas_map[field_schema_name]
            if field_schema["name"] not in ordered_schemas:
                add_schema_to_dependency_array(field_schema, ordered_schemas, schemas_map)
This is a helper function to order all schemas according to their usage. For example, if schema A uses schemas B
    and C, then they should be reordered as {B, C, A}.
      :param schema: schema object that we are processing right now
      :param ordered_schemas: an OrderedDict of schemas that were already encountered. This is also the "output"
        variable -- all schemas/enums that are needed will be recorded here in the correct order of their supposed
        declaration.
      :param schemas_map: dictionary(schemaname => schemaobject)