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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +5 -5
  2. data/lib/aws-sdk-code-generator.rb +68 -75
  3. data/lib/aws-sdk-code-generator/api.rb +130 -0
  4. data/lib/aws-sdk-code-generator/apply_docs.rb +15 -2
  5. data/lib/aws-sdk-code-generator/client_constructor.rb +39 -0
  6. data/lib/aws-sdk-code-generator/client_operation_documentation.rb +268 -0
  7. data/lib/aws-sdk-code-generator/client_operation_list.rb +148 -0
  8. data/lib/aws-sdk-code-generator/client_response_structure_example.rb +108 -0
  9. data/lib/aws-sdk-code-generator/code_builder.rb +146 -133
  10. data/lib/aws-sdk-code-generator/crosslink.rb +42 -0
  11. data/lib/aws-sdk-code-generator/docstring.rb +199 -0
  12. data/lib/aws-sdk-code-generator/error_list.rb +77 -0
  13. data/lib/aws-sdk-code-generator/errors.rb +2 -0
  14. data/lib/aws-sdk-code-generator/eventstream_example.rb +220 -0
  15. data/lib/aws-sdk-code-generator/gem_builder.rb +19 -25
  16. data/lib/aws-sdk-code-generator/hash_formatter.rb +5 -2
  17. data/lib/aws-sdk-code-generator/helper.rb +77 -61
  18. data/lib/aws-sdk-code-generator/plugin_list.rb +146 -0
  19. data/lib/aws-sdk-code-generator/resource_action.rb +69 -0
  20. data/lib/aws-sdk-code-generator/resource_action_code.rb +57 -0
  21. data/lib/aws-sdk-code-generator/resource_association.rb +37 -0
  22. data/lib/aws-sdk-code-generator/resource_attribute.rb +76 -0
  23. data/lib/aws-sdk-code-generator/resource_batch_action.rb +56 -0
  24. data/lib/aws-sdk-code-generator/resource_batch_action_code.rb +136 -0
  25. data/lib/aws-sdk-code-generator/resource_batch_action_documentation.rb +108 -0
  26. data/lib/aws-sdk-code-generator/resource_batch_builder.rb +212 -0
  27. data/lib/aws-sdk-code-generator/resource_builder.rb +48 -0
  28. data/lib/aws-sdk-code-generator/resource_client_request.rb +62 -0
  29. data/lib/aws-sdk-code-generator/resource_client_request_documentation.rb +81 -0
  30. data/lib/aws-sdk-code-generator/resource_client_request_params.rb +86 -0
  31. data/lib/aws-sdk-code-generator/resource_data_method.rb +60 -0
  32. data/lib/aws-sdk-code-generator/resource_has_association.rb +117 -0
  33. data/lib/aws-sdk-code-generator/resource_has_many_association.rb +52 -0
  34. data/lib/aws-sdk-code-generator/resource_has_many_association_code.rb +76 -0
  35. data/lib/aws-sdk-code-generator/resource_identifier.rb +44 -0
  36. data/lib/aws-sdk-code-generator/resource_identifiers_method.rb +29 -0
  37. data/lib/aws-sdk-code-generator/resource_load_method.rb +68 -0
  38. data/lib/aws-sdk-code-generator/resource_method.rb +22 -0
  39. data/lib/aws-sdk-code-generator/resource_skip_params.rb +36 -0
  40. data/lib/aws-sdk-code-generator/resource_value_source.rb +68 -0
  41. data/lib/aws-sdk-code-generator/resource_waiter.rb +80 -0
  42. data/lib/aws-sdk-code-generator/service.rb +30 -7
  43. data/lib/aws-sdk-code-generator/shared_example.rb +131 -0
  44. data/lib/aws-sdk-code-generator/syntax_example.rb +60 -0
  45. data/lib/aws-sdk-code-generator/syntax_example_hash.rb +174 -0
  46. data/lib/aws-sdk-code-generator/underscore.rb +10 -5
  47. data/lib/aws-sdk-code-generator/view.rb +33 -0
  48. data/lib/aws-sdk-code-generator/views.rb +2 -0
  49. data/lib/aws-sdk-code-generator/views/apig_endpoint_class.rb +25 -0
  50. data/lib/aws-sdk-code-generator/views/apig_readme.rb +32 -0
  51. data/lib/aws-sdk-code-generator/views/async_client_class.rb +68 -0
  52. data/lib/aws-sdk-code-generator/views/authorizer_class.rb +17 -0
  53. data/lib/aws-sdk-code-generator/views/client_api_module.rb +583 -0
  54. data/lib/aws-sdk-code-generator/views/client_class.rb +93 -0
  55. data/lib/aws-sdk-code-generator/views/docstring.rb +27 -0
  56. data/lib/aws-sdk-code-generator/views/errors_module.rb +32 -0
  57. data/lib/aws-sdk-code-generator/views/event_streams_module.rb +149 -0
  58. data/lib/aws-sdk-code-generator/views/features/env.rb +9 -0
  59. data/lib/aws-sdk-code-generator/views/features/smoke.rb +51 -0
  60. data/lib/aws-sdk-code-generator/views/features/smoke_step_definitions.rb +26 -0
  61. data/lib/aws-sdk-code-generator/views/features/step_definitions.rb +2 -0
  62. data/lib/aws-sdk-code-generator/views/gemspec.rb +39 -5
  63. data/lib/aws-sdk-code-generator/views/resource_class.rb +122 -0
  64. data/lib/aws-sdk-code-generator/views/root_resource_class.rb +58 -0
  65. data/lib/aws-sdk-code-generator/views/service_module.rb +30 -14
  66. data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -0
  67. data/lib/aws-sdk-code-generator/views/types_module.rb +294 -0
  68. data/lib/aws-sdk-code-generator/views/version.rb +2 -0
  69. data/lib/aws-sdk-code-generator/views/waiters_module.rb +37 -0
  70. data/lib/aws-sdk-code-generator/waiter.rb +95 -0
  71. data/lib/aws-sdk-code-generator/yard_option_tag.rb +43 -0
  72. metadata +61 -68
  73. data/lib/aws-sdk-code-generator/dsl/access_control_statement.rb +0 -23
  74. data/lib/aws-sdk-code-generator/dsl/attribute_accessor.rb +0 -43
  75. data/lib/aws-sdk-code-generator/dsl/attribute_reader.rb +0 -11
  76. data/lib/aws-sdk-code-generator/dsl/attribute_writer.rb +0 -11
  77. data/lib/aws-sdk-code-generator/dsl/autoload_statement.rb +0 -15
  78. data/lib/aws-sdk-code-generator/dsl/block_param.rb +0 -11
  79. data/lib/aws-sdk-code-generator/dsl/class.rb +0 -27
  80. data/lib/aws-sdk-code-generator/dsl/code_literal.rb +0 -66
  81. data/lib/aws-sdk-code-generator/dsl/code_object.rb +0 -33
  82. data/lib/aws-sdk-code-generator/dsl/docstring.rb +0 -36
  83. data/lib/aws-sdk-code-generator/dsl/eigenclass.rb +0 -15
  84. data/lib/aws-sdk-code-generator/dsl/extend_statement.rb +0 -12
  85. data/lib/aws-sdk-code-generator/dsl/formatter.rb +0 -25
  86. data/lib/aws-sdk-code-generator/dsl/include_statement.rb +0 -17
  87. data/lib/aws-sdk-code-generator/dsl/main.rb +0 -105
  88. data/lib/aws-sdk-code-generator/dsl/method.rb +0 -108
  89. data/lib/aws-sdk-code-generator/dsl/module.rb +0 -167
  90. data/lib/aws-sdk-code-generator/dsl/option_tag.rb +0 -36
  91. data/lib/aws-sdk-code-generator/dsl/param.rb +0 -43
  92. data/lib/aws-sdk-code-generator/dsl/param_list.rb +0 -38
  93. data/lib/aws-sdk-code-generator/dsl/return_tag.rb +0 -19
  94. data/lib/aws-sdk-code-generator/dsl/tag_default.rb +0 -20
  95. data/lib/aws-sdk-code-generator/dsl/tag_docstring.rb +0 -27
  96. data/lib/aws-sdk-code-generator/dsl/tag_type.rb +0 -18
  97. data/lib/aws-sdk-code-generator/generators/client_api_module.rb +0 -334
  98. data/lib/aws-sdk-code-generator/generators/client_class.rb +0 -389
  99. data/lib/aws-sdk-code-generator/generators/client_operation_documentation.rb +0 -166
  100. data/lib/aws-sdk-code-generator/generators/errors_module.rb +0 -25
  101. data/lib/aws-sdk-code-generator/generators/resource/action.rb +0 -88
  102. data/lib/aws-sdk-code-generator/generators/resource/batch_builder.rb +0 -211
  103. data/lib/aws-sdk-code-generator/generators/resource/builder.rb +0 -50
  104. data/lib/aws-sdk-code-generator/generators/resource/client_getter.rb +0 -15
  105. data/lib/aws-sdk-code-generator/generators/resource/client_request.rb +0 -49
  106. data/lib/aws-sdk-code-generator/generators/resource/client_request_docs.rb +0 -97
  107. data/lib/aws-sdk-code-generator/generators/resource/client_request_params.rb +0 -88
  108. data/lib/aws-sdk-code-generator/generators/resource/collection_class.rb +0 -180
  109. data/lib/aws-sdk-code-generator/generators/resource/data_attribute_getter.rb +0 -24
  110. data/lib/aws-sdk-code-generator/generators/resource/data_loaded_method.rb +0 -18
  111. data/lib/aws-sdk-code-generator/generators/resource/data_method.rb +0 -49
  112. data/lib/aws-sdk-code-generator/generators/resource/exists_method.rb +0 -29
  113. data/lib/aws-sdk-code-generator/generators/resource/extract_identifier_method.rb +0 -32
  114. data/lib/aws-sdk-code-generator/generators/resource/has_association.rb +0 -101
  115. data/lib/aws-sdk-code-generator/generators/resource/has_many_association.rb +0 -108
  116. data/lib/aws-sdk-code-generator/generators/resource/identifier_getter.rb +0 -26
  117. data/lib/aws-sdk-code-generator/generators/resource/identifiers_method.rb +0 -28
  118. data/lib/aws-sdk-code-generator/generators/resource/initialize_method.rb +0 -67
  119. data/lib/aws-sdk-code-generator/generators/resource/load_method.rb +0 -65
  120. data/lib/aws-sdk-code-generator/generators/resource/value_source.rb +0 -68
  121. data/lib/aws-sdk-code-generator/generators/resource/waiter_method.rb +0 -61
  122. data/lib/aws-sdk-code-generator/generators/resource_class.rb +0 -325
  123. data/lib/aws-sdk-code-generator/generators/response_structure_example.rb +0 -83
  124. data/lib/aws-sdk-code-generator/generators/root_resource_class.rb +0 -42
  125. data/lib/aws-sdk-code-generator/generators/service_documentation.rb +0 -64
  126. data/lib/aws-sdk-code-generator/generators/shared_example.rb +0 -132
  127. data/lib/aws-sdk-code-generator/generators/structure_type_class.rb +0 -95
  128. data/lib/aws-sdk-code-generator/generators/syntax_example.rb +0 -169
  129. data/lib/aws-sdk-code-generator/generators/types_module.rb +0 -52
  130. data/lib/aws-sdk-code-generator/generators/waiter_class.rb +0 -62
  131. data/lib/aws-sdk-code-generator/generators/waiters_module.rb +0 -20
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ClientOperationList
5
+
6
+ include Enumerable
7
+
8
+ def initialize(options)
9
+ api = options.fetch(:api)
10
+ examples = options.fetch(:examples, {})
11
+ module_name = options.fetch(:module_name)
12
+ protocol_settings = options.fetch(:protocol_settings, {})
13
+ client_examples = options.fetch(:client_examples, {})
14
+ paginators = options.fetch(:paginators, {})
15
+ operation_waiters = Waiter.build_operations_map(options[:waiters])
16
+
17
+ @operations = api['operations'].inject([]) do |ops, (name, operation)|
18
+ method_name = Underscore.underscore(name)
19
+ waiters = operation_waiters[method_name]
20
+
21
+ async_client = options[:async_client] || false
22
+ es_output = AwsSdkCodeGenerator::Helper.eventstream_output?(operation, api)
23
+ es_input = AwsSdkCodeGenerator::Helper.eventstream_input?(operation, api)
24
+ if es_input || es_output
25
+ # eventstreaming operations
26
+ if protocol_settings['h2'] == 'eventstream'
27
+ # h2 supported, only generate for async client
28
+ if async_client
29
+ if es_input == es_output
30
+ # input & output eventstream sharing
31
+ # same eventstream shape
32
+ # see EventStreamModule
33
+ es_input = "Input" + es_input
34
+ es_output = "Output" + es_output
35
+ end
36
+ ops << Operation.new(
37
+ name: method_name,
38
+ documentation: ClientOperationDocumentation.new(
39
+ name: name,
40
+ module_name: module_name,
41
+ method_name: method_name,
42
+ operation: operation,
43
+ api: api,
44
+ examples: examples,
45
+ client_examples: client_examples[method_name] || [],
46
+ async_client: true
47
+ ).to_s,
48
+ streaming: AwsSdkCodeGenerator::Helper.operation_streaming?(operation, api),
49
+ eventstream_output: es_output,
50
+ eventstream_input: es_input
51
+ )
52
+ end
53
+ elsif !es_input && es_output && !async_client
54
+ # http1.1 only support eventstream at output
55
+ ops << Operation.new(
56
+ name: method_name,
57
+ documentation: ClientOperationDocumentation.new(
58
+ name: name,
59
+ module_name: module_name,
60
+ method_name: method_name,
61
+ operation: operation,
62
+ api: api,
63
+ examples: examples,
64
+ client_examples: client_examples[method_name] || [],
65
+ async_client: false
66
+ ).to_s,
67
+ streaming: AwsSdkCodeGenerator::Helper.operation_streaming?(operation, api),
68
+ eventstream_output: es_output,
69
+ eventstream_input: false
70
+ )
71
+ end
72
+ elsif !async_client
73
+ # non streaming operations
74
+ # generate at sync client only
75
+ ops << Operation.new(
76
+ name: method_name,
77
+ documentation: ClientOperationDocumentation.new(
78
+ name: name,
79
+ module_name: module_name,
80
+ method_name: method_name,
81
+ operation: operation,
82
+ api: api,
83
+ examples: examples,
84
+ client_examples: client_examples[method_name] || [],
85
+ async_client: false,
86
+ pager: paginators && paginators['pagination'][name],
87
+ waiters: waiters
88
+ ).to_s,
89
+ streaming: AwsSdkCodeGenerator::Helper.operation_streaming?(operation, api),
90
+ eventstream_output: false,
91
+ eventstream_input: false
92
+ )
93
+ end
94
+
95
+ ops
96
+ end
97
+ end
98
+
99
+ # @return [Enumerable<Operation>]
100
+ def each(&block)
101
+ @operations.each(&block)
102
+ end
103
+
104
+ class Operation
105
+
106
+ def initialize(options)
107
+ @name = options.fetch(:name)
108
+ @documentation = options.fetch(:documentation)
109
+ @streaming = options.fetch(:streaming)
110
+ @eventstream_output = !!options.fetch(:eventstream_output)
111
+ @eventstream_input = !!options.fetch(:eventstream_input)
112
+ @output_eventstream_member = @eventstream_output ?
113
+ options.fetch(:eventstream_output) : nil
114
+ @input_eventstream_member = @eventstream_input ?
115
+ options.fetch(:eventstream_input) : nil
116
+ @bidirectional = @eventstream_output && @eventstream_input
117
+ end
118
+
119
+ # @return [String]
120
+ attr_reader :name
121
+
122
+ # @return [String, nil]
123
+ attr_reader :documentation
124
+
125
+ # @return [Boolean]
126
+ attr_reader :eventstream_input
127
+
128
+ # @return [Boolean]
129
+ attr_reader :eventstream_output
130
+
131
+ # @return [String]
132
+ attr_reader :input_eventstream_member
133
+
134
+ # @return [String]
135
+ attr_reader :output_eventstream_member
136
+
137
+ # @return [Boolean]
138
+ attr_reader :bidirectional
139
+
140
+ def block_option
141
+ if @streaming
142
+ ", &block"
143
+ end
144
+ end
145
+
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module AwsSdkCodeGenerator
6
+ class ClientResponseStructureExample
7
+
8
+ # @option options [required, Hash] :shape_ref
9
+ # @option options [required, Hash] :api
10
+ def initialize(options = {})
11
+ @shape_ref = options.fetch(:shape_ref)
12
+ @api = options.fetch(:api)
13
+ end
14
+
15
+ def to_str
16
+ "@example Response structure\n\n #{entry(@shape_ref, 'resp', Set.new).join("\n ")}"
17
+ end
18
+ alias to_s to_str
19
+
20
+ private
21
+
22
+ def structure(ref, context, visited)
23
+ lines = []
24
+ shape = shape(ref)
25
+ if shape['eventstream']
26
+ event_types = []
27
+ # Add event entry
28
+ event_ctx = shape['members'].each.inject([]) do |ctx, (member_name, member_ref)|
29
+ event_type = Underscore.underscore(member_name).to_sym
30
+ event_types << event_type
31
+ ctx << "For #{event_type.inspect} event available at #on_#{event_type}_event callback"\
32
+ ' and response eventstream enumerator:'
33
+ event_entry = entry(member_ref, 'event', Set.new).join("\n ")
34
+ ctx << (event_entry.empty? ? ' #=> EmptyStruct' : event_entry + "\n")
35
+ end
36
+ # Add eventstream entry
37
+ event_ctx.unshift("#{context}.event_types #=> #{event_types.inspect}\n")
38
+ event_ctx.unshift("#{context} #=> Enumerator")
39
+ event_ctx.unshift("All events are available at #{context}:")
40
+ return event_ctx
41
+ elsif shape['members']
42
+ shape['members'].each_pair do |member_name, member_ref|
43
+ lines += entry(member_ref, "#{context}.#{underscore(member_name)}", visited)
44
+ end
45
+ end
46
+ lines
47
+ end
48
+
49
+ def list(ref, context, visited)
50
+ lines = []
51
+ lines << "#{context} #=> Array"
52
+ lines += entry(shape(ref)['member'], "#{context}[0]", visited)
53
+ lines
54
+ end
55
+
56
+ def map(ref, context, visited)
57
+ lines = []
58
+ lines << "#{context} #=> Hash"
59
+ lines += entry(shape(ref)['value'], "#{context}[#{map_key(ref)}]", visited)
60
+ lines
61
+ end
62
+
63
+ def map_key(ref)
64
+ shape(ref)['key']['shape'].inspect
65
+ end
66
+
67
+ def entry(ref, context, visited)
68
+ if ref['shape'] == 'AttributeValue'
69
+ return ["#{context} #=> <Hash,Array,String,Numeric,Boolean,IO,Set,nil>"]
70
+ elsif visited.include?(ref['shape'])
71
+ return ["#{context} #=> Types::#{ref['shape']}"]
72
+ else
73
+ visited = visited + [ref['shape']]
74
+ end
75
+ case shape(ref)['type']
76
+ when 'structure' then structure(ref, context, visited)
77
+ when 'list' then list(ref, context, visited)
78
+ when 'map' then map(ref, context, visited)
79
+ else ["#{context} #=> #{type(ref)}"]
80
+ end
81
+ end
82
+
83
+ def type(ref)
84
+ if shape(ref)['type'] == 'string'
85
+ string(ref)
86
+ else
87
+ Api.ruby_type(ref, @api)
88
+ end
89
+ end
90
+
91
+ def string(ref)
92
+ if shape(ref)['enum']
93
+ "String, one of #{shape(ref)['enum'].map(&:inspect).join(', ')}"
94
+ else
95
+ 'String'
96
+ end
97
+ end
98
+
99
+ def shape(ref)
100
+ Api.shape(ref, @api)
101
+ end
102
+
103
+ def underscore(str)
104
+ Underscore.underscore(str)
105
+ end
106
+
107
+ end
108
+ end
@@ -1,23 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AwsSdkCodeGenerator
2
4
  class CodeBuilder
