From cddf323fff083b1b8cb16636b897584d1546ed13 Mon Sep 17 00:00:00 2001 From: Henry Andrews Date: Fri, 20 Oct 2017 13:26:31 -0700 Subject: [PATCH 1/4] Add ready-for-review works in progress These will be the "draft-07" documents. They will be modified in a subsequent commit to clearly indicate that they are for review only, and not for use. The "WIP-" prefix hopefully also clues people in that there is something unusual going on here. Doing everything possible (in this and the next commit) to make it clear that these are not published files, but rather are pre-built review copies for those who are unlikely to build their own from the github repo. --- work-in-progress/WIP-hyper-schema-output.json | 61 + work-in-progress/WIP-hyper-schema.json | 69 + work-in-progress/WIP-jsonschema-core.html | 1025 ++++++++++ .../WIP-jsonschema-hyperschema.html | 1645 +++++++++++++++++ .../WIP-jsonschema-validation.html | 1274 +++++++++++++ work-in-progress/WIP-links.json | 85 + .../WIP-relative-json-pointer.html | 669 +++++++ work-in-progress/WIP-schema.json | 167 ++ 8 files changed, 4995 insertions(+) create mode 100644 work-in-progress/WIP-hyper-schema-output.json create mode 100644 work-in-progress/WIP-hyper-schema.json create mode 100644 work-in-progress/WIP-jsonschema-core.html create mode 100644 work-in-progress/WIP-jsonschema-hyperschema.html create mode 100644 work-in-progress/WIP-jsonschema-validation.html create mode 100644 work-in-progress/WIP-links.json create mode 100644 work-in-progress/WIP-relative-json-pointer.html create mode 100644 work-in-progress/WIP-schema.json diff --git a/work-in-progress/WIP-hyper-schema-output.json b/work-in-progress/WIP-hyper-schema-output.json new file mode 100644 index 00000000..46f52995 --- /dev/null +++ b/work-in-progress/WIP-hyper-schema-output.json @@ -0,0 +1,61 @@ +{ + "$id": "http://json-schema.org/draft-7-wip/hyper-schema-output", + "$schema": "http://json-schema.org/draft-07-wip/schema#", + "type": "array", + "items": { + "allOf": [ + {"$ref": "http://json-schema.org/draft-07/links#/definitions/noRequiredFields" } + ], + "type": "object", + "required": [ + "contextUri", + "contextPointer", + "rel", + "attachmentPointer" + ], + "if": { "required": [ "hrefSchema" ] }, + "then": { "required": [ "hrefInputTemplates", "hrefPrepopulatedInput" ] }, + "else": { "required": [ "targetUri" ] }, + "properties": { + "contextUri": { + "$comment": "The fully resolved URI of the link context, including a fragment if it is possible to construct one for the given media type and instance", + "type": "string", + "format": "uri" + }, + "contextPointer": { + "$comment": "The absolute JSON Pointer to the location in the instance that is the context of the link. If the context resource supports JSON Pointer fragments, this will the string form of the identical JSON Pointer", + "type": "string", + "format": "json-pointer" + }, + "rel": { + "type": "string" + }, + "targetUri": { + "$comment": "The fully resolved target URI", + "type": "string", + "format": "uri" + }, + "hrefInputTemplates": { + "$comment": "The list of partially resolved URI Templates, starting with \"href\", followed by applicable \"base\" values from nearest to furthest.", + "type": "array", + "items": { + "type": "string", + "format": "uri-template" + } + }, + "hrefPrepopulatedInput": { + "$comment": "The initial data set to be presented with the input form when URI Tempalte input is accepted.", + "type": "object", + "propertyNames": { + "$comment": "These are all URI Template variable names, specifically the 'varname' production from RFC 6570, Section 2.3", + "pattern": "^(?:\\w|(?:%[a-f\\d]{2}))+(?:\\.(?:\\w|(?:%[a-f\\d]{2})))*$" + } + }, + "attachmentPointer": { + "$comment": "The absolute JSON Pointer, in string form, of the position to which this resolved link applies", + "type": "string", + "format": "json-pointer" + } + } + } +} diff --git a/work-in-progress/WIP-hyper-schema.json b/work-in-progress/WIP-hyper-schema.json new file mode 100644 index 00000000..68ca4fc7 --- /dev/null +++ b/work-in-progress/WIP-hyper-schema.json @@ -0,0 +1,69 @@ +{ + "$schema": "http://json-schema.org/draft-07-wip/hyper-schema#", + "$id": "http://json-schema.org/draft-07-wip/hyper-schema#", + "title": "JSON Hyper-Schema", + "definitions": { + "schemaArray": { + "allOf": [ + { "$ref": "http://json-schema.org/draft-07-wip/schema#/definitions/schemaArray" }, + { + "items": { "$ref": "#" } + } + ] + } + }, + "allOf": [ { "$ref": "http://json-schema.org/draft-07-wip/schema#" } ], + "properties": { + "additionalItems": { "$ref": "#" }, + "additionalProperties": { "$ref": "#"}, + "dependencies": { + "additionalProperties": { + "anyOf": [ + { "$ref": "#" }, + { "type": "array" } + ] + } + }, + "items": { + "anyOf": [ + { "$ref": "#" }, + { "$ref": "#/definitions/schemaArray" } + ] + }, + "definitions": { + "additionalProperties": { "$ref": "#" } + }, + "patternProperties": { + "additionalProperties": { "$ref": "#" } + }, + "properties": { + "additionalProperties": { "$ref": "#" } + }, + "if": {"$ref": "#"}, + "then": {"$ref": "#"}, + "else": {"$ref": "#"}, + "allOf": { "$ref": "#/definitions/schemaArray" }, + "anyOf": { "$ref": "#/definitions/schemaArray" }, + "oneOf": { "$ref": "#/definitions/schemaArray" }, + "not": { "$ref": "#" }, + "contains": { "$ref": "#" }, + "propertyNames": { "$ref": "#" }, + + "base": { + "type": "string", + "format": "uri-template" + }, + "links": { + "type": "array", + "items": { + "$ref": "http://json-schema.org/draft-07-wip/links#" + } + } + }, + "links": [ + { + "rel": "self", + "href": "{+%24id}" + } + ] +} diff --git a/work-in-progress/WIP-jsonschema-core.html b/work-in-progress/WIP-jsonschema-core.html new file mode 100644 index 00000000..22f869ff --- /dev/null +++ b/work-in-progress/WIP-jsonschema-core.html @@ -0,0 +1,1025 @@ + + + + + + + JSON Schema: A Media Type for Describing JSON Documents + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Internet Engineering Task ForceA. Wright, Ed.
Internet-Draft
Intended status: InformationalH. Andrews, Ed.
Expires: April 23, 2018Cloudflare, Inc.
October 20, 2017
+ +

JSON Schema: A Media Type for Describing JSON Documents
+ draft-handrews-json-schema-00

+ +

+ Abstract +

+

JSON Schema defines the media type "application/schema+json", a JSON-based format for describing the structure of JSON data. JSON Schema asserts what a JSON document must look like, ways to extract information from it, and how to interact with it. The "application/schema-instance+json" media type provides additional feature-rich integration with "application/schema+json" beyond what can be offered for "application/json" documents.

+

+ Note to Readers +

+

The issues list for this draft can be found at <https://github.com/json-schema-org/json-schema-spec/issues>.

+

For additional information, see <http://json-schema.org/>.

+

To provide feedback, use this issue tracker, the communication methods listed on the homepage, or email the document editors.

+

+ Status of This Memo +

+

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

+

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.

+

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

+

This Internet-Draft will expire on April 23, 2018.

+

+ Copyright Notice +

+

Copyright (c) 2017 IETF Trust and the persons identified as the document authors. All rights reserved.

+

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.

+ + +
+

Table of Contents

+ + +

1. Introduction

+

JSON Schema is a JSON media type for defining the structure of JSON data. JSON Schema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data.

+

This specification defines JSON Schema core terminology and mechanisms, including pointing to another JSON Schema by reference, dereferencing a JSON Schema reference, and specifying the vocabulary being used.

+

Other specifications define the vocabularies that perform assertions about validation, linking, annotation, navigation, and interaction.

+

2. Conventions and Terminology

+

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].

+

The terms "JSON", "JSON text", "JSON value", "member", "element", "object", "array", "number", "string", "boolean", "true", "false", and "null" in this document are to be interpreted as defined in RFC 7159 [RFC7159].

+

3. Overview

+

This document proposes a new media type "application/schema+json" to identify a JSON Schema for describing JSON data. It also proposes a further optional media type, "application/schema-instance+json", to provide additional integration features. JSON Schemas are themselves JSON documents. This, and related specifications, define keywords allowing authors to describe JSON data in several ways.

+

3.1. Validation

+

JSON Schema describes the structure of a JSON document (for instance, required properties and length limitations). Applications can use this information to validate instances (check that constraints are met), or inform interfaces to collect user input such that the constraints are satisfied.

+

Validation behaviour and keywords are specified in a separate document [json-schema-validation].

+

3.2. Hypermedia and Linking

+

JSON Hyper-Schema describes the hypertext structure of a JSON document. This includes link relations from the instance to other resources, interpretation of instances as multimedia data, and submission data required to use an API.

+

Hyper-schema behaviour and keywords are specified in a separate document [json-hyper-schema].

+

4. Definitions

+

4.1. JSON Document

+

A JSON document is an information resource (series of octets) described by the application/json media type.

+

In JSON Schema, the terms "JSON document", "JSON text", and "JSON value" are interchangeable because of the data model it defines.

+

JSON Schema is only defined over JSON documents. However, any document or memory structure that can be parsed into or processed according to the JSON Schema data model can be interpreted against a JSON Schema, including media types like CBOR [RFC7049].

+

4.2. Instance

+

A JSON document to which a schema is applied is known as an "instance".

+

4.2.1. Instance data model

+

JSON Schema interprets documents according to a data model. A JSON value interpreted according to this data model is called an "instance".

+

An instance has one of six primitive types, and a range of possible values depending on the type:

+ +
+
null
+
A JSON "null" production
+
boolean
+
A "true" or "false" value, from the JSON "true" or "false" productions
+
object
+
An unordered set of properties mapping a string to an instance, from the JSON "object" production
+
array
+
An ordered list of instances, from the JSON "array" production
+
number
+
An arbitrary-precision, base-10 decimal number value, from the JSON "number" production
+
string
+
A string of Unicode code points, from the JSON "string" production
+
+ +

+

Whitespace and formatting concerns are thus outside the scope of JSON Schema.

+

Since an object cannot have two properties with the same key, behavior for a JSON document that tries to define two properties (the "member" production) with the same key (the "string" production) in a single object is undefined.

+

4.2.2. Instance media types

+

JSON Schema is designed to fully work with "application/json" documents, as well as media types using the "+json" structured syntax suffix.

+

Some functionality that is useful for working with schemas is defined by each media type, namely media type parameters and URI fragment identifier syntax and semantics. These features are useful in content negotiation and in caclulating URIs for specific locations within an instance, respectively.

+

This specification defines the "application/schema-instance+json" media type in order to allow instance authors to take full advantage of parameters and fragment identifiers for these purposes.

+

4.2.3. Instance equality

+

Two JSON instances are said to be equal if and only if they are of the same type and have the same value according to the data model. Specifically, this means:

+ + + +

+

Implied in this definition is that arrays must be the same length, objects must have the same number of members, properties in objects are unordered, there is no way to define multiple properties with the same key, and mere formatting differences (indentation, placement of commas, trailing zeros) are insignificant.

+

4.3. JSON Schema documents

+

A JSON Schema document, or simply a schema, is a JSON document used to describe an instance. A schema is itself interpreted as an instance, but SHOULD always be given the media type "application/schema+json" rather than "application/schema-instance+json". The "application/schema+json" media type is defined to offer a superset of the media type parameter and fragment identifier syntax and semantics provided by "application/schema-instance+json".

+

A JSON Schema MUST be an object or a boolean.

+

JSON Schema vocabularies can include assertions, which return a boolean result when applied to an instance. The boolean schema values "true" and "false" are trivial assertions that always return themselves regardless of the instance value. As an example, in terms of the validation vocabulary, boolean schemas are equivalent to the following behaviors:

+ +
+
true
+
Always passes validation, as if the empty schema {}
+
false
+
Always fails validation, as if the schema { "not":{} }
+
+ +

+

Properties that are used to describe the instance are called keywords, or schema keywords. The meaning of properties is specified by the vocabulary that the schema is using.

+

A JSON Schema MAY contain properties which are not schema keywords. Unknown keywords SHOULD be ignored.

+

A schema that itself describes a schema is called a meta-schema. Meta-schemas are used to validate JSON Schemas and specify which vocabulary it is using.

+

An empty schema is a JSON Schema with no properties, or only unknown properties.

+

4.3.1. Root schema and subschemas

+

The root schema is the schema that comprises the entire JSON document in question.

+

Some keywords take schemas themselves, allowing JSON Schemas to be nested:

+
+
+{
+    "title": "root",
+    "items": {
+        "title": "array item"
+    }
+}
+
+                        
+

In this example document, the schema titled "array item" is a subschema, and the schema titled "root" is the root schema.

+

As with the root schema, a subschema is either an object or a boolean.

+

5. Fragment identifiers

+

In accordance with section 3.1 of [RFC6839], the syntax and semantics of fragment identifiers specified for any +json media type SHOULD be as specified for "application/json". (At publication of this document, there is no fragment identification syntax defined for "application/json".)

+

Additionally, the "application/schema+json" media type supports two fragment identifier structures: plain names and JSON Pointers. The "application/schema-instance+json" media type supports one fragment identifier structure: JSON Pointers.

+

The use of JSON Pointers as URI fragment identifiers is described in RFC 6901 [RFC6901]. For "application/schema+json", which supports two fragment identifier syntaxes, fragment identifiers matching the JSON Pointer syntax, including the empty string, MUST be interpreted as JSON Pointer fragment identifiers.

+

Per the W3C's best practices for fragment identifiers [W3C.WD-fragid-best-practices-20121025], plain name fragment identifiers in "application/schema+json" are reserved for referencing locally named schemas. All fragment identifiers that do not match the JSON Pointer syntax MUST be interpreted as plain name fragment identifiers.

+

Defining and referencing a plain name fragment identifier within an "application/schema+json" document are specified in the "$id" keyword [id-keyword] section.

+

+

6. General considerations

+

6.1. Range of JSON values

+

An instance may be any valid JSON value as defined by JSON [RFC7159]. JSON Schema imposes no restrictions on type: JSON Schema can describe any JSON value, including, for example, null.

+

6.2. Programming language independence

+

JSON Schema is programming language agnostic, and supports the full range of values described in the data model. Be aware, however, that some languages and JSON parsers may not be able to represent in memory the full range of values describable by JSON.

+

6.3. Mathematical integers

+

Some programming languages and parsers use different internal representations for floating point numbers than they do for integers.

+

For consistency, integer JSON numbers SHOULD NOT be encoded with a fractional part.

+

6.4. Extending JSON Schema

+

Implementations MAY define additional keywords to JSON Schema. Save for explicit agreement, schema authors SHALL NOT expect these additional keywords to be supported by peer implementations. Implementations SHOULD ignore keywords they do not support.

+

Authors of extensions to JSON Schema are encouraged to write their own meta-schemas, which extend the existing meta-schemas using "allOf". This extended meta-schema SHOULD be referenced using the "$schema" keyword, to allow tools to follow the correct behaviour.

+

Note that the recursive nature of meta-schemas requires re-definining recursive keywords in the extended meta-schema, as can be seen in the JSON Hyper-Schema meta-schema.

+

7. The "$schema" keyword

+

The "$schema" keyword is both used as a JSON Schema version identifier and the location of a resource which is itself a JSON Schema, which describes any schema written for this particular version.

+

The value of this keyword MUST be a URI [RFC3986] (containing a scheme) and this URI MUST be normalized. The current schema MUST be valid against the meta-schema identified by this URI.

+

If this URI identifies a retrievable resource, that resource SHOULD be of media type "application/schema+json".

+

The "$schema" keyword SHOULD be used in a root schema. It MUST NOT appear in subschemas.

+

[CREF1]While this pattern is likely to remain best practice for schema authoring, implementation behavior is subject to be revised or liberalized in future drafts.

+

Values for this property are defined in other documents and by other parties. JSON Schema implementations SHOULD implement support for current and previous published drafts of JSON Schema vocabularies as deemed reasonable.

+

8. Schema references with "$ref"

+

The "$ref" keyword is used to reference a schema, and provides the ability to validate recursive structures through self-reference.

+

An object schema with a "$ref" property MUST be interpreted as a "$ref" reference. The value of the "$ref" property MUST be a URI Reference. Resolved against the current URI base, it identifies the URI of a schema to use. All other properties in a "$ref" object MUST be ignored.

+

The URI is not a network locator, only an identifier. A schema need not be downloadable from the address if it is a network-addressable URL, and implementations SHOULD NOT assume they should perform a network operation when they encounter a network-addressable URI.

+

A schema MUST NOT be run into an infinite loop against a schema. For example, if two schemas "#alice" and "#bob" both have an "allOf" property that refers to the other, a naive validator might get stuck in an infinite recursive loop trying to validate the instance. Schemas SHOULD NOT make use of infinite recursive nesting like this; the behavior is undefined.

+

9. Base URI and dereferencing

+

9.1. Initial base URI

+

RFC3986 Section 5.1 [RFC3986] defines how to determine the default base URI of a document.

+

Informatively, the initial base URI of a schema is the URI at which it was found, or a suitable substitute URI if none is known.

+

9.2. The "$id" keyword

+

The "$id" keyword defines a URI for the schema, and the base URI that other URI references within the schema are resolved against. A subschema's "$id" is resolved against the base URI of its parent schema. If no parent sets an explicit base with "$id", the base URI is that of the entire document, as determined per RFC 3986 section 5 [RFC3986].

+

If present, the value for this keyword MUST be a string, and MUST represent a valid URI-reference [RFC3986]. This value SHOULD be normalized, and SHOULD NOT be an empty fragment <#> or an empty string <>.

+

The root schema of a JSON Schema document SHOULD contain an "$id" keyword with a URI (containing a scheme). This URI SHOULD either not have a fragment, or have one that is an empty string. [CREF2]How should an "$id" URI reference containing a fragement with other components be interpreted? There are two cases: when the other components match the current base URI and when they change the base URI.

+

To name subschemas in a JSON Schema document, subschemas can use "$id" to give themselves a document-local identifier. This is done by setting "$id" to a URI reference consisting only of a plain name fragment (not a JSON Pointer fragment). The fragment identifier MUST begin with a letter ([A-Za-z]), followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), or periods (".").

