haveapi-go-client 0.14.2 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/haveapi-go-client.gemspec +1 -1
- data/lib/haveapi/go_client/action.rb +4 -0
- data/lib/haveapi/go_client/api_version.rb +6 -1
- data/lib/haveapi/go_client/cli.rb +1 -0
- data/lib/haveapi/go_client/generator.rb +6 -0
- data/lib/haveapi/go_client/input_output.rb +1 -1
- data/lib/haveapi/go_client/parameters/base.rb +8 -0
- data/lib/haveapi/go_client/parameters/resource.rb +4 -0
- data/lib/haveapi/go_client/resource.rb +8 -2
- data/lib/haveapi/go_client/version.rb +1 -1
- data/template/action.go.erb +93 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f45b75cf1d53b1fefed6ae5c7e52f92a19451b44e8f9b0a0cd20489d005a9d5
|
4
|
+
data.tar.gz: 441f58911322190ab9ff6feca02ab982e7e89b6e86df01034355a80cd3d749d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f48a30555cec73de5a1fa65058a625030990bc93cf736220c128ccaf1841e694050d0093e5273a90692d3de2f3ba908c740482bc1ec390f355818cd87463f2e
|
7
|
+
data.tar.gz: '005849f0eea33021ee883a233a8198a596f863e738111be2376c8cfad24c61c59621b181348cf80afa32de6a1342f8062bdafd094a101118ab17d02155f71677'
|
data/haveapi-go-client.gemspec
CHANGED
@@ -10,11 +10,16 @@ module HaveAPI::GoClient
|
|
10
10
|
attr_reader :resources
|
11
11
|
|
12
12
|
def initialize(desc)
|
13
|
-
@resources = desc[:resources].map
|
13
|
+
@resources = desc[:resources].map do |k, v|
|
14
|
+
Resource.new(self, k, v)
|
15
|
+
end.sort!
|
16
|
+
|
14
17
|
@resources.each { |r| r.resolve_associations }
|
18
|
+
|
15
19
|
@auth_methods = desc[:authentication].map do |k, v|
|
16
20
|
AuthenticationMethods.new(self, k, v)
|
17
21
|
end
|
22
|
+
|
18
23
|
@metadata_namespace = desc[:meta][:namespace]
|
19
24
|
end
|
20
25
|
end
|
@@ -36,7 +36,7 @@ module HaveAPI::GoClient
|
|
36
36
|
@namespace = desc[:namespace]
|
37
37
|
@parameters = desc[:parameters].map do |k, v|
|
38
38
|
Parameter.new(role, direction, self, k.to_s, v)
|
39
|
-
end.compact
|
39
|
+
end.compact.sort!
|
40
40
|
@go_type = action.go_type + (prefix ? prefix : '') + direction.to_s.capitalize
|
41
41
|
@go_namespace = camelize(desc[:namespace])
|
42
42
|
end
|
@@ -44,10 +44,12 @@ module HaveAPI::GoClient
|
|
44
44
|
@full_dot_name = resource_path.map(&:name).map(&:capitalize).join('.')
|
45
45
|
@go_name = camelize(name)
|
46
46
|
@go_type = full_go_type
|
47
|
-
@resources = desc[:resources].map
|
47
|
+
@resources = desc[:resources].map do |k, v|
|
48
|
+
Resource.new(self, k, v)
|
49
|
+
end.sort!
|
48
50
|
@actions = desc[:actions].map do |k, v|
|
49
51
|
Action.new(self, k.to_s, v, prefix: prefix)
|
50
|
-
end
|
52
|
+
end.sort!
|
51
53
|
end
|
52
54
|
|
53
55
|
# @return [ApiVersion]
|
@@ -104,6 +106,10 @@ module HaveAPI::GoClient
|
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
109
|
+
def <=>(other)
|
110
|
+
go_name <=> other.go_name
|
111
|
+
end
|
112
|
+
|
107
113
|
protected
|
108
114
|
attr_reader :prefix
|
109
115
|
|
data/template/action.go.erb
CHANGED
@@ -26,6 +26,8 @@ type <%= action.metadata.global.input.go_type %> struct {
|
|
26
26
|
<% end -%>
|
27
27
|
// Only selected parameters are sent to the API. Ignored if empty.
|
28
28
|
_selectedParameters map[string]interface{}
|
29
|
+
// Parameters that are set to nil instead of value
|
30
|
+
_nilParameters map[string]interface{}
|
29
31
|
}
|
30
32
|
|
31
33
|
<% action.metadata.global.input.parameters.each do |p| -%>
|
@@ -37,9 +39,32 @@ func (in *<%= action.metadata.global.input.go_type %>) Set<%= p.go_name %>(value
|
|
37
39
|
in._selectedParameters = make(map[string]interface{})
|
38
40
|
}
|
39
41
|
|
42
|
+
<% if p.nillable? -%>
|
43
|
+
in.Set<%= p.go_name %>Nil(false)
|
44
|
+
<% end -%>
|
40
45
|
in._selectedParameters["<%= p.go_name %>"] = nil
|
41
46
|
return in
|
42
47
|
}
|
48
|
+
<% if p.nillable? -%>
|
49
|
+
|
50
|
+
// Set<%= p.go_name %>Nil sets parameter <%= p.go_name %> to nil and selects it for sending
|
51
|
+
func (in *<%= action.metadata.global.input.go_type %>) Set<%= p.go_name %>Nil(set bool) *<%= action.metadata.global.input.go_type %> {
|
52
|
+
if in._nilParameters == nil {
|
53
|
+
if !set {
|
54
|
+
return in
|
55
|
+
}
|
56
|
+
in._nilParameters = make(map[string]interface{})
|
57
|
+
}
|
58
|
+
|
59
|
+
if set {
|
60
|
+
in._nilParameters["<%= p.go_name %>"] = nil
|
61
|
+
in.SelectParameters("<%= p.go_name %>")
|
62
|
+
} else {
|
63
|
+
delete(in._nilParameters, "<%= p.go_name %>")
|
64
|
+
}
|
65
|
+
return in
|
66
|
+
}
|
67
|
+
<% end -%>
|
43
68
|
<% end -%>
|
44
69
|
|
45
70
|
// SelectParameters sets parameters from <%= action.metadata.global.input.go_type %>
|
@@ -74,6 +99,8 @@ type <%= action.input.go_type %> struct {
|
|
74
99
|
<% end -%>
|
75
100
|
// Only selected parameters are sent to the API. Ignored if empty.
|
76
101
|
_selectedParameters map[string]interface{}
|
102
|
+
// Parameters that are set to nil instead of value
|
103
|
+
_nilParameters map[string]interface{}
|
77
104
|
}
|
78
105
|
|
79
106
|
<% action.input.parameters.each do |p| -%>
|
@@ -85,9 +112,32 @@ func (in *<%= action.input.go_type %>) Set<%= p.go_name %>(value <%= p.go_in_typ
|
|
85
112
|
in._selectedParameters = make(map[string]interface{})
|
86
113
|
}
|
87
114
|
|
115
|
+
<% if p.nillable? -%>
|
116
|
+
in.Set<%= p.go_name %>Nil(false)
|
117
|
+
<% end -%>
|
88
118
|
in._selectedParameters["<%= p.go_name %>"] = nil
|
89
119
|
return in
|
90
120
|
}
|
121
|
+
<% if p.nillable? -%>
|
122
|
+
|
123
|
+
// Set<%= p.go_name %>Nil sets parameter <%= p.go_name %> to nil and selects it for sending
|
124
|
+
func (in *<%= action.input.go_type %>) Set<%= p.go_name %>Nil(set bool) *<%= action.input.go_type %> {
|
125
|
+
if in._nilParameters == nil {
|
126
|
+
if !set {
|
127
|
+
return in
|
128
|
+
}
|
129
|
+
in._nilParameters = make(map[string]interface{})
|
130
|
+
}
|
131
|
+
|
132
|
+
if set {
|
133
|
+
in._nilParameters["<%= p.go_name %>"] = nil
|
134
|
+
in.SelectParameters("<%= p.go_name %>")
|
135
|
+
} else {
|
136
|
+
delete(in._nilParameters, "<%= p.go_name %>")
|
137
|
+
}
|
138
|
+
return in
|
139
|
+
}
|
140
|
+
<% end -%>
|
91
141
|
<% end -%>
|
92
142
|
|
93
143
|
// SelectParameters sets parameters from <%= action.input.go_type %>
|
@@ -105,6 +155,21 @@ func (in *<%= action.input.go_type %>) SelectParameters(params ...string) *<%= a
|
|
105
155
|
return in
|
106
156
|
}
|
107
157
|
|
158
|
+
// UnselectParameters unsets parameters from <%= action.input.go_type %>
|
159
|
+
// that will be sent to the API.
|
160
|
+
// UnsSelectParameters can be called multiple times.
|
161
|
+
func (in *<%= action.input.go_type %>) UnselectParameters(params ...string) *<%= action.input.go_type %> {
|
162
|
+
if in._selectedParameters == nil {
|
163
|
+
return in
|
164
|
+
}
|
165
|
+
|
166
|
+
for _, param := range params {
|
167
|
+
delete(in._selectedParameters, param)
|
168
|
+
}
|
169
|
+
|
170
|
+
return in
|
171
|
+
}
|
172
|
+
|
108
173
|
func (in *<%= action.input.go_type %>) AnySelected() bool {
|
109
174
|
if in._selectedParameters == nil {
|
110
175
|
return false
|
@@ -254,6 +319,16 @@ func (inv *<%= action.go_invocation_type %>) IsParameterSelected(param string) b
|
|
254
319
|
_, exists := inv.Input._selectedParameters[param]
|
255
320
|
return exists
|
256
321
|
}
|
322
|
+
|
323
|
+
// IsParameterNil returns true if param is to be sent to the API as nil
|
324
|
+
func (inv *<%= action.go_invocation_type %>) IsParameterNil(param string) bool {
|
325
|
+
if inv.Input._nilParameters == nil {
|
326
|
+
return false
|
327
|
+
}
|
328
|
+
|
329
|
+
_, exists := inv.Input._nilParameters[param]
|
330
|
+
return exists
|
331
|
+
}
|
257
332
|
<% end -%>
|
258
333
|
<% if action.metadata.has_global_input? -%>
|
259
334
|
// NewMetaInput returns a new struct for global meta input parameters and sets
|
@@ -278,6 +353,16 @@ func (inv *<%= action.go_invocation_type %>) IsMetaParameterSelected(param strin
|
|
278
353
|
_, exists := inv.MetaInput._selectedParameters[param]
|
279
354
|
return exists
|
280
355
|
}
|
356
|
+
|
357
|
+
// IsMetaParameterNil returns true if global meta param is to be sent to the API as nil
|
358
|
+
func (inv *<%= action.go_invocation_type %>) IsMetaParameterNil(param string) bool {
|
359
|
+
if inv.MetaInput._nilParameters == nil {
|
360
|
+
return false
|
361
|
+
}
|
362
|
+
|
363
|
+
_, exists := inv.MetaInput._nilParameters[param]
|
364
|
+
return exists
|
365
|
+
}
|
281
366
|
<% end -%>
|
282
367
|
|
283
368
|
// Call() invokes the action and returns a response from the API server
|
@@ -448,7 +533,15 @@ func (inv *<%= action.go_invocation_type %>) makeInputParams() map[string]interf
|
|
448
533
|
if inv.Input != nil {
|
449
534
|
<% action.input.parameters.each do |p| -%>
|
450
535
|
if inv.IsParameterSelected("<%= p.go_name %>") {
|
536
|
+
<% if p.nillable? -%>
|
537
|
+
if inv.IsParameterNil("<%= p.go_name %>") {
|
538
|
+
ret["<%= p.name %>"] = nil
|
539
|
+
} else {
|
540
|
+
ret["<%= p.name %>"] = inv.Input.<%= p.go_name %>
|
541
|
+
}
|
542
|
+
<% else -%>
|
451
543
|
ret["<%= p.name %>"] = inv.Input.<%= p.go_name %>
|
544
|
+
<% end -%>
|
452
545
|
}
|
453
546
|
<% end -%>
|
454
547
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haveapi-go-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Skokan
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.16.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.16.0
|
55
55
|
description: Go client generator
|
56
56
|
email:
|
57
57
|
- jakub.skokan@vpsfree.cz
|