7a5dfc16c6f3e5f6ed2be3a2b2f169f7312cddedd6487489e0891e337cb708f2f05e091705ef1f71e75aa56bb79e00dc946e14fc889000cd97808d11129cf6 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. // ==================================================================================================
  2. // JSON Schema Draft 04
  3. // ==================================================================================================
  4. /**
  5. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1
  6. */
  7. export type JSONSchema4TypeName =
  8. | "string" //
  9. | "number"
  10. | "integer"
  11. | "boolean"
  12. | "object"
  13. | "array"
  14. | "null"
  15. | "any";
  16. /**
  17. * @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-3.5
  18. */
  19. export type JSONSchema4Type =
  20. | string //
  21. | number
  22. | boolean
  23. | JSONSchema4Object
  24. | JSONSchema4Array
  25. | null;
  26. // Workaround for infinite type recursion
  27. export interface JSONSchema4Object {
  28. [key: string]: JSONSchema4Type;
  29. }
  30. // Workaround for infinite type recursion
  31. // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
  32. export interface JSONSchema4Array extends Array<JSONSchema4Type> {}
  33. /**
  34. * Meta schema
  35. *
  36. * Recommended values:
  37. * - 'http://json-schema.org/schema#'
  38. * - 'http://json-schema.org/hyper-schema#'
  39. * - 'http://json-schema.org/draft-04/schema#'
  40. * - 'http://json-schema.org/draft-04/hyper-schema#'
  41. * - 'http://json-schema.org/draft-03/schema#'
  42. * - 'http://json-schema.org/draft-03/hyper-schema#'
  43. *
  44. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
  45. */
  46. export type JSONSchema4Version = string;
  47. /**
  48. * JSON Schema V4
  49. * @see https://tools.ietf.org/html/draft-zyp-json-schema-04
  50. */
  51. export interface JSONSchema4 {
  52. id?: string | undefined;
  53. $ref?: string | undefined;
  54. $schema?: JSONSchema4Version | undefined;
  55. /**
  56. * This attribute is a string that provides a short description of the
  57. * instance property.
  58. *
  59. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.21
  60. */
  61. title?: string | undefined;
  62. /**
  63. * This attribute is a string that provides a full description of the of
  64. * purpose the instance property.
  65. *
  66. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.22
  67. */
  68. description?: string | undefined;
  69. default?: JSONSchema4Type | undefined;
  70. multipleOf?: number | undefined;
  71. maximum?: number | undefined;
  72. exclusiveMaximum?: boolean | undefined;
  73. minimum?: number | undefined;
  74. exclusiveMinimum?: boolean | undefined;
  75. maxLength?: number | undefined;
  76. minLength?: number | undefined;
  77. pattern?: string | undefined;
  78. /**
  79. * May only be defined when "items" is defined, and is a tuple of JSONSchemas.
  80. *
  81. * This provides a definition for additional items in an array instance
  82. * when tuple definitions of the items is provided. This can be false
  83. * to indicate additional items in the array are not allowed, or it can
  84. * be a schema that defines the schema of the additional items.
  85. *
  86. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.6
  87. */
  88. additionalItems?: boolean | JSONSchema4 | undefined;
  89. /**
  90. * This attribute defines the allowed items in an instance array, and
  91. * MUST be a schema or an array of schemas. The default value is an
  92. * empty schema which allows any value for items in the instance array.
  93. *
  94. * When this attribute value is a schema and the instance value is an
  95. * array, then all the items in the array MUST be valid according to the
  96. * schema.
  97. *
  98. * When this attribute value is an array of schemas and the instance
  99. * value is an array, each position in the instance array MUST conform
  100. * to the schema in the corresponding position for this array. This
  101. * called tuple typing. When tuple typing is used, additional items are
  102. * allowed, disallowed, or constrained by the "additionalItems"
  103. * (Section 5.6) attribute using the same rules as
  104. * "additionalProperties" (Section 5.4) for objects.
  105. *
  106. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.5
  107. */
  108. items?: JSONSchema4 | JSONSchema4[] | undefined;
  109. maxItems?: number | undefined;
  110. minItems?: number | undefined;
  111. uniqueItems?: boolean | undefined;
  112. maxProperties?: number | undefined;
  113. minProperties?: number | undefined;
  114. /**
  115. * This attribute indicates if the instance must have a value, and not
  116. * be undefined. This is false by default, making the instance
  117. * optional.
  118. *
  119. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7
  120. */
  121. required?: boolean | string[] | undefined;
  122. /**
  123. * This attribute defines a schema for all properties that are not
  124. * explicitly defined in an object type definition. If specified, the
  125. * value MUST be a schema or a boolean. If false is provided, no
  126. * additional properties are allowed beyond the properties defined in
  127. * the schema. The default value is an empty schema which allows any
  128. * value for additional properties.
  129. *
  130. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.4
  131. */
  132. additionalProperties?: boolean | JSONSchema4 | undefined;
  133. definitions?: {
  134. [k: string]: JSONSchema4;
  135. } | undefined;
  136. /**
  137. * This attribute is an object with property definitions that define the
  138. * valid values of instance object property values. When the instance
  139. * value is an object, the property values of the instance object MUST
  140. * conform to the property definitions in this object. In this object,
  141. * each property definition's value MUST be a schema, and the property's
  142. * name MUST be the name of the instance property that it defines. The
  143. * instance property value MUST be valid according to the schema from
  144. * the property definition. Properties are considered unordered, the
  145. * order of the instance properties MAY be in any order.
  146. *
  147. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.2
  148. */
  149. properties?: {
  150. [k: string]: JSONSchema4;
  151. } | undefined;
  152. /**
  153. * This attribute is an object that defines the schema for a set of
  154. * property names of an object instance. The name of each property of
  155. * this attribute's object is a regular expression pattern in the ECMA
  156. * 262/Perl 5 format, while the value is a schema. If the pattern
  157. * matches the name of a property on the instance object, the value of
  158. * the instance's property MUST be valid against the pattern name's
  159. * schema value.
  160. *
  161. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.3
  162. */
  163. patternProperties?: {
  164. [k: string]: JSONSchema4;
  165. } | undefined;
  166. dependencies?: {
  167. [k: string]: JSONSchema4 | string[];
  168. } | undefined;
  169. /**
  170. * This provides an enumeration of all possible values that are valid
  171. * for the instance property. This MUST be an array, and each item in
  172. * the array represents a possible value for the instance value. If
  173. * this attribute is defined, the instance value MUST be one of the
  174. * values in the array in order for the schema to be valid.
  175. *
  176. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.19
  177. */
  178. enum?: JSONSchema4Type[] | undefined;
  179. /**
  180. * A single type, or a union of simple types
  181. */
  182. type?: JSONSchema4TypeName | JSONSchema4TypeName[] | undefined;
  183. allOf?: JSONSchema4[] | undefined;
  184. anyOf?: JSONSchema4[] | undefined;
  185. oneOf?: JSONSchema4[] | undefined;
  186. not?: JSONSchema4 | undefined;
  187. /**
  188. * The value of this property MUST be another schema which will provide
  189. * a base schema which the current schema will inherit from. The
  190. * inheritance rules are such that any instance that is valid according
  191. * to the current schema MUST be valid according to the referenced
  192. * schema. This MAY also be an array, in which case, the instance MUST
  193. * be valid for all the schemas in the array. A schema that extends
  194. * another schema MAY define additional attributes, constrain existing
  195. * attributes, or add other constraints.
  196. *
  197. * Conceptually, the behavior of extends can be seen as validating an
  198. * instance against all constraints in the extending schema as well as
  199. * the extended schema(s).
  200. *
  201. * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.26
  202. */
  203. extends?: string | string[] | undefined;
  204. /**
  205. * @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-5.6
  206. */
  207. [k: string]: any;
  208. format?: string | undefined;
  209. }
  210. // ==================================================================================================
  211. // JSON Schema Draft 06
  212. // ==================================================================================================
  213. export type JSONSchema6TypeName =
  214. | "string" //
  215. | "number"
  216. | "integer"
  217. | "boolean"
  218. | "object"
  219. | "array"
  220. | "null"
  221. | "any";
  222. export type JSONSchema6Type =
  223. | string //
  224. | number
  225. | boolean
  226. | JSONSchema6Object
  227. | JSONSchema6Array
  228. | null;
  229. // Workaround for infinite type recursion
  230. export interface JSONSchema6Object {
  231. [key: string]: JSONSchema6Type;
  232. }
  233. // Workaround for infinite type recursion
  234. // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
  235. export interface JSONSchema6Array extends Array<JSONSchema6Type> {}
  236. /**
  237. * Meta schema
  238. *
  239. * Recommended values:
  240. * - 'http://json-schema.org/schema#'
  241. * - 'http://json-schema.org/hyper-schema#'
  242. * - 'http://json-schema.org/draft-06/schema#'
  243. * - 'http://json-schema.org/draft-06/hyper-schema#'
  244. *
  245. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
  246. */
  247. export type JSONSchema6Version = string;
  248. /**
  249. * JSON Schema V6
  250. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01
  251. */
  252. export type JSONSchema6Definition = JSONSchema6 | boolean;
  253. export interface JSONSchema6 {
  254. $id?: string | undefined;
  255. $ref?: string | undefined;
  256. $schema?: JSONSchema6Version | undefined;
  257. /**
  258. * Must be strictly greater than 0.
  259. * A numeric instance is valid only if division by this keyword's value results in an integer.
  260. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.1
  261. */
  262. multipleOf?: number | undefined;
  263. /**
  264. * Representing an inclusive upper limit for a numeric instance.
  265. * This keyword validates only if the instance is less than or exactly equal to "maximum".
  266. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.2
  267. */
  268. maximum?: number | undefined;
  269. /**
  270. * Representing an exclusive upper limit for a numeric instance.
  271. * This keyword validates only if the instance is strictly less than (not equal to) to "exclusiveMaximum".
  272. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.3
  273. */
  274. exclusiveMaximum?: number | undefined;
  275. /**
  276. * Representing an inclusive lower limit for a numeric instance.
  277. * This keyword validates only if the instance is greater than or exactly equal to "minimum".
  278. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.4
  279. */
  280. minimum?: number | undefined;
  281. /**
  282. * Representing an exclusive lower limit for a numeric instance.
  283. * This keyword validates only if the instance is strictly greater than (not equal to) to "exclusiveMinimum".
  284. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.5
  285. */
  286. exclusiveMinimum?: number | undefined;
  287. /**
  288. * Must be a non-negative integer.
  289. * A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword.
  290. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.6
  291. */
  292. maxLength?: number | undefined;
  293. /**
  294. * Must be a non-negative integer.
  295. * A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.
  296. * Omitting this keyword has the same behavior as a value of 0.
  297. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.7
  298. */
  299. minLength?: number | undefined;
  300. /**
  301. * Should be a valid regular expression, according to the ECMA 262 regular expression dialect.
  302. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.8
  303. */
  304. pattern?: string | undefined;
  305. /**
  306. * This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself.
  307. * Omitting this keyword has the same behavior as an empty schema.
  308. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.9
  309. */
  310. items?: JSONSchema6Definition | JSONSchema6Definition[] | undefined;
  311. /**
  312. * This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself.
  313. * If "items" is an array of schemas, validation succeeds if every instance element
  314. * at a position greater than the size of "items" validates against "additionalItems".
  315. * Otherwise, "additionalItems" MUST be ignored, as the "items" schema
  316. * (possibly the default value of an empty schema) is applied to all elements.
  317. * Omitting this keyword has the same behavior as an empty schema.
  318. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.10
  319. */
  320. additionalItems?: JSONSchema6Definition | undefined;
  321. /**
  322. * Must be a non-negative integer.
  323. * An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword.
  324. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.11
  325. */
  326. maxItems?: number | undefined;
  327. /**
  328. * Must be a non-negative integer.
  329. * An array instance is valid against "maxItems" if its size is greater than, or equal to, the value of this keyword.
  330. * Omitting this keyword has the same behavior as a value of 0.
  331. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.12
  332. */
  333. minItems?: number | undefined;
  334. /**
  335. * If this keyword has boolean value false, the instance validates successfully.
  336. * If it has boolean value true, the instance validates successfully if all of its elements are unique.
  337. * Omitting this keyword has the same behavior as a value of false.
  338. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.13
  339. */
  340. uniqueItems?: boolean | undefined;
  341. /**
  342. * An array instance is valid against "contains" if at least one of its elements is valid against the given schema.
  343. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.14
  344. */
  345. contains?: JSONSchema6Definition | undefined;
  346. /**
  347. * Must be a non-negative integer.
  348. * An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.
  349. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.15
  350. */
  351. maxProperties?: number | undefined;
  352. /**
  353. * Must be a non-negative integer.
  354. * An object instance is valid against "maxProperties" if its number of properties is greater than,
  355. * or equal to, the value of this keyword.
  356. * Omitting this keyword has the same behavior as a value of 0.
  357. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.16
  358. */
  359. minProperties?: number | undefined;
  360. /**
  361. * Elements of this array must be unique.
  362. * An object instance is valid against this keyword if every item in the array is the name of a property in the instance.
  363. * Omitting this keyword has the same behavior as an empty array.
  364. *
  365. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.17
  366. */
  367. required?: string[] | undefined;
  368. /**
  369. * This keyword determines how child instances validate for objects, and does not directly validate the immediate instance itself.
  370. * Validation succeeds if, for each name that appears in both the instance and as a name within this keyword's value,
  371. * the child instance for that name successfully validates against the corresponding schema.
  372. * Omitting this keyword has the same behavior as an empty object.
  373. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.18
  374. */
  375. properties?: {
  376. [k: string]: JSONSchema6Definition;
  377. } | undefined;
  378. /**
  379. * This attribute is an object that defines the schema for a set of property names of an object instance.
  380. * The name of each property of this attribute's object is a regular expression pattern in the ECMA 262, while the value is a schema.
  381. * If the pattern matches the name of a property on the instance object, the value of the instance's property
  382. * MUST be valid against the pattern name's schema value.
  383. * Omitting this keyword has the same behavior as an empty object.
  384. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.19
  385. */
  386. patternProperties?: {
  387. [k: string]: JSONSchema6Definition;
  388. } | undefined;
  389. /**
  390. * This attribute defines a schema for all properties that are not explicitly defined in an object type definition.
  391. * If specified, the value MUST be a schema or a boolean.
  392. * If false is provided, no additional properties are allowed beyond the properties defined in the schema.
  393. * The default value is an empty schema which allows any value for additional properties.
  394. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.20
  395. */
  396. additionalProperties?: JSONSchema6Definition | undefined;
  397. /**
  398. * This keyword specifies rules that are evaluated if the instance is an object and contains a certain property.
  399. * Each property specifies a dependency.
  400. * If the dependency value is an array, each element in the array must be unique.
  401. * Omitting this keyword has the same behavior as an empty object.
  402. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.21
  403. */
  404. dependencies?: {
  405. [k: string]: JSONSchema6Definition | string[];
  406. } | undefined;
  407. /**
  408. * Takes a schema which validates the names of all properties rather than their values.
  409. * Note the property name that the schema is testing will always be a string.
  410. * Omitting this keyword has the same behavior as an empty schema.
  411. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.22
  412. */
  413. propertyNames?: JSONSchema6Definition | undefined;
  414. /**
  415. * This provides an enumeration of all possible values that are valid
  416. * for the instance property. This MUST be an array, and each item in
  417. * the array represents a possible value for the instance value. If
  418. * this attribute is defined, the instance value MUST be one of the
  419. * values in the array in order for the schema to be valid.
  420. *
  421. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.23
  422. */
  423. enum?: JSONSchema6Type[] | undefined;
  424. /**
  425. * More readable form of a one-element "enum"
  426. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.24
  427. */
  428. const?: JSONSchema6Type | undefined;
  429. /**
  430. * A single type, or a union of simple types
  431. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.25
  432. */
  433. type?: JSONSchema6TypeName | JSONSchema6TypeName[] | undefined;
  434. /**
  435. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26
  436. */
  437. allOf?: JSONSchema6Definition[] | undefined;
  438. /**
  439. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27
  440. */
  441. anyOf?: JSONSchema6Definition[] | undefined;
  442. /**
  443. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28
  444. */
  445. oneOf?: JSONSchema6Definition[] | undefined;
  446. /**
  447. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.29
  448. */
  449. not?: JSONSchema6Definition | undefined;
  450. /**
  451. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.1
  452. */
  453. definitions?: {
  454. [k: string]: JSONSchema6Definition;
  455. } | undefined;
  456. /**
  457. * This attribute is a string that provides a short description of the instance property.
  458. *
  459. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.2
  460. */
  461. title?: string | undefined;
  462. /**
  463. * This attribute is a string that provides a full description of the of purpose the instance property.
  464. *
  465. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.2
  466. */
  467. description?: string | undefined;
  468. /**
  469. * This keyword can be used to supply a default JSON value associated with a particular schema.
  470. * It is RECOMMENDED that a default value be valid against the associated schema.
  471. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.3
  472. */
  473. default?: JSONSchema6Type | undefined;
  474. /**
  475. * Array of examples with no validation effect the value of "default" is usable as an example without repeating it under this keyword
  476. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.4
  477. */
  478. examples?: JSONSchema6Type[] | undefined;
  479. /**
  480. * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-8
  481. */
  482. format?: string | undefined;
  483. }
  484. // ==================================================================================================
  485. // JSON Schema Draft 07
  486. // ==================================================================================================
  487. // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
  488. // --------------------------------------------------------------------------------------------------
  489. /**
  490. * Primitive type
  491. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
  492. */
  493. export type JSONSchema7TypeName =
  494. | "string" //
  495. | "number"
  496. | "integer"
  497. | "boolean"
  498. | "object"
  499. | "array"
  500. | "null";
  501. /**
  502. * Primitive type
  503. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
  504. */
  505. export type JSONSchema7Type =
  506. | string //
  507. | number
  508. | boolean
  509. | JSONSchema7Object
  510. | JSONSchema7Array
  511. | null;
  512. // Workaround for infinite type recursion
  513. export interface JSONSchema7Object {
  514. [key: string]: JSONSchema7Type;
  515. }
  516. // Workaround for infinite type recursion
  517. // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
  518. export interface JSONSchema7Array extends Array<JSONSchema7Type> {}
  519. /**
  520. * Meta schema
  521. *
  522. * Recommended values:
  523. * - 'http://json-schema.org/schema#'
  524. * - 'http://json-schema.org/hyper-schema#'
  525. * - 'http://json-schema.org/draft-07/schema#'
  526. * - 'http://json-schema.org/draft-07/hyper-schema#'
  527. *
  528. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
  529. */
  530. export type JSONSchema7Version = string;
  531. /**
  532. * JSON Schema v7
  533. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
  534. */
  535. export type JSONSchema7Definition = JSONSchema7 | boolean;
  536. export interface JSONSchema7 {
  537. $id?: string | undefined;
  538. $ref?: string | undefined;
  539. $schema?: JSONSchema7Version | undefined;
  540. $comment?: string | undefined;
  541. /**
  542. * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
  543. * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
  544. */
  545. $defs?: {
  546. [key: string]: JSONSchema7Definition;
  547. } | undefined;
  548. /**
  549. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
  550. */
  551. type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
  552. enum?: JSONSchema7Type[] | undefined;
  553. const?: JSONSchema7Type | undefined;
  554. /**
  555. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
  556. */
  557. multipleOf?: number | undefined;
  558. maximum?: number | undefined;
  559. exclusiveMaximum?: number | undefined;
  560. minimum?: number | undefined;
  561. exclusiveMinimum?: number | undefined;
  562. /**
  563. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
  564. */
  565. maxLength?: number | undefined;
  566. minLength?: number | undefined;
  567. pattern?: string | undefined;
  568. /**
  569. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
  570. */
  571. items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
  572. additionalItems?: JSONSchema7Definition | undefined;
  573. maxItems?: number | undefined;
  574. minItems?: number | undefined;
  575. uniqueItems?: boolean | undefined;
  576. contains?: JSONSchema7Definition | undefined;
  577. /**
  578. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
  579. */
  580. maxProperties?: number | undefined;
  581. minProperties?: number | undefined;
  582. required?: string[] | undefined;
  583. properties?: {
  584. [key: string]: JSONSchema7Definition;
  585. } | undefined;
  586. patternProperties?: {
  587. [key: string]: JSONSchema7Definition;
  588. } | undefined;
  589. additionalProperties?: JSONSchema7Definition | undefined;
  590. dependencies?: {
  591. [key: string]: JSONSchema7Definition | string[];
  592. } | undefined;
  593. propertyNames?: JSONSchema7Definition | undefined;
  594. /**
  595. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
  596. */
  597. if?: JSONSchema7Definition | undefined;
  598. then?: JSONSchema7Definition | undefined;
  599. else?: JSONSchema7Definition | undefined;
  600. /**
  601. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
  602. */
  603. allOf?: JSONSchema7Definition[] | undefined;
  604. anyOf?: JSONSchema7Definition[] | undefined;
  605. oneOf?: JSONSchema7Definition[] | undefined;
  606. not?: JSONSchema7Definition | undefined;
  607. /**
  608. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
  609. */
  610. format?: string | undefined;
  611. /**
  612. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
  613. */
  614. contentMediaType?: string | undefined;
  615. contentEncoding?: string | undefined;
  616. /**
  617. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
  618. */
  619. definitions?: {
  620. [key: string]: JSONSchema7Definition;
  621. } | undefined;
  622. /**
  623. * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
  624. */
  625. title?: string | undefined;
  626. description?: string | undefined;
  627. default?: JSONSchema7Type | undefined;
  628. readOnly?: boolean | undefined;
  629. writeOnly?: boolean | undefined;
  630. examples?: JSONSchema7Type | undefined;
  631. }
  632. export interface ValidationResult {
  633. valid: boolean;
  634. errors: ValidationError[];
  635. }
  636. export interface ValidationError {
  637. property: string;
  638. message: string;
  639. }
  640. /**
  641. * To use the validator call JSONSchema.validate with an instance object and an optional schema object.
  642. * If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
  643. * that schema will be used to validate and the schema parameter is not necessary (if both exist,
  644. * both validations will occur).
  645. */
  646. export function validate(instance: {}, schema: JSONSchema4 | JSONSchema6 | JSONSchema7): ValidationResult;
  647. /**
  648. * The checkPropertyChange method will check to see if an value can legally be in property with the given schema
  649. * This is slightly different than the validate method in that it will fail if the schema is readonly and it will
  650. * not check for self-validation, it is assumed that the passed in value is already internally valid.
  651. */
  652. export function checkPropertyChange(
  653. value: any,
  654. schema: JSONSchema4 | JSONSchema6 | JSONSchema7,
  655. property: string,
  656. ): ValidationResult;
  657. /**
  658. * This checks to ensure that the result is valid and will throw an appropriate error message if it is not.
  659. */
  660. export function mustBeValid(result: ValidationResult): void;