haveapi-go-client 0.14.2 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd022bb61d9864f5530163e06f9d7200db731c96bb5ad53b166bd8725690ccc3
4
- data.tar.gz: 2dfb02315a842f2b6297e981cf66e7d4fb63b8c61f225e6531f895050b1c85d5
3
+ metadata.gz: 6f45b75cf1d53b1fefed6ae5c7e52f92a19451b44e8f9b0a0cd20489d005a9d5
4
+ data.tar.gz: 441f58911322190ab9ff6feca02ab982e7e89b6e86df01034355a80cd3d749d7
5
5
  SHA512:
6
- metadata.gz: a1011921f6145ecc8b7956db1b80f17b877876731f185f20721d2fbe59a13c8b5071d112d7207a00fdc5e038ce72b596c4b12c04fb520638e35d08039e2c3837
7
- data.tar.gz: 39d9b7d30e151d1358693f6e9a6789e229986c78ea15ab1f66ac22fd20c3e7eefc0acaa5a62d95cffaea9d8e0d1bbce45cfe8f1759dcff166a096144d8eb0492
6
+ metadata.gz: 3f48a30555cec73de5a1fa65058a625030990bc93cf736220c128ccaf1841e694050d0093e5273a90692d3de2f3ba908c740482bc1ec390f355818cd87463f2e
7
+ data.tar.gz: '005849f0eea33021ee883a233a8198a596f863e738111be2376c8cfad24c61c59621b181348cf80afa32de6a1342f8062bdafd094a101118ab17d02155f71677'
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler'
22
22
  spec.add_development_dependency 'rake'
23
23
 
24
- spec.add_runtime_dependency 'haveapi-client', '~> 0.14.2'
24
+ spec.add_runtime_dependency 'haveapi-client', '~> 0.16.0'
25
25
  end
@@ -113,6 +113,10 @@ module HaveAPI::GoClient
113
113
  metadata && metadata.resolve_associations
114
114
  end
115
115
 
116
+ def <=>(other)
117
+ go_name <=> other.go_name
118
+ end
119
+
116
120
  protected
117
121
  attr_reader :prefix
118
122
 
@@ -10,11 +10,16 @@ module HaveAPI::GoClient
10
10
  attr_reader :resources
11
11
 
12
12
  def initialize(desc)
13
- @resources = desc[:resources].map { |k, v| Resource.new(self, k, v) }
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
@@ -34,6 +34,7 @@ module HaveAPI::GoClient
34
34
 
35
35
  g = Generator.new(ARGV[0], ARGV[1], options)
36
36
  g.generate
37
+ g.go_fmt
37
38
  end
38
39
  end
39
40
  end
@@ -59,6 +59,12 @@ module HaveAPI::GoClient
59
59
  api.auth_methods.each { |v| v.generate(self) }
60
60
  end
61
61
 
62
+ def go_fmt
63
+ unless system('go', 'fmt', chdir: dst)
64
+ fail "go fmt failed"
65
+ end
66
+ end
67
+
62
68
  protected
63
69
  attr_reader :api
64
70
  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
@@ -55,6 +55,14 @@ module HaveAPI::GoClient
55
55
  @desc = nil
56
56
  end
57
57
 
58
+ def nillable?
59
+ false
60
+ end
61
+
62
+ def <=>(other)
63
+ go_name <=> other
64
+ end
65
+
58
66
  protected
59
67
  # @return [Hash]
60
68
  attr_reader :desc
@@ -10,6 +10,10 @@ module HaveAPI::GoClient
10
10
  # @return [Parameters::Association]
11
11
  attr_reader :association
12
12
 
13
+ def nillable?
14
+ true
15
+ end
16
+
13
17
  protected
14
18
  def do_resolve
15
19
  @association = Parameters::Association.new(self, desc)
@@ -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 { |k, v| Resource.new(self, k, v) }
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
 
@@ -1,5 +1,5 @@
1
1
  module HaveAPI
2
2
  module GoClient
3
- VERSION = '0.14.2'
3
+ VERSION = '0.16.0'
4
4
  end
5
5
  end
@@ -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.14.2
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.14.2
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.14.2
54
+ version: 0.16.0
55
55
  description: Go client generator
56
56
  email:
57
57
  - jakub.skokan@vpsfree.cz