3
5
 
4
- # @api private
5
- GENERATED_SRC_WARNING = <<-WARNING
6
- # WARNING ABOUT GENERATED CODE
7
- #
8
- # This file is generated. See the contributing for info on making contributions:
9
- # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
10
- #
11
- # WARNING ABOUT GENERATED CODE
12
-
13
- WARNING
14
-
15
- include Helper
16
-
17
6
  # @option options [required, Service] :service
7
+ #
8
+ # @option options [required, String] :aws_sdk_core_lib_path
9
+ # Path to the lib directory for the source code of the
10
+ # AWS SDK for Ruby. This is needed so that documentation
11
+ # can be generated for default plugins and their options.
12
+ #
13
+ # @option options [Hash<String, Array<Hash>] :client_examples ({})
14
+ # A hash of client examples. Hash keys should be API operation method
15
+ # names (snake_cased). Hash values should be arrays of hashes.
16
+ # Each hash should contain the following keys:
17
+ #
18
+ # * `:name` - The name of the example
19
+ # * `:code` - The Ruby example code
20
+ #
18
21
  def initialize(options)
19
22
  @service = options.fetch(:service)
20
- # TODO : remove these
23
+ @aws_sdk_core_lib_path = options.fetch(:aws_sdk_core_lib_path)
24
+ @client_examples = options.fetch(:client_examples, {})
21
25
  @add_plugins = @service.add_plugins
