Skip to content

Commit 60df0bb

Browse files
authored
fix(utils): add to JSONSchema4Type missing Array and Object (#7406)
* fix: JSONSchema4Type missing Array and Object From https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/json-schema/index.d.ts#L30 * fix: cleanup and build fix * fix: lint disable line * fix: create and move array/object to a new extended type. * fix: lint error * fix: lint error
1 parent 49a53f0 commit 60df0bb

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Diff for: packages/utils/src/json-schema.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ export type JSONSchema4TypeName =
2727
*/
2828
export type JSONSchema4Type = boolean | number | string | null;
2929

30+
export type JSONSchema4TypeExtended =
31+
| JSONSchema4Type
32+
| JSONSchema4Array
33+
| JSONSchema4Object;
34+
35+
// Workaround for infinite type recursion
36+
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
37+
export interface JSONSchema4Object {
38+
[key: string]: JSONSchema4TypeExtended;
39+
}
40+
41+
// Workaround for infinite type recursion
42+
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
43+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
44+
export interface JSONSchema4Array extends Array<JSONSchema4TypeExtended> {}
45+
3046
/**
3147
* Meta schema
3248
*
@@ -51,7 +67,7 @@ export type JSONSchema4 =
5167
| JSONSchema4AnyOfSchema
5268
| JSONSchema4AnySchema
5369
| JSONSchema4ArraySchema
54-
| JSONSchema4BoleanSchema
70+
| JSONSchema4BooleanSchema
5571
| JSONSchema4MultiSchema
5672
| JSONSchema4NullSchema
5773
| JSONSchema4NumberSchema
@@ -133,7 +149,7 @@ interface JSONSchema4Base {
133149
/**
134150
* The default value for the item if not present
135151
*/
136-
default?: JSONSchema4Type | undefined;
152+
default?: JSONSchema4TypeExtended | undefined;
137153

138154
/**
139155
* This attribute indicates if the instance must have a value, and not
@@ -187,7 +203,7 @@ export interface JSONSchema4MultiSchema
187203
Omit<JSONSchema4ArraySchema, 'enum' | 'type'>,
188204
Omit<JSONSchema4StringSchema, 'enum' | 'type'>,
189205
Omit<JSONSchema4NumberSchema, 'enum' | 'type'>,
190-
Omit<JSONSchema4BoleanSchema, 'enum' | 'type'>,
206+
Omit<JSONSchema4BooleanSchema, 'enum' | 'type'>,
191207
Omit<JSONSchema4NullSchema, 'enum' | 'type'>,
192208
Omit<JSONSchema4AnySchema, 'enum' | 'type'> {
193209
type: JSONSchema4TypeName[];
@@ -440,7 +456,7 @@ export interface JSONSchema4NumberSchema extends JSONSchema4Base {
440456
/**
441457
* @see https://json-schema.org/understanding-json-schema/reference/boolean.html
442458
*/
443-
export interface JSONSchema4BoleanSchema extends JSONSchema4Base {
459+
export interface JSONSchema4BooleanSchema extends JSONSchema4Base {
444460
type: 'boolean';
445461

446462
/**

0 commit comments

Comments
 (0)