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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/lib/aws-sdk-code-generator/api.rb +150 -0
  3. data/lib/aws-sdk-code-generator/apply_docs.rb +15 -2
  4. data/lib/aws-sdk-code-generator/client_constructor.rb +39 -0
  5. data/lib/aws-sdk-code-generator/client_operation_documentation.rb +282 -0
  6. data/lib/aws-sdk-code-generator/client_operation_list.rb +148 -0
  7. data/lib/aws-sdk-code-generator/client_response_structure_example.rb +115 -0
  8. data/lib/aws-sdk-code-generator/code_builder.rb +146 -133
  9. data/lib/aws-sdk-code-generator/crosslink.rb +42 -0
  10. data/lib/aws-sdk-code-generator/docstring.rb +199 -0
  11. data/lib/aws-sdk-code-generator/error_list.rb +77 -0
  12. data/lib/aws-sdk-code-generator/errors.rb +2 -0
  13. data/lib/aws-sdk-code-generator/eventstream_example.rb +220 -0
  14. data/lib/aws-sdk-code-generator/gem_builder.rb +42 -25
  15. data/lib/aws-sdk-code-generator/hash_formatter.rb +5 -2
  16. data/lib/aws-sdk-code-generator/helper.rb +86 -119
  17. data/lib/aws-sdk-code-generator/plugin_list.rb +147 -0
  18. data/lib/aws-sdk-code-generator/resource_action.rb +69 -0
  19. data/lib/aws-sdk-code-generator/resource_action_code.rb +57 -0
  20. data/lib/aws-sdk-code-generator/resource_association.rb +37 -0
  21. data/lib/aws-sdk-code-generator/resource_attribute.rb +76 -0
  22. data/lib/aws-sdk-code-generator/resource_batch_action.rb +56 -0
  23. data/lib/aws-sdk-code-generator/resource_batch_action_code.rb +136 -0
  24. data/lib/aws-sdk-code-generator/resource_batch_action_documentation.rb +108 -0
  25. data/lib/aws-sdk-code-generator/resource_batch_builder.rb +212 -0
  26. data/lib/aws-sdk-code-generator/resource_builder.rb +48 -0
  27. data/lib/aws-sdk-code-generator/resource_client_request.rb +62 -0
  28. data/lib/aws-sdk-code-generator/resource_client_request_documentation.rb +81 -0
  29. data/lib/aws-sdk-code-generator/resource_client_request_params.rb +86 -0
  30. data/lib/aws-sdk-code-generator/resource_data_method.rb +60 -0
  31. data/lib/aws-sdk-code-generator/resource_has_association.rb +117 -0
  32. data/lib/aws-sdk-code-generator/resource_has_many_association.rb +52 -0
  33. data/lib/aws-sdk-code-generator/resource_has_many_association_code.rb +76 -0
  34. data/lib/aws-sdk-code-generator/resource_identifier.rb +44 -0
  35. data/lib/aws-sdk-code-generator/resource_identifiers_method.rb +29 -0
  36. data/lib/aws-sdk-code-generator/resource_load_method.rb +68 -0
  37. data/lib/aws-sdk-code-generator/resource_method.rb +22 -0
  38. data/lib/aws-sdk-code-generator/resource_skip_params.rb +36 -0
  39. data/lib/aws-sdk-code-generator/resource_value_source.rb +68 -0
  40. data/lib/aws-sdk-code-generator/resource_waiter.rb +80 -0
  41. data/lib/aws-sdk-code-generator/service.rb +30 -7
  42. data/lib/aws-sdk-code-generator/shared_example.rb +131 -0
  43. data/lib/aws-sdk-code-generator/syntax_example.rb +60 -0
  44. data/lib/aws-sdk-code-generator/syntax_example_hash.rb +174 -0
  45. data/lib/aws-sdk-code-generator/underscore.rb +10 -5
  46. data/lib/aws-sdk-code-generator/view.rb +33 -0
  47. data/lib/aws-sdk-code-generator/views/apig_endpoint_class.rb +25 -0
  48. data/lib/aws-sdk-code-generator/views/apig_readme.rb +32 -0
  49. data/lib/aws-sdk-code-generator/views/async_client_class.rb +68 -0
  50. data/lib/aws-sdk-code-generator/views/authorizer_class.rb +17 -0
  51. data/lib/aws-sdk-code-generator/views/client_api_module.rb +602 -0
  52. data/lib/aws-sdk-code-generator/views/client_class.rb +93 -0
  53. data/lib/aws-sdk-code-generator/views/docstring.rb +27 -0
  54. data/lib/aws-sdk-code-generator/views/errors_module.rb +32 -0
  55. data/lib/aws-sdk-code-generator/views/event_streams_module.rb +149 -0
  56. data/lib/aws-sdk-code-generator/views/features/env.rb +9 -0
  57. data/lib/aws-sdk-code-generator/views/features/smoke.rb +52 -0
  58. data/lib/aws-sdk-code-generator/views/features/smoke_step_definitions.rb +26 -0
  59. data/lib/aws-sdk-code-generator/views/features/step_definitions.rb +6 -2
  60. data/lib/aws-sdk-code-generator/views/gemspec.rb +39 -5
  61. data/lib/aws-sdk-code-generator/views/resource_class.rb +122 -0
  62. data/lib/aws-sdk-code-generator/views/root_resource_class.rb +58 -0
  63. data/lib/aws-sdk-code-generator/views/service_module.rb +38 -14
  64. data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -0
  65. data/lib/aws-sdk-code-generator/views/types_module.rb +329 -0
  66. data/lib/aws-sdk-code-generator/views/version.rb +2 -0
  67. data/lib/aws-sdk-code-generator/views/waiters_module.rb +37 -0
  68. data/lib/aws-sdk-code-generator/views.rb +2 -0
  69. data/lib/aws-sdk-code-generator/waiter.rb +95 -0
  70. data/lib/aws-sdk-code-generator/yard_option_tag.rb +43 -0
  71. data/lib/aws-sdk-code-generator.rb +68 -75
  72. data/templates/apig_endpoint_class.mustache +16 -0
  73. data/templates/apig_readme.mustache +62 -0
  74. data/templates/async_client_class.mustache +125 -0
  75. data/templates/authorizer_class.mustache +37 -0
  76. data/templates/client_api_module.mustache +106 -0
  77. data/templates/client_class.mustache +295 -0
  78. data/templates/code.mustache +4 -0
  79. data/templates/documentation.mustache +4 -0
  80. data/templates/errors_module.mustache +70 -0
  81. data/templates/event_streams_module.mustache +76 -0
  82. data/templates/features/env.mustache +15 -0
  83. data/templates/features/smoke.mustache +22 -0
  84. data/templates/features/smoke_step_definitions.mustache +31 -0
  85. data/templates/features/step_definitions.mustache +13 -0
  86. data/templates/gemspec.mustache +31 -0
  87. data/templates/license.txt +202 -0
  88. data/templates/method.mustache +7 -0
  89. data/templates/resource_class.mustache +304 -0
  90. data/templates/root_resource_class.mustache +51 -0
  91. data/templates/service_module.mustache +58 -0
  92. data/templates/spec/spec_helper.mustache +15 -0
  93. data/templates/types_module.mustache +53 -0
  94. data/templates/version.mustache +1 -0
  95. data/templates/waiters_module.mustache +112 -0
  96. metadata +115 -70
  97. data/lib/aws-sdk-code-generator/dsl/access_control_statement.rb +0 -23
  98. data/lib/aws-sdk-code-generator/dsl/attribute_accessor.rb +0 -43
  99. data/lib/aws-sdk-code-generator/dsl/attribute_reader.rb +0 -11
  100. data/lib/aws-sdk-code-generator/dsl/attribute_writer.rb +0 -11
  101. data/lib/aws-sdk-code-generator/dsl/autoload_statement.rb +0 -15
  102. data/lib/aws-sdk-code-generator/dsl/block_param.rb +0 -11
  103. data/lib/aws-sdk-code-generator/dsl/class.rb +0 -27
  104. data/lib/aws-sdk-code-generator/dsl/code_literal.rb +0 -66
  105. data/lib/aws-sdk-code-generator/dsl/code_object.rb +0 -33
  106. data/lib/aws-sdk-code-generator/dsl/docstring.rb +0 -36
  107. data/lib/aws-sdk-code-generator/dsl/eigenclass.rb +0 -15
  108. data/lib/aws-sdk-code-generator/dsl/extend_statement.rb +0 -12
  109. data/lib/aws-sdk-code-generator/dsl/formatter.rb +0 -25
  110. data/lib/aws-sdk-code-generator/dsl/include_statement.rb +0 -17
  111. data/lib/aws-sdk-code-generator/dsl/main.rb +0 -105
  112. data/lib/aws-sdk-code-generator/dsl/method.rb +0 -108
  113. data/lib/aws-sdk-code-generator/dsl/module.rb +0 -167
  114. data/lib/aws-sdk-code-generator/dsl/option_tag.rb +0 -36
  115. data/lib/aws-sdk-code-generator/dsl/param.rb +0 -43
  116. data/lib/aws-sdk-code-generator/dsl/param_list.rb +0 -38
  117. data/lib/aws-sdk-code-generator/dsl/return_tag.rb +0 -19
  118. data/lib/aws-sdk-code-generator/dsl/tag_default.rb +0 -20
  119. data/lib/aws-sdk-code-generator/dsl/tag_docstring.rb +0 -27
  120. data/lib/aws-sdk-code-generator/dsl/tag_type.rb +0 -18
  121. data/lib/aws-sdk-code-generator/generators/client_api_module.rb +0 -334
  122. data/lib/aws-sdk-code-generator/generators/client_class.rb +0 -389
  123. data/lib/aws-sdk-code-generator/generators/client_operation_documentation.rb +0 -166
  124. data/lib/aws-sdk-code-generator/generators/errors_module.rb +0 -25
  125. data/lib/aws-sdk-code-generator/generators/resource/action.rb +0 -88
  126. data/lib/aws-sdk-code-generator/generators/resource/batch_builder.rb +0 -211
  127. data/lib/aws-sdk-code-generator/generators/resource/builder.rb +0 -50
  128. data/lib/aws-sdk-code-generator/generators/resource/client_getter.rb +0 -15
  129. data/lib/aws-sdk-code-generator/generators/resource/client_request.rb +0 -49
  130. data/lib/aws-sdk-code-generator/generators/resource/client_request_docs.rb +0 -97
  131. data/lib/aws-sdk-code-generator/generators/resource/client_request_params.rb +0 -88
  132. data/lib/aws-sdk-code-generator/generators/resource/collection_class.rb +0 -180
  133. data/lib/aws-sdk-code-generator/generators/resource/data_attribute_getter.rb +0 -24
  134. data/lib/aws-sdk-code-generator/generators/resource/data_loaded_method.rb +0 -18
  135. data/lib/aws-sdk-code-generator/generators/resource/data_method.rb +0 -49
  136. data/lib/aws-sdk-code-generator/generators/resource/exists_method.rb +0 -29
  137. data/lib/aws-sdk-code-generator/generators/resource/extract_identifier_method.rb +0 -32
  138. data/lib/aws-sdk-code-generator/generators/resource/has_association.rb +0 -101
  139. data/lib/aws-sdk-code-generator/generators/resource/has_many_association.rb +0 -108
  140. data/lib/aws-sdk-code-generator/generators/resource/identifier_getter.rb +0 -26
  141. data/lib/aws-sdk-code-generator/generators/resource/identifiers_method.rb +0 -28
  142. data/lib/aws-sdk-code-generator/generators/resource/initialize_method.rb +0 -67
  143. data/lib/aws-sdk-code-generator/generators/resource/load_method.rb +0 -65
  144. data/lib/aws-sdk-code-generator/generators/resource/value_source.rb +0 -68
  145. data/lib/aws-sdk-code-generator/generators/resource/waiter_method.rb +0 -61
  146. data/lib/aws-sdk-code-generator/generators/resource_class.rb +0 -325
  147. data/lib/aws-sdk-code-generator/generators/response_structure_example.rb +0 -83
  148. data/lib/aws-sdk-code-generator/generators/root_resource_class.rb +0 -42
  149. data/lib/aws-sdk-code-generator/generators/service_documentation.rb +0 -64
  150. data/lib/aws-sdk-code-generator/generators/shared_example.rb +0 -132
  151. data/lib/aws-sdk-code-generator/generators/structure_type_class.rb +0 -95
  152. data/lib/aws-sdk-code-generator/generators/syntax_example.rb +0 -169
  153. data/lib/aws-sdk-code-generator/generators/types_module.rb +0 -52
  154. data/lib/aws-sdk-code-generator/generators/waiter_class.rb +0 -62
  155. data/lib/aws-sdk-code-generator/generators/waiters_module.rb +0 -20