22
26
  @remove_plugins = @service.remove_plugins
23
27
  @gem_dependencies = @service.gem_dependencies
@@ -29,38 +33,52 @@ module AwsSdkCodeGenerator
29
33
  @examples = @service.examples
30
34
  end
31
35
 
36
+ # Generates the source for a library as a single string.
37
+ # @return [String<code>]
38
+ # @api private
32
39
  def source
33
- svc_mod = new_svc_module
34
- @gem_dependencies.each { |gem_name, _| svc_mod.require(gem_name) }
35
- svc_mod.docstring(service_docstring)
36
- each_module do |mod, _|
37
- svc_mod.add(mod)
40
+ code = @gem_dependencies.map { |gem_name, _| "require '#{gem_name}'" }
41
+ source_files.each.with_index do |(file_name, src_code), n|
42
+ # skip the service module and customizations
43
+ next if file_name.include? '/customizations.rb'
44
+ next unless file_name.include? '/'
45
+ # skip markdown files
46
+ next if file_name.include? 'README.md'
47
+ code << src_code
38
48
  end
39
- @callback.call(svc_mod) if @callback
40
- svc_mod.root.to_s
49
+ code.join("\n")
41
50
  end
42
51
 
43
- # @option options [String] :prefix
44
52
  # @return [Enumerable<String<path>, String<code>>]
