Skip to content

Commit 1d8963e

Browse files
authored
Merge pull request #384 from dlax/media-in-validation
Moving "media" into validation (as "contentEncoding"+"contentMediaType")
2 parents 7f401b2 + e1116ab commit 1d8963e

File tree

4 files changed

+120
-140
lines changed

4 files changed

+120
-140
lines changed

hyper-schema.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,6 @@
5757
"items": {
5858
"$ref": "http://json-schema.org/draft-06/links#"
5959
}
60-
},
61-
"media": {
62-
"type": "object",
63-
"properties": {
64-
"type": {
65-
"type": "string"
66-
},
67-
"binaryEncoding": {
68-
"type": "string"
69-
}
70-
}
7160
}
7261
},
7362
"links": [

jsonschema-hyperschema.xml

Lines changed: 4 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="US-ASCII"?>
22
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
3-
<!ENTITY rfc2045 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2045.xml">
43
<!ENTITY rfc2046 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2046.xml">
54
<!ENTITY rfc2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
65
<!ENTITY rfc3986 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3986.xml">
@@ -123,8 +122,6 @@
123122
<t>
124123
This document describes how JSON Schema can be used to define hyperlinks on instance
125124
data.
126-
It also defines how to provide additional information required to interpret JSON
127-
data as rich multimedia documents.
128125
</t>
129126
<t>
130127
As with all JSON Schema keywords, all the keywords described in the "Schema
@@ -133,8 +130,7 @@
133130
</t>
134131
<figure>
135132
<preamble>
136-
Here is an example JSON Schema defining hyperlinks, and providing a multimedia
137-
interpretation for the "imgData" property:
133+
Here is an example JSON Schema defining hyperlinks:
138134
</preamble>
139135
<artwork>
140136
<![CDATA[
@@ -153,14 +149,6 @@
153149
},
154150
"authorId": {
155151
"type": "integer"
156-
},
157-
"imgData": {
158-
"title": "Article Illustration (thumbnail)",
159-
"type": "string",
160-
"media": {
161-
"binaryEncoding": "base64",
162-
"type": "image/png"
163-
}
164152
}
165153
},
166154
"required" : ["id", "title", "authorId"],
@@ -178,11 +166,8 @@
178166
]]>
179167
</artwork>
180168
<postamble>
181-
This example schema defines the properties of the instance. For the "imgData"
182-
property, it specifies that that it should be base64-decoded and the resulting
183-
binary data treated as a PNG image.
184-
It also defines link relations for the instance, with URIs incorporating values
185-
from the instance.
169+
This example schema defines the properties of the instance as well as link
170+
relations for the instance, with URIs incorporating values from the instance.
186171
<cref>
187172
"id" probably should not normally be a required keyword, since new instances
188173
will have an unknown "id" property until is it assigned by the server.
@@ -192,25 +177,6 @@
192177
</postamble>
193178
</figure>
194179

195-
<figure>
196-
<preamble>
197-
An example of a JSON instance described by the above schema might be:
198-
</preamble>
199-
<artwork>
200-
<![CDATA[
201-
{
202-
"id": 15,
203-
"title": "Example data",
204-
"authorId": 105,
205-
"imgData": "iVBORw...kJggg=="
206-
}
207-
]]>
208-
</artwork>
209-
<postamble>
210-
The base-64 data has been abbreviated for readability.
211-
</postamble>
212-
</figure>
213-
214180
<section title="Interaction with validation">
215181
<t>
216182
Hyper-schema keywords can be applied when the instance is valid against
@@ -338,94 +304,6 @@
338304
</figure>
339305
</section>
340306

341-
<section title="media">
342-
<t>
343-
The "media" property indicates that this instance contains non-JSON data encoded
344-
in a JSON string.
345-
It describes the type of content and how it is encoded.
346-
</t>
347-
<t>
348-
The value of this property MUST be an object.
349-
The value of this property SHOULD be ignored if the instance described is not a
350-
string.
351-
</t>
352-
353-
<section title="Properties of &quot;media&quot;">
354-
<t>
355-
The value of the "media" keyword MAY contain any of the following
356-
properties:
357-
</t>
358-
359-
<section title="binaryEncoding">
360-
<t>
361-
If the instance value is a string, this property defines that the string
362-
SHOULD be interpreted as binary data and decoded using the encoding
363-
named by this property.
364-
<xref target="RFC2045">RFC 2045, Sec 6.1</xref> lists the possible
365-
values for this property.
366-
</t>
367-
</section>
368-
369-
<section title="type">
370-
<t>
371-
The value of this property must be a media type, as defined by
372-
<xref target="RFC2046">RFC 2046</xref>. This property defines the media
373-
type of instances which this schema defines.
374-
</t>
375-
376-
<t>
377-
If the "binaryEncoding" property is not set, but the instance value is a
378-
string, then the value of this property SHOULD specify a text document
379-
type, and the character set SHOULD be the character set into which the
380-
JSON string value was decoded (for which the default is Unicode).
381-
</t>
382-
</section>
383-
</section>
384-
385-
<section title="Example">
386-
<figure>
387-
<preamble>
388-
Here is an example schema, illustrating the use of "media":
389-
</preamble>
390-
<artwork>
391-
<![CDATA[
392-
{
393-
"type": "string",
394-
"media": {
395-
"binaryEncoding": "base64",
396-
"type": "image/png"
397-
}
398-
}
399-
]]>
400-
</artwork>
401-
<postamble>
402-
Instances described by this schema should be strings, and their values
403-
should be interpretable as base64-encoded PNG images.
404-
</postamble>
405-
</figure>
406-
407-
<figure>
408-
<preamble>
409-
Another example:
410-
</preamble>
411-
<artwork>
412-
<![CDATA[
413-
{
414-
"type": "string",
415-
"media": {
416-
"type": "text/html"
417-
}
418-
}
419-
]]>
420-
</artwork>
421-
<postamble>
422-
Instances described by this schema should be strings containing HTML,
423-
using whatever character set the JSON string was decoded into (default
424-
is Unicode).
425-
</postamble>
426-
</figure>
427-
</section>
428-
</section>
429307
</section>
430308

