From cf053fac92d769ae398873631e577f864bf36d10 Mon Sep 17 00:00:00 2001 From: Chase Coalwell <782571+srchase@users.noreply.github.com> Date: Thu, 16 Feb 2023 11:50:25 -0700 Subject: [PATCH 1/4] Remove reflected values from validation message --- .../src/validation/index.spec.ts | 23 +++++++++---------- .../server-common/src/validation/index.ts | 19 +-------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts b/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts index 68c09a398b1..5a373b59ffb 100644 --- a/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts +++ b/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts @@ -32,8 +32,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz... " + - "(truncated) at '/test' failed to satisfy constraint: Member must satisfy regular expression pattern: ^[a-c]$" + "Value at '/test' failed to satisfy constraint: Member must satisfy regular expression pattern: ^[a-c]$" ); }); it("omits null values", () => { @@ -50,7 +49,7 @@ describe("message formatting", () => { it("formats required failures", () => { const failure = new RequiredValidationFailure("/test"); expect(generateValidationMessage(failure)).toEqual( - "Value null at '/test' failed to satisfy constraint: Member must not be null" + "Value at '/test' failed to satisfy constraint: Member must not be null" ); }); it("formats enum failures", () => { @@ -61,7 +60,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value pear at '/test' failed to satisfy constraint: Member must satisfy enum value set: [apple, banana]" + "Value at '/test' failed to satisfy constraint: Member must satisfy enum value set: [apple, banana]" ); }); it("formats integer enum failures", () => { @@ -72,7 +71,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value 3 at '/test' failed to satisfy constraint: Member must satisfy enum value set: [1, 2]" + "Value at '/test' failed to satisfy constraint: Member must satisfy enum value set: [1, 2]" ); }); describe("formats length failures", () => { @@ -84,7 +83,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value with length 3 at '/test' failed to satisfy constraint: Member must have length greater than or equal to 7" + "Value at '/test' failed to satisfy constraint: Member must have length greater than or equal to 7" ); }); it("with only max values", () => { @@ -95,7 +94,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value with length 3 at '/test' failed to satisfy constraint: Member must have length less than or equal to 2" + "Value at '/test' failed to satisfy constraint: Member must have length less than or equal to 2" ); }); it("with min and max values", () => { @@ -106,7 +105,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value with length 2 at '/test' failed to satisfy constraint: Member must have length between 3 and 7, inclusive" + "Value at '/test' failed to satisfy constraint: Member must have length between 3 and 7, inclusive" ); }); }); @@ -118,7 +117,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value xyz at '/test' failed to satisfy constraint: Member must satisfy regular expression pattern: ^[a-c]$" + "Value at '/test' failed to satisfy constraint: Member must satisfy regular expression pattern: ^[a-c]$" ); }); describe("formats range failures", () => { @@ -130,7 +129,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value 3 at '/test' failed to satisfy constraint: Member must be greater than or equal to 7" + "Value at '/test' failed to satisfy constraint: Member must be greater than or equal to 7" ); }); it("with only max values", () => { @@ -141,7 +140,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value 3 at '/test' failed to satisfy constraint: Member must be less than or equal to 2" + "Value at '/test' failed to satisfy constraint: Member must be less than or equal to 2" ); }); it("with min and max values", () => { @@ -152,7 +151,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value 2 at '/test' failed to satisfy constraint: Member must be between 3 and 7, inclusive" + "Value at '/test' failed to satisfy constraint: Member must be between 3 and 7, inclusive" ); }); }); diff --git a/smithy-typescript-ssdk-libs/server-common/src/validation/index.ts b/smithy-typescript-ssdk-libs/server-common/src/validation/index.ts index ec3afe2ecbb..bd1f16546c8 100644 --- a/smithy-typescript-ssdk-libs/server-common/src/validation/index.ts +++ b/smithy-typescript-ssdk-libs/server-common/src/validation/index.ts @@ -103,20 +103,6 @@ export const generateValidationSummary = (failures: readonly ValidationFailure[] }; export const generateValidationMessage = (failure: ValidationFailure): string => { - let failureValue; - if (failure.constraintType === "required") { - failureValue = "null "; - } else if (failure.failureValue === null) { - failureValue = ""; - } else { - const rawFailureValue = failure.failureValue.toString(); - if (rawFailureValue.length > 64) { - failureValue = rawFailureValue.substr(0, 49) + "... (truncated) "; - } else { - failureValue = rawFailureValue + " "; - } - } - let prefix = "Value"; let suffix: string; switch (failure.constraintType) { @@ -135,9 +121,6 @@ export const generateValidationMessage = (failure: ValidationFailure): string => break; } case "length": { - if (failure.failureValue !== null) { - prefix = prefix + " with length"; - } const min = failure.constraintValues[0]; const max = failure.constraintValues[1]; if (min === undefined) { @@ -170,5 +153,5 @@ export const generateValidationMessage = (failure: ValidationFailure): string => suffix = "must have unique values"; } } - return `${prefix} ${failureValue}at '${failure.path}' failed to satisfy constraint: Member ${suffix}`; + return `${prefix} at '${failure.path}' failed to satisfy constraint: Member ${suffix}`; }; From ad9eb16cd1c78f6ced580e4c35174c5aa9d59c17 Mon Sep 17 00:00:00 2001 From: Chase Coalwell <782571+srchase@users.noreply.github.com> Date: Thu, 16 Feb 2023 15:37:50 -0700 Subject: [PATCH 2/4] Add length back to message --- .../server-common/src/validation/index.spec.ts | 7 ++++--- .../server-common/src/validation/index.ts | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts b/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts index 5a373b59ffb..b328606a5ae 100644 --- a/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts +++ b/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts @@ -21,6 +21,7 @@ import { PatternValidationFailure, RangeValidationFailure, RequiredValidationFailure, + UniqueItemsValidationFailure, } from "./index"; describe("message formatting", () => { @@ -83,7 +84,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value at '/test' failed to satisfy constraint: Member must have length greater than or equal to 7" + "Value with length 3 at '/test' failed to satisfy constraint: Member must have length greater than or equal to 7" ); }); it("with only max values", () => { @@ -94,7 +95,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value at '/test' failed to satisfy constraint: Member must have length less than or equal to 2" + "Value with length 3 at '/test' failed to satisfy constraint: Member must have length less than or equal to 2" ); }); it("with min and max values", () => { @@ -105,7 +106,7 @@ describe("message formatting", () => { path: "/test", }; expect(generateValidationMessage(failure)).toEqual( - "Value at '/test' failed to satisfy constraint: Member must have length between 3 and 7, inclusive" + "Value with length 2 at '/test' failed to satisfy constraint: Member must have length between 3 and 7, inclusive" ); }); }); diff --git a/smithy-typescript-ssdk-libs/server-common/src/validation/index.ts b/smithy-typescript-ssdk-libs/server-common/src/validation/index.ts index bd1f16546c8..d9cc48fb5d8 100644 --- a/smithy-typescript-ssdk-libs/server-common/src/validation/index.ts +++ b/smithy-typescript-ssdk-libs/server-common/src/validation/index.ts @@ -121,6 +121,9 @@ export const generateValidationMessage = (failure: ValidationFailure): string => break; } case "length": { + if (failure.failureValue !== null) { + prefix = prefix + " with length " + failure.failureValue; + } const min = failure.constraintValues[0]; const max = failure.constraintValues[1]; if (min === undefined) { From 8f2d13d6449580b0d414b7844f9b1d805060b6f5 Mon Sep 17 00:00:00 2001 From: Chase Coalwell <782571+srchase@users.noreply.github.com> Date: Thu, 16 Feb 2023 15:38:25 -0700 Subject: [PATCH 3/4] Add test for unique items validation message --- .../server-common/src/validation/index.spec.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts b/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts index b328606a5ae..b18661d8afe 100644 --- a/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts +++ b/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts @@ -155,5 +155,15 @@ describe("message formatting", () => { "Value at '/test' failed to satisfy constraint: Member must be between 3 and 7, inclusive" ); }); + it("with unique items", () => { + const failure: UniqueItemsValidationFailure = { + constraintType: "uniqueItems", + failureValue: [5,9], + path:"/test", + }; + expect(generateValidationMessage(failure)).toEqual( + "Value with repeated values at '/test' failed to satisfy constraint: Member must have unique values" + ); + }) }); }); From bc2c59212b23ca116d82420f841888f1c7dd1eeb Mon Sep 17 00:00:00 2001 From: Chase Coalwell <782571+srchase@users.noreply.github.com> Date: Fri, 17 Feb 2023 17:31:01 -0700 Subject: [PATCH 4/4] Format TS --- .../server-common/src/validation/index.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts b/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts index b18661d8afe..7af632e36de 100644 --- a/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts +++ b/smithy-typescript-ssdk-libs/server-common/src/validation/index.spec.ts @@ -158,12 +158,12 @@ describe("message formatting", () => { it("with unique items", () => { const failure: UniqueItemsValidationFailure = { constraintType: "uniqueItems", - failureValue: [5,9], - path:"/test", + failureValue: [5, 9], + path: "/test", }; expect(generateValidationMessage(failure)).toEqual( "Value with repeated values at '/test' failed to satisfy constraint: Member must have unique values" ); - }) + }); }); });