diff --git a/CHANGELOG.md b/CHANGELOG.md index dcedf476330..873afc8c4ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2477,3 +2477,4 @@ If there are any bugs, improvements, optimizations or any new feature proposal f #### web3-validator +- The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. (#6981) \ No newline at end of file diff --git a/packages/web3-validator/CHANGELOG.md b/packages/web3-validator/CHANGELOG.md index 07ba353112d..dc5834852ca 100644 --- a/packages/web3-validator/CHANGELOG.md +++ b/packages/web3-validator/CHANGELOG.md @@ -172,4 +172,4 @@ Documentation: ### Fixed -- Nodejs Buffer is not recognized as valid bytes value +- The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. diff --git a/packages/web3-validator/src/utils.ts b/packages/web3-validator/src/utils.ts index 36a65e3f122..6f9fd6f7f55 100644 --- a/packages/web3-validator/src/utils.ts +++ b/packages/web3-validator/src/utils.ts @@ -141,7 +141,7 @@ export const abiSchemaToJsonSchema = ( // e.g. {name: 'a', type: 'uint'} if (isAbiParameterSchema(abi)) { abiType = abi.type; - abiName = abi.name; + abiName = abi.name || `${level}/${index}`; abiComponents = abi.components as FullValidationSchema; // If its short form string value e.g. ['uint'] } else if (typeof abi === 'string') { diff --git a/packages/web3-validator/test/fixtures/abi_to_json_schema.ts b/packages/web3-validator/test/fixtures/abi_to_json_schema.ts index 35ed35bce6f..e9e4391700c 100644 --- a/packages/web3-validator/test/fixtures/abi_to_json_schema.ts +++ b/packages/web3-validator/test/fixtures/abi_to_json_schema.ts @@ -157,6 +157,40 @@ const abiToJsonSchemaCases: AbiToJsonSchemaCase[] = [ }, }, + // this is for public mappings case where the abi has no name + { + title: 'multiple params of different types without name', + abi: { + fullSchema: [ + { name: '', type: 'uint' }, + { name: '', type: 'int' }, + ], + shortSchema: ['uint', 'int'], + data: [12, -1], + }, + json: { + fullSchema: { + type: 'array', + items: [ + { $id: '/0/0', format: 'uint', required: true }, + { $id: '/0/1', format: 'int', required: true }, + ], + minItems: 2, + maxItems: 2, + }, + shortSchema: { + type: 'array', + items: [ + { $id: '/0/0', format: 'uint', required: true }, + { $id: '/0/1', format: 'int', required: true }, + ], + minItems: 2, + maxItems: 2, + }, + data: [12, -1], + }, + }, + { title: 'single param array', abi: {