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
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ module Views
5
+ class AsyncClientClass < View
6
+
7
+ # @option options [required, String] :service_identifier
8
+ # @option options [required, String] :service_name
9
+ # @option options [required, String] :module_name
10
+ # @option options [required, String] :gem_name
11
+ # @option options [required, String] :gem_version
12
+ # @option options [required, String] :aws_sdk_core_lib_path
13
+ # @option options [required, String] :protocol
14
+ # @option options [required, String] :signature_version
15
+ # @option options [required, Hash] :add_plugins
16
+ # @option options [required, Array] :remove_plugins
17
+ # @option options [required, Hash] :api
18
+ # @option options [Hash] :client_examples
19
+ def initialize(options)
20
+ @service_identifier = options.fetch(:service_identifier)
21
+ @service_name = options.fetch(:service_name)
22
+ @module_name = options.fetch(:module_name)
23
+ @gem_name = options.fetch(:gem_name)
24
+ @gem_version = options.fetch(:gem_version)
25
+ @plugins = PluginList.new(options)
26
+ @client_constructor = ClientConstructor.new(plugins: @plugins)
27
+ @operations = ClientOperationList.new(options).to_a
28
+ end
29
+
30
+ # @return [String]
31
+ attr_reader :service_identifier
32
+
33
+ # @return [String]
34
+ attr_reader :service_name
35
+
36
+ # @return [String]
37
+ attr_reader :module_name
38
+
39
+ # @return [String]
40
+ attr_reader :gem_name
41
+
42
+ # @return [String]
43
+ attr_reader :gem_version
44
+
45
+ # @return [ClientConstructor]
46
+ attr_reader :client_constructor
47
+
48
+ # @return [Array<Operation>]
49
+ attr_reader :operations
50
+
51
+ # @return [String|nil]
52
+ def generated_src_warning
53
+ GENERATED_SRC_WARNING
54
+ end
55
+
56
+ # @return [Array<String>]
57
+ def plugin_requires
58
+ @plugins.map(&:require_path)
59
+ end
60
+
61
+ # @return [Array<String>]
62
+ def plugin_class_names
63
+ @plugins.map(&:class_name)
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ module Views
5
+
6
+ class AuthorizerClass < View
7
+
8
+ # @option options [required, String] :module_name
9
+ def initialize(options)
10
+ @module_name = options.fetch(:module_name)
11
+ end
12
+
13
+ attr_reader :module_name
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,602 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ module Views
5
+ class ClientApiModule < View
6
+
7
+ include Helper
8
+
9
+ SKIP_TRAITS = Set.new(%w(shape deprecated location locationName documentation))
10
+
11
+ SHAPE_CLASSES = {
12
+ 'blob' => 'BlobShape',
13
+ 'byte' => 'IntegerShape',
14
+ 'boolean' => 'BooleanShape',
15
+ 'character' => 'StringShape',
16
+ 'double' => 'FloatShape',
17
+ 'float' => 'FloatShape',
18
+ 'integer' => 'IntegerShape',
19
+ 'list' => 'ListShape',
20
+ 'long' => 'IntegerShape',
21
+ 'map' => 'MapShape',
22
+ 'string' => 'StringShape',
23
+ 'structure' => 'StructureShape',
24
+ 'timestamp' => 'TimestampShape'
25
+ }
26
+
27
+ SHAPE_KEYS = {
28
+ # keep
29
+ 'flattened' => true,
30
+ 'timestampFormat' => true, # glacier api customization
31
+ 'xmlNamespace' => true,
32
+ 'streaming' => true, # transfer-encoding
33
+ 'requiresLength' => true, # transfer-encoding
34
+ 'union' => false,
35
+ 'document' => true,
36
+ # event stream modeling
37
+ 'event' => false,
38
+ 'eventstream' => false,
39
+ 'eventheader' => false,
40
+ 'eventpayload' => false,
41
+ # ignore
42
+ 'synthetic' => false,
43
+ 'box' => false,
44
+ 'fault' => false,
45
+ 'error' => false,
46
+ 'deprecated' => false,
47
+ 'deprecatedMessage' => false,
48
+ 'type' => false,
49
+ 'documentation' => false,
50
+ 'members' => false,
51
+ 'member' => false,
52
+ 'key' => false,
53
+ 'locationName' => false,
54
+ 'value' => false,
55
+ 'required' => false,
56
+ 'enum' => false,
57
+ 'exception' => false,
58
+ 'payload' => false,
59
+ 'pattern' => false,
60
+ 'sensitive' => false,
61
+ 'min' => false,
62
+ 'max' => false,
63
+ 'wrapper' => false,
64
+ 'xmlOrder' => false,
65
+ 'retryable' => false,
66
+ }
67
+
68
+ METADATA_KEYS = {
69
+ # keep all
70
+ 'endpointPrefix' => true,
71
+ 'signatureVersion' => true,
72
+ 'signingName' => true,
73
+ 'serviceFullName' => true,
74
+ 'protocol' => true,
75
+ 'targetPrefix' => true,
76
+ 'jsonVersion' => true,
77
+ 'errorPrefix' => true,
78
+ 'timestampFormat' => true, # glacier api customization
79
+ 'xmlNamespace' => true,
80
+ 'protocolSettings' => {}, # current unused unless for h2 exclude
81
+ 'serviceId' => true,
82
+ 'apiVersion' => true,
83
+ 'checksumFormat' => true,
84
+ 'globalEndpoint' => true,
85
+ 'serviceAbbreviation' => true,
86
+ 'uid' => true
87
+ }
88
+
89
+ # @option options [required, Service] :service
90
+ def initialize(options)
91
+ @service = options.fetch(:service)
92
+ end
93
+
94
+ # @return [String|nil]
95
+ def generated_src_warning
96
+ return if @service.protocol == 'api-gateway'
97
+ GENERATED_SRC_WARNING
98
+ end
99
+
100
+ # @return [String]
101
+ def module_name
102
+ @service.module_name
103
+ end
104
+
105
+ # @return [String<YYYY-MM-DD>]
106
+ def api_version
107
+ @service.api_version
108
+ end
109
+
110
+ # @return [Array<Shape>]
111
+ def shapes
112
+ shape_enum.map do |shape_name, shape|
113
+ # APIG model, shape can start with downcase and with "__"
114
+ if @service.protocol == 'api-gateway'
115
+ shape_name = lstrip_prefix(upcase_first(shape_name))
116
+ end
117
+ Shape.new.tap do |s|
118
+ s.name = shape_name
119
+ s.class_name, shape = shape_class_name(shape)
120
+ s.constructor_args = shape_constructor_args(shape_name, shape)
121
+ end
122
+ end
123
+ end
124
+
125
+ def shape_definitions
126
+ shape_enum.inject([]) do |groups, (shape_name, shape)|
127
+ # APIG model, shape can start with downcase and with "__"
128
+ if @service.protocol == 'api-gateway'
129
+ shape_name = lstrip_prefix(upcase_first(shape_name))
130
+ end
131
+ lines = []
132
+ if non_error_struct?(shape) && !document_struct?(shape)
133
+ required = Set.new(shape['required'] || [])
134
+ unless shape['members'].nil?
135
+ shape['members'].each do |member_name, member_ref|
136
+ lines << "#{shape_name}.add_member(:#{underscore(member_name)}, #{shape_ref(member_ref, member_name, required)})"
137
+ end
138
+ end
139
+ if shape['union']
140
+ lines << "#{shape_name}.add_member(:unknown, Shapes::ShapeRef.new(shape: nil, location_name: 'unknown'))"
141
+ shape['members'].each do |member_name, member_ref|
142
+ member_name_underscore = underscore(member_name)
143
+ member_class_name = pascal_case(member_name_underscore)
144
+ lines << "#{shape_name}.add_member_subclass(:#{member_name_underscore}, Types::#{shape_name}::#{member_class_name})"
145
+ end
146
+ lines << "#{shape_name}.add_member_subclass(:unknown, Types::#{shape_name}::Unknown)"
147
+ end
148
+ lines << "#{shape_name}.struct_class = Types::#{shape_name}"
149
+ if payload = shape['payload']
150
+ lines << "#{shape_name}[:payload] = :#{underscore(payload)}"
151
+ lines << "#{shape_name}[:payload_member] = #{shape_name}.member(:#{underscore(payload)})"
152
+ end
153
+ groups << lines.join("\n")
154
+ elsif error_struct?(shape)
155
+ required = Set.new(shape['required'] || [])
156
+ unless shape['members'].nil?
157
+ shape['members'].each do |member_name, member_ref|
158
+ lines << "#{shape_name}.add_member(:#{underscore(member_name)}, #{shape_ref(member_ref, member_name, required)})"
159
+ end
160
+ end
161
+ lines << "#{shape_name}.struct_class = Types::#{shape_name}"
162
+ groups << lines.join("\n")
163
+ elsif shape['type'] == 'list'
164
+ lines << "#{shape_name}.member = #{shape_ref(shape['member'])}"
165
+ groups << lines.join("\n")
166
+ elsif shape['type'] == 'map'
167
+ lines << "#{shape_name}.key = #{shape_ref(shape['key'])}"
168
+ lines << "#{shape_name}.value = #{shape_ref(shape['value'])}"
169
+ groups << lines.join("\n")
170
+ else
171
+ groups
172
+ end
173
+ end
174
+ end
175
+
176
+ # @return [Array<Hash>]
177
+ def metadata
178
+ metadata = []
179
+ @service.api.fetch('metadata', {}).keys.sort.each do |key|
180
+ if METADATA_KEYS[key]
181
+ metadata << {
182
+ key: key.inspect,
183
+ value: @service.api['metadata'][key].inspect
184
+ }
185
+ elsif METADATA_KEYS[key].nil?
186
+ raise "unhandled metadata key #{key.inspect}"
187
+ end
188
+ end
189
+ metadata
190
+ end
191
+
192
+ def operations
193
+ @service.api['operations'].map do |operation_name, operation|
194
+ Operation.new.tap do |o|
195
+ o.name = operation['name'] || operation_name
196
+ o.method_name = underscore(operation_name)
197
+ o.http_method = operation['http']['method']
198
+ o.http_request_uri = operation['http']['requestUri']
199
+ o.http_checksum_required = true if operation['httpChecksumRequired']
200
+ %w(input output).each do |key|
201
+ if operation[key]
202
+ o.shape_references << "o.#{key} = #{operation_ref(operation[key])}"
203
+ else
204
+ o.shape_references << "o.#{key} = Shapes::ShapeRef.new(shape: Shapes::StructureShape.new(struct_class: Aws::EmptyStructure))"
205
+ end
206
+ end
207
+ o.error_shape_names = operation.fetch('errors', []).map {|e| e['shape'] }
208
+ o.deprecated = true if operation['deprecated']
209
+ o.endpoint_operation = true if operation['endpointoperation']
210
+ if operation.key?('endpointdiscovery')
211
+ # "endpointdiscovery" trait per operation
212
+ # contains hash values of configuration,
213
+ # current acked field: "required"
214
+ o.endpoint_discovery_available = true
215
+ o.endpoint_discovery = operation['endpointdiscovery'].inject([]) do |a, (k, v)|
216
+ a << { key: k.inspect, value: v.inspect }
217
+ a
218
+ end
219
+ # endpoint trait cannot be co-exist with endpoint discovery
220
+ elsif operation.key?('endpoint')
221
+ # endpoint trait per operation, cannot be enabled with endpoint discovery
222
+ o.endpoint_trait = true
223
+ o.endpoint_pattern = operation['endpoint'].inject([]) do |a, (k, v)|
224
+ a << { key: k.inspect, value: v.inspect }
225
+ a
226
+ end
227
+ end
228
+ o.authorizer = operation['authorizer'] if operation.key?('authorizer')
229
+ o.authtype = operation['authtype'] if operation.key?('authtype')
230
+ o.require_apikey = operation['requiresApiKey'] if operation.key?('requiresApiKey')
231
+ o.pager = pager(operation_name)
232
+ o.async = @service.protocol_settings['h2'] == 'eventstream' &&
233
+ AwsSdkCodeGenerator::Helper.operation_eventstreaming?(operation, @service.api)
234
+ end
235
+ end
236
+ end
237
+
238
+ def apig_authorizer
239
+ return nil unless @service.api.key? 'authorizers'
240
+ @service.api['authorizers'].map do |name, authorizer|
241
+ Authorizer.new.tap do |a|
242
+ a.name = name
243
+ a.authorizer_name = underscore(name)
244
+ a.type = authorizer['type'] if authorizer.key? 'type'
245
+ if authorizer.key? 'placement'
246
+ a.location = authorizer['placement']['location']
247
+ a.location_name = authorizer['placement']['name']
248
+ end
249
+ end
250
+ end
251
+ end
252
+
253
+ def endpoint_operation
254
+ @service.api['operations'].each do |name, ref|
255
+ return underscore(name) if ref['endpointoperation']
256
+ end
257
+ nil
258
+ end
259
+
260
+ def require_endpoint_discovery
261
+ @service.require_endpoint_discovery
262
+ end
263
+
264
+ private
265
+
266
+ def shape_class_name(shape)
267
+ type = shape['type']
268
+ # APIG time serializing difference
269
+ if @service.protocol == 'api-gateway' && type == 'timestamp'
270
+ shape['timestampFormat'] = 'iso8601'
271
+ end
272
+ if document_struct?(shape)
273
+ ["Shapes::DocumentShape", shape]
274
+ elsif shape['union']
275
+ ["Shapes::UnionShape", shape]
276
+ elsif SHAPE_CLASSES.key?(type)
277
+ ["Shapes::#{SHAPE_CLASSES[type]}", shape]
278
+ else
279
+ raise ArgumentError, "unsupported shape type `#{type}'"
280
+ end
281
+ end
282
+
283
+ def shape_constructor_args(shape_name, shape)
284
+ args = []
285
+ args << "name: '#{shape_name}'"
286
+ shape.each_pair do |key, value|
287
+ if SHAPE_KEYS[key]
288
+ args << "#{key}: #{value.inspect}"
289
+ elsif SHAPE_KEYS[key].nil?
290
+ raise "unhandled shape key #{key.inspect}"
291
+ end
292
+ end
293
+ args.join(', ')
294
+ end
295
+
296
+ def shape_enum
297
+ unless @service.protocol_settings.empty?
298
+ if @service.protocol_settings['h2'] == 'eventstream'
299
+ # some event shapes shared with error shapes
300
+ # might missing event trait
301
+ @service.api['shapes'].each do |_, shape|
302
+ if shape['eventstream']
303
+ # add event trait to all members if not exists
304
+ shape['members'].each do |name, ref|
305
+ @service.api['shapes'][ref['shape']]['event'] = true
306
+ end
307
+ end
308
+ end
309
+ end
310
+ end
311
+ Enumerator.new do |y|
312
+ @service.api.fetch('shapes', {}).keys.sort.each do |shape_name|
313
+ y.yield(shape_name, @service.api['shapes'].fetch(shape_name))
314
+ end
315
+ end
316
+ end
317
+
318
+ def non_error_struct?(shape)
319
+ if !!shape['event']
320
+ shape['type'] == 'structure'
321
+ else
322
+ shape['type'] == 'structure' &&
323
+ !shape['error'] &&
324
+ !shape['exception']
325
+ end
326
+ end
327
+
328
+ def error_struct?(shape)
329
+ shape['type'] == 'structure' && !!!shape['event'] &&
330
+ (shape['error'] || shape['exception'])
331
+ end
332
+
333
+ def document_struct?(shape)
334
+ shape['type'] == 'structure' && shape['document']
335
+ end
336
+
337
+ def structure_shape_enum
338
+ Enumerator.new do |y|
339
+ shape_enum.each do |shape_name, shape|
340
+ # non error types && non empty error struct
341
+ if non_error_struct?(shape) || error_struct?(shape)
342
+ y.yield(shape_name, shape)
343
+ end
344
+ end
345
+ end
346
+ end
347
+
348
+ def shape_ref(ref, member_name = nil, required = Set.new)
349
+ ref_name = ref['shape']
350
+ if @service.protocol == 'api-gateway'
351
+ ref_name = lstrip_prefix(ref_name)
352
+ end
353
+ line = "Shapes::ShapeRef.new(shape: #{ref_name}"
354
+ line += shape_ref_required(required, member_name)
355
+ line += shape_ref_deprecated(ref)
356
+ line += shape_ref_event(ref)
357
+ line += shape_ref_eventstream(ref)
358
+ line += shape_ref_eventpayload(ref)
359
+ line += shape_ref_eventheader(ref)
360
+ line += shape_ref_location(ref)
361
+ line += shape_ref_location_name(member_name, ref)
362
+ line += shape_ref_metadata(ref, member_name)
363
+ line += ")"
364
+ line
365
+ end
366
+
367
+ def shape_ref_required(required, member_name)
368
+ if required.include?(member_name)
369
+ ", required: true"
370
+ else
371
+ ""
372
+ end
373
+ end
374
+
375
+ def shape_ref_deprecated(ref)
376
+ if ref['deprecated'] || @service.api['shapes'][ref['shape']]['deprecated']
377
+ ", deprecated: true"
378
+ else
379
+ ""
380
+ end
381
+ end
382
+
383
+ def shape_ref_eventstream(ref)
384
+ if @service.api['shapes'][ref['shape']]['eventstream']
385
+ ", eventstream: true"
386
+ else
387
+ ''
388
+ end
389
+ end
390
+
391
+ def shape_ref_event(ref)
392
+ if @service.api['shapes'][ref['shape']]['event']
393
+ ", event: true"
394
+ else
395
+ ''
396
+ end
397
+ end
398
+
399
+ def shape_ref_eventpayload(ref)
400
+ if ref['eventpayload']
401
+ type = @service.api['shapes'][ref['shape']]['type']
402
+ ", eventpayload: true, eventpayload_type: '#{type}'"
403
+ else
404
+ ''
405
+ end
406
+ end
407
+
408
+ def shape_ref_eventheader(ref)
409
+ if ref['eventheader']
410
+ type = @service.api['shapes'][ref['shape']]['type']
411
+ ", eventheader: true, eventheader_type: '#{type}'"
412
+ else
413
+ ''
414
+ end
415
+ end
416
+
417
+ def shape_ref_location(ref)
418
+ if ref['location']
419
+ ", location: #{ref['location'].inspect}"
420
+ else
421
+ ''
422
+ end
423
+ end
424
+
425
+ def shape_ref_location_name(member_name, member_ref)
426
+ location_name = member_ref['locationName']
427
+ location_name ||= member_name unless member_ref['location'] == 'headers'
428
+ location_name ? ", location_name: #{location_name.inspect}" : ""
429
+ end
430
+
431
+ def shape_ref_metadata(member_ref, member_name)
432
+ metadata = member_ref.inject({}) do |hash, (key, value)|
433
+ hash[key] = value unless SKIP_TRAITS.include?(key)
434
+ if key == 'hostLabel'
435
+ hash['hostLabelName'] = member_name
436
+ end
437
+ hash
438
+ end
439
+ if metadata.empty?
440
+ ""
441
+ else
442
+ ", metadata: #{metadata.inspect}"
443
+ end
444
+ end
445
+
446
+ def pager(operation_name)
447
+ if @service.paginators && @service.paginators['pagination'][operation_name]
448
+ p = @service.paginators['pagination'][operation_name]
449
+ input = Array(p['input_token'])
450
+ output = Array(p['output_token'])
451
+ tokens = {}
452
+ input.each.with_index do |key, n|
453
+ tokens[underscore_jmespath(output[n])] = underscore_jmespath(key)
454
+ end
455
+ options = {}
456
+ options[:more_results] = underscore_jmespath(p['more_results']) if p['more_results']
457
+ options[:limit_key] = underscore_jmespath(p['limit_key']) if p['limit_key']
458
+ options[:tokens] = tokens
459
+ options = HashFormatter.new(
460
+ quote_strings: true,
461
+ inline: true,
462
+ wrap: false,
463
+ ).format(options)
464
+ "o[:pager] = Aws::Pager.new(#{options})" unless tokens.empty?
465
+ end
466
+ end
467
+
468
+ def operation_ref(ref)
469
+ metadata = ref.dup
470
+ shape_name = metadata.delete('shape')
471
+ # APIG model, shape can start with downcase and with "__"
472
+ if @service.protocol == 'api-gateway'
473
+ shape_name = lstrip_prefix(upcase_first(shape_name))
474
+ end
475
+ if metadata.empty?
476
+ options = ''
477
+ else
478
+ options = {}
479
+ metadata.each_pair do |key, value|
480
+ next if key == 'resultWrapper'
481
+ if key == 'locationName'
482
+ options[:location_name] = value.inspect
483
+ else
484
+ options[:metadata] ||= {}
485
+ options[:metadata][key] = value.inspect
486
+ end
487
+ end
488
+ if options.empty?
489
+ options = ''
490
+ else
491
+ opts = HashFormatter.new(wrap:false).format(options)
492
+ if opts[0] == "\n"
493
+ options = ",#{opts}"
494
+ else
495
+ options = ", #{opts}"
496
+ end
497
+ end
498
+ end
499
+ "Shapes::ShapeRef.new(shape: #{shape_name}#{options})"
500
+ end
501
+
502
+
503
+ class Shape
504
+
505
+ # @return [String]
506
+ attr_accessor :name
507
+
508
+ # @return [String<ClassName>]
509
+ attr_accessor :class_name
510
+
511
+ # @return [String]
512
+ attr_accessor :constructor_args
513
+
514
+ end
515
+
516
+ class Operation
517
+
518
+ def initialize
519
+ @shape_references = []
520
+ @error_shape_names = []
521
+ end
522
+
523
+ # @return [String] The UpperCamelCase operation name.
524
+ attr_accessor :name
525
+
526
+ # @return [String] The underscored method name.
527
+ attr_accessor :method_name
528
+
529
+ # @return [String] GET, PUT, POST, etc.
530
+ attr_accessor :http_method
531
+
532
+ # @return [String] "/", "/path?query", etc.
533
+ attr_accessor :http_request_uri
534
+
535
+ # @return [Boolean]
536
+ attr_accessor :http_checksum_required
537
+
538
+ # @return [Array<String>]
539
+ attr_accessor :shape_references
540
+
541
+ # @return [Array<String>]
542
+ attr_accessor :error_shape_names
543
+
544
+ # @return [Boolean]
545
+ attr_accessor :deprecated
546
+
547
+ # @return [Boolean]
548
+ attr_accessor :endpoint_discovery_available
549
+
550
+ # @return [Boolean]
551
+ attr_accessor :endpoint_operation
552
+
553
+ # @return [Array]
554
+ attr_accessor :endpoint_discovery
555
+
556
+ # @return [String,nil]
557
+ attr_accessor :authtype
558
+
559
+ # @return [Boolean]
560
+ attr_accessor :endpoint_trait
561
+
562
+ # @return [Array]
563
+ attr_accessor :endpoint_pattern
564
+
565
+ # APIG only
566
+ # @return [Boolean]
567
+ attr_accessor :require_apikey
568
+
569
+ # APIG only
570
+ # @return [String, nil]
571
+ attr_accessor :authorizer
572
+
573
+ # @return [Pager, nil]
574
+ attr_accessor :pager
575
+
576
+ # @return [Boolean]
577
+ attr_accessor :async
578
+
579
+ end
580
+
581
+ # APIG SDK only
582
+ class Authorizer
583
+
584
+ # @return [String]
585
+ attr_accessor :name
586
+
587
+ # @return [String]
588
+ attr_accessor :authorizer_name
589
+
590
+ # @return [String]
591
+ attr_accessor :type
592
+
593
+ # @return [String]
594
+ attr_accessor :location
595
+
596
+ # @return [String]
597
+ attr_accessor :location_name
598
+
599
+ end
600
+ end
601
+ end
602
+ end