Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use eval.InvalidArgError() to dsl.OneOf() #3624

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dsl/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
Loading