Support to validate uniqueness of values or keys in Type.Array() and Type.Array(Type.Object()) #1036
regis-underdog
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have found a couple of patterns popping up in my schemas: needing to validate that a schema has a field, say,
name
but that the name should be "unique". I also have arrays with values that I would like to validate were full of unique values.For arrays, something like this:
Another possibility since the semantics of my idea seems wrong (you'll see why this gets complicated in the second example):
For Arrays of Objects it gets complicated and I have to constantly write out-of-band validators myself. For example, unique keys of
name
in the array of objects:I am not sure how to best express the object-key value being unique in this scenario and hopefully it would be general enough to extend for both of these (and other use cases too) since the first example is just an array of unique objects and the second is an array of unique-ish object key-values.
Note: I understand this would not be compatible with the JSON Schema definitions and might be outside the scope of Typebox core functionality. I do see this pattern crop up frequently and I currently need to write out-of-band validators for uniqueness in lots of different places, so I'm hoping it would be valuable!
Beta Was this translation helpful? Give feedback.
All reactions