Skip to content

Commit 568409b

Browse files
committed
Improve contentMediaType explanation
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 5984270 commit 568409b

File tree

2 files changed

+64
-14
lines changed

2 files changed

+64
-14
lines changed

content/2020-12/content/contentEncoding.markdown

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ related:
2020
keyword: contentSchema
2121
---
2222

23-
The `contentEncoding` keyword signifies that an instance value (such as a
24-
specific object property) should be considered binary data encoded into a JSON
25-
string using the given encoding. This keyword does not affect validation, but
26-
the evaluator will collect its value as an annotation. The use of this and
27-
related keywords is a common technique to encode and describe arbitrary binary
28-
data (such as image, audio, and video) in JSON.
23+
The `contentEncoding` keyword signifies that a string instance value (such as a
24+
specific object property) should be considered binary data serialised using the
25+
given encoding. This keyword does not affect validation, but the evaluator will
26+
collect its value as an annotation. The use of this and related keywords is a
27+
common technique to encode and describe arbitrary binary data (such as image,
28+
audio, and video) in JSON.
2929

3030
{{<best-practice>}}
3131

@@ -51,10 +51,12 @@ supports content encoding/decoding and how to enable it.
5151

5252
This keyword is inspired by the
5353
[`Content-Transfer-Encoding`](https://www.rfc-editor.org/rfc/rfc2045.html#section-6)
54-
RFC 2045 MIME header used to transmit non-ASCII data over e-mail. For example,
55-
if you send a picture as an e-mail attachment, your e-mail client will likely
56-
send a multipart message that includes the Base64-encoded representation of
57-
such picture, while setting the `Content-Transfer-Encoding` header to `base64`.
54+
MIME header used in conjunction with the
55+
[`Content-Type`](https://www.rfc-editor.org/rfc/rfc2045.html#section-5) header
56+
to transmit non-ASCII data over e-mail. For example, if you send a PNG image as
57+
an e-mail attachment, your e-mail client will likely send a multipart message
58+
that includes the Base64-encoded image, sets the `Content-Transfer-Encoding`
59+
header to `base64`, and sets the `Content-Type` header to `image/png`.
5860

5961
{{</learning-more>}}
6062

content/2020-12/content/contentMediaType.markdown

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,59 @@ related:
2121
keyword: contentEncoding
2222
---
2323

24-
The `contentMediaType` keyword in JSON Schema specifies the MIME type of the contents of a string. It is used to annotate the type of media contained within a string. It should be noted that:
24+
When the [`contentEncoding`]({{< ref "2020-12/content/contentencoding" >}})
25+
keyword is set, the `contentMediaType` keyword signifies that a string instance
26+
value (such as a specific object property) should be considered binary data
27+
that represents the given type. This keyword does not affect validation, but
28+
the evaluator will collect its value as an annotation. The use of this and
29+
related keywords is a common technique to encode and describe arbitrary binary
30+
data (such as image, audio, and video) in JSON.
2531

26-
* This keyword is purely an annotation and does not directly affect validation.
27-
* It describes the media type of the binary string after it has been decoded as specified in `contentEncoding`.
28-
* It is recommended to set `contentEncoding` if `contentMediaType` is declared.
32+
{{<best-practice>}}
33+
34+
It is recommended to set this keyword along with the [`contentEncoding`]({{<
35+
ref "2020-12/content/contentencoding" >}}) keyword to declare the encoding used
36+
to serialised the data (for example, Base 64 encoding). Otherwise, the
37+
receiver must treat the instance value as a binary blob without knowing for
38+
sure how to decode it.
39+
40+
{{</best-practice>}}
41+
42+
{{<common-pitfall>}}
43+
44+
The JSON Schema specification prohibits implementations, for security reasons,
45+
from automatically attempting to decode, parse, or validate encoded data
46+
without the consumer explicitly opting in to such behaviour. If you require
47+
this feature, consult the documentation of your tooling of choice to see if it
48+
supports content encoding/decoding and how to enable it.
49+
50+
{{</common-pitfall>}}
51+
52+
{{<learning-more>}}
53+
54+
This keyword is inspired by the
55+
[`Content-Type`](https://www.rfc-editor.org/rfc/rfc2045.html#section-5) MIME
56+
header used in conjunction with the
57+
[`Content-Transfer-Encoding`](https://www.rfc-editor.org/rfc/rfc2045.html#section-6)
58+
header to transmit non-ASCII data over e-mail. For example, if you send a PNG
59+
image as an e-mail attachment, your e-mail client will likely send a multipart
60+
message that includes the Base64-encoded image, sets the `Content-Type` header
61+
to `image/png`, and sets the `Content-Transfer-Encoding` header to `base64`.
62+
63+
{{</learning-more>}}
64+
65+
The Internet Assigned Numbers Authority (IANA) standards organization is the
66+
source of truth for the exhaustive official list of registered content media
67+
types. You can find the complete list at
68+
[https://www.iana.org/assignments/media-types/media-types.xhtml](https://www.iana.org/assignments/media-types/media-types.xhtml).
69+
70+
In the interest of interoperability, avoid using custom unregistered content
71+
media types. If required, register a new content media type with the IANA
72+
[here](https://www.iana.org/form/media-types). Alternatively, [RFC 2046
73+
Section 6.3](https://datatracker.ietf.org/doc/html/rfc2046) suggests that if a
74+
custom unregistered content media type is really needed, it must live within a
75+
registered category and prefixed with `x-`. For example,
76+
`application/x-my-custom-media-type`.
2977

3078
## Examples
3179

0 commit comments

Comments
 (0)