45
53
  def source_files(options = {})
46
- prefix = options.fetch(:prefix, nil)
47
- prefix ||= @module_names.map { |n| underscore(n) }.join('/')
48
- # prefix should always be the gemname. The service-module (the first
49
- # item yielded below) should be moved from here into the gem builder
50
- # The source code builder should simply yield the empty module
54
+ prefix = options.fetch(:prefix, @service.gem_name)
51
55
  Enumerator.new do |y|
52
- y.yield("#{prefix}.rb", Views::ServiceModule.new(service: @service, prefix: prefix).render)
53
- y.yield("#{prefix}/customizations.rb", '')
54
- each_module do |mod, type, code|
55
- case type
56
- when :unwrapped
57
- filename = File.join(prefix, underscore(mod.name) + '.rb')
58
- y.yield(filename, GENERATED_SRC_WARNING + wrap(mod))
59
- when :wrapped # dsl module
60
- filename = File.join(prefix, underscore(mod.name) + '.rb')
61
- y.yield(filename, GENERATED_SRC_WARNING + mod.root.to_s)
62
- else
63
- raise "expected :wrapped or :unwrapped"
56
+ if @service.protocol == 'api-gateway'
57
+ y.yield("#{prefix}/../../README.md", apig_readme)
58
+ y.yield("#{prefix}/plugins/authorizer.rb", authorizer_class)
59
+ y.yield("#{prefix}/plugins/apig_endpoint.rb", apig_endpoint_class)
60
+ end
61
+ y.yield("#{prefix}.rb", service_module(prefix))
62
+ unless prefix == 'aws-sdk-sts'
63
+ y.yield("#{prefix}/customizations.rb", '')
64
+ end
65
+ y.yield("#{prefix}/types.rb", types_module)
66
+ if has_eventstream
67
+ y.yield("#{prefix}/event_streams.rb", event_streams_module)
68
+ end
69
+ y.yield("#{prefix}/client_api.rb", client_api_module)
70
+ y.yield("#{prefix}/client.rb", client_class)
71
+ if @service.protocol_settings['h2'] == 'eventstream'
72
+ y.yield("#{prefix}/async_client.rb", async_client_class)
73
+ end
74
+ y.yield("#{prefix}/errors.rb", errors_module)
75
+ y.yield("#{prefix}/waiters.rb", waiters_module) if @waiters
76
+ y.yield("#{prefix}/resource.rb", root_resource_class)
77
+ if @resources
78
+ @resources['resources'].keys.sort.each do |name|
79
+ path = "#{prefix}/#{Underscore.underscore(name)}.rb"
80
+ code = resource_class(name, @resources['resources'][name])
81
+ y.yield(path, code)
64
82
  end
