@@ -79,6 +79,24 @@ export const processPropertyNames = (
7979 if ( ! isOptional ) requiredKeys . push ( ...keys ) ;
8080} ;
8181
82+ /** @internal */
83+ export const mergeExamples = (
84+ target : FlattenObjectSchema ,
85+ entry : z . core . JSONSchema . BaseSchema ,
86+ isOptional : boolean ,
87+ ) => {
88+ if ( ! entry . examples ?. length ) return ;
89+ if ( isOptional ) {
90+ target . examples = R . concat ( target . examples || [ ] , entry . examples ) ;
91+ } else {
92+ target . examples = combinations (
93+ target . examples ?. filter ( isObject ) || [ ] ,
94+ entry . examples . filter ( isObject ) ,
95+ ( [ a , b ] ) => R . mergeDeepRight ( a , b ) ,
96+ ) ;
97+ }
98+ } ;
99+
82100export const flattenIO = (
83101 jsonSchema : z . core . JSONSchema . BaseSchema ,
84102 mode : MergeMode = "coerce" ,
@@ -91,17 +109,7 @@ export const flattenIO = (
91109 if ( entry . description ) flat . description ??= entry . description ;
92110 stack . push ( ...processAllOf ( entry , mode , isOptional ) ) ;
93111 stack . push ( ...processVariants ( entry ) ) ;
94- if ( entry . examples ?. length ) {
95- if ( isOptional ) {
96- flat . examples = R . concat ( flat . examples || [ ] , entry . examples ) ;
97- } else {
98- flat . examples = combinations (
99- flat . examples ?. filter ( isObject ) || [ ] ,
100- entry . examples . filter ( isObject ) ,
101- ( [ a , b ] ) => R . mergeDeepRight ( a , b ) ,
102- ) ;
103- }
104- }
112+ mergeExamples ( flat , entry , isOptional ) ;
105113 if ( ! isJsonObjectSchema ( entry ) ) continue ;
106114 stack . push ( [ isOptional , { examples : pullRequestExamples ( entry ) } ] ) ;
107115 if ( entry . properties ) {
0 commit comments