Skip to content

Commit

Permalink
fix ABI to JSON scheme conversion handling of multi-dimensional arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
fullkomnun committed Sep 17, 2023
1 parent f5c45df commit 728ada0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/web3-validator/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,16 @@ export const abiSchemaToJsonSchema = (
delete childSchema.minItems;
}

lastSchema.items = childSchema;
// lastSchema.items is a Schema, concat with 'childSchema'
if (!Array.isArray(lastSchema.items)) {
lastSchema.items = [lastSchema.items as JsonSchema, childSchema];
} // lastSchema.items is an empty Scheme array, set it to 'childSchema'
else if (lastSchema.items.length === 0) {
lastSchema.items = childSchema;
} // lastSchema.items is a non-empty Scheme array, append 'childSchema'
else {
lastSchema.items.push(childSchema);
}
lastSchema = childSchema;
}

Expand Down Expand Up @@ -237,6 +246,7 @@ export const abiSchemaToJsonSchema = (
...convertEthType(abiType),
});
}
lastSchema = schema;
}

return schema;
Expand Down

0 comments on commit 728ada0

Please sign in to comment.