fromJson static method

ToolContentSpec? fromJson(
  1. dynamic value
)

Implementation

static ToolContentSpec? fromJson(dynamic value) {
  if (value == null) {
    return null;
  }
  if (value is! Map) {
    throw ArgumentError.value(value, "value", "Tool content type must be a JSON object");
  }

  final rawTypes = value["types"];
  if (rawTypes is! List) {
    throw ArgumentError.value(rawTypes, "types", "Tool content type requires a types array");
  }

  final types = rawTypes
      .map((item) {
        if (item is! String) {
          throw ArgumentError.value(item, "types", "Tool content types must be strings");
        }
        return _toolContentTypeFromWire(item);
      })
      .toList(growable: false);

  final rawStream = value["stream"];
  final stream = rawStream is bool ? rawStream : false;
  Map<String, dynamic>? schema;
  final rawSchema = value["schema"];
  if (rawSchema != null) {
    if (rawSchema is! Map) {
      throw ArgumentError.value(rawSchema, "schema", "Tool content type schema must be a JSON object");
    }
    schema = rawSchema.cast<String, dynamic>();
  }
  return ToolContentSpec(types: types, stream: stream, schema: schema);
}