Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): add to JSONSchema4Type missing Array and Object #7406

Merged
merged 7 commits into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goodcatch

Spelling is hard 😅
Technically this is a breaking change but given it's a cock up I'm fine with doing this here. Given nobody noticed I doubt anyone is using it directly yet!

type: 'boolean';

/**
Expand Down