Skip to content

Instantly share code, notes, and snippets.

@kevinswiber
Last active May 25, 2019 20:28
Show Gist options
  • Save kevinswiber/14477759858a768d2809326ca4300d26 to your computer and use it in GitHub Desktop.
Save kevinswiber/14477759858a768d2809326ca4300d26 to your computer and use it in GitHub Desktop.
JSON Schema for Siren Hypermedia Format
{
"id": "http://sirenspec.org/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Entity",
"description": "An Entity is a URI-addressable resource that has properties and actions associated with it. It may contain sub-entities and navigational links.",
"type": "object",
"properties": {
"class": {
"description": "Describes the nature of an entity's content based on the current representation. Possible values are implementation-dependent and should be documented.",
"type": "array",
"items": {
"type": "string"
}
},
"title": {
"description": "Descriptive text about the entity.",
"type": "string"
},
"properties": {
"description": "A set of key-value pairs that describe the state of an entity.",
"type": "object"
},
"entities": {
"description": "A collection of related sub-entities. If a sub-entity contains an href value, it should be treated as an embedded link. Clients may choose to optimistically load embedded links. If no href value exists, the sub-entity is an embedded entity representation that contains all the characteristics of a typical entity. One difference is that a sub-entity MUST contain a rel attribute to describe its relationship to the parent entity.",
"type": "array",
"items": {
"$ref": "#/definitions/SubEntity"
}
},
"actions": {
"description": "A collection of actions; actions show available behaviors an entity exposes.",
"type": "array",
"items": {
"$ref": "#/definitions/Action"
}
},
"links": {
"description": "A collection of items that describe navigational links, distinct from entity relationships. Link items should contain a `rel` attribute to describe the relationship and an `href` attribute to point to the target URI. Entities should include a link `rel` to `self`.",
"type": "array",
"items": {
"$ref": "#/definitions/Link"
}
}
},
"definitions": {
"SubEntity": {
"anyOf": [
{ "$ref": "#/definitions/EmbeddedLinkSubEntity" },
{ "$ref": "#/definitions/EmbeddedRepresentationSubEntity" }
]
},
"EmbeddedLinkSubEntity": {
"type": "object",
"required": [ "rel", "href" ],
"properties": {
"class": {
"description": "Describes the nature of an entity's content based on the current representation. Possible values are implementation-dependent and should be documented.",
"type": "array",
"items": {
"type": "string"
}
},
"rel": {
"description": "Defines the relationship of the sub-entity to its parent, per Web Linking (RFC5899).",
"type": "array",
"items": {
"type": "string"
},
"minItems": 1
},
"href": {
"description": "The URI of the linked sub-entity.",
"type": "string",
"format": "uri"
},
"type": {
"description": "Defines media type of the linked sub-entity, per Web Linking (RFC5899).",
"type": "string"
},
"title": {
"description": "Descriptive text about the entity.",
"type": "string"
}
}
},
"EmbeddedRepresentationSubEntity": {
"allOf": [
{
"$ref": "#"
},
{
"required": [ "rel" ],
"properties": {
"rel": {
"description": "Defines the relationship of the sub-entity to its parent, per Web Linking (RFC5899).",
"type": "array",
"items": {
"type": "string"
},
"minItems": 1
}
}
}
]
},
"Action": {
"description": "Actions show available behaviors an entity exposes.",
"type": "object",
"required": [
"name",
"href"
],
"properties": {
"class": {
"description": "Describes the nature of an action based on the current representation. Possible values are implementation-dependent and should be documented.",
"type": "array",
"items": {
"type": "string"
}
},
"name": {
"description": "A string that identifies the action to be performed. Action names MUST be unique within the set of actions for an entity. The behaviour of clients when parsing a Siren document that violates this constraint is undefined.",
"type": "string"
},
"method": {
"description": "An enumerated attribute mapping to a protocol method. For HTTP, these values may be GET, PUT, POST, DELETE, or PATCH. As new methods are introduced, this list can be extended. If this attribute is omitted, GET should be assumed.",
"type": "string",
"default": "GET"
},
"href": {
"description": "The URI of the action.",
"type": "string",
"format": "uri"
},
"title": {
"description": "Descriptive text about the action.",
"type": "string"
},
"type": {
"description": "The encoding type for the request. When omitted and the fields attribute exists, the default value is `application/x-www-form-urlencoded`.",
"type": "string",
"default": "application/x-www-form-urlencoded"
},
"fields": {
"description": "A collection of fields.",
"type": "array",
"items": {
"$ref": "#/definitions/Field"
}
}
}
},
"Field": {
"description": "Fields represent controls inside of actions.",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"description": "A name describing the control. Field names MUST be unique within the set of fields for an action. The behaviour of clients when parsing a Siren document that violates this constraint is undefined.",
"type": "string"
},
"type": {
"description": "The input type of the field. This is a subset of the input types specified by HTML5.",
"type": "string",
"default": "text",
"enum": [
"hidden",
"text",
"search",
"tel",
"url",
"email",
"password",
"datetime",
"date",
"month",
"week",
"time",
"datetime-local",
"number",
"range",
"color",
"checkbox",
"radio",
"file"
]
},
"title": {
"description": "Textual annotation of a field. Clients may use this as a label.",
"type": "string"
},
"value": {
"description": "A value assigned to the field. May be a scalar value or a list of value objects.",
"oneOf": [
{
"type": [ "string", "number" ]
},
{
"type": "array",
"items": {
"$ref": "#/definitions/FieldValueObject"
}
}
]
}
}
},
"FieldValueObject": {
"description": "Value objects represent multiple selectable field values. Use in conjunction with field `\"type\" = \"radio\"` and `\"type\" = \"checkbox\"` to express that zero, one or many out of several possible values may be sent back to the server.",
"type": "object",
"required": [ "value" ],
"properties": {
"title": {
"description": "Textual description of a field value.",
"type": "string"
},
"value": {
"description": "Possible value for the field.",
"type": [ "string", "number" ]
},
"selected": {
"description": "A value object with a `\"selected\" = true` attribute indicates that this value should be considered preselected by the client. When missing, the default value is `false`.",
"type": "boolean",
"default": false
}
}
},
"Link": {
"description": "Links represent navigational transitions.",
"type": "object",
"required": [
"rel",
"href"
],
"properties": {
"class": {
"description": "Describes aspects of the link based on the current representation. Possible values are implementation-dependent and should be documented.",
"type": "array",
"items": {
"type": "string"
}
},
"title": {
"description": "Text describing the nature of a link.",
"type": "string"
},
"rel": {
"description": "Defines the relationship of the link to its entity, per Web Linking (RFC5988).",
"type": "array",
"items": {
"type": "string"
}
},
"href": {
"description": "The URI of the linked resource.",
"type": "string",
"format": "uri"
},
"type": {
"description": "Defines media type of the linked resource, per Web Linking (RFC5988).",
"type": "string"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment