question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignore entry that does not respect a schema

See original GitHub issue

Hey 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:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
armandabriccommented, Sep 2, 2021

Ho my bad! It works perfectly by replacing the z.any() in the preprocess.

Thanks again

0reactions
scotttrinhcommented, Sep 2, 2021

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 using z.any(). I’ve updated on the CodeSandbox.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found