Skip to content

How to define "at least one property required"? #518

Answered by davideroffo
davideroffo asked this question in Q&A
Discussion options

You must be logged in to vote

I solved it by using minProperties: 1 in conjunction with additionalProperties: false, following this Stack Overflow answer: https://stackoverflow.com/a/75233932/5830331 .

const server = Fastify({
  ajv: {
    customOptions: {
      removeAdditional: false
    }
  }
})

const Schema = Type.Partial(
  Type.Object({
    a: Type.String(),
    b: Type.String(),
    c: Type.String()
  })
, { minProperties: 1, additionalProperties: false })

Value.Check(Schema, { d: '' })               // false

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@davideroffo
Comment options

@davideroffo
Comment options

Answer selected by davideroffo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants