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,5 +1,8 @@
1
- require 'kramdown'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'set'
4
+ # kramdown
5
+ require 'kramdown'
3
6
 
4
7
  # disable inline attribute lists
5
8
  class Kramdown::Converter::Kramdown
@@ -7,6 +10,7 @@ class Kramdown::Converter::Kramdown
7
10
  nil
8
11
  end
9
12
  end
13
+ # end kramdown
10
14
 
11
15
  module AwsSdkCodeGenerator
12
16
  module Helper
@@ -21,37 +25,21 @@ module AwsSdkCodeGenerator
21
25
  end
22
26
  end
23
27
 
24
- # @param [Array<Array<String>>]
25
- def markdown_table(table)
26
- # compute the width of each column by scanning for longest values
27
- column_width = lambda do |col|
28
- table.map { |row| row[col].size }.max
29
- end
30
- widths = [
31
- column_width.call(0),
32
- column_width.call(1),
33
- column_width.call(2),
34
- column_width.call(3),
35
- ]
36
-
37
- # insert a dashed line after the header row
38
- table = [
39
- table[0],
40
- ['-' * widths[0], '-' * widths[1], '-' * widths[2], '-' * widths[3]]
41
- ] + table[1..-1]
42
-
43
- # build the final table
44
- line = "| #{widths.map{|n| "%-#{n}s" }.join(' | ')} |"
45
- table.map { |row| line % row }.join("\n")
46
- end
47
- module_function :markdown_table
48
-
49
28
  def underscore(str)
50
29
  str.split('.').map do |part|
51
30
  Underscore.underscore(part)
52
31
  end.join('.')
53
32
  end
54
33
 
34
+ # convert a snake case to pascal case
35
+ def pascal_case(str)
36
+ str
37
+ .to_s
38
+ .split('_')
39
+ .collect(&:capitalize)
40
+ .join
41
+ end
42
+
55
43
  def structures
56
44
  Enumerator.new do |y|
57
45
  (@api['shapes'] || {}).each do |shape_name, shape|
@@ -62,64 +50,6 @@ module AwsSdkCodeGenerator
62
50
  end
63
51
  end
64
52
 
65
- # @option options [Boolean] :nested (false)
66
- def ruby_input_type(shape_ref, options = {})
67
- nested = options.fetch(:nested, false)
68
- shape = @api['shapes'][shape_ref['shape']]
69
- case shape['type']
70
- when 'byte' then 'Integer<byte>'
71
- when 'blob' then 'String, IO'
72
- when 'boolean' then 'Boolean'
73
- when 'character' then 'String<character>'
74
- when 'double' then 'Float'
75
- when 'float' then 'Float'
76
- when 'integer' then 'Integer'
77
- when 'list'
78
- if nested
79
- "Array"
80
- else
81
- "Array<#{ruby_input_type(shape['member'], nested:true)}>"
82
- end
83
- when 'long' then 'Integer'
84
- when 'map'
85
- if nested
86
- "Hash"
87
- else
88
- "Hash<String,#{ruby_input_type(shape['value'], nested:true)}>"
89
- end
90
- when 'string' then 'String'
91
- when 'structure' then "Types::#{shape_ref['shape']}"
92
- when 'timestamp' then 'Time,DateTime,Date,Integer,String'
93
- else
94
- raise "unhandled type #{shape.type}.inspect"
95
- end
96
- end
97
-
98
- def ruby_type(shape_ref)
99
- shape = @api['shapes'][shape_ref['shape']]
100
- case shape['type']
101
- when 'blob' then streaming?(shape_ref, shape) ? 'IO' : 'String'
102
- when 'boolean' then 'Boolean'
103
- when 'byte' then 'Integer<byte>'
104
- when 'character' then 'String<character>'
105
- when 'double' then 'Float'
106
- when 'float' then 'Float'
107
- when 'integer' then 'Integer'
108
- when 'list' then "Array<#{ruby_type(shape['member'])}>"
109
- when 'long' then 'Integer'
110
- when 'map' then "Hash<String,#{ruby_type(shape['value'])}>"
111
- when 'string' then 'String'
112
- when 'structure' then "Types::#{shape_ref['shape']}"
113
- when 'timestamp' then 'Time'
114
- else
115
- raise "unhandled type #{shape['type'].inspect}"
116
- end
117
- end
118
-
119
- def streaming?(ref, shape)
120
- ref['streaming'] || shape['streaming']
121
- end
122
-
123
53
  # @option options [Integer] :line_width (70)
124
54
  def documentation(ref_or_shape, options = {})
125
55
  line_width = options.fetch(:line_width, 70)
@@ -143,6 +73,30 @@ module AwsSdkCodeGenerator
143
73
  shape(member_ref)
144
74
  end
145
75
 
76
+ def upcase_first(name)
77
+ if name[0] =~ /[a-z]/
78
+ name.size == 1 ? name.upcase : name[0].upcase + name[1..-1]
79
+ else
80
+ name
81
+ end
82
+ end
83
+
84
+ def downcase_first(name)
85
+ if name[0] =~/[A-Z]/
86
+ name.size == 1 ? name.downcase : name[0].downcase + name[1..-1]
87
+ else
88
+ name
89
+ end
90
+ end
91
+
92
+ def lstrip_prefix(name)
93
+ name.start_with?("__") ? name[2..-1] : name
94
+ end
95
+
96
+ def apig_prefix(name)
97
+ "__#{name}"
98
+ end
99
+
146
100
  def shape(ref)
147
101
  if ref.nil?
148
102
  nil
@@ -153,44 +107,50 @@ module AwsSdkCodeGenerator
153
107
  end
154
108
  end
155
109
 
110
+ # @param [String<HTML>] html
156
111
  # @option options [Integer] :line_width (70)
157
112
  def markdown(html, options = {})
