File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -78,8 +78,10 @@ func (fi InputFile) Ast() *ast.File { return fi.Pkg.Syntax[fi.SyntaxIdx] }
78
78
type TypeAcceptor interface {
79
79
// Should return true if type is required to be serializable
80
80
Accepts (tspec * ast.TypeSpec ) bool
81
- // should return true if no more types are expected
81
+ // Should return true if no more types are expected
82
82
IsDrained () bool
83
+ // Should return true if acceptor has no type restrictions
84
+ AcceptsAll () bool
83
85
fmt.Stringer
84
86
}
85
87
@@ -88,7 +90,7 @@ func (fi InputFile) GetInputStructs(acceptor TypeAcceptor) ([]domain.InputStruct
88
90
if err != nil {
89
91
return nil , err
90
92
}
91
- if ! acceptor .IsDrained () {
93
+ if ! acceptor .IsDrained () && ! acceptor . AcceptsAll () {
92
94
return nil , fmt .Errorf ("types '%s' were requested but not found" , acceptor )
93
95
}
94
96
if len (structs ) == 0 {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import (
19
19
"fmt"
20
20
"go/ast"
21
21
22
+ "github.com/am4n0w4r/simser/internal/domain"
22
23
"golang.org/x/exp/maps"
23
24
)
24
25
@@ -30,6 +31,9 @@ func newTypeAcceptor(rawTypeList []string) (*typeAcceptor, error) {
30
31
}
31
32
st := map [string ]uint8 {}
32
33
for _ , v := range rawTypeList {
34
+ if v == "" {
35
+ return nil , errors .Join (domain .ErrUnsupportedType , errors .New ("empty type name in type list" ))
36
+ }
33
37
st [v ] = 0
34
38
}
35
39
return (* typeAcceptor )(& st ), nil
@@ -47,11 +51,12 @@ func (st *typeAcceptor) Accepts(ts *ast.TypeSpec) bool {
47
51
}
48
52
49
53
func (ts typeAcceptor ) IsDrained () bool {
50
- _ , hasAll := ts ["all" ]
51
- if len (ts ) == 1 && hasAll {
52
- return false
53
- }
54
54
return len (ts ) == 0
55
55
}
56
56
57
+ func (ta typeAcceptor ) AcceptsAll () bool {
58
+ _ , hasAll := ta ["all" ]
59
+ return len (ta ) == 1 && hasAll
60
+ }
61
+
57
62
func (ts typeAcceptor ) String () string { return fmt .Sprintf ("%s" , maps .Keys (ts )) }
You can’t perform that action at this time.
0 commit comments