@@ -85,6 +85,13 @@ export const registerHandlebarHelpers = (
85
85
return value . replace ( / \n / g, '\\n' ) ;
86
86
} ) ;
87
87
88
+ Handlebars . registerHelper ( 'exactArray' , function ( this : any , model : Model , options : Handlebars . HelperOptions ) {
89
+ if ( model . export === 'array' && model . maxItems && model . minItems && model . maxItems === model . minItems ) {
90
+ return options . fn ( this ) ;
91
+ }
92
+ return options . inverse ( this ) ;
93
+ } ) ;
94
+
88
95
Handlebars . registerHelper ( 'ifdef' , function ( this : any , ...args ) : string {
89
96
const options = args . pop ( ) ;
90
97
if ( ! args . every ( value => ! value ) ) {
@@ -127,15 +134,22 @@ export const registerHandlebarHelpers = (
127
134
128
135
Handlebars . registerHelper (
129
136
'union' ,
130
- function ( this : any , properties : Model [ ] , parent : string | undefined , options : Handlebars . HelperOptions ) {
137
+ function (
138
+ this : any ,
139
+ properties : Model [ ] ,
140
+ parent : string | undefined ,
141
+ filterProperties : 'exact' | undefined ,
142
+ options : Handlebars . HelperOptions
143
+ ) {
131
144
const type = Handlebars . partials [ 'type' ] ;
132
- const types = properties . map ( property => type ( { ...root , ...property , parent } ) ) ;
133
- const uniqueTypes = types . filter ( unique ) ;
134
- let uniqueTypesString = uniqueTypes . join ( ' | ' ) ;
135
- if ( uniqueTypes . length > 1 ) {
136
- uniqueTypesString = `(${ uniqueTypesString } )` ;
145
+ const types = properties
146
+ . map ( property => type ( { ...root , ...property , parent } ) )
147
+ . filter ( ( ...args ) => filterProperties === 'exact' || unique ( ...args ) ) ;
148
+ let output = types . join ( ' | ' ) ;
149
+ if ( types . length > 1 && types . length !== properties . length ) {
150
+ output = `(${ output } )` ;
137
151
}
138
- return options . fn ( uniqueTypesString ) ;
152
+ return options . fn ( output ) ;
139
153
}
140
154
) ;
141
155
0 commit comments