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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
 
3
5
  module AwsSdkCodeGenerator
@@ -5,11 +7,18 @@ module AwsSdkCodeGenerator
5
7
  class ServiceModule < View
6
8
 
7
9
  # @option options [required, Service] :service
10
+ # @option options [required, String] :prefix
8
11
  def initialize(options)
9
12
  @service = options.fetch(:service)
10
13
  @prefix = options.fetch(:prefix)
11
14
  end
12
15
 
16
+ # @return [String|nil]
17
+ def generated_src_warning
18
+ return if @service.protocol == 'api-gateway'
19
+ GENERATED_SRC_WARNING
20
+ end
21
+
13
22
  def full_name
14
23
  @service.full_name
15
24
  end
@@ -42,18 +51,26 @@ module AwsSdkCodeGenerator
42
51
  @service.gem_dependencies.keys
43
52
  end
44
53
 
54
+ # @return [Boolean] - Return true if a check is needed before
55
+ # requiring core to prevent circular dependencies.
56
+ # This is required to support backwards compatibility for SSO which was
57
+ # moved from the aws-sdk-sso gem into aws-sdk-core.
58
+ def require_core_guard?
59
+ name == 'SSO' || name == 'STS'
60
+ end
61
+
45
62
  # @return [Array<String>]
46
63
  def relative_requires
47
64
  paths = Set.new
48
- paths << "#{prefix}/types"
49
- paths << "#{prefix}/client_api"
50
- paths << "#{prefix}/client"
51
- paths << "#{prefix}/errors"
52
- paths << "#{prefix}/waiters" if @service.waiters
53
- paths << "#{prefix}/resource"
65
+ paths << "#{@prefix}/types"
66
+ paths << "#{@prefix}/client_api"
67
+ paths << "#{@prefix}/client"
68
+ paths << "#{@prefix}/errors"
69
+ paths << "#{@prefix}/waiters" if @service.waiters
70
+ paths << "#{@prefix}/resource"
54
71
  if @service.resources && @service.resources['resources']
55
72
  @service.resources['resources'].keys.each do |resource_name|
56
- path = "#{prefix}/#{underscore(resource_name)}"
73
+ path = "#{@prefix}/#{underscore(resource_name)}"
57
74
  if paths.include?(path)
58
75
  raise "resource path conflict for `#{resource_name}'"
59
76
  else
@@ -61,7 +78,14 @@ module AwsSdkCodeGenerator
61
78
  end
62
79
  end
63
80
  end
64
- paths << "#{prefix}/customizations"
81
+ paths << "#{@prefix}/customizations"
82
+ if @service.api['metadata']['protocolSettings'] &&
83
+ @service.api['metadata']['protocolSettings']['h2'] == 'eventstream'
84
+ paths << "#{@prefix}/async_client"
85
+ paths << "#{@prefix}/event_streams"
86
+ elsif eventstream_shape?
87
+ paths << "#{@prefix}/event_streams"
88
+ end
65
89
  paths.to_a
66
90
  end
67
91
 
@@ -70,16 +94,16 @@ module AwsSdkCodeGenerator
70
94
  end
71
95
 
72
96
  def example_operation_name
97
+ raise "no operations found for the service" if @service.api['operations'].empty?
73
98
  underscore(@service.api['operations'].keys.first)
74
- nil
75
99
  end
76
100
 
77
- private
78
-
79
- def prefix
80
- @prefix
101
+ def eventstream_shape?
102
+ @service.api['shapes'].each do |_, shape_ref|
103
+ return true if shape_ref['eventstream']
104
+ end
105
+ false
81
106
  end
82
-
83
107
  end
84
108
  end
85
109
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AwsSdkCodeGenerator
2
4
  module Views
3
5
  module Spec
@@ -13,11 +15,18 @@ module AwsSdkCodeGenerator
13
15
  @gem_dependencies = service.gem_dependencies.map do |gem_name, _|
14
16
  { dependency: gem_name }
15
17
  end
18
+ @custom = service.protocol == 'api-gateway'
16
19
  end
17
20
 
18
21
  attr_reader :gem_name
19
22
  attr_reader :gem_dependencies
20
23
 
