How to define "at least one property required"? #518
Answered
by
davideroffo
davideroffo
asked this question in
Q&A
-
Good evening, everyone 🌆
Basically, I want to ensure that at least one of the parameters |
Beta Was this translation helpful? Give feedback.
Answered by
davideroffo
Aug 3, 2023
Replies: 1 comment 2 replies
-
@davideroffo Hi, Try const Schema = Type.Partial(
Type.Object({
a: Type.String(),
b: Type.String(),
c: Type.String()
})
, { minProperties: 1 })
// tests
//
import { Value } from '@sinclair/typebox/value'
Value.Check(Schema, { a: '', b: '', c: '' }) // true
Value.Check(Schema, { a: '', b: '' }) // true
Value.Check(Schema, { a: '' }) // true
Value.Check(Schema, { b: '' }) // true
Value.Check(Schema, { c: '' }) // true
Value.Check(Schema, {}) // false |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I solved it by using
minProperties: 1
in conjunction withadditionalProperties: false
, following this Stack Overflow answer: https://stackoverflow.com/a/75233932/5830331 .