toJson method

  1. @override
Map<String, dynamic> toJson()
override

Converts this InteractionAffordance to a Map resembling a JSON object.

Implementation

@override
Map<String, dynamic> toJson() {
  final result = {
    ...super.toJson(),
  };

  for (final (key, value) in [("idempotent", idempotent), ("safe", safe)]) {
    if (value) {
      result[key] = value;
    }
  }

  final keyValuePairs = [
    ("input", input),
    ("output", output),
    ("synchronous", synchronous),
  ];

  for (final (key, value) in keyValuePairs) {
    final dynamic convertedValue;

    switch (value) {
      case null:
        continue;
      case DataSchema():
        convertedValue = value.toJson();
      default:
        convertedValue = value;
    }

    result[key] = convertedValue;
  }

  return result;
}