24
+ # @return [String|nil]
25
+ def generated_src_warning
26
+ return if @custom
27
+ GENERATED_SRC_WARNING
28
+ end
29
+
21
30
  end
22
31
  end
23
32
  end
@@ -0,0 +1,329 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module AwsSdkCodeGenerator
6
+ module Views
7
+ class TypesModule < View
8
+
9
+ include Helper
10
+
11
+ # @option options [required, Service] :service
12
+ def initialize(options)
13
+ @service = options.fetch(:service)
14
+ @api = @service.api
15
+ @input_shapes = compute_input_shapes(@service.api)
16
+ @output_shapes = compute_output_shapes(@service.api)
17
+ end
18
+
19
+ # @return [String|nil]
20
+ def generated_src_warning
21
+ return if @service.protocol == 'api-gateway'
22
+ GENERATED_SRC_WARNING
23
+ end
24
+
25
+ def module_name
26
+ @service.module_name
27
+ end
28
+
29
+ # @return [Array<StructClass>]
30
+ def structures
31
+ unless @service.protocol_settings.empty?
32
+ if @service.protocol_settings['h2'] == 'eventstream'
33
+ @service.api['shapes'].each do |_, shape|
34
+ if shape['eventstream']
35
+ # add event trait to all members if not exists
36
+ shape['members'].each do |name, ref|
37
+ @service.api['shapes'][ref['shape']]['event'] = true
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ @service.api['shapes'].inject([]) do |list, (shape_name, shape)|
44
+ # APIG model can have input/output shape with downcase and '__'
45
+ if @service.protocol == 'api-gateway'
46
+ shape_name = lstrip_prefix(upcase_first(shape_name))
47
+ end
48
+ # eventstream shape will be inheriting from enumerator
49
+ if shape['eventstream']
50
+ list
51
+ elsif shape['type'] == 'structure' && !shape['document']
52
+ struct_members = struct_members(shape)
53
+ sensitive_params = struct_members.select(&:sensitive).map do |m|
54
+ m.member_name.to_sym
55
+ end
56
+ list << StructClass.new(
57
+ class_name: shape_name,
58
+ members: struct_members,
59
+ sensitive_params: sensitive_params,
60
+ documentation: struct_class_docs(shape_name, shape),
61
+ union: shape['union']
62
+ )
63
+ else
64
+ list
65
+ end
66
+ end
67
+ end
68
+
69
+ # return [Array<EventStreamClass>]
70
+ def eventstreams
71
+ @service.api['shapes'].inject([]) do |list, (shape_name, shape)|
72
+ if shape['eventstream']
73
+ list << EventStreamClass.new(
74
+ class_name: shape_name,
75
+ types: struct_members(shape),
76
+ documentation: eventstream_class_docs(shape_name, shape)
77
+ )
78
+ else
79
+ list
80
+ end
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def struct_members(shape)
87
+ return if shape['members'].nil?
88
+ members = shape['members'].map do |member_name, member_ref|
89
+ sensitive = !!(member_ref['sensitive'] ||
90
+ @api['shapes'][member_ref['shape']]['sensitive'])
91
+ StructMember.new(
92
+ member_name: underscore(member_name),
93
+ sensitive: sensitive
94
+ )
95
+ end
96
+ if shape['event']
97
+ members << StructMember.new(member_name: 'event_type')
98
+ end
99
+ members
100
+ end
101
+
102
+ def struct_class_docs(shape_name, shape)
103
+ join_docstrings([
104
+ html_to_markdown(Api.docstring(shape_name, @api)),
105
+ input_example_docs(shape_name, shape),
106
+ output_example_docs(shape_name, shape),
107
+ attribute_macros_docs(shape_name),
108
+ see_also_tag(shape_name),
109
+ ])
110
+ end
111
+
112
+ def eventstream_class_docs(shape_name, shape)
113
+ join_docstrings([
114
+ html_to_markdown(Api.docstring(shape_name, @api)),
115
+ input_example_docs(shape_name, shape),
116
+ eventstream_docs(shape_name),
117
+ see_also_tag(shape_name),
118
+ ])
119
+ end
120
+
121
+ def eventstream_docs(shape_name)
122
+ "EventStream is an Enumerator of Events.\n"\
123
+ " #event_types #=> Array, returns all modeled event types in the stream"
124
+ end
125
+
126
+ def output_example_docs(shape_name, shape)
127
+ if @output_shapes.include?(shape_name)
128
+ if shape['union']
129
+ "@note #{shape_name} is a union - when returned from an API call"\
130
+ ' exactly one value will be set and the returned type will'\
131
+ " be a subclass of #{shape_name} corresponding to the set member."
132
+ end
133
+ end
134
+ end
135
+
136
+ def input_example_docs(shape_name, shape)
137
+ if @input_shapes.include?(shape_name)
138
+ return if shape(shape_name)['members'].nil?
139
+ if shape(shape_name)['members'].empty?
140
+ '@api private'
141
+ elsif shape['union']
142
+ "@note #{shape_name} is a union - when making an API calls you"\
143
+ ' must set exactly one of the members.'
144
+ else
145
+ note = "@note When making an API call, you may pass #{shape_name}\n"
146
+ note += " data as a hash:\n\n"
147
+ note += ' ' + SyntaxExampleHash.new(
148
+ shape: shape(shape_name),
149
+ api: @service.api,
150
+ ).format(' ')
151
+ end
152
+ end
153
+ end
154
+
155
+ def attribute_macros_docs(shape_name)
156
+ # APIG model downcase shape name in origin or "__" prefix in origin
157
+ if @service.protocol == 'api-gateway'
158
+ if shape(shape_name).nil?
159
+ if !shape(downcase_first(shape_name)).nil?
160
+ shape_name = downcase_first(shape_name)
161
+ elsif !shape(apig_prefix(shape_name)).nil?
162
+ shape_name = apig_prefix(shape_name)
163
+ else
164
+ shape_name = apig_prefix(downcase_first(shape_name))
165
+ end
166
+ end
167
+ end
168
+ return if shape(shape_name)['members'].nil?
169
+ shape(shape_name)['members'].map do |member_name, member_ref|
170
+ docs = Api.docstring(member_ref, @api).to_s
171
+ docs += idempotency_token_msg if idempotency_token?(member_ref)
172
+ docs = html_to_markdown(docs, line_width: 68)
173
+ docs = docs.to_s.lines.to_a.join(' ')
174
+ macro = "@!attribute [rw] #{underscore(member_name)}\n"
175
+ macro += " #{docs}\n" unless docs == ''
176
+ macro += " @return [#{Api.ruby_type(member_ref, @api)}]"
177
+ macro
178
+ end
179
+ end
180
+
181
+ def see_also_tag(shape_name)
182
+ uid = @api['metadata']['uid']
183
+ if @api['metadata']['protocol'] != 'api-gateway' && Crosslink.taggable?(uid)
184
+ Crosslink.tag_string(uid, shape_name)
185
+ end
186
+ end
187
+
188
+ def compute_input_shapes(api)
189
+ inputs = Set.new
190
+ (api['operations'] || {}).each do |_, operation|
191
+ visit_shapes(operation['input'], inputs) if operation['input']
192
+ end
193
+ inputs
194
+ end
195
+
196
+ def compute_output_shapes(api)
197
+ outputs = Set.new
198
+ (api['operations'] || {}).each do |_, operation|
199
+ visit_shapes(operation['output'], outputs) if operation['output']
200
+ end
201
+ outputs
202
+ end
203
+
204
+ def idempotency_token?(member_ref)
205
+ member_ref['idempotencyToken'] || shape(member_ref)['idempotencyToken']
206
+ end
207
+
208
+ def idempotency_token_msg
209
+ "<p><b>A suitable default value is auto-generated.</b> You should normally not need to pass this option.</p>"
210
+ end
211
+
212
+ def visit_shapes(shape_ref, shapes)
213
+ return if shapes.include?(shape_ref['shape']) # recursion
214
+ shapes << shape_ref['shape']
215
+ s = shape(shape_ref)
216
+ raise "cannot locate shape #{shape_ref['shape']}" if s.nil?
217
+ case s['type']
218
+ when 'structure'
219
+ return if s['members'].nil?
220
+ s['members'].each_pair do |_, member_ref|
221
+ visit_shapes(member_ref, shapes)
222
+ end
223
+ when 'list'
224
+ visit_shapes(s['member'], shapes)
225
+ when 'map'
226
+ visit_shapes(s['key'], shapes)
227
+ visit_shapes(s['value'], shapes)
228
+ end
229
+ end
230
+
231
+ def shape(shape_ref)
232
+ Api.resolve(shape_ref, @api)[1]
233
+ end
234
+
235
+ class EventStreamClass
236
+
237
+ def initialize(options)
238
+ @class_name = options.fetch(:class_name)
239
+ @types = options.fetch(:types)
240
+ @documentation = options.fetch(:documentation)
241
+ if @types.nil? || @types.empty?
242
+ @empty = true
243
+ else
244
+ @empty = false
245
+ @types.last.last = true
246
+ end
247
+ end
248
+
249
+ # @return [String]
250
+ attr_accessor :class_name
251
+
252
+ # @return [Array<StructMember>]
253
+ attr_accessor :types
254
+
255
+ # @return [String, nil]
256
+ attr_accessor :documentation
257
+
258
+ # @return [Boolean]
259
+ def empty?
260
+ @empty
261
+ end
262
+
263
+ end
264
+
265
+ class StructClass
266
+
267
+ def initialize(options)
268
+ @class_name = options.fetch(:class_name)
269
+ @members = options.fetch(:members)
270
+ @documentation = options.fetch(:documentation)
271
+ @sensitive_params = options.fetch(:sensitive_params)
272
+ @union = options.fetch(:union)
273
+ @members << StructMember.new(member_name: :unknown, member_class_name: 'Unknown') if @union
274
+ if @members.nil? || @members.empty?
275
+ @empty = true
276
+ else
277
+ @empty = false
278
+ @members.last.last = true
279
+ end
280
+ end
281
+
282
+ # @return [String]
283
+ attr_accessor :class_name
284
+
285
+ # @return [Array<StructMember>]
286
+ attr_accessor :members
287
+
288
+ # @return [String, nil]
289
+ attr_accessor :documentation
290
+
291
+ # @return [Array<Symbol>]
292
+ attr_accessor :sensitive_params
293
+
294
+ # @return [Boolean]
295
+ def union?
296
+ @union
297
+ end
298
+
299
+ # @return [Boolean]
300
+ def empty?
301
+ @empty
302
+ end
303
+ end
304
+
305
+ class StructMember
306
+
307
+ def initialize(options)
308
+ @member_name = options.fetch(:member_name)
309
+ @member_class_name = AwsSdkCodeGenerator::Helper::pascal_case(@member_name)
310
+ @sensitive = options.fetch(:sensitive, false)
311
+ @last = false
312
+ end
313
+
314
+ # @return [String]
315
+ attr_accessor :member_name
316
+
317
+ # @return [Boolean]
318
+ attr_accessor :sensitive
319
+
320
+ # @return [String]
321
+ attr_accessor :member_class_name
322
+
323
+ # @return [Boolean]
324
+ attr_accessor :last
325
+
326
+ end
327
+ end
328
+ end
329
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AwsSdkCodeGenerator
2
4
  module Views
