Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 27KB

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