Skip to content

Commit

Permalink
fix(utils): add to JSONSchema4Type missing Array and Object (#7406)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wespickett committed Aug 10, 2023
1 parent 49a53f0 commit 60df0bb
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions packages/utils/src/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ export type JSONSchema4TypeName =
*/
export type JSONSchema4Type = boolean | number | string | null;

export type JSONSchema4TypeExtended =
| JSONSchema4Type
| JSONSchema4Array
| JSONSchema4Object;

// Workaround for infinite type recursion
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
export interface JSONSchema4Object {
[key: string]: JSONSchema4TypeExtended;
}

// Workaround for infinite type recursion
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface JSONSchema4Array extends Array<JSONSchema4TypeExtended> {}

/**
* Meta schema
*
Expand All @@ -51,7 +67,7 @@ export type JSONSchema4 =
| JSONSchema4AnyOfSchema
| JSONSchema4AnySchema
| JSONSchema4ArraySchema
| JSONSchema4BoleanSchema
| JSONSchema4BooleanSchema
| JSONSchema4MultiSchema
| JSONSchema4NullSchema
| JSONSchema4NumberSchema
Expand Down Expand Up @@ -133,7 +149,7 @@ interface JSONSchema4Base {
/**
* The default value for the item if not present
*/
default?: JSONSchema4Type | undefined;
default?: JSONSchema4TypeExtended | undefined;

/**
* This attribute indicates if the instance must have a value, and not
Expand Down Expand Up @@ -187,7 +203,7 @@ export interface JSONSchema4MultiSchema
Omit<JSONSchema4ArraySchema, 'enum' | 'type'>,
Omit<JSONSchema4StringSchema, 'enum' | 'type'>,
Omit<JSONSchema4NumberSchema, 'enum' | 'type'>,
Omit<JSONSchema4BoleanSchema, 'enum' | 'type'>,
Omit<JSONSchema4BooleanSchema, 'enum' | 'type'>,
Omit<JSONSchema4NullSchema, 'enum' | 'type'>,
Omit<JSONSchema4AnySchema, 'enum' | 'type'> {
type: JSONSchema4TypeName[];
Expand Down Expand Up @@ -440,7 +456,7 @@ export interface JSONSchema4NumberSchema extends JSONSchema4Base {
/**
* @see https://json-schema.org/understanding-json-schema/reference/boolean.html
*/
export interface JSONSchema4BoleanSchema extends JSONSchema4Base {
export interface JSONSchema4BooleanSchema extends JSONSchema4Base {
type: 'boolean';

/**
Expand Down

0 comments on commit 60df0bb

Please sign in to comment.