From 32ba8cfbecb98efdaba57ace326ce105691c0760 Mon Sep 17 00:00:00 2001 From: Jason Kwok <4410086+JasonHK@users.noreply.github.com> Date: Wed, 10 Jun 2020 00:35:40 +0800 Subject: [PATCH] [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 --- types/json-schema/index.d.ts | 103 +++++++++++++++++++++++++++++----- types/json-schema/tslint.json | 1 + 2 files changed, 89 insertions(+), 15 deletions(-) diff --git a/types/json-schema/index.d.ts b/types/json-schema/index.d.ts index 2844d6e6b6..d5b4429d8e 100644 --- a/types/json-schema/index.d.ts +++ b/types/json-schema/index.d.ts @@ -4,21 +4,46 @@ // Cyrille Tuzi // Lucian Buzzo // Roland Groza +// Jason Kwok // 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 {} /** * 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 {} /** * 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 { } +export interface JSONSchema7Array extends Array {} /** * Meta schema diff --git a/types/json-schema/tslint.json b/types/json-schema/tslint.json index db9ce1cb12..5957ae7250 100644 --- a/types/json-schema/tslint.json +++ b/types/json-schema/tslint.json @@ -1,6 +1,7 @@ { "extends": "dtslint/dt.json", "rules": { + "comment-format": false, "npm-naming": false, "semicolon": false }