diff --git a/ambar-core/src/json/decoder.ts b/ambar-core/src/json/decoder.ts index f19b841..b1477c3 100644 --- a/ambar-core/src/json/decoder.ts +++ b/ambar-core/src/json/decoder.ts @@ -358,5 +358,5 @@ const json: Decoder = rec((json) => oneOf([nullP, string, number, boolean, array(json), objectMap(json)]) ); -const stringEnum = (strs: T): Decoder => +const stringEnum = (strs: T): Decoder => oneOf(strs.map(stringLiteral)); diff --git a/ambar-core/src/json/encoder.ts b/ambar-core/src/json/encoder.ts index ed25570..21bdae1 100644 --- a/ambar-core/src/json/encoder.ts +++ b/ambar-core/src/json/encoder.ts @@ -164,7 +164,7 @@ const oneOf = (f: (v: V) => Encoder): Encoder => return encoder.run(input); }); -const stringEnum = (strs: T): Encoder => +const stringEnum = (strs: T): Encoder => string.rmap((input) => { if (!strs.includes(input)) { throw new Error( diff --git a/ambar-core/src/json/schema.ts b/ambar-core/src/json/schema.ts index 7478ca9..cb65319 100644 --- a/ambar-core/src/json/schema.ts +++ b/ambar-core/src/json/schema.ts @@ -177,7 +177,7 @@ const stringLiteral = (str: T): Schema => }) ); -const stringEnum = (strs: T): Schema => +const stringEnum = (strs: T): Schema => new Schema(D.stringEnum(strs), E.stringEnum(strs)); const oneOf = (f: (v: V) => Schema, ss: Array>): Schema =>