65
83
  end
66
84
  end
@@ -68,134 +86,129 @@ module AwsSdkCodeGenerator
68
86
 
69
87
  private
70
88
 
71
- def each_module(&block)
72
- yield(types_module, :unwrapped)
73
- yield(client_api_module, :unwrapped)
74
- yield(client_class, :wrapped)
75
- yield(errors_module, :unwrapped)
76
- yield(waiters_module, :wrapped) if @waiters
77
- yield(root_resource_class, :unwrapped)
78
- if @resources
79
- @resources['resources'].keys.sort.each do |name|
80
- yield(resource_class(name, @resources['resources'][name]), :unwrapped)
81
- end
82
- end
89
+ def service_module(prefix)
90
+ Views::ServiceModule.new(service: @service, prefix: prefix).render
83
91
  end
84
92
 
85
- def new_svc_module
86
- @module_names.inject(Dsl::Main.new) do |mod, module_name|
87
- mod.module(module_name)
88
- end
93
+ def types_module
94
+ Views::TypesModule.new(service: @service).render
89
95
  end
90
96
 
91
- def wrap(mod)
92
- svc_mod = new_svc_module
93
- svc_mod.add(mod)
94
- svc_mod.root.to_s
97
+ def event_streams_module
98
+ Views::EventStreamsModule.new(service: @service).render
95
99
  end