+

Providing a plain name fragment enables a subschema to be relocated within a schema without requiring that JSON Pointer references are updated.

+

The effect of defining a fragment-only "$id" URI reference that neither matches the above requirements nor is a valid JSON pointer is not defined.

+
+
+{
+    "$id": "http://example.com/root.json",
+    "definitions": {
+        "A": { "$id": "#foo" },
+        "B": {
+            "$id": "other.json",
+            "definitions": {
+                "X": { "$id": "#bar" },
+                "Y": { "$id": "t/inner.json" }
+            }
+        },
+        "C": {
+            "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
+        }
+    }
+}
+
+                        
+

For example:

+

The schemas at the following URI-encoded JSON Pointers [RFC6901] (relative to the root schema) have the following base URIs, and are identifiable by either URI in accordance with Section 5 above:

+

+ +

+
# (document root)
+
http://example.com/root.json#
+
#/definitions/A
+
http://example.com/root.json#foo
+
#/definitions/B
+
http://example.com/other.json
+
#/definitions/B/definitions/X
+
http://example.com/other.json#bar
+
#/definitions/B/definitions/Y
+
http://example.com/t/inner.json
+
#/definitions/C
+
urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f
+
+ +

+

9.2.1. Internal references

+

Schemas can be identified by any URI that has been given to them, including a JSON Pointer or their URI given directly by "$id".

+

Tools SHOULD take note of the URIs that schemas, including subschemas, provide for themselves using "$id". This is known as "Internal referencing".

+

For example, consider this schema:

+
+
+{
+    "$id": "http://example.net/root.json",
+    "items": {
+        "type": "array",
+        "items": { "$ref": "#item" }
+    },
+    "definitions": {
+        "single": {
+            "$id": "#item",
+            "type": "integer"
+        }
+    }
+}
+
+                        
+

When an implementation encounters the <#/definitions/single> schema, it resolves the "$id" URI reference against the current base URI to form <http://example.net/root.json#item>.

+

When an implementation then looks inside the <#/items> schema, it encounters the <#item> reference, and resolves this to <http://example.net/root.json#item> which is understood as the schema defined elsewhere in the same document without needing to resolve the fragment against the base URI.

+

9.2.2. External references

+

To differentiate schemas between each other in a vast ecosystem, schemas are identified by URI. As specified above, this does not necessarily mean anything is downloaded, but instead JSON Schema implementations SHOULD already understand the schemas they will be using, including the URIs that identify them.

+

Implementations SHOULD be able to associate arbitrary URIs with an arbitrary schema and/or automatically associate a schema's "$id"-given URI, depending on the trust that the validator has in the schema.

+

A schema MAY (and likely will) have multiple URIs, but there is no way for a URI to identify more than one schema. When multiple schemas try to identify with the same URI, validators SHOULD raise an error condition.

+

10. Comments with "$comment"

+

This keyword is reserved for comments from schema authors to readers or maintainers of the schema. The value of this keyword MUST be a string. Implementations MUST NOT present this string to end users. Tools for editing schemas SHOULD support displaying and editing this keyword. The value of this keyword MAY be used in debug or error output which is intended for developers making use of schemas. Schema vocabularies SHOULD allow "$comment" within any object containing vocabulary keywords. Implementations MAY assume "$comment" is allowed unless the vocabulary specifically forbids it. Vocabularies MUST NOT specify any effect of "$comment" beyond what is described in this specification. Tools that translate other media types or programming languages to and from application/schema+json MAY choose to convert that media type or programming language's native comments to or from "$comment" values. The behavior of such translation when both native comments and "$comment" properties are present is implementation-dependent. Implementations SHOULD treat "$comment" identically to an unknown extension keyword. They MAY strip "$comment" values at any point during processing. In particular, this allows for shortening schemas when the size of deployed schemas is a concern. Implementations MUST NOT take any other action based on the presence, absence, or contents of "$comment" properties.

+

11. Usage for hypermedia

+

JSON has been adopted widely by HTTP servers for automated APIs and robots. This section describes how to enhance processing of JSON documents in a more RESTful manner when used with protocols that support media types and Web linking [RFC5988].

+

11.1. Linking to a schema

+

It is RECOMMENDED that instances described by a schema provide a link to a downloadable JSON Schema using the link relation "describedby", as defined by Linked Data Protocol 1.0, section 8.1 [W3C.REC-ldp-20150226].

+

In HTTP, such links can be attached to any response using the Link header [RFC5988]. An example of such a header would be:

+
+
+Link: <http://example.com/my-hyper-schema#>; rel="describedby"
+
+                    
+

11.2. Identifying a schema via a media type parameter

+

Media types MAY allow for a "schema" media type parameter, which gives HTTP servers the ability to perform Content-Type Negotiation based on schema. The media-type parameter MUST be a whitespace-separated list of URIs (i.e. relative references are invalid).

+

When using the media type application/schema-instance+json, the "schema" parameter MUST be supplied.

+

The schema URI is opaque and SHOULD NOT automatically be dereferenced. If the implementation does not understand the semantics of the provided schema, the implementation can instead follow the "describedby" links, if any, which may provide information on how to handle the schema. Since "schema" doesn't necessarily point to a network location, the "describedby" relation is used for linking to a downloadable schema. However, for simplicity, schema authors should make these URIs point to the same resource when possible.

+

In HTTP, the media-type parameter would be sent inside the Content-Type header:

+
+
+Content-Type: application/json;
+          schema="http://example.com/my-hyper-schema#"
+
+                    
+

Multiple schemas are whitespace separated:

+
+
+Content-Type: application/json;
+          schema="http://example.com/alice http://example.com/bob"
+
+                    
+

[CREF3]This paragraph assumes that we can register a "schema" link relation. Should we instead specify something like "tag:json-schema.org,2017:schema" for now? HTTP can also send the "schema" in a Link, though this may impact media-type semantics and Content-Type negotiation if this replaces the media-type parameter entirely:

+
+
+Link: </alice>;rel="schema", </bob>;rel="schema"
+
+                    
+

11.3. Usage over HTTP

+

When used for hypermedia systems over a network, HTTP [RFC7231] is frequently the protocol of choice for distributing schemas. Misbehaving clients can pose problems for server maintainers if they pull a schema over the network more frequently than necessary, when it's instead possible to cache a schema for a long period of time.

+

HTTP servers SHOULD set long-lived caching headers on JSON Schemas. HTTP clients SHOULD observe caching headers and not re-request documents within their freshness period. Distributed systems SHOULD make use of a shared cache and/or caching proxy.

+
+
+User-Agent: product-name/5.4.1 so-cool-json-schema/1.0.2 curl/7.43.0
+
+                        
+

Clients SHOULD set or prepend a User-Agent header specific to the JSON Schema implementation or software product. Since symbols are listed in decreasing order of significance, the JSON Schema library name/version should precede the more generic HTTP library name (if any). For example:

+

Clients SHOULD be able to make requests with a "From" header so that server operators can contact the owner of a potentially misbehaving script.

+

12. Security considerations

+

Both schemas and instances are JSON values. As such, all security considerations defined in RFC 7159 [RFC7159] apply.

+

Instances and schemas are both frequently written by untrusted third parties, to be deployed on public Internet servers. Validators should take care that the parsing of schemas doesn't consume excessive system resources. Validators MUST NOT fall into an infinite loop.

+

Servers need to take care that malicious parties can't change the functionality of existing schemas by uploading a schema with an pre-existing or very similar "$id".

+

Individual JSON Schema vocabularies are liable to also have their own security considerations. Consult the respective specifications for more information.

+

Schema authors should take care with "$comment" contents, as a malicious implementation can display them to end-users in violation of a spec, or fail to strip them if such behavior is expected.

+

A malicous schema author could place executable code or other dangerous material within a "$comment". Implementations MUST NOT parse or otherwise take action based on "$comment" contents.

+

13. IANA Considerations

+

13.1. application/schema+json

+

The proposed MIME media type for JSON Schema is defined as follows:

+ + + +

+

13.2. application/schema-instance+json

+

The proposed MIME media type for JSON Schema Instances that require a JSON Schema-specific media type is defined as follows:

+ + + +

+

14. References

+

14.1. Normative References

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ [RFC2119] + Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997.
+ [RFC3986] + Berners-Lee, T., Fielding, R. and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, DOI 10.17487/RFC3986, January 2005.
+ [RFC6839] + Hansen, T. and A. Melnikov, "Additional Media Type Structured Syntax Suffixes", RFC 6839, DOI 10.17487/RFC6839, January 2013.
+ [RFC6901] + Bryan, P., Zyp, K. and M. Nottingham, "JavaScript Object Notation (JSON) Pointer", RFC 6901, DOI 10.17487/RFC6901, April 2013.
+ [RFC7159] + Bray, T., "The JavaScript Object Notation (JSON) Data Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March 2014.
+ [W3C.REC-ldp-20150226] + Speicher, S., Arwe, J. and A. Malhotra, "Linked Data Platform 1.0", World Wide Web Consortium Recommendation REC-ldp-20150226, February 2015.
+

14.2. Informative References

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ [RFC5988] + Nottingham, M., "Web Linking", RFC 5988, DOI 10.17487/RFC5988, October 2010.
+ [RFC7049] + Bormann, C. and P. Hoffman, "Concise Binary Object Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, October 2013.
+ [RFC7231] + Fielding, R. and J. Reschke, "Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content", RFC 7231, DOI 10.17487/RFC7231, June 2014.
+ [W3C.WD-fragid-best-practices-20121025] + Tennison, J., "Best Practices for Fragment Identifiers and Media Type Definitions", World Wide Web Consortium LastCall WD-fragid-best-practices-20121025, October 2012.
+ [json-schema-validation] + Wright, A. and G. Luff, "JSON Schema Validation: A Vocabulary for Structural Validation of JSON", Internet-Draft draft-wright-json-schema-validation-00, October 2016.
+ [json-hyper-schema] + Wright, A. and G. Luff, "JSON Hyper-Schema: A Vocabulary for Hypermedia Annotation of JSON", Internet-Draft draft-wright-json-schema-hyperschema-00, October 2016.
+

Appendix A. Acknowledgments

+

Thanks to Gary Court, Francis Galiegue, Kris Zyp, and Geraint Luff for their work on the initial drafts of JSON Schema.

+

Thanks to Jason Desrosiers, Daniel Perrett, Erik Wilde, Ben Hutton, Evgeny Poberezkin, Brad Bowman, Gowry Sankar, Donald Pipowitch, and Dave Finlay for their submissions and patches to the document.

+

Appendix B. ChangeLog

+

[CREF4]This section to be removed before leaving Internet-Draft status.

+

+ +

+
draft-handrews-json-schema-00
+
+
    +
  • Reserve "$comment" for non-user-visible notes about the schema
  • +
  • Wording improvements around "$id" and fragments
  • +
  • Note the challenges of extending meta-schemas with recursive references
  • +
  • Add "application/schema-instance+json" media type
  • +
  • Recommend a "schema" link relation / parameter instead of "profile"
  • +
+

+
+
draft-wright-json-schema-01
+
+
    +
  • Updated intro
  • +
  • Allowed for any schema to be a boolean
  • +
  • "$schema" SHOULD NOT appear in subschemas, although that may change
  • +
  • Changed "id" to "$id"; all core keywords prefixed with "$"
  • +
  • Clarify and formalize fragments for application/schema+json
  • +
  • Note applicability to formats such as CBOR that can be represented in the JSON data model
  • +
+

+
+
draft-wright-json-schema-00
+
+
    +
  • Updated references to JSON
  • +
  • Updated references to HTTP
  • +
  • Updated references to JSON Pointer
  • +
  • Behavior for "id" is now specified in terms of RFC3986
  • +
  • Aligned vocabulary usage for URIs with RFC3986
  • +
  • Removed reference to draft-pbryan-zyp-json-ref-03
  • +
  • Limited use of "$ref" to wherever a schema is expected
  • +
  • Added definition of the "JSON Schema data model"
  • +
  • Added additional security considerations
  • +
  • Defined use of subschema identifiers for "id"
  • +
  • Rewrote section on usage with HTTP
  • +
  • Rewrote section on usage with rel="describedBy" and rel="profile"
  • +
  • Fixed numerous invalid examples
  • +
+

+
+
draft-zyp-json-schema-04
+
+
    +
  • Split validation keywords into separate document
  • +
+

+
+
draft-zyp-json-schema-00
+
+
    +
  • Initial draft.
  • +
  • Salvaged from draft v3.
  • +
  • Mandate the use of JSON Reference, JSON Pointer.
  • +
  • Define the role of "id". Define URI resolution scope.
  • +
  • Add interoperability considerations.
  • +
+

+
+
+ +

+

+ Authors' Addresses +

+
+
+ + Austin Wright (editor) + + + + + + + + + + + + + EMail: aaa@bzfx.net + +
+
+
+ + Henry Andrews (editor) + + + Cloudflare, Inc. + + + + + + + + + + EMail: henry@cloudflare.com + +
+
+ + + diff --git a/work-in-progress/WIP-jsonschema-hyperschema.html b/work-in-progress/WIP-jsonschema-hyperschema.html new file mode 100644 index 00000000..53c98603 --- /dev/null +++ b/work-in-progress/WIP-jsonschema-hyperschema.html @@ -0,0 +1,1645 @@ + + + + + + + JSON Hyper-Schema: A Vocabulary for Hypermedia Annotation of JSON + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Internet Engineering Task ForceH. Andrews, Ed.
Internet-DraftCloudflare, Inc.
Intended status: InformationalA. Wright, Ed.
Expires: April 23, 2018October 20, 2017
+ +

JSON Hyper-Schema: A Vocabulary for Hypermedia Annotation of JSON
+ draft-handrews-json-schema-hyperschema-00

+ +

+ Abstract +

+

JSON Schema is a JSON based format for describing JSON data using various vocabularies. This document specifies a vocabulary for annotating JSON documents with hyperlinks and instructions for processing and manipulating remote JSON resources through hypermedia environments such as HTTP.

+

+ Note to Readers +

+

The issues list for this draft can be found at <https://github.com/json-schema-org/json-schema-spec/issues>.

+

For additional information, see <http://json-schema.org/>.

+

To provide feedback, use this issue tracker, the communication methods listed on the homepage, or email the document editors.

+

+ Status of This Memo +

+

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

+

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.

+

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

+

This Internet-Draft will expire on April 23, 2018.

+

+ Copyright Notice +

+

Copyright (c) 2017 IETF Trust and the persons identified as the document authors. All rights reserved.

+

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.

+ + +
+

Table of Contents

+ + +

1. Introduction

+

JSON Hyper-Schema is a JSON Schema vocabulary for annotating JSON documents with hyperlinks and instructions for processing and manipulating remote JSON resources through hypermedia environments such as HTTP.

+

The term JSON Hyper-Schema is used to refer to a JSON Schema that uses these keywords. The term "hyper-schema" on its own refers to a JSON Hyper-Schema within the scope of this specification.

+

The primary mechanism introduced for specifying links is the Link Description Object (LDO), which is a serialization of the abstract link model defined in RFC 5988bis, section 2 [I-D.nottingham-rfc5988bis]. [CREF1]This section references the work-in-progress RFC5988bis, with the expectation that it will reach RFC before this specification does.

+

This specification will use the concepts, syntax, and terminology defined by the JSON Schema core [json-schema] and JSON Schema validation [json-schema-validation] specifications. It is advised that readers have a copy of these specifications.

+

2. Notational Conventions

+

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].

+

3. Overview

+

JSON Hyper-Schema makes it possible to build hypermedia systems from JSON documents by describing how to construct hyperlinks from instance data.

+

The combination of a JSON instance document and a valid application/schema+json hyper-schema for that instance behaves as a single hypermedia representation. By allowing this separation, hyper-schema-based systems can gracefully support applications that expect plain JSON, while providing full hypermedia capabilities for hyper-schema-aware applications and user agents.

+

Client-side user agents can detect the presence of hyper-schema by looking for the application/schema+json media type and a "$schema" value that indicates the presence of the hyper-schema vocabulary. A user agent can then use an implementation of JSON Hyper-Schema to provide an interface to the combination of the schema and instance documents as a single logical representation of a resource, just as with any single-document hypermedia representation format.

+

Hyper-schemas allow representations to take up fewer bytes on the wire, and distribute the burden of link construction from the server to each client. A user agent need not construct a link unless a client application requests that link. JSON Hyper-Schema can also be used on the server side to generate other link serializations or representation formats at runtime, or pre-emptively follow links to facilitate server push usage.

+

3.1. Terminology

+

The terms "schema", "instance", and "meta-schema" are to be interpreted as defined in the JSON Schema core specification [json-schema].

+

The terms "applicable" and "attached" are to be interpreted as defined in Section 10.1 of the JSON Schema validation specification [json-schema-validation].

+

The terms "link", "link context" (or "context"), "link target" (or "target"), and "target attributes" are to be interpreted as defined in Section 2 of RFC 5988bis [I-D.nottingham-rfc5988bis].

+

The term "user agent" is to be interpreted as defined in Section 2.1 of RFC 7230 [RFC7230], generalized to apply to any protocol that may be used in a hypermedia system rather than specifically being an HTTP client.

+

This specification defines the following terms:

+ +
+
JSON Hyper-Schema
+
A JSON Schema using the keywords defined by this specification.
+
hyper-schema
+
Within this document, the term "hyper-schema" always refers to a JSON Hyper-Schema
+
link validity
+
A valid link for an instance is one that is applicable to that instance and does not fail any requirement imposed by the keywords in the Link Description Object.
+
generic user agent
+
A user agent which is only aware of standardized link relations, media types, URI schemes, and protocols. It may have an extensible architecture to allow adding support for standards beyond the core set of which it is aware.
+
client application
+
An application which uses a hypermedia system for a specific purpose. Such an application may also be its own user agent, or it may be built on top of a generic user agent. A client application is programmed with knowledge of link relations, media types, URI schemes, protocols, and data structures that are specific to the application's domain.
+
client input
+
Data provided through a user agent, and most often also through a client application. Such data may be requested from a user interactively, or provided before interaction in forms such as command-line arguments, configuration files, or hardcoded values in source code.
+
operation
+
A specific use of a hyperlink, such as making a network request (for a URI with a scheme such as "http://" that indicates a protocol) or otherwise taking action based on a link (reading data from a "data:" URI, or constructing an email message based on a "mailto:" link). For protocols such as HTTP that support multiple methods, each method is considered to be a separate operation on the same link.
+
+ +

+

3.2. Functionality

+

