From 01859c4307e61e4884e1f9d8edfea806e60c16b5 Mon Sep 17 00:00:00 2001 From: Jose Ramon Palanco Date: Thu, 2 Jul 2026 20:41:28 +0200 Subject: [PATCH] fix: tolerate null repository fields from the backend Real backend data (seen on a live dev instance) carries active: null and data: null on repository documents; Zod's .default() only covers undefined, so the whole repository list failed to parse and the TUI showed a validation error instead of repos. Coerce nullish active, repo_type, status, and data fields to their defaults. Fixture now includes null cases as regression coverage. --- src/services/apiSchemas.ts | 16 ++++++++-------- tests/fixtures/plexicus/repos.json | 8 ++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/services/apiSchemas.ts b/src/services/apiSchemas.ts index f93eb7a..d2eb3fc 100644 --- a/src/services/apiSchemas.ts +++ b/src/services/apiSchemas.ts @@ -84,15 +84,15 @@ export const SingleFindingResponseSchema = z.object({ const RepoAttributesSchema = z.object({ nickname: z.string(), uri: z.string(), - active: z.boolean().default(true), - repo_type: z.string().default('github'), - status: z.string().default('active'), + active: z.boolean().nullish().transform(v => v ?? true), + repo_type: z.string().nullish().transform(v => v ?? 'github'), + status: z.string().nullish().transform(v => v ?? 'active'), data: z.object({ - branch: z.string().optional(), - source_control: z.string().optional(), - url: z.string().optional(), - tags: z.array(z.string()).optional(), - }).optional(), + branch: z.string().nullish(), + source_control: z.string().nullish(), + url: z.string().nullish(), + tags: z.array(z.string()).nullish(), + }).nullish(), findings: z.object({ total: z.number().default(0), critical: z.number().default(0), diff --git a/tests/fixtures/plexicus/repos.json b/tests/fixtures/plexicus/repos.json index 571db90..27e6357 100644 --- a/tests/fixtures/plexicus/repos.json +++ b/tests/fixtures/plexicus/repos.json @@ -28,7 +28,7 @@ "attributes": { "nickname": "backend-core", "uri": "https://github.com/plexicus/backend-core", - "active": true, + "active": null, "repo_type": "github", "status": "active", "data": { @@ -54,11 +54,7 @@ "active": true, "repo_type": "github", "status": "active", - "data": { - "branch": "main", - "source_control": "github", - "tags": [] - }, + "data": null, "findings": { "total": 15, "critical": 0,