schema.json 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. {
  2. "$schema": "http://json-schema.org/draft-06/schema#",
  3. "title": "JSON:API Schema",
  4. "description": "This is a schema for responses in the JSON:API format. For more, see http://jsonapi.org",
  5. "oneOf": [
  6. {
  7. "$ref": "#/definitions/success"
  8. },
  9. {
  10. "$ref": "#/definitions/failure"
  11. },
  12. {
  13. "$ref": "#/definitions/info"
  14. }
  15. ],
  16. "definitions": {
  17. "success": {
  18. "type": "object",
  19. "required": [
  20. "data"
  21. ],
  22. "properties": {
  23. "data": {
  24. "$ref": "#/definitions/data"
  25. },
  26. "included": {
  27. "description": "To reduce the number of HTTP requests, servers **MAY** allow responses that include related resources along with the requested primary resources. Such responses are called \"compound documents\".",
  28. "type": "array",
  29. "items": {
  30. "$ref": "#/definitions/resource"
  31. },
  32. "uniqueItems": true
  33. },
  34. "meta": {
  35. "$ref": "#/definitions/meta"
  36. },
  37. "links": {
  38. "description": "Link members related to the primary data.",
  39. "allOf": [
  40. {
  41. "$ref": "#/definitions/links"
  42. },
  43. {
  44. "$ref": "#/definitions/pagination"
  45. }
  46. ]
  47. },
  48. "jsonapi": {
  49. "$ref": "#/definitions/jsonapi"
  50. }
  51. },
  52. "additionalProperties": false
  53. },
  54. "failure": {
  55. "type": "object",
  56. "required": [
  57. "errors"
  58. ],
  59. "properties": {
  60. "errors": {
  61. "type": "array",
  62. "items": {
  63. "$ref": "#/definitions/error"
  64. },
  65. "uniqueItems": true
  66. },
  67. "meta": {
  68. "$ref": "#/definitions/meta"
  69. },
  70. "jsonapi": {
  71. "$ref": "#/definitions/jsonapi"
  72. },
  73. "links": {
  74. "$ref": "#/definitions/links"
  75. }
  76. },
  77. "additionalProperties": false
  78. },
  79. "info": {
  80. "type": "object",
  81. "required": [
  82. "meta"
  83. ],
  84. "properties": {
  85. "meta": {
  86. "$ref": "#/definitions/meta"
  87. },
  88. "links": {
  89. "$ref": "#/definitions/links"
  90. },
  91. "jsonapi": {
  92. "$ref": "#/definitions/jsonapi"
  93. }
  94. },
  95. "additionalProperties": false
  96. },
  97. "meta": {
  98. "description": "Non-standard meta-information that can not be represented as an attribute or relationship.",
  99. "type": "object",
  100. "additionalProperties": true
  101. },
  102. "data": {
  103. "description": "The document's \"primary data\" is a representation of the resource or collection of resources targeted by a request.",
  104. "oneOf": [
  105. {
  106. "$ref": "#/definitions/resource"
  107. },
  108. {
  109. "description": "An array of resource objects, an array of resource identifier objects, or an empty array ([]), for requests that target resource collections.",
  110. "type": "array",
  111. "items": {
  112. "$ref": "#/definitions/resource"
  113. },
  114. "uniqueItems": true
  115. },
  116. {
  117. "description": "null if the request is one that might correspond to a single resource, but doesn't currently.",
  118. "type": "null"
  119. }
  120. ]
  121. },
  122. "resource": {
  123. "description": "\"Resource objects\" appear in a JSON:API document to represent resources.",
  124. "type": "object",
  125. "required": [
  126. "type",
  127. "id"
  128. ],
  129. "properties": {
  130. "type": {
  131. "type": "string"
  132. },
  133. "id": {
  134. "type": "string"
  135. },
  136. "attributes": {
  137. "$ref": "#/definitions/attributes"
  138. },
  139. "relationships": {
  140. "$ref": "#/definitions/relationships"
  141. },
  142. "links": {
  143. "$ref": "#/definitions/links"
  144. },
  145. "meta": {
  146. "$ref": "#/definitions/meta"
  147. }
  148. },
  149. "additionalProperties": false
  150. },
  151. "relationshipLinks": {
  152. "description": "A resource object **MAY** contain references to other resource objects (\"relationships\"). Relationships may be to-one or to-many. Relationships can be specified by including a member in a resource's links object.",
  153. "type": "object",
  154. "properties": {
  155. "self": {
  156. "description": "A `self` member, whose value is a URL for the relationship itself (a \"relationship URL\"). This URL allows the client to directly manipulate the relationship. For example, it would allow a client to remove an `author` from an `article` without deleting the people resource itself.",
  157. "$ref": "#/definitions/link"
  158. },
  159. "related": {
  160. "$ref": "#/definitions/link"
  161. }
  162. },
  163. "additionalProperties": true
  164. },
  165. "links": {
  166. "type": "object",
  167. "additionalProperties": {
  168. "$ref": "#/definitions/link"
  169. }
  170. },
  171. "link": {
  172. "description": "A link **MUST** be represented as either: a string containing the link's URL or a link object.",
  173. "oneOf": [
  174. {
  175. "description": "A string containing the link's URL.",
  176. "type": "string",
  177. "format": "uri-reference"
  178. },
  179. {
  180. "type": "object",
  181. "required": [
  182. "href"
  183. ],
  184. "properties": {
  185. "href": {
  186. "description": "A string containing the link's URL.",
  187. "type": "string",
  188. "format": "uri-reference"
  189. },
  190. "meta": {
  191. "$ref": "#/definitions/meta"
  192. }
  193. }
  194. }
  195. ]
  196. },
  197. "attributes": {
  198. "description": "Members of the attributes object (\"attributes\") represent information about the resource object in which it's defined.",
  199. "type": "object",
  200. "patternProperties": {
  201. "^(?!relationships$|links$|id$|type$)\\w[-\\w_]*$": {
  202. "description": "Attributes may contain any valid JSON value."
  203. }
  204. },
  205. "additionalProperties": false
  206. },
  207. "relationships": {
  208. "description": "Members of the relationships object (\"relationships\") represent references from the resource object in which it's defined to other resource objects.",
  209. "type": "object",
  210. "patternProperties": {
  211. "^(?!id$|type$)\\w[-\\w_]*$": {
  212. "properties": {
  213. "links": {
  214. "$ref": "#/definitions/relationshipLinks"
  215. },
  216. "data": {
  217. "description": "Member, whose value represents \"resource linkage\".",
  218. "oneOf": [
  219. {
  220. "$ref": "#/definitions/relationshipToOne"
  221. },
  222. {
  223. "$ref": "#/definitions/relationshipToMany"
  224. }
  225. ]
  226. },
  227. "meta": {
  228. "$ref": "#/definitions/meta"
  229. }
  230. },
  231. "anyOf": [
  232. {"required": ["data"]},
  233. {"required": ["meta"]},
  234. {"required": ["links"]}
  235. ],
  236. "additionalProperties": false
  237. }
  238. },
  239. "additionalProperties": false
  240. },
  241. "relationshipToOne": {
  242. "description": "References to other resource objects in a to-one (\"relationship\"). Relationships can be specified by including a member in a resource's links object.",
  243. "anyOf": [
  244. {
  245. "$ref": "#/definitions/empty"
  246. },
  247. {
  248. "$ref": "#/definitions/linkage"
  249. }
  250. ]
  251. },
  252. "relationshipToMany": {
  253. "description": "An array of objects each containing \"type\" and \"id\" members for to-many relationships.",
  254. "type": "array",
  255. "items": {
  256. "$ref": "#/definitions/linkage"
  257. },
  258. "uniqueItems": true
  259. },
  260. "empty": {
  261. "description": "Describes an empty to-one relationship.",
  262. "type": "null"
  263. },
  264. "linkage": {
  265. "description": "The \"type\" and \"id\" to non-empty members.",
  266. "type": "object",
  267. "required": [
  268. "type",
  269. "id"
  270. ],
  271. "properties": {
  272. "type": {
  273. "type": "string"
  274. },
  275. "id": {
  276. "type": "string"
  277. },
  278. "meta": {
  279. "$ref": "#/definitions/meta"
  280. }
  281. },
  282. "additionalProperties": false
  283. },
  284. "pagination": {
  285. "type": "object",
  286. "properties": {
  287. "first": {
  288. "description": "The first page of data",
  289. "oneOf": [
  290. { "$ref": "#/definitions/link" },
  291. { "type": "null" }
  292. ]
  293. },
  294. "last": {
  295. "description": "The last page of data",
  296. "oneOf": [
  297. { "$ref": "#/definitions/link" },
  298. { "type": "null" }
  299. ]
  300. },
  301. "prev": {
  302. "description": "The previous page of data",
  303. "oneOf": [
  304. { "$ref": "#/definitions/link" },
  305. { "type": "null" }
  306. ]
  307. },
  308. "next": {
  309. "description": "The next page of data",
  310. "oneOf": [
  311. { "$ref": "#/definitions/link" },
  312. { "type": "null" }
  313. ]
  314. }
  315. }
  316. },
  317. "jsonapi": {
  318. "description": "An object describing the server's implementation",
  319. "type": "object",
  320. "properties": {
  321. "version": {
  322. "type": "string"
  323. },
  324. "meta": {
  325. "$ref": "#/definitions/meta"
  326. }
  327. },
  328. "additionalProperties": false
  329. },
  330. "error": {
  331. "type": "object",
  332. "properties": {
  333. "id": {
  334. "description": "A unique identifier for this particular occurrence of the problem.",
  335. "type": "string"
  336. },
  337. "links": {
  338. "$ref": "#/definitions/links"
  339. },
  340. "status": {
  341. "description": "The HTTP status code applicable to this problem, expressed as a string value.",
  342. "type": "string"
  343. },
  344. "code": {
  345. "description": "An application-specific error code, expressed as a string value.",
  346. "type": "string"
  347. },
  348. "title": {
  349. "description": "A short, human-readable summary of the problem. It **SHOULD NOT** change from occurrence to occurrence of the problem, except for purposes of localization.",
  350. "type": "string"
  351. },
  352. "detail": {
  353. "description": "A human-readable explanation specific to this occurrence of the problem.",
  354. "type": "string"
  355. },
  356. "source": {
  357. "type": "object",
  358. "properties": {
  359. "pointer": {
  360. "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].",
  361. "type": "string"
  362. },
  363. "parameter": {
  364. "description": "A string indicating which query parameter caused the error.",
  365. "type": "string"
  366. }
  367. }
  368. },
  369. "meta": {
  370. "$ref": "#/definitions/meta"
  371. }
  372. },
  373. "additionalProperties": false
  374. }
  375. }
  376. }