Merge schemas
When we define a schema using Guard, the schema will be added to a route. But it will be overridden if the route provides a schema:
import { Elysia, t } from 'elysia'
// This will override the guard schema
If we want a schema to co-exist with route schema, we can define it as merged guard schema:
import { Elysia, t } from 'elysia'
// body will have both age and name property
Schema library interoperability
Schemas between merged guard schemas can be from different validation libraries.
For example you can define a merged guard schema using zod, and a local schema using t from elysia, and both will works interchangeably.
Assignment
Let’s make both age and name properties required in the request body by using merged guard schema.