@@ -6,6 +6,15 @@ The `propertyDependencies` keyword is a more friendly way to select between two
6
6
or more schemas to validate an instance against than is currently supported by
7
7
JSON Schema.
8
8
9
+ ## Current Status
10
+
11
+ This proposal is complete and awaiting integration into the specification.
12
+
13
+ As some additional context, this proposal has been written prior to the stable
14
+ specification's initial release. As such, it will not be integrated until at
15
+ least the spec's second release at the earliest. It is also operating as a
16
+ proving grounds, of sorts, for the SDLC's Feature Life Cycle.
17
+
9
18
## Note to Readers
10
19
11
20
The issues list for this document can be found at
@@ -30,7 +39,7 @@ specification](../jsonschema-core.html) also apply to this document.
30
39
A common need in JSON Schema is to select between one schema or another to
31
40
validate an instance based on the value of some property in the JSON instance.
32
41
There are a several patterns people use to accomplish this, but they all have
33
- significant [ problems] ( #problems ) .
42
+ significant [ problems] ( propertyDependencies-adr.md #problems) . <!-- Update when moving ADR -->
34
43
35
44
OpenAPI solves this problem with the ` discriminator ` keyword. However, their
36
45
approach is more oriented toward code generation concerns, is poorly specified
@@ -113,73 +122,11 @@ subsection of "Keywords for Applying Subschemas Conditionally".
113
122
}
114
123
```
115
124
116
- ## [Appendix] Problems With Existing Patterns {#problems}
117
-
118
- ### `oneOf`/`anyOf`
119
-
120
- The pattern of using `oneOf` to describe a choice between two schemas has become
121
- ubiquitous.
122
-
123
- ```jsonschema
124
- {
125
- "oneOf" : [
126
- { "$ref" : " #/$defs/aaa" },
127
- { "$ref" : " #/$defs/bbb" }
128
- ]
129
- }
130
- ```
131
-
132
- However, this pattern has several shortcomings. The main problem is that it
133
- tends to produce confusing error messages. Some implementations employ
134
- heuristics to guess the user's intent and provide better messaging, but that's
135
- not wide-spread or consistent behavior, nor is it expected or required from
136
- implementations.
137
-
138
- This pattern is also inefficient. Generally, there is a single value in the
139
- object that determines which alternative to chose, but the ` oneOf ` pattern has
140
- no way to specify what that value is and therefore needs to evaluate the entire
141
- schema. This is made worse in that every alternative needs to be fully validated
142
- to ensure that only one of the alternative passes and all the others fail. This
143
- last problem can be avoided by using ` anyOf ` instead, but that pattern is much
144
- less used.
145
-
146
- ### ` if ` /` then `
147
-
148
- We can describe this kind of constraint more efficiently and with with better
149
- error messaging by using ` if ` /` then ` . This allows the user to explicitly specify
150
- the constraint to be used to select which alternative the schema should be used
151
- to validate the schema. However, this pattern has problems of it's own. It's
152
- verbose, error prone, and not particularly intuitive, which leads most people to
153
- avoid it.
154
-
155
- ``` jsonschema
156
- {
157
- "allOf": [
158
- {
159
- "if": {
160
- "properties": {
161
- "foo": { "const": "aaa" }
162
- },
163
- "required": ["foo"]
164
- },
165
- "then": { "$ref": "#/$defs/foo-aaa" }
166
- },
167
- {
168
- "if": {
169
- "properties": {
170
- "foo": { "const": "bbb" }
171
- },
172
- "required": ["foo"]
173
- },
174
- "then": { "$ref": "#/$defs/foo-bbb" }
175
- }
176
- ]
177
- }
178
- ```
179
-
180
125
## [Appendix] Change Log
181
126
182
- * [ October 2023] Created
127
+ * [March 2021] - Initially proposed
128
+ * [October 2021] Added to specification document
129
+ * [May 2024] Extracted from specification document as experimental feature
183
130
184
131
## Champions
185
132
0 commit comments