Skip to content

Update JSON Schema to be v1.0 compliant #1555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 88 additions & 68 deletions schema
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://jsonapi.org/schemas/spec/v1.0/draft",
"$comment": "The $id URI should be modified before releasing. This URI does not need to be network addressable. It is an ID only.",
"title": "JSON:API Schema",
"description": "This is a schema for responses in the JSON:API format. For more, see http://jsonapi.org",
"description": "A JSON Schema downloaded from jsonapi.org/schema on 2020-02-22 - modified to align with the specification. Additionaly, this schema only validates RESPONSES from a request. Validating request payloads requires slightly different constraints.",
"oneOf": [
{
"$ref": "#/definitions/success"
},
{
"$ref": "#/definitions/failure"
},
{
"$ref": "#/definitions/info"
}
],

"definitions": {
"success": {
"type": "object",
Expand All @@ -37,14 +35,7 @@
},
"links": {
"description": "Link members related to the primary data.",
"allOf": [
{
"$ref": "#/definitions/links"
},
{
"$ref": "#/definitions/pagination"
}
]
"$ref": "#/definitions/links"
},
"jsonapi": {
"$ref": "#/definitions/jsonapi"
Expand Down Expand Up @@ -77,25 +68,6 @@
},
"additionalProperties": false
},
"info": {
"type": "object",
"required": [
"meta"
],
"properties": {
"meta": {
"$ref": "#/definitions/meta"
},
"links": {
"$ref": "#/definitions/links"
},
"jsonapi": {
"$ref": "#/definitions/jsonapi"
}
},
"additionalProperties": false
},

"meta": {
"description": "Non-standard meta-information that can not be represented as an attribute or relationship.",
"type": "object",
Expand Down Expand Up @@ -142,7 +114,7 @@
"$ref": "#/definitions/relationships"
},
"links": {
"$ref": "#/definitions/links"
"$ref": "#/definitions/relationshipLinks"
},
"meta": {
"$ref": "#/definitions/meta"
Expand All @@ -160,23 +132,43 @@
},
"related": {
"$ref": "#/definitions/link"
},
"pagination": {
"$ref": "#/definitions/pagination"
}
},
"additionalProperties": true
},
"links": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/link"
}
},
"links": {
"type": "object",
"allOf": [
{
"properties": {
"first": true,
"last": true,
"next": true,
"prev": true
},
"additionalProperties": {
"$ref": "#/definitions/link"
}
},
{
"$ref": "#/definitions/pagination"
}
]
},
"link": {
"description": "A link **MUST** be represented as either: a string containing the link's URL or a link object.",
"oneOf": [
{
"description": "A string containing the link's URL.",
"type": "string",
"format": "uri-reference"
"format": "uri",
"$comment": "URI regex as per https://tools.ietf.org/html/rfc3986#appendix-B",
"pattern": "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"
},
{
"type": "object",
Expand All @@ -187,7 +179,9 @@
"href": {
"description": "A string containing the link's URL.",
"type": "string",
"format": "uri-reference"
"format": "uri",
"$comment": "URI regex as per https://tools.ietf.org/html/rfc3986#appendix-B",
"pattern": "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"
},
"meta": {
"$ref": "#/definitions/meta"
Expand All @@ -196,7 +190,6 @@
}
]
},

"attributes": {
"description": "Members of the attributes object (\"attributes\") represent information about the resource object in which it's defined.",
"type": "object",
Expand All @@ -206,16 +199,22 @@
}
},
"not": {
"$comment": "This is what the specification requires, but it seems bad. https://github.com/json-api/json-api/issues/1553",
"anyOf": [
{"required": ["relationships"]},
{"required": ["links"]},
{"required": ["id"]},
{"required": ["type"]}
Copy link

@bill-okara bill-okara Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this then allow "id" and "type" as attributes member, would that violate one of the restrictions for fields?

a resource can not have an attribute and relationship with the same name, nor can it have an attribute or relationship named type or id.

{
"required": [
"relationships"
]
},
{
"required": [
"links"
]
}
]
},
"additionalProperties": false
},

"relationships": {
"description": "Members of the relationships object (\"relationships\") represent references from the resource object in which it's defined to other resource objects.",
"type": "object",
Expand All @@ -241,16 +240,22 @@
}
},
"anyOf": [
{"required": ["data"]},
{"required": ["meta"]},
{"required": ["links"]}
{
"required": [
"data"
]
},
{
"required": [
"meta"
]
},
{
"required": [
"links"
]
}
],
"not": {
"anyOf": [
{"required": ["id"]},
{"required": ["type"]}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be moved up one level instead of removed to satisfy the restriction

a resource can not have an attribute and relationship with the same name, nor can it have an attribute or relationship named type or id.

]
},
"additionalProperties": false
}
},
Expand Down Expand Up @@ -305,34 +310,49 @@
"first": {
"description": "The first page of data",
"oneOf": [
{ "$ref": "#/definitions/link" },
{ "type": "null" }
{
"$ref": "#/definitions/link"
},
{
"type": "null"
}
]
},
"last": {
"description": "The last page of data",
"oneOf": [
{ "$ref": "#/definitions/link" },
{ "type": "null" }
{
"$ref": "#/definitions/link"
},
{
"type": "null"
}
]
},
"prev": {
"description": "The previous page of data",
"oneOf": [
{ "$ref": "#/definitions/link" },
{ "type": "null" }
{
"$ref": "#/definitions/link"
},
{
"type": "null"
}
]
},
"next": {
"description": "The next page of data",
"oneOf": [
{ "$ref": "#/definitions/link" },
{ "type": "null" }
{
"$ref": "#/definitions/link"
},
{
"type": "null"
}
]
}
}
},

"jsonapi": {
"description": "An object describing the server's implementation",
"type": "object",
Expand All @@ -346,13 +366,13 @@
},
"additionalProperties": false
},

"error": {
"type": "object",
"properties": {
"id": {
"description": "A unique identifier for this particular occurrence of the problem.",
"type": "string"
"type": "string",
"$comment": "The spec doesn't specify that this MUST be a string, so this could be changed to additionally allow numbers"
Comment on lines +374 to +375
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also allow null values?

},
"links": {
"$ref": "#/definitions/links"
Expand All @@ -378,7 +398,8 @@
"properties": {
"pointer": {
"description": "A JSON Pointer [RFC6901] to the associated entity in the request document [e.g. \"/data\" for a primary data object, or \"/data/attributes/title\" for a specific attribute].",
"type": "string"
"type": "string",
"pattern": "^(?:\\/(?:[^~/]|~0|~1)*)*$"
},
"parameter": {
"description": "A string indicating which query parameter caused the error.",
Expand All @@ -394,4 +415,3 @@
}
}
}

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy