From 2cad6cc87cc6da061de28252b4f89bdd279471c2 Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Sat, 1 Nov 2025 22:01:42 +0530 Subject: [PATCH] feat(model): Add robust id and name parsing with validation --- lib/core/models/model.dart | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/core/models/model.dart b/lib/core/models/model.dart index 99ee7d0..d4d1ca8 100644 --- a/lib/core/models/model.dart +++ b/lib/core/models/model.dart @@ -125,9 +125,20 @@ sealed class Model with _$Model { } } + final idRaw = json['id']; + final id = idRaw?.toString(); + if (id == null || id.isEmpty) { + throw ArgumentError('Model JSON missing required "id" field.'); + } + + final nameRaw = json['name']; + final name = (nameRaw == null || nameRaw.toString().trim().isEmpty) + ? id + : nameRaw.toString(); + return Model( - id: json['id'] as String, - name: json['name'] as String, + id: id, + name: name, description: json['description'] as String?, isMultimodal: isMultimodal, supportsStreaming: supportsStreaming,