@@ -2,6 +2,7 @@ import { z } from "zod";
22import {
33 flattenIO ,
44 isJsonObjectSchema ,
5+ mergeExamples ,
56 propsMerger ,
67 canMerge ,
78 nestOptional ,
@@ -199,6 +200,55 @@ describe("JSON Schema helpers", () => {
199200 } ) ;
200201 } ) ;
201202
203+ describe ( "mergeExamples()" , ( ) => {
204+ test ( "should do nothing when entry has no examples" , ( ) => {
205+ const flat = { type : "object" as const , properties : { } } ;
206+ mergeExamples ( flat , { type : "string" } , false ) ;
207+ expect ( flat ) . toEqual ( { type : "object" , properties : { } } ) ;
208+ } ) ;
209+
210+ test ( "should concatenate examples when optional" , ( ) => {
211+ const flat = {
212+ type : "object" as const ,
213+ properties : { } ,
214+ examples : [ { a : 1 } ] ,
215+ } ;
216+ mergeExamples ( flat , { examples : [ { b : 2 } , { c : 3 } ] } , true ) ;
217+ expect ( flat . examples ) . toEqual ( [ { a : 1 } , { b : 2 } , { c : 3 } ] ) ;
218+ } ) ;
219+
220+ test ( "should initialize examples when optional and flat has none" , ( ) => {
221+ const flat : { type : "object" ; properties : { } ; examples ?: unknown [ ] } = {
222+ type : "object" ,
223+ properties : { } ,
224+ } ;
225+ mergeExamples ( flat , { examples : [ { a : 1 } ] } , true ) ;
226+ expect ( flat . examples ) . toEqual ( [ { a : 1 } ] ) ;
227+ } ) ;
228+
229+ test ( "should produce combinations when required" , ( ) => {
230+ const flat = {
231+ type : "object" as const ,
232+ properties : { } ,
233+ examples : [ { a : 1 } ] ,
234+ } ;
235+ mergeExamples ( flat , { examples : [ { b : 2 } , { b : 3 } ] } , false ) ;
236+ expect ( flat . examples ) . toEqual ( [
237+ { a : 1 , b : 2 } ,
238+ { a : 1 , b : 3 } ,
239+ ] ) ;
240+ } ) ;
241+
242+ test ( "should handle required with no prior examples" , ( ) => {
243+ const flat : { type : "object" ; properties : { } ; examples ?: unknown [ ] } = {
244+ type : "object" ,
245+ properties : { } ,
246+ } ;
247+ mergeExamples ( flat , { examples : [ { a : 1 } ] } , false ) ;
248+ expect ( flat . examples ) . toEqual ( [ { a : 1 } ] ) ;
249+ } ) ;
250+ } ) ;
251+
202252 describe ( "pullRequestExamples()" , ( ) => {
203253 test ( "should return empty array for empty properties" , ( ) => {
204254 expect ( pullRequestExamples ( { type : "object" , properties : { } } ) ) . toEqual (
0 commit comments