@@ -76,4 +76,113 @@ describe("convertJsonSchemaToZod", () => {
7676 // For enums, we just check that the original enum values are present
7777 expect ( resultSchema . enum ) . toEqual ( jsonSchema . enum ) ;
7878 } ) ;
79- } ) ;
79+
80+ // Tests for unimplemented but supported features
81+ describe ( "String validation" , ( ) => {
82+ it ( "should support minLength and maxLength constraints" , ( ) => {
83+ const jsonSchema = {
84+ $schema : "http://json-schema.org/draft-07/schema#" ,
85+ type : "string" ,
86+ minLength : 3 ,
87+ maxLength : 10
88+ } ;
89+
90+ const zodSchema = convertJsonSchemaToZod ( jsonSchema ) ;
91+ const resultSchema = zodToJsonSchema ( zodSchema ) ;
92+ expect ( resultSchema ) . toEqual ( jsonSchema ) ;
93+ } ) ;
94+
95+ it ( "should support pattern constraint" , ( ) => {
96+ const jsonSchema = {
97+ $schema : "http://json-schema.org/draft-07/schema#" ,
98+ type : "string" ,
99+ pattern : "^[a-zA-Z0-9]+$"
100+ } ;
101+
102+ const zodSchema = convertJsonSchemaToZod ( jsonSchema ) ;
103+ const resultSchema = zodToJsonSchema ( zodSchema ) ;
104+ expect ( resultSchema ) . toEqual ( jsonSchema ) ;
105+ } ) ;
106+ } ) ;
107+
108+ describe ( "Number validation" , ( ) => {
109+ it ( "should support minimum and maximum constraints" , ( ) => {
110+ const jsonSchema = {
111+ $schema : "http://json-schema.org/draft-07/schema#" ,
112+ type : "number" ,
113+ minimum : 0 ,
114+ maximum : 100
115+ } ;
116+
117+ const zodSchema = convertJsonSchemaToZod ( jsonSchema ) ;
118+ const resultSchema = zodToJsonSchema ( zodSchema ) ;
119+ expect ( resultSchema ) . toEqual ( jsonSchema ) ;
120+ } ) ;
121+
122+ it ( "should support exclusiveMinimum and exclusiveMaximum constraints" , ( ) => {
123+ const jsonSchema = {
124+ $schema : "http://json-schema.org/draft-07/schema#" ,
125+ type : "number" ,
126+ exclusiveMinimum : 0 ,
127+ exclusiveMaximum : 100
128+ } ;
129+
130+ const zodSchema = convertJsonSchemaToZod ( jsonSchema ) ;
131+ const resultSchema = zodToJsonSchema ( zodSchema ) ;
132+ expect ( resultSchema ) . toEqual ( jsonSchema ) ;
133+ } ) ;
134+
135+ it ( "should support multipleOf constraint" , ( ) => {
136+ const jsonSchema = {
137+ $schema : "http://json-schema.org/draft-07/schema#" ,
138+ type : "number" ,
139+ multipleOf : 5
140+ } ;
141+
142+ const zodSchema = convertJsonSchemaToZod ( jsonSchema ) ;
143+ const resultSchema = zodToJsonSchema ( zodSchema ) ;
144+ expect ( resultSchema ) . toEqual ( jsonSchema ) ;
145+ } ) ;
146+ } ) ;
147+
148+ describe ( "Array validation" , ( ) => {
149+ it ( "should support minItems and maxItems constraints" , ( ) => {
150+ const jsonSchema = {
151+ $schema : "http://json-schema.org/draft-07/schema#" ,
152+ type : "array" ,
153+ items : {
154+ type : "string"
155+ } ,
156+ minItems : 1 ,
157+ maxItems : 10
158+ } ;
159+
160+ const zodSchema = convertJsonSchemaToZod ( jsonSchema ) ;
161+ const resultSchema = zodToJsonSchema ( zodSchema ) ;
162+ expect ( resultSchema ) . toEqual ( jsonSchema ) ;
163+ } ) ;
164+
165+ it ( "should support uniqueItems constraint" , ( ) => {
166+ const jsonSchema = {
167+ $schema : "http://json-schema.org/draft-07/schema#" ,
168+ type : "array" ,
169+ items : {
170+ type : "string"
171+ } ,
172+ uniqueItems : true
173+ } ;
174+
175+ const zodSchema = convertJsonSchemaToZod ( jsonSchema ) ;
176+
177+ // Unfortunately, zod-to-json-schema doesn't properly translate refinements for uniqueItems
178+ // So we'll verify the functionality by testing with actual data
179+ expect ( ( ) => zodSchema . parse ( [ "a" , "b" , "c" ] ) ) . not . toThrow ( ) ;
180+ expect ( ( ) => zodSchema . parse ( [ "a" , "a" , "c" ] ) ) . toThrow ( ) ;
181+
182+ // We can't do the normal round-trip test, so we'll verify key parts of the schema
183+ const resultSchema = zodToJsonSchema ( zodSchema ) ;
184+ expect ( resultSchema . type ) . toEqual ( "array" ) ;
185+ expect ( resultSchema . items ) . toEqual ( { type : "string" } ) ;
186+ } ) ;
187+ } ) ;
188+ } ) ;
0 commit comments