Skip to content

Commit 55308a3

Browse files
committed
Revise contentSchema
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 2c42434 commit 55308a3

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

content/2020-12/content/contentMediaType.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ registered category and prefixed with `x-`. For example,
101101
{ "keyword": "/contentMediaType", "instance": "", "value": "text/html" }
102102
{{</instance-annotation>}}
103103

104-
{{<instance-pass `A string value that represents an invalid HTML document encoded in Base 64 is valid and an annotations are emitted`>}}
104+
{{<instance-pass `A string value that represents an invalid HTML document encoded in Base 64 is valid and an annotations are still emitted`>}}
105105
"PFwvZm9v" // <\/foo
106106
{{</instance-pass>}}
107107

content/2020-12/content/contentSchema.markdown

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,28 @@ related:
2323
keyword: contentEncoding
2424
---
2525

26-
The `contentSchema` keyword allows you to specify a schema that describes the structure of the content within a string instance, particularly when used in conjunction with the `contentMediaType` keyword. This is useful when the string instance contains data conforming to the JSON data model.
26+
When the [`contentMediaType`]({{< ref "2020-12/content/contentmediatype" >}})
27+
keyword is set to a media type that adheres to the JSON data model (like JSON
28+
itself, [YAML](https://yaml.org) or [UBJSON](https://ubjson.org)), the
29+
`contentSchema` keyword declares the schema that describes the corresponding
30+
string instance value _after_ decoding it. This keyword does not affect
31+
validation, but the evaluator will collect its value as an annotation.
2732

28-
However, it's important to note that `contentSchema` is merely an annotation and is not directly involved in the validation process. Instead, applications that consume JSON Schemas must use this information as they see fit. `contentSchema` must be a valid JSON Schema, but it is ignored if `contentMediaType` is absent.
33+
{{<common-pitfall>}}
2934

30-
Applications utilizing JSON Schemas are expected to use the provided `contentSchema` to validate content if applicable. If a schema is provided but does not match the content structure, it should be considered an error.
35+
The JSON Schema specification prohibits implementations, for security reasons,
36+
from automatically attempting to decode, parse, or validate encoded data
37+
without the consumer explicitly opting in to such behaviour. If you require
38+
this feature, consult the documentation of your tooling of choice to see if it
39+
supports content encoding/decoding and how to enable it.
40+
41+
{{</common-pitfall>}}
42+
43+
{{<constraint-warning `string`>}}
3144

3245
## Examples
3346

34-
{{<schema `Schema with 'contentSchema', 'contentMediaType' and 'contentEncoding' keyword`>}}
47+
{{<schema `A schema that describes JSON object values encoded using Base 64`>}}
3548
{
3649
"$schema": "https://json-schema.org/draft/2020-12/schema",
3750
"contentMediaType": "application/json",
@@ -40,16 +53,38 @@ Applications utilizing JSON Schemas are expected to use the provided `contentSch
4053
}
4154
{{</schema>}}
4255

43-
{{<instance-pass `An instance with a properly stringified JSON document encoded in base64 is valid`>}}
44-
"eyAibmFtZSI6ICJKb2huIERvZSIgfQ==" // --> { "name": "John Doe" }
56+
{{<instance-pass `A string value that represents a valid JSON object encoded in Base 64 is valid and an annotations are emitted`>}}
57+
"eyAibmFtZSI6ICJKb2huIERvZSIgfQ==" // { "name": "John Doe" }
4558
{{</instance-pass>}}
4659

47-
{{<instance-pass `An encoded value that represents invalid JSON data is still valid`>}}
48-
"eyAibmFtZSI6IH0=" // --> { "name": }
60+
{{<instance-annotation>}}
61+
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
62+
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
63+
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }
64+
{{</instance-annotation>}}
65+
66+
{{<instance-pass `A string value that represents an invalid JSON object encoded in Base 64 is valid and an annotations are still emitted`>}}
67+
"eyAibmFtZSI6IH0=" // { "name": }
68+
{{</instance-pass>}}
69+
70+
{{<instance-annotation>}}
71+
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
72+
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
73+
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }
74+
{{</instance-annotation>}}
75+
76+
{{<instance-pass `A string value that represents a valid JSON number encoded in Base 64 is valid and an annotations are still emitted`>}}
77+
"MTIzNA==" // 1234
4978
{{</instance-pass>}}
5079

51-
{{<instance-pass `A non-object instance is ignored`>}}
52-
true
80+
{{<instance-annotation>}}
81+
{ "keyword": "/contentMediaType", "instance": "", "value": "application/json" }
82+
{ "keyword": "/contentEncoding", "instance": "", "value": "base64" }
83+
{ "keyword": "/contentSchema", "instance": "", "value": { "type": "object" } }
84+
{{</instance-annotation>}}
85+
86+
{{<instance-pass `A non-string value is valid but (perhaps counter-intuitively) annotations are still emitted`>}}
87+
1234
5388
{{</instance-pass>}}
5489

5590
{{<instance-annotation>}}

0 commit comments

Comments
 (0)