Closed truc3651 closed 2 years ago
That's the neat thing: you don't :)
Just extract part of the schema into a function and use it in validators.
There are many ways to do it just using the language constructs. Following is a one simple example.
const sharedSchema = {
page: schema.number.optional([]),
limit: schema.number.optional([]),
order: schema.enum.optional(['ascend', 'descend']),
orderBy: schema.string.optional(),
keyword: schema.string.optional(),
}
schema.create({
...sharedSchema
})
schema.create({
...sharedSchema,
filterBy: schema.enum.optional(this.refs.filterBy)
})
I have a PaginationValidator (used to valdiate api list data)
There's some apis has its own schema fields, and I want to expand PaginationValidator schema (page, limit ...) with these extended fields
maybe
How can I extend the validator?