New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combining multiple schemas #232
Comments
Apparently .concat can be chained. I managed to join multiple schemas as shown by the example below:
|
A generic implementation could like this: function merge(...schemas) {
const [first, ...rest] = schemas;
const merged = rest.reduce(
(mergedSchemas, schema) => mergedSchemas.concat(schema),
first
);
return merged;
}
// usage:
const merged = merge(schema1, schema2, schema3, etc); |
Another implementation could look like this: const schema1 = object({
a: string(),
b: array(),
});
const schema2 = schema1.shape({
b: object(),
});
const schema2 = object({
a: string(),
b: object(),
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I'm trying to combine several schemas into 1 and the documentation mentioned that only 2 schemas can be combined using "concat"
I have kind of achieved it by chaining "concat" after one another but I'm wondering if there's a more elegant of achieving it.
Here is the example:
The text was updated successfully, but these errors were encountered: