diff --git a/packages/schema/src/json-schema.ts b/packages/schema/src/json-schema.ts index 86e414a557..aaa594ed19 100644 --- a/packages/schema/src/json-schema.ts +++ b/packages/schema/src/json-schema.ts @@ -112,14 +112,20 @@ export const queryProperty = { } } - const validator = new Ajv({ strict: false }).compile(schema) + const validator = new Ajv({ strict: false }).compile(querySchema) + + assert.ok(validator(q)) + }) + + it('$in and $nin works with array definitions', async () => { + const schema = { + things: { + type: 'array', + items: { type: 'number' } + } + } as const + + const querySchema = { + type: 'object', + properties: querySyntax(schema) + } as const + + type Query = FromSchema + + const q: Query = { + things: { + $in: [10, 20], + $nin: [30] + } + } + + const validator = new Ajv({ strict: false }).compile(querySchema) assert.ok(validator(q)) }) diff --git a/packages/typebox/src/index.ts b/packages/typebox/src/index.ts index f6b5f8e2cc..b14e549101 100644 --- a/packages/typebox/src/index.ts +++ b/packages/typebox/src/index.ts @@ -110,8 +110,8 @@ export const queryProperty = { }) }) + it('$in and $nin works with array type', async () => { + const schema = Type.Object({ + things: Type.Array(Type.Number()) + }) + const querySchema = querySyntax(schema) + const validator = new Ajv().compile(querySchema) + + type Query = Static + + const query: Query = { + things: { + $in: [10, 20], + $nin: [30] + } + } + + const validated = (await validator(query)) as any as Query + + assert.ok(validated) + }) + it('defaultAppConfiguration', async () => { const configSchema = Type.Intersect([ defaultAppConfiguration,