diff --git a/dsl/attribute.go b/dsl/attribute.go index 75f7408701..ba4adce7ae 100644 --- a/dsl/attribute.go +++ b/dsl/attribute.go @@ -229,13 +229,13 @@ func OneOf(name string, args ...any) { } fn, ok := args[len(args)-1].(func()) if !ok { - eval.ReportError("OneOf: last argument must be a function") + eval.InvalidArgError("function", args[len(args)-1]) } var desc string if len(args) > 1 { desc, ok = args[0].(string) if !ok { - eval.ReportError("OneOf: description must be a string") + eval.InvalidArgError("string", args[0]) } } Attribute(name, &expr.Union{TypeName: name}, desc, fn) diff --git a/eval/eval_test.go b/eval/eval_test.go index d74c0c33e1..bfda376449 100644 --- a/eval/eval_test.go +++ b/eval/eval_test.go @@ -20,6 +20,8 @@ func TestInvalidArgError(t *testing.T) { "ErrorName (int)": {func() { Type("name", func() { ErrorName(1, 2) }) }, "cannot use 2 (type int) as type name"}, "Example": {func() { Example(1, 2) }, "cannot use 1 (type int) as type summary (string)"}, "Headers": {func() { Headers(1) }, "cannot use 1 (type int) as type function"}, + "OneOf (function)": {func() { Type("name", func() { OneOf("name", "description", 1) }) }, "cannot use 1 (type int) as type function"}, + "OneOf (string)": {func() { Type("name", func() { OneOf("name", 1, func() {}) }) }, "cannot use 1 (type int) as type string"}, "Param": {func() { API("name", func() { HTTP(func() { Params(1) }) }) }, "cannot use 1 (type int) as type function"}, "Response": {func() { Service("s", func() { HTTP(func() { Response(1) }) }) }, "cannot use 1 (type int) as type name of error"}, "ResultType": {func() { ResultType("identifier", 1) }, "cannot use 1 (type int) as type function or string"},