Search code examples
meteorsimple-schema

How to modify an already constructed schema


I'm using a third party package that defines a schema like this:

People.schema = new SimpleSchema({
  firstName: {
    type: String,
    optional: false
  }
  //Many other fields defined...
});

I would like to modify it to have optional: true for the first name without changing the source code for the third party package.

I could use People.schema.pick to get a schema with all of the fields except the firstName, and then combine this with another schema with firstName as optional. But this method would require listing all of the fields in the schema in the pick function, which is tedious.

Is there a better way of accomplishing this?


Solution

  • I can edit the object simple schema creates just like any other object: People.schema._schema.firstName.optional = true.

    To override the field.