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.
- checksums.yaml +5 -5
- data/lib/aws-sdk-code-generator/api.rb +150 -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 +282 -0
- data/lib/aws-sdk-code-generator/client_operation_list.rb +148 -0
- data/lib/aws-sdk-code-generator/client_response_structure_example.rb +115 -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 +42 -25
- data/lib/aws-sdk-code-generator/hash_formatter.rb +5 -2
- data/lib/aws-sdk-code-generator/helper.rb +86 -119
- data/lib/aws-sdk-code-generator/plugin_list.rb +147 -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/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 +602 -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 +52 -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 +6 -2
- 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 +38 -14
- data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -0
- data/lib/aws-sdk-code-generator/views/types_module.rb +329 -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/views.rb +2 -0
- data/lib/aws-sdk-code-generator/waiter.rb +95 -0
- data/lib/aws-sdk-code-generator/yard_option_tag.rb +43 -0
- data/lib/aws-sdk-code-generator.rb +68 -75
- data/templates/apig_endpoint_class.mustache +16 -0
- data/templates/apig_readme.mustache +62 -0
- data/templates/async_client_class.mustache +125 -0
- data/templates/authorizer_class.mustache +37 -0
- data/templates/client_api_module.mustache +106 -0
- data/templates/client_class.mustache +295 -0
- data/templates/code.mustache +4 -0
- data/templates/documentation.mustache +4 -0
- data/templates/errors_module.mustache +70 -0
- data/templates/event_streams_module.mustache +76 -0
- data/templates/features/env.mustache +15 -0
- data/templates/features/smoke.mustache +22 -0
- data/templates/features/smoke_step_definitions.mustache +31 -0
- data/templates/features/step_definitions.mustache +13 -0
- data/templates/gemspec.mustache +31 -0
- data/templates/license.txt +202 -0
- data/templates/method.mustache +7 -0
- data/templates/resource_class.mustache +304 -0
- data/templates/root_resource_class.mustache +51 -0
- data/templates/service_module.mustache +58 -0
- data/templates/spec/spec_helper.mustache +15 -0
- data/templates/types_module.mustache +53 -0
- data/templates/version.mustache +1 -0
- data/templates/waiters_module.mustache +112 -0
- metadata +115 -70
- 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
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AwsSdkCodeGenerator
|
4
|
+
class ResourceWaiter
|
5
|
+
|
6
|
+
# @return [String]
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
attr_accessor :client_waiter_name
|
10
|
+
|
11
|
+
# @return [String]
|
12
|
+
attr_accessor :waiter_class_name
|
13
|
+
|
14
|
+
# @return [Integer]
|
15
|
+
attr_accessor :delay
|
16
|
+
|
17
|
+
# @return [Integer]
|
18
|
+
attr_accessor :max_attempts
|
19
|
+
|
20
|
+
# @return [String<Ruby>]
|
21
|
+
attr_accessor :wait_call
|
22
|
+
|
23
|
+
# @return [String<Ruby>]
|
24
|
+
attr_accessor :constructor_args
|
25
|
+
|
26
|
+
class << self
|
27
|
+
|
28
|
+
# @param [Hash] resource
|
29
|
+
# @param [Hash, nil] client_waiters
|
30
|
+
# @return [Array<ResourceWaiter>]
|
31
|
+
def build_list(resource, client_waiters)
|
32
|
+
client_waiters = Waiter.build_list(client_waiters)
|
33
|
+
(resource['waiters'] || {}).map do |name, waiter|
|
34
|
+
client_waiter = client_waiters.find do |w|
|
35
|
+
w.name == Underscore.underscore(waiter['waiterName'])
|
36
|
+
end
|
37
|
+
ResourceWaiter.new.tap do |w|
|
38
|
+
w.name = Underscore.underscore(name)
|
39
|
+
w.client_waiter_name = client_waiter.name
|
40
|
+
w.waiter_class_name = client_waiter.class_name
|
41
|
+
w.delay = client_waiter.delay
|
42
|
+
w.max_attempts = client_waiter.max_attempts
|
43
|
+
w.wait_call = wait_call(waiter)
|
44
|
+
w.constructor_args = constructor_args(resource, waiter)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def wait_call(waiter)
|
52
|
+
args = ResourceClientRequestParams.new(
|
53
|
+
params: waiter['params']
|
54
|
+
).to_s.strip
|
55
|
+
if waiter['path']
|
56
|
+
"resp = waiter.wait(params.merge(#{args}))"
|
57
|
+
else
|
58
|
+
"waiter.wait(params.merge(#{args}))"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def constructor_args(resource, waiter)
|
63
|
+
args = {}
|
64
|
+
(resource['identifiers'] || []).each do |i|
|
65
|
+
name = Underscore.underscore(i['name']).to_sym
|
66
|
+
args[name] = "@#{name}"
|
67
|
+
end
|
68
|
+
if waiter['path']
|
69
|
+
args[:data] = ResourceValueSource.new(
|
70
|
+
'source' => 'response',
|
71
|
+
'path' => waiter['path']
|
72
|
+
)
|
73
|
+
end
|
74
|
+
args[:client] = '@client'
|
75
|
+
HashFormatter.new(wrap: false).format(args)[1..-2]
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module AwsSdkCodeGenerator
|
2
4
|
class Service
|
3
5
|
|
@@ -12,6 +14,7 @@ module AwsSdkCodeGenerator
|
|
12
14
|
# @option options [Hash, String] :waiters
|
13
15
|
# @option options [Hash, String] :resources
|
14
16
|
# @option options [Hash, String] :examples
|
17
|
+
# @option options [Hash, String] :smoke_tests
|
15
18
|
# @option options [Hash<gem,version>] :gem_dependencies ({})
|
16
19
|
# @option options [Hash] :add_plugins ({})
|
17
20
|
# @option options [Hash] :remove_plugins ([])
|
@@ -22,24 +25,32 @@ module AwsSdkCodeGenerator
|
|
22
25
|
@gem_name = options[:gem_name] || "aws-sdk-#{identifier}"
|
23
26
|
@gem_version = options.fetch(:gem_version)
|
24
27
|
@api = load_json(options.fetch(:api))
|
25
|
-
|
28
|
+
unless @api['metadata']['protocol'] == 'api-gateway'
|
29
|
+
# Dont reply on API Gateway doc.json
|
30
|
+
ApplyDocs.new(@api).apply(load_json(options[:docs]))
|
31
|
+
end
|
26
32
|
@paginators = load_json(options[:paginators])
|
27
33
|
@waiters = load_json(options[:waiters])
|
28
34
|
@resources = load_json(options[:resources])
|
29
35
|
@examples = load_json(options[:examples])
|
30
|
-
@
|
31
|
-
|
32
|
-
}.merge(options[:gem_dependencies] || {})
|
36
|
+
@smoke_tests = load_json(options[:smoke_tests])
|
37
|
+
@gem_dependencies = options[:gem_dependencies] || {}
|
33
38
|
@add_plugins = options[:add_plugins] || {}
|
34
39
|
@remove_plugins = options[:remove_plugins] || []
|
35
40
|
@endpoints_key = options.fetch(:endpoints_key, nil)
|
41
|
+
# APIG custom service only
|
42
|
+
@default_endpoint = options[:default_endpoint]
|
36
43
|
|
37
44
|
# computed attributes
|
38
45
|
@protocol = api.fetch('metadata').fetch('protocol')
|
46
|
+
@protocol_settings = api.fetch('metadata')['protocolSettings'] || {}
|
39
47
|
@api_version = api.fetch('metadata')['apiVersion']
|
40
48
|
@signature_version = api.fetch('metadata')['signatureVersion']
|
41
49
|
@full_name = api.fetch('metadata')['serviceFullName']
|
42
50
|
@short_name = api.fetch('metadata')['serviceAbbreviation'] || @full_name
|
51
|
+
@require_endpoint_discovery = api.fetch('operations', []).any? do |_, o|
|
52
|
+
o['endpointdiscovery'] && o['endpointdiscovery']['required']
|
53
|
+
end
|
43
54
|
end
|
44
55
|
|
45
56
|
# @return [String] The service name, e.g. "S3"
|
@@ -63,6 +74,9 @@ module AwsSdkCodeGenerator
|
|
63
74
|
# @return [Hash, nil] The service shared examples model.
|
64
75
|
attr_reader :examples
|
65
76
|
|
77
|
+
# @return [Hash, nil] The service smoke test model.
|
78
|
+
attr_reader :smoke_tests
|
79
|
+
|
66
80
|
# @return [Hash<String,String>] A hash of gem dependencies. Hash keys
|
67
81
|
# are gem names, values are versions.
|
68
82
|
attr_reader :gem_dependencies
|
@@ -70,9 +84,15 @@ module AwsSdkCodeGenerator
|
|
70
84
|
# @return [String]
|
71
85
|
attr_reader :gem_version
|
72
86
|
|
87
|
+
# @return [String] The gem name, e.g. "aws-sdk-s3"
|
88
|
+
attr_reader :gem_name
|
89
|
+
|
73
90
|
# @return [String, nil]
|
74
91
|
attr_reader :endpoints_key
|
75
92
|
|
93
|
+
# @return [String] Required for APIG custom service
|
94
|
+
attr_reader :default_endpoint
|
95
|
+
|
76
96
|
# @return [Hash<String,String>] A hash of plugins to add.
|
77
97
|
attr_reader :add_plugins
|
78
98
|
|
@@ -82,12 +102,12 @@ module AwsSdkCodeGenerator
|
|
82
102
|
# @return [String] The service identifier, e.g. "s3"
|
83
103
|
attr_reader :identifier
|
84
104
|
|
85
|
-
# @return [String] The gem name, e.g. "aws-sdk-s3"
|
86
|
-
attr_reader :gem_name
|
87
|
-
|
88
105
|
# @return [String] The service protocol, e.g. "json", "query", etc.
|
89
106
|
attr_reader :protocol
|
90
107
|
|
108
|
+
# @return [Hash] The service protocol settings
|
109
|
+
attr_reader :protocol_settings
|
110
|
+
|
91
111
|
# @return [String] The service API version, e.g. "YYYY-MM-DD".
|
92
112
|
attr_reader :api_version
|
93
113
|
|
@@ -101,6 +121,9 @@ module AwsSdkCodeGenerator
|
|
101
121
|
# @return [String] The short product name for the service, e.g. "Amazon S3".
|
102
122
|
attr_reader :short_name
|
103
123
|
|
124
|
+
# @return [Boolean] true if any operation requires endpoint_discovery
|
125
|
+
attr_reader :require_endpoint_discovery
|
126
|
+
|
104
127
|
# @api private
|
105
128
|
def inspect
|
106
129
|
"#<#{self.class.name}>"
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AwsSdkCodeGenerator
|
4
|
+
class SharedExample
|
5
|
+
|
6
|
+
def initialize(params, method_name, operation, api, comments)
|
7
|
+
@params = params
|
8
|
+
@method_name = method_name
|
9
|
+
@operation = operation
|
10
|
+
@api = api
|
11
|
+
@comments = comments
|
12
|
+
@params ||= {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_str_input
|
16
|
+
lines = structure(@params, Api.shape(@operation['input'], @api), "", [])
|
17
|
+
params = lines.join("\n")
|
18
|
+
"resp = client.#{@method_name}(#{params})"
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_str_output
|
22
|
+
lines = structure(@params, Api.shape(@operation['output'], @api), "", [])
|
23
|
+
params = lines.join("\n")
|
24
|
+
"#{params}"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def entry(json, ref, indent, path)
|
30
|
+
case ref['type']
|
31
|
+
when 'structure'
|
32
|
+
if is_ddb_simple_attribute?(ref)
|
33
|
+
string(json.first[1])
|
34
|
+
else
|
35
|
+
structure(json, ref, indent, path)
|
36
|
+
end
|
37
|
+
when 'map' then map(json, ref, indent, path)
|
38
|
+
when 'list' then list(json, ref, indent, path)
|
39
|
+
when 'timestamp' then "Time.parse(#{json.inspect})"
|
40
|
+
when 'string', 'blob' then string(json)
|
41
|
+
else json
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_ddb_simple_attribute?(ref)
|
46
|
+
ref['members'].keys == ["S", "N", "B", "SS", "NS", "BS", "M", "L", "NULL", "BOOL"] &&
|
47
|
+
@api['metadata']['serviceFullName'] == 'Amazon DynamoDB'
|
48
|
+
end
|
49
|
+
|
50
|
+
def string(json)
|
51
|
+
# Travis jruby hangs when parsing long string (e.g. policy string)
|
52
|
+
# Clean all white spaces in those strings
|
53
|
+
if json.length > 2048
|
54
|
+
json.gsub(/\s+/, "").inspect
|
55
|
+
else
|
56
|
+
json.inspect
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def structure(json, ref, indent, path)
|
61
|
+
lines = ["{"]
|
62
|
+
json.each do |key, val|
|
63
|
+
path << ".#{key}"
|
64
|
+
shape_val = entry(val, Api.shape(ref['members'][key], @api), "#{indent} ", path)
|
65
|
+
lines << "#{indent} #{Underscore.underscore(key)}: #{format(shape_val)}, #{apply_comments(path)}"
|
66
|
+
path.pop
|
67
|
+
end
|
68
|
+
lines << "#{indent}}"
|
69
|
+
lines
|
70
|
+
end
|
71
|
+
|
72
|
+
def map(json, ref, indent, path)
|
73
|
+
lines = ["{"]
|
74
|
+
json.each do |key, val|
|
75
|
+
path << ".#{key}"
|
76
|
+
_, ref_value = Api.resolve(ref['value'], @api)
|
77
|
+
shape_val = entry(val, ref_value, "#{indent} ", path)
|
78
|
+
lines << "#{indent} \"#{key}\" => #{format(shape_val)}, #{apply_comments(path)}"
|
79
|
+
path.pop
|
80
|
+
end
|
81
|
+
lines << "#{indent}}"
|
82
|
+
lines
|
83
|
+
end
|
84
|
+
|
85
|
+
def list(json, ref, indent, path)
|
86
|
+
lines = ["["]
|
87
|
+
json.each_with_index do |member, index|
|
88
|
+
path << "[#{index}]"
|
89
|
+
_, ref_val = Api.resolve(ref['member']['shape'], @api)
|
90
|
+
shape_val = entry(member, ref_val, "#{indent} ", path)
|
91
|
+
if shape_val.is_a?(Array)
|
92
|
+
shape_val = shape_val.join("\n")
|
93
|
+
end
|
94
|
+
lines << "#{indent} #{shape_val}, #{apply_comments(path)}"
|
95
|
+
path.pop
|
96
|
+
end
|
97
|
+
lines << "#{indent}]"
|
98
|
+
lines
|
99
|
+
end
|
100
|
+
|
101
|
+
def format(shape_val)
|
102
|
+
formatted = []
|
103
|
+
if shape_val.is_a?(Array)
|
104
|
+
hashes = []
|
105
|
+
shape_val.each do |v|
|
106
|
+
hashes << (v.is_a?(Hash) ? format_hash(v, ' ') : v)
|
107
|
+
end
|
108
|
+
hashes.join(",")
|
109
|
+
formatted << hashes
|
110
|
+
elsif shape_val.is_a?(Hash)
|
111
|
+
formatted << format_hash(shape_val, ' ')
|
112
|
+
else
|
113
|
+
formatted << shape_val
|
114
|
+
end
|
115
|
+
formatted.join("\n")
|
116
|
+
end
|
117
|
+
|
118
|
+
def format_hash(value, indent)
|
119
|
+
HashFormatter.new(indent: indent).format(value)
|
120
|
+
end
|
121
|
+
|
122
|
+
def apply_comments(path)
|
123
|
+
key = path.join().sub(/^\./, '')
|
124
|
+
if @comments && @comments[key]
|
125
|
+
"# #{@comments[key]}"
|
126
|
+
else
|
127
|
+
""
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module AwsSdkCodeGenerator
|
6
|
+
class SyntaxExample
|
7
|
+
|
8
|
+
include Helper
|
9
|
+
|
10
|
+
# @option options [required, Hash] :api
|
11
|
+
# @option options [required, Hash] :shape
|
12
|
+
def initialize(options = {})
|
13
|
+
@api = options.fetch(:api)
|
14
|
+
@method_name = options.fetch(:method_name)
|
15
|
+
@receiver = options.fetch(:receiver)
|
16
|
+
@resp_var = options[:resp_var] ? "#{options[:resp_var]} = " : ''
|
17
|
+
@shape = filter_shape(options)
|
18
|
+
@async = options[:async] || false
|
19
|
+
@hash = SyntaxExampleHash.new(api: @api, shape: @shape, async: @async).format('# ') if @shape
|
20
|
+
end
|
21
|
+
|
22
|
+
def format
|
23
|
+
if @shape && @shape['members'] && @shape['members'].length > 0
|
24
|
+
<<-EXAMPLE.strip
|
25
|
+
# @example Request syntax with placeholder values
|
26
|
+
#
|
27
|
+
# #{@resp_var}#{@receiver}.#{@method_name}(#{@hash})
|
28
|
+
#{async_format}
|
29
|
+
EXAMPLE
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def async_format
|
36
|
+
if @async
|
37
|
+
<<-ASYNC.strip
|
38
|
+
# # => Seahorse::Client::AsyncResponse
|
39
|
+
# async_resp.wait
|
40
|
+
# # => Seahorse::Client::Response
|
41
|
+
# # Or use async_resp.join!
|
42
|
+
ASYNC
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def filter_shape(options)
|
51
|
+
skip = Set.new(options.fetch(:skip, []))
|
52
|
+
shape = Helper.deep_copy(options.fetch(:shape))
|
53
|
+
options.fetch(:skip, []).each do |skip|
|
54
|
+
shape['members'].delete(skip)
|
55
|
+
end
|
56
|
+
shape
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module AwsSdkCodeGenerator
|
6
|
+
class SyntaxExampleHash
|
7
|
+
|
8
|
+
include Helper
|
9
|
+
|
10
|
+
# @option options [required, Hash] :api
|
11
|
+
# @option options [required, Hash] :shape_ref
|
12
|
+
def initialize(options = {})
|
13
|
+
@api = options.fetch(:api)
|
14
|
+
@shape = options.fetch(:shape)
|
15
|
+
@async = options[:async] || false
|
16
|
+
end
|
17
|
+
|
18
|
+
def format(indent = '')
|
19
|
+
struct(@shape, indent, [])
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def ref_value(ref, i, visited)
|
25
|
+
if visited.include?(ref['shape'])
|
26
|
+
return "{\n#{i} # recursive #{ref['shape']}\n#{i}}"
|
27
|
+
else
|
28
|
+
visited = visited + [ref['shape']]
|
29
|
+
end
|
30
|
+
|
31
|
+
s = shape(ref)
|
32
|
+
case s['type']
|
33
|
+
when 'structure'
|
34
|
+
if ref['shape'] == 'AttributeValue'
|
35
|
+
'"value"'
|
36
|
+
else
|
37
|
+
struct(s, i, visited)
|
38
|
+
end
|
39
|
+
|
40
|
+
when 'blob'
|
41
|
+
if ref['streaming']
|
42
|
+
'source_file'
|
43
|
+
else
|
44
|
+
'"data"'
|
45
|
+
end
|
46
|
+
|
47
|
+
when 'list' then list(s, i, visited)
|
48
|
+
when 'map' then map(s, i, visited)
|
49
|
+
when 'boolean' then "false"
|
50
|
+
when 'integer', 'long' then '1'
|
51
|
+
when 'float', 'double' then '1.0'
|
52
|
+
when 'byte' then '97'
|
53
|
+
when 'character' then '"a"'
|
54
|
+
when 'string' then string(ref)
|
55
|
+
when 'timestamp' then 'Time.now'
|
56
|
+
else raise "unsupported shape #{s['type'].inspect}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def struct(struct_shape, i, visited)
|
61
|
+
lines = ['{']
|
62
|
+
unless struct_shape['members'].nil?
|
63
|
+
struct_shape['members'].each_pair do |member_name, member_ref|
|
64
|
+
next if member_ref['documented'] === false
|
65
|
+
# input eventstream shouldn't be provided from params
|
66
|
+
if @api['shapes'][member_ref['shape']]['eventstream'] === true
|
67
|
+
lines << "#{i} input_event_stream_hander: EventStreams::#{member_ref['shape']}.new,"
|
68
|
+
else
|
69
|
+
lines << struct_member(struct_shape, member_name, member_ref, i, visited)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
lines << "#{i}}"
|
74
|
+
lines.join("\n")
|
75
|
+
end
|
76
|
+
|
77
|
+
def struct_member(struct, member_name, member_ref, i, visited)
|
78
|
+
entry = "#{i} #{underscore(member_name)}: #{ref_value(member_ref, i + ' ', visited)},"
|
79
|
+
required = (struct['required'] || []).include?(member_name)
|
80
|
+
apply_comments(member_ref, entry, required: required)
|
81
|
+
end
|
82
|
+
|
83
|
+
def list(list_shape, i, visited)
|
84
|
+
member_ref = list_shape['member']
|
85
|
+
if complex?(member_ref)
|
86
|
+
complex_list(member_ref, i, visited)
|
87
|
+
else
|
88
|
+
scalar_list(member_ref, i, visited)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def scalar_list(member_ref, i, visited)
|
93
|
+
"[#{ref_value(member_ref, i, visited)}]"
|
94
|
+
end
|
95
|
+
|
96
|
+
def complex_list(member_ref, i, visited)
|
97
|
+
"[\n#{i} #{ref_value(member_ref, i + ' ', visited)},\n#{i}]"
|
98
|
+
end
|
99
|
+
|
100
|
+
def map(map_shape, i, visited)
|
101
|
+
key = string(map_shape['key'])
|
102
|
+
value = ref_value(map_shape['value'], i + ' ', visited)
|
103
|
+
"{\n#{i} #{key} => #{value},#{comments(map_shape['value'], false)}\n#{i}}"
|
104
|
+
end
|
105
|
+
|
106
|
+
def string(ref)
|
107
|
+
string_shape = shape(ref)
|
108
|
+
if string_shape['enum']
|
109
|
+
string_shape['enum'].first.inspect
|
110
|
+
else ref['shape']
|
111
|
+
ref['shape'].inspect
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def apply_comments(ref, text, options = {})
|
116
|
+
required = options.fetch(:required)
|
117
|
+
lines = text.lines.to_a
|
118
|
+
if lines[0].match(/\n$/)
|
119
|
+
lines[0] = lines[0].sub(/\n$/, comments(ref, required) + "\n")
|
120
|
+
else
|
121
|
+
lines[0] += comments(ref, required)
|
122
|
+
end
|
123
|
+
lines.join
|
124
|
+
end
|
125
|
+
|
126
|
+
def comments(ref, required)
|
127
|
+
comments = []
|
128
|
+
if ref[:response_target]
|
129
|
+
comments << 'where to write response data, file path, or IO object'
|
130
|
+
end
|
131
|
+
if ref[:streaming]
|
132
|
+
comments << 'file/IO object, or string data'
|
133
|
+
end
|
134
|
+
if required
|
135
|
+
comments << 'required'
|
136
|
+
end
|
137
|
+
if enum = enum_values(ref)
|
138
|
+
comments << "accepts #{enum.to_a.join(', ')}"
|
139
|
+
end
|
140
|
+
if ddb_av?(ref)
|
141
|
+
comments << 'value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>'
|
142
|
+
end
|
143
|
+
comments == [] ? '' : " # #{comments.join(', ')}"
|
144
|
+
end
|
145
|
+
|
146
|
+
def enum_values(ref)
|
147
|
+
s = shape(ref)
|
148
|
+
case s['type']
|
149
|
+
when 'list' then enum_values(s['member'])
|
150
|
+
when 'string' then s['enum']
|
151
|
+
else nil
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def complex?(ref)
|
156
|
+
s = shape(ref)
|
157
|
+
if s['type'] == 'structure'
|
158
|
+
!ddb_av?(ref)
|
159
|
+
else
|
160
|
+
s['type'] == 'list' || s['type'] == 'map'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def ddb_av?(ref)
|
165
|
+
s = shape(ref)
|
166
|
+
case s['type']
|
167
|
+
when 'list' then ddb_av?(s['member'])
|
168
|
+
when 'structure' then ref['shape'] == 'AttributeValue'
|
169
|
+
else false
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module AwsSdkCodeGenerator
|
2
4
|
module Underscore
|
3
5
|
class << self
|
@@ -10,11 +12,12 @@ module AwsSdkCodeGenerator
|
|
10
12
|
# @param [String] string
|
11
13
|
# @return [String] Returns the underscored version of the given string.
|
12
14
|
def underscore(string)
|
13
|
-
string.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
new_string = string.dup
|
16
|
+
new_string.gsub!(@irregular_regex) { |word| "_#{@irregular_inflections[word]}" }
|
17
|
+
new_string.gsub!(/([A-Z0-9]+)([A-Z][a-z])/, '\1_\2'.freeze)
|
18
|
+
new_string = new_string.scan(/[a-z0-9]+|\d+|[A-Z0-9]+[a-z]*/).join('_'.freeze)
|
19
|
+
new_string.downcase!
|
20
|
+
new_string
|
18
21
|
end
|
19
22
|
|
20
23
|
# @param [String<JMESPath>]
|
@@ -38,6 +41,8 @@ module AwsSdkCodeGenerator
|
|
38
41
|
'iSCSI' => 'iscsi',
|
39
42
|
'ACLs' => 'acls',
|
40
43
|
'Md5s' => 'md5s',
|
44
|
+
'HIT' => 'hit',
|
45
|
+
'URL' => 'url',
|
41
46
|
#'SSEKMS' => 'sse_kms',
|
42
47
|
})
|
43
48
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mustache'
|
2
4
|
|
3
5
|
module AwsSdkCodeGenerator
|
@@ -15,9 +17,40 @@ module AwsSdkCodeGenerator
|
|
15
17
|
subclass.raise_on_context_miss = true
|
16
18
|
end
|
17
19
|
|
20
|
+
# @param (see Underscore.underscore)
|
21
|
+
# @option (see Underscore.underscore)
|
22
|
+
# @return (see Underscore.underscore)
|
18
23
|
def underscore(string)
|
19
24
|
Underscore.underscore(string)
|
20
25
|
end
|
21
26
|
|
27
|
+
# @param (see Underscore.underscore_jmespath)
|
28
|
+
# @option (see Underscore.underscore_jmespath)
|
29
|
+
# @return (see Underscore.underscore_jmespath)
|
30
|
+
def underscore_jmespath(string)
|
31
|
+
Underscore.underscore_jmespath(string)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param (see Docstring.html_to_markdown)
|
35
|
+
# @option (see Docstring.html_to_markdown)
|
36
|
+
# @return (see Docstring.html_to_markdown)
|
37
|
+
def html_to_markdown(html, options = {})
|
38
|
+
Docstring.html_to_markdown(html, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param (see Docstring.block_comment)
|
42
|
+
# @option (see Docstring.block_comment)
|
43
|
+
# @return (see Docstring.block_comment)
|
44
|
+
def block_comment(text, options = {})
|
45
|
+
Docstring.block_comment(text, options = {})
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param (see Docstring.join_docstrings)
|
49
|
+
# @option (see Docstring.join_docstrings)
|
50
|
+
# @return (see Docstring.join_docstrings)
|
51
|
+
def join_docstrings(docs, options = {})
|
52
|
+
Docstring.join_docstrings(docs, options)
|
53
|
+
end
|
54
|
+
|
22
55
|
end
|
23
56
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AwsSdkCodeGenerator
|
4
|
+
module Views
|
5
|
+
|
6
|
+
class APIGEndpointClass < View
|
7
|
+
|
8
|
+
# @option options [required, String] :module_name
|
9
|
+
# @option options [required, String] :default_endpoint
|
10
|
+
def initialize(options)
|
11
|
+
@module_name = options.fetch(:module_name)
|
12
|
+
endpoint = options.fetch(:default_endpoint)
|
13
|
+
unless endpoint.start_with?('http://') || endpoint.start_with?('https://')
|
14
|
+
endpoint = "https://#{endpoint}"
|
15
|
+
end
|
16
|
+
@default_endpoint = endpoint
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :module_name
|
20
|
+
|
21
|
+
attr_reader :default_endpoint
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AwsSdkCodeGenerator
|
4
|
+
module Views
|
5
|
+
class APIGReadme < View
|
6
|
+
|
7
|
+
# @option options [required, String] :service_name
|
8
|
+
# @option options [required, String] :module_name
|
9
|
+
# @option options [required, String] :gem_name
|
10
|
+
# @option options [required, String] :gem_major_version
|
11
|
+
def initialize(options)
|
12
|
+
@service_name = options.fetch(:service_name)
|
13
|
+
@module_name = options.fetch(:module_name)
|
14
|
+
@gem_name = options.fetch(:gem_name)
|
15
|
+
@gem_major_version = options.fetch(:gem_major_version)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
attr_reader :module_name
|
20
|
+
|
21
|
+
# @return [String]
|
22
|
+
attr_reader :gem_major_version
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
attr_reader :gem_name
|
26
|
+
|
27
|
+
# @return [String]
|
28
|
+
attr_reader :service_name
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|