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.
- checksums.yaml +5 -5
- data/lib/aws-sdk-code-generator/api.rb +150 -0
- data/lib/aws-sdk-code-generator/apply_docs.rb +15 -2
- data/lib/aws-sdk-code-generator/client_constructor.rb +39 -0
- data/lib/aws-sdk-code-generator/client_operation_documentation.rb +282 -0
- data/lib/aws-sdk-code-generator/client_operation_list.rb +148 -0
- data/lib/aws-sdk-code-generator/client_response_structure_example.rb +115 -0
- data/lib/aws-sdk-code-generator/code_builder.rb +146 -133
- data/lib/aws-sdk-code-generator/crosslink.rb +42 -0
- data/lib/aws-sdk-code-generator/docstring.rb +199 -0
- data/lib/aws-sdk-code-generator/error_list.rb +77 -0
- data/lib/aws-sdk-code-generator/errors.rb +2 -0
- data/lib/aws-sdk-code-generator/eventstream_example.rb +220 -0
- data/lib/aws-sdk-code-generator/gem_builder.rb +42 -25
- data/lib/aws-sdk-code-generator/hash_formatter.rb +5 -2
- data/lib/aws-sdk-code-generator/helper.rb +86 -119
- data/lib/aws-sdk-code-generator/plugin_list.rb +147 -0
- data/lib/aws-sdk-code-generator/resource_action.rb +69 -0
- data/lib/aws-sdk-code-generator/resource_action_code.rb +57 -0
- data/lib/aws-sdk-code-generator/resource_association.rb +37 -0
- data/lib/aws-sdk-code-generator/resource_attribute.rb +76 -0
- data/lib/aws-sdk-code-generator/resource_batch_action.rb +56 -0
- data/lib/aws-sdk-code-generator/resource_batch_action_code.rb +136 -0
- data/lib/aws-sdk-code-generator/resource_batch_action_documentation.rb +108 -0
- data/lib/aws-sdk-code-generator/resource_batch_builder.rb +212 -0
- data/lib/aws-sdk-code-generator/resource_builder.rb +48 -0
- data/lib/aws-sdk-code-generator/resource_client_request.rb +62 -0
- data/lib/aws-sdk-code-generator/resource_client_request_documentation.rb +81 -0
- data/lib/aws-sdk-code-generator/resource_client_request_params.rb +86 -0
- data/lib/aws-sdk-code-generator/resource_data_method.rb +60 -0
- data/lib/aws-sdk-code-generator/resource_has_association.rb +117 -0
- data/lib/aws-sdk-code-generator/resource_has_many_association.rb +52 -0
- data/lib/aws-sdk-code-generator/resource_has_many_association_code.rb +76 -0
- data/lib/aws-sdk-code-generator/resource_identifier.rb +44 -0
- data/lib/aws-sdk-code-generator/resource_identifiers_method.rb +29 -0
- data/lib/aws-sdk-code-generator/resource_load_method.rb +68 -0
- data/lib/aws-sdk-code-generator/resource_method.rb +22 -0
- data/lib/aws-sdk-code-generator/resource_skip_params.rb +36 -0
- data/lib/aws-sdk-code-generator/resource_value_source.rb +68 -0
- data/lib/aws-sdk-code-generator/resource_waiter.rb +80 -0
- data/lib/aws-sdk-code-generator/service.rb +30 -7
- data/lib/aws-sdk-code-generator/shared_example.rb +131 -0
- data/lib/aws-sdk-code-generator/syntax_example.rb +60 -0
- data/lib/aws-sdk-code-generator/syntax_example_hash.rb +174 -0
- data/lib/aws-sdk-code-generator/underscore.rb +10 -5
- data/lib/aws-sdk-code-generator/view.rb +33 -0
- data/lib/aws-sdk-code-generator/views/apig_endpoint_class.rb +25 -0
- data/lib/aws-sdk-code-generator/views/apig_readme.rb +32 -0
- data/lib/aws-sdk-code-generator/views/async_client_class.rb +68 -0
- data/lib/aws-sdk-code-generator/views/authorizer_class.rb +17 -0
- data/lib/aws-sdk-code-generator/views/client_api_module.rb +602 -0
- data/lib/aws-sdk-code-generator/views/client_class.rb +93 -0
- data/lib/aws-sdk-code-generator/views/docstring.rb +27 -0
- data/lib/aws-sdk-code-generator/views/errors_module.rb +32 -0
- data/lib/aws-sdk-code-generator/views/event_streams_module.rb +149 -0
- data/lib/aws-sdk-code-generator/views/features/env.rb +9 -0
- data/lib/aws-sdk-code-generator/views/features/smoke.rb +52 -0
- data/lib/aws-sdk-code-generator/views/features/smoke_step_definitions.rb +26 -0
- data/lib/aws-sdk-code-generator/views/features/step_definitions.rb +6 -2
- data/lib/aws-sdk-code-generator/views/gemspec.rb +39 -5
- data/lib/aws-sdk-code-generator/views/resource_class.rb +122 -0
- data/lib/aws-sdk-code-generator/views/root_resource_class.rb +58 -0
- data/lib/aws-sdk-code-generator/views/service_module.rb +38 -14
- data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -0
- data/lib/aws-sdk-code-generator/views/types_module.rb +329 -0
- data/lib/aws-sdk-code-generator/views/version.rb +2 -0
- data/lib/aws-sdk-code-generator/views/waiters_module.rb +37 -0
- data/lib/aws-sdk-code-generator/views.rb +2 -0
- data/lib/aws-sdk-code-generator/waiter.rb +95 -0
- data/lib/aws-sdk-code-generator/yard_option_tag.rb +43 -0
- data/lib/aws-sdk-code-generator.rb +68 -75
- data/templates/apig_endpoint_class.mustache +16 -0
- data/templates/apig_readme.mustache +62 -0
- data/templates/async_client_class.mustache +125 -0
- data/templates/authorizer_class.mustache +37 -0
- data/templates/client_api_module.mustache +106 -0
- data/templates/client_class.mustache +295 -0
- data/templates/code.mustache +4 -0
- data/templates/documentation.mustache +4 -0
- data/templates/errors_module.mustache +70 -0
- data/templates/event_streams_module.mustache +76 -0
- data/templates/features/env.mustache +15 -0
- data/templates/features/smoke.mustache +22 -0
- data/templates/features/smoke_step_definitions.mustache +31 -0
- data/templates/features/step_definitions.mustache +13 -0
- data/templates/gemspec.mustache +31 -0
- data/templates/license.txt +202 -0
- data/templates/method.mustache +7 -0
- data/templates/resource_class.mustache +304 -0
- data/templates/root_resource_class.mustache +51 -0
- data/templates/service_module.mustache +58 -0
- data/templates/spec/spec_helper.mustache +15 -0
- data/templates/types_module.mustache +53 -0
- data/templates/version.mustache +1 -0
- data/templates/waiters_module.mustache +112 -0
- metadata +115 -70
- data/lib/aws-sdk-code-generator/dsl/access_control_statement.rb +0 -23
- data/lib/aws-sdk-code-generator/dsl/attribute_accessor.rb +0 -43
- data/lib/aws-sdk-code-generator/dsl/attribute_reader.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/attribute_writer.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/autoload_statement.rb +0 -15
- data/lib/aws-sdk-code-generator/dsl/block_param.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/class.rb +0 -27
- data/lib/aws-sdk-code-generator/dsl/code_literal.rb +0 -66
- data/lib/aws-sdk-code-generator/dsl/code_object.rb +0 -33
- data/lib/aws-sdk-code-generator/dsl/docstring.rb +0 -36
- data/lib/aws-sdk-code-generator/dsl/eigenclass.rb +0 -15
- data/lib/aws-sdk-code-generator/dsl/extend_statement.rb +0 -12
- data/lib/aws-sdk-code-generator/dsl/formatter.rb +0 -25
- data/lib/aws-sdk-code-generator/dsl/include_statement.rb +0 -17
- data/lib/aws-sdk-code-generator/dsl/main.rb +0 -105
- data/lib/aws-sdk-code-generator/dsl/method.rb +0 -108
- data/lib/aws-sdk-code-generator/dsl/module.rb +0 -167
- data/lib/aws-sdk-code-generator/dsl/option_tag.rb +0 -36
- data/lib/aws-sdk-code-generator/dsl/param.rb +0 -43
- data/lib/aws-sdk-code-generator/dsl/param_list.rb +0 -38
- data/lib/aws-sdk-code-generator/dsl/return_tag.rb +0 -19
- data/lib/aws-sdk-code-generator/dsl/tag_default.rb +0 -20
- data/lib/aws-sdk-code-generator/dsl/tag_docstring.rb +0 -27
- data/lib/aws-sdk-code-generator/dsl/tag_type.rb +0 -18
- data/lib/aws-sdk-code-generator/generators/client_api_module.rb +0 -334
- data/lib/aws-sdk-code-generator/generators/client_class.rb +0 -389
- data/lib/aws-sdk-code-generator/generators/client_operation_documentation.rb +0 -166
- data/lib/aws-sdk-code-generator/generators/errors_module.rb +0 -25
- data/lib/aws-sdk-code-generator/generators/resource/action.rb +0 -88
- data/lib/aws-sdk-code-generator/generators/resource/batch_builder.rb +0 -211
- data/lib/aws-sdk-code-generator/generators/resource/builder.rb +0 -50
- data/lib/aws-sdk-code-generator/generators/resource/client_getter.rb +0 -15
- data/lib/aws-sdk-code-generator/generators/resource/client_request.rb +0 -49
- data/lib/aws-sdk-code-generator/generators/resource/client_request_docs.rb +0 -97
- data/lib/aws-sdk-code-generator/generators/resource/client_request_params.rb +0 -88
- data/lib/aws-sdk-code-generator/generators/resource/collection_class.rb +0 -180
- data/lib/aws-sdk-code-generator/generators/resource/data_attribute_getter.rb +0 -24
- data/lib/aws-sdk-code-generator/generators/resource/data_loaded_method.rb +0 -18
- data/lib/aws-sdk-code-generator/generators/resource/data_method.rb +0 -49
- data/lib/aws-sdk-code-generator/generators/resource/exists_method.rb +0 -29
- data/lib/aws-sdk-code-generator/generators/resource/extract_identifier_method.rb +0 -32
- data/lib/aws-sdk-code-generator/generators/resource/has_association.rb +0 -101
- data/lib/aws-sdk-code-generator/generators/resource/has_many_association.rb +0 -108
- data/lib/aws-sdk-code-generator/generators/resource/identifier_getter.rb +0 -26
- data/lib/aws-sdk-code-generator/generators/resource/identifiers_method.rb +0 -28
- data/lib/aws-sdk-code-generator/generators/resource/initialize_method.rb +0 -67
- data/lib/aws-sdk-code-generator/generators/resource/load_method.rb +0 -65
- data/lib/aws-sdk-code-generator/generators/resource/value_source.rb +0 -68
- data/lib/aws-sdk-code-generator/generators/resource/waiter_method.rb +0 -61
- data/lib/aws-sdk-code-generator/generators/resource_class.rb +0 -325
- data/lib/aws-sdk-code-generator/generators/response_structure_example.rb +0 -83
- data/lib/aws-sdk-code-generator/generators/root_resource_class.rb +0 -42
- data/lib/aws-sdk-code-generator/generators/service_documentation.rb +0 -64
- data/lib/aws-sdk-code-generator/generators/shared_example.rb +0 -132
- data/lib/aws-sdk-code-generator/generators/structure_type_class.rb +0 -95
- data/lib/aws-sdk-code-generator/generators/syntax_example.rb +0 -169
- data/lib/aws-sdk-code-generator/generators/types_module.rb +0 -52
- data/lib/aws-sdk-code-generator/generators/waiter_class.rb +0 -62
- data/lib/aws-sdk-code-generator/generators/waiters_module.rb +0 -20
@@ -1,325 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module AwsSdkCodeGenerator
|
4
|
-
module Generators
|
5
|
-
class ResourceClass < Dsl::Class
|
6
|
-
|
7
|
-
extend Helper
|
8
|
-
|
9
|
-
# @option options [required, String] :name
|
10
|
-
# @option options [required, Hash] :resource
|
11
|
-
# @option options [required, Hash] :api
|
12
|
-
# @option options [Hash] :paginators
|
13
|
-
# @option options [Hash] :waiters
|
14
|
-
# @option options [String] :var_name (underscore(name))
|
15
|
-
def initialize(options)
|
16
|
-
@api = options.fetch(:api)
|
17
|
-
@name = options.fetch(:name)
|
18
|
-
@resource = options.fetch(:resource)
|
19
|
-
@paginators = options.fetch(:paginators, nil)
|
20
|
-
@waiters = options.fetch(:waiters, nil)
|
21
|
-
@var_name = options.fetch(:var_name, underscore(@name))
|
22
|
-
super(@name)
|
23
|
-
build
|
24
|
-
check_for_method_name_conflicts!
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def build
|
30
|
-
extend_module('Aws::Deprecations')
|
31
|
-
add(initialize_method)
|
32
|
-
code('# @!group Read-Only Attributes')
|
33
|
-
add(*identifier_getters)
|
34
|
-
add(*data_attribute_getters)
|
35
|
-
code('# @!endgroup')
|
36
|
-
add(client_getter)
|
37
|
-
add(load_method)
|
38
|
-
add(data_method)
|
39
|
-
add(data_loaded_method)
|
40
|
-
add(exists_method)
|
41
|
-
add(*waiters)
|
42
|
-
apply_actions
|
43
|
-
apply_associations
|
44
|
-
add(identifiers_method)
|
45
|
-
add(*private_methods)
|
46
|
-
add(batch_action)
|
47
|
-
end
|
48
|
-
|
49
|
-
def initialize_method
|
50
|
-
Generators::Resource::InitializeMethod.new(resource: @resource)
|
51
|
-
end
|
52
|
-
|
53
|
-
def identifier_getters
|
54
|
-
identifiers.map do |i|
|
55
|
-
Generators::Resource::IdentifierGetter.new(identifier: i)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def data_attribute_getters
|
60
|
-
data_attribute_names.map do |member_name, member_ref|
|
61
|
-
Generators::Resource::DataAttributeGetter.new(
|
62
|
-
api: @api,
|
63
|
-
member_name: member_name,
|
64
|
-
member_ref: member_ref
|
65
|
-
)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def client_getter
|
70
|
-
Generators::Resource::ClientGetter.new
|
71
|
-
end
|
72
|
-
|
73
|
-
def load_method
|
74
|
-
Generators::Resource::LoadMethod.new(
|
75
|
-
resource_name: @name,
|
76
|
-
definition: @resource['load']
|
77
|
-
)
|
78
|
-
end
|
79
|
-
|
80
|
-
def data_method
|
81
|
-
Generators::Resource::DataMethod.new(
|
82
|
-
resource_name: @name,
|
83
|
-
resource: @resource
|
84
|
-
)
|
85
|
-
end
|
86
|
-
|
87
|
-
def data_loaded_method
|
88
|
-
Generators::Resource::DataLoadedMethod.new
|
89
|
-
end
|
90
|
-
|
91
|
-
def exists_method
|
92
|
-
if @resource['waiters'] && @resource['waiters']['Exists']
|
93
|
-
Generators::Resource::ExistsMethod.new(
|
94
|
-
resource_name: @name,
|
95
|
-
resource: @resource,
|
96
|
-
waiters: @waiters,
|
97
|
-
)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def waiters
|
102
|
-
(@resource['waiters'] || {}).map do |waiter_name, waiter|
|
103
|
-
Generators::Resource::WaiterMethod.new(
|
104
|
-
resource_name: @name,
|
105
|
-
resource: @resource,
|
106
|
-
resource_waiter_name: waiter_name,
|
107
|
-
resource_waiter: waiter,
|
108
|
-
waiter: @waiters['waiters'][waiter['waiterName']]
|
109
|
-
)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def apply_actions
|
114
|
-
actions = @resource['actions'] || {}
|
115
|
-
return if actions.empty?
|
116
|
-
code('# @!group Actions')
|
117
|
-
actions.each do |name, action|
|
118
|
-
add(Resource::Action.new(
|
119
|
-
api: @api,
|
120
|
-
name: name,
|
121
|
-
action: action,
|
122
|
-
var_name: @var_name,
|
123
|
-
))
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def apply_associations
|
128
|
-
associations = []
|
129
|
-
associations += has_associations
|
130
|
-
associations += has_many_associations
|
131
|
-
|
132
|
-
return if associations.empty?
|
133
|
-
|
134
|
-
code('# @!group Associations')
|
135
|
-
associations.sort_by(&:name).each do |association_method|
|
136
|
-
add(association_method)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def has_associations
|
141
|
-
(@resource['has'] || {}).map do |name, has|
|
142
|
-
Resource::HasAssociation.new(
|
143
|
-
api: @api,
|
144
|
-
name: name,
|
145
|
-
has: has
|
146
|
-
)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def has_many_associations
|
151
|
-
(@resource['hasMany'] || {}).map do |name, has_many|
|
152
|
-
Resource::HasManyAssociation.new(
|
153
|
-
name: name,
|
154
|
-
has_many: has_many,
|
155
|
-
api: @api,
|
156
|
-
paginators: @paginators,
|
157
|
-
var_name: @var_name,
|
158
|
-
)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def batch_action
|
163
|
-
Generators::Resource::CollectionClass.new(
|
164
|
-
resource_name: @name,
|
165
|
-
resource: @resource,
|
166
|
-
api: @api,
|
167
|
-
)
|
168
|
-
end
|
169
|
-
|
170
|
-
def identifiers_method
|
171
|
-
Generators::Resource::IdentifiersMethod.new(
|
172
|
-
identifiers: identifiers
|
173
|
-
)
|
174
|
-
end
|
175
|
-
|
176
|
-
def private_methods
|
177
|
-
methods = []
|
178
|
-
methods.concat(extract_identifier_methods)
|
179
|
-
methods << yield_waiter_and_warn_method
|
180
|
-
methods << separate_params_and_options
|
181
|
-
methods.compact
|
182
|
-
end
|
183
|
-
|
184
|
-
def extract_identifier_methods
|
185
|
-
identifiers.map.with_index do |identifier, n|
|
186
|
-
Generators::Resource::ExtractIdentifierMethod.new(
|
187
|
-
identifier: identifier,
|
188
|
-
index: n
|
189
|
-
)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def identifiers
|
194
|
-
@resource['identifiers'] || []
|
195
|
-
end
|
196
|
-
|
197
|
-
def data_attribute_names
|
198
|
-
|
199
|
-
skip = Set.new
|
200
|
-
|
201
|
-
# do no duplicate identifiers
|
202
|
-
identifiers.each do |i|
|
203
|
-
skip << i['name']
|
204
|
-
skip << i['memberName'] if i.key?('memberName')
|
205
|
-
end
|
206
|
-
|
207
|
-
# do no duplicate action names
|
208
|
-
(@resource['actions'] || {}).keys.each do |action_name|
|
209
|
-
skip << action_name
|
210
|
-
end
|
211
|
-
|
212
|
-
# do no duplicate has association names
|
213
|
-
(@resource['has'] || {}).keys.each do |association_name|
|
214
|
-
skip << association_name
|
215
|
-
end
|
216
|
-
|
217
|
-
# do no duplicate hasMany association names
|
218
|
-
(@resource['hasMany'] || {}).keys.each do |association_name|
|
219
|
-
skip << association_name
|
220
|
-
end
|
221
|
-
|
222
|
-
shape = (@api['shapes'] || {})[@resource['shape']] || {}
|
223
|
-
members = shape['members'] || {}
|
224
|
-
Enumerator.new do |y|
|
225
|
-
members.each do |member_name, member_ref|
|
226
|
-
unless skip.include?(member_name)
|
227
|
-
y.yield(member_name, member_ref)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
def check_for_method_name_conflicts!
|
234
|
-
|
235
|
-
names = Set.new
|
236
|
-
|
237
|
-
# Ensure the resource does not have duplicate names. This
|
238
|
-
# includes comparing identifier names, action names, association
|
239
|
-
# names, e.g. anything that is exposed as a method.
|
240
|
-
@code_objects.each do |code_obj|
|
241
|
-
if Dsl::Method === code_obj || Dsl::AttributeAccessor === code_obj
|
242
|
-
check_for_duplicate_method!(code_obj.name, names)
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
# It is possible for Dsl::Method#aliases to collide with
|
247
|
-
# code object names. Remove aliases that collide.
|
248
|
-
@code_objects.each do |code_obj|
|
249
|
-
if Dsl::Method === code_obj
|
250
|
-
code_obj.aliases.each do |alias_name|
|
251
|
-
if names.include?(alias_name.to_s)
|
252
|
-
code_obj.aliases.delete(alias_name.to_s)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
# Compare all resource methods against methods defined
|
259
|
-
# on Ruby's Object class as an instance method. We need to
|
260
|
-
# ensure we do not clobber built in Ruby functionality.
|
261
|
-
Object.instance_methods.each do |obj_method_name|
|
262
|
-
if names.include?(obj_method_name.to_s)
|
263
|
-
raise Errors::ResourceMethodConflict.new(
|
264
|
-
resource_name: @name,
|
265
|
-
method_name: obj_method_name
|
266
|
-
)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
def check_for_duplicate_method!(method_name, names)
|
272
|
-
method_name = method_name.to_s
|
273
|
-
if names.include?(method_name)
|
274
|
-
raise Errors::ResourceMethodConflict.new(
|
275
|
-
resource_name: @name,
|
276
|
-
method_name: method_name
|
277
|
-
)
|
278
|
-
else
|
279
|
-
names << method_name
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
def yield_waiter_and_warn_method
|
284
|
-
if @resource['waiters'] && @resource['waiters'].size > 0
|
285
|
-
Dsl::Method.new(:yield_waiter_and_warn, access: :private) do |m|
|
286
|
-
m.param(:waiter)
|
287
|
-
m.block_param
|
288
|
-
m.code(<<-CODE)
|
289
|
-
if !@waiter_block_warned
|
290
|
-
msg = "pass options to configure the waiter; "
|
291
|
-
msg << "yielding the waiter is deprecated"
|
292
|
-
warn(msg)
|
293
|
-
@waiter_block_warned = true
|
294
|
-
end
|
295
|
-
yield(waiter.waiter)
|
296
|
-
CODE
|
297
|
-
end
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
def separate_params_and_options
|
302
|
-
if @resource['waiters'] && @resource['waiters'].size > 0
|
303
|
-
Dsl::Method.new(:separate_params_and_options, access: :private) do |m|
|
304
|
-
m.param(:options)
|
305
|
-
m.code(<<-CODE)
|
306
|
-
opts = Set.new([:client, :max_attempts, :delay, :before_attempt, :before_wait])
|
307
|
-
waiter_opts = {}
|
308
|
-
waiter_params = {}
|
309
|
-
options.each_pair do |key, value|
|
310
|
-
if opts.include?(key)
|
311
|
-
waiter_opts[key] = value
|
312
|
-
else
|
313
|
-
waiter_params[key] = value
|
314
|
-
end
|
315
|
-
end
|
316
|
-
waiter_opts[:client] ||= @client
|
317
|
-
[waiter_opts, waiter_params]
|
318
|
-
CODE
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
end
|
324
|
-
end
|
325
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module AwsSdkCodeGenerator
|
4
|
-
module Generators
|
5
|
-
class ResponseStructureExample
|
6
|
-
|
7
|
-
include Helper
|
8
|
-
|
9
|
-
# @option options [required, Hash] :shape_ref
|
10
|
-
# @option options [required, Hash] :api
|
11
|
-
def initialize(options = {})
|
12
|
-
@shape_ref = options.fetch(:shape_ref)
|
13
|
-
@api = options.fetch(:api)
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_str
|
17
|
-
"\n@example Response structure\n #{entry(@shape_ref, "resp", Set.new).join("\n ")}"
|
18
|
-
end
|
19
|
-
alias to_s to_str
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def structure(ref, context, visited)
|
24
|
-
lines = []
|
25
|
-
shape(ref)['members'].each_pair do |member_name, member_ref|
|
26
|
-
lines += entry(member_ref, "#{context}.#{underscore(member_name)}", visited)
|
27
|
-
end
|
28
|
-
lines
|
29
|
-
end
|
30
|
-
|
31
|
-
def list(ref, context, visited)
|
32
|
-
lines = []
|
33
|
-
lines << "#{context} #=> Array"
|
34
|
-
lines += entry(shape(ref)['member'], "#{context}[0]", visited)
|
35
|
-
lines
|
36
|
-
end
|
37
|
-
|
38
|
-
def map(ref, context, visited)
|
39
|
-
lines = []
|
40
|
-
lines << "#{context} #=> Hash"
|
41
|
-
lines += entry(shape(ref)['value'], "#{context}[#{map_key(ref)}]", visited)
|
42
|
-
lines
|
43
|
-
end
|
44
|
-
|
45
|
-
def map_key(ref)
|
46
|
-
shape(ref)['key']['shape'].inspect
|
47
|
-
end
|
48
|
-
|
49
|
-
def entry(ref, context, visited)
|
50
|
-
if ref['shape'] == 'AttributeValue'
|
51
|
-
return ["#{context} #=> <Hash,Array,String,Numeric,Boolean,IO,Set,nil>"]
|
52
|
-
elsif visited.include?(ref['shape'])
|
53
|
-
return ["#{context} #=> Types::#{ref['shape']}"]
|
54
|
-
else
|
55
|
-
visited = visited + [ref['shape']]
|
56
|
-
end
|
57
|
-
case shape(ref)['type']
|
58
|
-
when 'structure' then structure(ref, context, visited)
|
59
|
-
when 'list' then list(ref, context, visited)
|
60
|
-
when 'map' then map(ref, context, visited)
|
61
|
-
else ["#{context} #=> #{type(ref)}"]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def type(ref)
|
66
|
-
if shape(ref)['type'] == 'string'
|
67
|
-
string(ref)
|
68
|
-
else
|
69
|
-
ruby_type(ref)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def string(ref)
|
74
|
-
if shape(ref)['enum']
|
75
|
-
"String, one of #{shape(ref)['enum'].map(&:inspect).join(', ')}"
|
76
|
-
else
|
77
|
-
'String'
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
class RootResourceClass < ResourceClass
|
4
|
-
|
5
|
-
include Helper
|
6
|
-
|
7
|
-
# @option options [required, Hash] :api
|
8
|
-
# @option options [required, String] :var_name
|
9
|
-
# @option options [Hash] :resources
|
10
|
-
# @option options [Hash] :paginators
|
11
|
-
def initialize(options)
|
12
|
-
resources = options.fetch(:resources) || {}
|
13
|
-
super(
|
14
|
-
api: options.fetch(:api),
|
15
|
-
name: 'Resource',
|
16
|
-
resource: resources.fetch('service', {}),
|
17
|
-
paginators: options.fetch(:paginators, nil) || {},
|
18
|
-
waiters:nil,
|
19
|
-
var_name: options.fetch(:var_name)
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def build
|
26
|
-
add(initialize_method)
|
27
|
-
add(client_getter)
|
28
|
-
apply_actions
|
29
|
-
apply_associations
|
30
|
-
end
|
31
|
-
|
32
|
-
def initialize_method
|
33
|
-
Dsl::Method.new('initialize') do |m|
|
34
|
-
m.param('options', default:{})
|
35
|
-
m.option(name:'client', type:'Client')
|
36
|
-
m.code('@client = options[:client] || Client.new(options)')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
module AwsSdkCodeGenerator
|
4
|
-
module Generators
|
5
|
-
class ServiceDocumentation
|
6
|
-
|
7
|
-
include Helper
|
8
|
-
|
9
|
-
# @option options [required, Hash] :api
|
10
|
-
# @option options [required, Hash] :product_name
|
11
|
-
# @option options [required, Hash] :namespace
|
12
|
-
def initialize(options = {})
|
13
|
-
@api = options.fetch(:api)
|
14
|
-
@product_name = options.fetch(:product_name)
|
15
|
-
@namespace = options.fetch(:namespace)
|
16
|
-
@var_name = @namespace.split('::').last.downcase
|
17
|
-
end
|
18
|
-
|
19
|
-
def docstring
|
20
|
-
<<-MARKDOWN
|
21
|
-
@service
|
22
|
-
This module provides support for #{@product_name}, which shipped in `aws-sdk-#{@var_name}` gem.
|
23
|
-
|
24
|
-
# #{@namespace}::Client
|
25
|
-
|
26
|
-
The {#{@namespace}::Client} class provides one method for each API
|
27
|
-
operation. Operation methods each accept a hash of request parameters
|
28
|
-
and return a response object.#{example_operation}
|
29
|
-
|
30
|
-
See {Client} for more information.
|
31
|
-
|
32
|
-
# #{@namespace}::Errors
|
33
|
-
|
34
|
-
Errors returned from #{@product_name} all
|
35
|
-
extend {Errors::ServiceError}.
|
36
|
-
|
37
|
-
begin
|
38
|
-
# do stuff
|
39
|
-
rescue #{@namespace}::Errors::ServiceError
|
40
|
-
# rescues all service API errors
|
41
|
-
end
|
42
|
-
|
43
|
-
See {Errors} for more information.
|
44
|
-
MARKDOWN
|
45
|
-
end
|
46
|
-
|
47
|
-
def example_operation
|
48
|
-
if @api['operations'] && @api['operations'].first
|
49
|
-
<<-EXAMPLE
|
50
|
-
|
51
|
-
|
52
|
-
#{@var_name} = #{@namespace}::Client.new
|
53
|
-
resp = #{@var_name}.#{example_operation_name}(params)
|
54
|
-
EXAMPLE
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def example_operation_name
|
59
|
-
underscore(@api['operations'].keys.first)
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
class SharedExample
|
4
|
-
|
5
|
-
include Helper
|
6
|
-
|
7
|
-
# @option options [required, String] :operation_name
|
8
|
-
# @option options [required, Hash] api
|
9
|
-
# @option options [required, Hash] examples
|
10
|
-
# @option options [required, Integer] example
|
11
|
-
def initialize(options = {})
|
12
|
-
@operation_name = options.fetch(:operation_name)
|
13
|
-
@operation = options.fetch(:api)['operations'][@operation_name]
|
14
|
-
@example = options.fetch(:examples)['examples'][@operation_name][options.fetch(:example)]
|
15
|
-
@api = options.fetch(:api)
|
16
|
-
@method_name = underscore(@operation_name)
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
lines = []
|
21
|
-
lines << ""
|
22
|
-
lines << "@example Example: #{@example['description']}"
|
23
|
-
lines << ""
|
24
|
-
apply_input_example(lines)
|
25
|
-
apply_output_example(lines)
|
26
|
-
lines.join("\n")
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def apply_input_example(lines)
|
32
|
-
lines << " resp = client.#{@method_name}(#{input_params})"
|
33
|
-
end
|
34
|
-
|
35
|
-
def input_params
|
36
|
-
if @example['input'] && @operation['input']
|
37
|
-
entry(
|
38
|
-
@example['input'],
|
39
|
-
@operation['input'],
|
40
|
-
indent = ' ',
|
41
|
-
path = [],
|
42
|
-
@example['comments']['input']
|
43
|
-
).join("\n")
|
44
|
-
else
|
45
|
-
''
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def apply_output_example(lines)
|
50
|
-
if @example['output'] && @operation['output']
|
51
|
-
lines << ""
|
52
|
-
lines << " # resp.to_h outputs the following:"
|
53
|
-
lines << " " + entry(
|
54
|
-
@example['output'],
|
55
|
-
@operation['output'],
|
56
|
-
indent = ' ',
|
57
|
-
path = [],
|
58
|
-
@example['comments']['output']
|
59
|
-
).join("\n")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def entry(json, ref, indent, path, comments)
|
64
|
-
case shape(ref)['type']
|
65
|
-
when 'structure' then structure(json, ref, indent, path, comments)
|
66
|
-
when 'map' then map(json, ref, indent, path, comments)
|
67
|
-
when 'list' then list(json, ref, indent, path, comments)
|
68
|
-
when 'timestamp' then "Time.parse(#{json.inspect})"
|
69
|
-
when 'string', 'blob', 'integer', 'long', 'float', 'double', 'boolean'
|
70
|
-
json.inspect
|
71
|
-
else
|
72
|
-
raise ArgumentError, "unhandled type #{shape(ref)['type'].inspect}"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def structure(json, ref, indent, path, comments)
|
77
|
-
lines = ["{"]
|
78
|
-
json.each_pair do |key, val|
|
79
|
-
path << ".#{key}"
|
80
|
-
shape_val = entry(val, shape(ref)['members'][key], "#{indent} ", path, comments)
|
81
|
-
if shape_val.is_a?(Array)
|
82
|
-
shape_val = shape_val.join("\n")
|
83
|
-
end
|
84
|
-
lines << "#{indent} #{underscore(key)}: #{shape_val},#{comments_for(path, comments)}"
|
85
|
-
path.pop
|
86
|
-
end
|
87
|
-
lines << "#{indent}}"
|
88
|
-
lines
|
89
|
-
end
|
90
|
-
|
91
|
-
def map(json, ref, indent, path, comments)
|
92
|
-
lines = ["{"]
|
93
|
-
json.each do |key, val|
|
94
|
-
path << ".#{key}"
|
95
|
-
shape_val = entry(val, shape(ref)['value'], "#{indent} ", path, comments)
|
96
|
-
if shape_val.is_a?(Array)
|
97
|
-
shape_val = shape_val.join("\n")
|
98
|
-
end
|
99
|
-
lines << "#{indent} \"#{key}\" => #{shape_val},#{comments_for(path, comments)}"
|
100
|
-
path.pop
|
101
|
-
end
|
102
|
-
lines << "#{indent}}"
|
103
|
-
lines
|
104
|
-
end
|
105
|
-
|
106
|
-
def list(json, ref, indent, path, comments)
|
107
|
-
lines = ["["]
|
108
|
-
json.each_with_index do |value, index|
|
109
|
-
path << "[#{index}]"
|
110
|
-
shape_val = entry(value, shape(ref)['member'], "#{indent} ", path, comments)
|
111
|
-
if shape_val.is_a?(Array)
|
112
|
-
shape_val = shape_val.join("\n")
|
113
|
-
end
|
114
|
-
lines << "#{indent} #{shape_val},#{comments_for(path, comments)}"
|
115
|
-
path.pop
|
116
|
-
end
|
117
|
-
lines << "#{indent}]"
|
118
|
-
lines
|
119
|
-
end
|
120
|
-
|
121
|
-
def comments_for(path, comments)
|
122
|
-
path = path.join().sub(/^\./, '')
|
123
|
-
if comments.key?(path)
|
124
|
-
" # #{comments[path]}"
|
125
|
-
else
|
126
|
-
""
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|