aws-sdk-code-generator 0.1.0.pre → 0.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +5 -5
  2. data/lib/aws-sdk-code-generator.rb +68 -75
  3. data/lib/aws-sdk-code-generator/api.rb +130 -0
  4. data/lib/aws-sdk-code-generator/apply_docs.rb +15 -2
  5. data/lib/aws-sdk-code-generator/client_constructor.rb +39 -0
  6. data/lib/aws-sdk-code-generator/client_operation_documentation.rb +268 -0
  7. data/lib/aws-sdk-code-generator/client_operation_list.rb +148 -0
  8. data/lib/aws-sdk-code-generator/client_response_structure_example.rb +108 -0
  9. data/lib/aws-sdk-code-generator/code_builder.rb +146 -133
  10. data/lib/aws-sdk-code-generator/crosslink.rb +42 -0
  11. data/lib/aws-sdk-code-generator/docstring.rb +199 -0
  12. data/lib/aws-sdk-code-generator/error_list.rb +77 -0
  13. data/lib/aws-sdk-code-generator/errors.rb +2 -0
  14. data/lib/aws-sdk-code-generator/eventstream_example.rb +220 -0
  15. data/lib/aws-sdk-code-generator/gem_builder.rb +19 -25
  16. data/lib/aws-sdk-code-generator/hash_formatter.rb +5 -2
  17. data/lib/aws-sdk-code-generator/helper.rb +77 -61
  18. data/lib/aws-sdk-code-generator/plugin_list.rb +146 -0
  19. data/lib/aws-sdk-code-generator/resource_action.rb +69 -0
  20. data/lib/aws-sdk-code-generator/resource_action_code.rb +57 -0
  21. data/lib/aws-sdk-code-generator/resource_association.rb +37 -0
  22. data/lib/aws-sdk-code-generator/resource_attribute.rb +76 -0
  23. data/lib/aws-sdk-code-generator/resource_batch_action.rb +56 -0
  24. data/lib/aws-sdk-code-generator/resource_batch_action_code.rb +136 -0
  25. data/lib/aws-sdk-code-generator/resource_batch_action_documentation.rb +108 -0
  26. data/lib/aws-sdk-code-generator/resource_batch_builder.rb +212 -0
  27. data/lib/aws-sdk-code-generator/resource_builder.rb +48 -0
  28. data/lib/aws-sdk-code-generator/resource_client_request.rb +62 -0
  29. data/lib/aws-sdk-code-generator/resource_client_request_documentation.rb +81 -0
  30. data/lib/aws-sdk-code-generator/resource_client_request_params.rb +86 -0
  31. data/lib/aws-sdk-code-generator/resource_data_method.rb +60 -0
  32. data/lib/aws-sdk-code-generator/resource_has_association.rb +117 -0
  33. data/lib/aws-sdk-code-generator/resource_has_many_association.rb +52 -0
  34. data/lib/aws-sdk-code-generator/resource_has_many_association_code.rb +76 -0
  35. data/lib/aws-sdk-code-generator/resource_identifier.rb +44 -0
  36. data/lib/aws-sdk-code-generator/resource_identifiers_method.rb +29 -0
  37. data/lib/aws-sdk-code-generator/resource_load_method.rb +68 -0
  38. data/lib/aws-sdk-code-generator/resource_method.rb +22 -0
  39. data/lib/aws-sdk-code-generator/resource_skip_params.rb +36 -0
  40. data/lib/aws-sdk-code-generator/resource_value_source.rb +68 -0
  41. data/lib/aws-sdk-code-generator/resource_waiter.rb +80 -0
  42. data/lib/aws-sdk-code-generator/service.rb +30 -7
  43. data/lib/aws-sdk-code-generator/shared_example.rb +131 -0
  44. data/lib/aws-sdk-code-generator/syntax_example.rb +60 -0
  45. data/lib/aws-sdk-code-generator/syntax_example_hash.rb +174 -0
  46. data/lib/aws-sdk-code-generator/underscore.rb +10 -5
  47. data/lib/aws-sdk-code-generator/view.rb +33 -0
  48. data/lib/aws-sdk-code-generator/views.rb +2 -0
  49. data/lib/aws-sdk-code-generator/views/apig_endpoint_class.rb +25 -0
  50. data/lib/aws-sdk-code-generator/views/apig_readme.rb +32 -0
  51. data/lib/aws-sdk-code-generator/views/async_client_class.rb +68 -0
  52. data/lib/aws-sdk-code-generator/views/authorizer_class.rb +17 -0
  53. data/lib/aws-sdk-code-generator/views/client_api_module.rb +583 -0
  54. data/lib/aws-sdk-code-generator/views/client_class.rb +93 -0
  55. data/lib/aws-sdk-code-generator/views/docstring.rb +27 -0
  56. data/lib/aws-sdk-code-generator/views/errors_module.rb +32 -0
  57. data/lib/aws-sdk-code-generator/views/event_streams_module.rb +149 -0
  58. data/lib/aws-sdk-code-generator/views/features/env.rb +9 -0
  59. data/lib/aws-sdk-code-generator/views/features/smoke.rb +51 -0
  60. data/lib/aws-sdk-code-generator/views/features/smoke_step_definitions.rb +26 -0
  61. data/lib/aws-sdk-code-generator/views/features/step_definitions.rb +2 -0
  62. data/lib/aws-sdk-code-generator/views/gemspec.rb +39 -5
  63. data/lib/aws-sdk-code-generator/views/resource_class.rb +122 -0
  64. data/lib/aws-sdk-code-generator/views/root_resource_class.rb +58 -0
  65. data/lib/aws-sdk-code-generator/views/service_module.rb +30 -14
  66. data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -0
  67. data/lib/aws-sdk-code-generator/views/types_module.rb +294 -0
  68. data/lib/aws-sdk-code-generator/views/version.rb +2 -0
  69. data/lib/aws-sdk-code-generator/views/waiters_module.rb +37 -0
  70. data/lib/aws-sdk-code-generator/waiter.rb +95 -0
  71. data/lib/aws-sdk-code-generator/yard_option_tag.rb +43 -0
  72. metadata +61 -68
  73. data/lib/aws-sdk-code-generator/dsl/access_control_statement.rb +0 -23
  74. data/lib/aws-sdk-code-generator/dsl/attribute_accessor.rb +0 -43
  75. data/lib/aws-sdk-code-generator/dsl/attribute_reader.rb +0 -11
  76. data/lib/aws-sdk-code-generator/dsl/attribute_writer.rb +0 -11
  77. data/lib/aws-sdk-code-generator/dsl/autoload_statement.rb +0 -15
  78. data/lib/aws-sdk-code-generator/dsl/block_param.rb +0 -11
  79. data/lib/aws-sdk-code-generator/dsl/class.rb +0 -27
  80. data/lib/aws-sdk-code-generator/dsl/code_literal.rb +0 -66
  81. data/lib/aws-sdk-code-generator/dsl/code_object.rb +0 -33
  82. data/lib/aws-sdk-code-generator/dsl/docstring.rb +0 -36
  83. data/lib/aws-sdk-code-generator/dsl/eigenclass.rb +0 -15
  84. data/lib/aws-sdk-code-generator/dsl/extend_statement.rb +0 -12
  85. data/lib/aws-sdk-code-generator/dsl/formatter.rb +0 -25
  86. data/lib/aws-sdk-code-generator/dsl/include_statement.rb +0 -17
  87. data/lib/aws-sdk-code-generator/dsl/main.rb +0 -105
  88. data/lib/aws-sdk-code-generator/dsl/method.rb +0 -108
  89. data/lib/aws-sdk-code-generator/dsl/module.rb +0 -167
  90. data/lib/aws-sdk-code-generator/dsl/option_tag.rb +0 -36
  91. data/lib/aws-sdk-code-generator/dsl/param.rb +0 -43
  92. data/lib/aws-sdk-code-generator/dsl/param_list.rb +0 -38
  93. data/lib/aws-sdk-code-generator/dsl/return_tag.rb +0 -19
  94. data/lib/aws-sdk-code-generator/dsl/tag_default.rb +0 -20
  95. data/lib/aws-sdk-code-generator/dsl/tag_docstring.rb +0 -27
  96. data/lib/aws-sdk-code-generator/dsl/tag_type.rb +0 -18
  97. data/lib/aws-sdk-code-generator/generators/client_api_module.rb +0 -334
  98. data/lib/aws-sdk-code-generator/generators/client_class.rb +0 -389
  99. data/lib/aws-sdk-code-generator/generators/client_operation_documentation.rb +0 -166
  100. data/lib/aws-sdk-code-generator/generators/errors_module.rb +0 -25
  101. data/lib/aws-sdk-code-generator/generators/resource/action.rb +0 -88
  102. data/lib/aws-sdk-code-generator/generators/resource/batch_builder.rb +0 -211
  103. data/lib/aws-sdk-code-generator/generators/resource/builder.rb +0 -50
  104. data/lib/aws-sdk-code-generator/generators/resource/client_getter.rb +0 -15
  105. data/lib/aws-sdk-code-generator/generators/resource/client_request.rb +0 -49
  106. data/lib/aws-sdk-code-generator/generators/resource/client_request_docs.rb +0 -97
  107. data/lib/aws-sdk-code-generator/generators/resource/client_request_params.rb +0 -88
  108. data/lib/aws-sdk-code-generator/generators/resource/collection_class.rb +0 -180
  109. data/lib/aws-sdk-code-generator/generators/resource/data_attribute_getter.rb +0 -24
  110. data/lib/aws-sdk-code-generator/generators/resource/data_loaded_method.rb +0 -18
  111. data/lib/aws-sdk-code-generator/generators/resource/data_method.rb +0 -49
  112. data/lib/aws-sdk-code-generator/generators/resource/exists_method.rb +0 -29
  113. data/lib/aws-sdk-code-generator/generators/resource/extract_identifier_method.rb +0 -32
  114. data/lib/aws-sdk-code-generator/generators/resource/has_association.rb +0 -101
  115. data/lib/aws-sdk-code-generator/generators/resource/has_many_association.rb +0 -108
  116. data/lib/aws-sdk-code-generator/generators/resource/identifier_getter.rb +0 -26
  117. data/lib/aws-sdk-code-generator/generators/resource/identifiers_method.rb +0 -28
  118. data/lib/aws-sdk-code-generator/generators/resource/initialize_method.rb +0 -67
  119. data/lib/aws-sdk-code-generator/generators/resource/load_method.rb +0 -65
  120. data/lib/aws-sdk-code-generator/generators/resource/value_source.rb +0 -68
  121. data/lib/aws-sdk-code-generator/generators/resource/waiter_method.rb +0 -61
  122. data/lib/aws-sdk-code-generator/generators/resource_class.rb +0 -325
  123. data/lib/aws-sdk-code-generator/generators/response_structure_example.rb +0 -83
  124. data/lib/aws-sdk-code-generator/generators/root_resource_class.rb +0 -42
  125. data/lib/aws-sdk-code-generator/generators/service_documentation.rb +0 -64
  126. data/lib/aws-sdk-code-generator/generators/shared_example.rb +0 -132
  127. data/lib/aws-sdk-code-generator/generators/structure_type_class.rb +0 -95
  128. data/lib/aws-sdk-code-generator/generators/syntax_example.rb +0 -169
  129. data/lib/aws-sdk-code-generator/generators/types_module.rb +0 -52
  130. data/lib/aws-sdk-code-generator/generators/waiter_class.rb +0 -62
  131. data/lib/aws-sdk-code-generator/generators/waiters_module.rb +0 -20
