File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,36 @@ func (d *Definition) Object(name string) (*Object, error) {
45
45
return nil , ErrNotFound
46
46
}
47
47
48
+ // ObjectIsInput gets whether this object is a method
49
+ // input (request) type or not.\
50
+ // Returns true if any method.InputObject.ObjectName matches
51
+ // name.
52
+ func (d * Definition ) ObjectIsInput (name string ) bool {
53
+ for _ , service := range d .Services {
54
+ for _ , method := range service .Methods {
55
+ if method .InputObject .ObjectName == name {
56
+ return true
57
+ }
58
+ }
59
+ }
60
+ return false
61
+ }
62
+
63
+ // ObjectIsOutput gets whether this object is a method
64
+ // output (response) type or not.
65
+ // Returns true if any method.OutputObject.ObjectName matches
66
+ // name.
67
+ func (d * Definition ) ObjectIsOutput (name string ) bool {
68
+ for _ , service := range d .Services {
69
+ for _ , method := range service .Methods {
70
+ if method .OutputObject .ObjectName == name {
71
+ return true
72
+ }
73
+ }
74
+ }
75
+ return false
76
+ }
77
+
48
78
// Service describes a service, akin to an interface in Go.
49
79
type Service struct {
50
80
Name string `json:"name"`
Original file line number Diff line number Diff line change @@ -208,3 +208,18 @@ func TestExtractCommentMetadata(t *testing.T) {
208
208
is .Equal (metadata ["required" ], true )
209
209
is .Equal (metadata ["monkey" ], float64 (24 ))
210
210
}
211
+
212
+ func TestObjectIsInputOutput (t * testing.T ) {
213
+ is := is .New (t )
214
+ patterns := []string {"./testdata/services/pleasantries" }
215
+ parser := New (patterns ... )
216
+ parser .Verbose = testing .Verbose ()
217
+ parser .ExcludeInterfaces = []string {"Ignorer" }
218
+ def , err := parser .Parse ()
219
+ is .NoErr (err )
220
+
221
+ is .Equal (def .ObjectIsInput ("GreetRequest" ), true )
222
+ is .Equal (def .ObjectIsInput ("GreetResponse" ), false )
223
+ is .Equal (def .ObjectIsOutput ("GreetRequest" ), false )
224
+ is .Equal (def .ObjectIsOutput ("GreetResponse" ), true )
225
+ }
You can’t perform that action at this time.
0 commit comments