3
5
  class Version < View
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ module Views
5
+ class WaitersModule < View
6
+
7
+ def initialize(options)
8
+ @module_name = options.fetch(:module_name)
9
+ @waiters = Waiter.build_list(options.fetch(:waiters))
10
+ @custom = options.fetch(:custom)
11
+ end
12
+
13
+ # @return [String]
14
+ attr_reader :module_name
15
+
16
+ # @return [Array<Waiter>]
17
+ attr_reader :waiters
18
+
19
+ # @return [String|nil]
20
+ def generated_src_warning
21
+ return if @custom
22
+ GENERATED_SRC_WARNING
23
+ end
24
+
25
+ # @return [Boolean]
26
+ def waiters?
27
+ waiters.size > 0
28
+ end
29
+
30
+ # @return [String<Markdown>]
31
+ def waiters_markdown_table
32
+ Waiter.markdown_table(@waiters)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gemspec'
2
4
 
3
5
  module Views; end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class Waiter
5
+
6
+ # @return [String]
7
+ attr_accessor :name
8
+
9
+ # @return [String]
10
+ attr_accessor :documentation
11
+
12
+ # @return [String]
13
+ attr_accessor :class_name
14
+
15
+ # @return [String]
16
+ attr_accessor :client_method
17
+
18
+ # @return [Integer]
19
+ attr_accessor :delay
20
+
21
+ # @return [Integer]
22
+ attr_accessor :max_attempts
23
+
24
+ # @return [String]
25
+ attr_accessor :acceptors
26
+
27
+ # @return [Boolean]
28
+ attr_accessor :last
29
+
30
+ class << self
31
+
32
+ # @return [Array<Waiter>]
33
+ def build_list(waiters)
34
+ waiters = waiters ? waiters['waiters'] : {}
35
+ waiters = waiters.map do |waiter_name, waiter|
36
+ Waiter.new.tap do |w|
37
+ w.name = Underscore.underscore(waiter_name)
38
+ w.class_name = waiter_name
39
+ w.client_method = Underscore.underscore(waiter['operation'])
40
+ w.delay = waiter['delay'].to_i
41
+ w.max_attempts = waiter['maxAttempts'].to_i
42
+ w.acceptors = acceptors(waiter['acceptors'])
43
+ w.documentation = Docstring.block_comment(waiter['description'])
44
+ end
45
+ end.sort_by(&:name)
46
+ waiters.last.last = true unless waiters.empty?
47
+ waiters
48
+ end
49
+
50
+ # @return [Map<String, Array<Waiter> >]
51
+ def build_operations_map(waiters)
52
+ operations_map = {}
53
+ waiters = build_list(waiters)
54
+ waiters.each do |w|
55
+ (operations_map[w.client_method] ||= []) << w
56
+ end
57
+ operations_map
58
+ end
59
+
60
+ # @param [Array<Waiter>]
61
+ # @return [String<Markdown>]
62
+ def markdown_table(waiters)
63
+ table = []
64
+ table << ['waiter_name', 'params', ':delay', ':max_attempts']
65
+ waiters.each do |waiter|
66
+ table << [
67
+ waiter.name,
68
+ "{Client##{waiter.client_method}}",
69
+ waiter.delay,
70
+ waiter.max_attempts
71
+ ]
72
+ end
73
+ Docstring.markdown_table(table)
74
+ end
75
+
76
+ private
77
+
78
+ def acceptors(acceptors)
79
+ acceptors.each do |acceptor|
80
+ if acceptor['argument']
81
+ acceptor['argument'] = Underscore.underscore_jmespath(
82
+ acceptor['argument']
83
+ )
84
+ end
85
+ end
86
+ HashFormatter.new(
87
+ wrap: false,
88
+ inline: false,
89
+ quote_strings: true
90
+ ).format(acceptors: acceptors)
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class YardOptionTag
5
+
6
+ # @option options [required, String] :name
7
+ # @option options [Boolean] :required (false)
8
+ # @option options [required, String] :ruby_type
9
+ # @option options [String, nil] :docstring (nil)
10
+ # @option options [Object] :default_value
11
+ # @option options [String] :option_hash_name ('options')
12
+ def initialize(options)
13
+ @name = options.fetch(:name)
14
+ @ruby_type = options.fetch(:ruby_type)
15
+ @required = options.fetch(:required, false) ? 'required, ' : ''
16
+ @docstring = options.fetch(:docstring).to_s
17
+ @default_value = options[:default_value]
18
+ @option_hash_name = options.fetch(:option_hash_name, 'options')
19
+ @indent = options.fetch(:indent, "")
20
+ end
21
+
22
+ def build
23
+ if @docstring.empty?
24
+ first_line.rstrip
25
+ else
26
+ first_line + Docstring.block_comment(@docstring, gap: " #{@indent}")
27
+ end
28
+ end
29
+ alias to_str build
30
+ alias to_s build
31
+
32
+ private
33
+
34
+ def first_line
35
+ "# #{@indent}@option #{@option_hash_name} [#{@required}#{@ruby_type}] :#{@name}#{default_value}\n"
36
+ end
37
+
38
+ def default_value
39
+ @default_value.nil? ? '' : " (#{@default_value.inspect})"
40
+ end
41
+
42
+ end
43
+ end