96
100
 
97
- def service_module(autoload_prefix)
98
- autoloads = Generators::ServiceAutoloads.new(
99
- prefix: autoload_prefix,
100
- resources: @resources,
101
- waiters: !!@waiters
102
- )
103
- svc_mod = new_svc_module
104
- @gem_dependencies.each { |gem_name, _| svc_mod.require(gem_name) }
105
- svc_mod.docstring(service_docstring)
106
- svc_mod.code("GEM_VERSION = '#{@service.gem_version}'")
107
- autoloads.apply(svc_mod)
108
- @callback.call(svc_mod) if @callback
109
- svc_mod.root.to_s
101
+ def client_api_module
102
+ Views::ClientApiModule.new(service: @service).render
110
103
  end
111
104
 
112
- def types_module
113
- Generators::TypesModule.new(api: @api)
105
+ def client_class
106
+ Views::ClientClass.new(
107
+ service_identifier: @service.identifier,
108
+ service_name: @service.name,
109
+ protocol_settings: @service.protocol_settings,
110
+ module_name: @service.module_name,
111
+ gem_name: @service.gem_name,
112
+ gem_version: @service.gem_version,
113
+ aws_sdk_core_lib_path: @aws_sdk_core_lib_path,
114
+ client_examples: @client_examples,
115
+ protocol: @service.protocol,
116
+ signature_version: @service.signature_version,
117
+ require_endpoint_discovery: @service.require_endpoint_discovery,
118
+ add_plugins: @service.add_plugins,
119
+ remove_plugins: @service.remove_plugins,
120
+ api: @service.api,
121
+ paginators: @service.paginators,
122
+ waiters: @service.waiters,
123
+ examples: @service.examples,
124
+ custom: @service.protocol == 'api-gateway'
125
+ ).render
126
+ end
127
+
128
+ def async_client_class
129
+ Views::AsyncClientClass.new(
130
+ service_identifier: @service.identifier,
131
+ service_name: @service.name,
132
+ protocol_settings: @service.protocol_settings,
133
+ module_name: @service.module_name,
134
+ gem_name: @service.gem_name,
135
+ gem_version: @service.gem_version,
136
+ aws_sdk_core_lib_path: @aws_sdk_core_lib_path,
137
+ protocol: @service.protocol,
138
+ signature_version: @service.signature_version,
139
+ add_plugins: @service.add_plugins,
140
+ remove_plugins: @service.remove_plugins,
141
+ api: @service.api,
142
+ async_client: true
143
+ ).render
114
144
  end
