diff --git a/packages/repository-json-schema/src/filter-json-schema.ts b/packages/repository-json-schema/src/filter-json-schema.ts index 9ced979baaa7..14ac016221e1 100644 --- a/packages/repository-json-schema/src/filter-json-schema.ts +++ b/packages/repository-json-schema/src/filter-json-schema.ts @@ -93,7 +93,26 @@ export function getFilterJsonSchemaFor( minimum: 1, examples: [100], }, - + sum: { + type: 'string', + examples: ['column1'], + }, + min: { + type: 'string', + examples: ['column1'], + }, + max: { + type: 'string', + examples: ['column1'], + }, + avg: { + type: 'string', + examples: ['column1'], + }, + count: { + type: 'string', + examples: ['column1'], + }, skip: { type: 'integer', minimum: 0, @@ -120,6 +139,9 @@ export function getFilterJsonSchemaFor( if (!excluded.includes('fields')) { properties.fields = getFieldsJsonSchemaFor(modelCtor, options); } + if (!excluded.includes('groupBy')) { + properties.fields = getGroupByJsonSchemaFor(modelCtor, options); + } // Remove excluded properties for (const p of excluded) { @@ -235,3 +257,37 @@ export function getFieldsJsonSchemaFor( return schema; } + +export function getGroupByJsonSchemaFor( + modelCtor: typeof Model, + options: FilterSchemaOptions = {}, +): JsonSchema { + const schema: JsonSchema = {oneOf: []}; + if (options.setTitle !== false) { + schema.title = `${modelCtor.modelName}.GroupBy`; + } + + const properties = Object.keys(modelCtor.definition.properties); + const additionalProperties = modelCtor.definition.settings.strict === false; + + schema.oneOf?.push({ + type: 'object', + properties: properties.reduce( + (prev, crr) => ({...prev, [crr]: {type: 'boolean'}}), + {}, + ), + additionalProperties, + }); + + schema.oneOf?.push({ + type: 'array', + items: { + type: 'string', + enum: properties.length && !additionalProperties ? properties : undefined, + examples: properties, + }, + uniqueItems: true, + }); + + return schema; +} diff --git a/packages/repository/src/repositories/legacy-juggler-bridge.ts b/packages/repository/src/repositories/legacy-juggler-bridge.ts index 3df52ed95514..2f89a34514a8 100644 --- a/packages/repository/src/repositories/legacy-juggler-bridge.ts +++ b/packages/repository/src/repositories/legacy-juggler-bridge.ts @@ -739,7 +739,7 @@ export class DefaultCrudRepository< } protected toEntity(model: juggler.PersistedModel): R { - return new this.entityClass(model.toObject()) as R; + return new this.entityClass(model.toObject({onlySchema: false})) as R; } protected toEntities(models: juggler.PersistedModel[]): R[] {