[json-schema] Added type definition for JSON object (#44955)

* [json-schema] Added type definition for JSON object

* Revert "[json-schema] Added type definition for JSON object"

This reverts commit 21ecb0a486420079a1973fce895b473b9081516b.

* [json-schema] Added type definition for JSON object

* [json-schema] Added the missing indentation

Co-authored-by: Jason Kwok <JasonHK@users.noreply.github.com>
This commit is contained in:
Jason Kwok 2020-06-10 00:35:40 +08:00 committed by GitHub
parent 9cf43fab2e
commit 32ba8cfbec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 15 deletions

View File

@ -4,21 +4,46 @@
// Cyrille Tuzi <https://github.com/cyrilletuzi>
// Lucian Buzzo <https://github.com/lucianbuzzo>
// Roland Groza <https://github.com/rolandjitsu>
// Jason Kwok <https://github.com/JasonHK>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/* JSON Schema 4 */
//==================================================================================================
// JSON Schema Draft 04
//==================================================================================================
/**
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1
*/
export type JSONSchema4TypeName = 'string' | 'number' | 'integer' | 'boolean'
| 'object' | 'array' | 'null' | 'any'
export type JSONSchema4TypeName =
| 'string'
| 'number'
| 'integer'
| 'boolean'
| 'object'
| 'array'
| 'null'
| 'any';
/**
* @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-3.5
*/
export type JSONSchema4Type = any[] | boolean | number | null | object | string
export type JSONSchema4Type =
| string
| number
| boolean
| JSONSchema4Object
| JSONSchema4Array
| null;
// Workaround for infinite type recursion
export interface JSONSchema4Object {
[key: string]: JSONSchema4Type;
}
// Workaround for infinite type recursion
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
export interface JSONSchema4Array extends Array<JSONSchema4Type> {}
/**
* Meta schema
@ -216,11 +241,36 @@ export interface JSONSchema4 {
format?: string
}
/* JSON Schema 6 */
//==================================================================================================
// JSON Schema Draft 06
//==================================================================================================
export type JSONSchema6TypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null' | 'any'
export type JSONSchema6TypeName =
| 'string'
| 'number'
| 'integer'
| 'boolean'
| 'object'
| 'array'
| 'null'
| 'any';
export type JSONSchema6Type = any[] | boolean | number | null | object | string
export type JSONSchema6Type =
| string
| number
| boolean
| JSONSchema6Object
| JSONSchema6Array
| null;
// Workaround for infinite type recursion
export interface JSONSchema6Object {
[key: string]: JSONSchema6Type;
}
// Workaround for infinite type recursion
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
export interface JSONSchema6Array extends Array<JSONSchema6Type> {}
/**
* Meta schema
@ -507,22 +557,45 @@ export interface JSONSchema6 {
format?: string
}
/**
* JSON Schema 7
* Draft 07
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
*/
//==================================================================================================
// JSON Schema Draft 07
//==================================================================================================
// https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
//--------------------------------------------------------------------------------------------------
/**
* Primitive type
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
*/
export type JSONSchema7TypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
export type JSONSchema7Type = JSONSchema7Array[] | boolean | number | null | object | string;
export type JSONSchema7TypeName =
| 'string'
| 'number'
| 'integer'
| 'boolean'
| 'object'
| 'array'
| 'null';
/**
* Primitive type
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
*/
export type JSONSchema7Type =
| string
| number
| boolean
| JSONSchema7Object
| JSONSchema7Array
| null;
// Workaround for infinite type recursion
export interface JSONSchema7Object {
[key: string]: JSONSchema7Type;
}
// Workaround for infinite type recursion
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
export interface JSONSchema7Array extends Array<JSONSchema7Type> { }
export interface JSONSchema7Array extends Array<JSONSchema7Type> {}
/**
* Meta schema

View File

@ -1,6 +1,7 @@
{
"extends": "dtslint/dt.json",
"rules": {
"comment-format": false,
"npm-naming": false,
"semicolon": false
}