From ca20de2e81f372fedde2e23f1ad55c5d9683dedd Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Sat, 10 Aug 2024 10:10:32 +0900 Subject: [PATCH] Add TooFewArgError to dsl.OneOf --- dsl/attribute.go | 4 ++++ eval/eval_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/dsl/attribute.go b/dsl/attribute.go index d6a7d3faf3..75f7408701 100644 --- a/dsl/attribute.go +++ b/dsl/attribute.go @@ -219,6 +219,10 @@ func Field(tag any, name string, args ...any) { // }) // }) func OneOf(name string, args ...any) { + if len(args) == 0 { + eval.TooFewArgError() + return + } if len(args) > 2 { eval.TooManyArgError() return diff --git a/eval/eval_test.go b/eval/eval_test.go index 14f91d87e7..d74c0c33e1 100644 --- a/eval/eval_test.go +++ b/eval/eval_test.go @@ -42,6 +42,7 @@ func TestTooFewArgError(t *testing.T) { "ErrorName": func() { ErrorName() }, "ErrorName (int)": func() { Type("name", func() { ErrorName(1) }) }, "Example": func() { Example() }, + "OneOf": func() { OneOf("name") }, "Response (grpc)": func() { Service("s", func() { GRPC(func() { Response("name") }) }) }, "Response (http)": func() { Service("s", func() { HTTP(func() { Response("name") }) }) }, }