Skip to content

Commit

Permalink
feat(schema): make schema nullable by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuan Nguyen committed Sep 30, 2019
1 parent 6fee527 commit c1c715d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function namedSchema(
* @param objectSchema The initial schema
*/
export function schema(
objectSchema: ObjectSchema = yup.object()
objectSchema: ObjectSchema<object | null> = yup.object().nullable(true)
): ClassDecorator {
return target => {
defineSchema(target, objectSchema);
Expand Down Expand Up @@ -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),
});
};
}
Expand Down

0 comments on commit c1c715d

Please sign in to comment.