Skip to content
Permalink
Browse files

fix: objectSchema to allow partial schemas

  • Loading branch information...
kirillgroshkov committed May 19, 2019
1 parent 4ce1477 commit 2c55a6e465c3069d109e821758b43329d9b30ac8
Showing with 6 additions and 1 deletion.
  1. +1 −1 src/validation/joi/joi.shared.schemas.ts
  2. +5 −0 src/validation/joi/joi.validation.util.test.ts
@@ -14,7 +14,7 @@ export function arraySchema<T> (items?: AnySchemaT<T, T>): ArraySchemaTyped<T> {
}

export function objectSchema<IN, OUT = IN> (
schema?: { [key in keyof IN]: AnySchemaT<IN[key]> },
schema?: { [key in keyof Partial<IN>]: AnySchemaT<IN[key]> },
): ObjectSchemaTyped<IN, OUT> {
return Joi.object(schema)
}
@@ -266,3 +266,8 @@ test('default to empty array', () => {
),
).toEqual([])
})

// Checking that partial schema is allowed (not all keys of Obj1 are required)
const _partialSchema = objectSchema<Obj1>({
a2: stringSchema,
})

0 comments on commit 2c55a6e

Please sign in to comment.
You can’t perform that action at this time.