aws-sdk-resources 2.11.549

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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/lib/aws-sdk-resources.rb +91 -0
  3. data/lib/aws-sdk-resources/batch.rb +143 -0
  4. data/lib/aws-sdk-resources/builder.rb +85 -0
  5. data/lib/aws-sdk-resources/builder_sources.rb +105 -0
  6. data/lib/aws-sdk-resources/collection.rb +107 -0
  7. data/lib/aws-sdk-resources/definition.rb +331 -0
  8. data/lib/aws-sdk-resources/documenter.rb +70 -0
  9. data/lib/aws-sdk-resources/documenter/base_operation_documenter.rb +279 -0
  10. data/lib/aws-sdk-resources/documenter/data_operation_documenter.rb +25 -0
  11. data/lib/aws-sdk-resources/documenter/has_many_operation_documenter.rb +69 -0
  12. data/lib/aws-sdk-resources/documenter/has_operation_documenter.rb +66 -0
  13. data/lib/aws-sdk-resources/documenter/operation_documenter.rb +20 -0
  14. data/lib/aws-sdk-resources/documenter/resource_operation_documenter.rb +53 -0
  15. data/lib/aws-sdk-resources/documenter/waiter_operation_documenter.rb +77 -0
  16. data/lib/aws-sdk-resources/errors.rb +15 -0
  17. data/lib/aws-sdk-resources/operation_methods.rb +83 -0
  18. data/lib/aws-sdk-resources/operations.rb +280 -0
  19. data/lib/aws-sdk-resources/options.rb +17 -0
  20. data/lib/aws-sdk-resources/request.rb +39 -0
  21. data/lib/aws-sdk-resources/request_params.rb +140 -0
  22. data/lib/aws-sdk-resources/resource.rb +243 -0
  23. data/lib/aws-sdk-resources/services/ec2.rb +21 -0
  24. data/lib/aws-sdk-resources/services/ec2/instance.rb +29 -0
  25. data/lib/aws-sdk-resources/services/iam.rb +19 -0
  26. data/lib/aws-sdk-resources/services/s3.rb +20 -0
  27. data/lib/aws-sdk-resources/services/s3/bucket.rb +131 -0
  28. data/lib/aws-sdk-resources/services/s3/encryption.rb +21 -0
  29. data/lib/aws-sdk-resources/services/s3/encryption/client.rb +369 -0
  30. data/lib/aws-sdk-resources/services/s3/encryption/decrypt_handler.rb +174 -0
  31. data/lib/aws-sdk-resources/services/s3/encryption/default_cipher_provider.rb +63 -0
  32. data/lib/aws-sdk-resources/services/s3/encryption/default_key_provider.rb +38 -0
  33. data/lib/aws-sdk-resources/services/s3/encryption/encrypt_handler.rb +50 -0
  34. data/lib/aws-sdk-resources/services/s3/encryption/errors.rb +13 -0
  35. data/lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb +56 -0
  36. data/lib/aws-sdk-resources/services/s3/encryption/io_decrypter.rb +29 -0
  37. data/lib/aws-sdk-resources/services/s3/encryption/io_encrypter.rb +69 -0
  38. data/lib/aws-sdk-resources/services/s3/encryption/key_provider.rb +29 -0
  39. data/lib/aws-sdk-resources/services/s3/encryption/kms_cipher_provider.rb +71 -0
  40. data/lib/aws-sdk-resources/services/s3/encryption/materials.rb +58 -0
  41. data/lib/aws-sdk-resources/services/s3/encryption/utils.rb +79 -0
  42. data/lib/aws-sdk-resources/services/s3/file_downloader.rb +169 -0
  43. data/lib/aws-sdk-resources/services/s3/file_part.rb +75 -0
  44. data/lib/aws-sdk-resources/services/s3/file_uploader.rb +58 -0
  45. data/lib/aws-sdk-resources/services/s3/multipart_file_uploader.rb +187 -0
  46. data/lib/aws-sdk-resources/services/s3/multipart_upload.rb +42 -0
  47. data/lib/aws-sdk-resources/services/s3/multipart_upload_error.rb +16 -0
  48. data/lib/aws-sdk-resources/services/s3/object.rb +290 -0
  49. data/lib/aws-sdk-resources/services/s3/object_copier.rb +99 -0
  50. data/lib/aws-sdk-resources/services/s3/object_multipart_copier.rb +180 -0
  51. data/lib/aws-sdk-resources/services/s3/object_summary.rb +73 -0
  52. data/lib/aws-sdk-resources/services/s3/presigned_post.rb +651 -0
  53. data/lib/aws-sdk-resources/services/sns.rb +7 -0
  54. data/lib/aws-sdk-resources/services/sns/message_verifier.rb +171 -0
  55. data/lib/aws-sdk-resources/services/sqs.rb +7 -0
  56. data/lib/aws-sdk-resources/services/sqs/queue_poller.rb +521 -0
  57. data/lib/aws-sdk-resources/source.rb +39 -0
  58. metadata +118 -0
