haveapi-go-client 0.31.1 → 0.31.2

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: 2db2499a0d0a8c758e9da6ee9c29a409636de10a81ee9e924d06cc7fe1065106
4
- data.tar.gz: 94888154a8e97d91387f193d26213a7f5d818fc0d2d4ab176c8462f46b8162a7
3
+ metadata.gz: 8173f3bbbff07f213ebe0a81f076d61d5ebb226fcdabdca72fa2ed2ccb451948
4
+ data.tar.gz: 341ec4463fe3db550a8a3845bd0669932cb66034a1a1c002fb2827b492d9b10b
5
5
  SHA512:
6
- metadata.gz: 0371616532eaf5a1d46740a2b2a843e29a54a7fd08c51f7857923d4cae55c7b77962fae3653759d395e6a0f361adabf6c25cf7b6767184e27143380b35875f18
7
- data.tar.gz: 6c5c5e06b8982e7796b8625bcc86edd411a45c4a2e6650878697beb3cda7839f1aee02e0b32bc5c81f701f70c0f3ca7e12e0e85522399b1b141a56737a489319
6
+ metadata.gz: b59d736fd2b7aa75454498871139641bfe6afcfaf413aaeb04a649d0cbb257ba2a0f19b68291e3b9d4a2bad3bded1271db812ccdac2caf08df2ad4c8eb166c06
7
+ data.tar.gz: 5eb842814c531bb8d0a230d210217ad37dc09aa842bd6a8867f82bf6bb13ac91a3ad9a615bf98b9d0cae6c2891452f1d0f77ac1a36187ef8295b2127f81377c3
@@ -18,5 +18,5 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'haveapi-client', '~> 0.31.1'
21
+ spec.add_dependency 'haveapi-client', '~> 0.31.2'
22
22
  end
@@ -411,7 +411,8 @@ module HaveAPI::GoClient
411
411
  when :basic
412
412
  ['api.SetBasicAuthentication(os.Getenv("HAVEAPI_USER"), os.Getenv("HAVEAPI_PASSWORD"))']
413
413
  when :token
414
- unless saved[:http_header] == visible[:http_header] && saved[:query_parameter] == visible[:query_parameter]
414
+ unless same_transport_name?(saved[:http_header], visible[:http_header]) &&
415
+ same_transport_name?(saved[:query_parameter], visible[:query_parameter])
415
416
  unsupported!('This authentication method does not match the configured Go SDK.')
416
417
  end