A JSON Hyper-Schema implementation is able to take a hyper-schema, an instance, and in some cases client input, and produce a set of fully resolved valid links. As defined by RFC 5988bis, section 2 [I-D.nottingham-rfc5988bis], a link consists of a context, a typed relation, a target, and optionally additional target attributes.

+

The relation type and target attributes are taken directly from each link's Link Description Object. The context and target identifiers are constructed from some combination of URI Templates, instance data, and (in the case of the target identifier) client input.

+

The target is always fully identified by a URI. Due to the lack of a URI fragment identifier syntax for application/json and many other media types that can be used with JSON Hyper-Schema, the context may be only partially identified by a URI. In such cases, the remaining identification will be provided as a JSON Pointer.

+

A few IANA-registered link relation types are given specific semantics in a JSON Hyper-Schema document. A "self" link is used to interact with the resource that the instance document represents, while "collection" and "item" links identify resources for which collection-specific semantics can be assumed.

+

4. Meta-schemas and output schema

+

[CREF2]The "draft-07-wip" is a placeholder.

+

The current URI for the JSON Hyper-Schema meta-schema is http://json-schema.org/draft-07-wip/hyper-schema# (draft-07 work-in-progress version).

+

The link description format [ldo] can be used without JSON Schema, and use of this format can be declared by referencing the normative link description schema as the schema for the data structure that uses the links. The URI of the normative link description schema is: http://json-schema.org/draft-07-wip/links# (draft-07 work-in-progress version).

+

JSON Hyper-Schema implementations are free to provide output in any format. However, a specific format is defined for use in the conformance test suite, which is also used to illustrate points in the "Implementation Requirements" [implementation], and to show the output generated by examples [examples]. It is RECOMMENDED that implementations be capable of producing output in this format to facilitated testing. The URI of the JSON Schema describing the recommended output format is http://json-schema.org/draft-7-wip/hyper-schema-output# (draft-07 work-in-progress version).

+

5. Schema keywords

+

Hyper-schema keywords from all schemas that are applicable to a position in an instance, as defined by Section 10.1 of JSON Schema validation [json-schema-validation], can be used with that instance.

+

When multiple subschemas are applicable to a given sub-instance, all "link" arrays MUST be combined, in any order, into a single set. Each object in the resulting set MUST retain its own list of applicable "base" values, in resolution order, from the same schema and any parent schemas.

+

As with all JSON Schema keywords, all keywords described in this section are optional. The minimal valid JSON Hyper-schema is the blank object.

+

5.1. base

+

If present, this keyword MUST be first resolved as a URI Template [uriTemplating], and then MUST be resolved as a URI Reference against the current URI base of the instance. The result MUST be set as the new URI base for the instance while processing the sub-schema containing "base" and all sub-schemas within it.

+

The process for resolving the "base" template can be different when being resolved for use with "anchor" than when being resolved for use with "href", which is explained in detail in the URI Templating section.

+

5.2. links

+

The "links" property of schemas is used to associate Link Description Objects with instances. The value of this property MUST be an array, and the items in the array must be Link Description Objects, as defined below.

+

6. Link Description Object

+

[CREF3]This section references the work-in-progress RFC5988bis, with the expectation that it will reach RFC before this specification does. A Link Description Object (LDO) is a serialization of the abstract link model defined in RFC 5988bis, section 2 [I-D.nottingham-rfc5988bis]. As described in that document, a link consists of a context, a relation type, a target, and optionally target attributes. JSON Hyper-Schema's LDO provides all of these, along with additional features using JSON Schema to describe input for use with the links in various ways.

+

Due to the use of URI Templates to identify link contexts and targets, as well as optional further use of client input when identifying targets, an LDO is a link template that may resolve to multiple links when used with a JSON instance document.

+

A specific use of an LDO, typically involving a request and response across a protocol, is referred to as an operation. For many protocols, multiple operations are possible on any given link. The protocol is indicated by the target's URI scheme. Note that not all URI schemes indicate a protocol that can be used for communications, and even resources with URI schemes that do indicate such protocols need not be available over that protocol.

+

A Link Description Object MUST be an object, and the "href" [href] and "rel" [rel] properties MUST be present. Each keyword is covered briefly in this section, with additional usage explanation and comprehensive examples given later in the document.

+

6.1. Link context

+

In JSON Hyper-Schema, the link's context resource is, by default, the sub-instance to which it is attached (as defined by Section 10.1 of the JSON Schema validation specification [json-schema-validation]). This is often not the entire instance document. This default context can be changed using the keywords in this section.

+

Depending on the media type of the instance, it may or may not be possible to assign a URI to the exact default context resource. In particular, application/json does not define a URI fragment resolution syntax, so properties or array elements within a plain JSON document cannot be fully identified by a URI. When it is not possible to produce a complete URI, the position of the context SHOULD be conveyed by a the URI of the instance document, together with a separate plain-string JSON Pointer.

+

Implementations MUST be able to construct the link context's URI, and (if necessary for full identification), a JSON Pointer in string representation form as per RFC 6901, section 5 [RFC6901] in place of a URI fragment. The process for constructing a URI based on a URI template is given in the URI Templating [uriTemplating] section.

+

6.1.1. anchor

+

This property sets the context URI of the link. The value of the property is a URI Template [RFC6570], and the resulting URI-reference [RFC3986] MUST be resolved against the base URI of the instance.

+

The URI is computed from the provided URI template using the same process described for the "href" [href] property, with the exception that "hrefSchema" [hrefSchema] MUST NOT be applied. Unlike target URIs, context URIs do not accept user input.

+

6.1.2. anchorPointer

+

This property changes the point within the instance that is considered to be the context resource of the link. The value of the property MUST be a valid JSON Pointer in JSON String representation form, or a valid Relative JSON Pointer [I-D.luff-relative-json-pointer] which is evaluated relative to the default context.

+

While an alternate context with a known URI is best set with the "anchor" [anchor] keyword, the lack of a fragment identifier syntax for application/json means that it is usually not possible to change the context within a JSON instance using a URI.

+

Even in "+json" media types that define JSON Pointer as a fragment identifier syntax, if the default context is nested within an array, it is not possible to obtain the index of the default context's position in that array in order to construct a pointer to another property in that same nested JSON object. This will be demonstrated in the examples.

+

The result of processing this keyword SHOULD be a URI fragment if the media type of the instance allows for such a fragment. Otherwise it MUST be a string-encoded JSON Pointer.

+

6.2. Link relation type

+

The link's relation type identifies its semantics. It is the primary means of conveying how an application can interact with a resource.

+

Relationship definitions are not normally media type dependent, and users are encouraged to utilize the most suitable existing accepted relation definitions.

+

6.2.1. rel

+

The value of this property MUST be a string, and MUST be a single Link Relation Type as defined in RFC 5988bis, Section 2.1.

+

This property is required.

+

6.2.2. "self" links

+

A hyper-schema implementation MUST recognize that a link with relation type "self" that is applicable to the entire instance document describes how a user agent can interact with the resource represented by that instance document. A "self" link MUST be resolvable from the instance, and therefore "hrefSchema" MUST NOT be present.

+

Hyper-schema authors SHOULD use "templateRequired" to ensure that the "self" link has all instance data that is needed for use.

+

6.2.3. "collection" and "item" links

+

RFC 6573 [RFC6573] defines and registers the "item" and "collection" link relation types. JSON Hyper-Schema imposes additional semantics on collection resources indicated by these types.

+

Implementations MUST recognize the target of a "collection" link and the context of an "item" link as collections.

+

A well-known design pattern in hypermedia is to use a collection resource to create a member of the collection and give it a server-assigned URI. If the protocol indicated by the URI scheme defines a specific method that is suited to creating a resource with a server-assigned URI, then a collection resource, as identified by these link relation types, MUST NOT define semantics for that method that conflict with the semantics of creating a collection member. Collection resources MAY implement item creation via such a protocol method, and user agents MAY assume that any such operation, if it exists, has item creation semantics.

+

As such a method would correspond to JSON Hyper-Schema's data submission concept, the "submissionSchema" [submissionSchema] field for the link SHOULD be compatible with the schema of the representation of the collection's items, as indicated by the "item" link's target resource or the "self" link of the "collection" link's context resource.

+

6.2.4. Using extension relation types

+

When no registered relation (aside from "related") applies, users are encouraged to mint their own extension relation types, as described in section 4.2 of RFC 5988 [RFC5988]. The simplest approaches for choosing link relation type URIs are to either use a URI scheme that is already in use to identify the system's primary resources, or to use a human-readable, non-dereferenceable URI scheme such as "tag", defined by RFC 4151 [RFC4151].

+

Extension relation type URIs need not be dereferenceable, even when using a scheme that allows it.

+

6.3. Link target

+

The target URI template is used to identify the link's target, potentially making use of instance data. Additionally, with "hrefSchema" [hrefSchema], this template can identify a set of possible target resources to use based on client input. The full process of resolving the URI template, with or without client input, is covered in the URI Templating [uriTemplating] section.

+

6.3.1. href

+

The value of the "href" link description property is a template used to determine the target URI of the related resource. The value of the instance property MUST be resolved as a URI-reference [RFC3986] against the base URI of the instance.

+

This property is REQUIRED.

+

6.4. Adjusting URI Template resolution

+

The keywords in this section are used when resolving all URI Templates involved in hyper-schema: "base", "anchor", and "href". See the URI Templating [uriTemplating] section for the complete template resolution algorithm.

+

Note that when resolving a "base" template, the attachment point from which resolution begins is the attachment point of the "href" or "anchor" keyword being resolved which requires "base" templates to be resolved, not the attachment point of the "base" keyword itself.

+

6.4.1. templatePointers

+

The value of the "templatePointers" link description property MUST be an object. Each property value in the object MUST be a valid JSON Pointer [RFC6901], or a valid Relative JSON Pointer [I-D.luff-relative-json-pointer] which is evaluated relative to the attachment point of the link for which the template is being resolved.

+

For each property name in the object that matches a variable name in the template being resolved, the value of that property adjusts the starting position of variable resolution for that variable. Properties which do not match template variable names in the template being resolved MUST be ignored.

+

6.4.2. templateRequired

+

The value of this keyword MUST be an array, and the elements MUST be unique. Each element SHOULD match a variable in the link's URI Template, without percent-encoding. After completing the entire URI Template resolution process, if any variable that is present in this array does not have a value, the link MUST NOT be used.

+

6.5. Link target attributes

+

All properties in this section are advisory only. While keywords such as "title" and "description" are used primarily to present the link to users, those keywords that predict the nature of a link interaction or response MUST NOT be considered authoritative. The runtime behavior of the target resource MUST be respected whenever it conflicts with the target attributes in the LDO.

+

6.5.1. title

+

This property defines a title for the link. The value MUST be a string.

+

User agents MAY use this title when presenting the link to the user.

+

6.5.2. description

+

This property provides additional information beyond what is present in the title. The value MUST be a string. While a title is preferably short, a description can be used to go into more detail about the purpose and usage of the link.

+

User agents MAY use this description when presenting the link to the user.

+

6.5.3. targetMediaType

+

The value of this property represents the media type RFC 2046 [RFC2046], that is expected to be returned when fetching this resource. This property value MAY be a media range instead, using the same pattern defined in RFC 7231, section 5.3.2 - HTTP "Accept" header [RFC7231].

+

This property is analogous to the "type" property of other link serialization formats. User agents MAY use this information to inform the interface they present to the user before the link is followed, but MUST NOT use this information in the interpretation of the resulting data. Instead, a client MUST use the media type given by the response for run-time interpretation. See the section on "Security Concerns" [security] for a detailed examination of mis-use of "targetMediaType".

+

For protocols supporting content-negotiation, implementations MAY choose to describe possible target media types using protocol-specific information in "headerSchema" [headerSchema]. If both protocol-specific information and "targtMediaType" are present, then the value of "targetMediaType" MUST be compatible with the protocol-specific information, and SHOULD indicate the media type that will be returned in the absence of content negotiation.

+

When no such protocol-specific information is available, or when the implementation does not recognize the protocol involved, then the value SHOULD be taken to be "application/json".

+

6.5.4. targetSchema

+

This property provides a schema that is expected to describe the link target's representation. Depending on the protocol, the schema may or may not describe the request or response to any particular operation performed with the link. See the JSON Hyper-Schema and HTTP [HTTP] section for an in-depth discussion of how this keyword is used with HTTP.

+

6.5.5. targetHints

+

[CREF4]This section attempts to strike a balance between comprehensiveness and flexibility by deferring most of its structure to the protocol indicated by the URI scheme. Note that a resource can be identified by a URI with a dereferenceable scheme, yet not be accessible over that protocol. While currently very loose, this section is expected to become more well-defined based on draft feedback, and may change significantly in future drafts.

+

The value of this property is advisory only. It represents information that is expected to be discoverable through interacting with the target resource, typically in the form of protocol-specific control information or meta-data such as headers returned in response to an HTTP HEAD or OPTIONS request. The protocol is determined by the "href" URI scheme, although note that resources are not guaranteed to be accessible over such a protocol.

+

The value of this property SHOULD be an object. The keys to this object SHOULD be lower-cased forms of the control data field names. Each value SHOULD be an array, in order to uniformly handle multi-valued fields. Multiple values MUST be presented as an array, and not as a single string.

+

Protocols with control information not suitable for representation as a JSON object MAY be represented by another data type, such as an array.

+

Values that cannot be understood as part of the indicated protocol MUST be ignored by a JSON Hyper-Schema implementation. Applications MAY make use of such values, but MUST NOT assume interoperability with other implementations.

+

Implementations MUST NOT assume that all discoverable information is accounted for in this object. Clients MUST properly handle run-time responses that contradict this property's values.

+

Clients MUST NOT assume that an implementation will automatically take any action based on the value of this property.

+

See "JSON Hyper-Schema and HTTP" [HTTP] for guidance on using this keyword with HTTP and analogous protocols.

+

6.6. Link input

+

There are four ways to use client-supplied data with a link, and each is addressed by a separate link description object keyword. When performing operations, clients SHOULD ignore schemas that are not relevant to their semantics.

+

6.6.1. hrefSchema

+

The value of the "hrefSchema" link description property MUST be a valid JSON Schema. This schema is used to validate user input or other user agent data for filling out the URI Template in "href" [href].

+

Omitting "hrefSchema" or setting the entire schema to "false" prevents any user agent data from being accepted.

+

Setting any subschema that applies to a particular variable to the JSON literal value "false" prevents any user agent data from being accepted for that single variable.

+

For template variables that can be resolved from the instance data, if the instance data is valid against all applicable subschemas in "hrefSchema", then it MUST be used to pre-populate the input data set for that variable.

+

Note that even when data is pre-populated from the instance, the validation schema for that variable in "hrefSchema" need not be identical to the validation schema(s) that apply to the instance data's location. This allows for different validation rules for user agent data, such as supporting spelled-out months for date-time input, but using the standard date-time format for storage.

+

After input is accepted, potentially overriding the pre-populated instance data, the resulting data set MUST successfully validate against the value of "hrefSchema". If it does not then the link MUST NOT be used. If it is valid, then the process given in the "URI Templating" section continues with this updated data set.

+

6.6.2. headerSchema

+

[CREF5]As with "targetHints", this keyword is somewhat under-specified to encourage experimentation and feedback as we try to balance flexibility and clarity.

+

If present, this property is a schema for protocol-specific request headers or analogous control and meta-data. The value of this object MUST be a valid JSON Schema. The protocol is determined by the "href" URI scheme, although note that resources are not guaranteed to be accessible over such a protocol. The schema is advisory only; the target resource's behavior is not constrained by its presence.

+

The purpose of this keyword is to advertise target resource interaction features, and indicate to clients what headers and header values are likely to be useful. Clients MAY use the schema to validate relevant headers, but MUST NOT assume that missing headers or values are forbidden from use. While schema authors MAY set "additionalProperties" to false, this is NOT RECOMMENDED and MUST NOT prevent clients or user agents from supplying additional headers when requests are made.

+

The exact mapping of the JSON data model into the headers is protocol-dependent. However, in most cases this schema SHOULD specify a type of "object", and the property names SHOULD be lower-cased forms of the control data field names. See the "JSON Hyper-Schema and HTTP" [HTTP] section for detailed guidance on using this keyword with HTTP and analogous protocols.

+

"headerSchema" is applicable to any request method or command that the protocol supports. When generating a request, clients SHOULD ignore schemas for headers that are not relevant to that request.

+

6.6.3. Manipulating the target resource representation

+

In JSON Hyper-Schema, "targetSchema" [targetSchema] supplies a non-authoritative description of the target resource's representation. A client can use "targetSchema" to structure input for replacing or modifying the representation, or as the base representation for building a patch document based on a patch media type.

+

Alternatively, if "targetSchema" is absent or if the client prefers to only use authoritative information, it can interact with the target resource to confirm or discover its representation structure.

+

"targetSchema" is not intended to describe link operation responses, except when the response semantics indicate that it is a representation of the target resource. In all cases, the schema indicated by the response itself is authoritative. See "JSON Hyper-Schema and HTTP" [HTTP] for detailed examples.

+

6.6.4. Submitting data for processing

+

The "submissionSchema" [submissionSchema] and "submissionMediaType" [submissionMediaType] keywords describe the domain of the processing function implemented by the target resource. Otherwise, as noted above, the submission schema and media type are ignored for operations to which they are not relevant.

+

6.6.4.1. submissionMediaType

+

If present, this property indicates the media type format the client should use for the request payload described by "submissionSchema" [submissionSchema].

+

Omitting this keyword has the same behavior as a value of application/json.

+

Note that "submissionMediaType" and "submissionSchema" are not restricted to HTTP URIs. [CREF6]This statement might move to wherever the example ends up.

+

6.6.4.2. submissionSchema

+

This property contains a schema which defines the acceptable structure of the document to be encoded according to the "submissionMediaType" property and sent to the target resource for processing. This can be viewed as describing the domain of the processing function implemented by the target resource.

+

This is a separate concept from the "targetSchema" [targetSchema] property, which describes the target information resource (including for replacing the contents of the resource in a PUT request), unlike "submissionSchema" which describes the user-submitted request data to be evaluated by the resource. "submissionSchema" is intended for use with requests that have payloads that are not necessarily defined in terms of the target representation.

+

Omitting "submissionSchema" has the same behavior as a value of "true".

+

7. Implementation requirements

+

At a high level, a conforming implementation will meet the following requirements. Each of these requirements is covered in more detail in the individual keyword sections and keyword group overviews.

+

Note that the requirements around how an implementation MUST recognize "self", "collection", and "item" links are thoroughly covered in the link relation type [relationType] section and are not repeated here.

+

While it is not a mandatory format for implementations, the output format used in the test suite summarizes what needs to be computed for each link before it can be used:

