Are allOf and properties keywords interchangeable?

182 views Asked by At

I need to represent various data and basically combine multiple json schema into one. As far as I understand this can be accomplished in two ways:

  • using allOf
  • using properties

Is there any difference between them? Could something that I would write as property be invalid if I write in a new schema appended in allOf-> property and vice-versa?

1

There are 1 answers

0
jruizaranguren On

They are pretty different. Informal meaning:

  • property: if you have this property, it has to satisfy the following schema.
  • allOf: the object must satisfy all schemas included in the allOf array.

Relating to your last question, if you make exactly the same constraints in a property, and in a schema within the allOf key, you will have the same semantics.

But in an allOf clause you may have a more rich set of constraints that affect not only a property but the object itself (maxProperties, additionalProperties, patternProperties, etc.). It can also be used to organize complex schemas or split domains.