@@ -1,334 +0,0 @@
1
- module AwsSdkCodeGenerator
2
- module Generators
3
- class ClientApiModule < Dsl::Module
4
-
5
- include Helper
6
-
7
- SKIP_TRAITS = Set.new(%w(shape deprecated location locationName documentation))
8
-
9
- SHAPE_CLASSES = {
10
- 'blob' => 'BlobShape',
11
- 'byte' => 'IntegerShape',
12
- 'boolean' => 'BooleanShape',
13
- 'character' => 'StringShape',
14
- 'double' => 'FloatShape',
15
- 'float' => 'FloatShape',
16
- 'integer' => 'IntegerShape',
17
- 'list' => 'ListShape',
18
- 'long' => 'IntegerShape',
19
- 'map' => 'MapShape',
20
- 'string' => 'StringShape',
21
- 'structure' => 'StructureShape',
22
- 'timestamp' => 'TimestampShape',
23
- }
24
-
25
- SHAPE_KEYS = {
26
- # keep
27
- 'flattened' => true,
28
- 'timestampFormat' => true, # glacier api customization
29
- 'xmlNamespace' => true,
30
- # ignore
31
- 'box' => false,
32
- 'fault' => false,
33
- 'error' => false,
34
- 'deprecated' => false,
35
- 'type' => false,
36
- 'documentation' => false,
37
- 'members' => false,
38
- 'member' => false,
39
- 'key' => false,
40
- 'locationName' => false,
41
- 'value' => false,
42
- 'required' => false,
43
- 'streaming' => false,
44
- 'enum' => false,
45
- 'exception' => false,
46
- 'payload' => false,
47
- 'pattern' => false,
48
- 'sensitive' => false,
49
- 'min' => false,
50
- 'max' => false,
51
- 'wrapper' => false,
52
- 'xmlOrder' => false,
53
- }
54
-
55
- METADATA_KEYS = {
56
- # keep
57
- 'endpointPrefix' => true,
58
- 'signatureVersion' => true,
59
- 'signingName' => true,
60
- 'serviceFullName' => true,
61
- 'protocol' => true,
62
- 'targetPrefix' => true,
63
- 'jsonVersion' => true,
64
- 'errorPrefix' => true,
65
- 'timestampFormat' => true, # glacier api customization
66
- 'xmlNamespace' => true,
67
-
68
- # ignore
69
- 'apiVersion' => false,
70
- 'checksumFormat' => false,
71
- 'globalEndpoint' => false,
72
- 'serviceAbbreviation' => false,
73
- 'uid' => false,
74
- }
75
-
76
- # @option options [required, Hash] :api
77
- # @option options [required, Hash, nil] :paginators
78
- def initialize(options)
79
- @api = options.fetch(:api)
80
- @paginators = options.fetch(:paginators)
81
- super('ClientApi')
82
- docstring("@api private")
83
- include('Seahorse::Model')
84
- apply_shape_classes(self)
85
- apply_shape_definitions(self)
86
- apply_api_const(self)
87
- end
88
-
89
- private
90
-
91
- def metadata
92
- Dsl::CodeLiteral.new do |c|
93
- c << "api.metadata = {"
94
- c.indent do
95
- (@api['metadata'] || {}).keys.sort.each do |key|
96
- if METADATA_KEYS[key]
97
- c << "#{key.inspect} => #{@api['metadata'][key].inspect},"
98
- elsif METADATA_KEYS[key].nil?
99
- raise "unhandled metadata key #{key.inspect}"
100
- end
101
- end
102
- end
103
- c << "}"
104
- end
105
- end
106
-
107
- def operations
108
- (@api['operations'] || {}).map do |name, operation|
109
- operation(name, operation)
110
- end
111
- end
112
-
113
- def operation(name, operation)
114
- Dsl::CodeLiteral.new do |code|
115
- code << "api.add_operation(:#{underscore(name)}, Seahorse::Model::Operation.new.tap do |o|"
116
- code.indent do |c|
117
- c << "o.name = #{name.inspect}"
118
- c << "o.http_method = #{operation['http']['method'].inspect}"
119
- c << "o.http_request_uri = #{operation['http']['requestUri'].inspect}"
120
- c << "o.deprecated = true" if operation['deprecated']
121
- c << "o['authtype'] = #{operation['authtype'].inspect}" if operation['authtype']
122
- %w(input output).each do |mode|
123
- c << "o.#{mode} = #{operation_shape_ref(operation[mode])}"
124
- end
125
- Array(operation['errors']).each do |error|
126
- c << "o.errors << #{operation_shape_ref(error)}"
127
- end
128
- apply_operation_pager(c, name)
129
- end
130
- code << "end)"
131
- end
132
- end
133
-
134
- def operation_shape_ref(ref)
135
- if ref
136
- metadata = ref.dup
137
- shape_name = metadata.delete('shape')
138
- if metadata.empty?
139
- options = ''
140
- else
141
- options = {}
142
- metadata.each_pair do |key, value|
143
- next if key == 'resultWrapper'
144
- if key == 'locationName'
145
- options[:location_name] = value.inspect
146
- else
147
- options[:metadata] ||= {}
148
- options[:metadata][key] = value.inspect
149
- end
150
- end
151
- if options.empty?
152
- options = ''
153
- else
154
- options = ', ' + HashFormatter.new(wrap:false).format(options)
155
- end
156
- end
157
- "Shapes::ShapeRef.new(shape: #{shape_name}#{options})"
158
- else
159
- "Shapes::ShapeRef.new(shape: Shapes::StructureShape.new(struct_class: Aws::EmptyStructure))"
160
- end
161
- end
162
-
163
- def shape_ref(ref, member_name = nil, required = Set.new)
164
- line = "Shapes::ShapeRef.new(shape: #{ref['shape']}"
165
- line += shape_ref_required(required, member_name)
166
- line += shape_ref_deprecated(ref)
167
- line += shape_ref_location(ref)
168
- line += shape_ref_location_name(member_name, ref)
169
- line += shape_ref_metadata(ref)
170
- line += ")"
171
- line
172
- end
173
-
174
- def apply_operation_pager(code, operation_name)
175
- if @paginators && @paginators['pagination'][operation_name]
176
- p = @paginators['pagination'][operation_name]
177
- input = Array(p['input_token'])
178
- output = Array(p['output_token'])
179
- tokens = {}
180
- input.each.with_index do |key, n|
181
- tokens[underscore_jmespath(output[n])] = underscore_jmespath(key)
182
- end
183
- options = {}
184
- options[:more_results] = underscore_jmespath(p['more_results']) if p['more_results']
185
- options[:limit_key] = underscore_jmespath(p['limit_key']) if p['limit_key']
186
- options[:tokens] = tokens
187
- options = HashFormatter.new(
188
- quote_strings: true,
189
- inline: true,
190
- wrap: false,
191
- ).format(options)
192
- code << "o[:pager] = Aws::Pager.new(#{options})" unless tokens.empty?
193
- end
194
- end
195
-
196
- def underscore_jmespath(str)
197
- Underscore.underscore_jmespath(str)
198
- end
199
-
200
- def apply_shape_classes(m)
201
- m.code do |c|
202
- shape_defs.each do |shape_name, shape|
203
- attrs = []
204
- attrs << "name: '#{shape_name}'"
205
- shape.each_pair do |key, value|
206
- if SHAPE_KEYS[key]
207
- attrs << "#{key}: #{value.inspect}"
208
- elsif SHAPE_KEYS[key].nil?
209
- raise "unhandled shape key #{key.inspect}"
210
- end
211
- end
212
- attrs = attrs.join(', ')
213
- c << "#{shape_name} = Shapes::#{shape_class(shape['type'])}.new(#{attrs})"
214
- end
215
- end
216
- end
217
-
218
- def apply_shape_definitions(m)
219
- m.code do |c|
220
- shape_defs.each do |shape_name, shape|
221
- if shape['type'] == 'structure' && !shape['error'] && !shape['exception']
222
- required = Set.new(shape['required'] || [])
223
- shape['members'].each do |member_name, member_ref|
224
- c << "#{shape_name}.add_member(:#{underscore(member_name)}, #{shape_ref(member_ref, member_name, required)})"
225
- end
226
- c << "#{shape_name}.struct_class = Types::#{shape_name}"
227
- if payload = shape['payload']
228
- c << "#{shape_name}[:payload] = :#{underscore(payload)}"
229
- c << "#{shape_name}[:payload_member] = #{shape_name}.member(:#{underscore(payload)})"
230
- end
231
- elsif shape['type'] == 'list'
232
- c << "#{shape_name}.member = #{shape_ref(shape['member'])}"
233
- elsif shape['type'] == 'map'
234
- c << "#{shape_name}.key = #{shape_ref(shape['key'])}"
235
- c << "#{shape_name}.value = #{shape_ref(shape['value'])}"
236
- else
237
- next
238
- end
239
- c.newline
240
- end
241
- end
242
- end
243
-
244
- def apply_api_const(m)
245
- m.code do |c|
246
- c << "# @api private"
247
- c << "API = Seahorse::Model::Api.new.tap do |api|"
248
- c.indent do
249
- c.newline
250
- if @api['metadata'] && @api['metadata']['apiVersion']
251
- c << "api.version = #{@api['metadata']['apiVersion'].inspect}"
252
- c.newline
253
- end
254
- c << metadata
255
- operations.each do |operation|
256
- c.newline
257
- c << operation
258
- end
259
- end
260
- c << "end"
261
- end
262
- end
263
-
264
- def shape_ref_required(required, member_name)
265
- if required.include?(member_name)
266
- ", required: true"
267
- else
268
- ""
269
- end
270
- end
271
-
272
- def shape_ref_deprecated(ref)
273
- if ref['deprecated'] || @api['shapes'][ref['shape']]['deprecated']
274
- ", deprecated: true"
275
- else
276
- ""
277
- end
278
- end
279
-
280
- def shape_ref_location(ref)
281
- if ref['location']
282
- ", location: #{ref['location'].inspect}"
283
- else
284
- ''
285
- end
286
- end
287
-
288
- def shape_ref_location_name(member_name, member_ref)
289
- location_name = member_ref['locationName']
290
- location_name ||= member_name unless member_ref['location'] == 'headers'
291
- location_name ? ", location_name: #{location_name.inspect}" : ""
292
- end
293
-
294
- def shape_ref_metadata(member_ref)
295
- metadata = member_ref.inject({}) do |hash, (key, value)|
296
- hash[key] = value unless SKIP_TRAITS.include?(key)
297
- hash
298
- end
299
- if metadata.empty?
300
- ""
301
- else
302
- ", metadata: #{metadata.inspect}"
303
- end
304
- end
305
-
306
- def shape_class(type)
307
- if SHAPE_CLASSES.key?(type)
308
- SHAPE_CLASSES[type]
309
- else
310
- raise ArgumentError, "unsupported shape type `#{type}'"
311
- end
312
- end
313
-
314
- def shape_defs
315
- Enumerator.new do |y|
316
- (@api['shapes'] || {}).keys.sort.each do |shape_name|
317
- y.yield(shape_name, @api['shapes'][shape_name])
318
- end
319
- end
320
- end
321
-
322
- def structure_defs
323
- Enumerator.new do |y|
324
- shape_defs.each do |shape_name, shape|
325
- if shape['type'] == 'structure' && !shape['error'] && !shape['exception']
326
- y.yield(shape_name, shape)
327
- end
328
- end
329
- end
330
- end
331
-
332
- end
333
- end
334
- end