+ +
+
contextUri
+
The fully resolved URI (with scheme) of the context resource. If the context is not the entire resource and there is a usable fragment identifier syntax, then the URI includes a fragment. Note that there is no such syntax for application/json.
+
contextPointer
+
The JSON Pointer for the location within the instance of the context resource. If the instance media type supports JSON Pointers as fragment identifiers, this pointer will be the same as the one encoded in the fragment of the "contextUri" field.
+
rel
+
The link relation type, as it appears in the LDO.
+
targetUri
+
The fully resolved URI (with a scheme) of the target resource. If the link accepts input, this can only be produced once the input has been supplied.
+
hrefInputTemplates
+
The list of partially resolved URI references for a link that accepts input. The first entry in the list is the partially resolved "href". The additional entries, if any, are the partially resolved "base" values ordered from the most immediate out to the root of the schema. Template variables that are pre-populated in the input are not resolved at this stage, as the pre-populated value can be overridden.
+
hrefPrepopulatedInput
+
The data set that the user agent should use to prepopulate any input mechanism before accepting client input. If input is to be accepted but no fields are to be pre-populated, then this will be an empty object.
+
attachmentPointer
+
The JSON Pointer for the location within the instance to which the link is attached. By default, "contextUri" and "attachementUri" are the same, but "contextUri" can be changed by LDO keywords, while "attachmentUri" cannot.
+
+ +

Other LDO keywords that are not involved in producing the above information are included exactly as they appear when producing output for the test suite. Those fields will not be further discussed here unless specifically relevant.

+

7.1. Link discovery and look-up

+

Before links can be used, they must be discovered by applying the hyper-schema to the instance and finding all applicable and valid links. Note that in addition to collecting valid links, any "base" [base] values necessary to resolve each LDO's URI Templates must also be located and associated with the LDO through whatever mechanism is most useful for the implementation's URI Template resolution process.

+

And implementation MUST support looking up links by either their attachment pointer or context pointer, either by performing the look-up or by providing the set of all links with both pointers determined so that user agents can implement the look-up themselves.

+

When performing look-ups by context pointer, links that are attached to elements of the same array MUST be returned in the same order as the array elements to which they are attached.

+

7.2. URI Templating

+

Three hyper-schema keywords are URI Templates [RFC6570]: "base", "anchor", and "href". Each are resolved separately to URI-references, and then the anchor or href URI-reference is resolved against the base (which is itself resolved against earlier bases as needed, each of which was first resolved from a URI Template to a URI-reference).

+

All three keywords share the same algorithm for resolving variables from instance data, which makes use of the "templatePointers" and "templateRequired" keywords. When resolving "href", both it and any "base" templates needed for resolution to an absolute URI, the algorithm is modified to optionally accept user input based on the "hrefSchema" keyword.

+

For each URI Template (T), the following pseudocode describes an algorithm for resolving T into a URI-reference (R). For the purpose of this algorithm:

+ + + +

+

This algorithm should be applied first to either "href" or "anchor", and then as needed to each successive "base". The order is important, as it is not always possible to tell whether a template will resolve to a full URI or a URI-reference.

+

In English, the high-level algorithm is:

+ +
    +
  1. Populate template variable data from the instance
  2. +
  3. If input is desired, accept input
  4. +
  5. Check that all required variables have a value
  6. +
  7. Encode values into strings and fill out the template
  8. +
+ +

+

This is the high-level algorithm as pseudocode. "T" comes from either "href" or "anchor" within the LDO, or from "base" in a containing schema. Pseudocode for each step follows. "initialTemplateKeyword" indicates which of the two started the process (since "base" is always resolved in order to finish resolving one or the other of those keywords).

+
+
+templateData = populateDataFromInstance(T, ldo, instance)
+
+if initialTemplateKeyword == "href" and ldo.hrefSchema exists:
+    inputData = acceptInput(ldo, instance, templateData)
+    for varname in inputData:
+        templateData[varname] = inputData[varname]
+
+for varname in ldo.templateRequired:
+    if not exists templateData[varname]
+        fatal("Missing required variable(s)")
+
+templateData = stringEncode(templateData)
+R = rfc6570ResolutionAlgorithm(T, templateData)
+
+                    
+

7.2.1. Populating template data from the instance

+

This step looks at various locations in the instance for variable values. For each variable:

+ +
    +
  1. Use "templatePointers" to find a value if the variable appears in that keyword's value
  2. +
  3. Otherwise, look for a property name matching the variable in the instance location to which the link is attached
  4. +
  5. In either case, if there is a value at the location, put it in the template resolution data set
  6. +
+ +

+
+
+for varname in T:
+    varname = rfc3986PercentDecode(varname)
+    if varname in ldo.templatePointers:
+        valuePointer = templatePointers[varname]
+        if valuePointer is relative:
+            valuePointer = resolveRelative(attachmentPointer,
+                                           valuePointer)
+    else
+        valuePointer = attachmentPointer + "/" + varname
+
+    value = instance.valueAt(valuePointer)
+    if value is defined:
+        templateData[varname] = value
+
+                        
+

7.2.2. Accepting input for template data

+

This step is relatively complex, as there are several cases to support. Some variables will forbid input and some will allow it. Some will have initial values that need to be presented in the input interface, and some will not.

+

+ +

    +
  1. Deterimine which variables can accept input
  2. +
  3. Pre-populate the input data set if the template resolution data set has a value
  4. +
  5. Accept input (present a web form, make a callback, etc.)
  6. +
  7. Validate the input data set, (not the template resolution data set)
  8. +
  9. Put the input in the template resolution data set, overriding any existing values
  10. +
+ +

+

"InputForm" represents whatever sort of input mechanism is appropriate. This may be a literal web form, or may be a more programmatic construct such as a callback function accepting specific fields and data types, with the given initial values, if any.

+
+
+form = new InputForm()
+for varname in T:
+    useField = true
+    useInitialData = true
+    for schema in getApplicableSchemas(ldo.hrefSchema,
+                                       "/" + varname):
+        if schema is false:
+            useField = false
+            break
+
+        if varname in templateData and
+           not isValid(templateData[varname], schema)):
+            useInitialData = false
+            break
+
+    if useField:
+        if useInitialData:
+            form.addInputFieldFor(varname, ldo.hrefSchema,
+                                  templateData[varname])
+        else:
+            form.addInputFieldFor(varname, ldo.hrefSchema)
+
+inputData = form.acceptInput()
+
+if not isValid(inputData, hrefSchema):
+    fatal("Input invalid, link is not usable")
+
+return inputData:
+
+                        
+

7.2.3. Encoding data as strings

+

This section is straightforward, converting literals to their names as strings, and converting numbers to strings in the most obvious manner, and percent-encoding as needed for use in the URI.

+
+
+for varname in templateData:
+    value = templateData[varname]
+    if value is true:
+        templateData[varname] = "true"
+    else if value is false:
+        temlateData[varname] = "false"
+    else if value is null:
+        templateData[varname] = "null"
+    else if value is a number:
+        templateData[varname] =
+            bestEffortOriginalJsonString(value)
+    else:
+        templateData[varname] = rfc3986PercentEncode(value)
+
+                        
+

In some software environments the original JSON representation of a number will not be available (there is no way to tell the difference between 1.0 and 1), so any reasonable representation should be used. Schema and API authors should bear this in mind, and use other types (such as string or boolean) if the exact representation is important. If the number was provide as input in the form of a string, the string used as input SHOULD be used.

+

7.3. Providing access to LDO keywords

+

For a given link, an implementation MUST make the values of all target attribute keywords directly available to the user agent. Implementations MAY provide additional interfaces for using this information, as discussed in each keyword's section.

+

For a given link, an implementation MUST make the value of each input schema keyword directly available to the user agent.

+

To encourage encapsulation of the URI Template resolution process, implementations MAY omit the LDO keywords that are used only to construct URIs. However, implementations MUST provide access to the link relation type.

+

Unrecognized keywords SHOULD be made available to the user agent, and MUST otherwise be ignored.

+

7.4. Requests

+

A hyper-schema implementation SHOULD provide access to all information needed to construct any valid request to the target resource.

+

The LDO can express all information needed to perform any operation on a link. This section explains what hyper-schema fields a user agent should examine to build requests from any combination of instance data and client input. A hyper-schema implementation is not itself expected to construct and send requests.

+

Target URI construction rules, including "hrefSchema" for accepting input, are identical for all possible requests.

+

Requests that do not carry a body payload do not require additional keyword support.

+

Requests that take a target representation as a payload SHOULD use the "targetSchema" and "targetMediaType" keywords for input description and payload validation. If a protocol allows an operation taking a payload that is based on the representation as modified by a media type (such as a patch media type), then such a media type SHOULD be indicated through "targetHints" in a protocol-specific manner.

+

Requests that take a payload that is not derived from the target resource's representation SHOULD use the "submissionSchema" and "submissionMediaType" keywords for input description and payload validation. Protocols used in hypermedia generally only support one such non-representation operation per link.

+

RPC systems that pipe many application operations with arbitrarily different request structures through a single hypermedia protocol operation are outside of the scope of a hypermedia format such as JSON Hyper-Schema.

+

7.5. Responses

+

As a hypermedia format, JSON Hyper-Schema is concerned with describing a resource, including describing its links in sufficient detail to make all valid requests. It is not concerned with directly describing all possible responses for those requests.

+

As in any hypermedia system, responses are expected to be self-describing. In the context of hyper-schema, this means that each response MUST link its own hyper-schema(s). While responses that consist of a representation of the target resource are expected to be valid against "targetSchema" and "targetMediaType", those keywords are advisory only and MUST be ignored if contradicted by the response itself.

+

Other responses, including error responses, complex redirections, and processing status representations SHOULD also link to their own schemas and use appropriate media types (e.g. "application/problem+json" [RFC7807] for errors). Certain errors might not link a schema due to being generated by an intermediary that is not aware of hyper-schema, rather than by the origin.

+

User agents are expected to understand protocol status codes and response media types well enough to handle common situations, and provide enough information to client applications to handle domain-specific responses.

+

Statically mapping all possible responses and their schemas at design time is outside of the scope of JSON Hyper-Schema, but may be within the scope of other JSON Schema vocabularies which build on hyper-schema (see Appendix A.3).

+

7.6. Streaming parsers

+

The requirements around discovering links based on their context, or using the context of links to identify collections, present unique challenges when used with streaming parsers. It is not possible to authoritatively fulfill these requirements without processing the entire schema and instance documents.

+

Such implementations MAY choose to return non-authoritative answers based on data processed to date. When offering this approach, implementations MUST be clear on the nature of the response, and MUST offer an option to block and wait until all data is processed and an authoritative answer can be returned.

+

8. JSON Hyper-Schema and HTTP

+

While JSON Hyper-Schema is a hypermedia format and therefore protocol-independent, it is expected that its most common use will be in HTTP systems, or systems using protocols such as CoAP that are explicitly analogous to HTTP.

+

This section provides guidance on how to define links for use with each common HTTP method, and how collection resources impose additional constraints on the use of HTTP POST. Additionally, guidance is provided on hinting at HTTP response header values and describing possible HTTP request headers that are relevant to the given resource.

+

8.1. One link per target and relation type

+

Link Description Objects do not directly indicate what operations, such as HTTP methods, are supported by the target resource. Instead, operations should be inferred primarily from link relation types [rel] and URI schemes.

+

This means that for each target resource and link relation type pair, schema authors SHOULD only define a single LDO. While it is possible to use "allow" with "targetHints" to repeat a relation type and target pair with different HTTP methods marked as allowed, this is NOT RECOMMENDED and may not be well-supported by conforming implementations.

+

All information necessary to use each HTTP method can be conveyed in a single LDO as explained in this section. The "allow" field in "targetHints" is intended simply to hint at which operations are supported, not to separately define each operation.

+

Note, however, that a resource may always decline an operation at runtime, for instance due to authorization failure, or due to other application state that controls the operation's availability.

+

8.2. "targetSchema" and HTTP

+

The relationship between a resource's representation and HTTP requests and responses is determined by RFC 7231, section 4.3.1 - "GET", section 4.3.4 "PUT", and section 3.1.4.2, "Content-Location" [RFC7231]. In particular, "targetSchema" suggests what a client can expect for the response to an HTTP GET or any response for which the "Content-Location" header is equal to the request URI, and what a client should send if it replaces the resource in an HTTP PUT request.

+

The media type of the representation is given by the "targetMediaType" field. Alternatively, possible available media types MAY be advertised for HTTP-accessible resources using the "accept" field in "headerSchema", corresponding to the HTTP "Accept" header.

+

Per RFC 5789 [RFC5789], the request structure for an HTTP PATCH is determined by the combination of "targetSchema" and the request media type, which is conveyed by the "Accept-Patch" header. Media types that are suitable for PATCH-ing define a syntax for expressing changes to a document, which can be applied to the representation described by "targetSchema" to determine the set of syntactically valid request payloads.

+

HTTP POST request payloads are described by the "submissionSchema" and "submissionMediaType" fields. Additionally, the "Accept-Post" header can be used to specify the necessary media type, and MAY be advertised via the "targetHints" field. [CREF7]What happens if both are used? Also, "submissionSchema" is a MUST to support, while "targetHints" are at most a SHOULD. But forbidding the use of "Accept-Post" in "targetHints" seems incorrect.

+

8.3. Optimizing HTTP discoverability with "targetHints"

+

[CREF8]It would be good to also include a section with CoAP examples.

+

JSON serializations of HTTP response header information SHOULD follow the guidelines established by the work in progress "A JSON Encoding for HTTP Header Field Values" [I-D.reschke-http-jfv]. Approaches shown in that document's examples SHOULD be applied to other similarly structured headers wherever possible.

+

No distinction is made between headers that may appear in responses to different methods, such as HEAD vs OPTIONS.

+

It is RECOMMENDED that schema authors provide hints for the values of the following types of HTTP headers whenever applicable:

+ + + +

+

In general, headers that are likely to have different values at different times SHOULD NOT be included in "targetHints".

+

8.4. Advertising HTTP features with "headerSchema"

+

Schemas SHOULD be written to describe JSON serializations that follow guidelines established by the work in progress "A JSON Encoding for HTTP Header Field Values" [I-D.reschke-http-jfv] Approaches shown in that document's examples SHOULD be applied to other similarly structured headers wherever possible.

+

It is RECOMMENDED that schema authors describe the available usage of the following types of HTTP headers whenever applicable:

+ + + +

+

Headers such as cache control and conditional request headers are generally implemented by intermediaries rather than the resource, and are therefore not generally useful to describe. While the resource must supply the information needed to use conditional requests, the runtime handling of such headers and related responses is not resource-specific.

+

8.5. Creating resources through collections

+

When using HTTP, or a protocol such as CoAP that is explicitly analogous to HTTP, this is done by POST-ing a representation of the individual resource to be created to the collection resource. The process for recognizing collection and item resources is described in Section 6.2.3.

+

9. Examples

+

This section shows how the keywords that construct URIs and JSON Pointers are used. The results are shown in the format used by the test suite. [CREF9]Need to post that and link it, but it should be pretty self-explanatory to those of you reviewing things at this stage.

+

Most other keywords are either straightforward ("title" and "description"), apply validation to specific sorts of input, requests, or responses, or have protocol-specific behavior. Examples demonstrating HTTP usage are available in an Appendix [HTTP].

+

9.1. Entry point links, no templates

+

For this example, we will assume an example API with a documented entry point URI of https://example.com, which is an empty JSON object with a link to a schema. Here, the entry point has no data of its own and exists only to provide an initial set of links:

+
+
+GET https://api.example.com HTTP/1.1
+
+200 OK
+Content-Type: application/json
+Link: <https://schema.example.com/entry> rel=describedBy
+{}
+
+                    
+

The linked hyper-schema defines the API's base URI and provides two links: an "about" link to API documentation, and a "self" link indicating that this is a schema for the base URI. In this case the base URI is also the entry point URI.

+
+
+{
+    "$id": "https://schema.example.com/entry",
+    "$schema": "http://json-schema.org/draft-07-wip/hyper-schema#",
+    "base": "https://api.example.com",
+    "links": [
+        {
+            "rel": "self",
+            "href": ""
+        },
+        {
+            "rel": "about",
+            "href": "/docs"
+        }
+    ]
+}
+                    
+

These are the simplest possible links, with only a relation type and an "href" with no template variables. They resolve as follows:

+
+[
+    {
+        "contextUri": "https://api.example.com",
+        "contextPointer": "",
+        "rel": "self",
+        "targetUri": "https://api.example.com",
+        "attachmentPointer": ""
+    },
+    {
+        "contextUri": "https://api.example.com",
+        "contextPointer": "",
+        "rel": "about",
+        "targetUri": "https://api.example.com/docs",
+        "attachmentPointer": ""
+    }
+]
+                    
+

The attachment pointer is the root pointer (the only possiblity with an empty object for the instance). The context URI is the default, which is the requested document. Since application/json does not allow for fragments, the context pointer is necessary to fully describe the context. Its default behavior is to be the same as the attachment pointer.

+

9.2. Individually identified resources

+

Let's add "things" to our system, starting with an individual thing:

+
+{
+    "$id": "https://schema.example.com/thing",
+    "$schema": "http://json-schema.org/draft-07-wip/hyper-schema#",
+    "base": "https://api.example.com",
+    "type": "object",
+    "required": ["data"],
+    "properties": {
+        "id": {"$ref": "#/definitions/id"},
+        "data": true
+    },
+    "links": [
+        {
+            "rel": "self",
+            "href": "things/{id}",
+            "templateRequired": ["id"],
+            "targetSchema": {"$ref": "#"}
+        }
+    ],
+    "definitions": {
+        "id": {
+            "type": "integer",
+            "minimum": 1,
+            "readOnly": true
+        }
+    }
+}
+                    
+

Our "thing" has a server-assigned id, which is required in order to construct the "self" link. It also has a "data" field which can be of any type. The reason for the "definitions" section will be clear in the next example.

+

Note that "id" is not required by the validation schema, but is required by the self link. This makes sense: a "thing" only has a URI if it has been created, and the server has assigned an id. However, you can use this schema with an instance containing only the data field, which allows you to validate "thing" instances that you are about to create.

+

Let's add a link to our entry point schema that lets you jump directly to a particular thing if you can supply it's id as input. To save space, only the new LDO is shown. Unlike "self" and "about", there is no IANA-registered relationship about hypothetical things, so an extension relationship is defined using the "tag:" URI scheme [RFC4151]:

+
+{
+    "rel": "tag:rel.example.com,2017:thing",
+    "href": "things/{id}",
+    "hrefSchema": {
+        "required": ["id"],
+        "properties": {
+            "id": {"$ref": "thing#/definitions/id"}
+        }
+    },
+    "targetSchema": {"$ref": "thing#"}
+}
+                    
+

