ElicitationSchema.fromJson constructor

ElicitationSchema.fromJson(
  1. Map<String, dynamic> json
)

Parse a primitive schema definition map back into a typed instance. Recognizes string / number / integer / boolean / single-select enum / multi-select enum (type: array whose items is an enum). Falls back to RawElicitationSchema for anything unrecognized.

Implementation

factory ElicitationSchema.fromJson(Map<String, dynamic> json) {
  final type = json['type'];
  if (type == 'string') {
    if (json['enum'] is List) {
      return EnumSchema.fromJson(json);
    }
    return StringSchema.fromJson(json);
  }
  if (type == 'number' || type == 'integer') {
    return NumberSchema.fromJson(json);
  }
  if (type == 'boolean') {
    return BooleanSchema.fromJson(json);
  }
  if (type == 'array') {
    final items = json['items'];
    if (items is Map && items['enum'] is List) {
      return EnumSchema.fromJson(json);
    }
  }
  return RawElicitationSchema(Map<String, dynamic>.from(json));
}