Skip to content

Commit 106135b

Browse files
authored
RPCv2 and CBOR support (#3006)
1 parent 5053f27 commit 106135b

File tree

95 files changed

+6448
-340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+6448
-340
lines changed

.github/workflows/changelog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
uses: thollander/actions-comment-pull-request@main
2020
with:
2121
message: 'You have made a change to core without a corresponding change to the CHANGELOG.md. This change will not result in a new version and will not published unless an entry is added to CHANGELOG.md.'
22-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ gem 'aws-crt' if ENV['CRT']
99
gem 'http-2'
1010
gem 'jmespath'
1111

12-
# json and xml parsers
12+
# protocol parsers
1313
gem 'json'
1414
gem 'nokogiri', '>= 1.6.8.1'
1515
gem 'oga'
1616
gem 'rexml', '= 3.2.6' # Temporary Workaround (https://github.com/ruby/rexml/issues/131)
1717

18-
# These json and xml parsers do not have java gems
18+
# These protocol parsers do not have java gems
1919
unless defined?(JRUBY_VERSION)
2020
gem 'libxml-ruby'
2121
gem 'oj'

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/client_operation_documentation.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def initialize(options)
1616
@method_name = options.fetch(:method_name)
1717
@operation = options.fetch(:operation)
1818
@api = options.fetch(:api)
19+
@protocol = options.fetch(:protocol)
1920
@client_examples = options.fetch(:client_examples, [])
2021
@examples = options.fetch(:examples)
2122
@module_name = options.fetch(:module_name)
@@ -279,7 +280,7 @@ def waiters_tag(waiters)
279280

280281
def see_also_tag(operation, api)
281282
uid = api['metadata']['uid']
282-
if api['metadata']['protocol'] != 'api-gateway' && Crosslink.taggable?(uid)
283+
if @protocol != 'api-gateway' && Crosslink.taggable?(uid)
283284
"# " + Crosslink.tag_string(uid, operation)
284285
end
285286
end

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/client_operation_list.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def initialize(options)
99
api = options.fetch(:api)
1010
examples = options.fetch(:examples, {})
1111
module_name = options.fetch(:module_name)
12+
protocol = options.fetch(:protocol)
1213
protocol_settings = options.fetch(:protocol_settings, {})
1314
client_examples = options.fetch(:client_examples, {})
1415
paginators = options.fetch(:paginators, {})
@@ -41,6 +42,7 @@ def initialize(options)
4142
method_name: method_name,
4243
operation: operation,
4344
api: api,
45+
protocol: protocol,
4446
examples: examples,
4547
client_examples: client_examples[method_name] || [],
4648
async_client: true
@@ -60,6 +62,7 @@ def initialize(options)
6062
method_name: method_name,
6163
operation: operation,
6264
api: api,
65+
protocol: protocol,
6366
examples: examples,
6467
client_examples: client_examples[method_name] || [],
6568
async_client: false
@@ -80,6 +83,7 @@ def initialize(options)
8083
method_name: method_name,
8184
operation: operation,
8285
api: api,
86+
protocol: protocol,
8387
examples: examples,
8488
client_examples: client_examples[method_name] || [],
8589
async_client: false,

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/code_builder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ def client_class(codegenerated_plugins)
185185
Views::ClientClass.new(
186186
service_identifier: @service.identifier,
187187
service_name: @service.name,
188+
protocol: @service.protocol,
188189
protocol_settings: @service.protocol_settings,
189190
module_name: @service.module_name,
190191
gem_name: @service.gem_name,
191192
gem_version: @service.gem_version,
192193
aws_sdk_core_lib_path: @aws_sdk_core_lib_path,
193194
client_examples: @client_examples,
194-
protocol: @service.protocol,
195195
signature_version: @service.signature_version,
196196
require_endpoint_discovery: @service.require_endpoint_discovery,
197197
add_plugins: @service.add_plugins,
@@ -210,12 +210,12 @@ def async_client_class(codegenerated_plugins)
210210
Views::AsyncClientClass.new(
211211
service_identifier: @service.identifier,
212212
service_name: @service.name,
213+
protocol: @service.protocol,
213214
protocol_settings: @service.protocol_settings,
214215
module_name: @service.module_name,
215216
gem_name: @service.gem_name,
216217
gem_version: @service.gem_version,
217218
aws_sdk_core_lib_path: @aws_sdk_core_lib_path,
218-
protocol: @service.protocol,
219219
signature_version: @service.signature_version,
220220
add_plugins: @service.add_plugins,
221221
remove_plugins: @service.remove_plugins,

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/plugin_list.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def protocol_plugins(protocol)
8686
'rest-xml' => { 'Aws::Plugins::Protocols::RestXml' => "#{core_plugins}/protocols/rest_xml.rb" },
8787
'query' => { 'Aws::Plugins::Protocols::Query' => "#{core_plugins}/protocols/query.rb" },
8888
'ec2' => { 'Aws::Plugins::Protocols::EC2' => "#{core_plugins}/protocols/ec2.rb" },
89+
'smithy-rpc-v2-cbor' => { 'Aws::Plugins::Protocols::RpcV2' => "#{core_plugins}/protocols/rpc_v2.rb" },
8990
'api-gateway' => {
9091
'Aws::Plugins::Protocols::ApiGateway' => "#{core_plugins}/protocols/api_gateway.rb",
9192
'Aws::Plugins::ApiKey' => "#{core_plugins}/api_key.rb",

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/service.rb

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@
22

33
module AwsSdkCodeGenerator
44
class Service
5+
# Ordered priority list of supported protocols
6+
# api-gateway is a special case and is always first.
7+
SUPPORTED_PROTOCOLS = %w[
8+
api-gateway
9+
smithy-rpc-v2-cbor
10+
json_1.0
11+
json_1.1
12+
rest-json
13+
rest-xml
14+
query
15+
ec2
16+
]
517

618
# @param [Hash] options
7-
# @option options [required, String] :gem_version Gem version, e.g. "1.0.0".
819
# @option options [required, String] :name The service name, e.g. "S3"
920
# @option options [String] :module_name The service module name, defaults
1021
# to "Aws::#{name}", e.g. "Aws::S3".
22+
# @option options [String] :gem_name The gem name, defaults to
23+
# "aws-sdk-#{name}", e.g. "aws-sdk-s3".
24+
# @option options [required, String] :gem_version Gem version, e.g. "1.0.0".
1125
# @option options [required, Hash, String] :api
1226
# @option options [Hash, String] :docs
1327
# @option options [Hash, String] :paginators
@@ -21,44 +35,48 @@ class Service
2135
# @option options [Hash] :add_plugins ({})
2236
# @option options [Hash] :remove_plugins ([])
2337
# @option options [Boolean] :deprecated (false)
38+
# @option options [String] :default_endpoint (nil)
39+
# @option options [String] :endpoints_key (nil)
2440
def initialize(options)
2541
@name = options.fetch(:name)
2642
@identifier = name.downcase
2743
@module_name = options[:module_name] || "Aws::#{name}"
2844
@gem_name = options[:gem_name] || "aws-sdk-#{identifier}"
2945
@gem_version = options.fetch(:gem_version)
46+
3047
@api = load_json(options.fetch(:api))
31-
unless @api['metadata']['protocol'] == 'api-gateway'
32-
# Dont reply on API Gateway doc.json
48+
49+
# computed attributes
50+
metadata = @api.fetch('metadata')
51+
@protocol = select_protocol(metadata)
52+
@protocol_settings = metadata['protocolSettings'] || {}
53+
@api_version = metadata['apiVersion']
54+
@signature_version = metadata['signatureVersion']
55+
@full_name = metadata['serviceFullName']
56+
@short_name = metadata['serviceAbbreviation'] || @full_name
57+
58+
# Dont reply on API Gateway doc.json
59+
unless @protocol == 'api-gateway'
3360
ApplyDocs.new(@api).apply(load_json(options[:docs]))
3461
end
3562
@paginators = load_json(options[:paginators])
3663
@waiters = load_json(options[:waiters])
3764
@resources = load_json(options[:resources])
3865
@examples = load_json(options[:examples])
39-
@smoke_tests = load_json(options[:smoke_tests])
4066
unless options[:legacy_endpoints]
4167
@endpoint_rules = load_json(options[:endpoint_rules])
4268
@endpoint_tests = load_json(options[:endpoint_tests])
4369
end
70+
@smoke_tests = load_json(options[:smoke_tests])
71+
4472
@gem_dependencies = options[:gem_dependencies] || {}
4573
@add_plugins = options[:add_plugins] || {}
4674
@remove_plugins = options[:remove_plugins] || []
75+
@deprecated = options[:deprecated] || false
76+
@default_endpoint = options[:default_endpoint] # APIG custom service only
4777
@endpoints_key = options.fetch(:endpoints_key, nil)
48-
# APIG custom service only
49-
@default_endpoint = options[:default_endpoint]
5078

51-
# computed attributes
52-
@protocol = api.fetch('metadata').fetch('protocol')
53-
@protocol_settings = api.fetch('metadata')['protocolSettings'] || {}
54-
@api_version = api.fetch('metadata')['apiVersion']
55-
@signature_version = api.fetch('metadata')['signatureVersion']
56-
@full_name = api.fetch('metadata')['serviceFullName']
57-
@short_name = api.fetch('metadata')['serviceAbbreviation'] || @full_name
58-
@require_endpoint_discovery = api.fetch('operations', []).any? do |_, o|
59-
o['endpointdiscovery'] && o['endpointdiscovery']['required']
60-
end
61-
@deprecated = options[:deprecated] || false
79+
@require_endpoint_discovery = endpoint_discovery_required?
6280
end
6381

6482
# @return [String] The service name, e.g. "S3"
@@ -129,6 +147,9 @@ def included_in_core?
129147
# @return [String] The service protocol, e.g. "json", "query", etc.
130148
attr_reader :protocol
131149

150+
# @return [Array<String>] The list of supported protocols
151+
attr_reader :protocols
152+
132153
# @return [Hash] The service protocol settings
133154
attr_reader :protocol_settings
134155

@@ -174,6 +195,29 @@ def inspect
174195

175196
private
176197

198+
def select_protocol(metadata)
199+
protocols = metadata.fetch('protocols', [metadata['protocol']])
200+
protocol = SUPPORTED_PROTOCOLS.find do |supported_protocol|
201+
if %w[json_1.0 json_1.1].include?(supported_protocol)
202+
supported_protocol, version = supported_protocol.split('_')
203+
end
204+
205+
if protocols.include?(supported_protocol) &&
206+
(version.nil? || version == metadata['jsonVersion'])
207+
return supported_protocol
208+
end
209+
end
210+
return protocol if protocol
211+
212+
raise "unsupported protocols `#{protocols.join(', ')}'"
213+
end
214+
215+
def endpoint_discovery_required?
216+
@api.fetch('operations', []).any? do |_, o|
217+
o['endpointdiscovery'] && o['endpointdiscovery']['required']
218+
end
219+
end
220+
177221
def load_json(value)
178222
case value
179223
when nil then nil

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/client_api_module.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,26 @@ class ClientApiModule < View
2727
SHAPE_KEYS = {
2828
# keep
2929
'flattened' => true,
30-
'timestampFormat' => true, # glacier api customization
30+
'timestampFormat' => true,
3131
'xmlNamespace' => true,
32-
'streaming' => true, # transfer-encoding
33-
'requiresLength' => true, # transfer-encoding
34-
'union' => false, # should remain false
32+
'streaming' => true,
33+
'requiresLength' => true,
34+
'union' => false, # handled separately - should remain false
3535
'document' => true,
3636
'jsonvalue' => true,
37-
'error' => true, # parsing customized error code in query protocol
38-
'locationName' => true, # to recognize xmlName defined on shape
37+
'error' => true,
38+
'locationName' => true,
39+
# ignore
3940
# event stream modeling
4041
'event' => false,
4142
'eventstream' => false,
4243
'eventheader' => false,
4344
'eventpayload' => false,
44-
# ignore
45+
'exceptionEvent' => false, # internal, exceptions cannot be events
46+
# other
4547
'synthetic' => false,
4648
'box' => false,
4749
'fault' => false,
48-
'exception_event' => false, # internal, exceptions cannot be events
4950
'deprecated' => false,
5051
'deprecatedMessage' => false,
5152
'type' => false,
@@ -68,7 +69,7 @@ class ClientApiModule < View
6869
}
6970

7071
METADATA_KEYS = {
71-
# keep all
72+
# keep
7273
'endpointPrefix' => true,
7374
'signatureVersion' => true,
7475
'auth' => true,
@@ -79,18 +80,18 @@ class ClientApiModule < View
7980
'targetPrefix' => true,
8081
'jsonVersion' => true,
8182
'errorPrefix' => true,
82-
'timestampFormat' => true, # glacier api customization
83+
'timestampFormat' => true,
8384
'xmlNamespace' => true,
84-
'protocolSettings' => {}, # current unused unless for h2 exclude
85+
'protocolSettings' => {},
8586
'serviceId' => true,
8687
'apiVersion' => true,
8788
'checksumFormat' => true,
8889
'globalEndpoint' => true,
8990
'serviceAbbreviation' => true,
9091
'uid' => true,
91-
'awsQueryCompatible' => true, # AwsQuery migration
92+
'awsQueryCompatible' => true,
9293
# ignore
93-
'ripServiceName' => true
94+
'ripServiceName' => false
9495
}
9596

9697
# @option options [required, Service] :service

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/rbs/types_module.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def structures
3131
# exceptions will not have the event trait.
3232
shape['members'].each do |name, ref|
3333
if !!@service.api['shapes'][ref['shape']]['exception']
34-
@service.api['shapes'][ref['shape']]['exception_event'] = true
34+
@service.api['shapes'][ref['shape']]['exceptionEvent'] = true
3535
end
3636
end
3737
end
@@ -90,7 +90,7 @@ def struct_members(shape)
9090
returns: AwsSdkCodeGenerator::RBS.to_type(member_ref, @api)
9191
)
9292
end
93-
if shape['event'] || shape['exception_event']
93+
if shape['event'] || shape['exceptionEvent']
9494
members << StructMember.new(
9595
member_name: 'event_type',
9696
returns: 'untyped'

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/types_module.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def structures
3434
# exceptions will not have the event trait.
3535
shape['members'].each do |name, ref|
3636
if !!@service.api['shapes'][ref['shape']]['exception']
37-
@service.api['shapes'][ref['shape']]['exception_event'] = true
37+
@service.api['shapes'][ref['shape']]['exceptionEvent'] = true
3838
end
3939
end
4040
end
@@ -92,7 +92,7 @@ def struct_members(shape)
9292
sensitive: sensitive
9393
)
9494
end
95-
if shape['event'] || shape['exception_event']
95+
if shape['event'] || shape['exceptionEvent']
9696
members << StructMember.new(member_name: 'event_type')
9797
end
9898
members
@@ -180,7 +180,7 @@ def attribute_macros_docs(shape_name)
180180

181181
def see_also_tag(shape_name)
182182
uid = @api['metadata']['uid']
183-
if @api['metadata']['protocol'] != 'api-gateway' && Crosslink.taggable?(uid)
183+
if @service.protocol != 'api-gateway' && Crosslink.taggable?(uid)
184184
Crosslink.tag_string(uid, shape_name)
185185
end
186186
end

0 commit comments

Comments
 (0)