The "href" value here is the same, but everything else is different. Recall that the instance is an empty object, so "id" cannot be resolved from instance data. Instead it is required as client input. This LDO could also have used "templateRequired" but with "required" in "hrefSchema" it is not strictly necessary. Providing "templateRequired" without marking "id" as required in "hrefSchema" would lead to errors, as client input is the only possible source for resolving this link.

+

9.3. Submitting a payload and accepting URI input

+

This example covers using the "submission" fields for non-representation input, as well as using them alongside of resolving the URI Template with input. Unlike HTML forms, which require either constructing a URI or sending a payload, but do not allow not both at once, JSON Hyper-Schema can describe both sorts of input to for the same operation on the same link.

+

The "submissionSchema" and "submissionMediaType" fields are for describing payloads that are not representations of the target resource. When used with "http(s)://" URIs, they generally refer to a POST request payload, as seen in the appendix on HTTP usage [HTTP].

+

In this case, we use a "mailto:" URI, which, per RFC 6068, Section 3" [RFC6068], does not provide any operation for retrieving a resource. It can only be used to construct a message for sending. Since there is no concept of a retrievable, replaceable, or deletable target resource, "targetSchema" and "targetMediaType" are not used. Non-representation payloads are described by "submissionSchema" and "submission MediaType".

+

Therefore, we use "submissionMediaType" to indicate a multipart/alternative payload format, providing two representations of the same data (HTML and plain text). Since a multipart/alternative message is an ordered sequence (the last part is the most preferred alternative), we model the sequence as an array in "submissionSchema". Since each part is itself a document with a media type, we model each item in the array as a string, using "contentMediaType" to indicate the format within the string.

+

Note that media types such as multipart/form-data, which associate a name with each part and are not ordered, should be modeled as JSON objects rather than arrays.

+

For the URI parameters, each of the three demonstrates a different way of resolving the input:

+ +
+
email:
+
This variable's presence in "templateRequired" means that it must be resolved for the template to be used. Since the "false" schema assigned to it in "hrefSchema" excludes it from the input data set, it must be resolved from the instance.
+
title:
+
The instance field matching this variable is required, and it is also allowed in the input data. So its instance value is used to pre-populate the input data set before accepting the client's input. The client can opt to leave the instance value in place. Since this field is required in "hrefSchema", the client cannot delete it (although it could set it to an empty string).
+
cc:
+
The "false" schema set for this in the main schema prevents this field from having an instance value. If it is present at all, it must come from client input. As it is not required in "hrefSchema", it may not be used at all.
+
+ +

+

Note that some lines are wrapped to fit this document's width restrictions.

+
+{
+    "$id": "https://schema.example.com/interesting-stuff",
+    "$schema": "http://json-schema.org/draft-07-wip/hyper-schema#",
+    "required": ["stuffWorthEmailingAbout", "email", "title"],
+    "properties": {
+        "title": {
+            "type": "string"
+        },
+        "stuffWorthEmailingAbout": {
+            "type": "string"
+        },
+        "email": {
+            "type": "string",
+            "format": "email"
+        },
+        "cc": false
+    },
+    "links": [
+        {
+            "rel": "author",
+            "href": "mailto:{email}?subject={title}{&cc}",
+            "templateRequired": ["email"],
+            "hrefSchema": {
+                "required": ["title"],
+                "properties": {
+                    "title": {
+                        "type": "string"
+                    },
+                    "cc": {
+                        "type": "string",
+                        "format": "email"
+                    },
+                    "email": false
+                }
+            }
+            "submissionMediaType":
+                    "multipart/alternative; boundary=ab2",
+            "submissionSchema": {
+                "type": "array",
+                "items": [
+                    {
+                        "type": "string",
+                        "contentMediaType":
+                                "text/plain; charset=utf8"
+                    },
+                    {
+                        "type": "string",
+                        "contentMediaType": "text/html"
+                    }
+                ],
+                "minItems": 2
+            }
+        }
+    ]
+}
+                    
+

So, given the following instance retrieved from "https://api.example.com/stuff":

+
+{
+    "title": "The Awesome Thing",
+    "stuffWorthEmailingAbout": "Lots of text here...",
+    "email": "someone@exapmle.com"
+}
+                    
+

We can partially resolve the link as follows, before asking the client for input.

+
+{
+    "contextUri": "https://api.example.com/stuff",
+    "contextPointer": "",
+    "rel": "author",
+    "hrefInputTemplates": [
+      "mailto:someone@example.com?subject={title}{&cc}",
+    ],
+    "hrefPrepopulatedInput": {
+        "title": "The Really Awesome Thing"
+    },
+    "attachmentPointer": ""
+}
+                    
+

Notice the "href*" keywords in place of "targetUri". These are three possible "targetUri" values covering different sorts of input:

+ +
+
No additional or changed input:
+
"mailto:someone@example.com?subject=The%20Awesome%20Thing"
+
Change "title" to "your work":
+
"mailto:someone@example.com?subject=your%20work"
+
Change title and add a "cc" of "other@elsewhere.org":
+
"mailto:someone@example.com?subject=your%20work&cc=other@elsewhere.org"
+
+ +

+

9.4. "anchor" and "base" as URI Templates

+

+ [CREF10]"base" used as a template with both "anchor" and "href" templates. +

+

9.5. Collections

+

+ [CREF11]Reciprocal collection/item relations Pagination: fixed links vs jumping to an arbitrary offset Using "anchorPointer" and "templatePointers" Discovering ordered links Multiple self links (for the collection and each item) +

+

In many systems, individual resources are grouped into collections. Those collections also often provide a way to create individual item resources with server-assigned identifiers.

+

This schema describes a collection where each item representation is identical to the individual resource item representation, and there is enough metadata included in the collection representation to produce pagination links. The "first" and "last" pagination links were omitted as this is already a long example.

+

Note that there is an object member called "items", which is an array and thefore uses the validation keyword "items" in its own schema. The outer "items" is a property name, the inner one is a schema keyword.

+
+{
+    "$id": "https://schema.example.com/thing-collection",
+    "$schema": "http://json-schema.org/draft-07-wip/hyper-schema#",
+    "base": "https://api.example.com",
+    "type": "object",
+    "required": ["items"],
+    "properties": {
+        "items": {
+            "type": "array",
+            "items": {
+                "allOf": [{"$ref": "thing#"}],
+                "links": [
+                    {
+                        "anchorPointer": "",
+                        "rel": "item",
+                        "href": "things/{id}",
+                        "hrefRequired": ["id"],
+                        "targetSchema": {"$ref": "thing#"}
+                    }
+                ]
+            }
+        },
+        "meta": {
+            "type": "object",
+            "properties": {
+                "prev": {"$ref": "#/definitions/scrolling"},
+                "current": {"$ref": "#/definitions/scrolling"},
+                "next": {"$ref": "#/definitions/scrolling"}
+            }
+        }
+    },
+    "links": [
+        {
+            "rel": "self",
+            "href": "things{?offset,limit}",
+            "hrefRequired": ["offset", "limit"],
+            "hrefPointers": {
+                "offset": "/meta/current/offset",
+                "limit": "/meta/current/limit"
+            },
+            "targetSchema": {"$ref": "#"}
+        },
+        {
+            "rel": "prev",
+            "href": "things{?offset,limit}",
+            "hrefRequired": ["offset", "limit"],
+            "hrefPointers": {
+                "offset": "/meta/prev/offset",
+                "limit": "/meta/prev/limit"
+            },
+            "targetSchema": {"$ref": "#"}
+        },
+        {
+            "rel": "next",
+            "href": "things{?offset,limit}",
+            "hrefRequired": ["offset", "limit"],
+            "hrefPointers": {
+                "offset": "/meta/next/offset",
+                "limit": "/meta/next/limit"
+            },
+            "targetSchema": {"$ref": "#"}
+        }
+    ],
+    "definitions": {
+        "scrolling": {
+            "type": "object",
+            "properties": {
+                "offset": {
+                    "type": "integer",
+                    "minimum": 0,
+                    "default": 0
+                },
+                "limit": {
+                    "type": "integer",
+                    "minimum": 1,
+                    "maximum": 100,
+                    "default": 10
+                }
+            }
+        }
+    }
+}
+                    
+

Notice that the "self" link includes the pagination query that produced the exact representation, rather than being a generic link to the collection allowing selecting the page via input. There is no link for manual page selection in the example as shown here, nor is there a "submissionSchema" for item creation, but we will consider those additions further down.

+
+{
+    "items": [
+        {"id": 12345, "data": {}},
+        {"id": 67890, "data": {}}
+    ],
+    "meta": {
+        "current": {
+            "offset": 0,
+            "limit": 2
+        },
+        "next": {
+            "offset": 3,
+            "limit": 2
+        }
+    }
+}
+                    
+

Here are all of the links that apply to this instance, including those that are referenced by using the "thing" schema for the individual items. The "self" links for the overal resource and each individual item are distinguished by different context pointers. Note also that the "item" and "self" links for a given thing have identical target URIs but different context pointers.

+
+[
+    {
+        "contextUri": "https://api.example.com/things",
+        "contextPointer": "",
+        "rel": "self",
+        "targetUri": "https://api.example.com/things?offset=20,limit=2",
+        "attachmentPointer": ""
+    },
+    {
+        "contextUri": "https://api.example.com/things",
+        "contextPointer": "",
+        "rel": "next",
+        "targetUri": "https://api.example.com/things?offset=22,limit=2",
+        "attachmentPointer": ""
+    },
+    {
+        "contextUri": "https://api.example.com/things",
+        "contextPointer": "",
+        "rel": "item",
+        "targetUri": "https://api.example.com/things/1234",
+        "attachmentPointer": "/items/0"
+    },
+    {
+        "contextUri": "https://api.example.com/things",
+        "contextPointer": "",
+        "rel": "item",
+        "targetUri": "https://api.example.com/things/67890",
+        "attachmentPointer": "/items/1"
+    },
+    {
+        "contextUri": "https://api.example.com/things",
+        "contextPointer": "/items/0",
+        "rel": "self",
+        "targetUri": "https://api.example.com/things/1234",
+        "attachmentPointer": "/items/0"
+    },
+    {
+        "contextUri": "https://api.example.com/things",
+        "contextPointer": "/items/1",
+        "rel": "self",
+        "targetUri": "https://api.example.com/things/67890",
+        "attachmentPointer": "/items/1"
+    }
+]
+
+                    
+

Note that there is no "prev" link in the output, as we are looking at the first page. The lack of a "prev" field under "meta", together with the "prev" link's "hrefRequired" values, means that the link is not usable with this particular instance.

+

To fully specify our collection, we also need to add the following link to our "thing" schema. Note that this would cause it to also appear as a link in each item in the collection representation, which is a good example of why it is best to only construct links upon request. There is no need for having as many functionally identical "collection" links as there are items in a collection page on every collection representation.

+

This link would be added to the top-level "links" array in the "https://schemasexample.com/thing" schema.

+
+{
+    "rel": "collection",
+    "href": "/things",
+    "targetSchema": {"$ref": "thing-collection#"},
+    "submissionSchema": {"$ref": "#"}
+}
+                    
+

Here we see the "submissionSchema" indicating that we can create a single "thing" by submitting a representation (minus server-created fields such as "id") to the collection that is this link's target schema. While we cannot, in general, make assumptions about the semantics of making a data submission request (in HTTP terms, a POST), Section 6.2.3 tells us that we MAY make such an assumption when the link relation is "collection", and that hyper-schema authors MUST NOT use a "collection" link if the data submission operation has semantics other than item creation.

+

[CREF12]I left off the scrolling parameters for this link. Technically, the link should go to the page containing the specific "thing" that is the context of the link. If the collection is using semantic sorting, then this is do-able (ideally setting the page boundary such that this is the first item, and allowing input on the page count / "limit" parameter). But getting into semantic scrolling/pagination seems way too involved for this example.

+

[CREF13]Note also that POST-ing to a collection page that will not contain the created item also seems weird. While retrieving the collection from a query parameter-less URI will still retrieve a page, that's a limit imposed by the server. POST-ing to such a URI and disregarding the "default" values for the parameters seems correct. This is another reason to *not* automatically write default values into the query.

+

But what if we do not have any "thing"s yet? We cannot get to the individual "thing" schema as there is no individual "thing" to fetch. And the "tag:rel.example.com,2017:thing" link in the entry point resource does not indicate how to create a "thing". The "self" link requires the "id" to already exist, but it is assigned by the server. So we need to add another link to our entry point schema:

+

This LDO would be added to the top-level "links" array in the entry point resource's hyper-schema.

+
+{
+    "rel": "tag:rel.example.com,2017:thing-collection",
+    "href": "/things{?offset,limit}",
+    "hrefSchema": {
+        "$ref": "thing-collection#/definitions/scrolling"
+    },
+    "submissionSchema": {
+        "$ref": "thing#"
+    },
+    "targetSchema": {
+        "$ref": "thing-collection#"
+    }
+}
+                    
+

Now we see the scrolling parameters being accepted as input, so we can jump to any scroll window within the collection.

+

[CREF14]Here we also see the "submissionSchema" to use to create a "thing", but how do we recognize it? We can't use a "collection" link relation here, because there is no identifiable "thing" to serve as the context resource. We could look at the submission schema, notice that it has a "collection" link and is therefore an item, and notice that its "collection" link produces the same(-ish?) URI, but that seems overly complicated and also gets into trouble with query parameters again.

+

10. Security Considerations

+

+ [CREF15]Need to reference the core and validation security considerations. +

+

10.1. "self" links

+

When link relation of "self" is used to denote a full representation of an object, the user agent SHOULD NOT consider the representation to be the authoritative representation of the resource denoted by the target URI if the target URI is not equivalent to or a sub-path of the URI used to request the resource representation which contains the target URI with the "self" link.

+

10.2. Target attributes

+

[CREF16]This whole section needs more work, but I do like having security concerns around target interactions consolidated and addressed as a whole.

+

The "targetMediaType" property in link definitions defines the expected format of the link's target. However, this is advisory only, and MUST NOT be considered authoritative.

+

When choosing how to interpret data, the type information provided by the server (or inferred from the filename, or any other usual method) MUST be the only consideration, and the "targetMediaType" property of the link MUST NOT be used. User agents MAY use this information to determine how they represent the link or where to display it (for example hover-text, opening in a new tab). If user agents decide to pass the link to an external program, they SHOULD first verify that the data is of a type that would normally be passed to that external program.

+

This is to guard against re-interpretation of "safe" data, similar to the precautions for "targetSchema".

+

The "targetSchema" keyword has similar security concerns to that of "targetMediaType". Clients MUST NOT use the value of this property to aid in the interpretation of the data received in response to following the link, as this leaves "safe" data open to re-interpretation.

+

11. Acknowledgments

+

Thanks to Gary Court, Francis Galiegue, Kris Zyp, and Geraint Luff for their work on the initial drafts of JSON Schema.

+

Thanks to Jason Desrosiers, Daniel Perrett, Erik Wilde, Ben Hutton, Evgeny Poberezkin, Brad Bowman, Gowry Sankar, Donald Pipowitch, Dave Finlay, and Denis Laxalde for their submissions and patches to the document.

+

12. References

+

12.1. Normative References

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ [RFC2119] + Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997.
+ [RFC3986] + Berners-Lee, T., Fielding, R. and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, DOI 10.17487/RFC3986, January 2005.
+ [RFC6570] + Gregorio, J., Fielding, R., Hadley, M., Nottingham, M. and D. Orchard, "URI Template", RFC 6570, DOI 10.17487/RFC6570, March 2012.
+ [RFC6901] + Bryan, P., Zyp, K. and M. Nottingham, "JavaScript Object Notation (JSON) Pointer", RFC 6901, DOI 10.17487/RFC6901, April 2013.
+ [I-D.luff-relative-json-pointer] + Luff, G., "Relative JSON Pointers", Internet-Draft draft-luff-relative-json-pointer-00, July 2013.
+ [I-D.reschke-http-jfv] + Reschke, J., "A JSON Encoding for HTTP Header Field Values", Internet-Draft draft-reschke-http-jfv-06, June 2017.
+ [json-schema] + Wright, A., "JSON Schema: A Media Type for Describing JSON Documents", Internet-Draft draft-wright-json-schema-01, October 2016.
+ [json-schema-validation] + Wright, A., "JSON Schema Validation: A Vocabulary for Structural Validation of JSON", Internet-Draft draft-wright-json-schema-validation-01, October 2016.
+

12.2. Informative References

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ [RFC2046] + Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types", RFC 2046, DOI 10.17487/RFC2046, November 1996.
+ [RFC4151] + Kindberg, T. and S. Hawke, "The 'tag' URI Scheme", RFC 4151, DOI 10.17487/RFC4151, October 2005.
+ [RFC5789] + Dusseault, L. and J. Snell, "PATCH Method for HTTP", RFC 5789, DOI 10.17487/RFC5789, March 2010.
+ [RFC5988] + Nottingham, M., "Web Linking", RFC 5988, DOI 10.17487/RFC5988, October 2010.
+ [RFC6068] + Duerst, M., Masinter, L. and J. Zawinski, "The 'mailto' URI Scheme", RFC 6068, DOI 10.17487/RFC6068, October 2010.
+ [RFC6573] + Amundsen, M., "The Item and Collection Link Relations", RFC 6573, DOI 10.17487/RFC6573, April 2012.
+ [RFC7230] + Fielding, R. and J. Reschke, "Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing", RFC 7230, DOI 10.17487/RFC7230, June 2014.
+ [RFC7231] + Fielding, R. and J. Reschke, "Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content", RFC 7231, DOI 10.17487/RFC7231, June 2014.
+ [RFC7807] + Nottingham, M. and E. Wilde, "Problem Details for HTTP APIs", RFC 7807, DOI 10.17487/RFC7807, March 2016.
+ [I-D.nottingham-rfc5988bis] + Nottingham, M., "Web Linking", Internet-Draft draft-nottingham-rfc5988bis-08, August 2017.
+

Appendix A. Using JSON Hyper-Schema in APIs

+

Hypermedia APIs, which follow the constraints of the REST architectural style, enable the creation of generic user agents. Such a user agent has no application-specific knowledge. Rather, it understands pre-defined media types, URI schemes, protocols, and link relations, often by recognizing these and coordinating the use of existing software that implements support for them. Client applications can then be built on top of such a user agent, focusing on their own semantics and logic rather than the mechanics of the interactions.

+

Hyper-schema is only concerned with one resource and set of associated links at a time. Just as a web browser works with only one HTML page at a time, with no concept of whether or how that page functions as part of a "site", a hyper-schema-aware user agent works with one resource at a time, without any concept of whether or how that resource fits into an API.

