Skip to content

Commit 9b81f7f

Browse files
committed
Improve description
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent c037900 commit 9b81f7f

File tree

2 files changed

+62
-62
lines changed

2 files changed

+62
-62
lines changed

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

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -27,90 +27,89 @@ related:
2727
keyword: deprecated
2828
---
2929

30-
The `description` keyword in JSON Schema is used to provide a human readable description for the schema. It does not affect data validation but serves as an informative annotation.
30+
The `description` keyword is a placeholder for a longer human-readable string
31+
summary of what a schema or any of its subschemas are about. This keyword does
32+
not affect validation, but the evaluator will collect its value as an
33+
annotation.
34+
35+
{{<best-practice>}}
36+
37+
We heavily recommend to declare this keyword at the top level of every schema,
38+
as a human-readable longer description of what the schema is about.
39+
Note that this keyword is meant to be to be used in conjunction with the
40+
[`title`]({{< ref "2020-12/meta-data/title" >}}) keyword. The idea is to
41+
augment the short summary with a longer description, and not to avoid the
42+
concise summary altogether.
43+
44+
{{</best-practice>}}
45+
46+
{{<common-pitfall>}}
47+
48+
Tooling makers must be careful when statically traversing schemas in search of
49+
occurences of this keyword. It is possible for schemas to make use of this
50+
keyword behind conditional operators, references, or any other type of keyword
51+
that makes it hard or even impossible to correctly locate these values without
52+
fully evaluating the schema against an instance. The only bullet proof method
53+
is through annotation collection.
54+
55+
{{</common-pitfall>}}
56+
57+
{{<metaschema-check-type `string`>}}
3158

3259
## Examples
3360

34-
{{<schema `Schema with 'description' keyword`>}}
61+
{{<schema `A schema that declares a top level description alongside a short title`>}}
3562
{
3663
"$schema": "https://json-schema.org/draft/2020-12/schema",
37-
"description": "The age of a person",
38-
"type": "number"
64+
"title": "Even Number",
65+
"description": "This schema describes an even number",
66+
"type": "number",
67+
"multiple": 2
3968
}
4069
{{</schema>}}
4170

42-
{{<instance-pass `An instance with a numeric value is valid`>}}
43-
45
71+
{{<instance-pass `An even number value is valid and annotations are emitted`>}}
72+
10
4473
{{</instance-pass>}}
4574

4675
{{<instance-annotation>}}
47-
{ "keyword": "/description", "instance": "", "value": "The age of a person" }
76+
{ "keyword": "/title", "instance": "", "value": "Even number" }
77+
{ "keyword": "/description", "instance": "", "value": "This schema describes an even number" }
4878
{{</instance-annotation>}}
4979

50-
{{<schema `Schema with logical operators`>}}
80+
{{<instance-fail `An odd number value is invalid no annotations are emitted`>}}
81+
7
82+
{{</instance-fail>}}
83+
84+
{{<schema `A schema that declares conditional descriptions alongside a top level title`>}}
5185
{
5286
"$schema": "https://json-schema.org/draft/2020-12/schema",
53-
"description": "Personal information of a user",
54-
"properties": {
55-
"name": { "type": "string" },
56-
"age": { "type": "number" }
57-
},
58-
"if": {
59-
"description": "if block",
60-
"properties": {
61-
"age": { "description": "Age", "minimum": 18 }
62-
}
63-
},
64-
"then": {
65-
"description": "then block",
66-
"properties": {
67-
"eligible": { "description": "Eligible", "const": true }
68-
}
69-
},
70-
"else": {
71-
"description": "else block",
72-
"properties": {
73-
"eligible": { "description": "Not eligible", "const": false }
74-
}
75-
}
87+
"title": "Number",
88+
"type": "number",
89+
"if": { "multipleOf": 2 },
90+
"then": { "description": "This is an even number" },
91+
"else": { "description": "This is an odd number" }
7692
}
7793
{{</schema>}}
7894

79-
{{<instance-pass>}}
80-
{
81-
"name": "John Doe",
82-
"age": 25,
83-
"eligible": true
84-
}
95+
{{<instance-pass `An even number value is valid and the corresponding description annotation is emitted`>}}
96+
10
8597
{{</instance-pass>}}
8698

8799
{{<instance-annotation>}}
88-
{ "keyword": "/description", "instance": "", "value": "Personal information of a user" }
89-
{ "keyword": "/if/description", "instance": "", "value": "if block" }
90-
{ "keyword": "/if/properties/age/description", "instance": "/age", "value": "Age" }
91-
{ "keyword": "/then/description", "instance": "", "value": "then block", }
92-
{ "keyword": "/then/properties/eligible/description", "instance": "/eligible", "value": "Eligible" }
100+
{ "keyword": "/title", "instance": "", "value": "Number" }
101+
{ "keyword": "/then/description", "instance": "", "value": "This is an even number" }
93102
{{</instance-annotation>}}
94103

95-
{{<schema `Schema with multiple annotations for the same instance`>}}
96-
{
97-
"$schema": "https://json-schema.org/draft/2020-12/schema",
98-
"description": "A person name",
99-
"$ref": "#/$defs/name",
100-
"$defs": {
101-
"name": {
102-
"description": "A person name",
103-
"type": "string"
104-
}
105-
}
106-
}
107-
{{</schema>}}
108-
109-
{{<instance-pass>}}
110-
"John Doe"
104+
{{<instance-pass `An odd number value is valid and the corresponding description annotation is emitted`>}}
105+
7
111106
{{</instance-pass>}}
112107

113108
{{<instance-annotation>}}
114-
{ "keyword": "/description", "instance": "", "value": "A person name" }
115-
{ "keyword": "/$ref/description", "instance": "", "value": "A person name" }
109+
{ "keyword": "/title", "instance": "", "value": "Number" }
110+
{ "keyword": "/else/description", "instance": "", "value": "This is an odd number" }
116111
{{</instance-annotation>}}
112+
113+
{{<instance-fail `A non-number value is invalid no annotations are emitted`>}}
114+
"Hello World"
115+
{{</instance-fail>}}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ related:
2828
---
2929

3030
The `title` keyword is a placeholder for a concise human-readable string
31-
description of a schema or any of its subschemas. This keyword does not affect
32-
validation, but the evaluator will collect its value as an annotation.
31+
summary of what a schema or any of its subschemas are about. This keyword does
32+
not affect validation, but the evaluator will collect its value as an
33+
annotation.
3334

3435
{{<best-practice>}}
3536

0 commit comments

Comments
 (0)