158
- line_width = options.fetch(:line_width, 70)
159
- # TODO : this section of code is **very slow** and runs many times
160
- # while building a service.
161
- if html
162
- html = "<p>#{html}</p>" unless html.match(/<\w+>/)
163
-
164
- # unescaped curly braces cause YARD errors, they are interpreted
165
- # as code links.
166
- html = html.gsub('{', "\\{").gsub('}', "\\}")
167
-
168
- # Kramdown generates invalid markup when there are attributes
169
- # on the code tag, have to reduce these down to get the proper markdown.
170
- html = html.gsub(/<code.*?>(.+?)<\/code>/) { "<code>#{$1}</code>" }
171
-
172
- # Kramdown creates invalid markup with target="_blank" attributes.
173
- html = html.gsub(' target="_blank"', '')
174
-
175
- # There are quite a few empty <a> tags. These appear to be code names,
176
- # such as structure member names, or structure type names. We should
177
- # investigate if it is possible to inflect these properly and then
178
- # turn them into YARD links.
179
- html = html.gsub(/<a>(.+?)<\/a>/) { $1 }
180
-
181
- # <important> tag doesn't render well
182
- html = html.gsub(/<important>(.+?)<\/important>/){ "<p>#{$1}</p>" }
183
-
184
- markdown = Kramdown::Document.new(
185
- html,
186
- input: 'html',
187
- line_width: line_width,
188
- auto_ids: false
189
- ).to_kramdown.strip
190
-
191
- # remove extra escape
192
- markdown.gsub(/\\(\*|`|'|")/, '\1')
113
+ Docstring.html_to_markdown(html, options)
114
+ end
115
+
116
+ def operation_streaming?(operation, api)
117
+ return unless operation.key? 'output'
118
+ output = operation['output']['shape']
119
+ if api['shapes'][output].key? 'payload'
120
+ output_shape = api['shapes'][output]
121
+ payload = output_shape['payload']
122
+ if output_shape.key? 'members'
123
+ payload_ref = output_shape['members'][payload]
124
+ elsif output_shape.key? 'member'
125
+ payload_ref = output_shape['member'][payload]
126
+ end
127
+ Api.streaming?(payload_ref, api)
128
+ end
129
+ end
130
+
131
+ def operation_eventstreaming?(operation, api)
132
+ !!eventstream_input?(operation, api) ||
133
+ !!eventstream_output?(operation, api)
134
+ end
135
+
136
+ def eventstream_output?(operation, api)
137
+ return false unless operation.key? 'output'
138
+ output_shape = api['shapes'][operation['output']['shape']]
139
+ return false unless output_shape.key? 'members'
140
+ output_shape['members'].each do |name, ref|
141
+ return ref['shape'] if Api.eventstream?(ref, api)
193
142
  end
143
+ return false
144
+ end
145
+
146
+ def eventstream_input?(operation, api)
147
+ return false unless operation.key? 'input'
148
+ input_shape = api['shapes'][operation['input']['shape']]
149
+ return false unless input_shape.key? 'members'
150
+ input_shape['members'].each do |name, ref|
151
+ return ref['shape'] if Api.eventstream?(ref, api)
152
+ end
153
+ return false
194
154
  end
195
155
 
196
156
  def deep_copy(obj)
@@ -211,5 +171,12 @@ module AwsSdkCodeGenerator
211
171
  end
212
172
  end
213
173
 
174
+ def wrap_string(str, width, indent = '')
175
+ str.gsub(/(.{1,#{width}})(\s+|\Z)/, "#{indent}\\1\n").chomp
176
+ end
177
+
178
+ module_function :deep_copy, :operation_streaming?, :downcase_first, :wrap_string, :apig_prefix,
179
+ :eventstream_output?, :eventstream_input?, :operation_eventstreaming?, :pascal_case
180
+
214
181
  end
215
182
  end
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class PluginList
5
+
6
+ include Enumerable
7
+
8
+ def initialize(options)
9
+ @aws_sdk_core_lib_path = options.fetch(:aws_sdk_core_lib_path)
10
+ @plugins = compute_plugins(options)
11
+ end
12
+
13
+ # @return [Enumerable<Plugin>]
14
+ def each(&block)
15
+ @plugins.each(&block)
16
+ end
17
+
18
+ private
19
+
20
+ def compute_plugins(options)
21
+ plugins = {}
22
+ plugins.update(options[:async_client] ? default_async_plugins : default_plugins)
23
+ plugins.update(signature_plugins(options.fetch(:signature_version)))
24
+ plugins.update(protocol_plugins(options.fetch(:protocol)))
25
+ plugins.update(options.fetch(:add_plugins))
26
+ options.fetch(:remove_plugins).each do |plugin_name|
27
+ plugins.delete(plugin_name)
28
+ end
29
+ plugins.map do |class_name, path|
30
+ path = File.absolute_path(path)
31
+ Kernel.require(path)
32
+
33
+ Plugin.new(
34
+ class_name: class_name,
35
+ options: const_get(class_name).options,
36
+ path: path)
37
+ end
38
+ end
39
+
40
+ def default_plugins
41
+ {
42
+ 'Seahorse::Client::Plugins::ContentLength' => "#{seahorse_plugins}/content_length.rb",
43
+ 'Aws::Plugins::CredentialsConfiguration' => "#{core_plugins}/credentials_configuration.rb",
44
+ 'Aws::Plugins::Logging' => "#{core_plugins}/logging.rb",
45
+ 'Aws::Plugins::ParamConverter' => "#{core_plugins}/param_converter.rb",
46
+ 'Aws::Plugins::ParamValidator' => "#{core_plugins}/param_validator.rb",
47
+ 'Aws::Plugins::UserAgent' => "#{core_plugins}/user_agent.rb",
48
+ 'Aws::Plugins::HelpfulSocketErrors' => "#{core_plugins}/helpful_socket_errors.rb",
49
+ 'Aws::Plugins::RetryErrors' => "#{core_plugins}/retry_errors.rb",
50
+ 'Aws::Plugins::GlobalConfiguration' => "#{core_plugins}/global_configuration.rb",
51
+ 'Aws::Plugins::RegionalEndpoint' => "#{core_plugins}/regional_endpoint.rb",
52
+ 'Aws::Plugins::EndpointDiscovery' => "#{core_plugins}/endpoint_discovery.rb",
53
+ 'Aws::Plugins::EndpointPattern' => "#{core_plugins}/endpoint_pattern.rb",
54
+ 'Aws::Plugins::ResponsePaging' => "#{core_plugins}/response_paging.rb",
55
+ 'Aws::Plugins::StubResponses' => "#{core_plugins}/stub_responses.rb",
56
+ 'Aws::Plugins::IdempotencyToken' => "#{core_plugins}/idempotency_token.rb",
57
+ 'Aws::Plugins::JsonvalueConverter' => "#{core_plugins}/jsonvalue_converter.rb",
58
+ 'Aws::Plugins::ClientMetricsPlugin' => "#{core_plugins}/client_metrics_plugin.rb",
59
+ 'Aws::Plugins::ClientMetricsSendPlugin' => "#{core_plugins}/client_metrics_send_plugin.rb",
60
+ 'Aws::Plugins::TransferEncoding' => "#{core_plugins}/transfer_encoding.rb",
61
+ 'Aws::Plugins::HttpChecksum' => "#{core_plugins}/http_checksum.rb"
62
+ }
63
+ end
64
+
65
+ def default_async_plugins
66
+ plugins = default_plugins.dup
67
+ plugins.delete('Seahorse::Client::Plugins::ContentLength')
68
+ plugins.delete('Aws::Plugins::ResponsePaging')
69
+ plugins.delete('Aws::Plugins::EndpointDiscovery')
70
+ plugins.delete('Aws::Plugins::EndpointPattern')
71
+ plugins.delete('Aws::Plugins::ClientMetricsPlugin')
72
+ plugins.delete('Aws::Plugins::ClientMetricsSendPlugin')
73
+ plugins.delete('Aws::Plugins::TransferEncoding')
74
+ plugins['Aws::Plugins::InvocationId'] = "#{core_plugins}/invocation_id.rb"
75
+ plugins
76
+ end
77
+
78
+ def protocol_plugins(protocol)
79
+ {
80
+ 'json' => { 'Aws::Plugins::Protocols::JsonRpc' => "#{core_plugins}/protocols/json_rpc.rb" },
81
+ 'rest-json' => { 'Aws::Plugins::Protocols::RestJson' => "#{core_plugins}/protocols/rest_json.rb" },
82
+ 'rest-xml' => { 'Aws::Plugins::Protocols::RestXml' => "#{core_plugins}/protocols/rest_xml.rb" },
83
+ 'query' => { 'Aws::Plugins::Protocols::Query' => "#{core_plugins}/protocols/query.rb" },
84
+ 'ec2' => { 'Aws::Plugins::Protocols::EC2' => "#{core_plugins}/protocols/ec2.rb" },
85
+ 'api-gateway' => {
86
+ 'Aws::Plugins::Protocols::ApiGateway' => "#{core_plugins}/protocols/api_gateway.rb",
87
+ 'Aws::Plugins::ApiKey' => "#{core_plugins}/api_key.rb",
88
+ 'Aws::Plugins::APIGUserAgent' => "#{core_plugins}/apig_user_agent.rb",
89
+ 'Aws::Plugins::APIGAuthorizerToken' => "#{core_plugins}/apig_authorizer_token.rb",
90
+ 'Aws::Plugins::APIGCredentialsConfiguration' => "#{core_plugins}/apig_credentials_configuration.rb"
91
+ },
92
+ nil => {}
93
+ }[protocol]
94
+ end
95
+
96
+ def signature_plugins(signature_version)
97
+ case signature_version
98
+ when 'v4'
99
+ { 'Aws::Plugins::SignatureV4' => "#{core_plugins}/signature_v4.rb" }
100
+ when 'v2'
101
+ { 'Aws::Plugins::SignatureV2' => "#{core_plugins}/signature_v2.rb" }
102
+ else
103
+ {}
104
+ end
105
+ end
106
+
107
+ def core_plugins
108
+ File.join(@aws_sdk_core_lib_path, 'aws-sdk-core/plugins')
109
+ end
110
+
111
+ def seahorse_plugins
112
+ File.join(@aws_sdk_core_lib_path, 'seahorse/client/plugins')
113
+ end
114
+
115
+ def core_lib
116
+ # TODO : may need to register the default plugins directory rather
117
+ # than have the hard-coded here as a relative path
118
+ File.expand_path('../../../../../gems/aws-sdk-core/lib', __FILE__)
119
+ end
120
+
121
+ def const_get(class_name)
122
+ const_names = class_name.split('::')
123
+ const_names.inject(Kernel) do |const, const_name|
124
+ const.const_get(const_name)
125
+ end
126
+ end
127
+
128
+ class Plugin
129
+
130
+ def initialize(options)
131
+ @class_name = options.fetch(:class_name)
132
+ @options = options.fetch(:options)
133
+ @require_path = options.fetch(:path).split('/lib/').last
134
+ end
135
+
136
+ # @return [String]
137
+ attr_reader :class_name
138
+
139
+ # @return [Array<Seahorse::Client::Plugin::PluginOption>]
140
+ attr_reader :options
141
+
142
+ # @return [String]
143
+ attr_reader :require_path
144
+
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceAction
5
+ class << self
6
+
7
+ include Helper
8
+
9
+ # @return [Array<ResourceMethod>]
10
+ def build_list(resource_name, resource, api)
11
+ resource.fetch('actions', {}).map do |action_name, action|
12
+ build(
13
+ resource_name: resource_name,
14
+ action_name: action_name,
15
+ action: action,
16
+ api: api
17
+ )
18
+ end
19
+ end
20
+
21
+ # @option options [required, String] :resource_name
22
+ # @option options [required, String] :action_name
23
+ # @option options [required, String] :action
24
+ # @option options [required, String] :api
25
+ def build(options)
26
+ ResourceMethod.new.tap do |m|
27
+ m.method_name = Underscore.underscore(options.fetch(:action_name))
28
+ m.arguments = 'options = {}'
29
+ operation_name = options.fetch(:action)['request']['operation']
30
+ api = options.fetch(:api)
31
+ if operation_streaming?(api['operations'][operation_name], api)
32
+ m.arguments += ', &block'
33
+ options[:streaming] = true
34
+ end
35
+ m.code = ResourceActionCode.new(options).build
36
+ m.documentation = documentation(options)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def documentation(options)
43
+ api = options.fetch(:api)
44
+ action = options.fetch(:action)
45
+ operation = api['operations'][action['request']['operation']]
46
+ ResourceClientReqeustDocumentation.new(
47
+ method_name: Underscore.underscore(options.fetch(:action_name)),
48
+ receiver: Underscore.underscore(options.fetch(:resource_name)),
49
+ resp_var: action['resource'] ? action['resource']['type'].downcase : nil,
50
+ returns: returns(action, operation),
51
+ request: action['request'],
52
+ api: api,
53
+ ).build
54
+ end
55
+
56
+ def returns(action, operation)
57
+ if action['resource']
58
+ resource = action['resource']
59
+ Api.plural?(resource) ? "#{resource['type']}::Collection" : resource['type']
60
+ elsif operation['output']
61
+ "Types::#{operation['output']['shape']}"
62
+ else
63
+ "EmptyStructure"
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceActionCode
5
+
6
+ def initialize(options)
7
+ action = options.fetch(:action)
8
+ @request = action.fetch('request')
9
+ @resource = action.fetch('resource', nil)
10
+ @streaming = options.fetch(:streaming, false)
11
+ end
12
+
13
+ def build
14
+ parts = []
15
+ if batch_action?
16
+ parts << 'batch = []'
17
+ parts << client_request
18
+ parts << ResourceBatchBuilder.new(resource: @resource).build
19
+ parts << "#{resource_type}::Collection.new([batch], size: batch.size)"
20
+ elsif resource_action?
21
+ parts << client_request(
22
+ @resource['identifiers'].any? { |i| i['source'] == 'response' } || @resource['path']
23
+ )
24
+ parts << ResourceBuilder.new(resource: @resource, request_made: true).build
25
+ else
26
+ parts << client_request
27
+ parts << 'resp.data'
28
+ end
29
+ parts.join("\n").rstrip
30
+ end
31
+
32
+ private
33
+
34
+ def client_request(resp = true)
35
+ ResourceClientRequest.build(request: @request, resp: resp, streaming: @streaming)
36
+ end
37
+
38
+ def resource_type
39
+ @resource['type']
40
+ end
41
+
42
+ def batch_action?
43
+ if resource_action?
44
+ paths = (@resource['identifiers'] || []).map {|i| i['path'] }
45
+ paths << @resource['path']
46
+ paths.compact.any? { |path| path.match(/\[/) }
47
+ else
48
+ false
49
+ end
50
+ end
51
+
52
+ def resource_action?
53
+ !!@resource
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceAssociation
5
+ class << self
6
+
7
+ # @return [Array<ResourceMethod>]
8
+ def build_list(options)
9
+ associations = []
10
+ associations += has_associations(options)
11
+ associations += has_many_associations(options)
12
+ associations.sort_by(&:method_name)
13
+ end
14
+
15
+ private
16
+
17
+ def has_associations(options)
18
+ options.fetch(:resource).fetch('has', {}).map do |name, assoc|
19
+ ResourceHasAssociation.build(options.merge(
20
+ name: name,
21
+ assoc: assoc,
22
+ ))
23
+ end
24
+ end
25
+
26
+ def has_many_associations(options)
27
+ options.fetch(:resource).fetch('hasMany', {}).map do |name, assoc|
28
+ ResourceHasManyAssociation.build(options.merge(
29
+ name: name,
30
+ assoc: assoc,
31
+ ))
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceAttribute
5
+
6
+ # @return [String]
7
+ attr_accessor :name
8
+
9
+ # @return [String, nil]
10
+ attr_accessor :documentation
11
+
12
+ class << self
13
+
14
+ # @return [Array<ResourceAttribute>)
15
+ def build_list(resource, api)
16
+ if resource['shape']
17
+ data_attribute_names(resource, api).map do |member_name, member_ref|
18
+ docstring = Docstring.block_comment(
19
+ Docstring.html_to_markdown(Api.docstring(member_ref, api))
20
+ )
21
+ docstring = (docstring ? "#{docstring}\n" : '')
22
+ type = Api.ruby_type(member_ref, api)
23
+ ResourceAttribute.new.tap do |attr|
24
+ attr.name = Underscore.underscore(member_name)
25
+ attr.documentation = docstring + "# @return [#{type}]"
26
+ end
27
+ end
28
+ else
29
+ []
30
+ end
31
+
32
+ end
33
+
34
+ private
35
+
36
+ def data_attribute_names(resource, api)
37
+
38
+ identifiers = resource['identifiers']
39
+
40
+ skip = Set.new
41
+
42
+ # do no duplicate identifiers
43
+ identifiers.each do |i|
44
+ skip << i['name']
45
+ skip << i['memberName'] if i.key?('memberName')
46
+ end
47
+
48
+ # do no duplicate action names
49
+ (resource['actions'] || {}).keys.each do |action_name|
50
+ skip << action_name
51
+ end
52
+
53
+ # do no duplicate has association names
54
+ (resource['has'] || {}).keys.each do |association_name|
55
+ skip << association_name
56
+ end
57
+
58
+ # do no duplicate hasMany association names
59
+ (resource['hasMany'] || {}).keys.each do |association_name|
60
+ skip << association_name
61
+ end
62
+
63
+ shape = Api.shape(resource['shape'], api)
64
+ members = shape['members'] || {}
65
+ Enumerator.new do |y|
66
+ members.each do |member_name, member_ref|
67
+ unless skip.include?(member_name)
68
+ y.yield(member_name, member_ref)
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+ end
76
+ end