+

Therefore, hyper-schema is suitable for use within an API, but is not suitable for the description of APIs as complete entities in their own right. There is no way to describe concepts at the API scope, rather than the resource and link scope, and such descriptions are outside of the boundaries of JSON Hyper-Schema.

+

A.1. Resource evolution with Hyper-Schema

+

Since a given JSON Hyper-Schema is used with a single resource at a single point in time, it has no inherent notion of versioning. However, a given resource can change which schema or schemas it uses over time, and the URIs of these schemas can be used to indicate versioning information. When used with a media type that supports indicating a schema with a media type parameter, these versioned schema URIs can be used in content negotiation.

+

A resource can indicate that it is an instance of multiple schemas, which allows supporting multiple compatible versions simultaneously. A client application can then make use of the hyper-schema that it recognizes, and ignore newer or older versions.

+

A.2. Responses and errors

+

Because a hyper-schema represents a single resource at a time, it does not provide for an enumeration of all possible responses to protocol operations performed with links. Each response, including errors, is considered its own (possibly anonymous) resource, and should identify its own hyper-schema, and optionally use an appropriate media type such as RFC 7807's "application/problem+json" [RFC7807], to allow the user agent or client application to interpret any information that is provided beyond the protocol's own status reporting.

+

A.3. Static analysis of an API's hyper-schemas

+

It is possible to statically analyze a set of hyper-schemas without instance data in order to generate output such as documentation or code. However, the full feature set of both validation and hyper-schema cannot be accessed without runtime instance data.

+

This is an intentional design choice to provide the maximum runtime flexibility for hypermedia systems. JSON Schema as a media type allows for establishing additional vocabularies for static analysis and content generation, which are not addressed in this specification. Additionally, individual systems may restrict their usage to subsets that can be analyzed statically if full design-time description is a goal. [CREF17]Vocabularies for API documentation and other purposes have been proposed, and contributions are welcome at https://github.com/json-schema-org/json-schema-vocabularies

+

Appendix B. Change Log

+

[CREF18]This section to be removed before leaving Internet-Draft status.

+

+ +

+
draft-handrews-json-schema-hyperschema-00
+
+
    +
  • Top to bottom reorganization and rewrite
  • +
  • Group keywords per RFC 5988bis context/relation/target/target attributes
  • +
  • Additional keyword groups for template resolution and describing input
  • +
  • Added section on general implementation requirements
  • +
  • Expanded overview to provide context
  • +
  • Consolidated HTTP guidance in its own section
  • +
  • Added a subsection on static analysis of hyper-schemas
  • +
  • Consolidated security concerns in their own section
  • +
  • Added an appendix on usage in APIs
  • +
  • Moved "readOnly" to the validation specification
  • +
  • Moved "media" to validation as "contentMediaType"/"contentEncoding"
  • +
  • Renamed "submissionEncType" to "submissionMediaType"
  • +
  • Renamed "mediaType" to "targetMediaType"
  • +
  • Added "anchor" and "anchorPointer"
  • +
  • Added "templatePointers" and "templateRequired"
  • +
  • Clarified how "hrefSchema" is used
  • +
  • Added "targetHints" and "headerSchema"
  • +
  • Added guidance on "self", "collection" and "item" link usage
  • +
  • Added "description" as an LDO keyword
  • +
  • Added "$comment" in LDOs to match the schema keyword
  • +
+

+
+
draft-wright-json-schema-hyperschema-01
+
+
    +
  • Fixed examples
  • +
  • Added "hrefSchema" for user input to "href" URI Templates
  • +
  • Removed URI Template pre-processing
  • +
  • Clarified how links and data submission work
  • +
  • Clarified how validation keywords apply hyper-schema keywords and links
  • +
  • Clarified HTTP use with "targetSchema"
  • +
  • Renamed "schema" to "submissionSchema"
  • +
  • Renamed "encType" to "submissionEncType"
  • +
  • Removed "method"
  • +
+

+
+
draft-wright-json-schema-hyperschema-00
+
+
    +
  • "rel" is now optional
  • +
  • rel="self" no longer changes URI base
  • +
  • Added "base" keyword to change instance URI base
  • +
  • Removed "root" link relation
  • +
  • Removed "create" link relation
  • +
  • Removed "full" link relation
  • +
  • Removed "instances" link relation
  • +
  • Removed special behavior for "describedBy" link relation
  • +
  • Removed "pathStart" keyword
  • +
  • Removed "fragmentResolution" keyword
  • +
  • Updated references to JSON Pointer, HTML
  • +
  • Changed behavior of "method" property to align with hypermedia best current practices
  • +
+

+
+
draft-luff-json-hyper-schema-01
+
+
    +
  • Split from main specification.
  • +
+

+
+
+ +

+

+ Authors' Addresses +

+
+
+ + Henry Andrews (editor) + + + Cloudflare, Inc. + + + + + + + + + + EMail: henry@cloudflare.com + +
+
+
+ + Austin Wright (editor) + + + + + + + + + + + + + EMail: aaa@bzfx.net + +
+
+ + + diff --git a/work-in-progress/WIP-jsonschema-validation.html b/work-in-progress/WIP-jsonschema-validation.html new file mode 100644 index 00000000..205e68f9 --- /dev/null +++ b/work-in-progress/WIP-jsonschema-validation.html @@ -0,0 +1,1274 @@ + + + + + + + JSON Schema Validation: A Vocabulary for Structural Validation of JSON + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Internet Engineering Task ForceH. Andrews, Ed.
Internet-DraftCloudflare, Inc.
Intended status: InformationalA. Wright, Ed.
Expires: April 23, 2018
G. Luff
October 20, 2017
+ +

JSON Schema Validation: A Vocabulary for Structural Validation of JSON
+ draft-handrews-json-schema-validation-00

+ +

+ Abstract +

+

JSON Schema (application/schema+json) has several purposes, one of which is JSON instance validation. This document specifies a vocabulary for JSON Schema to describe the meaning of JSON documents, provide hints for user interfaces working with JSON data, and to make assertions about what a valid document must look like.

+

+ Note to Readers +

+

The issues list for this draft can be found at <https://github.com/json-schema-org/json-schema-spec/issues>.

+

For additional information, see <http://json-schema.org/>.

+

To provide feedback, use this issue tracker, the communication methods listed on the homepage, or email the document editors.

+

+ Status of This Memo +

+

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

+

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.

+

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

+

This Internet-Draft will expire on April 23, 2018.

+

+ Copyright Notice +

+

Copyright (c) 2017 IETF Trust and the persons identified as the document authors. All rights reserved.

+

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.

+ + +
+

Table of Contents

+ + +

1. Introduction

+

JSON Schema can be used to require that a given JSON document (an instance) satisfies a certain number of criteria. These criteria are asserted by using keywords described in this specification. In addition, a set of keywords is also defined to assist in interactive user interface instance generation.

+

This specification will use the concepts, syntax, and terminology defined by the JSON Schema core [json-schema] specification.

+

2. Conventions and Terminology

+

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].

+

This specification uses the term "container instance" to refer to both array and object instances. It uses the term "children instances" to refer to array elements or object member values.

+

Elements in an array value are said to be unique if no two elements of this array are equal [json-schema].

+

3. Overview

+

JSON Schema validation applies schemas to locations within the instance, and asserts constraints on the structure of the data at each location. An instance location that satisfies all asserted constraints is then annotated with any keywords that contain non-assertion information, such as desciptive metadata and usage hints. If all locations within the instance satisfy all asserted constraints, then the instance is said to be valid against the schema.

+

Each schema object is independently evaluated against each instance location to which it applies. This greatly simplifies the implementation requirements for validators by ensuring that they do not need to maintain state across the document-wide validation process.

+

3.1. Applicability

+

Validation begins by applying the root schema to the complete instance document. From there, various keywords are used to determine which additional subschemas are applied to either the current location, or a child location. These keywords also define whether and how subschema assertion results are modified and/or combined. Such keywords do not assert conditions on their own. Rather, they control how assertions are applied and evaluated.

+

The keywords in the boolean logic [logic] and conditional [conditional] sections of this specification apply subschemas to the same location as the parent schema. The former group defines boolean operations on the subschema assertion results, while the latter evaluates one subschema and uses its assertion results to determine which of two other subschemas to apply as well.

+

Several keywords determine which subschemas are applied to array items, object property values, and object property names. They are: "items", "additionalItems", "contains", "properties", "patternProperties", "additionalProperties", and "propertyNames". The "contains" keyword only requires its subschema to be valid against at least one child instance, while the other keywords require that all subschemas are valid against all child instances to which they apply.

+

3.1.1. Keyword independence

+

Validation keywords typically operate independently, without affecting each other's outcomes.

+

For schema author convenience, there are some exceptions among the keywords that control subschema applicability:

+ + + +

+

3.2. Assertions

+

Validation is a process of checking assertions. Each assertion adds constraints that an instance must satisfy in order to successfully validate.

+

Assertion keywords that are absent never restrict validation. In some cases, this no-op behavior is identical to a keyword that exists with certain values, and these values are noted where known.

+

All of the keywords in the general [general], numeric [numeric], and string [string] sections are assertions, as well as "minItems", "maxItems", "uniqueItems", "minProperties", "maxProperties", and "required". Additionally, "dependencies" is shorthand for a combination of conditional and assertion keywords.

+

The "format", "contentType", and "contentEncoding" keywords can also be implemented as assertions, although that functionality is an optional part of this specification, and the keywords convey additional non-assertion information.

+

3.2.1. Assertions and instance primitive types

+

Most validation assertions only constrain values within a certain primitive type. When the type of the instance is not of the type targeted by the keyword, the instance is considered to conform to the assertion.

+

For example, the "maxLength" keyword will only restrict certain strings (that are too long) from being valid. If the instance is a number, boolean, null, array, or object, then it is valid against this assertion.

+

3.3. Annotations

+

In addition to assertions, this specification provides a small vocabulary of metadata keywords that can be used to annotate the JSON instance with useful information. The Section 7 and Section 8 keywords are also useful as annotations as well as being optional assertions, as they convey additional usage guidance for the instance data.

+

A schema that is applicable to a particular location in the instance, against which the instance location is valid, attaches its annotations to that location in the instance. Since many subschemas can be applicable to any single location, annotation keywords need to specify any unusual handling of multiple applicable occurrences of the keyword with different values. The default behavior is simply to collect all values.

+

Additional vocabularies SHOULD make use of this mechanism for applying their own annotations to instances.

+

3.3.1. Negated schemas

+

Annotations in a subschema contained within a "not", at any depth, including any number of intervening additional "not" subschemas, MUST be ignored. Similarly, annotations within a failing branch of a "oneOf", "anyOf", "then", or "else" MUST be ignored.

+

3.3.2. Annotations and short-circuit validation

+

Annotation keywords MUST be applied to all possible sub-instances. even if such application can be short-circuited when only assertion evaluation is needed. For instance, the "contains" keyword need only be checked for assertions until at least one array item proves valid. However, when working with annotations, all items in the array must be evaluated to determine all items with which the annotations should be associated.

+

4. Interoperability considerations

+

4.1. Validation of string instances

+

It should be noted that the nul character (\u0000) is valid in a JSON string. An instance to validate may contain a string value with this character, regardless of the ability of the underlying programming language to deal with such data.

+

4.2. Validation of numeric instances

+

The JSON specification allows numbers with arbitrary precision, and JSON Schema does not add any such bounds. This means that numeric instances processed by JSON Schema can be arbitrarily large and/or have an arbitrarily long decimal part, regardless of the ability of the underlying programming language to deal with such data.

+

4.3. Regular expressions

+

Two validation keywords, "pattern" and "patternProperties", use regular expressions to express constraints, and the "regex" value for the "format" keyword constrains the instance value to be a regular expression. These regular expressions SHOULD be valid according to the ECMA 262 [ecma262] regular expression dialect.

+

Furthermore, given the high disparity in regular expression constructs support, schema authors SHOULD limit themselves to the following regular expression tokens:

+ + + +

+

Finally, implementations MUST NOT take regular expressions to be anchored, neither at the beginning nor at the end. This means, for instance, the pattern "es" matches "expression".

+

5. Meta-schema

+

The current URI for the JSON Schema Validation is <http://json-schema.org/draft-06/schema#>.

+

6. Validation keywords

+

Validation keywords in a schema impose requirements for successful validation of an instance.

+

6.1. Validation keywords for any instance type

+

6.1.1. type

+

The value of this keyword MUST be either a string or an array. If it is an array, elements of the array MUST be strings and MUST be unique.

+

String values MUST be one of the six primitive types ("null", "boolean", "object", "array", "number", or "string"), or "integer" which matches any number with a zero fractional part.

+

An instance validates if and only if the instance is in any of the sets listed for this keyword.

+

6.1.2. enum

+

The value of this keyword MUST be an array. This array SHOULD have at least one element. Elements in the array SHOULD be unique.

+

An instance validates successfully against this keyword if its value is equal to one of the elements in this keyword's array value.

+

Elements in the array might be of any value, including null.

+

6.1.3. const

+

The value of this keyword MAY be of any type, including null.

+

An instance validates successfully against this keyword if its value is equal to the value of the keyword.

+

6.2. Validation keywords for numeric instances (number and integer)

+

6.2.1. multipleOf

+

The value of "multipleOf" MUST be a number, strictly greater than 0.

+

A numeric instance is valid only if division by this keyword's value results in an integer.

+

6.2.2. maximum

+

The value of "maximum" MUST be a number, representing an inclusive upper limit for a numeric instance.

+

If the instance is a number, then this keyword validates only if the instance is less than or exactly equal to "maximum".

+

6.2.3. exclusiveMaximum

+

The value of "exclusiveMaximum" MUST be number, representing an exclusive upper limit for a numeric instance.

+

If the instance is a number, then the instance is valid only if it has a value strictly less than (not equal to) "exclusiveMaximum".

+

6.2.4. minimum

+

The value of "minimum" MUST be a number, representing an inclusive lower limit for a numeric instance.

+

If the instance is a number, then this keyword validates only if the instance is greater than or exactly equal to "minimum".

+

6.2.5. exclusiveMinimum

+

The value of "exclusiveMinimum" MUST be number, representing an exclusive lower limit for a numeric instance.

+

If the instance is a number, then the instance is valid only if it has a value strictly greater than (not equal to) "exclusiveMinimum".

+

6.3. Validation keywords for strings

+

6.3.1. maxLength

+

The value of this keyword MUST be a non-negative integer.

+

A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword.

+

The length of a string instance is defined as the number of its characters as defined by RFC 7159 [RFC7159].

+

6.3.2. minLength

+

The value of this keyword MUST be a non-negative integer.

+

A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.

+

The length of a string instance is defined as the number of its characters as defined by RFC 7159 [RFC7159].

+

Omitting this keyword has the same behavior as a value of 0.

+

6.3.3. pattern

+

The value of this keyword MUST be a string. This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect.

+

A string instance is considered valid if the regular expression matches the instance successfully. Recall: regular expressions are not implicitly anchored.

+

6.4. Validation keywords for arrays

+

6.4.1. items

+

The value of "items" MUST be either a valid JSON Schema or an array of valid JSON Schemas.

+

This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself.

+

If "items" is a schema, validation succeeds if all elements in the array successfully validate against that schema.

+

If "items" is an array of schemas, validation succeeds if each element of the instance validates against the schema at the same position, if any.

+

Omitting this keyword has the same behavior as an empty schema.

+

6.4.2. additionalItems

+

The value of "additionalItems" MUST be a valid JSON Schema.

+

This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself.

+

If "items" is an array of schemas, validation succeeds if every instance element at a position greater than the size of "items" validates against "additionalItems".

+

Otherwise, "additionalItems" MUST be ignored, as the "items" schema (possibly the default value of an empty schema) is applied to all elements.

+

Omitting this keyword has the same behavior as an empty schema.

+

6.4.3. maxItems

+

The value of this keyword MUST be a non-negative integer.

+

An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword.

+

6.4.4. minItems

+

The value of this keyword MUST be a non-negative integer.

+

An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword.

+

Omitting this keyword has the same behavior as a value of 0.

+

6.4.5. uniqueItems

+

The value of this keyword MUST be a boolean.

+

If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique.

+

Omitting this keyword has the same behavior as a value of false.

+

6.4.6. contains

+

The value of this keyword MUST be a valid JSON Schema.

+

An array instance is valid against "contains" if at least one of its elements is valid against the given schema.

+

6.5. Validation keywords for objects

+

6.5.1. maxProperties

+

The value of this keyword MUST be a non-negative integer.

+

An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.

+

6.5.2. minProperties

+

The value of this keyword MUST be a non-negative integer.

+

An object instance is valid against "minProperties" if its number of properties is greater than, or equal to, the value of this keyword.

+

Omitting this keyword has the same behavior as a value of 0.

+

6.5.3. required

+

The value of this keyword MUST be an array. Elements of this array, if any, MUST be strings, and MUST be unique.

+

An object instance is valid against this keyword if every item in the array is the name of a property in the instance.

+

Omitting this keyword has the same behavior as an empty array.

+

6.5.4. properties

+

The value of "properties" MUST be an object. Each value of this object MUST be a valid JSON Schema.

+

This keyword determines how child instances validate for objects, and does not directly validate the immediate instance itself.

+

Validation succeeds if, for each name that appears in both the instance and as a name within this keyword's value, the child instance for that name successfully validates against the corresponding schema.

+

Omitting this keyword has the same behavior as an empty object.

+

6.5.5. patternProperties

+

The value of "patternProperties" MUST be an object. Each property name of this object SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect. Each property value of this object MUST be a valid JSON Schema.

+

This keyword determines how child instances validate for objects, and does not directly validate the immediate instance itself. Validation of the primitive instance type against this keyword always succeeds.

+

Validation succeeds if, for each instance name that matches any regular expressions that appear as a property name in this keyword's value, the child instance for that name successfully validates against each schema that corresponds to a matching regular expression.

+

Omitting this keyword has the same behavior as an empty object.

+

6.5.6. additionalProperties

+

The value of "additionalProperties" MUST be a valid JSON Schema.

+

This keyword determines how child instances validate for objects, and does not directly validate the immediate instance itself.

+

Validation with "additionalProperties" applies only to the child values of instance names that do not match any names in "properties", and do not match any regular expression in "patternProperties".

+

For all such properties, validation succeeds if the child instance validates against the "additionalProperties" schema.

+

Omitting this keyword has the same behavior as an empty schema.

+

6.5.7. dependencies

+

