From c1c715db50a79fd3dd1f57df6076b6b86bcbfd8d Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Mon, 30 Sep 2019 18:06:16 +1000 Subject: [PATCH] feat(schema): make schema nullable by default --- src/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5b4fa47..04a81ee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,7 +47,7 @@ export function namedSchema( * @param objectSchema The initial schema */ export function schema( - objectSchema: ObjectSchema = yup.object() + objectSchema: ObjectSchema = yup.object().nullable(true) ): ClassDecorator { return target => { defineSchema(target, objectSchema); @@ -85,12 +85,15 @@ export function nested(): PropertyDecorator { return; } // if the schema was not registered via @schema, build one for it automatically - registeredSchema = defineSchema(nestedType, yup.object()); + registeredSchema = defineSchema( + nestedType, + yup.object().nullable(true) + ); } metadataStorage.addSchemaMetadata({ target: target instanceof Function ? target : target.constructor, property, - schema: registeredSchema, + schema: registeredSchema.clone().nullable(true), }); }; }