eivindfjeldstad/validate

What is the right way to extend a schema?

Opened this issue · 1 comments

I'm trying to figure out how to 'extend' a schema (i.e. create a schema that inherits properties from a parent schema).

This is how I'm doing it:

const Vehicle = new Schema({
  color: String
})

const Car = new Schema({
   ...Vehicle.props,
   licensePlate: String
})

Is this the right way to do it?

Can't you do like this?

const vehicleShape = {
  color: String
}

const VehicleSchema = new Schema(vehicleShape)

const CarSchema = new Schema({
   ...vehicleShape,
   licensePlate: String
})

Let me know if it worked for you!
tks