115
145
 
116
- def client_api_module
117
- Generators::ClientApiModule.new(api: @api, paginators:@paginators)
146
+ def errors_module
147
+ Views::ErrorsModule.new(service: @service).render
118
148
  end
119
149
 
120
- def client_class(svc_mod = new_svc_module)
121
- klass = Generators::ClientClass.new(
122
- parent: svc_mod,
123
- identifier: @module_names.last.downcase,
124
- api: @api,
150
+ def waiters_module
151
+ Views::WaitersModule.new(
152
+ module_name: @service.module_name,
125
153
  waiters: @waiters,
126
- examples: @examples,
127
- add_plugins: @add_plugins,
128
- remove_plugins: @remove_plugins,
129
- gem_name: @service.gem_name,
130
- gem_version: @service.gem_version,
131
- )
132
- svc_mod.add(klass)
133
- klass
154
+ custom: @service.protocol == 'api-gateway'
155
+ ).render
134
156
  end
135
157
 
136
- def errors_module
137
- Generators::ErrorsModule.new(api: @api)
158
+ def authorizer_class
159
+ Views::AuthorizerClass.new(
160
+ module_name: @service.module_name
161
+ ).render
138
162
  end
139
163
 
140
- def waiters_module(svc_mod = new_svc_module)
141
- klass = Generators::WaitersModule.new(
142
- parent: svc_mod,
143
- waiters: @waiters
144
- )
145
- svc_mod.add(klass)
146
- klass
164
+ def apig_endpoint_class
165
+ Views::APIGEndpointClass.new(
166
+ module_name: @service.module_name,
167
+ default_endpoint: @service.default_endpoint
168
+ ).render
147
169
  end