[CREF1]Now that "if", "then", and "else" are keywords, it is not clear whether there is any benefit in keeping the schema form of "dependencies". It is frequently misunderstood, and having a form that takes a subschema as well as a form that takes a primitive value is particularly confusing. And it seems to be rarely used. Depending on feedback with "if", "then", and "else", the schema form of this keyword may well be removed in a future draft. Current thought is that the string form (giving property names in an array) is a useful shortcut.

+

This keyword specifies rules that are evaluated if the instance is an object and contains a certain property.

+

This keyword's value MUST be an object. Each property specifies a dependency. Each dependency value MUST be an array or a valid JSON Schema.

+

If the dependency value is a subschema, and the dependency key is a property in the instance, the entire instance must validate against the dependency value.

+

If the dependency value is an array, each element in the array, if any, MUST be a string, and MUST be unique. If the dependency key is a property in the instance, each of the items in the dependency value must be a property that exists in the instance.

+

Omitting this keyword has the same behavior as an empty object.

+

6.5.8. propertyNames

+

The value of "propertyNames" MUST be a valid JSON Schema.

+

If the instance is an object, this keyword validates if every property name in the instance validates against the provided schema. Note the property name that the schema is testing will always be a string.

+

Omitting this keyword has the same behavior as an empty schema.

+

6.6. Keywords for applying subschemas conditionally

+

These keywords work together to implement conditional application of a subschema based on the outcome of another subschema.

+

These keywords MUST NOT interact with each other across subschema boundaries. In other words, an "if" in one branch of an "allOf" MUST NOT have an impact on a "then" or "else" in another branch.

+

6.6.1. if

+

This keyword's value MUST be a valid JSON Schema.

+

Instances that successfully validate against this keyword's subschema MUST also be valid against the subschema value of the "then" keyword, if present.

+

Instances that fail to validate against this keyword's subschema MUST also be valid against the subschema value of the "else" keyword.

+

Validation of the instance against this keyword on its own always succeeds, regardless of the validation outcome of against its subschema.

+

6.6.2. then

+

This keyword's value MUST be a valid JSON Schema.

+

When present alongside of "if", the instance successfully validates against this keyword if it validates against both the "if"'s subschema and this keyword's subschema.

+

When "if" is absent, or the instance fails to validate against its subschema, validation against this keyword always succeeds. Implementations SHOULD avoid attempting to validate against the subschema in these cases.

+

6.6.3. else

+

This keyword's value MUST be a valid JSON Schema.

+

When present alongside of "if", the instance successfully validates against this keyword if it fails to validate against the "if"'s subschema, and successfully validates against this keyword's subschema.

+

When "if" is absent, or the instance successfully validates against its subschema, validation against this keyword always succeeds. Implementations SHOULD avoid attempting to validate against the subschema in these cases.

+

6.7. Keywords for applying subschemas with boolean logic

+

6.7.1. allOf

+

This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.

+

An instance validates successfully against this keyword if it validates successfully against all schemas defined by this keyword's value.

+

6.7.2. anyOf

+

This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.

+

An instance validates successfully against this keyword if it validates successfully against at least one schema defined by this keyword's value.

+

6.7.3. oneOf

+

This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.

+

An instance validates successfully against this keyword if it validates successfully against exactly one schema defined by this keyword's value.

+

6.7.4. not

+

This keyword's value MUST be a valid JSON Schema.

+

An instance is valid against this keyword if it fails to validate successfully against the schema defined by this keyword.

+

7. Semantic validation with "format"

+

7.1. Foreword

+

Structural validation alone may be insufficient to validate that an instance meets all the requirements of an application. The "format" keyword is defined to allow interoperable semantic validation for a fixed subset of values which are accurately described by authoritative resources, be they RFCs or other external specifications.

+

The value of this keyword is called a format attribute. It MUST be a string. A format attribute can generally only validate a given set of instance types. If the type of the instance to validate is not in this set, validation for this format attribute and instance SHOULD succeed.

+

7.2. Implementation requirements

+

The "format" keyword functions as both an annotation (Section 3.3) and as an assertion (Section 3.2). While no special effort is required to implement it as an annotation convenying semantic meaning, implementing validation is non-trivial.

+

Implementations MAY support the "format" keyword as a validation assertion. Should they choose to do so:

+ + + +

+

Implementations MAY add custom format attributes. Save for agreement between parties, schema authors SHALL NOT expect a peer implementation to support this keyword and/or custom format attributes.

+

7.3. Defined formats

+

7.3.1. Dates and times

+

These attributes apply to string instances.

+

Date and time format names are derived from RFC 3339, section 5.6 [RFC3339].

+

Implementations supporting formats SHOULD implement support for the following attributes:

+ +
+
date-time
+
A string instance is valid against this attribute if it is a valid representation according to the "date-time" production.
+
date
+
A string instance is valid against this attribute if it is a valid representation according to the "full-date" production.
+
time
+
A string instance is valid against this attribute if it is a valid representation according to the "full-time" production.
+
+ +

+

Implementations MAY support additional attributes using the other production names defined in that section. If "full-date" or "full-time" are implemented, the corresponding short form ("date" or "time" respectively) MUST be implemented, and MUST behave identically. Implementations SHOULD NOT define extension attributes with any name matching an RFC 3339 production unless it validates according to the rules of that production. [CREF2]There is not currently consensus on the need for supporting all RFC 3339 formats, so this approach of reserving the namespace will encourage experimentation without committing to the entire set. Either the format implementation requirements will become more flexible in general, or these will likely either be promoted to fully specified attributes or dropped.

+

7.3.2. Email addresses

+

These attributes apply to string instances.

+

A string instance is valid against these attributes if it is a valid Internet email address as follows:

+ +
+
email
+
As defined by RFC 5322, section 3.4.1 [RFC5322].
+
idn-email
+
As defined by RFC 6531 [RFC6531]
+
+ +

Note that all strings valid against the "email" attribute are also valid against the "idn-email" attribute.

+

7.3.3. Hostnames

+

These attributes apply to string instances.

+

A string instance is valid against these attributes if it is a valid representation for an Internet hostname as follows:

+ +
+
hostname
+
As defined by RFC 1034, section 3.1 [RFC1034], including host names produced using the Punycode algorithm specified in RFC 5891, section 4.4 [RFC5891].
+
idn-hostname
+
As defined by either RFC 1034 as for hostname, or an internationalized hostname as defined by RFC 5890, section 2.3.2.3 [RFC5890].
+
+ +

Note that all strings valid against the "hostname" attribute are also valid against the "idn-hostname" attribute.

+

7.3.4. IP addresses

+

These attributes apply to string instances.

+

A string instance is valid against these attributes if it is a valid representation of an IP address as follows:

+ +
+
ipv4
+
An IPv4 address according to the "dotted-quad" ABNF syntax as defined in RFC 2673, section 3.2 [RFC2673].
+
ipv6
+
An IPv6 address as defined in RFC 4291, section 2.2 [RFC4291].
+
+ +

+

7.3.5. Resource identifiers

+

These attributes apply to string instances.

+

+ +

+
uri
+
A string instance is valid against this attribute if it is a valid URI, according to [RFC3986].
+
uri-reference
+
A string instance is valid against this attribute if it is a valid URI Reference (either a URI or a relative-reference), according to [RFC3986].
+
iri
+
A string instance is valid against this attribute if it is a valid IRI, according to [RFC3987].
+
iri-reference
+
A string instance is valid against this attribute if it is a valid IRI Reference (either an IRI or a relative-reference), according to [RFC3987].
+
+ +

Note that all valid URIs are valid IRIs, and all valid URI References are also valid IRI References.

+

7.3.6. uri-template

+

This attribute applies to string instances.

+

A string instance is valid against this attribute if it is a valid URI Template (of any level), according to [RFC6570].

+

Note that URI Templates may be used for IRIs; there is no separate IRI Template specification.

+

7.3.7. JSON Pointers

+

These attributes apply to string instances.

+

+ +

+
json-pointer
+
A string instance is valid against this attribute if it is a valid JSON string representation of a JSON Pointer, according to RFC 6901, section 5 [RFC6901].
+
relative-json-pointer
+
A string instance is valid against this attribute if it is a valid Relative JSON Pointer [I-D.luff-relative-json-pointer].
+
+ +

To allow for both absolute and relative JSON Pointers, use "anyOf" or "oneOf" to indicate support for either format.

+

7.3.8. regex

+

This attribute applies to string instances.

+

A regular expression, which SHOULD be valid according to the ECMA 262 [ecma262] regular expression dialect.

+

Implementations that validate formats MUST accept at least the subset of ECMA 262 defined in the Regular Expressions [regexInterop] section of this specification, and SHOULD accept all valid ECMA 262 expressions.

+

8. String-encoding non-JSON data

+

8.1. Foreword

+

Properties defined in this section indicate that an instance contains non-JSON data encoded in a JSON string. They describe the type of content and how it is encoded.

+

These properties provide additional information required to interpret JSON data as rich multimedia documents.

+

8.2. Implementation requirements

+

The content keywords function as both annotations (Section 3.3) and as assertions (Section 3.2). While no special effort is required to implement them as annotations convenying how applications can interpret the data in the string, implementing validation of conformance to the media type and encoding is non-trivial.

+

Implementations MAY support the "contentMediaType" and "contentEncoding" keywords as validation assertions. Should they choose to do so, they SHOULD offer an option to disable validation for these keywords.

+

8.3. contentEncoding

+

If the instance value is a string, this property defines that the string SHOULD be interpreted as binary data and decoded using the encoding named by this property. RFC 2045, Sec 6.1 [RFC2045] lists the possible values for this property.

+

The value of this property MUST be a string.

+

The value of this property SHOULD be ignored if the instance described is not a string.

+

8.4. contentMediaType

+

The value of this property must be a media type, as defined by RFC 2046 [RFC2046]. This property defines the media type of instances which this schema defines.

+

The value of this property MUST be a string.

+

The value of this property SHOULD be ignored if the instance described is not a string.

+

If the "contentEncoding" property is not present, but the instance value is a string, then the value of this property SHOULD specify a text document type, and the character set SHOULD be the character set into which the JSON string value was decoded (for which the default is Unicode).

+

8.5. Example

+

Here is an example schema, illustrating the use of "contentEncoding" and "contentMediaType":

+
+
+{
+    "type": "string",
+    "contentEncoding": "base64",
+    "contentMediaType": "image/png"
+}
+
+                    
+

Instances described by this schema should be strings, and their values should be interpretable as base64-encoded PNG images.

+

Another example:

+
+
+{
+    "type": "string",
+    "contentMediaType": "text/html"
+}
+
+                    
+

Instances described by this schema should be strings containing HTML, using whatever character set the JSON string was decoded into (default is Unicode).

+

9. Schema re-use with "definitions"

+

The "definitions" keywords provides a standardized location for schema authors to inline re-usable JSON Schemas into a more general schema. The keyword does not directly affect the validation result.

+

This keyword's value MUST be an object. Each member value of this object MUST be a valid JSON Schema.

+
+
+{
+    "type": "array",
+    "items": { "$ref": "#/definitions/positiveInteger" },
+    "definitions": {
+        "positiveInteger": {
+            "type": "integer",
+            "exclusiveMinimum": 0
+        }
+    }
+}
+
+                    
+

As an example, here is a schema describing an array of positive integers, where the positive integer constraint is a subschema in "definitions":

+

10. Schema annotations

+

Schema validation is a useful mechanism for annotating instance data with additional information. The rules for determining when and how annotations are associated with an instance are outlined in this specification's overview.

+

These general-purpose annotation keywords provide commonly used information for documentation and user interface display purposes. They are not intended to form a comprehensive set of features. Rather, additional vocabularies can be defined for more complex annotation-based applications.

+

10.1. "title" and "description"

+

The value of both of these keywords MUST be a string.

+

Both of these keywords can be used to decorate a user interface with information about the data produced by this user interface. A title will preferably be short, whereas a description will provide explanation about the purpose of the instance described by this schema.

+

10.2. "default"

+

There are no restrictions placed on the value of this keyword. When multiple occurrences of this keyword are applicable to a single sub-instance, implementations SHOULD remove duplicates.

+

This keyword can be used to supply a default JSON value associated with a particular schema. It is RECOMMENDED that a default value be valid against the associated schema.

+

10.3. "readOnly" and "writeOnly"

+

The value of these keywords MUST be a boolean. When multiple occurrences of these keywords are applicable to a single sub-instance, the resulting value MUST be true if any occurrence specifies a true value, and MUST be false otherwise.

+

If "readOnly" has a value of boolean true, it indicates that the value of the instance is managed exclusively by the owning authority, and attempts by an application to modify the value of this property are expected to be ignored or rejected by that owning authority.

+

An instance document that is marked as "readOnly for the entire document MAY be ignored if sent to the owning authority, or MAY result in an error, at the authority's discretion.

+

If "writeOnly" has a value of boolean true, it indicates that the value is never present when the instance is retrieved from the owning authority. It can be present when sent to the owning authority to update or create the document (or the resource it represents), but it will not be included in any updated or newly created version of the instance.

+

An instance document that is marked as "writeOnly" for the entire document MAY be returned as a blank document of some sort, or MAY produce an error upon retrieval, or have the retrieval request ignored, at the authority's discretion.

+

For example, "readOnly" would be used to mark a database-generated serial number as read-only, while "writeOnly" would be used to mark a password input field.

+

These keywords can be used to assist in user interface instance generation. In particular, an application MAY choose to use a widget that hides input values as they are typed for write-only fields.

+

Omitting these keywords has the same behavior as values of false.

+

10.4. "examples"

+

The value of this keyword MUST be an array. There are no restrictions placed on the values within the array. When multiple occurrences of this keyword are applicable to a single sub-instance, implementations MUST provide a flat array of all values rather than an array of arrays.

+

This keyword can be used to provide sample JSON values associated with a particular schema, for the purpose of illustrating usage. It is RECOMMENDED that these values be valid against the associated schema.

+

Implementations MAY use the value(s) of "default", if present, as an additional example. If "examples" is absent, "default" MAY still be used in this manner.

+

11. Security considerations

+

JSON Schema validation defines a vocabulary for JSON Schema core and concerns all the security considerations listed there.

+

JSON Schema validation allows the use of Regular Expressions, which have numerous different (often incompatible) implementations. Some implementations allow the embedding of arbitrary code, which is outside the scope of JSON Schema and MUST NOT be permitted. Regular expressions can often also be crafted to be extremely expensive to compute (with so-called "catastrophic backtracking"), resulting in a denial-of-service attack.

+

12. References

+

12.1. Normative References

+ + + + + + + , " + +
+ [RFC2119] + Bradner, S., Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997.
[json-schema]JSON Schema: A Media Type for Describing JSON Documents", Internet-Draft draft-wright-json-schema-00, October 2016.
+

12.2. Informative References

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + , " + +
+ [RFC1034] + Mockapetris, P., "Domain names - concepts and facilities", STD 13, RFC 1034, DOI 10.17487/RFC1034, November 1987.
+ [RFC2045] + Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies", RFC 2045, DOI 10.17487/RFC2045, November 1996.
+ [RFC2046] + Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types", RFC 2046, DOI 10.17487/RFC2046, November 1996.
+ [RFC2673] + Crawford, M., "Binary Labels in the Domain Name System", RFC 2673, DOI 10.17487/RFC2673, August 1999.
+ [RFC3339] + Klyne, G. and C. Newman, "Date and Time on the Internet: Timestamps", RFC 3339, DOI 10.17487/RFC3339, July 2002.
+ [RFC3986] + Berners-Lee, T., Fielding, R. and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, DOI 10.17487/RFC3986, January 2005.
+ [RFC3987] + Duerst, M. and M. Suignard, "Internationalized Resource Identifiers (IRIs)", RFC 3987, DOI 10.17487/RFC3987, January 2005.
+ [RFC4291] + Hinden, R. and S. Deering, "IP Version 6 Addressing Architecture", RFC 4291, DOI 10.17487/RFC4291, February 2006.
+ [RFC5890] + Klensin, J., "Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework", RFC 5890, DOI 10.17487/RFC5890, August 2010.
+ [RFC5891] + Klensin, J., "Internationalized Domain Names in Applications (IDNA): Protocol", RFC 5891, DOI 10.17487/RFC5891, August 2010.
+ [RFC6570] + Gregorio, J., Fielding, R., Hadley, M., Nottingham, M. and D. Orchard, "URI Template", RFC 6570, DOI 10.17487/RFC6570, March 2012.
+ [RFC6531] + Yao, J. and W. Mao, "SMTP Extension for Internationalized Email", RFC 6531, DOI 10.17487/RFC6531, February 2012.
+ [RFC6901] + Bryan, P., Zyp, K. and M. Nottingham, "JavaScript Object Notation (JSON) Pointer", RFC 6901, DOI 10.17487/RFC6901, April 2013.
+ [RFC7159] + Bray, T., "The JavaScript Object Notation (JSON) Data Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March 2014.
+ [RFC5322] + Resnick, P., "Internet Message Format", RFC 5322, DOI 10.17487/RFC5322, October 2008.
+ [I-D.luff-relative-json-pointer] + Luff, G., Relative JSON Pointers", Internet-Draft draft-luff-relative-json-pointer-00, July 2013.
[ecma262]ECMA 262 specification"
+

Appendix A. Acknowledgments

+

Thanks to Gary Court, Francis Galiegue, Kris Zyp, and Geraint Luff for their work on the initial drafts of JSON Schema.

+

Thanks to Jason Desrosiers, Daniel Perrett, Erik Wilde, Ben Hutton, Evgeny Poberezkin, Brad Bowman, Gowry Sankar, Donald Pipowitch, and Dave Finlay for their submissions and patches to the document.

+

Appendix B. ChangeLog

+

[CREF3]This section to be removed before leaving Internet-Draft status.

+

+ +

+
draft-handrews-json-schema-validation-00
+
+
    +
  • Added "if"/"then"/"else"
  • +
  • Warn of possibly removing "dependencies" in the future
  • +
  • Grouped validation keywords into sub-sections for readability
  • +
  • Moved "readOnly" from hyper-schema to validation meta-data
  • +
  • Added "writeOnly"
  • +
  • Added string-encoded media section, with former hyper-schema "media" keywords
  • +
  • Restored "regex" format (removal was unintentional)
  • +
  • Added "date" and "time" formats, and reserved additional RFC 3339 format names
  • +
  • I18N formats: "iri", "iri-reference", "idn-hostname", "idn-email"
  • +
  • Clarify that "json-pointer" format means string encoding, not URI fragment
  • +
  • Fixed typo that inverted the meaning of "minimum" and "exclusiveMinimum"
  • +
+