431309
<section title="Link Description Object">
@@ -1010,9 +888,7 @@ GET /foo/
1010888
"properties": {
1011889
"message": {
1012890
"description": "Re-interpret `message` as HTML",
1013-
"media": {
1014-
"type": "text/html"
1015-
}
891+
"contentMediaType": "text/html"
1016892
}
1017893
}
1018894
}
@@ -1310,7 +1186,6 @@ GET /foo/
13101186
<back>
13111187
<!-- References Section -->
13121188
<references title="Normative References">
1313-
&rfc2045;
13141189
&rfc2119;
13151190
&rfc3986;
13161191
<!--&rfc4287;-->

jsonschema-validation.xml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0" encoding="US-ASCII"?>
22
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
33
<!ENTITY RFC1034 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.1034.xml">
4+
<!ENTITY RFC2045 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2045.xml">
5+
<!ENTITY RFC2046 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2046.xml">
46
<!ENTITY RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
57
<!ENTITY RFC2673 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2673.xml">
68
<!ENTITY RFC3339 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3339.xml">
@@ -993,6 +995,116 @@
993995
</section>
994996
</section>
995997

998+
<section title='String-encoding non-JSON data'>
999+
1000+
<section title="Foreword">
1001+
<t>
1002+
Properties defined in this section indicate that an instance contains
1003+
non-JSON data encoded in a JSON string.
1004+
They describe the type of content and how it is encoded.
1005+
</t>
1006+
<t>
1007+
These properties provide additional information required to interpret JSON data
1008+
as rich multimedia documents.
1009+
</t>
1010+
</section>
1011+
1012+
<section title="Implementation requirements">
1013+
<t>
1014+
Implementations MAY support keywords defined in this section.
1015+
Should they choose to do so, they SHOULD offer an option to disable validation
1016+
for these keywords.
1017+
</t>
1018+
</section>
1019+
1020+
<section title="contentEncoding">
1021+
1022+
<t>
1023+
If the instance value is a string, this property defines that the string
1024+
SHOULD be interpreted as binary data and decoded using the encoding
1025+
named by this property.
1026+
<xref target="RFC2045">RFC 2045, Sec 6.1</xref> lists the possible
1027+
values for this property.
1028+
</t>
1029+
1030+
<t>
1031+
The value of this property MUST be a string.
1032+
</t>
1033+
1034+
<t>
1035+
The value of this property SHOULD be ignored if the instance described is not a
1036+
string.
1037+
</t>
1038+
1039+
</section>
1040+
1041+
<section title="contentMediaType">
1042+
<t>
1043+
The value of this property must be a media type, as defined by
1044+
<xref target="RFC2046">RFC 2046</xref>. This property defines the media
1045+
type of instances which this schema defines.
1046+
</t>
1047+
1048+
<t>
1049+
The value of this property MUST be a string.
1050+
</t>
1051+
1052+
<t>
1053+
The value of this property SHOULD be ignored if the instance described is not a
1054+
string.
1055+
</t>
1056+
1057+
<t>
1058+
If the "contentEncoding" property is not present, but the instance value is a
1059+
string, then the value of this property SHOULD specify a text document type,
1060+
and the character set SHOULD be the character set into which the JSON string
1061+
value was decoded (for which the default is Unicode).
1062+
</t>
1063+
</section>
1064+
1065+
<section title="Example">
1066+
<figure>
1067+
<preamble>
1068+
Here is an example schema, illustrating the use of "contentEncoding" and
1069+
"contentMediaType":
1070+
</preamble>
1071+
<artwork>
1072+
<![CDATA[
1073+
{
1074+
"type": "string",
1075+
"contentEncoding": "base64",
1076+
"contentMediaType": "image/png"
1077+
}
1078+
]]>
1079+
</artwork>
1080+
<postamble>
1081+
Instances described by this schema should be strings, and their values
1082+
should be interpretable as base64-encoded PNG images.
1083+
</postamble>
1084+
</figure>
1085+
1086+
<figure>
1087+
<preamble>
1088+
Another example:
1089+
</preamble>
1090+
<artwork>
1091+
<![CDATA[
1092+
{
1093+
"type": "string",
1094+
"contentMediaType": "text/html"
1095+
}
1096+
]]>
1097+
</artwork>
1098+
<postamble>
1099+
Instances described by this schema should be strings containing HTML, using
1100+
whatever character set the JSON string was decoded into (default is
1101+
Unicode).
1102+
</postamble>
1103+
</figure>
1104+
</section>
1105+
1106+
</section>
1107+
9961108
<section title="Security considerations">
9971109
<t>
9981110
JSON Schema validation defines a vocabulary for JSON Schema core and concerns all
@@ -1034,6 +1146,8 @@
10341146

10351147
<references title="Informative References">
10361148
&RFC1034;
1149+
&RFC2045;
1150+
&RFC2046;
10371151
&RFC2673;
10381152
&RFC3339;
10391153
&RFC3986;

schema.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@
152152
]
153153
},
154154
"format": { "type": "string" },
155+
"contentMediaType": { "type": "string" },
156+
"contentEncoding": { "type": "string" },
155157
"if": {"$ref": "#"},
156158
"then": {"$ref": "#"},
157159
"else": {"$ref": "#"},

0 commit comments

Comments
 (0)