@@ -85,7 +85,16 @@ function findFirstSample(e) {
8585
8686const isPrimitive = e => ( e instanceof StringElement ) || ( e instanceof NumberElement ) || ( e instanceof BooleanElement ) ;
8787const isEnumElement = e => e instanceof EnumElement ;
88- const isPlural = e => e instanceof ArrayElement ;
88+ const isArrayElement = e => e instanceof ArrayElement ;
89+
90+ const hasSample = e => findFirstSample ( e ) !== null ;
91+ const hasDefault = e => findDefault ( e ) !== null ;
92+ const hasContent = e => e . content !== undefined ;
93+ const hasValue = R . anyPass ( [ hasContent , hasSample , hasDefault ] ) ;
94+ const hasNoValue = R . complement ( hasValue ) ;
95+ const isNoValuePrimitive = R . both ( isPrimitive , hasNoValue ) ;
96+ const isNonEmptyArrayElement = e => isArrayElement ( e ) && e . content && ! e . isEmpty ;
97+
8998
9099function trivialValue ( e ) {
91100 if ( e instanceof BooleanElement ) {
@@ -113,8 +122,10 @@ function mapValue(e, options, f, elements) {
113122 }
114123
115124 const opts = updateTypeAttributes ( e , options ) ;
116- if ( e . content && ( ! isPlural ( e ) || ! e . isEmpty ) ) {
125+
126+ if ( e . content && ! ( isArrayElement ( e ) && e . content . every ( isNoValuePrimitive ) ) ) {
117127 const result = f ( e , opts , elements , 'content' ) ;
128+
118129 if ( undefined !== result ) {
119130 return result ;
120131 }
@@ -136,6 +147,15 @@ function mapValue(e, options, f, elements) {
136147 }
137148 }
138149
150+ // reconsider content for array element (prefer sample/default first)
151+ if ( isNonEmptyArrayElement ( e ) ) {
152+ const result = f ( e , opts , elements , 'content' ) ;
153+
154+ if ( undefined !== result ) {
155+ return result ;
156+ }
157+ }
158+
139159 if ( isFlag ( NULLABLE_FLAG , opts ) ) {
140160 const result = f ( new NullElement ( ) , opts , elements , 'nullable' ) ;
141161 if ( undefined !== result ) {
@@ -180,7 +200,7 @@ function mapValue(e, options, f, elements) {
180200 }
181201 }
182202
183- if ( isPlural ( e ) && e . isEmpty ) {
203+ if ( isArrayElement ( e ) && e . isEmpty ) {
184204 return f ( e , opts , elements , 'generated' ) ;
185205 }
186206
0 commit comments