+
+
draft-wright-json-schema-validation-01
+
+
    +
  • Standardized on hyphenated format names ("uriref" becomes "uri-ref")
  • +
  • Add the formats "uri-template" and "json-pointer"
  • +
  • Changed "exclusiveMaximum"/"exclusiveMinimum" from boolean modifiers of "maximum"/"minimum" to independent numeric fields.
  • +
  • Split the additionalItems/items into two sections
  • +
  • Reworked properties/patternProperties/additionalProperties definition
  • +
  • Added "examples" keyword
  • +
  • Added "contains" keyword
  • +
  • Allow empty "required" and "dependencies" arrays
  • +
  • Fixed "type" reference to primitive types
  • +
  • Added "const" keyword
  • +
  • Added "propertyNames" keyword
  • +
+

+
+
draft-wright-json-schema-validation-00
+
+
    +
  • Added additional security considerations
  • +
  • Removed reference to "latest version" meta-schema, use numbered version instead
  • +
  • Rephrased many keyword definitions for brevity
  • +
  • Added "uriref" format that also allows relative URI references
  • +
+

+
+
draft-fge-json-schema-validation-01
+
+
    +
  • Initial draft.
  • +
  • Salvaged from draft v3.
  • +
  • Redefine the "required" keyword.
  • +
  • Remove "extends", "disallow"
  • +
  • Add "anyOf", "allOf", "oneOf", "not", "definitions", "minProperties", "maxProperties".
  • +
  • "dependencies" member values can no longer be single strings; at least one element is required in a property dependency array.
  • +
  • Rename "divisibleBy" to "multipleOf".
  • +
  • "type" arrays can no longer have schemas; remove "any" as a possible value.
  • +
  • Rework the "format" section; make support optional.
  • +
  • "format": remove attributes "phone", "style", "color"; rename "ip-address" to "ipv4"; add references for all attributes.
  • +
  • Provide algorithms to calculate schema(s) for array/object instances.
  • +
  • Add interoperability considerations.
  • +
+

+
+
+ +

+

+ Authors' Addresses +

+
+
+ + Henry Andrews (editor) + + + Cloudflare, Inc. + + + + + + + + + + EMail: henry@cloudflare.com + +
+
+
+ + Austin Wright (editor) + + + + + + + + + + + + + EMail: aaa@bzfx.net + +
+
+
+ + Geraint Luff + + + + + + + + + + + + + EMail: luffgd@gmail.com + +
+
+ + + diff --git a/work-in-progress/WIP-links.json b/work-in-progress/WIP-links.json new file mode 100644 index 00000000..1712ef11 --- /dev/null +++ b/work-in-progress/WIP-links.json @@ -0,0 +1,85 @@ +{ + "$schema": "http://json-schema.org/draft-07-wip/hyper-schema#", + "$id": "http://json-schema.org/draft-07-wip/links#", + "title": "Link Description Object", + "allOf": [ + { "required": [ "rel", "href" ] }, + { "$ref": "#/definitions/noRequiredFields" } + ], + "definitions": { + "noRequiredFields": { + "type": "object", + "properties": { + "anchor": { + "type": "string", + "format": "uri-template" + }, + "anchorPointer": { + "type": "string", + "anyOf": [ + { "format": "json-pointer" }, + { "format": "relative-json-pointer" } + ] + }, + "rel": { + "type": "string" + }, + "href": { + "type": "string", + "format": "uri-template" + }, + "hrefSchema": { + "allOf": [ + { "$ref": "http://json-schema.org/draft-07-wip/hyper-schema#" } + ] + }, + "templatePointers": { + "type": "object", + "additionalProperties": { + "type": "string", + "anyOf": [ + { "format": "json-pointer" }, + { "format": "relative-json-pointer" } + ] + } + }, + "templateRequired": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "targetSchema": { + "$ref": "http://json-schema.org/draft-07-wip/hyper-schema#" + }, + "targetMediaType": { + "type": "string" + }, + "targetHints": { }, + "hrefSchema": { + "$ref": "http://json-schema.org/draft-07-wip/hyper-schema#" + }, + "headerSchema": { + "$ref": "http://json-schema.org/draft-07-wip/hyper-schema#" + }, + "submissionMediaType": { + "type": "string", + "default": "application/json" + }, + "submissionSchema": { + "$ref": "http://json-schema.org/draft-07-wip/hyper-schema#" + }, + "$comment": { + "type": "string" + } + } + } + } +} diff --git a/work-in-progress/WIP-relative-json-pointer.html b/work-in-progress/WIP-relative-json-pointer.html new file mode 100644 index 00000000..d71e281f --- /dev/null +++ b/work-in-progress/WIP-relative-json-pointer.html @@ -0,0 +1,669 @@ + + + + + + + Relative JSON Pointers + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Internet Engineering Task ForceG. Luff
Internet-Draft
Intended status: InformationalH. Andrews, Ed.
Expires: April 23, 2018Cloudflare, Inc.
October 20, 2017
+ +

Relative JSON Pointers
+ draft-handrews-relative-json-pointer-00

+ +

+ Abstract +

+

JSON Pointer is a syntax for specifying locations in a JSON document, starting from the document root. This document defines an extension to the JSON Pointer syntax, allowing relative locations from within the document.

+

+ Status of This Memo +

+

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

+

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.

+

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

+

This Internet-Draft will expire on April 23, 2018.

+

+ Copyright Notice +

+

Copyright (c) 2017 IETF Trust and the persons identified as the document authors. All rights reserved.

+

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.

+ + +
+

Table of Contents

+ + +

1. Introduction

+

JSON Pointer (RFC 6901 [RFC6901]) is a syntax for specifying locations in a JSON document, starting from the document root. This document defines a related syntax allowing identification of relative locations from within the document.

+

2. Conventions and Terminology

+

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].

+

3. Syntax

+

A Relative JSON Pointer is a Unicode string (see RFC 4627, Section 3 [RFC4627]), comprising a positive integer, followed by either a '#' (%x23) character or a JSON Pointer (RFC 6901 [RFC6901]).

+

The separation between the integer prefix and the JSON Pointer will always be unambiguous, because a JSON Pointer must be either zero- length or start with a '/' (%x2F). Similarly, a JSON Pointer will never be ambiguous with the '#'.

+

The ABNF syntax of a Relative JSON Pointer is:

+
+
+      relative-json-pointer =  positive-integer &lt;json-pointer&gt;
+      relative-json-pointer =/ positive-integer "#"
+      positive-integer      =  %x30 / %x31-39 *( %x30-39 )
+              ; "0", or digits without a leading "0"
+
+                
+

where <json-pointer> follows the production defined in RFC 6901, Section 3 [RFC6901] ("Syntax").

+

+

4. Evaluation

+

Evaluation of a Relative JSON Pointer begins with a reference to a value within a JSON document, and completes with either a value within that document, a string corresponding to an object member, or integer value representing an array index.

+

Evaluation begins by processing the positive-integer prefix. This can be found by taking the longest continuous sequence of decimal digits available, starting from the beginning of the string, taking the decimal numerical value. If this value is more than zero, then the following steps are repeated that number of times: RFC 6901, Section 4 [RFC6901] ("Evaluation"), with the modification that the initial reference being used is the reference currently being held (which may not be root of the document).

+ + + +

If the remainder of the Relative JSON Pointer is a JSON Pointer, then evaluation proceeds as per

+

Otherwise (when the remainder of the Relative JSON Pointer is the character '#'), the final result is determined as follows:

+ + + +

+

5. JSON String Representation

+

The concerns surrounding JSON String representation of a Relative JSON Pointer are identical to those laid out in RFC 6901, Section 5 [RFC6901].

+

5.1. Examples

+

For example, given the JSON document:

+
+
+                      {
+                         "foo": ["bar", "baz"],
+                         "highly": {
+                            "nested": {
+                               "objects": true
+                            }
+                         }
+                      }
+
+                    
+

Starting from the value "baz" (inside "foo"), the following JSON strings evaluate to the accompanying values:

+
+
+                  "0"                         "baz"
+                  "1/0"                       "bar"
+                  "2/highly/nested/objects"   true
+                  "0#"                        1
+                  "1#"                        "foo"
+
+                    
+

Starting from the value {"objects":true} (corresponding to the member key "nested"), the following JSON strings evaluate to the accompanying values:

+
+
+                "0/objects"                 true
+                "1/nested/objects"          true
+                "2/foo/0"                   "bar"
+                "0#"                        "nested"
+                "1#"                        "highly"
+
+                    
+

6. Non-use in URI Fragment Identifiers

+

Unlike a JSON Pointer, a Relative JSON Pointer can not be used in a URI fragment identifier. Such fragments specify exact positions within a document, and therefore Relative JSON Pointers are not suitable.

+

7. Error Handling

+

In the event of an error condition, evaluation of the JSON Pointer fails to complete.

+

Evaluation may fail due to invalid syntax, or referencing a non- existent value. This specification does not define how errors are handled. An application of JSON Relative Pointer SHOULD specify the impact and handling of each type of error.

+

8. Relationship to JSON Pointer

+

Relative JSON Pointers are intended as a companion to JSON Pointers. Applications MUST specify the use of each syntax separately. Defining either JSON Pointer or Relative JSON Pointer as an acceptable syntax does not imply that the other syntax is also acceptable.

+

9. Acknowledgements

+

The language and structure of this specification are based heavily on [RFC6901], sometimes quoting it outright.

+

This draft remains primarily as written and published by Geraint Luff, with only minor subsequent alterations under new editorship.

+

10. Security Considerations

+

Evaluation of a given Relative JSON Pointer is not guaranteed to reference an actual JSON value. Applications using Relative JSON Pointer should anticipate this situation by defining how a pointer that does not resolve ought to be handled.

+

As part of processing, a composite data structure may be assembled from multiple JSON documents (in part or in full). In such cases, applications SHOULD ensure that a Relative JSON Pointer does not evaluate to a value outside the document for which is was written.

+

Note that JSON pointers can contain the NUL (Unicode U+0000) character. Care is needed not to misinterpret this character in programming languages that use NUL to mark the end of a string.

+

11. References

+

11.1. Normative References

+ + + + + + + + + + + +
+ [RFC2119] + Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997.
+ [RFC6901] + Bryan, P., Zyp, K. and M. Nottingham, "JavaScript Object Notation (JSON) Pointer", RFC 6901, DOI 10.17487/RFC6901, April 2013.
+

11.2. Informative References

+ + + + + + + +
+ [RFC4627] + Crockford, D., "The application/json Media Type for JavaScript Object Notation (JSON)", RFC 4627, DOI 10.17487/RFC4627, July 2006.
+

Appendix A. ChangeLog

+

[CREF1]This section to be removed before leaving Internet-Draft status.

+

+ +

+
draft-handrews-relative-json-pointer-00
+
+
    +
  • Revived draft with identical wording and structure.
  • +
  • Clarified how to use alongside JSON Pointer.
  • +
+

+
+
draft-luff-relative-json-pointer-00
+
+
    +
  • Initial draft.
  • +
+

+
+
+ +

+

+ Authors' Addresses +

+
+
+ + Geraint Luff + + + + + + + Cambridge, + + + + UK + + EMail: luffgd@gmail.com + +
+
+
+ + Henry Andrews (editor) + + + Cloudflare, Inc. + + + + + + + + + + EMail: henry@cloudflare.com + +
+
+ + + diff --git a/work-in-progress/WIP-schema.json b/work-in-progress/WIP-schema.json new file mode 100644 index 00000000..4d8330f4 --- /dev/null +++ b/work-in-progress/WIP-schema.json @@ -0,0 +1,167 @@ +{ + "$schema": "http://json-schema.org/draft-07-wip/schema#", + "$id": "http://json-schema.org/draft-07-wip/schema#", + "title": "Core schema meta-schema", + "definitions": { + "schemaArray": { + "type": "array", + "minItems": 1, + "items": { "$ref": "#" } + }, + "nonNegativeInteger": { + "type": "integer", + "minimum": 0 + }, + "nonNegativeIntegerDefault0": { + "allOf": [ + { "$ref": "#/definitions/nonNegativeInteger" }, + { "default": 0 } + ] + }, + "simpleTypes": { + "enum": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ] + }, + "stringArray": { + "type": "array", + "items": { "type": "string" }, + "uniqueItems": true, + "default": [] + } + }, + "type": ["object", "boolean"], + "properties": { + "$id": { + "type": "string", + "format": "uri-reference" + }, + "$schema": { + "type": "string", + "format": "uri" + }, + "$ref": { + "type": "string", + "format": "uri-reference" + }, + "$comment": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": {}, + "readOnly": { + "type": "boolean", + "default": false + }, + "examples": { + "type": "array", + "items": {} + }, + "multipleOf": { + "type": "number", + "exclusiveMinimum": 0 + }, + "maximum": { + "type": "number" + }, + "exclusiveMaximum": { + "type": "number" + }, + "minimum": { + "type": "number" + }, + "exclusiveMinimum": { + "type": "number" + }, + "maxLength": { "$ref": "#/definitions/nonNegativeInteger" }, + "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, + "pattern": { + "type": "string", + "format": "regex" + }, + "additionalItems": { "$ref": "#" }, + "items": { + "anyOf": [ + { "$ref": "#" }, + { "$ref": "#/definitions/schemaArray" } + ], + "default": {} + }, + "maxItems": { "$ref": "#/definitions/nonNegativeInteger" }, + "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, + "uniqueItems": { + "type": "boolean", + "default": false + }, + "contains": { "$ref": "#" }, + "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" }, + "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, + "required": { "$ref": "#/definitions/stringArray" }, + "additionalProperties": { "$ref": "#" }, + "definitions": { + "type": "object", + "additionalProperties": { "$ref": "#" }, + "default": {} + }, + "properties": { + "type": "object", + "additionalProperties": { "$ref": "#" }, + "default": {} + }, + "patternProperties": { + "type": "object", + "additionalProperties": { "$ref": "#" }, + "propertyNames": { "format": "regex" }, + "default": {} + }, + "dependencies": { + "type": "object", + "additionalProperties": { + "anyOf": [ + { "$ref": "#" }, + { "$ref": "#/definitions/stringArray" } + ] + } + }, + "propertyNames": { "$ref": "#" }, + "const": {}, + "enum": { + "type": "array", + "minItems": 1, + "uniqueItems": true + }, + "type": { + "anyOf": [ + { "$ref": "#/definitions/simpleTypes" }, + { + "type": "array", + "items": { "$ref": "#/definitions/simpleTypes" }, + "minItems": 1, + "uniqueItems": true + } + ] + }, + "format": { "type": "string" }, + "contentMediaType": { "type": "string" }, + "contentEncoding": { "type": "string" }, + "if": {"$ref": "#"}, + "then": {"$ref": "#"}, + "else": {"$ref": "#"}, + "allOf": { "$ref": "#/definitions/schemaArray" }, + "anyOf": { "$ref": "#/definitions/schemaArray" }, + "oneOf": { "$ref": "#/definitions/schemaArray" }, + "not": { "$ref": "#" } + }, + "default": {} +} From 253a99190a9daef7fc5c4c51637abc0017a2dd06 Mon Sep 17 00:00:00 2001 From: Henry Andrews Date: Fri, 20 Oct 2017 13:38:25 -0700 Subject: [PATCH 2/4] Note that these are for review feedback ONLY! Put big honking warnings in the title, and name the documents draft-WORK-IN-PROGRESS-json-schema[-*]-NN and similarly change the schema identifiers. These are obviously not real draft or meta-schema names. --- work-in-progress/WIP-hyper-schema-output.json | 4 ++-- work-in-progress/WIP-hyper-schema.json | 10 +++++----- work-in-progress/WIP-jsonschema-core.html | 10 +++++----- work-in-progress/WIP-jsonschema-hyperschema.html | 10 +++++----- work-in-progress/WIP-jsonschema-validation.html | 10 +++++----- work-in-progress/WIP-links.json | 14 +++++++------- work-in-progress/WIP-relative-json-pointer.html | 10 +++++----- work-in-progress/WIP-schema.json | 4 ++-- 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/work-in-progress/WIP-hyper-schema-output.json b/work-in-progress/WIP-hyper-schema-output.json index 46f52995..8b260cf4 100644 --- a/work-in-progress/WIP-hyper-schema-output.json +++ b/work-in-progress/WIP-hyper-schema-output.json @@ -1,6 +1,6 @@ { - "$id": "http://json-schema.org/draft-7-wip/hyper-schema-output", - "$schema": "http://json-schema.org/draft-07-wip/schema#", + "$id": "http://json-schema.org/WORK-IN-PROGRESS/hyper-schema-output", + "$schema": "http://json-schema.org/WORK-IN-PROGRESS/schema#", "type": "array", "items": { "allOf": [ diff --git a/work-in-progress/WIP-hyper-schema.json b/work-in-progress/WIP-hyper-schema.json index 68ca4fc7..0960f523 100644 --- a/work-in-progress/WIP-hyper-schema.json +++ b/work-in-progress/WIP-hyper-schema.json @@ -1,18 +1,18 @@ { - "$schema": "http://json-schema.org/draft-07-wip/hyper-schema#", - "$id": "http://json-schema.org/draft-07-wip/hyper-schema#", + "$schema": "http://json-schema.org/WORK-IN-PROGRESS/hyper-schema#", + "$id": "http://json-schema.org/WORK-IN-PROGRESS/hyper-schema#", "title": "JSON Hyper-Schema", "definitions": { "schemaArray": { "allOf": [ - { "$ref": "http://json-schema.org/draft-07-wip/schema#/definitions/schemaArray" }, + { "$ref": "http://json-schema.org/WORK-IN-PROGRESS/schema#/definitions/schemaArray" }, { "items": { "$ref": "#" } } ] } }, - "allOf": [ { "$ref": "http://json-schema.org/draft-07-wip/schema#" } ], + "allOf": [ { "$ref": "http://json-schema.org/WORK-IN-PROGRESS/schema#" } ], "properties": { "additionalItems": { "$ref": "#" }, "additionalProperties": { "$ref": "#"}, @@ -56,7 +56,7 @@ "links": { "type": "array", "items": { - "$ref": "http://json-schema.org/draft-07-wip/links#" + "$ref": "http://json-schema.org/WORK-IN-PROGRESS/links#" } } }, diff --git a/work-in-progress/WIP-jsonschema-core.html b/work-in-progress/WIP-jsonschema-core.html index 22f869ff..f38e90a5 100644 --- a/work-in-progress/WIP-jsonschema-core.html +++ b/work-in-progress/WIP-jsonschema-core.html @@ -5,7 +5,7 @@ - JSON Schema: A Media Type for Describing JSON Documents + FOR PRE-PUBLICATION REVIEW ONLY: JSON Schema: A Media Type for Describing JSON Documents