schemaTypeString function

String schemaTypeString(
  1. SchemaType<Object?> type,
  2. DartGeneratorOptions options
)

Returns a String that represents the SchemaType in "Dart syntax".

For example, if the schema type is created with the Dart code Nullable(Ints()), then this function returns just that.

For ObjectsBase instances that are not Objects, this method returns the name of the schema type that would've been generated by generateDartClasses.

Implementation

String schemaTypeString(
    SchemaType<Object?> type, DartGeneratorOptions options) {
  return switch (type) {
    Arrays<dynamic, SchemaType>(itemsType: var items) =>
      _schemaTypeStringWrapper('Arrays', items, options),
    ObjectsBase<dynamic>() when type.mapValueTypeOrNull(options) != null =>
      _schemaTypeMaps(type, options),
    Objects(name: var name) => '${_reviverName(options.className(name))}()',
    ObjectsBase<Object?>() => '${_reviverName(type.dartType().toString())}()',
    Nullable<dynamic, NonNull>(type: var inner) =>
      _schemaTypeStringWrapper('Nullable', inner, options),
    Validatable<Object?>() => _schemaTypeValidatable(type),
    Ints() => 'Ints()',
    Floats() => 'Floats()',
    Strings() => 'Strings()',
    Bools() => 'Bools()',
  };
}