From 9ca5949a756cdfe5763b7d5522312c03aab6bdff Mon Sep 17 00:00:00 2001 From: Abdelrahman Awad Date: Sun, 5 Jan 2025 14:54:58 +0200 Subject: [PATCH] fix: create the base paths outside the map iterations --- src/standardSchema.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/standardSchema.ts b/src/standardSchema.ts index 95a3e543..ef6f3281 100644 --- a/src/standardSchema.ts +++ b/src/standardSchema.ts @@ -151,13 +151,13 @@ function createStandardIssues( error: ValidationError, parentPath?: string, ): StandardIssue[] { + const path = parentPath ? `${parentPath}.${error.path}` : error.path; + return error.errors.map( (err) => ({ message: err, - path: createStandardPath( - parentPath ? `${parentPath}.${error.path}` : error.path, - ), + path: createStandardPath(path), } satisfies StandardIssue), ); } @@ -170,10 +170,7 @@ function issuesFromValidationError( return createStandardIssues(error, parentPath); } - return error.inner.flatMap((err) => - issuesFromValidationError( - err, - parentPath ? `${parentPath}.${error.path}` : error.path, - ), - ); + const path = parentPath ? `${parentPath}.${error.path}` : error.path; + + return error.inner.flatMap((err) => issuesFromValidationError(err, path)); }