@@ -94,6 +94,32 @@ export function getFilterJsonSchemaFor(
9494 examples : [ 100 ] ,
9595 } ,
9696
97+ sum : {
98+ type : 'string' ,
99+ examples : [ 'column1' ] ,
100+ } ,
101+ min : {
102+ type : 'string' ,
103+ examples : [ 'column1' ] ,
104+ } ,
105+ max : {
106+ type : 'string' ,
107+ examples : [ 'column1' ] ,
108+ } ,
109+ avg : {
110+ type : 'string' ,
111+ examples : [ 'column1' ] ,
112+ } ,
113+ count : {
114+ type : 'string' ,
115+ examples : [ 'column1' ] ,
116+ } ,
117+ groupBy : {
118+ type : 'array' ,
119+ items : {
120+ type : 'string' ,
121+ } ,
122+ } ,
97123 skip : {
98124 type : 'integer' ,
99125 minimum : 0 ,
@@ -120,6 +146,9 @@ export function getFilterJsonSchemaFor(
120146 if ( ! excluded . includes ( 'fields' ) ) {
121147 properties . fields = getFieldsJsonSchemaFor ( modelCtor , options ) ;
122148 }
149+ if ( ! excluded . includes ( 'groupBy' ) ) {
150+ properties . fields = getGroupByJsonSchemaFor ( modelCtor , options ) ;
151+ }
123152
124153 // Remove excluded properties
125154 for ( const p of excluded ) {
@@ -235,3 +264,37 @@ export function getFieldsJsonSchemaFor(
235264
236265 return schema ;
237266}
267+
268+ export function getGroupByJsonSchemaFor (
269+ modelCtor : typeof Model ,
270+ options : FilterSchemaOptions = { } ,
271+ ) : JsonSchema {
272+ const schema : JsonSchema = { oneOf : [ ] } ;
273+ if ( options . setTitle !== false ) {
274+ schema . title = `${ modelCtor . modelName } .GroupBy` ;
275+ }
276+
277+ const properties = Object . keys ( modelCtor . definition . properties ) ;
278+ const additionalProperties = modelCtor . definition . settings . strict === false ;
279+
280+ schema . oneOf ?. push ( {
281+ type : 'object' ,
282+ properties : properties . reduce (
283+ ( prev , crr ) => ( { ...prev , [ crr ] : { type : 'boolean' } } ) ,
284+ { } ,
285+ ) ,
286+ additionalProperties,
287+ } ) ;
288+
289+ schema . oneOf ?. push ( {
290+ type : 'array' ,
291+ items : {
292+ type : 'string' ,
293+ enum : properties . length && ! additionalProperties ? properties : undefined ,
294+ examples : properties ,
295+ } ,
296+ uniqueItems : true ,
297+ } ) ;
298+
299+ return schema ;
300+ }
0 commit comments