source: trip-planner-front/node_modules/json-schema/draft-zyp-json-schema-03.xml@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 49.0 KB
Line 
1<?xml version="1.0" encoding="US-ASCII"?>
2<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
3<!ENTITY rfc4627 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4627.xml">
4<!ENTITY rfc3986 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3986.xml">
5<!ENTITY rfc2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
6<!ENTITY rfc4287 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4287.xml">
7<!ENTITY rfc2616 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2616.xml">
8<!ENTITY rfc3339 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3339.xml">
9<!ENTITY rfc2045 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2045.xml">
10<!ENTITY rfc5226 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5226.xml">
11<!ENTITY rfc2396 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2396.xml">
12<!ENTITY iddiscovery SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.hammer-discovery.xml">
13<!ENTITY uritemplate SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.gregorio-uritemplate.xml">
14<!ENTITY linkheader SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.nottingham-http-link-header.xml">
15<!ENTITY html401 SYSTEM "http://xml.resource.org/public/rfc/bibxml4/reference.W3C.REC-html401-19991224.xml">
16<!ENTITY css21 SYSTEM "http://xml.resource.org/public/rfc/bibxml4/reference.W3C.CR-CSS21-20070719.xml">
17]>
18<?rfc toc="yes"?>
19<?rfc symrefs="yes"?>
20<?rfc compact="yes"?>
21<?rfc subcompact="no"?>
22<?rfc strict="no"?>
23<?rfc rfcedstyle="yes"?>
24<rfc category="info" docName="draft-zyp-json-schema-03" ipr="trust200902">
25 <front>
26 <title abbrev="JSON Schema Media Type">A JSON Media Type for Describing the Structure and Meaning of JSON Documents</title>
27
28 <author fullname="Kris Zyp" initials="K" role="editor" surname="Zyp">
29 <organization>SitePen (USA)</organization>
30 <address>
31 <postal>
32 <street>530 Lytton Avenue</street>
33 <city>Palo Alto, CA 94301</city>
34 <country>USA</country>
35 </postal>
36 <phone>+1 650 968 8787</phone>
37 <email>kris@sitepen.com</email>
38 </address>
39 </author>
40
41 <author fullname="Gary Court" initials="G" surname="Court">
42 <address>
43 <postal>
44 <street></street>
45 <city>Calgary, AB</city>
46 <country>Canada</country>
47 </postal>
48 <email>gary.court@gmail.com</email>
49 </address>
50 </author>
51
52 <date year="2011" />
53 <workgroup>Internet Engineering Task Force</workgroup>
54 <keyword>JSON</keyword>
55 <keyword>Schema</keyword>
56 <keyword>JavaScript</keyword>
57 <keyword>Object</keyword>
58 <keyword>Notation</keyword>
59 <keyword>Hyper Schema</keyword>
60 <keyword>Hypermedia</keyword>
61
62 <abstract>
63 <t>
64 JSON (JavaScript Object Notation) Schema defines the media type "application/schema+json",
65 a JSON based format for defining
66 the structure of JSON data. JSON Schema provides a contract for what JSON
67 data is required for a given application and how to interact with it. JSON
68 Schema is intended to define validation, documentation, hyperlink
69 navigation, and interaction control of JSON data.
70 </t>
71 </abstract>
72 </front>
73
74 <middle>
75 <section title="Introduction">
76 <t>
77 JSON (JavaScript Object Notation) Schema is a JSON media type for defining
78 the structure of JSON data. JSON Schema provides a contract for what JSON
79 data is required for a given application and how to interact with it. JSON
80 Schema is intended to define validation, documentation, hyperlink
81 navigation, and interaction control of JSON data.
82 </t>
83 </section>
84
85 <section title="Conventions">
86 <t>
87 <!-- The text in this section has been copied from the official boilerplate,
88 and should not be modified.-->
89
90 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
91 "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
92 interpreted as described in <xref target="RFC2119">RFC 2119</xref>.
93 </t>
94 </section>
95
96 <!-- ********************************************* -->
97
98 <section title="Overview">
99 <t>
100 JSON Schema defines the media type "application/schema+json" for
101 describing the structure of other
102 JSON documents. JSON Schema is JSON-based and includes facilities
103 for describing the structure of JSON documents in terms of
104 allowable values, descriptions, and interpreting relations with other resources.
105 </t>
106 <t>
107 JSON Schema format is organized into several separate definitions. The first
108 definition is the core schema specification. This definition is primary
109 concerned with describing a JSON structure and specifying valid elements
110 in the structure. The second definition is the Hyper Schema specification
111 which is intended define elements in a structure that can be interpreted as
112 hyperlinks.
113 Hyper Schema builds on JSON Schema to describe the hyperlink structure of
114 other JSON documents and elements of interaction. This allows user agents to be able to successfully navigate
115 JSON documents based on their schemas.
116 </t>
117 <t>
118 Cumulatively JSON Schema acts as a meta-document that can be used to define the required type and constraints on
119 property values, as well as define the meaning of the property values
120 for the purpose of describing a resource and determining hyperlinks
121 within the representation.
122 </t>
123 <figure>
124 <preamble>An example JSON Schema that describes products might look like:</preamble>
125 <artwork>
126<![CDATA[
127{
128 "title": "Product",
129 "properties": {
130 "id": {
131 "type": "number",
132 "description": "Product identifier",
133 "required": true
134 },
135 "name": {
136 "description": "Name of the product",
137 "type": "string",
138 "required": true
139 },
140 "price": {
141 "required": true,
142 "type": "number",
143 "minimum": 0,
144 "required": true
145 },
146 "tags": {
147 "type": "array",
148 "items": {
149 "type": "string"
150 }
151 }
152 },
153 "links": [{
154 "rel": "full",
155 "href": "{id}"
156 }, {
157 "rel": "comments",
158 "href": "comments/?id={id}"
159 }]
160}
161]]>
162 </artwork>
163 <postamble>
164 This schema defines the properties of the instance JSON documents,
165 the required properties (id, name, and price), as well as an optional
166 property (tags). This also defines the link relations of the instance
167 JSON documents.
168 </postamble>
169 </figure>
170
171 <section title="Terminology">
172 <t>
173 For this specification, <spanx style="strong">schema</spanx> will be used to denote a JSON Schema
174 definition, and an <spanx style="strong">instance</spanx> refers to a JSON value that the schema
175 will be describing and validating.
176 </t>
177 </section>
178
179 <section title="Design Considerations">
180 <t>
181 The JSON Schema media type does not attempt to dictate the structure of JSON
182 representations that contain data, but rather provides a separate format
183 for flexibly communicating how a JSON representation should be
184 interpreted and validated, such that user agents can properly understand
185 acceptable structures and extrapolate hyperlink information
186 with the JSON document. It is acknowledged that JSON documents come
187 in a variety of structures, and JSON is unique in that the structure
188 of stored data structures often prescribes a non-ambiguous definite
189 JSON representation. Attempting to force a specific structure is generally
190 not viable, and therefore JSON Schema allows for a great flexibility
191 in the structure of the JSON data that it describes.
192 </t>
193 <t>
194 This specification is protocol agnostic.
195 The underlying protocol (such as HTTP) should sufficiently define the
196 semantics of the client-server interface, the retrieval of resource
197 representations linked to by JSON representations, and modification of
198 those resources. The goal of this
199 format is to sufficiently describe JSON structures such that one can
200 utilize existing information available in existing JSON
201 representations from a large variety of services that leverage a representational state transfer
202 architecture using existing protocols.
203 </t>
204 </section>
205 </section>
206
207 <section title="Schema/Instance Association">
208 <t>
209 JSON Schema instances are correlated to their schema by the "describedby"
210 relation, where the schema is defined to be the target of the relation.
211 Instance representations may be of the "application/json" media type or
212 any other subtype. Consequently, dictating how an instance
213 representation should specify the relation to the schema is beyond the normative scope
214 of this document (since this document specifically defines the JSON
215 Schema media type, and no other), but it is recommended that instances
216 specify their schema so that user agents can interpret the instance
217 representation and messages may retain the self-descriptive
218 characteristic, avoiding the need for out-of-band information about
219 instance data. Two approaches are recommended for declaring the
220 relation to the schema that describes the meaning of a JSON instance's (or collection
221 of instances) structure. A MIME type parameter named
222 "profile" or a relation of "describedby" (which could be defined by a Link header) may be used:
223
224 <figure>
225 <artwork>
226<![CDATA[
227Content-Type: application/my-media-type+json;
228 profile=http://json.com/my-hyper-schema
229]]>
230 </artwork>
231 </figure>
232
233 or if the content is being transferred by a protocol (such as HTTP) that
234 provides headers, a Link header can be used:
235
236 <figure>
237 <artwork>
238<![CDATA[
239Link: <http://json.com/my-hyper-schema>; rel="describedby"
240]]>
241 </artwork>
242 </figure>
243
244 Instances MAY specify multiple schemas, to indicate all the schemas that
245 are applicable to the data, and the data SHOULD be valid by all the schemas.
246 The instance data MAY have multiple schemas
247 that it is defined by (the instance data SHOULD be valid for those schemas).
248 Or if the document is a collection of instances, the collection MAY contain
249 instances from different schemas. When collections contain heterogeneous
250 instances, the "pathStart" attribute MAY be specified in the
251 schema to disambiguate which schema should be applied for each item in the
252 collection. However, ultimately, the mechanism for referencing a schema is up to the
253 media type of the instance documents (if they choose to specify that schemas
254 can be referenced).
255 </t>
256
257 <section title="Self-Descriptive Schema">
258 <t>
259 JSON Schemas can themselves be described using JSON Schemas.
260 A self-describing JSON Schema for the core JSON Schema can
261 be found at <eref target="http://json-schema.org/schema">http://json-schema.org/schema</eref> for the latest version or
262 <eref target="http://json-schema.org/draft-03/schema">http://json-schema.org/draft-03/schema</eref> for the draft-03 version. The hyper schema
263 self-description can be found at <eref target="http://json-schema.org/hyper-schema">http://json-schema.org/hyper-schema</eref>
264 or <eref target="http://json-schema.org/draft-03/hyper-schema">http://json-schema.org/draft-03/hyper-schema</eref>. All schemas
265 used within a protocol with media type definitions
266 SHOULD include a MIME parameter that refers to the self-descriptive
267 hyper schema or another schema that extends this hyper schema:
268
269 <figure>
270 <artwork>
271<![CDATA[
272Content-Type: application/json;
273 profile=http://json-schema.org/draft-03/hyper-schema
274]]>
275 </artwork>
276 </figure>
277 </t>
278 </section>
279 </section>
280
281 <section title="Core Schema Definition">
282 <t>
283 A JSON Schema is a JSON Object that defines various attributes
284 (including usage and valid values) of a JSON value. JSON
285 Schema has recursive capabilities; there are a number of elements
286 in the structure that allow for nested JSON Schemas.
287 </t>
288
289 <figure>
290 <preamble>An example JSON Schema definition could look like:</preamble>
291 <artwork>
292<![CDATA[
293{
294 "description": "A person",
295 "type": "object",
296
297 "properties": {
298 "name": {
299 "type": "string"
300 },
301 "age": {
302 "type": "integer",
303 "maximum": 125
304 }
305 }
306}
307]]>
308 </artwork>
309 </figure>
310
311 <t>
312 A JSON Schema object may have any of the following properties, called schema
313 attributes (all attributes are optional):
314 </t>
315
316 <section title="type">
317 <t>
318 This attribute defines what the primitive type or the schema of the instance MUST be in order to validate.
319 This attribute can take one of two forms:
320
321 <list style="hanging">
322 <t hangText="Simple Types">
323 A string indicating a primitive or simple type. The following are acceptable string values:
324
325 <list style="hanging">
326 <t hangText="string">Value MUST be a string.</t>
327 <t hangText="number">Value MUST be a number, floating point numbers are allowed. </t>
328 <t hangText="integer">Value MUST be an integer, no floating point numbers are allowed. This is a subset of the number type.</t>
329 <t hangText="boolean">Value MUST be a boolean. </t>
330 <t hangText="object">Value MUST be an object.</t>
331 <t hangText="array">Value MUST be an array.</t>
332 <t hangText="null">Value MUST be null. Note this is mainly for purpose of being able use union types to define nullability. If this type is not included in a union, null values are not allowed (the primitives listed above do not allow nulls on their own).</t>
333 <t hangText="any">Value MAY be of any type including null.</t>
334 </list>
335
336 If the property is not defined or is not in this list, then any type of value is acceptable.
337 Other type values MAY be used for custom purposes, but minimal validators of the specification
338 implementation can allow any instance value on unknown type values.
339 </t>
340
341 <t hangText="Union Types">
342 An array of two or more simple type definitions. Each item in the array MUST be a simple type definition or a schema.
343 The instance value is valid if it is of the same type as one of the simple type definitions, or valid by one of the schemas, in the array.
344 </t>
345 </list>
346 </t>
347
348 <figure>
349 <preamble>For example, a schema that defines if an instance can be a string or a number would be:</preamble>
350 <artwork>
351<![CDATA[
352{
353 "type": ["string", "number"]
354}
355]]></artwork>
356 </figure>
357 </section>
358
359 <section title="properties" anchor="properties">
360 <t>This attribute is an object with property definitions that define the valid values of instance object property values. When the instance value is an object, the property values of the instance object MUST conform to the property definitions in this object. In this object, each property definition's value MUST be a schema, and the property's name MUST be the name of the instance property that it defines. The instance property value MUST be valid according to the schema from the property definition. Properties are considered unordered, the order of the instance properties MAY be in any order.</t>
361 </section>
362
363 <section title="patternProperties">
364 <t>This attribute is an object that defines the schema for a set of property names of an object instance. The name of each property of this attribute's object is a regular expression pattern in the ECMA 262/Perl 5 format, while the value is a schema. If the pattern matches the name of a property on the instance object, the value of the instance's property MUST be valid against the pattern name's schema value.</t>
365 </section>
366
367 <section title="additionalProperties" anchor="additionalProperties">
368 <t>This attribute defines a schema for all properties that are not explicitly defined in an object type definition. If specified, the value MUST be a schema or a boolean. If false is provided, no additional properties are allowed beyond the properties defined in the schema. The default value is an empty schema which allows any value for additional properties.</t>
369 </section>
370
371 <section title="items">
372 <t>This attribute defines the allowed items in an instance array, and MUST be a schema or an array of schemas. The default value is an empty schema which allows any value for items in the instance array.</t>
373 <t>When this attribute value is a schema and the instance value is an array, then all the items in the array MUST be valid according to the schema.</t>
374 <t>When this attribute value is an array of schemas and the instance value is an array, each position in the instance array MUST conform to the schema in the corresponding position for this array. This called tuple typing. When tuple typing is used, additional items are allowed, disallowed, or constrained by the <xref target="additionalItems">"additionalItems"</xref> attribute using the same rules as <xref target="additionalProperties">"additionalProperties"</xref> for objects.</t>
375 </section>
376
377 <section title="additionalItems" anchor="additionalItems">
378 <t>This provides a definition for additional items in an array instance when tuple definitions of the items is provided. This can be false to indicate additional items in the array are not allowed, or it can be a schema that defines the schema of the additional items.</t>
379 </section>
380
381 <section title="required">
382 <t>This attribute indicates if the instance must have a value, and not be undefined. This is false by default, making the instance optional.</t>
383 </section>
384
385 <section title="dependencies">
386 <t>This attribute is an object that defines the requirements of a property on an instance object. If an object instance has a property with the same name as a property in this attribute's object, then the instance must be valid against the attribute's property value (hereafter referred to as the "dependency value").</t>
387 <t>
388 The dependency value can take one of two forms:
389
390 <list style="hanging">
391 <t hangText="Simple Dependency">
392 If the dependency value is a string, then the instance object MUST have a property with the same name as the dependency value.
393 If the dependency value is an array of strings, then the instance object MUST have a property with the same name as each string in the dependency value's array.
394 </t>
395 <t hangText="Schema Dependency">
396 If the dependency value is a schema, then the instance object MUST be valid against the schema.
397 </t>
398 </list>
399 </t>
400 </section>
401
402 <section title="minimum">
403 <t>This attribute defines the minimum value of the instance property when the type of the instance value is a number.</t>
404 </section>
405
406 <section title="maximum">
407 <t>This attribute defines the maximum value of the instance property when the type of the instance value is a number.</t>
408 </section>
409
410 <section title="exclusiveMinimum">
411 <t>This attribute indicates if the value of the instance (if the instance is a number) can not equal the number defined by the "minimum" attribute. This is false by default, meaning the instance value can be greater then or equal to the minimum value.</t>
412 </section>
413
414 <section title="exclusiveMaximum">
415 <t>This attribute indicates if the value of the instance (if the instance is a number) can not equal the number defined by the "maximum" attribute. This is false by default, meaning the instance value can be less then or equal to the maximum value.</t>
416 </section>
417
418 <section title="minItems">
419 <t>This attribute defines the minimum number of values in an array when the array is the instance value.</t>
420 </section>
421
422 <section title="maxItems">
423 <t>This attribute defines the maximum number of values in an array when the array is the instance value.</t>
424 </section>
425
426 <section title="uniqueItems" anchor="uniqueItems">
427 <t>This attribute indicates that all items in an array instance MUST be unique (contains no two identical values).</t>
428 <t>
429 Two instance are consider equal if they are both of the same type and:
430
431 <list>
432 <t>are null; or</t>
433 <t>are booleans/numbers/strings and have the same value; or</t>
434 <t>are arrays, contains the same number of items, and each item in the array is equal to the corresponding item in the other array; or</t>
435 <t>are objects, contains the same property names, and each property in the object is equal to the corresponding property in the other object.</t>
436 </list>
437 </t>
438 </section>
439
440 <section title="pattern">
441 <t>When the instance value is a string, this provides a regular expression that a string instance MUST match in order to be valid. Regular expressions SHOULD follow the regular expression specification from ECMA 262/Perl 5</t>
442 </section>
443
444 <section title="minLength">
445 <t>When the instance value is a string, this defines the minimum length of the string.</t>
446 </section>
447
448 <section title="maxLength">
449 <t>When the instance value is a string, this defines the maximum length of the string.</t>
450 </section>
451
452 <section title="enum">
453 <t>This provides an enumeration of all possible values that are valid for the instance property. This MUST be an array, and each item in the array represents a possible value for the instance value. If this attribute is defined, the instance value MUST be one of the values in the array in order for the schema to be valid. Comparison of enum values uses the same algorithm as defined in <xref target="uniqueItems">"uniqueItems"</xref>.</t>
454 </section>
455
456 <section title="default">
457 <t>This attribute defines the default value of the instance when the instance is undefined.</t>
458 </section>
459
460 <section title="title">
461 <t>This attribute is a string that provides a short description of the instance property.</t>
462 </section>
463
464 <section title="description">
465 <t>This attribute is a string that provides a full description of the of purpose the instance property.</t>
466 </section>
467
468 <section title="format">
469 <t>This property defines the type of data, content type, or microformat to be expected in the instance property values. A format attribute MAY be one of the values listed below, and if so, SHOULD adhere to the semantics describing for the format. A format SHOULD only be used to give meaning to primitive types (string, integer, number, or boolean). Validators MAY (but are not required to) validate that the instance values conform to a format.</t>
470
471 <t>
472 The following formats are predefined:
473
474 <list style="hanging">
475 <t hangText="date-time">This SHOULD be a date in ISO 8601 format of YYYY-MM-DDThh:mm:ssZ in UTC time. This is the recommended form of date/timestamp.</t>
476 <t hangText="date">This SHOULD be a date in the format of YYYY-MM-DD. It is recommended that you use the "date-time" format instead of "date" unless you need to transfer only the date part.</t>
477 <t hangText="time">This SHOULD be a time in the format of hh:mm:ss. It is recommended that you use the "date-time" format instead of "time" unless you need to transfer only the time part.</t>
478 <t hangText="utc-millisec">This SHOULD be the difference, measured in milliseconds, between the specified time and midnight, 00:00 of January 1, 1970 UTC. The value SHOULD be a number (integer or float).</t>
479 <t hangText="regex">A regular expression, following the regular expression specification from ECMA 262/Perl 5.</t>
480 <t hangText="color">This is a CSS color (like "#FF0000" or "red"), based on <xref target="W3C.CR-CSS21-20070719">CSS 2.1</xref>.</t>
481 <t hangText="style">This is a CSS style definition (like "color: red; background-color:#FFF"), based on <xref target="W3C.CR-CSS21-20070719">CSS 2.1</xref>.</t>
482 <t hangText="phone">This SHOULD be a phone number (format MAY follow E.123).</t>
483 <t hangText="uri">This value SHOULD be a URI.</t>
484 <t hangText="email">This SHOULD be an email address.</t>
485 <t hangText="ip-address">This SHOULD be an ip version 4 address.</t>
486 <t hangText="ipv6">This SHOULD be an ip version 6 address.</t>
487 <t hangText="host-name">This SHOULD be a host-name.</t>
488 </list>
489 </t>
490
491 <t>Additional custom formats MAY be created. These custom formats MAY be expressed as an URI, and this URI MAY reference a schema of that format.</t>
492 </section>
493
494 <section title="divisibleBy">
495 <t>This attribute defines what value the number instance must be divisible by with no remainder (the result of the division must be an integer.) The value of this attribute SHOULD NOT be 0.</t>
496 </section>
497
498 <section title="disallow">
499 <t>This attribute takes the same values as the "type" attribute, however if the instance matches the type or if this value is an array and the instance matches any type or schema in the array, then this instance is not valid.</t>
500 </section>
501
502 <section title="extends">
503 <t>The value of this property MUST be another schema which will provide a base schema which the current schema will inherit from. The inheritance rules are such that any instance that is valid according to the current schema MUST be valid according to the referenced schema. This MAY also be an array, in which case, the instance MUST be valid for all the schemas in the array. A schema that extends another schema MAY define additional attributes, constrain existing attributes, or add other constraints.</t>
504 <t>
505 Conceptually, the behavior of extends can be seen as validating an
506 instance against all constraints in the extending schema as well as
507 the extended schema(s). More optimized implementations that merge
508 schemas are possible, but are not required. Some examples of using "extends":
509
510 <figure>
511 <artwork>
512<![CDATA[
513{
514 "description": "An adult",
515 "properties": {
516 "age": {
517 "minimum": 21
518 }
519 },
520 "extends": {"$ref": "person"}
521}
522]]>
523 </artwork>
524 </figure>
525
526 <figure>
527 <artwork>
528<![CDATA[
529{
530 "description": "Extended schema",
531 "properties": {
532 "deprecated": {
533 "type": "boolean"
534 }
535 },
536 "extends": {"$ref": "http://json-schema.org/draft-03/schema"}
537}
538]]>
539 </artwork>
540 </figure>
541 </t>
542 </section>
543
544 <section title="id">
545 <t>
546 This attribute defines the current URI of this schema (this attribute is
547 effectively a "self" link). This URI MAY be relative or absolute. If
548 the URI is relative it is resolved against the current URI of the parent
549 schema it is contained in. If this schema is not contained in any
550 parent schema, the current URI of the parent schema is held to be the
551 URI under which this schema was addressed. If id is missing, the current URI of a schema is
552 defined to be that of the parent schema. The current URI of the schema
553 is also used to construct relative references such as for $ref.
554 </t>
555 </section>
556
557 <section title="$ref">
558 <t>
559 This attribute defines a URI of a schema that contains the full representation of this schema.
560 When a validator encounters this attribute, it SHOULD replace the current schema with the schema referenced by the value's URI (if known and available) and re-validate the instance.
561 This URI MAY be relative or absolute, and relative URIs SHOULD be resolved against the URI of the current schema.
562 </t>
563 </section>
564
565 <section title="$schema">
566 <t>
567 This attribute defines a URI of a JSON Schema that is the schema of the current schema.
568 When this attribute is defined, a validator SHOULD use the schema referenced by the value's URI (if known and available) when resolving <xref target="hyper-schema">Hyper Schema</xref><xref target="links">links</xref>.
569 </t>
570
571 <t>
572 A validator MAY use this attribute's value to determine which version of JSON Schema the current schema is written in, and provide the appropriate validation features and behavior.
573 Therefore, it is RECOMMENDED that all schema authors include this attribute in their schemas to prevent conflicts with future JSON Schema specification changes.
574 </t>
575 </section>
576 </section>
577
578 <section title="Hyper Schema" anchor="hyper-schema">
579 <t>
580 The following attributes are specified in addition to those
581 attributes that already provided by the core schema with the specific
582 purpose of informing user agents of relations between resources based
583 on JSON data. Just as with JSON
584 schema attributes, all the attributes in hyper schemas are optional.
585 Therefore, an empty object is a valid (non-informative) schema, and
586 essentially describes plain JSON (no constraints on the structures).
587 Addition of attributes provides additive information for user agents.
588 </t>
589
590 <section title="links" anchor="links">
591 <t>
592 The value of the links property MUST be an array, where each item
593 in the array is a link description object which describes the link
594 relations of the instances.
595 </t>
596
597 <section title="Link Description Object">
598 <t>
599 A link description object is used to describe link relations. In
600 the context of a schema, it defines the link relations of the
601 instances of the schema, and can be parameterized by the instance
602 values. The link description format can be used on its own in
603 regular (non-schema documents), and use of this format can
604 be declared by referencing the normative link description
605 schema as the the schema for the data structure that uses the
606 links. The URI of the normative link description schema is:
607 <eref target="http://json-schema.org/links">http://json-schema.org/links</eref> (latest version) or
608 <eref target="http://json-schema.org/draft-03/links">http://json-schema.org/draft-03/links</eref> (draft-03 version).
609 </t>
610
611 <section title="href">
612 <t>
613 The value of the "href" link description property
614 indicates the target URI of the related resource. The value
615 of the instance property SHOULD be resolved as a URI-Reference per <xref target="RFC3986">RFC 3986</xref>
616 and MAY be a relative URI. The base URI to be used for relative resolution
617 SHOULD be the URI used to retrieve the instance object (not the schema)
618 when used within a schema. Also, when links are used within a schema, the URI
619 SHOULD be parametrized by the property values of the instance
620 object, if property values exist for the corresponding variables
621 in the template (otherwise they MAY be provided from alternate sources, like user input).
622 </t>
623
624 <t>
625 Instance property values SHOULD be substituted into the URIs where
626 matching braces ('{', '}') are found surrounding zero or more characters,
627 creating an expanded URI. Instance property value substitutions are resolved
628 by using the text between the braces to denote the property name
629 from the instance to get the value to substitute.
630
631 <figure>
632 <preamble>For example, if an href value is defined:</preamble>
633 <artwork>
634<![CDATA[
635http://somesite.com/{id}
636]]>
637 </artwork>
638 <postamble>Then it would be resolved by replace the value of the "id" property value from the instance object.</postamble>
639 </figure>
640
641 <figure>
642 <preamble>If the value of the "id" property was "45", the expanded URI would be:</preamble>
643 <artwork>
644<![CDATA[
645http://somesite.com/45
646]]>
647 </artwork>
648 </figure>
649
650 If matching braces are found with the string "@" (no quotes) between the braces, then the
651 actual instance value SHOULD be used to replace the braces, rather than a property value.
652 This should only be used in situations where the instance is a scalar (string,
653 boolean, or number), and not for objects or arrays.
654 </t>
655 </section>
656
657 <section title="rel">
658 <t>
659 The value of the "rel" property indicates the name of the
660 relation to the target resource. The relation to the target SHOULD be interpreted as specifically from the instance object that the schema (or sub-schema) applies to, not just the top level resource that contains the object within its hierarchy. If a resource JSON representation contains a sub object with a property interpreted as a link, that sub-object holds the relation with the target. A relation to target from the top level resource MUST be indicated with the schema describing the top level JSON representation.
661 </t>
662
663 <t>
664 Relationship definitions SHOULD NOT be media type dependent, and users are encouraged to utilize existing accepted relation definitions, including those in existing relation registries (see <xref target="RFC4287">RFC 4287</xref>). However, we define these relations here for clarity of normative interpretation within the context of JSON hyper schema defined relations:
665
666 <list style="hanging">
667 <t hangText="self">
668 If the relation value is "self", when this property is encountered in
669 the instance object, the object represents a resource and the instance object is
670 treated as a full representation of the target resource identified by
671 the specified URI.
672 </t>
673
674 <t hangText="full">
675 This indicates that the target of the link is the full representation for the instance object. The object that contains this link possibly may not be the full representation.
676 </t>
677
678 <t hangText="describedby">
679 This indicates the target of the link is the schema for the instance object. This MAY be used to specifically denote the schemas of objects within a JSON object hierarchy, facilitating polymorphic type data structures.
680 </t>
681
682 <t hangText="root">
683 This relation indicates that the target of the link
684 SHOULD be treated as the root or the body of the representation for the
685 purposes of user agent interaction or fragment resolution. All other
686 properties of the instance objects can be regarded as meta-data
687 descriptions for the data.
688 </t>
689 </list>
690 </t>
691
692 <t>
693 The following relations are applicable for schemas (the schema as the "from" resource in the relation):
694
695 <list style="hanging">
696 <t hangText="instances">This indicates the target resource that represents collection of instances of a schema.</t>
697 <t hangText="create">This indicates a target to use for creating new instances of a schema. This link definition SHOULD be a submission link with a non-safe method (like POST).</t>
698 </list>
699 </t>
700
701 <t>
702 <figure>
703 <preamble>For example, if a schema is defined:</preamble>
704 <artwork>
705<![CDATA[
706{
707 "links": [{
708 "rel": "self",
709 "href": "{id}"
710 }, {
711 "rel": "up",
712 "href": "{upId}"
713 }, {
714 "rel": "children",
715 "href": "?upId={id}"
716 }]
717}
718]]>
719 </artwork>
720 </figure>
721
722 <figure>
723 <preamble>And if a collection of instance resource's JSON representation was retrieved:</preamble>
724 <artwork>
725<![CDATA[
726GET /Resource/
727
728[{
729 "id": "thing",
730 "upId": "parent"
731}, {
732 "id": "thing2",
733 "upId": "parent"
734}]
735]]>
736 </artwork>
737 </figure>
738
739 This would indicate that for the first item in the collection, its own
740 (self) URI would resolve to "/Resource/thing" and the first item's "up"
741 relation SHOULD be resolved to the resource at "/Resource/parent".
742 The "children" collection would be located at "/Resource/?upId=thing".
743 </t>
744 </section>
745
746 <section title="targetSchema">
747 <t>This property value is a schema that defines the expected structure of the JSON representation of the target of the link.</t>
748 </section>
749
750 <section title="Submission Link Properties">
751 <t>
752 The following properties also apply to link definition objects, and
753 provide functionality analogous to HTML forms, in providing a
754 means for submitting extra (often user supplied) information to send to a server.
755 </t>
756
757 <section title="method">
758 <t>
759 This attribute defines which method can be used to access the target resource.
760 In an HTTP environment, this would be "GET" or "POST" (other HTTP methods
761 such as "PUT" and "DELETE" have semantics that are clearly implied by
762 accessed resources, and do not need to be defined here).
763 This defaults to "GET".
764 </t>
765 </section>
766
767 <section title="enctype">
768 <t>
769 If present, this property indicates a query media type format that the server
770 supports for querying or posting to the collection of instances at the target
771 resource. The query can be
772 suffixed to the target URI to query the collection with
773 property-based constraints on the resources that SHOULD be returned from
774 the server or used to post data to the resource (depending on the method).
775
776 <figure>
777 <preamble>For example, with the following schema:</preamble>
778 <artwork>
779<![CDATA[
780{
781 "links": [{
782 "enctype": "application/x-www-form-urlencoded",
783 "method": "GET",
784 "href": "/Product/",
785 "properties": {
786 "name": {
787 "description": "name of the product"
788 }
789 }
790 }]
791}
792]]>
793 </artwork>
794 <postamble>This indicates that the client can query the server for instances that have a specific name.</postamble>
795 </figure>
796
797 <figure>
798 <preamble>For example:</preamble>
799 <artwork>
800<![CDATA[
801/Product/?name=Slinky
802]]>
803 </artwork>
804 </figure>
805
806 If no enctype or method is specified, only the single URI specified by
807 the href property is defined. If the method is POST, "application/json" is
808 the default media type.
809 </t>
810 </section>
811
812 <section title="schema">
813 <t>
814 This attribute contains a schema which defines the acceptable structure of the submitted
815 request (for a GET request, this schema would define the properties for the query string
816 and for a POST request, this would define the body).
817 </t>
818 </section>
819 </section>
820 </section>
821 </section>
822
823 <section title="fragmentResolution">
824 <t>
825 This property indicates the fragment resolution protocol to use for
826 resolving fragment identifiers in URIs within the instance
827 representations. This applies to the instance object URIs and all
828 children of the instance object's URIs. The default fragment resolution
829 protocol is "slash-delimited", which is defined below. Other fragment
830 resolution protocols MAY be used, but are not defined in this document.
831 </t>
832
833 <t>
834 The fragment identifier is based on <xref target="RFC2396">RFC 2396, Sec 5</xref>, and defines the
835 mechanism for resolving references to entities within a document.
836 </t>
837
838 <section title="slash-delimited fragment resolution">
839 <t>
840 With the slash-delimited fragment resolution protocol, the fragment
841 identifier is interpreted as a series of property reference tokens that start with and
842 are delimited by the "/" character (\x2F). Each property reference token
843 is a series of unreserved or escaped URI characters. Each property
844 reference token SHOULD be interpreted, starting from the beginning of
845 the fragment identifier, as a path reference in the target JSON
846 structure. The final target value of the fragment can be determined by
847 starting with the root of the JSON structure from the representation of
848 the resource identified by the pre-fragment URI. If the target is a JSON
849 object, then the new target is the value of the property with the name
850 identified by the next property reference token in the fragment. If the
851 target is a JSON array, then the target is determined by finding the
852 item in array the array with the index defined by the next property
853 reference token (which MUST be a number). The target is successively
854 updated for each property reference token, until the entire fragment has
855 been traversed.
856 </t>
857
858 <t>
859 Property names SHOULD be URI-encoded. In particular, any "/" in a
860 property name MUST be encoded to avoid being interpreted as a property
861 delimiter.
862 </t>
863
864 <t>
865 <figure>
866 <preamble>For example, for the following JSON representation:</preamble>
867 <artwork>
868<![CDATA[
869{
870 "foo": {
871 "anArray": [{
872 "prop": 44
873 }],
874 "another prop": {
875 "baz": "A string"
876 }
877 }
878}
879]]>
880 </artwork>
881 </figure>
882
883 <figure>
884 <preamble>The following fragment identifiers would be resolved:</preamble>
885 <artwork>
886<![CDATA[
887fragment identifier resolution
888------------------- ----------
889# self, the root of the resource itself
890#/foo the object referred to by the foo property
891#/foo/another%20prop the object referred to by the "another prop"
892 property of the object referred to by the
893 "foo" property
894#/foo/another%20prop/baz the string referred to by the value of "baz"
895 property of the "another prop" property of
896 the object referred to by the "foo" property
897#/foo/anArray/0 the first object in the "anArray" array
898]]>
899 </artwork>
900 </figure>
901 </t>
902 </section>
903
904 <section title="dot-delimited fragment resolution">
905 <t>
906 The dot-delimited fragment resolution protocol is the same as
907 slash-delimited fragment resolution protocol except that the "." character
908 (\x2E) is used as the delimiter between property names (instead of "/") and
909 the path does not need to start with a ".". For example, #.foo and #foo are a valid fragment
910 identifiers for referencing the value of the foo propery.
911 </t>
912 </section>
913 </section>
914
915 <section title="readonly">
916 <t>This attribute indicates that the instance property SHOULD NOT be changed. Attempts by a user agent to modify the value of this property are expected to be rejected by a server.</t>
917 </section>
918
919 <section title="contentEncoding">
920 <t>If the instance property value is a string, this attribute defines that the string SHOULD be interpreted as binary data and decoded using the encoding named by this schema property. <xref target="RFC2045">RFC 2045, Sec 6.1</xref> lists the possible values for this property.</t>
921 </section>
922
923 <section title="pathStart">
924 <t>
925 This attribute is a URI that defines what the instance's URI MUST start with in order to validate.
926 The value of the "pathStart" attribute MUST be resolved as per <xref target="RFC3986">RFC 3986, Sec 5</xref>,
927 and is relative to the instance's URI.
928 </t>
929
930 <t>
931 When multiple schemas have been referenced for an instance, the user agent
932 can determine if this schema is applicable for a particular instance by
933 determining if the URI of the instance begins with the the value of the "pathStart"
934 attribute. If the URI of the instance does not start with this URI,
935 or if another schema specifies a starting URI that is longer and also matches the
936 instance, this schema SHOULD NOT be applied to the instance. Any schema
937 that does not have a pathStart attribute SHOULD be considered applicable
938 to all the instances for which it is referenced.
939 </t>
940 </section>
941
942 <section title="mediaType">
943 <t>This attribute defines the media type of the instance representations that this schema is defining.</t>
944 </section>
945 </section>
946
947 <section title="Security Considerations">
948 <t>
949 This specification is a sub-type of the JSON format, and
950 consequently the security considerations are generally the same as <xref target="RFC4627">RFC 4627</xref>.
951 However, an additional issue is that when link relation of "self"
952 is used to denote a full representation of an object, the user agent
953 SHOULD NOT consider the representation to be the authoritative representation
954 of the resource denoted by the target URI if the target URI is not
955 equivalent to or a sub-path of the the URI used to request the resource
956 representation which contains the target URI with the "self" link.
957
958 <figure>
959 <preamble>For example, if a hyper schema was defined:</preamble>
960 <artwork>
961<![CDATA[
962{
963 "links": [{
964 "rel": "self",
965 "href": "{id}"
966 }]
967}
968]]>
969 </artwork>
970 </figure>
971
972 <figure>
973 <preamble>And a resource was requested from somesite.com:</preamble>
974 <artwork>
975<![CDATA[
976GET /foo/
977]]>
978 </artwork>
979 </figure>
980
981 <figure>
982 <preamble>With a response of:</preamble>
983 <artwork>
984<![CDATA[
985Content-Type: application/json; profile=/schema-for-this-data
986
987[{
988 "id": "bar",
989 "name": "This representation can be safely treated \
990 as authoritative "
991}, {
992 "id": "/baz",
993 "name": "This representation should not be treated as \
994 authoritative the user agent should make request the resource\
995 from '/baz' to ensure it has the authoritative representation"
996}, {
997 "id": "http://othersite.com/something",
998 "name": "This representation\
999 should also not be treated as authoritative and the target\
1000 resource representation should be retrieved for the\
1001 authoritative representation"
1002}]
1003]]>
1004 </artwork>
1005 </figure>
1006 </t>
1007 </section>
1008
1009 <section title="IANA Considerations">
1010 <t>The proposed MIME media type for JSON Schema is "application/schema+json".</t>
1011 <t>Type name: application</t>
1012 <t>Subtype name: schema+json</t>
1013 <t>Required parameters: profile</t>
1014 <t>
1015 The value of the profile parameter SHOULD be a URI (relative or absolute) that
1016 refers to the schema used to define the structure of this structure (the
1017 meta-schema). Normally the value would be http://json-schema.org/draft-03/hyper-schema,
1018 but it is allowable to use other schemas that extend the hyper schema's meta-
1019 schema.
1020 </t>
1021 <t>Optional parameters: pretty</t>
1022 <t>The value of the pretty parameter MAY be true or false to indicate if additional whitespace has been included to make the JSON representation easier to read.</t>
1023
1024 <section title="Registry of Link Relations">
1025 <t>
1026 This registry is maintained by IANA per <xref target="RFC4287">RFC 4287</xref> and this specification adds
1027 four values: "full", "create", "instances", "root". New
1028 assignments are subject to IESG Approval, as outlined in <xref target="RFC5226">RFC 5226</xref>.
1029 Requests should be made by email to IANA, which will then forward the
1030 request to the IESG, requesting approval.
1031 </t>
1032 </section>
1033 </section>
1034 </middle>
1035
1036 <back>
1037 <!-- References Section -->
1038 <references title="Normative References">
1039 &rfc2045;
1040 &rfc2119;
1041 &rfc2396;
1042 &rfc3339;
1043 &rfc3986;
1044 &rfc4287;
1045 </references>
1046 <references title="Informative References">
1047 &rfc2616;
1048 &rfc4627;
1049 &rfc5226;
1050 &iddiscovery;
1051 &uritemplate;
1052 &linkheader;
1053 &html401;
1054 &css21;
1055 </references>
1056
1057 <section title="Change Log">
1058 <t>
1059 <list style="hanging">
1060 <t hangText="draft-03">
1061 <list style="symbols">
1062 <t>Added example and verbiage to "extends" attribute.</t>
1063 <t>Defined slash-delimited to use a leading slash.</t>
1064 <t>Made "root" a relation instead of an attribute.</t>
1065 <t>Removed address values, and MIME media type from format to reduce confusion (mediaType already exists, so it can be used for MIME types).</t>
1066 <t>Added more explanation of nullability.</t>
1067 <t>Removed "alternate" attribute.</t>
1068 <t>Upper cased many normative usages of must, may, and should.</t>
1069 <t>Replaced the link submission "properties" attribute to "schema" attribute.</t>
1070 <t>Replaced "optional" attribute with "required" attribute.</t>
1071 <t>Replaced "maximumCanEqual" attribute with "exclusiveMaximum" attribute.</t>
1072 <t>Replaced "minimumCanEqual" attribute with "exclusiveMinimum" attribute.</t>
1073 <t>Replaced "requires" attribute with "dependencies" attribute.</t>
1074 <t>Moved "contentEncoding" attribute to hyper schema.</t>
1075 <t>Added "additionalItems" attribute.</t>
1076 <t>Added "id" attribute.</t>
1077 <t>Switched self-referencing variable substitution from "-this" to "@" to align with reserved characters in URI template.</t>
1078 <t>Added "patternProperties" attribute.</t>
1079 <t>Schema URIs are now namespace versioned.</t>
1080 <t>Added "$ref" and "$schema" attributes.</t>
1081 </list>
1082 </t>
1083
1084 <t hangText="draft-02">
1085 <list style="symbols">
1086 <t>Replaced "maxDecimal" attribute with "divisibleBy" attribute.</t>
1087 <t>Added slash-delimited fragment resolution protocol and made it the default.</t>
1088 <t>Added language about using links outside of schemas by referencing its normative URI.</t>
1089 <t>Added "uniqueItems" attribute.</t>
1090 <t>Added "targetSchema" attribute to link description object.</t>
1091 </list>
1092 </t>
1093
1094 <t hangText="draft-01">
1095 <list style="symbols">
1096 <t>Fixed category and updates from template.</t>
1097 </list>
1098 </t>
1099
1100 <t hangText="draft-00">
1101 <list style="symbols">
1102 <t>Initial draft.</t>
1103 </list>
1104 </t>
1105 </list>
1106 </t>
1107 </section>
1108
1109 <section title="Open Issues">
1110 <t>
1111 <list>
1112 <t>Should we give a preference to MIME headers over Link headers (or only use one)?</t>
1113 <t>Should "root" be a MIME parameter?</t>
1114 <t>Should "format" be renamed to "mediaType" or "contentType" to reflect the usage MIME media types that are allowed?</t>
1115 <t>How should dates be handled?</t>
1116 </list>
1117 </t>
1118 </section>
1119 </back>
1120</rfc>
Note: See TracBrowser for help on using the repository browser.