Skip to content

Commit b846fbb

Browse files
Merge pull request #26 from kaleido-io/fix-ffischema
Fix Ethereum FFIParamValidator to allow oneOf syntax for basic types
2 parents 898ef39 + 22bb1ca commit b846fbb

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

pkg/ffi2abi/ffi_param_validator.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ var compiledMetaSchema = jsonschema.MustCompileString("ffiParamDetails.json", `{
4141
}
4242
},
4343
"required": [
44+
"type",
45+
"details"
46+
]
47+
},
48+
{
49+
"type": "object",
50+
"properties": {
51+
"oneOf": {
52+
"type": "array"
53+
},
54+
"details": {
55+
"$ref": "#/$defs/details"
56+
}
57+
},
58+
"required": [
59+
"oneOf",
4460
"details"
4561
]
4662
},
@@ -63,8 +79,8 @@ var compiledMetaSchema = jsonschema.MustCompileString("ffiParamDetails.json", `{
6379
}
6480
},
6581
"required": [
66-
"details",
67-
"type"
82+
"type",
83+
"details"
6884
]
6985
}
7086
]
@@ -85,6 +101,22 @@ var compiledMetaSchema = jsonschema.MustCompileString("ffiParamDetails.json", `{
85101
}
86102
},
87103
"required": [
104+
"type",
105+
"details"
106+
]
107+
},
108+
{
109+
"type": "object",
110+
"properties": {
111+
"oneOf": {
112+
"type": "array"
113+
},
114+
"details": {
115+
"$ref": "#/$defs/objectFieldDetails"
116+
}
117+
},
118+
"required": [
119+
"oneOf",
88120
"details"
89121
]
90122
},
@@ -107,6 +139,7 @@ var compiledMetaSchema = jsonschema.MustCompileString("ffiParamDetails.json", `{
107139
}
108140
},
109141
"required": [
142+
"type",
110143
"details"
111144
]
112145
}

pkg/ffi2abi/ffi_param_validator_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,32 @@ func TestInputFixedArraySizeType(t *testing.T) {
318318
}`)
319319
assert.NoError(t, err)
320320
}
321+
322+
func TestOneOfSyntax(t *testing.T) {
323+
_, err := NewTestSchema(`{
324+
"type": "object",
325+
"details": {
326+
"type": "tuple",
327+
"internalType": "struct Custom.Thing"
328+
},
329+
"properties": {
330+
"customProp": {
331+
"oneOf": [
332+
{
333+
"type": "string"
334+
},
335+
{
336+
"type": "integer"
337+
}
338+
],
339+
"details": {
340+
"type": "uint256",
341+
"internalType": "uint256",
342+
"index": 0
343+
},
344+
"description": "An integer. You are recommended to use a JSON string. A JSON number can be used for values up to the safe maximum."
345+
}
346+
}
347+
}`)
348+
assert.NoError(t, err)
349+
}

0 commit comments

Comments
 (0)