@@ -0,0 +1,331 @@
1
+ require 'set'
2
+
3
+ module Aws
4
+ module Resources
5
+
6
+ # Given a resource definition document, a {Definition} can build a set
7
+ # of related resource classes.
8
+ class Definition
9
+
10
+ # @param [Hash] definition
11
+ # @option options [String] :source_path
12
+ def initialize(definition = {}, options = {})
13
+ @source = definition
14
+ @source_path = options[:source_path]
15
+ end
16
+
17
+ # @param [Module<Service>] namespace
18
+ # @return [void]
19
+ def apply(namespace)
20
+ build_resource_classes(namespace)
21
+ each_resource_class(namespace) do |resource, definition|
22
+ define_load(namespace, resource, definition['load'])
23
+ define_actions(namespace, resource, definition['actions'] || {})
24
+ define_batch_actions(namespace, resource, definition['batchActions'] || {})
25
+ define_waiters(namespace, resource, definition['waiters'] || {})
26
+ define_has(namespace, resource, definition['has'] || {})
27
+ define_has_many(namespace, resource, definition['hasMany'] || {})
28
+ define_data_attributes(namespace, resource, definition)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def build_resource_classes(namespace)
35
+ each_definition do |name, definition|
36
+ resource_class = Class.new(Resource)
37
+ resource_class.client_class = namespace::Client
38
+ resource_class.resource_name = name
39
+ (definition['identifiers'] || []).each do |identifier|
40
+ resource_class.add_identifier(underscore(identifier['name']))
41
+ end
42
+ namespace.const_set(name, resource_class)
43
+ end
44
+ end
45
+
46
+ def each_resource_class(namespace, &block)
47
+ each_definition do |name, definition|
48
+ yield(namespace.const_get(name), definition)
49
+ end
50
+ end
51
+
52
+ def define_batch_actions(namespace, resource, batch_actions)
53
+ batch_actions.each do |name, definition|
54
+ method_name = "batch_" + underscore(name)
55
+ method_name += '!' if dangerous?(name, definition)
56
+ operation = build_operation(namespace, resource, definition)
57
+ resource.add_batch_operation(method_name, operation)
58
+ end
59
+ end
60
+
61
+ def dangerous?(name, definition)
62
+ if
63
+ name.match(/delete/i) ||
64
+ name.match(/terminate/i) ||
65
+ definition['request']['operation'].match(/delete/i) ||
66
+ definition['request']['operation'].match(/terminate/i)
67
+ then
68
+ true
69
+ else
70
+ false
71
+ end
72
+ end
73
+
74
+ def define_data_attributes(namespace, resource, definition)
75
+ if shape_name = definition['shape']
76
+ shape = resource.client_class.api.metadata['shapes'][shape_name]
77
+ shape.member_names.each do |member_name|
78
+ if
79
+ resource.instance_methods.include?(member_name) ||
80
+ data_attribute_is_an_identifier?(member_name, resource, definition)
81
+ then
82
+ next # some data attributes are duplicates to identifiers
83
+ else
84
+ resource.add_data_attribute(member_name)
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ def data_attribute_is_an_identifier?(attr_name, resource, definition)
91
+ resource.identifiers.include?(attr_name) ||
92
+ definition['identifiers'].any? { |i| underscore(i['dataMember']) == attr_name.to_s }
93
+ end
94
+
95
+ def define_load(namespace, resource, definition)
96
+ return unless definition
97
+ resource.load_operation = Operations::LoadOperation.new(
98
+ request: define_request(definition['request']),
99
+ path: underscore(definition['path']),
100
+ source: source(definition),
101
+ )
102
+ end
103
+
104
+ def define_actions(namespace, resource, actions)
105
+ actions.each do |name, action|
106
+ operation = build_operation(namespace, resource, action)
107
+ resource.add_operation(underscore(name), operation)
108
+ end
109
+ end
110
+
111
+ def define_waiters(namespace, resource, waiters)
112
+ waiters.each do |name, definition|
113
+ operation = build_waiter_operation(namespace, resource, definition)
114
+ resource.add_operation("wait_until_#{underscore(name)}", operation)
115
+ end
116
+ end
117
+
118
+ def build_operation(namespace, resource, definition)
119
+ if definition['resource']
120
+ build_resource_action(namespace, resource, definition)
121
+ else
122
+ build_basic_action(namespace, resource, definition)
123
+ end
124
+ end
125
+
126
+ def build_basic_action(namespace, resource, definition)
127
+ Operations::Operation.new(
128
+ request: define_request(definition['request']),
129
+ source: source(definition)
130
+ )
131
+ end
132
+
133
+ def build_resource_action(namespace, resource, definition)
134
+ builder = define_builder(namespace, definition['resource'])
135
+ if path = definition['resource']['path']
136
+ builder.sources << BuilderSources::ResponsePath.new({
137
+ source: underscore(path),
138
+ target: :data,
139
+ })
140
+ end
141
+ Operations::ResourceOperation.new(
142
+ request: define_request(definition['request']),
143
+ builder: builder,
144
+ source: source(definition)
145
+ )
146
+ end
147
+
148
+ def has_many(namespace, resource, definition)
149
+ builder = define_builder(namespace, definition['resource'])
150
+ if path = definition['resource']['path']
151
+ builder.sources << BuilderSources::ResponsePath.new({
152
+ source: underscore(path),
153
+ target: :data,
154
+ })
155
+ end
156
+ Operations::HasManyOperation.new(
157
+ request: define_request(definition['request']),
158
+ builder: builder,
159
+ source: source(definition),
160
+ limit_key: limit_key(resource, definition))
161
+ end
162
+
163
+ def build_waiter_operation(namespace, resource, definition)
164
+ Operations::WaiterOperation.new(
165
+ waiter_name: underscore(definition['waiterName']).to_sym,
166
+ waiter_params: request_params(definition['params']),
167
+ path: underscore(definition['path'])
168
+ )
169
+ end
170
+
171
+ def limit_key(resource, definition)
172
+ operation_name = definition['request']['operation']
173
+ operation = resource.client_class.api.operation(underscore(operation_name))
174
+ if operation[:pager]
175
+ operation[:pager].limit_key
176
+ else
177
+ nil
178
+ end
179
+ end
180
+
181
+ def define_request(definition)
182
+ Request.new(
183
+ method_name: underscore(definition['operation']),
184
+ params: request_params(definition['params'] || [])
185
+ )
186
+ end
187
+
188
+ def request_params(params)
189
+ params.map do |definition|
190
+ send("#{definition['source']}_request_param", definition)
191
+ end
192
+ end
193
+
194
+ def identifier_request_param(definition)
195
+ RequestParams::Identifier.new({
196
+ target: underscore(definition['target']),
197
+ name: underscore(definition['name']).to_sym,
198
+ })
199
+ end
200
+
201
+ def data_request_param(definition)
202
+ RequestParams::DataMember.new({
203
+ target: underscore(definition['target']),
204
+ path: underscore(definition['path']),
205
+ })
206
+ end
207
+
208
+ def string_request_param(definition)
209
+ RequestParams::Literal.new({
210
+ target: underscore(definition['target']),
211
+ value: definition['value'],
212
+ })
213
+ end
214
+ alias integer_request_param string_request_param
215
+ alias float_request_param string_request_param
216
+ alias boolean_request_param string_request_param
217
+ alias null_request_param string_request_param
218
+
219
+ def define_has_many(namespace, resource, has_many)
220
+ has_many.each do |name, definition|
221
+ operation = has_many(namespace, resource, definition)
222
+ resource.add_operation(underscore(name), operation)
223
+ end
224
+ end
225
+
226
+ def define_has(namespace, resource, has)
227
+ has.each do |name, definition|
228
+ has_operation(namespace, resource, name, definition)
229
+ end
230
+ end
231
+
232
+ def has_operation(namespace, resource, name, definition)
233
+ builder = define_builder(namespace, definition['resource'])
234
+ if path = definition['resource']['path']
235
+ builder.sources << BuilderSources::DataMember.new({
236
+ source: underscore(path),
237
+ target: :data,
238
+ })
239
+ end
240
+ operation = Operations::HasOperation.new(
241
+ builder: builder,
242
+ source: source(definition))
243
+ resource.add_operation(underscore(name), operation)
244
+ end
245
+
246
+ def define_builder(namespace, definition)
247
+ Builder.new(
248
+ resource_class: namespace.const_get(definition['type']),
249
+ sources: builder_sources(definition['identifiers'] || [])
250
+ )
251
+ end
252
+
253
+ def builder_sources(sources)
254
+ sources.map do |definition|
255
+ send("#{definition['source']}_builder_source", definition, sources)
256
+ end
257
+ end
258
+
259
+ def input_builder_source(definition, sources)
260
+ arguments = sources.select { |s| s['source'] == 'input' }
261
+ BuilderSources::Argument.new({
262
+ source: arguments.index(definition),
263
+ target: underscore(definition['target']),
264
+ })
265
+ end
266
+
267
+ def identifier_builder_source(definition, _)
268
+ BuilderSources::Identifier.new({
269
+ source: underscore(definition['name']),
270
+ target: underscore(definition['target']),
271
+ })
272
+ end
273
+
274
+ def data_builder_source(definition, _)
275
+ BuilderSources::DataMember.new({
276
+ source: underscore(definition['path']),
277
+ target: underscore(definition['target']),
278
+ })
279
+ end
280
+
281
+ def requestParameter_builder_source(definition, _)
282
+ BuilderSources::RequestParameter.new({
283
+ source: underscore(definition['path']),
284
+ target: underscore(definition['target']),
285
+ })
286
+ end
287
+
288
+ def response_builder_source(definition, _)
289
+ BuilderSources::ResponsePath.new({
290
+ source: underscore(definition['path']),
291
+ target: underscore(definition['target']),
292
+ })
293
+ end
294
+
295
+ def string_builder_source(definition, _)
296
+ BuilderSources::ResponsePath.new({
297
+ source: underscore(definition['value']),
298
+ target: underscore(definition['target']),
299
+ })
300
+ end
301
+
302
+ def svc_definition
303
+ @source['service'] || {}
304
+ end
305
+
306
+ def resource_definitions
307
+ @source['resources'] || {}
308
+ end
309
+
310
+ def each_definition(&block)
311
+ yield('Resource', svc_definition)
312
+ resource_definitions.each(&block)
313
+ end
314
+
315
+ def underscore(str)
316
+ if str
317
+ str.gsub(/\w+/) { |part| Seahorse::Util.underscore(part) }
318
+ end
319
+ end
320
+
321
+ def source(definition)
322
+ if ENV['SOURCE']
323
+ Source.new(definition, @source_path)
324
+ else
325
+ nil
326
+ end
327
+ end
328
+
329
+ end
330
+ end
331
+ end
@@ -0,0 +1,70 @@
1
+ require 'json'
2
+
3
+ module Aws
4
+ module Resources
5
+ class Documenter
6
+
7
+ autoload :BaseOperationDocumenter, 'aws-sdk-resources/documenter/base_operation_documenter'
8
+ autoload :HasOperationDocumenter, 'aws-sdk-resources/documenter/has_operation_documenter'
9
+ autoload :HasManyOperationDocumenter, 'aws-sdk-resources/documenter/has_many_operation_documenter'
10
+ autoload :OperationDocumenter, 'aws-sdk-resources/documenter/operation_documenter'
11
+ autoload :ResourceOperationDocumenter, 'aws-sdk-resources/documenter/resource_operation_documenter'
12
+ autoload :WaiterOperationDocumenter, 'aws-sdk-resources/documenter/waiter_operation_documenter'
13
+
14
+ class << self
15
+
16
+ include Seahorse::Model::Shapes
17
+
18
+ def apply_customizations
19
+ document_s3_object_upload_file_additional_options
20
+ document_s3_object_copy_from_options
21
+ end
22
+
23
+ private
24
+
25
+ def document_s3_object_upload_file_additional_options
26
+ input = Aws::S3::Client.api.operation(:create_multipart_upload).input
27
+ opts = input.shape.member_names - [:bucket, :key]
28
+ tags = opts.map do |opt|
29
+ ref = input.shape.member(opt)
30
+ type = case ref.shape
31
+ when StructureShape then 'Structure'
32
+ when ListShape then 'Array'
33
+ when MapShape then 'Hash'
34
+ when StringShape then 'String'
35
+ when IntegerShape then 'Integer'
36
+ when FloatShape then 'Float'
37
+ when BooleanShape then 'Boolean'
38
+ when TimestampShape then 'Time'
39
+ when BlobShape then 'IO'
40
+ else
41
+ raise "unhandled shape class `#{ref.shape.class.name}'"
42
+ end
43
+ docs = ref.documentation || ref.shape.documentation
44
+ "@option options [#{type}] :#{opt} #{docs}"
45
+ end
46
+ tags = YARD::DocstringParser.new.parse(tags).to_docstring.tags
47
+ m = YARD::Registry['Aws::S3::Object#upload_file']
48
+ tags.each { |tag| m.add_tag(tag) }
49
+ end
50
+
51
+ def document_s3_object_copy_from_options
52
+ copy_from = YARD::Registry['Aws::S3::Object#copy_from']
53
+ copy_to = YARD::Registry['Aws::S3::Object#copy_to']
54
+ existing_tags = copy_from.tags
55
+ existing_tags.each do |tag|
56
+ if tag.tag_name == 'option' && tag.pair.name != ":copy_source"
57
+ copy_from.add_tag(tag)
58
+ copy_to.add_tag(tag)
59
+ end
60
+ end
61
+ end
62
+
63
+ def tag(string)
64
+ YARD::DocstringParser.new.parse(string).to_docstring.tags.first
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,279 @@
1
+ require 'set'
2
+
3
+ module Aws
4
+ module Resources
5
+ class Documenter
6
+ class BaseOperationDocumenter
7
+
8
+ include Api::Docs::Utils
9
+ include Seahorse::Model::Shapes
10
+
11
+ def initialize(yard_class, resource_class, operation_name, operation)
12
+ @yard_class = yard_class
13
+ @resource_class = resource_class
14
+ @resource_class_name = @resource_class.name.split('::').last
15
+ @operation_name = operation_name.to_s
16
+ @operation = operation
17
+ @source = @operation.source
18
+ if @operation.respond_to?(:request)
19
+ @api_request_name = @operation.request.method_name
20
+ @api_request = @resource_class.client_class.api.operation(@api_request_name)
21
+ @api_request_params = @operation.request.params
22
+ @request_operation_name = @operation.request.method_name.to_s
23
+ @called_operation = "Client##{@api_request_name}"
24
+ @yard_client_operation = YARD::Registry["#{@resource_class.client_class.name}##{api_request_name}"]
25
+
26
+ end
27
+ if @operation.respond_to?(:builder)
28
+ @builder = @operation.builder
29
+ @target_resource_class = @builder.resource_class
30
+ @target_resource_class_name = @target_resource_class.name.split('::').last
31
+ end
32
+ end
33
+
34
+ # @return [YARD::CodeObject::ClassObject]
35
+ attr_reader :yard_class
36
+
37
+ # @return [Class<Resource>] Returns the resource class this
38
+ # operation belongs to.
39
+ attr_reader :resource_class
40
+
41
+ # @return [String] The name of this resource operation.
42
+ attr_reader :operation_name
43
+
44
+ # @return [String] Returns the name of the resource class being
45
+ # documented without the namespace prefix. Example:
46
+ #
47
+ # * Aws::S3::Resource => 'Resource'
48
+ # * Aws::S3::Bucket => 'Bucket'
49
+ #
50
+ attr_reader :resource_class_name
51
+
52
+ # @return [Class<Resource>,nil] Returns the class of the resource
53
+ # returned by invoking this operation. Returns `nil` if this operation
54
+ # does not return any resource objects.
55
+ attr_reader :target_resource_class
56
+
57
+ # @return [String,nil] Returns the name of the resource class
58
+ # returned by this operation. This is the base name of
59
+ # the class without a namespace prefix. Returns `nil` if this
60
+ # operation does not return any resource objects.
61
+ attr_reader :target_resource_class_name
62
+
63
+ # @return [String,nil] Returns the name of the API operation called
64
+ # on the client. Returns `nil` if this operation does not make
65
+ # any API requests.
66
+ attr_reader :api_request_name
67
+
68
+ # @return [Seahorse::Model::Operation,nil] Returns the model of the
69
+ # API operation called. Returns `nil` if this operation does not make
70
+ # any API requests.
71
+ attr_reader :api_request
72
+
73
+ # @return [Array<Resources::RequestParams::Base>, nil] Returns the
74
+ # parameters this operation binds to the made request. Returns `nil`
75
+ # if this operation does not make a request.
76
+ attr_reader :api_request_params
77
+
78
+ # @return [String,nil] Returns the `Client#operation_name` reference.
79
+ # This is useful for generating `@see` tags and `{links}`.
80
+ attr_reader :called_operation
81
+
82
+ # @return [Builder,nil] Returns the resource builder for
83
+ # this operation. Returns `nil` if this operation does not build
84
+ # and return resource objects.
85
+ attr_reader :builder
86
+
87
+ # @return [Source]
88
+ attr_reader :source
89
+
90
+ # Constructs and returns a new YARD method object for this operation.
91
+ # @return [YARD::CodeObject::MethodObject]
92
+ def method_object
93
+ if m = YARD::Registry[@resource_class.name + "##{operation_name}"]
94
+ else
95
+ m = YARD::CodeObjects::MethodObject.new(yard_class, operation_name)
96
+ m.docstring = docstring
97
+ m.parameters = parameters
98
+ end
99
+ m.scope = :instance
100
+ if source
101
+ m.source_type = :json
102
+ m.source = source.format
103
+ filename = source.file
104
+ filename = filename.match('(aws-sdk-core/apis/.+)')[1]
105
+ m.add_file(filename, nil, true)
106
+ end
107
+ tags.each do |tag|
108
+ m.add_tag(tag)
109
+ end
110
+ m
111
+ end
112
+
113
+ private
114
+
115
+ def parameters
116
+ if option_tags.empty?
117
+ []
118
+ else
119
+ [['options', '{}']]
120
+ end
121
+ end
122
+
123
+ def docstring
124
+ ''
125
+ end
126
+
127
+ def tags
128
+ (option_tags + example_tags + [return_tag] + see_also_tags).compact
129
+ end
130
+
131
+ # This method should be overridden in sub-classes to add YARD tags
132
+ # to the method code object.
133
+ # @return [Array<YARD::Tag>]
134
+ def example_tags
135
+ if api_request && api_request.input
136
+ [request_syntax_example_tag]
137
+ else
138
+ []
139
+ end
140
+ end
141
+
142
+ def request_syntax_example_tag
143
+ input = operation_input_ref(api_request, without: fixed_param_names)
144
+ params = Api::Docs::ParamFormatter.new(input).format
145
+ example = "#{variable_name}.#{operation_name}(#{params})"
146
+ example = "@example Request syntax example with placeholder values" +
147
+ "\n\n " + example.lines.join(' ')
148
+ tag(example)
149
+ end
150
+
151
+ def option_tags
152
+ if api_request && api_request.input
153
+ skip = fixed_param_names
154
+ tags = []
155
+ @yard_client_operation.tags.each do |tag|
156
+ if YARD::Tags::OptionTag === tag
157
+ next if skip.include?(tag.pair.name[1..-1]) # remove `:` prefix
158
+ tags << tag
159
+ end
160
+ end
161
+ tags
162
+ else
163
+ []
164
+ end
165
+ end
166
+
167
+ # Returns a set of root input params that are provided by default
168
+ # by this operation. These params should not be documented in syntax
169
+ # examples or in option tags.
170
+ def fixed_param_names
171
+ if api_request_params
172
+ Set.new(api_request_params.map { |p| p.target.split(/\b/).first })
173
+ else
174
+ Set.new
175
+ end
176
+ end
177
+
178
+ # If this operation makes an API request, then a `@see` tag is
179
+ # returned that references the client API operation.
180
+ # @return [Array<YARD::Tag>]
181
+ def see_also_tags
182
+ tags = []
183
+ tags += related_resource_operation_tags if target_resource_class
184
+ tags += called_operation_tag if called_operation
185
+ tags
186
+ end
187
+
188
+ def called_operation_tag
189
+ tag = "@see #{called_operation}"
190
+ YARD::DocstringParser.new.parse(tag).to_docstring.tags
191
+ end
192
+
193
+ def related_resource_operation_tags
194
+ tags = []
195
+ resource_class.operations.each do |name,op|
196
+ if
197
+ name.to_s != self.operation_name &&
198
+ op.respond_to?(:builder) &&
199
+ op.builder.resource_class == target_resource_class
200
+ then
201
+ tags << "@see ##{name}"
202
+ end
203
+ end
204
+ YARD::DocstringParser.new.parse(tags.sort.join("\n")).to_docstring.tags
205
+ end
206
+
207
+ # Returns a suitable variable name for the resource class being
208
+ # documented:
209
+ #
210
+ # Aws::S3::Resource => 's3'
211
+ # Aws::S3::Bucket => 'bucket'
212
+ #
213
+ def variable_name
214
+ parts = resource_class.name.split('::')
215
+ (parts.last == 'Resource' ? parts[-2] : parts[-1]).downcase
216
+ end
217
+
218
+ def path_type
219
+ case path_shape
220
+ when StructureShape then 'Structure'
221
+ when ListShape then 'Array'
222
+ when MapShape then 'Hash'
223
+ when StringShape then 'String'
224
+ when IntegerShape then 'Integer'
225
+ when FloatShape then 'Float'
226
+ when BooleanShape then 'Boolean'
227
+ when TimestampShape then 'Time'
228
+ when BlobShape then 'IO'
229
+ else
230
+ raise "unhandled shape class `#{path_shape.class.name}'"
231
+ end
232
+ end
233
+
234
+ def path_shape
235
+ resolve_shape(response_shape, @operation.path)
236
+ end
237
+
238
+ # Returns the output shape for the called operation.
239
+ def response_shape
240
+ api = resource_class.client_class.api
241
+ output = api.operation(@operation.request.method_name).output
242
+ output ? output.shape : nil
243
+ end
244
+
245
+ def resolve_shape(shape, path)
246
+ if path != '@'
247
+ shape = path.scan(/\w+|\[.*?\]/).inject(shape) do |shape, part|
248
+ if part[0] == '['
249
+ shape.member.shape
250
+ else
251
+ shape.member(part).shape
252
+ end
253
+ end
254
+ end
255
+ end
256
+
257
+ def param_type(ref)
258
+ case ref.shape
259
+ when BlobShape then 'IO'
260
+ when BooleanShape then 'Boolean'
261
+ when FloatShape then 'Float'
262
+ when IntegerShape then 'Integer'
263
+ when ListShape then 'Array'
264
+ when MapShape then 'Hash'
265
+ when StringShape then 'String'
266
+ when StructureShape then 'Hash'
267
+ when TimestampShape then 'Time'
268
+ else raise 'unhandled type'
269
+ end
270
+ end
271
+
272
+ def docs(ref)
273
+ ref.documentation || ref.shape.documentation
274
+ end
275
+
276
+ end
277
+ end
278
+ end
279
+ end