Ignore entry that does not respect a schema
See original GitHub issueHey there,
Is there a way to filter element of an array that does not match our schema?
For example I have this schema:
enum BarType {
Big = "big",
Small = "small",
}
const schema = z.object({
foo_id: z.string(),
bars: z.array(
z.object({
id: z.string(),
type: z.nativeEnum(BarType),
}),
),
});
Is there a way to ignore in the bars
entries all the type that are not valid BarType
enum?
Here a gist with a complete example: https://gist.github.com/armandabric/f88bf690ade47d292ef3cec11716d41f
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Understanding schema errors
Schema checks ensure that the code returned is as included in the list of valid entries for the field as can be found...
Read more >How to configure Swashbuckle to ignore property on model
Our models are shared with some legacy interfaces so there are a couple of properties I want to ignore on the models. I...
Read more >Configure schema inference and evolution in Auto Loader
Schema is never evolved and stream does not fail due to schema changes. All new columns are recorded in the rescued data column....
Read more >Docs: Options
Schema management system for MySQL and MariaDB. Free open-source command-line tool. SaaS schema linter solution with GitHub integration.
Read more >Referential actions
For all other database providers, Prisma rejects the schema with a validation error. SQL Server. Restrict is not available for SQL Server databases,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ho my bad! It works perfectly by replacing the
z.any()
in the preprocess.Thanks again
Ahh, you said “foo id”, so I thought you meant the
foo_id
property of the base schema. You can make the input schema as strict as you want instead of usingz.any()
. I’ve updated on the CodeSandbox.