Skip to content

Commit f7c2017

Browse files
committed
Revise the deprecated keyword
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent d88e948 commit f7c2017

File tree

1 file changed

+61
-54
lines changed

1 file changed

+61
-54
lines changed

content/2020-12/meta-data/deprecated.markdown

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,89 +28,96 @@ related:
2828
keyword: writeOnly
2929
---
3030

31-
The `deprecated` keyword is used to indicate that a particular property should not be used and may be removed in the future. It provides a warning to users or applications that certain parts of the schema or are no longer recommended for use.
31+
The `deprecated` keyword, when set to `true`, signifies that an instance value
32+
(such as a specific property) should not be used and may be removed in the
33+
future. This keyword does not affect validation, but the evaluator will collect
34+
its value as an annotation.
3235

33-
* `deprecated` does not affect data validation but serves as an informative annotation.
34-
* A true value suggests that applications should avoid using the deprecated property, and the property might be removed in future versions of the schema.
36+
{{<best-practice>}}
3537

36-
## Examples
38+
Avoid setting this keyword to the default value `false`. If an instance value
39+
is not considered to be deprecated, the best practice is to omit the use of
40+
this keyword altogether. This prevents unnecessarily generating and collecting
41+
an annotation that does not carry any additional meaning.
3742

38-
{{<schema `Schema with 'deprecated' keyword`>}}
39-
{
40-
"$schema": "https://json-schema.org/draft/2020-12/schema",
41-
"deprecated": true,
42-
"type": "number"
43-
}
44-
{{</schema>}}
43+
{{</best-practice>}}
4544

46-
{{<instance-pass `An instance with a numeric value is valid`>}}
47-
45
48-
{{</instance-pass>}}
45+
{{<common-pitfall>}}
4946

50-
{{<instance-annotation>}}
51-
{ "keyword": "/deprecated", "instance": "", "value": true }
52-
{{</instance-annotation>}}
47+
Tooling makers must be careful when statically traversing schemas in search of
48+
occurences of this keyword. It is possible for schemas to make use of this
49+
keyword behind conditional operators, references, or any other type of keyword
50+
that makes it hard or even impossible to correctly locate these values without
51+
fully evaluating the schema against an instance. The only bullet proof method
52+
is through annotation collection.
53+
54+
For example, an instance property might only be deprecated under certain
55+
conditions determined by a dynamic operator like [`anyOf`]({{< ref
56+
"2020-12/applicator/anyof" >}}).
57+
58+
{{</common-pitfall>}}
59+
60+
{{<metaschema-check-type `boolean`>}}
5361

54-
{{<schema `Schema with logical operators`>}}
62+
## Examples
63+
64+
{{<schema `A schema that statically marks the city optional object property as deprecated`>}}
5565
{
5666
"$schema": "https://json-schema.org/draft/2020-12/schema",
5767
"properties": {
58-
"foo": { "type": "boolean" },
59-
"bar": { "type": "string" }
60-
},
61-
"if": {
62-
"properties": {
63-
"foo": { "const": true }
64-
}
65-
},
66-
"then": {
67-
"properties": {
68-
"bar": { "deprecated": true }
69-
}
70-
},
71-
"else": {
72-
"properties": {
73-
"bar": { "deprecated": false }
74-
}
68+
"country": { "type": "string" },
69+
"city": { "type": "string", "deprecated": true }
7570
}
7671
}
7772
{{</schema>}}
7873

79-
{{<instance-pass>}}
80-
{ "foo": false, "bar": "bar" }
74+
{{<instance-pass `An object value that defines the deprecated property is valid but an annotation is emitted`>}}
75+
{ "country": "United Kingdom", "city": "London" }
8176
{{</instance-pass>}}
8277

8378
{{<instance-annotation>}}
84-
{ "keyword": "/else/properties/bar/deprecated", "instance": "/bar", "value": false }
79+
{ "keyword": "/properties/city/deprecated", "instance": "/city", "value": true }
8580
{{</instance-annotation>}}
8681

87-
{{<instance-pass>}}
88-
{ "foo": true, "bar": "bar" }
82+
{{<instance-pass `An object value that does not define the deprecated property is valid and no annotation is emitted`>}}
83+
{ "country": "United Kingdom" }
8984
{{</instance-pass>}}
9085

91-
{{<instance-annotation>}}
92-
{ "keyword": "/then/properties/bar/deprecated", "instance": "/bar", "value": true }
93-
{{</instance-annotation>}}
86+
{{<instance-fail `An object value that does not match the schema is invalid and no annotations are emitted`>}}
87+
{ "city": 1 }
88+
{{</instance-fail>}}
9489

95-
{{<schema `Schema with multiple annotations for the same instance`>}}
90+
{{<schema `A schema that dynamically marks the city optional object property as deprecated based on the presence of the country property`>}}
9691
{
9792
"$schema": "https://json-schema.org/draft/2020-12/schema",
98-
"deprecated": true,
99-
"$ref": "#/$defs/name",
100-
"$defs": {
101-
"name": {
102-
"deprecated": true,
103-
"type": "string"
93+
"properties": {
94+
"country": { "type": "string" },
95+
"city": { "type": "string" }
96+
},
97+
"dependentSchemas": {
98+
"country": {
99+
"properties": { "city": { "deprecated": true } }
104100
}
105101
}
106102
}
107103
{{</schema>}}
108104

109-
{{<instance-pass>}}
110-
"John Doe"
105+
{{<instance-pass `An object value that defines both properties is valid but an annotation is emitted`>}}
106+
{ "country": "United Kingdom", "city": "London" }
111107
{{</instance-pass>}}
112108

113109
{{<instance-annotation>}}
114-
{ "keyword": "/deprecated", "instance": "", "value": true }
115-
{ "keyword": "/$ref/deprecated", "instance": "", "value": true }
110+
{ "keyword": "/dependentSchemas/country/properties/city/deprecated", "instance": "/city", "value": true }
116111
{{</instance-annotation>}}
112+
113+
{{<instance-pass `An object value that only defines the city property is valid and no annotation is emitted`>}}
114+
{ "city": "London" }
115+
{{</instance-pass>}}
116+
117+
{{<instance-pass `An object value that only defines the country property is valid and no annotation is emitted`>}}
118+
{ "country": "United Kingdom" }
119+
{{</instance-pass>}}
120+
121+
{{<instance-fail `An object value that does not match the schema is invalid and no annotations are emitted`>}}
122+
{ "city": 1 }
123+
{{</instance-fail>}}

0 commit comments

Comments
 (0)