haveapi-go-client 0.32.1 → 0.32.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 +4 -4
- data/docs/documentation.md +1 -1
- data/haveapi-go-client.gemspec +1 -1
- data/lib/haveapi/go_client/documentation.rb +75 -46
- data/lib/haveapi/go_client/version.rb +1 -1
- data/spec/unit/documentation_spec.rb +43 -4
- 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: 60282247e22a59813f4a2d5b312f1439636f1ef5f0bd2c4ed71a25d7773b2117
|
|
4
|
+
data.tar.gz: 68bf5c663a6b1a84a26647306c2fd1ee7fc06c92d87b9892871628d608d534c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 28e33ca5adabbaa97b5c1263e2fee22e1e0ba0132b74c912cdcbda33029a0190d189e1a183e3c1fa9df4f97e176c0b3bcb541c3acfeecea9ec1fd2ea7c53c966
|
|
7
|
+
data.tar.gz: c73fd6a38bcae1208eb174f137b42c286506685214acecdf123732030ab0edcd5cd3556d3dd4121ba5fa6b6ac02f1cc262f115daac791125bf4b5533252bb4fd
|
data/docs/documentation.md
CHANGED
|
@@ -47,7 +47,7 @@ are loaded during registration; automatic adapters are initialized at the end of
|
|
|
47
47
|
mount. No profiles are published when mount fails. HTML requests read no files,
|
|
48
48
|
fetch no descriptions and run no generator, compiler or formatter. Removing the
|
|
49
49
|
profile changes documentation availability without changing API wire behavior.
|
|
50
|
-
See the [server profile guide](../../../doc/client-examples.md) for configuration,
|
|
50
|
+
See the [server profile guide](../../../doc/en/client-examples.md) for configuration,
|
|
51
51
|
compatibility assumptions and rollback requirements.
|
|
52
52
|
|
|
53
53
|
## Mapping and supported samples
|
data/haveapi-go-client.gemspec
CHANGED
|
@@ -55,7 +55,7 @@ module HaveAPI::GoClient
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def render(kind:, context:, mode:, auth_method: nil, auth_description: nil)
|
|
58
|
-
return limitation('This Go API client example mode is unsupported.') unless mode == :sync
|
|
58
|
+
return limitation(documentation_message('generated.go.mode', context:, default: 'This Go API client example mode is unsupported.')) unless mode == :sync
|
|
59
59
|
|
|
60
60
|
case kind
|
|
61
61
|
when :init
|
|
@@ -65,10 +65,10 @@ module HaveAPI::GoClient
|
|
|
65
65
|
when :example
|
|
66
66
|
render_example(context)
|
|
67
67
|
else
|
|
68
|
-
limitation('This Go API client example is unavailable.')
|
|
68
|
+
limitation(documentation_message('generated.go.unavailable', context:, default: 'This Go API client example is unavailable.'))
|
|
69
69
|
end
|
|
70
70
|
rescue Unsupported => e
|
|
71
|
-
limitation(e.
|
|
71
|
+
limitation(documentation_message(e.key, context:, default: e.default, **e.values))
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def detail_levels_for(kind:, context:, result:, mode:, auth_method: nil, auth_description: nil)
|
|
@@ -83,7 +83,36 @@ module HaveAPI::GoClient
|
|
|
83
83
|
|
|
84
84
|
protected
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
def documentation_message(key, context:, default:, **values)
|
|
87
|
+
if context.respond_to?(:documentation_message)
|
|
88
|
+
context.documentation_message(key, default:, **values)
|
|
89
|
+
else
|
|
90
|
+
values.empty? ? default : format(default, values)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def example_comment(key, context:, default:, **values)
|
|
95
|
+
if context.respond_to?(:example_comment)
|
|
96
|
+
context.example_comment(key, default:, **values)
|
|
97
|
+
else
|
|
98
|
+
values.empty? ? default : format(default, values)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def comment_lines(text, prefix)
|
|
103
|
+
text.gsub(/\r\n?/, "\n").split("\n", -1).map { |line| "#{prefix}#{line}" }.join("\n")
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
class Unsupported < StandardError
|
|
107
|
+
attr_reader :key, :default, :values
|
|
108
|
+
|
|
109
|
+
def initialize(key, default:, **values)
|
|
110
|
+
@key = key
|
|
111
|
+
@default = default
|
|
112
|
+
@values = values
|
|
113
|
+
super(values.empty? ? default : format(default, values))
|
|
114
|
+
end
|
|
115
|
+
end
|
|
87
116
|
|
|
88
117
|
def validate_description
|
|
89
118
|
unless @description.is_a?(Hash) && @description[:authentication].is_a?(Hash) \
|
|
@@ -125,13 +154,13 @@ module HaveAPI::GoClient
|
|
|
125
154
|
def render_example(context)
|
|
126
155
|
resolved = resolve(resource_path: context.resource_path, action_name: context.action_name)
|
|
127
156
|
live = visible_action(context.description, context.resource_path, context.action_name)
|
|
128
|
-
unsupported!('This action is unavailable in the configured Go API client.') unless resolved && live && context.action
|
|
157
|
+
unsupported!('generated.go.action', default: 'This action is unavailable in the configured Go API client.') unless resolved && live && context.action
|
|
129
158
|
saved = resolved.description
|
|
130
159
|
check_action(saved, live)
|
|
131
160
|
check_action(saved, context.action)
|
|
132
161
|
sample = context.sample
|
|
133
162
|
unless sample.is_a?(Hash) && [true, false].include?(sample[:status])
|
|
134
|
-
unsupported!('This sample does not describe a structured request and response.')
|
|
163
|
+
unsupported!('generated.go.structured_sample', default: 'This sample does not describe a structured request and response.')
|
|
135
164
|
end
|
|
136
165
|
|
|
137
166
|
action = resolved.action
|
|
@@ -141,7 +170,7 @@ module HaveAPI::GoClient
|
|
|
141
170
|
lines = ["invocation := api.#{members.join('.')}.Prepare()"]
|
|
142
171
|
lines.concat(path_lines(action, sample))
|
|
143
172
|
lines.concat(input_lines(action, saved[:input], live[:input], sample))
|
|
144
|
-
lines.concat(metadata_lines(action, saved, live)) if context.detail == :thorough
|
|
173
|
+
lines.concat(metadata_lines(action, saved, live, context)) if context.detail == :thorough
|
|
145
174
|
lines.concat(call_lines(action, live, sample, context))
|
|
146
175
|
code(context.detail == :thorough ? program(context, ['fmt'], lines) : (lines + ['']).join("\n"))
|
|
147
176
|
end
|
|
@@ -149,18 +178,18 @@ module HaveAPI::GoClient
|
|
|
149
178
|
def check_action(saved, live)
|
|
150
179
|
unless saved[:method] == live[:method] && saved[:path] == live[:path] \
|
|
151
180
|
&& (saved[:blocking] == true) == (live[:blocking] == true)
|
|
152
|
-
unsupported!('The configured Go API client does not match this action route.')
|
|
181
|
+
unsupported!('generated.go.route', default: 'The configured Go API client does not match this action route.')
|
|
153
182
|
end
|
|
154
183
|
%i[input output].each do |direction|
|
|
155
184
|
left = saved[direction] || {}
|
|
156
185
|
right = live[direction] || {}
|
|
157
186
|
unless left[:layout].to_s == right[:layout].to_s && left[:namespace].to_s == right[:namespace].to_s
|
|
158
|
-
unsupported!('The configured Go API client does not match this action layout.')
|
|
187
|
+
unsupported!('generated.go.layout', default: 'The configured Go API client does not match this action layout.')
|
|
159
188
|
end
|
|
160
189
|
end
|
|
161
190
|
return unless [saved, live].any? { |description| required_metadata?(description) }
|
|
162
191
|
|
|
163
|
-
unsupported!('This action requires metadata that is absent from the sample.')
|
|
192
|
+
unsupported!('generated.go.metadata', default: 'This action requires metadata that is absent from the sample.')
|
|
164
193
|
end
|
|
165
194
|
|
|
166
195
|
def required_metadata?(description)
|
|
@@ -174,7 +203,7 @@ module HaveAPI::GoClient
|
|
|
174
203
|
return if !desc || (desc[:parameters] || {}).empty?
|
|
175
204
|
|
|
176
205
|
unless INPUT_LAYOUTS.include?(desc[:layout].to_s)
|
|
177
|
-
unsupported!('The Go generator does not support list input in documentation examples.')
|
|
206
|
+
unsupported!('generated.go.list_input', default: 'The Go generator does not support list input in documentation examples.')
|
|
178
207
|
end
|
|
179
208
|
check_parameters(action.input, desc, input: true)
|
|
180
209
|
end
|
|
@@ -182,20 +211,20 @@ module HaveAPI::GoClient
|
|
|
182
211
|
def check_output(action, desc, live, sample, context)
|
|
183
212
|
if !desc || (desc[:parameters] || {}).empty?
|
|
184
213
|
if sample[:status] && sample[:response] && ![{}, []].include?(sample[:response])
|
|
185
|
-
unsupported!('This response is unavailable in the configured Go API client.')
|
|
214
|
+
unsupported!('generated.go.response', default: 'This response is unavailable in the configured Go API client.')
|
|
186
215
|
end
|
|
187
216
|
return
|
|
188
217
|
end
|
|
189
218
|
|
|
190
219
|
unless OUTPUT_LAYOUTS.include?(desc[:layout].to_s)
|
|
191
|
-
unsupported!('The Go generator does not support this output layout.')
|
|
220
|
+
unsupported!('generated.go.output_layout', default: 'The Go generator does not support this output layout.')
|
|
192
221
|
end
|
|
193
222
|
check_parameters(action.output, desc, input: false)
|
|
194
223
|
return unless sample[:status] && sample.has_key?(:response) && !sample[:response].nil?
|
|
195
224
|
|
|
196
225
|
list = desc[:layout].to_s.end_with?('_list')
|
|
197
226
|
values = list ? sample[:response] : [sample[:response]]
|
|
198
|
-
unsupported!('This sample does not match the Go API client output layout.') unless values.is_a?(Array)
|
|
227
|
+
unsupported!('generated.go.sample_output_layout', default: 'This sample does not match the Go API client output layout.') unless values.is_a?(Array)
|
|
199
228
|
values.each_with_index do |value, index|
|
|
200
229
|
response_path = list ? "response[#{index}]" : 'response'
|
|
201
230
|
check_output_value(action.output, desc, live, value, context, response_path:)
|
|
@@ -205,37 +234,37 @@ module HaveAPI::GoClient
|
|
|
205
234
|
def check_parameters(io, desc, input:)
|
|
206
235
|
names = io ? io.parameters.map(&:name) : []
|
|
207
236
|
unless (desc[:parameters] || {}).keys.all? { |name| names.include?(name.to_s) }
|
|
208
|
-
unsupported!('The Go generator does not support Custom fields in this sample.')
|
|
237
|
+
unsupported!('generated.go.custom', default: 'The Go generator does not support Custom fields in this sample.')
|
|
209
238
|
end
|
|
210
239
|
members = io.parameters.map(&:go_name)
|
|
211
240
|
reserved = input ? INPUT_MEMBERS + members.map { |name| "Set#{name}" } + members.map { |name| "Set#{name}Nil" } : []
|
|
212
241
|
return unless members.uniq != members || members.intersect?(reserved)
|
|
213
242
|
|
|
214
|
-
unsupported!('The Go generator cannot represent these parameter name collisions.')
|
|
243
|
+
unsupported!('generated.go.name_collision', default: 'The Go generator cannot represent these parameter name collisions.')
|
|
215
244
|
end
|
|
216
245
|
|
|
217
246
|
def check_output_value(io, desc, live, value, context, response_path:)
|
|
218
|
-
unsupported!('This sample does not match the Go API client output layout.') unless value.is_a?(Hash)
|
|
247
|
+
unsupported!('generated.go.sample_output_layout', default: 'This sample does not match the Go API client output layout.') unless value.is_a?(Hash)
|
|
219
248
|
value.each do |name, item|
|
|
220
|
-
unsupported!('This sample does not match the Go API client output layout.') unless name.is_a?(String) || name.is_a?(Symbol)
|
|
249
|
+
unsupported!('generated.go.sample_output_layout', default: 'This sample does not match the Go API client output layout.') unless name.is_a?(String) || name.is_a?(Symbol)
|
|
221
250
|
parameter = io.parameters.find { |candidate| candidate.name == name.to_s }
|
|
222
251
|
unless parameter
|
|
223
|
-
unsupported!(
|
|
252
|
+
unsupported!('generated.go.undeclared_field', default: 'API example field %{path} is not declared in the Go API client schema.', path: response_field_path(response_path, name))
|
|
224
253
|
end
|
|
225
254
|
left = lookup(desc[:parameters], name)
|
|
226
255
|
right = lookup(live && live[:parameters], name)
|
|
227
256
|
unless left && right && parameter_contract(left) == parameter_contract(right)
|
|
228
|
-
unsupported!('This response field does not match the configured Go API client.')
|
|
257
|
+
unsupported!('generated.go.response_field', default: 'This response field does not match the configured Go API client.')
|
|
229
258
|
end
|
|
230
259
|
if item.nil? && !parameter.respond_to?(:association)
|
|
231
|
-
unsupported!('The Go API client cannot distinguish scalar null output from its zero value.')
|
|
260
|
+
unsupported!('generated.go.null_output', default: 'The Go API client cannot distinguish scalar null output from its zero value.')
|
|
232
261
|
end
|
|
233
262
|
literal(parameter.go_out_type, item) unless parameter.respond_to?(:association)
|
|
234
263
|
next unless parameter.respond_to?(:association)
|
|
235
264
|
next if item.nil?
|
|
236
265
|
|
|
237
266
|
unless item.is_a?(Hash)
|
|
238
|
-
unsupported!('The Go API client requires an object for an associated response field.')
|
|
267
|
+
unsupported!('generated.go.associated_object', default: 'The Go API client requires an object for an associated response field.')
|
|
239
268
|
end
|
|
240
269
|
|
|
241
270
|
associated = parameter.association.resource.actions.find { |candidate| candidate.name == 'show' }
|
|
@@ -243,7 +272,7 @@ module HaveAPI::GoClient
|
|
|
243
272
|
saved_association = resolve(resource_path: path, action_name: 'show')
|
|
244
273
|
live_association = visible_action(context.description, path, 'show')
|
|
245
274
|
unless saved_association && live_association
|
|
246
|
-
unsupported!('This associated response is unavailable in the visible Go API client documentation.')
|
|
275
|
+
unsupported!('generated.go.associated_response', default: 'This associated response is unavailable in the visible Go API client documentation.')
|
|
247
276
|
end
|
|
248
277
|
check_parameters(associated.output, saved_association.description[:output], input: false)
|
|
249
278
|
check_output_value(associated.output, saved_association.description[:output], live_association[:output], item, context,
|
|
@@ -264,17 +293,17 @@ module HaveAPI::GoClient
|
|
|
264
293
|
names = action.path.scan(/\{([a-zA-Z0-9\-_]+)\}/).flatten
|
|
265
294
|
values = sample[:path_params] || []
|
|
266
295
|
unless values.is_a?(Array) && names.length == values.length
|
|
267
|
-
unsupported!('This sample does not supply all Go API client path parameters.')
|
|
296
|
+
unsupported!('generated.go.path_parameters', default: 'This sample does not supply all Go API client path parameters.')
|
|
268
297
|
end
|
|
269
298
|
names.zip(values).map do |name, value|
|
|
270
299
|
case value
|
|
271
300
|
when Integer
|
|
272
|
-
unsupported!('This path value is outside the Go int64 range.') unless int64?(value)
|
|
301
|
+
unsupported!('generated.go.int64_range', default: 'This path value is outside the Go int64 range.') unless int64?(value)
|
|
273
302
|
"invocation.SetPathParamInt(#{go_string_literal(name)}, #{value})"
|
|
274
303
|
when String
|
|
275
304
|
"invocation.SetPathParamString(#{go_string_literal(name)}, #{go_string_literal(value)})"
|
|
276
305
|
else
|
|
277
|
-
unsupported!('This Go API client path parameter must be an integer or string.')
|
|
306
|
+
unsupported!('generated.go.path_type', default: 'This Go API client path parameter must be an integer or string.')
|
|
278
307
|
end
|
|
279
308
|
end
|
|
280
309
|
end
|
|
@@ -283,9 +312,9 @@ module HaveAPI::GoClient
|
|
|
283
312
|
return [] unless sample.has_key?(:request) && !sample[:request].nil?
|
|
284
313
|
|
|
285
314
|
request = sample[:request]
|
|
286
|
-
unsupported!('The Go generator supports object input only.') unless request.is_a?(Hash)
|
|
315
|
+
unsupported!('generated.go.object_input', default: 'The Go generator supports object input only.') unless request.is_a?(Hash)
|
|
287
316
|
unless action.has_input?
|
|
288
|
-
unsupported!('This input is unavailable in the configured Go API client.') unless request.empty?
|
|
317
|
+
unsupported!('generated.go.input', default: 'This input is unavailable in the configured Go API client.') unless request.empty?
|
|
289
318
|
return []
|
|
290
319
|
end
|
|
291
320
|
lines = ["#{'input := ' unless request.empty?}invocation.NewInput().SelectParameters()"]
|
|
@@ -294,10 +323,10 @@ module HaveAPI::GoClient
|
|
|
294
323
|
saved_parameter = lookup(saved && saved[:parameters], name)
|
|
295
324
|
live_parameter = lookup(live && live[:parameters], name)
|
|
296
325
|
unless parameter && saved_parameter && live_parameter && parameter_contract(saved_parameter) == parameter_contract(live_parameter)
|
|
297
|
-
unsupported!('This input field does not match the configured Go API client.')
|
|
326
|
+
unsupported!('generated.go.input_field', default: 'This input field does not match the configured Go API client.')
|
|
298
327
|
end
|
|
299
328
|
if value.nil?
|
|
300
|
-
unsupported!('This Go API client input field does not accept null.') unless parameter.nillable?
|
|
329
|
+
unsupported!('generated.go.null_input', default: 'This Go API client input field does not accept null.') unless parameter.nillable?
|
|
301
330
|
lines << "input.Set#{parameter.go_name}Nil(true)"
|
|
302
331
|
else
|
|
303
332
|
lines << "input.Set#{parameter.go_name}(#{literal(parameter.go_in_type, value)})"
|
|
@@ -306,7 +335,7 @@ module HaveAPI::GoClient
|
|
|
306
335
|
lines
|
|
307
336
|
end
|
|
308
337
|
|
|
309
|
-
def metadata_lines(action, saved, live)
|
|
338
|
+
def metadata_lines(action, saved, live, context)
|
|
310
339
|
io = action.metadata && action.metadata.global && action.metadata.global.input
|
|
311
340
|
return [] unless io && io.parameters.any?
|
|
312
341
|
|
|
@@ -318,9 +347,9 @@ module HaveAPI::GoClient
|
|
|
318
347
|
left && right && parameter_contract(left) == parameter_contract(right)
|
|
319
348
|
end
|
|
320
349
|
|
|
321
|
-
['
|
|
350
|
+
[comment_lines(example_comment('go_metadata', default: 'To supply advertised global metadata, select only the fields you set:', context:), '// '),
|
|
322
351
|
'// metadata := invocation.NewMetaInput().SelectParameters()'] +
|
|
323
|
-
io.parameters.map { |parameter| "// metadata.Set#{parameter.go_name}(value)
|
|
352
|
+
io.parameters.map { |parameter| "// metadata.Set#{parameter.go_name}(value) #{comment_lines(example_comment('go_metadata_type', default: 'value has type %{type}', context:, type: parameter.go_in_type), '// ')}" }
|
|
324
353
|
end
|
|
325
354
|
|
|
326
355
|
def call_lines(action, live, sample, context)
|
|
@@ -335,7 +364,7 @@ module HaveAPI::GoClient
|
|
|
335
364
|
"\treturn",
|
|
336
365
|
'}'
|
|
337
366
|
]
|
|
338
|
-
return lines + ['
|
|
367
|
+
return lines + [comment_lines(example_comment('failure_branch', default: 'This sample demonstrates the failure branch above.', context:), '// ')] unless sample[:status]
|
|
339
368
|
|
|
340
369
|
lines.concat(output_lines(action, sample))
|
|
341
370
|
if context.detail == :thorough && operation_visible?(action, live, context)
|
|
@@ -350,12 +379,12 @@ module HaveAPI::GoClient
|
|
|
350
379
|
"\t\tfmt.Println(state.Message, state.Errors)",
|
|
351
380
|
"\t\treturn",
|
|
352
381
|
"\t}",
|
|
353
|
-
|
|
382
|
+
comment_lines(example_comment('operation_status_fields', default: 'Inspect the operation status using its documented output fields.', context:), ' // '),
|
|
354
383
|
'}',
|
|
355
|
-
'
|
|
384
|
+
comment_lines(example_comment('request_completion', default: 'Request success does not establish operation completion.', context:), '// ')
|
|
356
385
|
)
|
|
357
386
|
elsif action.blocking?
|
|
358
|
-
lines << '
|
|
387
|
+
lines << comment_lines(example_comment('request_completion', default: 'Request success does not establish operation completion.', context:), '// ')
|
|
359
388
|
end
|
|
360
389
|
lines
|
|
361
390
|
end
|
|
@@ -433,25 +462,25 @@ module HaveAPI::GoClient
|
|
|
433
462
|
method = method.to_sym
|
|
434
463
|
visible = lookup(context.description[:authentication], method)
|
|
435
464
|
saved = lookup(@description[:authentication], method)
|
|
436
|
-
unsupported!('This authentication method is unavailable in the configured Go API client.') unless visible && saved && desc
|
|
465
|
+
unsupported!('generated.go.authentication', default: 'This authentication method is unavailable in the configured Go API client.') unless visible && saved && desc
|
|
437
466
|
lines = case method
|
|
438
467
|
when :basic
|
|
439
468
|
['api.SetBasicAuthentication("user", "secret")']
|
|
440
469
|
when :token
|
|
441
470
|
unless same_transport_name?(saved[:http_header], visible[:http_header]) &&
|
|
442
471
|
same_transport_name?(saved[:query_parameter], visible[:query_parameter])
|
|
443
|
-
unsupported!('This authentication method does not match the configured Go API client.')
|
|
472
|
+
unsupported!('generated.go.authentication_mismatch', default: 'This authentication method does not match the configured Go API client.')
|
|
444
473
|
end
|
|
445
474
|
['api.SetExistingTokenAuth("example-token")',
|
|
446
|
-
'
|
|
475
|
+
comment_lines(example_comment('go_existing_token', default: 'Use a token obtained through the advertised authentication provider.', context:), '// ')]
|
|
447
476
|
when :oauth2
|
|
448
477
|
unless saved[:http_header] == visible[:http_header]
|
|
449
|
-
unsupported!('This authentication method does not match the configured Go API client.')
|
|
478
|
+
unsupported!('generated.go.authentication_mismatch', default: 'This authentication method does not match the configured Go API client.')
|
|
450
479
|
end
|
|
451
480
|
['api.SetExistingOAuth2Auth("example-access-token")',
|
|
452
|
-
'
|
|
481
|
+
comment_lines(example_comment('go_existing_oauth', default: 'Obtain the access token through the OAuth2 provider before running this program.', context:), '// ')]
|
|
453
482
|
else
|
|
454
|
-
unsupported!('This authentication method is unsupported by the Go generator.')
|
|
483
|
+
unsupported!('generated.go.authentication_unsupported', default: 'This authentication method is unsupported by the Go generator.')
|
|
455
484
|
end
|
|
456
485
|
code(program(context, [], lines))
|
|
457
486
|
end
|
|
@@ -482,7 +511,7 @@ module HaveAPI::GoClient
|
|
|
482
511
|
when 'bool' then [true, false].include?(value)
|
|
483
512
|
else false
|
|
484
513
|
end
|
|
485
|
-
unsupported!('This sample value cannot be represented by the Go API client field type.') unless valid
|
|
514
|
+
unsupported!('generated.go.value', default: 'This sample value cannot be represented by the Go API client field type.') unless valid
|
|
486
515
|
type == 'string' ? go_string_literal(value) : value.to_s
|
|
487
516
|
end
|
|
488
517
|
|
|
@@ -542,8 +571,8 @@ module HaveAPI::GoClient
|
|
|
542
571
|
value.freeze
|
|
543
572
|
end
|
|
544
573
|
|
|
545
|
-
def unsupported!(
|
|
546
|
-
raise Unsupported,
|
|
574
|
+
def unsupported!(key, default:, **values)
|
|
575
|
+
raise Unsupported.new(key, default:, **values)
|
|
547
576
|
end
|
|
548
577
|
|
|
549
578
|
def code(source)
|
|
@@ -1,16 +1,55 @@
|
|
|
1
|
+
require_relative '../../../../servers/ruby/spec/client_examples/comment_capture'
|
|
1
2
|
require 'haveapi/go_client/documentation'
|
|
2
3
|
require 'open3'
|
|
3
4
|
require_relative '../support/documentation_fixture'
|
|
4
5
|
|
|
5
6
|
RSpec.describe HaveAPI::GoClient::Documentation do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let(:action) { description.dig(:resources, :client, :resources, :child, :actions, :client) }
|
|
9
|
-
let(:sample) { GoDocumentationFixture.sample }
|
|
7
|
+
include ExampleCommentCapture
|
|
8
|
+
|
|
10
9
|
let(:context) do
|
|
11
10
|
Struct.new(:version, :base_url, :description, :resource_path, :action_name, :action, :sample, :detail).new(detail: :thorough, version: '7', base_url: 'https://api.example.test/mounted/', description:,
|
|
12
11
|
resource_path: %w[client child], action_name: 'client', action:, sample:)
|
|
13
12
|
end
|
|
13
|
+
let(:sample) { GoDocumentationFixture.sample }
|
|
14
|
+
let(:action) { description.dig(:resources, :client, :resources, :child, :actions, :client) }
|
|
15
|
+
let(:adapter) { described_class.new(description:, import_path: 'example.test/sdk/client', module_version: 'v1.2.3') }
|
|
16
|
+
let(:description) { GoDocumentationFixture.description }
|
|
17
|
+
|
|
18
|
+
it 'localizes authored comments without changing commands or data for standalone contexts' do
|
|
19
|
+
action[:blocking] = true
|
|
20
|
+
context.sample[:request][:name] = 'literal // # komentář'
|
|
21
|
+
%i[simple thorough].each do |detail|
|
|
22
|
+
context.detail = detail
|
|
23
|
+
[[:init, nil], %i[auth basic], %i[auth token], %i[auth oauth2], [:example, nil]].each do |kind, method|
|
|
24
|
+
sources = expect_adapter_comment_parity(described_class, context, kind:, mode: :sync,
|
|
25
|
+
auth_method: method, auth_description: description[:authentication][method]) do |klass|
|
|
26
|
+
klass.new(description:, import_path: 'example.test/sdk/client', module_version: 'v1.2.3')
|
|
27
|
+
end
|
|
28
|
+
expect(sources.last).to include('literal // # komentář') if kind == :example
|
|
29
|
+
formatted, status = Open3.capture2e('gofmt', stdin_data: sources.last)
|
|
30
|
+
expect(status).to be_success, formatted
|
|
31
|
+
expect(formatted).to eq(sources.last)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'localizes keyed limitations using only the current context, including field paths' do
|
|
37
|
+
localized = localized_comment_context(context, :cs)
|
|
38
|
+
result = adapter.render(kind: :init, context: localized, mode: :unknown)
|
|
39
|
+
expect(result).to eq(status: :limitation, reason: 'Tento režim příkladu API klienta pro Go není podporovaný.')
|
|
40
|
+
expect(result).to be_frozen
|
|
41
|
+
expect(result[:reason]).to be_frozen
|
|
42
|
+
expect(adapter.render(kind: :init, context:, mode: :unknown)[:reason]).to eq('This Go API client example mode is unsupported.')
|
|
43
|
+
expect(adapter).to be_frozen
|
|
44
|
+
sample[:response] = { 'unknown.field' => 1 }
|
|
45
|
+
reason = adapter.render(kind: :example, context: localized, mode: :sync).fetch(:reason)
|
|
46
|
+
expect(reason).to include('unknown.field')
|
|
47
|
+
expect(reason).not_to include('API example field')
|
|
48
|
+
fallback = localized.dup
|
|
49
|
+
fallback.define_singleton_method(:documentation_message) { |_key, default:, **values| values.empty? ? default : format(default, values) }
|
|
50
|
+
expect(adapter.render(kind: :example, context: fallback, mode: :sync).fetch(:reason))
|
|
51
|
+
.to include('API example field', 'unknown.field')
|
|
52
|
+
end
|
|
14
53
|
|
|
15
54
|
def render
|
|
16
55
|
adapter.render(kind: :example, context:, mode: :sync)
|
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.32.
|
|
4
|
+
version: 0.32.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.32.
|
|
18
|
+
version: 0.32.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.32.
|
|
25
|
+
version: 0.32.2
|
|
26
26
|
description: Go client generator
|
|
27
27
|
email:
|
|
28
28
|
- jakub.skokan@vpsfree.cz
|