flattenObjectTypes method

Iterable<NestedObjectValueTypeEntry> flattenObjectTypes(
  1. String name, {
  2. NestedObjectValueTypeParentCategory parentCategory = NestedObjectValueTypeParentCategory.root,
})

Recursively traverses the ValueType children, producing a flat list of NestedObjectValueTypeEntrys.

Implementation

Iterable<NestedObjectValueTypeEntry> flattenObjectTypes(
  String name, {
  NestedObjectValueTypeParentCategory parentCategory =
      NestedObjectValueTypeParentCategory.root,
}) sync* {
  final valueType = this;
  if (valueType is TypedJsonObjectValueType) {
    yield NestedObjectValueTypeEntry(
      name: name,
      parentCategory: parentCategory,
      valueType: valueType,
    );
    for (final entry in valueType.fieldValueTypes.entries) {
      yield* entry.value.flattenObjectTypes(
        entry.key,
        parentCategory: NestedObjectValueTypeParentCategory.object,
      );
    }
  } else if (valueType is TypedListValueType) {
    yield* valueType.elementValueType.flattenObjectTypes(
      name,
      parentCategory: NestedObjectValueTypeParentCategory.list,
    );
  } else if (valueType is TypedJsonMapValueType) {
    yield* valueType.keyValueType.flattenObjectTypes(
      name,
      parentCategory: NestedObjectValueTypeParentCategory.map,
    );
    yield* valueType.valueValueType.flattenObjectTypes(
      name,
      parentCategory: NestedObjectValueTypeParentCategory.map,
    );
  }
}