allof-contradictory-constraints
Finds an allOf whose branches give a required property no possible value.
| Attribute | Value |
|---|---|
| Category | Schema |
| Maturity | Platinum |
| OpenAPI | Swagger 2.0; OpenAPI 3.0, 3.1, 3.2 |
| Starter | Off |
| Lenient | Warning |
| Recommended–Complete | Error |
Intent
Every allOf branch must hold at the same time. Non-overlapping enum or const values for a required property make the combined schema impossible to satisfy.
Flags
Two or more inline or referenced allOf branches that constrain the same required property to finite, non-overlapping values. A property counts as required when the parent requires it, or every constraining branch does.
Does not flag
Optional properties, value sets with at least one shared value, or constraints that are not expressed with enum or const.
See it fail
Pet:
type: object
required: [kind]
allOf:
- type: object
properties:
kind:
type: string
enum: [cat]
- type: object
properties:
kind:
type: string
enum: [dog]
kind must be both cat and dog, which is impossible.
Fix it
Give the branches an overlapping value, or use oneOf when they represent alternatives:
Pet:
oneOf:
- type: object
required: [kind]
properties:
kind:
type: string
enum: [cat]
- type: object
required: [kind]
properties:
kind:
type: string
enum: [dog]
Configure
profiles:
default:
rules:
extends: [recommended]
override:
allof-contradictory-constraints: warn
Nearby: enum-no-matching-values, duplicate-oneof-discriminator.