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.
- checksums.yaml +5 -5
- data/lib/aws-sdk-code-generator.rb +68 -75
- data/lib/aws-sdk-code-generator/api.rb +130 -0
- data/lib/aws-sdk-code-generator/apply_docs.rb +15 -2
- data/lib/aws-sdk-code-generator/client_constructor.rb +39 -0
- data/lib/aws-sdk-code-generator/client_operation_documentation.rb +268 -0
- data/lib/aws-sdk-code-generator/client_operation_list.rb +148 -0
- data/lib/aws-sdk-code-generator/client_response_structure_example.rb +108 -0
- data/lib/aws-sdk-code-generator/code_builder.rb +146 -133
- data/lib/aws-sdk-code-generator/crosslink.rb +42 -0
- data/lib/aws-sdk-code-generator/docstring.rb +199 -0
- data/lib/aws-sdk-code-generator/error_list.rb +77 -0
- data/lib/aws-sdk-code-generator/errors.rb +2 -0
- data/lib/aws-sdk-code-generator/eventstream_example.rb +220 -0
- data/lib/aws-sdk-code-generator/gem_builder.rb +19 -25
- data/lib/aws-sdk-code-generator/hash_formatter.rb +5 -2
- data/lib/aws-sdk-code-generator/helper.rb +77 -61
- data/lib/aws-sdk-code-generator/plugin_list.rb +146 -0
- data/lib/aws-sdk-code-generator/resource_action.rb +69 -0
- data/lib/aws-sdk-code-generator/resource_action_code.rb +57 -0
- data/lib/aws-sdk-code-generator/resource_association.rb +37 -0
- data/lib/aws-sdk-code-generator/resource_attribute.rb +76 -0
- data/lib/aws-sdk-code-generator/resource_batch_action.rb +56 -0
- data/lib/aws-sdk-code-generator/resource_batch_action_code.rb +136 -0
- data/lib/aws-sdk-code-generator/resource_batch_action_documentation.rb +108 -0
- data/lib/aws-sdk-code-generator/resource_batch_builder.rb +212 -0
- data/lib/aws-sdk-code-generator/resource_builder.rb +48 -0
- data/lib/aws-sdk-code-generator/resource_client_request.rb +62 -0
- data/lib/aws-sdk-code-generator/resource_client_request_documentation.rb +81 -0
- data/lib/aws-sdk-code-generator/resource_client_request_params.rb +86 -0
- data/lib/aws-sdk-code-generator/resource_data_method.rb +60 -0
- data/lib/aws-sdk-code-generator/resource_has_association.rb +117 -0
- data/lib/aws-sdk-code-generator/resource_has_many_association.rb +52 -0
- data/lib/aws-sdk-code-generator/resource_has_many_association_code.rb +76 -0
- data/lib/aws-sdk-code-generator/resource_identifier.rb +44 -0
- data/lib/aws-sdk-code-generator/resource_identifiers_method.rb +29 -0
- data/lib/aws-sdk-code-generator/resource_load_method.rb +68 -0
- data/lib/aws-sdk-code-generator/resource_method.rb +22 -0
- data/lib/aws-sdk-code-generator/resource_skip_params.rb +36 -0
- data/lib/aws-sdk-code-generator/resource_value_source.rb +68 -0
- data/lib/aws-sdk-code-generator/resource_waiter.rb +80 -0
- data/lib/aws-sdk-code-generator/service.rb +30 -7
- data/lib/aws-sdk-code-generator/shared_example.rb +131 -0
- data/lib/aws-sdk-code-generator/syntax_example.rb +60 -0
- data/lib/aws-sdk-code-generator/syntax_example_hash.rb +174 -0
- data/lib/aws-sdk-code-generator/underscore.rb +10 -5
- data/lib/aws-sdk-code-generator/view.rb +33 -0
- data/lib/aws-sdk-code-generator/views.rb +2 -0
- data/lib/aws-sdk-code-generator/views/apig_endpoint_class.rb +25 -0
- data/lib/aws-sdk-code-generator/views/apig_readme.rb +32 -0
- data/lib/aws-sdk-code-generator/views/async_client_class.rb +68 -0
- data/lib/aws-sdk-code-generator/views/authorizer_class.rb +17 -0
- data/lib/aws-sdk-code-generator/views/client_api_module.rb +583 -0
- data/lib/aws-sdk-code-generator/views/client_class.rb +93 -0
- data/lib/aws-sdk-code-generator/views/docstring.rb +27 -0
- data/lib/aws-sdk-code-generator/views/errors_module.rb +32 -0
- data/lib/aws-sdk-code-generator/views/event_streams_module.rb +149 -0
- data/lib/aws-sdk-code-generator/views/features/env.rb +9 -0
- data/lib/aws-sdk-code-generator/views/features/smoke.rb +51 -0
- data/lib/aws-sdk-code-generator/views/features/smoke_step_definitions.rb +26 -0
- data/lib/aws-sdk-code-generator/views/features/step_definitions.rb +2 -0
- data/lib/aws-sdk-code-generator/views/gemspec.rb +39 -5
- data/lib/aws-sdk-code-generator/views/resource_class.rb +122 -0
- data/lib/aws-sdk-code-generator/views/root_resource_class.rb +58 -0
- data/lib/aws-sdk-code-generator/views/service_module.rb +30 -14
- data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -0
- data/lib/aws-sdk-code-generator/views/types_module.rb +294 -0
- data/lib/aws-sdk-code-generator/views/version.rb +2 -0
- data/lib/aws-sdk-code-generator/views/waiters_module.rb +37 -0
- data/lib/aws-sdk-code-generator/waiter.rb +95 -0
- data/lib/aws-sdk-code-generator/yard_option_tag.rb +43 -0
- metadata +61 -68
- data/lib/aws-sdk-code-generator/dsl/access_control_statement.rb +0 -23
- data/lib/aws-sdk-code-generator/dsl/attribute_accessor.rb +0 -43
- data/lib/aws-sdk-code-generator/dsl/attribute_reader.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/attribute_writer.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/autoload_statement.rb +0 -15
- data/lib/aws-sdk-code-generator/dsl/block_param.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/class.rb +0 -27
- data/lib/aws-sdk-code-generator/dsl/code_literal.rb +0 -66
- data/lib/aws-sdk-code-generator/dsl/code_object.rb +0 -33
- data/lib/aws-sdk-code-generator/dsl/docstring.rb +0 -36
- data/lib/aws-sdk-code-generator/dsl/eigenclass.rb +0 -15
- data/lib/aws-sdk-code-generator/dsl/extend_statement.rb +0 -12
- data/lib/aws-sdk-code-generator/dsl/formatter.rb +0 -25
- data/lib/aws-sdk-code-generator/dsl/include_statement.rb +0 -17
- data/lib/aws-sdk-code-generator/dsl/main.rb +0 -105
- data/lib/aws-sdk-code-generator/dsl/method.rb +0 -108
- data/lib/aws-sdk-code-generator/dsl/module.rb +0 -167
- data/lib/aws-sdk-code-generator/dsl/option_tag.rb +0 -36
- data/lib/aws-sdk-code-generator/dsl/param.rb +0 -43
- data/lib/aws-sdk-code-generator/dsl/param_list.rb +0 -38
- data/lib/aws-sdk-code-generator/dsl/return_tag.rb +0 -19
- data/lib/aws-sdk-code-generator/dsl/tag_default.rb +0 -20
- data/lib/aws-sdk-code-generator/dsl/tag_docstring.rb +0 -27
- data/lib/aws-sdk-code-generator/dsl/tag_type.rb +0 -18
- data/lib/aws-sdk-code-generator/generators/client_api_module.rb +0 -334
- data/lib/aws-sdk-code-generator/generators/client_class.rb +0 -389
- data/lib/aws-sdk-code-generator/generators/client_operation_documentation.rb +0 -166
- data/lib/aws-sdk-code-generator/generators/errors_module.rb +0 -25
- data/lib/aws-sdk-code-generator/generators/resource/action.rb +0 -88
- data/lib/aws-sdk-code-generator/generators/resource/batch_builder.rb +0 -211
- data/lib/aws-sdk-code-generator/generators/resource/builder.rb +0 -50
- data/lib/aws-sdk-code-generator/generators/resource/client_getter.rb +0 -15
- data/lib/aws-sdk-code-generator/generators/resource/client_request.rb +0 -49
- data/lib/aws-sdk-code-generator/generators/resource/client_request_docs.rb +0 -97
- data/lib/aws-sdk-code-generator/generators/resource/client_request_params.rb +0 -88
- data/lib/aws-sdk-code-generator/generators/resource/collection_class.rb +0 -180
- data/lib/aws-sdk-code-generator/generators/resource/data_attribute_getter.rb +0 -24
- data/lib/aws-sdk-code-generator/generators/resource/data_loaded_method.rb +0 -18
- data/lib/aws-sdk-code-generator/generators/resource/data_method.rb +0 -49
- data/lib/aws-sdk-code-generator/generators/resource/exists_method.rb +0 -29
- data/lib/aws-sdk-code-generator/generators/resource/extract_identifier_method.rb +0 -32
- data/lib/aws-sdk-code-generator/generators/resource/has_association.rb +0 -101
- data/lib/aws-sdk-code-generator/generators/resource/has_many_association.rb +0 -108
- data/lib/aws-sdk-code-generator/generators/resource/identifier_getter.rb +0 -26
- data/lib/aws-sdk-code-generator/generators/resource/identifiers_method.rb +0 -28
- data/lib/aws-sdk-code-generator/generators/resource/initialize_method.rb +0 -67
- data/lib/aws-sdk-code-generator/generators/resource/load_method.rb +0 -65
- data/lib/aws-sdk-code-generator/generators/resource/value_source.rb +0 -68
- data/lib/aws-sdk-code-generator/generators/resource/waiter_method.rb +0 -61
- data/lib/aws-sdk-code-generator/generators/resource_class.rb +0 -325
- data/lib/aws-sdk-code-generator/generators/response_structure_example.rb +0 -83
- data/lib/aws-sdk-code-generator/generators/root_resource_class.rb +0 -42
- data/lib/aws-sdk-code-generator/generators/service_documentation.rb +0 -64
- data/lib/aws-sdk-code-generator/generators/shared_example.rb +0 -132
- data/lib/aws-sdk-code-generator/generators/structure_type_class.rb +0 -95
- data/lib/aws-sdk-code-generator/generators/syntax_example.rb +0 -169
- data/lib/aws-sdk-code-generator/generators/types_module.rb +0 -52
- data/lib/aws-sdk-code-generator/generators/waiter_class.rb +0 -62
- data/lib/aws-sdk-code-generator/generators/waiters_module.rb +0 -20
@@ -1,167 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Dsl
|
3
|
-
class Module < Dsl::Main
|
4
|
-
|
5
|
-
include Dsl::CodeObject
|
6
|
-
|
7
|
-
# @option options [Main, Module] :parent (nil)
|
8
|
-
def initialize(name, options = {}, &block)
|
9
|
-
@name = name
|
10
|
-
@code_objects = []
|
11
|
-
@access = :public
|
12
|
-
@parent = options.fetch(:parent, nil)
|
13
|
-
@docstring = Dsl::Docstring.new(nil)
|
14
|
-
yield(self) if block
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :name
|
18
|
-
|
19
|
-
def add(*code_objects)
|
20
|
-
code_objects.each do |code_object|
|
21
|
-
if Dsl::Method === code_object && code_object.access != @access
|
22
|
-
add(AccessControlStatement.new(code_object.access))
|
23
|
-
elsif Dsl::AccessControlStatement === code_object
|
24
|
-
@access = code_object.access
|
25
|
-
end
|
26
|
-
super(code_object)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def require_statement(path)
|
31
|
-
root.require(path)
|
32
|
-
end
|
33
|
-
alias require require_statement
|
34
|
-
|
35
|
-
def docstring(docstring = nil)
|
36
|
-
@docstring ||= Dsl::Docstring.new
|
37
|
-
@docstring.append(docstring) unless docstring.nil?
|
38
|
-
@docstring
|
39
|
-
end
|
40
|
-
|
41
|
-
def require_relative(path)
|
42
|
-
root.require_relative(path)
|
43
|
-
end
|
44
|
-
|
45
|
-
def constructor(options = {}, &block)
|
46
|
-
method(:initialize, options, &block)
|
47
|
-
end
|
48
|
-
|
49
|
-
def attr_accessor(name, options = {}, &block)
|
50
|
-
a = Dsl::AttributeAccessor.new(name, options)
|
51
|
-
yield(a) if block
|
52
|
-
add(a)
|
53
|
-
end
|
54
|
-
|
55
|
-
def autoload(const_name, path)
|
56
|
-
@code_objects << AutoloadStatement.new(const_name, path)
|
57
|
-
end
|
58
|
-
|
59
|
-
def attr_reader(name, options = {}, &block)
|
60
|
-
a = Dsl::AttributeReader.new(name, options)
|
61
|
-
yield(a) if block
|
62
|
-
add(a)
|
63
|
-
end
|
64
|
-
|
65
|
-
def attr_writer(name, &block)
|
66
|
-
a = Dsl::AttributeWriter.new(name)
|
67
|
-
yield(a) if block
|
68
|
-
add(a)
|
69
|
-
end
|
70
|
-
|
71
|
-
def eigenclass(&block)
|
72
|
-
m = Dsl::Eigenclass.new
|
73
|
-
yield(m) if block
|
74
|
-
add(m)
|
75
|
-
end
|
76
|
-
|
77
|
-
def lines
|
78
|
-
code = []
|
79
|
-
code.concat(@docstring.lines)
|
80
|
-
code += open_module
|
81
|
-
code << :newline if padded?(0)
|
82
|
-
|
83
|
-
@code_objects.each.with_index do |code_object, n|
|
84
|
-
code << code_object.lines
|
85
|
-
code << :newline if separator?(n)
|
86
|
-
end
|
87
|
-
|
88
|
-
if @code_objects.empty?
|
89
|
-
code[-1] += "; end"
|
90
|
-
else
|
91
|
-
code += close_module
|
92
|
-
end
|
93
|
-
code
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def open_module
|
99
|
-
["module #{@name}"]
|
100
|
-
end
|
101
|
-
|
102
|
-
def close_module
|
103
|
-
["end"]
|
104
|
-
end
|
105
|
-
|
106
|
-
def padded?(n)
|
107
|
-
!@code_objects[n].kind_of?(Dsl::Module) &&
|
108
|
-
!(
|
109
|
-
@code_objects.all? { |obj| autoload_statement?(obj) } ||
|
110
|
-
@code_objects.all? { |obj| mixin?(obj) } ||
|
111
|
-
@code_objects.all? { |obj| undocumented_attr_macro?(obj) }
|
112
|
-
)
|
113
|
-
end
|
114
|
-
|
115
|
-
def separator?(n)
|
116
|
-
if last?(n)
|
117
|
-
padded?(@code_objects.size - 1)
|
118
|
-
elsif grouped_statements?(n)
|
119
|
-
false
|
120
|
-
else
|
121
|
-
true
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def last?(n)
|
126
|
-
@code_objects.size == n + 1
|
127
|
-
end
|
128
|
-
|
129
|
-
def grouped_statements?(n)
|
130
|
-
two_autoloads?(n) ||
|
131
|
-
two_mixins?(n) ||
|
132
|
-
two_undocumented_attr_macros?(n)
|
133
|
-
end
|
134
|
-
|
135
|
-
def two_autoloads?(n)
|
136
|
-
@code_objects[n + 1] &&
|
137
|
-
autoload_statement?(@code_objects[n + 1]) &&
|
138
|
-
autoload_statement?(@code_objects[n])
|
139
|
-
end
|
140
|
-
|
141
|
-
def two_mixins?(n)
|
142
|
-
@code_objects[n + 1] &&
|
143
|
-
mixin?(@code_objects[n + 1]) &&
|
144
|
-
mixin?(@code_objects[n])
|
145
|
-
end
|
146
|
-
|
147
|
-
def two_undocumented_attr_macros?(n)
|
148
|
-
@code_objects[n + 1] &&
|
149
|
-
undocumented_attr_macro?(@code_objects[n + 1]) &&
|
150
|
-
undocumented_attr_macro?(@code_objects[n])
|
151
|
-
end
|
152
|
-
|
153
|
-
def autoload_statement?(code_object)
|
154
|
-
Dsl::AutoloadStatement === code_object
|
155
|
-
end
|
156
|
-
|
157
|
-
def mixin?(code_object)
|
158
|
-
Dsl::IncludeStatement === code_object
|
159
|
-
end
|
160
|
-
|
161
|
-
def undocumented_attr_macro?(code_object)
|
162
|
-
Dsl::AttributeAccessor === code_object && !code_object.documented?
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Dsl
|
3
|
-
class OptionTag
|
4
|
-
|
5
|
-
# @option options [required, String] :name
|
6
|
-
# @option options [required, String] :type
|
7
|
-
# @option options [String] :param ('options')
|
8
|
-
# @option options [Boolean] :required (false)
|
9
|
-
# @option options [String, nil] :docstring (nil)
|
10
|
-
# @option options [Object] :default
|
11
|
-
def initialize(options)
|
12
|
-
@name = options.fetch(:name)
|
13
|
-
@type = options.fetch(:type)
|
14
|
-
@param = options.fetch(:param, 'options')
|
15
|
-
@required = options.fetch(:required, false) ? 'required, ' : ''
|
16
|
-
@docstring = Dsl::TagDocstring.new(options.fetch(:docstring, nil))
|
17
|
-
@default = Dsl::TagDefault.new(options.fetch(:default, nil))
|
18
|
-
end
|
19
|
-
|
20
|
-
def lines
|
21
|
-
[first_line] + @docstring.lines
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def first_line
|
27
|
-
"# @option #{@param} [#{@required}#{@type}] :#{@name}#{yard_default}"
|
28
|
-
end
|
29
|
-
|
30
|
-
def yard_default
|
31
|
-
@default.empty? ? '' : " (#{@default})"
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Dsl
|
3
|
-
class Param
|
4
|
-
|
5
|
-
# @option options [String] :type
|
6
|
-
# @option options [Object] :default
|
7
|
-
# @option options [String] :docstring
|
8
|
-
# @option options [Boolean] :documented (true)
|
9
|
-
def initialize(name, options = {})
|
10
|
-
@name = name.to_s
|
11
|
-
@type = TagType.new(options.fetch(:type, nil))
|
12
|
-
@default = TagDefault.new(options.fetch(:default, nil))
|
13
|
-
@docstring = TagDocstring.new(options.fetch(:docstring, nil))
|
14
|
-
@documented = options.fetch(:documented, true)
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :name, :default
|
18
|
-
|
19
|
-
def documented?
|
20
|
-
!!@documented
|
21
|
-
end
|
22
|
-
|
23
|
-
def tag
|
24
|
-
if [@type, @default, @docstring].all?(&:empty?)
|
25
|
-
[]
|
26
|
-
else
|
27
|
-
[first_line] + @docstring.lines
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def first_line
|
34
|
-
"# @param#{@type} #{@name}#{yard_default}"
|
35
|
-
end
|
36
|
-
|
37
|
-
def yard_default
|
38
|
-
@default.empty? ? '' : " (#{@default})"
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Dsl
|
3
|
-
# @api private
|
4
|
-
class ParamList
|
5
|
-
|
6
|
-
def initialize(params)
|
7
|
-
@params = params
|
8
|
-
end
|
9
|
-
|
10
|
-
def signature
|
11
|
-
if @params.empty?
|
12
|
-
nil
|
13
|
-
else
|
14
|
-
"(#{@params.map { |p| param_signature(p) }.join(', ')})"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def tags
|
19
|
-
lines = []
|
20
|
-
@params.each do |param|
|
21
|
-
lines.concat(param.tag) if param.documented?
|
22
|
-
end
|
23
|
-
lines
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def param_signature(param)
|
29
|
-
if param.default.empty?
|
30
|
-
param.name
|
31
|
-
else
|
32
|
-
"#{param.name} = #{param.default}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Dsl
|
3
|
-
# @api private
|
4
|
-
class ReturnTag
|
5
|
-
|
6
|
-
# @option options [required, String] :type
|
7
|
-
# @option options [String] :docstring
|
8
|
-
def initialize(options)
|
9
|
-
@type = Dsl::TagType.new(options.fetch(:type))
|
10
|
-
@docstring = Dsl::TagDocstring.new(options.fetch(:docstring, nil))
|
11
|
-
end
|
12
|
-
|
13
|
-
def lines
|
14
|
-
["# @return#{@type}"] + @docstring.lines
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Dsl
|
3
|
-
# @api private
|
4
|
-
class TagDocstring
|
5
|
-
|
6
|
-
def initialize(docstring)
|
7
|
-
@lines = docstring.to_s.strip.lines.inject([]) do |lines, line|
|
8
|
-
line = line.rstrip
|
9
|
-
if line.empty?
|
10
|
-
lines << "#"
|
11
|
-
else
|
12
|
-
lines << "# #{line.rstrip}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# @return Array<String>
|
18
|
-
attr_reader :lines
|
19
|
-
|
20
|
-
# @return [Boolean]
|
21
|
-
def empty?
|
22
|
-
@lines.empty?
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Dsl
|
3
|
-
# @api private
|
4
|
-
class TagType < String
|
5
|
-
|
6
|
-
def self.new(type)
|
7
|
-
if type
|
8
|
-
types = Array(type)
|
9
|
-
types = types.map { |t| t.nil? ? 'nil' : t.to_s }
|
10
|
-
super(types.empty? ? '' : " [#{types.join(', ')}]")
|
11
|
-
else
|
12
|
-
super('')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,334 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
class ClientApiModule < Dsl::Module
|
4
|
-
|
5
|
-
include Helper
|
6
|
-
|
7
|
-
SKIP_TRAITS = Set.new(%w(shape deprecated location locationName documentation))
|
8
|
-
|
9
|
-
SHAPE_CLASSES = {
|
10
|
-
'blob' => 'BlobShape',
|
11
|
-
'byte' => 'IntegerShape',
|
12
|
-
'boolean' => 'BooleanShape',
|
13
|
-
'character' => 'StringShape',
|
14
|
-
'double' => 'FloatShape',
|
15
|
-
'float' => 'FloatShape',
|
16
|
-
'integer' => 'IntegerShape',
|
17
|
-
'list' => 'ListShape',
|
18
|
-
'long' => 'IntegerShape',
|
19
|
-
'map' => 'MapShape',
|
20
|
-
'string' => 'StringShape',
|
21
|
-
'structure' => 'StructureShape',
|
22
|
-
'timestamp' => 'TimestampShape',
|
23
|
-
}
|
24
|
-
|
25
|
-
SHAPE_KEYS = {
|
26
|
-
# keep
|
27
|
-
'flattened' => true,
|
28
|
-
'timestampFormat' => true, # glacier api customization
|
29
|
-
'xmlNamespace' => true,
|
30
|
-
# ignore
|
31
|
-
'box' => false,
|
32
|
-
'fault' => false,
|
33
|
-
'error' => false,
|
34
|
-
'deprecated' => false,
|
35
|
-
'type' => false,
|
36
|
-
'documentation' => false,
|
37
|
-
'members' => false,
|
38
|
-
'member' => false,
|
39
|
-
'key' => false,
|
40
|
-
'locationName' => false,
|
41
|
-
'value' => false,
|
42
|
-
'required' => false,
|
43
|
-
'streaming' => false,
|
44
|
-
'enum' => false,
|
45
|
-
'exception' => false,
|
46
|
-
'payload' => false,
|
47
|
-
'pattern' => false,
|
48
|
-
'sensitive' => false,
|
49
|
-
'min' => false,
|
50
|
-
'max' => false,
|
51
|
-
'wrapper' => false,
|
52
|
-
'xmlOrder' => false,
|
53
|
-
}
|
54
|
-
|
55
|
-
METADATA_KEYS = {
|
56
|
-
# keep
|
57
|
-
'endpointPrefix' => true,
|
58
|
-
'signatureVersion' => true,
|
59
|
-
'signingName' => true,
|
60
|
-
'serviceFullName' => true,
|
61
|
-
'protocol' => true,
|
62
|
-
'targetPrefix' => true,
|
63
|
-
'jsonVersion' => true,
|
64
|
-
'errorPrefix' => true,
|
65
|
-
'timestampFormat' => true, # glacier api customization
|
66
|
-
'xmlNamespace' => true,
|
67
|
-
|
68
|
-
# ignore
|
69
|
-
'apiVersion' => false,
|
70
|
-
'checksumFormat' => false,
|
71
|
-
'globalEndpoint' => false,
|
72
|
-
'serviceAbbreviation' => false,
|
73
|
-
'uid' => false,
|
74
|
-
}
|
75
|
-
|
76
|
-
# @option options [required, Hash] :api
|
77
|
-
# @option options [required, Hash, nil] :paginators
|
78
|
-
def initialize(options)
|
79
|
-
@api = options.fetch(:api)
|
80
|
-
@paginators = options.fetch(:paginators)
|
81
|
-
super('ClientApi')
|
82
|
-
docstring("@api private")
|
83
|
-
include('Seahorse::Model')
|
84
|
-
apply_shape_classes(self)
|
85
|
-
apply_shape_definitions(self)
|
86
|
-
apply_api_const(self)
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
def metadata
|
92
|
-
Dsl::CodeLiteral.new do |c|
|
93
|
-
c << "api.metadata = {"
|
94
|
-
c.indent do
|
95
|
-
(@api['metadata'] || {}).keys.sort.each do |key|
|
96
|
-
if METADATA_KEYS[key]
|
97
|
-
c << "#{key.inspect} => #{@api['metadata'][key].inspect},"
|
98
|
-
elsif METADATA_KEYS[key].nil?
|
99
|
-
raise "unhandled metadata key #{key.inspect}"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
c << "}"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def operations
|
108
|
-
(@api['operations'] || {}).map do |name, operation|
|
109
|
-
operation(name, operation)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def operation(name, operation)
|
114
|
-
Dsl::CodeLiteral.new do |code|
|
115
|
-
code << "api.add_operation(:#{underscore(name)}, Seahorse::Model::Operation.new.tap do |o|"
|
116
|
-
code.indent do |c|
|
117
|
-
c << "o.name = #{name.inspect}"
|
118
|
-
c << "o.http_method = #{operation['http']['method'].inspect}"
|
119
|
-
c << "o.http_request_uri = #{operation['http']['requestUri'].inspect}"
|
120
|
-
c << "o.deprecated = true" if operation['deprecated']
|
121
|
-
c << "o['authtype'] = #{operation['authtype'].inspect}" if operation['authtype']
|
122
|
-
%w(input output).each do |mode|
|
123
|
-
c << "o.#{mode} = #{operation_shape_ref(operation[mode])}"
|
124
|
-
end
|
125
|
-
Array(operation['errors']).each do |error|
|
126
|
-
c << "o.errors << #{operation_shape_ref(error)}"
|
127
|
-
end
|
128
|
-
apply_operation_pager(c, name)
|
129
|
-
end
|
130
|
-
code << "end)"
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def operation_shape_ref(ref)
|
135
|
-
if ref
|
136
|
-
metadata = ref.dup
|
137
|
-
shape_name = metadata.delete('shape')
|
138
|
-
if metadata.empty?
|
139
|
-
options = ''
|
140
|
-
else
|
141
|
-
options = {}
|
142
|
-
metadata.each_pair do |key, value|
|
143
|
-
next if key == 'resultWrapper'
|
144
|
-
if key == 'locationName'
|
145
|
-
options[:location_name] = value.inspect
|
146
|
-
else
|
147
|
-
options[:metadata] ||= {}
|
148
|
-
options[:metadata][key] = value.inspect
|
149
|
-
end
|
150
|
-
end
|
151
|
-
if options.empty?
|
152
|
-
options = ''
|
153
|
-
else
|
154
|
-
options = ', ' + HashFormatter.new(wrap:false).format(options)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
"Shapes::ShapeRef.new(shape: #{shape_name}#{options})"
|
158
|
-
else
|
159
|
-
"Shapes::ShapeRef.new(shape: Shapes::StructureShape.new(struct_class: Aws::EmptyStructure))"
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def shape_ref(ref, member_name = nil, required = Set.new)
|
164
|
-
line = "Shapes::ShapeRef.new(shape: #{ref['shape']}"
|
165
|
-
line += shape_ref_required(required, member_name)
|
166
|
-
line += shape_ref_deprecated(ref)
|
167
|
-
line += shape_ref_location(ref)
|
168
|
-
line += shape_ref_location_name(member_name, ref)
|
169
|
-
line += shape_ref_metadata(ref)
|
170
|
-
line += ")"
|
171
|
-
line
|
172
|
-
end
|
173
|
-
|
174
|
-
def apply_operation_pager(code, operation_name)
|
175
|
-
if @paginators && @paginators['pagination'][operation_name]
|
176
|
-
p = @paginators['pagination'][operation_name]
|
177
|
-
input = Array(p['input_token'])
|
178
|
-
output = Array(p['output_token'])
|
179
|
-
tokens = {}
|
180
|
-
input.each.with_index do |key, n|
|
181
|
-
tokens[underscore_jmespath(output[n])] = underscore_jmespath(key)
|
182
|
-
end
|
183
|
-
options = {}
|
184
|
-
options[:more_results] = underscore_jmespath(p['more_results']) if p['more_results']
|
185
|
-
options[:limit_key] = underscore_jmespath(p['limit_key']) if p['limit_key']
|
186
|
-
options[:tokens] = tokens
|
187
|
-
options = HashFormatter.new(
|
188
|
-
quote_strings: true,
|
189
|
-
inline: true,
|
190
|
-
wrap: false,
|
191
|
-
).format(options)
|
192
|
-
code << "o[:pager] = Aws::Pager.new(#{options})" unless tokens.empty?
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
def underscore_jmespath(str)
|
197
|
-
Underscore.underscore_jmespath(str)
|
198
|
-
end
|
199
|
-
|
200
|
-
def apply_shape_classes(m)
|
201
|
-
m.code do |c|
|
202
|
-
shape_defs.each do |shape_name, shape|
|
203
|
-
attrs = []
|
204
|
-
attrs << "name: '#{shape_name}'"
|
205
|
-
shape.each_pair do |key, value|
|
206
|
-
if SHAPE_KEYS[key]
|
207
|
-
attrs << "#{key}: #{value.inspect}"
|
208
|
-
elsif SHAPE_KEYS[key].nil?
|
209
|
-
raise "unhandled shape key #{key.inspect}"
|
210
|
-
end
|
211
|
-
end
|
212
|
-
attrs = attrs.join(', ')
|
213
|
-
c << "#{shape_name} = Shapes::#{shape_class(shape['type'])}.new(#{attrs})"
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
def apply_shape_definitions(m)
|
219
|
-
m.code do |c|
|
220
|
-
shape_defs.each do |shape_name, shape|
|
221
|
-
if shape['type'] == 'structure' && !shape['error'] && !shape['exception']
|
222
|
-
required = Set.new(shape['required'] || [])
|
223
|
-
shape['members'].each do |member_name, member_ref|
|
224
|
-
c << "#{shape_name}.add_member(:#{underscore(member_name)}, #{shape_ref(member_ref, member_name, required)})"
|
225
|
-
end
|
226
|
-
c << "#{shape_name}.struct_class = Types::#{shape_name}"
|
227
|
-
if payload = shape['payload']
|
228
|
-
c << "#{shape_name}[:payload] = :#{underscore(payload)}"
|
229
|
-
c << "#{shape_name}[:payload_member] = #{shape_name}.member(:#{underscore(payload)})"
|
230
|
-
end
|
231
|
-
elsif shape['type'] == 'list'
|
232
|
-
c << "#{shape_name}.member = #{shape_ref(shape['member'])}"
|
233
|
-
elsif shape['type'] == 'map'
|
234
|
-
c << "#{shape_name}.key = #{shape_ref(shape['key'])}"
|
235
|
-
c << "#{shape_name}.value = #{shape_ref(shape['value'])}"
|
236
|
-
else
|
237
|
-
next
|
238
|
-
end
|
239
|
-
c.newline
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
def apply_api_const(m)
|
245
|
-
m.code do |c|
|
246
|
-
c << "# @api private"
|
247
|
-
c << "API = Seahorse::Model::Api.new.tap do |api|"
|
248
|
-
c.indent do
|
249
|
-
c.newline
|
250
|
-
if @api['metadata'] && @api['metadata']['apiVersion']
|
251
|
-
c << "api.version = #{@api['metadata']['apiVersion'].inspect}"
|
252
|
-
c.newline
|
253
|
-
end
|
254
|
-
c << metadata
|
255
|
-
operations.each do |operation|
|
256
|
-
c.newline
|
257
|
-
c << operation
|
258
|
-
end
|
259
|
-
end
|
260
|
-
c << "end"
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
def shape_ref_required(required, member_name)
|
265
|
-
if required.include?(member_name)
|
266
|
-
", required: true"
|
267
|
-
else
|
268
|
-
""
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
def shape_ref_deprecated(ref)
|
273
|
-
if ref['deprecated'] || @api['shapes'][ref['shape']]['deprecated']
|
274
|
-
", deprecated: true"
|
275
|
-
else
|
276
|
-
""
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
def shape_ref_location(ref)
|
281
|
-
if ref['location']
|
282
|
-
", location: #{ref['location'].inspect}"
|
283
|
-
else
|
284
|
-
''
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
def shape_ref_location_name(member_name, member_ref)
|
289
|
-
location_name = member_ref['locationName']
|
290
|
-
location_name ||= member_name unless member_ref['location'] == 'headers'
|
291
|
-
location_name ? ", location_name: #{location_name.inspect}" : ""
|
292
|
-
end
|
293
|
-
|
294
|
-
def shape_ref_metadata(member_ref)
|
295
|
-
metadata = member_ref.inject({}) do |hash, (key, value)|
|
296
|
-
hash[key] = value unless SKIP_TRAITS.include?(key)
|
297
|
-
hash
|
298
|
-
end
|
299
|
-
if metadata.empty?
|
300
|
-
""
|
301
|
-
else
|
302
|
-
", metadata: #{metadata.inspect}"
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
def shape_class(type)
|
307
|
-
if SHAPE_CLASSES.key?(type)
|
308
|
-
SHAPE_CLASSES[type]
|
309
|
-
else
|
310
|
-
raise ArgumentError, "unsupported shape type `#{type}'"
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
def shape_defs
|
315
|
-
Enumerator.new do |y|
|
316
|
-
(@api['shapes'] || {}).keys.sort.each do |shape_name|
|
317
|
-
y.yield(shape_name, @api['shapes'][shape_name])
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
def structure_defs
|
323
|
-
Enumerator.new do |y|
|
324
|
-
shape_defs.each do |shape_name, shape|
|
325
|
-
if shape['type'] == 'structure' && !shape['error'] && !shape['exception']
|
326
|
-
y.yield(shape_name, shape)
|
327
|
-
end
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
end
|
333
|
-
end
|
334
|
-
end
|