417
418
  ['api.SetExistingTokenAuth(os.Getenv("HAVEAPI_TOKEN"))',
@@ -428,6 +429,11 @@ module HaveAPI::GoClient
428
429
  code(program(context, ['os'], lines))
429
430
  end
430
431
 
432
+ def same_transport_name?(saved, visible)
433
+ # Automatic profiles copy Symbol names through JSON as Strings.
434
+ [saved, visible].all? { |name| name.is_a?(String) || name.is_a?(Symbol) } && saved.to_s == visible.to_s
435
+ end
436
+
431
437
  def program(context, imports, lines)
432
438
  # Saved server routes already include the mount root and /vVERSION.
433
439
  origin = URI.parse(context.base_url)
@@ -1,5 +1,5 @@
1
1
  module HaveAPI
2
2
  module GoClient
3
- VERSION = '0.31.1'.freeze
3
+ VERSION = '0.31.2'.freeze
4
4
  end
5
5
  end
@@ -22,6 +22,13 @@ class GoDocumentationProfileCheck
22
22
  privileged_description = FIXTURE.description(server, user: :privileged)
23
23
  context = FIXTURE.context(public_description)
24
24
  adapter = profile.adapter
25
+ saved_token = adapter.instance_variable_get(:@description).dig(:authentication, :token)
26
+ visible_token = public_description.fetch(:authentication).fetch(:token)
27
+ assert(saved_token.fetch(:query_parameter) == '_auth_token', 'automatic profile must capture the JSON String query name')
28
+ assert(visible_token.fetch(:query_parameter) == :_auth_token, 'live token provider must retain its Symbol query name')
29
+ token_example = adapter.render(kind: :auth, context:, mode: :sync, auth_method: :token, auth_description: visible_token)
30
+ assert(token_example[:status] == :code, "unexpected token limitation: #{token_example[:reason]}")
31
+ assert(token_example.fetch(:code).include?('api.SetExistingTokenAuth(os.Getenv("HAVEAPI_TOKEN"))'), 'matching token transport must render environment-token code')
25
32
  structural = adapter.instance_variable_get(:@description).dig(:resources, :set_timeout_resource, :resources, :child, :actions, :client)
26
33
  assert(!structural.has_key?(:examples), 'the private model must not retain example payloads')
27
34
  assert(!structural.dig(:input, :parameters, :private_value).has_key?(:default), 'the private model must not retain parameter defaults')
@@ -2,6 +2,8 @@
2
2
  module GoDocumentationProfileFixture
3
3
  HOSTILE = "quote\"\\\n雪</script>".freeze
4
4
 
5
+ class TokenConfig < HaveAPI::Authentication::Token::Config; end
6
+
5
7
  module Resources
6
8
  class Owner < HaveAPI::Resource
7
9
  version '7'
@@ -101,6 +103,7 @@ module GoDocumentationProfileFixture
101
103
  server = HaveAPI::Server.new(Resources)
102
104
  server.use_version('7')
103
105
  server.default_version = '7'
106
+ server.auth_chain << HaveAPI::Authentication::Token.with_config(TokenConfig)
104
107
  server.documentation_clients('7', go: { import_path: 'example.test/current-sdk/client', **go })
105
108
  server.mount('/mounted/')
106
109
  server
@@ -170,6 +170,62 @@ RSpec.describe HaveAPI::GoClient::Documentation do
170
170
  expect(adapter.render(kind: :auth, context:, mode: :sync, auth_method: :token, auth_description: {})).to include(status: :limitation)
171
171
  end
172
172
 
173
+ [[String, String], [Symbol, Symbol], [String, Symbol], [Symbol, String]].each do |saved_type, visible_type|
174
+ it "matches token transport names saved as #{saved_type} and visible as #{visible_type}" do
175
+ description[:authentication][:token].merge!(http_header: saved_type == String ? 'X-Token' : :'X-Token',
176
+ query_parameter: saved_type == String ? 'token' : :token)
177
+ adapter
178
+ context.description = Marshal.load(Marshal.dump(description))
179
+ context.description[:authentication][:token].merge!(http_header: visible_type == String ? 'X-Token' : :'X-Token',
180
+ query_parameter: visible_type == String ? 'token' : :token)
181
+
182
+ result = adapter.render(kind: :auth, context:, mode: :sync, auth_method: :token, auth_description: {})
183
+ expect(result[:status]).to eq(:code)
184
+ expect(result[:code]).to include('api.SetExistingTokenAuth(os.Getenv("HAVEAPI_TOKEN"))')
185
+ end
186
+ end
187
+
188
+ %i[http_header query_parameter].each do |field|
189
+ it "rejects a different token #{field} even when the other transport matches" do
190
+ adapter
191
+ context.description = Marshal.load(Marshal.dump(description))
192
+ context.description[:authentication][:token][field] = 'other'
193
+
194
+ expect(adapter.render(kind: :auth, context:, mode: :sync, auth_method: :token, auth_description: {})).to include(
195
+ status: :limitation, reason: 'This authentication method does not match the configured Go SDK.'
196
+ )
197
+ end
198
+
199
+ [nil, false, 7].each do |invalid|
200
+ it "rejects unsupported token #{field} values #{invalid.inspect} without coercion" do
201
+ [[invalid, invalid], [invalid, invalid.to_s], [invalid.to_s, invalid]].each do |saved, visible|
202
+ description[:authentication][:token][field] = saved
203
+ candidate = described_class.new(description:, import_path: 'example.test/sdk/client')
204
+ context.description = Marshal.load(Marshal.dump(description))
205
+ context.description[:authentication][:token][field] = visible
206
+
207
+ expect(candidate.render(kind: :auth, context:, mode: :sync, auth_method: :token, auth_description: {})).to include(
208
+ status: :limitation, reason: 'This authentication method does not match the configured Go SDK.'
209
+ )
210
+ end
211
+ end
212
+ end
213
+ end
214
+
215
+ %i[saved visible descriptor].each do |missing|
216
+ it "keeps token authentication unavailable without the #{missing} provider description" do
217
+ description[:authentication].delete(:token) if missing == :saved
218
+ adapter
219
+ context.description = Marshal.load(Marshal.dump(description))
220
+ context.description[:authentication][:token] = GoDocumentationFixture.token
221
+ context.description[:authentication].delete(:token) if missing == :visible
222
+
223
+ result = adapter.render(kind: :auth, context:, mode: :sync, auth_method: :token,
224
+ auth_description: missing == :descriptor ? nil : {})
225
+ expect(result).to include(status: :limitation, reason: 'This authentication method is unavailable in the configured Go SDK.')
226
+ end
227
+ end
228
+
173
229
  it 'does not show operation helpers when action-state visibility is absent' do
174
230
  action[:blocking] = true
175
231
  action[:meta][:global][:output] = GoDocumentationFixture.io({ action_state_id: { type: 'Integer' } }, namespace: false)
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.31.1
4
+ version: 0.31.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.31.1
18
+ version: 0.31.2
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 0.31.1
25
+ version: 0.31.2
26
26
  description: Go client generator
27
27
  email:
28
28
  - jakub.skokan@vpsfree.cz