Remove empty anyOf
See original GitHub issueI have the following schema to add support for mongodb ObjectId
type:
export const objectId = z.union([
z.instanceof(ObjectId),
z
.string()
.regex(/^[a-f0-9]{24}$/, { message: "This string does not look like an ObjectId()" })
.transform((s) => new ObjectId(s))
]);
This translates to the following schema:
{
anyOf: [ {}, { type: 'string', pattern: '^[a-f0-9]{24}$' } ]
}
The issue is that {}
allows for any input. I think it would be more appropriate to imply that z.instanceOf()
cannot be translated into a JSON Schema and therefore should never be able to match anything somehow.
Does that make any sense?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Remove empty Objects from Array - javascript - Stack Overflow
I already use _.uniq from underscore.js to remove all duplicates from my array, which works fine. Though they are unique, one empty Object...
Read more >Removing Array variable if it is empty
I have a series of Arrays that I am creating and adding into a compose to get them showing in a line by...
Read more >Split a String removing any Empty Elements in JavaScript
To split a string and remove any empty elements from the array, call the `split()` method on the string to get an array...
Read more >How To Remove Empty Array Elements In PHP | Lee Blue
Quick PHP tip: It is common to want to explode a string based on some delimiting character, then iterate over the array.
Read more >Modifying data during validation - Ajv JSON schema validator
Ajv has several options that allow to modify data during validation: removeAdditional - to remove properties not defined in the schema object. useDefaults...
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
Hey! This seems like a reasonable option at lest for the time being yes.
@qraynaud Hey, I just released 3.18.1 which adds a
strictUnion
option. Let me know if this solves your problem. If so I think we can close this