@@ -44,22 +44,13 @@ function toAllowedValueLabel(value: unknown): string {
4444}
4545
4646function toAllowedValueValue ( value : unknown ) : string {
47- if ( typeof value === "string" ) {
48- return value ;
49- }
50- return safeStringify ( value ) ;
47+ return typeof value === "string" ? value : safeStringify ( value ) ;
5148}
5249
5350function toAllowedValueDedupKey ( value : unknown ) : string {
54- if ( value === null ) {
55- return "null:null" ;
56- }
57- const kind = typeof value ;
51+ const kind = value === null ? "null" : typeof value ;
5852 // Preserve schema distinctions such as numeric 1 vs string "1" even when labels match.
59- if ( kind === "string" ) {
60- return `string:${ value as string } ` ;
61- }
62- return `${ kind } :${ safeStringify ( value ) } ` ;
53+ return `${ kind } :${ toAllowedValueValue ( value ) } ` ;
6354}
6455
6556/** Summarizes enum/allowed-value candidates for compact validation error hints. */
@@ -97,14 +88,10 @@ export function summarizeAllowedValues(
9788 } ;
9889}
9990
100- function messageAlreadyIncludesAllowedValues ( message : string ) : boolean {
101- const lower = normalizeLowercaseStringOrEmpty ( message ) ;
102- return lower . includes ( "(allowed:" ) || lower . includes ( "expected one of" ) ;
103- }
104-
10591/** Appends an allowed-values hint unless the validation message already includes one. */
10692export function appendAllowedValuesHint ( message : string , summary : AllowedValuesSummary ) : string {
107- if ( messageAlreadyIncludesAllowedValues ( message ) ) {
93+ const lower = normalizeLowercaseStringOrEmpty ( message ) ;
94+ if ( lower . includes ( "(allowed:" ) || lower . includes ( "expected one of" ) ) {
10895 return message ;
10996 }
11097 return `${ message } (allowed: ${ summary . formatted } )` ;
0 commit comments