@@ -93,7 +93,26 @@ export function getFilterJsonSchemaFor(
93
93
minimum : 1 ,
94
94
examples : [ 100 ] ,
95
95
} ,
96
-
96
+ sum : {
97
+ type : 'string' ,
98
+ examples : [ 'column1' ] ,
99
+ } ,
100
+ min : {
101
+ type : 'string' ,
102
+ examples : [ 'column1' ] ,
103
+ } ,
104
+ max : {
105
+ type : 'string' ,
106
+ examples : [ 'column1' ] ,
107
+ } ,
108
+ avg : {
109
+ type : 'string' ,
110
+ examples : [ 'column1' ] ,
111
+ } ,
112
+ count : {
113
+ type : 'string' ,
114
+ examples : [ 'column1' ] ,
115
+ } ,
97
116
skip : {
98
117
type : 'integer' ,
99
118
minimum : 0 ,
@@ -120,6 +139,9 @@ export function getFilterJsonSchemaFor(
120
139
if ( ! excluded . includes ( 'fields' ) ) {
121
140
properties . fields = getFieldsJsonSchemaFor ( modelCtor , options ) ;
122
141
}
142
+ if ( ! excluded . includes ( 'groupBy' ) ) {
143
+ properties . fields = getGroupByJsonSchemaFor ( modelCtor , options ) ;
144
+ }
123
145
124
146
// Remove excluded properties
125
147
for ( const p of excluded ) {
@@ -235,3 +257,37 @@ export function getFieldsJsonSchemaFor(
235
257
236
258
return schema ;
237
259
}
260
+
261
+ export function getGroupByJsonSchemaFor (
262
+ modelCtor : typeof Model ,
263
+ options : FilterSchemaOptions = { } ,
264
+ ) : JsonSchema {
265
+ const schema : JsonSchema = { oneOf : [ ] } ;
266
+ if ( options . setTitle !== false ) {
267
+ schema . title = `${ modelCtor . modelName } .GroupBy` ;
268
+ }
269
+
270
+ const properties = Object . keys ( modelCtor . definition . properties ) ;
271
+ const additionalProperties = modelCtor . definition . settings . strict === false ;
272
+
273
+ schema . oneOf ?. push ( {
274
+ type : 'object' ,
275
+ properties : properties . reduce (
276
+ ( prev , crr ) => ( { ...prev , [ crr ] : { type : 'boolean' } } ) ,
277
+ { } ,
278
+ ) ,
279
+ additionalProperties,
280
+ } ) ;
281
+
282
+ schema . oneOf ?. push ( {
283
+ type : 'array' ,
284
+ items : {
285
+ type : 'string' ,
286
+ enum : properties . length && ! additionalProperties ? properties : undefined ,
287
+ examples : properties ,
288
+ } ,
289
+ uniqueItems : true ,
290
+ } ) ;
291
+
292
+ return schema ;
293
+ }
0 commit comments