@@ -93,7 +93,26 @@ export function getFilterJsonSchemaFor(
9393 minimum : 1 ,
9494 examples : [ 100 ] ,
9595 } ,
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+ } ,
97116 skip : {
98117 type : 'integer' ,
99118 minimum : 0 ,
@@ -120,6 +139,9 @@ export function getFilterJsonSchemaFor(
120139 if ( ! excluded . includes ( 'fields' ) ) {
121140 properties . fields = getFieldsJsonSchemaFor ( modelCtor , options ) ;
122141 }
142+ if ( ! excluded . includes ( 'groupBy' ) ) {
143+ properties . fields = getGroupByJsonSchemaFor ( modelCtor , options ) ;
144+ }
123145
124146 // Remove excluded properties
125147 for ( const p of excluded ) {
@@ -235,3 +257,37 @@ export function getFieldsJsonSchemaFor(
235257
236258 return schema ;
237259}
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