aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2026-01-20 20:20:12 +0100
committerDmitry Vyukov <dvyukov@google.com>2026-01-21 13:38:45 +0000
commit6e304df8df70bfaecd0ff91478acda0e9177f030 (patch)
treec46356f0b9b1936ef19857d1efdf631e5b55f361 /pkg
parente477616cc03edfcd82015477fada8dcab6760cee (diff)
pkg/aflow: support for optional tool args
Diffstat (limited to 'pkg')
-rw-r--r--pkg/aflow/schema.go5
-rw-r--r--pkg/aflow/schema_test.go12
2 files changed, 15 insertions, 2 deletions
diff --git a/pkg/aflow/schema.go b/pkg/aflow/schema.go
index a563a4bdf..855bfc303 100644
--- a/pkg/aflow/schema.go
+++ b/pkg/aflow/schema.go
@@ -9,6 +9,7 @@ import (
"iter"
"maps"
"reflect"
+ "strings"
"github.com/google/jsonschema-go/jsonschema"
)
@@ -81,6 +82,10 @@ func convertFromMap[T any](m map[string]any, strict, tool bool) (T, error) {
for name, field := range foreachField(&val) {
f, ok := m[name]
if !ok {
+ fieldType, _ := reflect.TypeFor[T]().FieldByName(name)
+ if strings.Contains(fieldType.Tag.Get("json"), ",omitempty") {
+ continue
+ }
if tool {
return val, BadCallError(fmt.Sprintf("missing argument %q", name))
} else {
diff --git a/pkg/aflow/schema_test.go b/pkg/aflow/schema_test.go
index b5ed1062f..5adef3776 100644
--- a/pkg/aflow/schema_test.go
+++ b/pkg/aflow/schema_test.go
@@ -79,10 +79,10 @@ func TestConvertFromMap(t *testing.T) {
testConvertFromMap(t, true, map[string]any{
"I1": 2.0,
}, struct {
- I0 int
+ I0 int `json:"I0"`
}{},
`missing argument "I0"`,
- `field "I0" is not present when converting map to struct { I0 int }`)
+ `field "I0" is not present when converting map to struct { I0 int "json:\"I0\"" }`)
testConvertFromMap(t, true, map[string]any{
"I0": "foo",
@@ -108,6 +108,14 @@ func TestConvertFromMap(t *testing.T) {
}{},
`unused fields when converting map to struct { I0 int }: map[I1:2]`,
`unused fields when converting map to struct { I0 int }: map[I1:2]`)
+
+ testConvertFromMap(t, false, map[string]any{
+ "I1": 2.0,
+ }, struct {
+ I0 int `json:",omitempty"`
+ }{},
+ ``,
+ ``)
}
func testConvertFromMap[T any](t *testing.T, strict bool, input map[string]any, output T, toolErr, nonToolErr string) {