Making specific fields optional in a schema definition

Is there some way to do a
partial
or required but only for specific fields? For example, I'm having:

    Schema.Struct({
      id: Schema.String,
      title: Schema.String,
      content: Schema.optional(Schema.String),
      order: Schema.Number,
      columnId: Schema.String,
      boardId: Schema.String,
    }),


And I want the following result:

    Schema.Struct({
      id: Schema.String,
      title: Schema.optional(Schema.String),
      content: Schema.optional(Schema.String),
      order: Schema.optional(Schema.Number),
      columnId: Schema.optional(Schema.String),
      boardId: Schema.String,
    }),


So either specify which fields may be optional, or specify which should stay required. Currently I'm doing the following, but I thought there may be a cleaner way:

  OriginalSchema.pipe((schema) =>
    schema.pipe(
      Schema.pick("boardId", "_id"),
      Schema.extend(schema.pipe(Schema.omit("boardId", "_id"), Schema.partial)),
    ),
  ),
Was this page helpful?