Skip to content

Commit

Permalink
clipped the recursion with a recursion limit of 10
Browse files Browse the repository at this point in the history
  • Loading branch information
catosaurusrex2003 committed Oct 22, 2024
1 parent 4253f29 commit 9b73e41
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions library/src/helpers/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,12 @@ export class SchemaHelpers {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private static jsonFieldToSchema(value: any): any {
private static jsonFieldToSchema(value: any, MAX_REC: number = 10): any {

Check failure on line 521 in library/src/helpers/schema.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Type number trivially inferred from a number literal, remove type annotation
// MAX_REC should never be passed as parameter.
// it is meant for internal recursion limit tracking
if (MAX_REC == 0) {
return {};
}
if (value === undefined || value === null) {
return {
type: 'string',
Expand All @@ -545,7 +550,7 @@ export class SchemaHelpers {
return {
type: 'array',
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
items: value.map((v) => this.jsonFieldToSchema(v)),
items: value.map((v) => this.jsonFieldToSchema(v, MAX_REC - 1)),
[this.extRenderAdditionalInfo]: false,
};
}
Expand All @@ -554,7 +559,7 @@ export class SchemaHelpers {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
properties: Object.entries(value).reduce(
(obj, [k, v]) => {
obj[k] = this.jsonFieldToSchema(v);
obj[k] = this.jsonFieldToSchema(v, MAX_REC - 1);
return obj;
},
{} as Record<string, unknown>,
Expand Down

0 comments on commit 9b73e41

Please sign in to comment.