148
170
 
149
171
  def root_resource_class
150
- Generators::RootResourceClass.new({
151
- api: @api,
152
- resources: @resources,
172
+ Views::RootResourceClass.new(
173
+ module_name: @service.module_name,
174
+ service_name: @service.name,
175
+ resources: @service.resources,
153
176
  paginators: @paginators,
154
- var_name: underscore(@module_names.last),
155
- })
177
+ api: @api,
178
+ custom: @service.protocol == 'api-gateway'
179
+ ).render
156
180
  end
157
181
 
158
182
  def resource_class(resource_name, resource_definition)
159
- Generators::ResourceClass.new(
183
+ Views::ResourceClass.new(
184
+ module_name: @service.module_name,
185
+ class_name: resource_name,
160
186
  api: @api,
161
- name: resource_name,
162
- resource: resource_definition,
163
187
  paginators: @paginators,
164
188
  waiters: @waiters,
165
- )
189
+ resource: resource_definition,
190
+ custom: @service.protocol == 'api-gateway'
191
+ ).render
166
192
  end
167
193
 
168
- def service_docstring
169
- metadata = @api['metadata'] || {}
170
- Generators::ServiceDocumentation.new(
171
- product_name: metadata['serviceFullName'] || @module_names.last,
172
- namespace: @module_names.join('::'),
173
- api: @api
174
- ).docstring
194
+ def apig_readme
195
+ Views::APIGReadme.new(
196
+ service_name: @service.name,
197
+ gem_major_version: @service.gem_version.split('.').first,
198
+ gem_name: @service.gem_name,
199
+ module_name: @service.module_name
200
+ ).render
175
201
  end
176
202
 
177
- # @api private
178
- # This method can be removed if move to used the combined API and
179
- # docs JSON document.
180
- def apply_docs(api, docs)
181
- api['documentation'] = docs['service']
182
- docs['operations'].each do |name, docstring|
183
- api['operations'][name]['documentation'] = docstring
184
- end
185
- docs['shapes'].each do |shape_name, shape_docs|
186
- api['shapes'][shape_name]['documentation'] = shape_docs['base']
187
- shape_docs['refs'].each do |ref, ref_docs|
188
- ref_shape, ref_member = ref.split('$')
189
- case api['shapes'][ref_shape]['type']
190
- when 'structure'
191
- api['shapes'][ref_shape]['members'][ref_member]['documentation'] = ref_docs
192
- when 'list', 'map'
193
- api['shapes'][ref_shape][ref_member]['documentation'] = ref_docs
194
- end
203
+ private
195
204
 
196
- end
205
+ def has_eventstream
206
+ @service.api['shapes'].each do |_, ref|
207
+ return true if ref['eventstream']
197
208
  end
209
+ false
198
210
  end
199
211
 
200
212
  end
213
+
201
214
  end