From bbf9c5e2a6b2f5e849380ecdc770380c44e8e7ee Mon Sep 17 00:00:00 2001 From: Justin Date: Sat, 10 Feb 2024 17:19:28 -0700 Subject: [PATCH] Add dict to nativeEnum type --- src/parsers/nativeEnum.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/parsers/nativeEnum.ts b/src/parsers/nativeEnum.ts index e6088bf..ed5be54 100644 --- a/src/parsers/nativeEnum.ts +++ b/src/parsers/nativeEnum.ts @@ -3,6 +3,7 @@ import { ZodNativeEnumDef } from "zod"; export type JsonSchema7NativeEnumType = { type: "string" | "number" | ["string", "number"]; enum: (string | number)[]; + dict: Record; }; export function parseNativeEnumDef( @@ -19,6 +20,11 @@ export function parseNativeEnumDef( new Set(actualValues.map((values: string | number) => typeof values)), ); + const dictionary = {}; + for (const key of actualKeys) { + dictionary[object[key]] = key; + } + return { type: parsedTypes.length === 1 @@ -27,5 +33,6 @@ export function parseNativeEnumDef( : "number" : ["string", "number"], enum: actualValues, + dict: dictionary }; }