@@ -1,389 +0,0 @@
1
- require 'set'
2
- require 'pp'
3
- require 'seahorse/client/plugin'
4
-
5
- module AwsSdkCodeGenerator
6
- module Generators
7
- class ClientClass < Dsl::Class
8
-
9
- include Helper
10
-
11
- # @option options [required, Main, Module] :parent
12
- # @option options [required, String] :identifier
13
- # @option options [required, Hash] :api
14
- # @option options [required, Hash, nil] :waiters
15
- # @option options [required, Hash, nil] :examples
16
- # @option options [Hash] :add_plugins ({})
17
- # @option options [Array<String>] :remove_plugins ([])
18
- def initialize(options)
19
- @identifier = options.fetch(:identifier)
20
- @api = options.fetch(:api)
21
- @waiters = options.fetch(:waiters)
22
- @examples = options.fetch(:examples)
23
- @add_plugins = options.fetch(:add_plugins, {})
24
- @remove_plugins = options.fetch(:remove_plugins, [])
25
- @gem_name = options.fetch(:gem_name, nil)
26
- @gem_version = options.fetch(:gem_version, nil)
27
- super('Client', extends: 'Seahorse::Client::Base', parent: options.fetch(:parent))
28
- apply_modules(self)
29
- apply_identifier(self)
30
- apply_api(self)
31
- apply_plugins(self)
32
- apply_initialize_method(self)
33
- top("\nAws::Plugins::GlobalConfiguration.add_identifier(:#{@identifier})")
34
- apply_operations(self)
35
- apply_waiter_methods(self)
36
- eigenclass do |eigenclass|
37
- eigenclass.attr_reader('identifier', api_private: true)
38
- eigenclass.method('errors_module', api_private: true) do |m|
39
- m.code('Errors')
40
- end
41
- end
42
- end
43
-
44
- private
45
-
46
- def client_plugins
47
- @client_plugins ||= begin
48
- plugins = {}
49
- plugins.update(default_plugins)
50
- plugins.update(signature_plugins)
51
- plugins.update(protocol_plugins(@api['metadata']['protocol']))
52
- plugins.update(@add_plugins)
53
- @remove_plugins.each do |plugin_name|
54
- plugins.delete(plugin_name)
55
- end
56
- plugins.map do |class_name, path|
57
- path = "./#{path}" unless path[0] == '/'
58
- Kernel.require(path)
59
- ClientPlugin.new(
60
- class_name: class_name,
61
- options: const_get(class_name).options,
62
- path: path)
63
- end
64
- end
65
- end
66
-
67
- def const_get(class_name)
68
- const_names = class_name.split('::')
69
- const_names.inject(Kernel) do |const, const_name|
70
- const.const_get(const_name)
71
- end
72
- end
73
-
74
- def documented_plugin_options
75
- client_plugins.map(&:options).flatten.select(&:documented?).sort_by do |opt|
76
- [opt.required ? 'a' : 'b', opt.name]
77
- end
78
- end
79
-
80
- def apply_modules(klass)
81
- klass.include('Aws::ClientStubs')
82
- end
83
-
84
- def apply_identifier(klass)
85
- klass.code do |c|
86
- c << "@identifier = :#{@identifier}"
87
- end
88
- end
89
-
90
- def apply_api(klass)
91
- klass.code("set_api(ClientApi::API)")
92
- end
93
-
94
- def apply_plugins(klass)
95
- klass.code do |c|
96
- client_plugins.each do |plugin|
97
- klass.top("require '#{plugin.require_path}'")
98
- c << "add_plugin(#{plugin.class_name})"
99
- end
100
- end
101
- end
102
-
103
- def apply_initialize_method(klass)
104
- klass.method(:initialize) do |m|
105
- documented_plugin_options.each do |option|
106
- m.option(
107
- name: option.name,
108
- type: option.doc_type,
109
- required: option.required,
110
- default: option.doc_default,
111
- docstring: option.docstring
112
- )
113
- end
114
- m.param('*args')
115
- m.code('super')
116
- end
117
- end
118
-
119
- def apply_operations(klass)
120
- code('# @!group API Operations')
121
- (@api['operations'] || {}).each do |operation_name, operation|
122
- method_name = underscore(operation_name)
123
- klass.method(method_name) do |m|
124
- ClientOperationDocumentation.apply(
125
- api: @api,
126
- service_identifier: @identifier,
127
- operation_name: operation_name,
128
- operation: operation,
129
- examples: @examples,
130
- method: m
131
- )
132
- m.param('params', type: Hash, default: {})
133
- m.param('options', type: Hash, default: {}, documented: false)
134
- m.code do |c|
135
- c << "req = build_request(:#{method_name}, params)"
136
- c << "req.send_request(options)"
137
- end
138
- end
139
- end
140
- code('# @!endgroup')
141
-
142
-
143
- if @gem_name && @gem_version
144
- gem_version = "\ncontext[:gem_name] = '#{@gem_name}'"
145
- gem_version += "\ncontext[:gem_version] = '#{@gem_version}'"
146
- end
147
- klass.method(:build_request, api_private: true) do |m|
148
- m.param(:operation_name)
149
- m.param(:params, default: {})
150
- m.code(<<-CODE)
151
- handlers = @handlers.for(operation_name)
152
- context = Seahorse::Client::RequestContext.new(
153
- operation_name: operation_name,
154
- operation: config.api.operation(operation_name),
155
- client: self,
156
- params: params,
157
- config: config)#{gem_version}
158
- Seahorse::Client::Request.new(handlers, context)
159
- CODE
160
- end
161
- end
162
-
163
- def apply_waiter_methods(klass)
164
-
165
- # wait_until(waiter_name, params = {}, options = {}, &block)
166
- if @waiters
167
- klass.add(Dsl::Method.new('wait_until') do |m|
168
- m.param('waiter_name', type: Symbol)
169
- m.param('params', type: Hash, default: {})
170
- m.param('options', type: Hash, default: {})
171
- m.option(name: 'max_attempts', type: Integer)
172
- m.option(name: 'delay', type: Integer)
173
- m.option(name: 'before_attempt', type: Proc)
174
- m.option(name: 'before_wait', type: Proc)
175
- m.docstring(<<-DOCS)
176
- Polls an API operation until a resource enters a desired state.
177
-
178
- ## Basic Usage
179
-
180
- A waiter will call an API operation until:
181
-
182
- * It is successful
183
- * It enters a terminal state
184
- * It makes the maximum number of attempts
185
-
186
- In between attempts, the waiter will sleep.
187
-
188
- # polls in a loop, sleeping between attempts
189
- client.waiter_until(waiter_name, params)
190
-
191
- ## Configuration
192
-
193
- You can configure the maximum number of polling attempts, and the
194
- delay (in seconds) between each polling attempt. You can pass
195
- configuration as the final arguments hash.
196
-
197
- # poll for ~25 seconds
198
- client.wait_until(waiter_name, params, {
199
- max_attempts: 5,
200
- delay: 5,
201
- })
202
-
203
- ## Callbacks
204
-
205
- You can be notified before each polling attempt and before each
206
- delay. If you throw `:success` or `:failure` from these callbacks,
207
- it will terminate the waiter.
208
-
209
- started_at = Time.now
210
- client.wait_until(waiter_name, params, {
211
-
212
- # disable max attempts
213
- max_attempts: nil,
214
-
215
- # poll for 1 hour, instead of a number of attempts
216
- before_wait: -> (attempts, response) do
217
- throw :failure if Time.now - started_at > 3600
218
- end
219
- })
220
-
221
- ## Handling Errors
222
-
223
- When a waiter is unsuccessful, it will raise an error.
224
- All of the failure errors extend from
225
- {Aws::Waiters::Errors::WaiterFailed}.
226
-
227
- begin
228
- client.wait_until(...)
229
- rescue Aws::Waiters::Errors::WaiterFailed
230
- # resource did not enter the desired state in time
231
- end
232
-
233
- ## Valid Waiters
234
-
235
- The following table lists the valid waiter names, the operations they call,
236
- and the default `:delay` and `:max_attempts` values.
237
-
238
- #{waiter_table}
239
-
240
- @raise [Errors::FailureStateError] Raised when the waiter terminates
241
- because the waiter has entered a state that it will not transition
242
- out of, preventing success.
243
-
244
- @raise [Errors::TooManyAttemptsError] Raised when the configured
245
- maximum number of attempts have been made, and the waiter is not
246
- yet successful.
247
-
248
- @raise [Errors::UnexpectedError] Raised when an error is encounted
249
- while polling for a resource that is not expected.
250
-
251
- @raise [Errors::NoSuchWaiterError] Raised when you request to wait
252
- for an unknown state.
253
-
254
- @return [Boolean] Returns `true` if the waiter was successful.
255
- DOCS
256
- m.code(<<-CODE)
257
- w = waiter(waiter_name, options)
258
- yield(w.waiter) if block_given? # deprecated
259
- w.wait(params)
260
- CODE
261
- end)
262
- end
263
-
264
- # waiter_names
265
- klass.add(Dsl::Method.new('waiter_names') do |m|
266
- m.docstring("@api private")
267
- m.docstring("@deprecated")
268
- if @waiters
269
- m.code("waiters.keys")
270
- else
271
- m.code('[]')
272
- end
273
- end)
274
-
275
- # private: waiter(waiter_name)
276
- klass.add(Dsl::Method.new('waiter', access: :private) do |m|
277
- m.param('waiter_name', type: Symbol)
278
- m.param('options', type: Hash, default: {})
279
- m.code(<<-CODE)
280
- waiter_class = waiters[waiter_name]
281
- if waiter_class
282
- waiter_class.new(options.merge(client: self))
283
- else
284
- raise Aws::Waiters::Errors::NoSuchWaiterError.new(waiter_name, waiters.keys)
285
- end
286
- CODE
287
- end) if @waiters
288
-
289
- # private: waiters
290
- klass.add(Dsl::Method.new('waiters', access: :private) do |m|
291
- waiters = {}
292
- ((@waiters || {})['waiters'] || {}).each_pair do |name, definition|
293
- class_name = "Waiters::#{name}"
294
- waiters[underscore(name).to_sym] = class_name
295
- end
296
- m.code(HashFormatter.new.format(waiters))
297
- end) if @waiters
298
-
299
- end
300
-
301
- def core_lib
302
- # TODO : may need to register the default plugins directory rather
303
- # than have the hard-coded here as a relative path
304
- File.expand_path('../../../../../../gems/aws-sdk-core/lib', __FILE__)
305
- end
306
-
307
- def core_plugins
308
- "#{core_lib}/aws-sdk-core/plugins"
309
- end
310
-
311
- def seahorse_plugins
312
- "#{core_lib}/seahorse/client/plugins"
313
- end
314
-
315
- def default_plugins
316
- {
317
- 'Seahorse::Client::Plugins::ContentLength' => "#{seahorse_plugins}/content_length.rb",
318
- 'Aws::Plugins::CredentialsConfiguration' => "#{core_plugins}/credentials_configuration.rb",
319
- 'Aws::Plugins::Logging' => "#{core_plugins}/logging.rb",
320
- 'Aws::Plugins::ParamConverter' => "#{core_plugins}/param_converter.rb",
321
- 'Aws::Plugins::ParamValidator' => "#{core_plugins}/param_validator.rb",
322
- 'Aws::Plugins::UserAgent' => "#{core_plugins}/user_agent.rb",
323
- 'Aws::Plugins::HelpfulSocketErrors' => "#{core_plugins}/helpful_socket_errors.rb",
324
- 'Aws::Plugins::RetryErrors' => "#{core_plugins}/retry_errors.rb",
325
- 'Aws::Plugins::GlobalConfiguration' => "#{core_plugins}/global_configuration.rb",
326
- 'Aws::Plugins::RegionalEndpoint' => "#{core_plugins}/regional_endpoint.rb",
327
- 'Aws::Plugins::ResponsePaging' => "#{core_plugins}/response_paging.rb",
328
- 'Aws::Plugins::StubResponses' => "#{core_plugins}/stub_responses.rb",
329
- 'Aws::Plugins::IdempotencyToken' => "#{core_plugins}/idempotency_token.rb",
330
- }
331
- end
332
-
333
- def protocol_plugins(protocol)
334
- {
335
- 'json' => { 'Aws::Plugins::Protocols::JsonRpc' => "#{core_plugins}/protocols/json_rpc.rb" },
336
- 'rest-json' => { 'Aws::Plugins::Protocols::RestJson' => "#{core_plugins}/protocols/rest_json.rb" },
337
- 'rest-xml' => { 'Aws::Plugins::Protocols::RestXml' => "#{core_plugins}/protocols/rest_xml.rb" },
338
- 'query' => { 'Aws::Plugins::Protocols::Query' => "#{core_plugins}/protocols/query.rb" },
339
- 'ec2' => { 'Aws::Plugins::Protocols::EC2' => "#{core_plugins}/protocols/ec2.rb" },
340
- nil => {}
341
- }[protocol]
342
- end
343
-
344
- def signature_plugins
345
- case @api['metadata']['signatureVersion']
346
- when 'v4'
347
- { 'Aws::Plugins::SignatureV4' => "#{core_plugins}/signature_v4.rb" }
348
- when 'v2'
349
- { 'Aws::Plugins::SignatureV2' => "#{core_plugins}/signature_v2.rb" }
350
- else
351
- {}
352
- end
353
- end
354
-
355
- def waiter_table
356
- # insert one row for each supported service
357
- table = []
358
- @waiters['waiters'].each_pair do |name, waiter|
359
- table << [underscore(name), "{##{underscore(waiter['operation'])}}", waiter['delay'], waiter['maxAttempts']]
360
- end
361
- table = table.sort_by(&:first)
362
-
363
- # header row
364
- table.unshift(['waiter_name', 'params', ':delay', ':max_attempts'])
365
- markdown_table(table)
366
- end
367
-
368
- # @api private
369
- class ClientPlugin
370
-
371
- def initialize(options)
372
- @class_name = options.fetch(:class_name)
373
- @options = options.fetch(:options)
374
- @require_path = options.fetch(:path).split('/lib/').last
375
- end
376
-
377
- # @return [String]
378
- attr_reader :class_name
379
-
380
- # @return [Array<Seahorse::Client::Plugin::PluginOption>]
381
- attr_reader :options
382
-
383
- # @return [String]
384
- attr_reader :require_path
385
-
386
- end
387
- end
388
- end
389
- end
@@ -1,166 +0,0 @@
1
- module AwsSdkCodeGenerator
2
- module Generators
3
- class ClientOperationDocumentation
4
-
5
- include Helper
6
-
7
- def self.apply(options)
8
- new(options).apply(options)
9
- end
10
-
11
- # @option options [required, Hash] :api
12
- # @option options [required, String] :service_identifier
13
- # @option options [required, String] :operation_name
14
- # @option options [required, Hash] :operation
15
- # @option options [Hash] :examples
16
- def initialize(options)
17
- @api = options.fetch(:api)
18
- @service_id = options.fetch(:service_identifier)
19
- @operation_name = options.fetch(:operation_name)
20
- @method_name = underscore(@operation_name)
21
- @operation = options.fetch(:operation)
22
- @examples = options.fetch(:examples, nil) || { 'examples' => {} }
23
- end
24
-
25
- def apply(options)
26
- method = options.fetch(:method)
27
- method.docstring do |docstring|
28
- apply_operation_docs(docstring)
29
- apply_option_tags(docstring)
30
- apply_return_tags(docstring)
31
- apply_shared_examples(docstring)
32
- apply_examples_from_disk(docstring)
33
- apply_request_syntax_example(docstring)
34
- apply_response_struture_example(docstring)
35
- apply_overload_tag(docstring)
36
- end
37
- end
38
-
39
- private
40
-
41
- def apply_operation_docs(docstring)
42
- docstring.append(markdown(@operation['documentation']))
43
- end
44
-
45
- def apply_option_tags(docstring)
46
- # document the `:response_target` option if the response is streaming
47
- if output = shape(@operation['output'])
48
- if output['payload'] && output['members'][output['payload']]['streaming']
49
- docstring.lines.concat(Dsl::OptionTag.new(
50
- name: 'response_target',
51
- type: 'String, IO',
52
- param: 'params',
53
- required: false,
54
- docstring: 'Where to write response data, file path, or IO object.'
55
- ).lines)
56
- end
57
- end
58
-
59
- if input_shape = shape(@operation['input'])
60
- required = input_shape['required'] || []
61
- input_shape['members'].each_pair do |member_name, member_ref|
62
- docstring.lines.concat(Dsl::OptionTag.new(
63
- name: underscore(member_name),
64
- type: ruby_input_type(member_ref),
65
- param: 'params',
66
- required: required.include?(member_name),
67
- docstring: documentation(member_ref),
68
- ).lines)
69
- end
70
- end
71
- end
72
-
73
- def apply_return_tags(docstring)
74
- output_shape = shape(@operation['output'])
75
- resp = '{Seahorse::Client::Response response}'
76
- if output_shape && output_shape['members'].size > 0
77
- type = ruby_type(@operation['output'])
78
- returns = "@return [#{type}] Returns a #{resp} object which responds to "
79
- returns << "the following methods:\n\n"
80
- output_shape['members'].each_pair do |mname, mref|
81
- mtype = ruby_type(mref).gsub(/</, '&lt;').gsub(/>/, '&gt;')
82
- returns << " * {#{type}##{underscore(mname)} ##{mname}} => #{mtype}\n"
83
- end
84
- docstring.append(returns)
85
- else
86
- docstring.append("@return [Struct] Returns an empty #{resp}.")
87
- end
88
- end
89
-
90
- def apply_shared_examples(docstring)
91
- (@examples[@operation_name] || []).size.times do |n|
92
- begin
93
- # TODO : known issue with an ec2 shared example that
94
- # attempts to document a member that is not
95
- # present in the model any longer (intentionally
96
- # removed in customizations) - raises runtime
97
- # error. This should be cleaned up.
98
- docstring.append(
99
- SharedExample.new(
100
- operation_name: @operation_name,
101
- api: @api,
102
- examples: @examples,
103
- example: n
104
- ).to_s
105
- )
106
- rescue
107
- end
108
- end
109
- end
110
-
111
- def apply_shared_example(docstring, example)
112
- return
113
-
114
- input_comments = json_ex['comments']['input']
115
- input = SharedExample.new(json_ex['input'], method_name, operation, input_comments).to_str_input
116
- parts = []
117
- parts << "@example Example: #{json_ex['title']}\n\n"
118
- parts << " # #{json_ex['description']}\n\n"
119
- parts += input.lines.map { |line| " " + line }
120
- if json_ex['output']
121
- output_comments = json_ex['comments']['output']
122
- output = SharedExample.new(json_ex['output'], method_name, operation, output_comments).to_str_output
123
- parts << "\n\n # resp.to_h outputs the following:\n"
124
- parts += output.lines.map { |line| " " + line }
125
- end
126
- tag(parts.join)
127
- end
128
-
129
- def apply_examples_from_disk(docstring)
130
- examples = File.expand_path('../../../../../../doc-src/examples', __FILE__)
131
- glob = "#{examples}/#{@service_id}/client/#{@method_name}/*.rb"
132
- Dir.glob(glob).map do |path|
133
- title = File.basename(path).split(/\./).first
134
- title = title.sub(/^\d+_/, '').gsub(/_/, ' ')
135
- title = title[0].upcase + title[1..-1]
136
- docstring.append("\n@example #{title}")
137
- docstring.append(" " + File.read(path).lines.join(' '))
138
- end
139
- end
140
-
141
- def apply_request_syntax_example(docstring)
142
- if @operation['input']
143
- syntax = SyntaxExample.new(
144
- struct_shape: shape(@operation['input']),
145
- api: @api,
146
- indent: ' '
147
- ).format.strip
148
- docstring.append("\n@example Request syntax with placeholder values")
149
- docstring.append(" resp = client.#{@method_name}(#{syntax})")
150
- end
151
- end
152
-
153
- def apply_response_struture_example(docstring)
154
- output = @operation['output']
155
- if output && shape(output)['members'].size > 0
156
- docstring.append(ResponseStructureExample.new(shape_ref:output, api:@api).to_s)
157
- end
158
- end
159
-
160
- def apply_overload_tag(docstring)
161
- docstring.append("@overload #{@method_name}(params = {})")
162
- end
163
-
164
- end
165
- end
166
- end