From 1245723edb527084288b95bd0681ae31df464024 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Tue, 8 Jul 2025 14:24:26 -0400 Subject: [PATCH 01/10] Use plugins per protocol approach --- gems/smithy-client/lib/smithy-client.rb | 4 - .../smithy-client/plugins/param_converter.rb | 3 +- .../lib/smithy-client/plugins/protocol.rb | 66 -------------- .../lib/smithy-client/plugins/rpc_v2_cbor.rb | 21 +++++ .../smithy-client/plugins/stub_responses.rb | 2 + .../lib/smithy-client/response.rb | 22 ++++- .../lib/smithy-client/rpc_v2_cbor.rb | 12 +++ .../{response_parser.rb => error_handler.rb} | 37 ++++---- .../{request_builder.rb => handler.rb} | 31 ++++--- .../lib/smithy-client/rpc_v2_cbor/protocol.rb | 38 -------- .../lib/smithy-client/stubbing.rb | 2 +- .../smithy-client/stubbing/null_protocol.rb | 18 ++++ .../lib/smithy-client/stubbing/protocol.rb | 29 ------ .../rpc_v2_cbor.rb} | 15 +-- gems/smithy-client/lib/smithy-client/stubs.rb | 4 +- .../plugins/checksum_required_spec.rb | 16 +--- .../plugins/default_params_spec.rb | 14 +-- .../smithy-client/plugins/host_prefix_spec.rb | 15 +-- .../plugins/http_api_key_auth_spec.rb | 7 -- .../plugins/http_basic_auth_spec.rb | 7 -- .../plugins/http_bearer_auth_spec.rb | 7 -- .../plugins/http_digest_auth_spec.rb | 7 -- .../plugins/idempotency_token_spec.rb | 23 +---- .../smithy-client/plugins/logging_spec.rb | 21 ++--- .../smithy-client/plugins/net_http_spec.rb | 12 +-- .../plugins/pageable_response_spec.rb | 14 +-- .../plugins/param_converter_spec.rb | 2 - .../plugins/param_validator_spec.rb | 2 - .../smithy-client/plugins/protocol_spec.rb | 91 ------------------- .../plugins/raise_response_errors_spec.rb | 22 ++--- .../plugins/request_compression_spec.rb | 14 +-- .../plugins/resolve_auth_spec.rb | 17 +--- .../plugins/response_target_spec.rb | 2 - .../plugins/retry_errors_spec.rb | 18 +--- .../plugins/stub_responses_spec.rb | 16 +--- .../spec/smithy-client/waiters_spec.rb | 13 +-- .../lib/smithy/templates/client/client.erb | 5 - .../client/endpoint_provider_spec.erb | 12 +-- gems/smithy/lib/smithy/views/client/client.rb | 14 +-- gems/smithy/lib/smithy/weld.rb | 8 -- gems/smithy/lib/smithy/welds.rb | 7 +- .../welds/{plugins.rb => default_plugins.rb} | 4 +- .../lib/smithy/welds/protocols/rpc_v2_cbor.rb | 24 +++++ gems/smithy/lib/smithy/welds/rpc_v2_cbor.rb | 20 ---- .../spec/fixtures/no_protocol/model.json | 8 -- .../spec/fixtures/no_protocol/model.smithy | 5 - .../spec/fixtures/rpcv2_protocol/model.json | 58 ------------ .../spec/fixtures/rpcv2_protocol/model.smithy | 8 -- .../fixtures/rpcv2_protocol/smithy-build.json | 8 -- .../spec/fixtures/weld_protocol/model.json | 19 ---- .../spec/fixtures/weld_protocol/model.smithy | 10 -- .../spec/interfaces/client/client_spec.rb | 13 +-- .../interfaces/client/stub_responses_spec.rb | 4 +- .../spec/interfaces/welds/protocols_spec.rb | 53 ----------- 54 files changed, 195 insertions(+), 729 deletions(-) delete mode 100644 gems/smithy-client/lib/smithy-client/plugins/protocol.rb create mode 100644 gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb create mode 100644 gems/smithy-client/lib/smithy-client/rpc_v2_cbor.rb rename gems/smithy-client/lib/smithy-client/rpc_v2_cbor/{response_parser.rb => error_handler.rb} (61%) rename gems/smithy-client/lib/smithy-client/rpc_v2_cbor/{request_builder.rb => handler.rb} (71%) delete mode 100644 gems/smithy-client/lib/smithy-client/rpc_v2_cbor/protocol.rb create mode 100644 gems/smithy-client/lib/smithy-client/stubbing/null_protocol.rb delete mode 100644 gems/smithy-client/lib/smithy-client/stubbing/protocol.rb rename gems/smithy-client/lib/smithy-client/{rpc_v2_cbor/response_stubber.rb => stubbing/rpc_v2_cbor.rb} (65%) delete mode 100644 gems/smithy-client/spec/smithy-client/plugins/protocol_spec.rb rename gems/smithy/lib/smithy/welds/{plugins.rb => default_plugins.rb} (94%) create mode 100644 gems/smithy/lib/smithy/welds/protocols/rpc_v2_cbor.rb delete mode 100644 gems/smithy/lib/smithy/welds/rpc_v2_cbor.rb delete mode 100644 gems/smithy/spec/fixtures/no_protocol/model.json delete mode 100644 gems/smithy/spec/fixtures/no_protocol/model.smithy delete mode 100644 gems/smithy/spec/fixtures/rpcv2_protocol/model.json delete mode 100644 gems/smithy/spec/fixtures/rpcv2_protocol/model.smithy delete mode 100644 gems/smithy/spec/fixtures/rpcv2_protocol/smithy-build.json delete mode 100644 gems/smithy/spec/fixtures/weld_protocol/model.json delete mode 100644 gems/smithy/spec/fixtures/weld_protocol/model.smithy delete mode 100644 gems/smithy/spec/interfaces/welds/protocols_spec.rb diff --git a/gems/smithy-client/lib/smithy-client.rb b/gems/smithy-client/lib/smithy-client.rb index 33236bb8e..c85cea37b 100644 --- a/gems/smithy-client/lib/smithy-client.rb +++ b/gems/smithy-client/lib/smithy-client.rb @@ -52,10 +52,6 @@ require_relative 'smithy-client/identity' require_relative 'smithy-client/refreshing_identity_provider' -# protocols - -require_relative 'smithy-client/rpc_v2_cbor/protocol' - # stubbing require_relative 'smithy-client/stubs' diff --git a/gems/smithy-client/lib/smithy-client/plugins/param_converter.rb b/gems/smithy-client/lib/smithy-client/plugins/param_converter.rb index 9f2e812e3..6e6b37b70 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/param_converter.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/param_converter.rb @@ -22,8 +22,7 @@ class Handler < Client::Handler def call(context) converter = Client::ParamConverter.new(context.operation.input) context.params = converter.convert(context.params) - context.http_response.on_done { converter.close_opened_files } - @handler.call(context) + @handler.call(context).on_done { converter.close_opened_files } end end end diff --git a/gems/smithy-client/lib/smithy-client/plugins/protocol.rb b/gems/smithy-client/lib/smithy-client/plugins/protocol.rb deleted file mode 100644 index 4451434a7..000000000 --- a/gems/smithy-client/lib/smithy-client/plugins/protocol.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -module Smithy - module Client - module Plugins - # @api private - class Protocol < Plugin - option( - :protocol, - doc_default: '', - doc_type: 'String, Class', - docstring: 'The protocol to use for request serialization and response deserialization.' - ) - - # @api private - class BuildHandler < Handler - def call(context) - context.config.protocol.build_request(context) - @handler.call(context) - end - end - - # @api private - class ParseHandler < Handler - def call(context) - response = @handler.call(context) - response.error = context.config.protocol.parse_error(response) unless response.error - response.data = context.config.protocol.parse_data(response) unless response.error - response - end - end - - def add_handlers(handlers, _config) - handlers.add(BuildHandler) - handlers.add(ParseHandler, step: :parse) - end - - def before_initialize(client_class, options) - protocol = options[:protocol] - case protocol - when nil - resolve_default_protocol(client_class, options) - when String - protocol_class = client_class.protocols[protocol] - raise ArgumentError, "Unknown protocol: #{protocol}" unless protocol_class - - options[:protocol] = protocol_class.new - else - options[:protocol] = protocol - end - end - - private - - def resolve_default_protocol(client_class, options) - protocol_class = client_class.protocols.values.first - if protocol_class - options[:protocol] = protocol_class.new - elsif options[:stub_responses] - options[:protocol] = Stubbing::Protocol.new - end - end - end - end - end -end diff --git a/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb b/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb new file mode 100644 index 000000000..ea0b8b829 --- /dev/null +++ b/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require_relative '../rpc_v2_cbor' + +module Smithy + module Client + module Plugins + # @api private + class RpcV2Cbor < Plugin + # @api private + option(:cbor_codec) { CBOR::Codec.new } + + # @api private + option(:stubber) { Stubbing::RpcV2Cbor.new } + + handler(Client::RpcV2Cbor::Handler) + handler(Client::RpcV2Cbor::ErrorHandler, step: :sign) + end + end + end +end diff --git a/gems/smithy-client/lib/smithy-client/plugins/stub_responses.rb b/gems/smithy-client/lib/smithy-client/plugins/stub_responses.rb index cb7470847..ca3166f79 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/stub_responses.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/stub_responses.rb @@ -23,6 +23,8 @@ class StubResponses < Plugin option(:api_requests) { [] } # @api private option(:api_requests_mutex) { Mutex.new } + # @api private + option(:stubber) { Stubbing::NullProtocol.new } def add_handlers(handlers, config) return unless config.stub_responses diff --git a/gems/smithy-client/lib/smithy-client/response.rb b/gems/smithy-client/lib/smithy-client/response.rb index 8ca4d25ce..b6456fcbf 100644 --- a/gems/smithy-client/lib/smithy-client/response.rb +++ b/gems/smithy-client/lib/smithy-client/response.rb @@ -13,7 +13,9 @@ def initialize(options = {}) @context = options[:context] || HandlerContext.new @data = options[:data] @error = options[:error] - @context.http_response.on_error { |error| @error = error } + @http_request = @context.http_request + @http_response = @context.http_response + @http_response.on_error { |error| @error = error } super(@error || @data) end @@ -28,6 +30,24 @@ def initialize(options = {}) # operation. This will be `nil` if the operation was successful. attr_accessor :error + # @overload on_done(status_code, &block) + # @param [Integer] status_code The block will be + # triggered only for responses with the given status code. + # + # @overload on_done(status_code_range, &block) + # @param [Range] status_code_range The block will be + # triggered only for responses with a status code that falls + # within the given range. + # + # @return [self] + def on_done(range = nil, &) + response = self + @http_response.on_done(range) do + yield response + end + self + end + # Necessary to define as a subclass of Delegator # @api private def __getobj__(&) diff --git a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor.rb b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor.rb new file mode 100644 index 000000000..c2a16a601 --- /dev/null +++ b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Smithy + module Client + # @api private + module RpcV2Cbor; end + end +end + +require_relative 'rpc_v2_cbor/error_handler' +require_relative 'rpc_v2_cbor/handler' +require_relative 'stubbing/rpc_v2_cbor' diff --git a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/response_parser.rb b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/error_handler.rb similarity index 61% rename from gems/smithy-client/lib/smithy-client/rpc_v2_cbor/response_parser.rb rename to gems/smithy-client/lib/smithy-client/rpc_v2_cbor/error_handler.rb index d65aecb14..08467e992 100644 --- a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/response_parser.rb +++ b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/error_handler.rb @@ -2,34 +2,35 @@ module Smithy module Client - module RPCv2CBOR + module RpcV2Cbor # @api private - class ResponseParser - def initialize(options = {}) - @codec = CBOR::Codec.new(options) - end - - def parse_error(context) - if !valid_response?(context) - code, message, data = http_status_error(context) - build_error(context, code, message, data) - elsif (300..599).cover?(context.http_response.status_code) - error(context) + class ErrorHandler < Client::Handler + def call(context) + # Malformed responses should throw an http based error, so we check + # 200 range for error handling only for this case. + @handler.call(context).on_done(200..599) do |response| + if !valid_response?(context) + code, message, data = http_status_error(context) + response.error = build_error(context, code, message, data) + elsif (300..599).cover?(context.http_response.status_code) + response.error = error(context) + end end end - def parse_data(context) - @codec.deserialize(context.operation.output, context.http_response.body.read) - end - private def valid_response?(context) req_header = context.http_request.headers['smithy-protocol'] - resp_header = context.http_request.headers['smithy-protocol'] + resp_header = context.http_response.headers['smithy-protocol'] req_header == resp_header end + # TODO: Fix this + # This is not correct per protocol tests. Some headers will determine the error code. + # If the body is empty, there is still potentially an error code from the header, but + # we are making a generic http status error instead. In a new major version, we should + # always try to extract header, and during extraction, check headers and body. def error(context) body = context.http_response.body.read if body.empty? @@ -56,7 +57,7 @@ def parse_error_data(context, body, code) context.operation.errors.each do |ref| next unless ref.shape.id == code - data = @codec.deserialize(ref, body, ref.shape.type.new) + data = context.config.cbor_codec.deserialize(ref, body, ref.shape.type.new) end data end diff --git a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/request_builder.rb b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb similarity index 71% rename from gems/smithy-client/lib/smithy-client/rpc_v2_cbor/request_builder.rb rename to gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb index 12aa6096e..b343a08a6 100644 --- a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/request_builder.rb +++ b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb @@ -2,26 +2,27 @@ module Smithy module Client - module RPCv2CBOR + module RpcV2Cbor # @api private - class RequestBuilder - include Schema::Shapes - - def initialize(options = {}) - @codec = CBOR::Codec.new(options) + class Handler < Client::Handler + def call(context) + build_request(context) + response = @handler.call(context) + response.on_done(200..299) { |resp| resp.data = parse_body(context) } + response end - def build(context) - apply_http_method(context) + private + + def build_request(context) + context.http_request.http_method = 'POST' apply_headers(context) apply_body(context) apply_url_path(context) end - private - - def apply_http_method(context) - context.http_request.http_method = 'POST' + def parse_body(context) + context.config.cbor_codec.deserialize(context.operation.output, context.http_response.body.read) end def apply_headers(context) @@ -35,7 +36,7 @@ def apply_content_type_header(context) content_type = if event_stream?(input) 'application/vnd.amazon.eventstream' - elsif input.shape != Prelude::Unit + elsif input.shape != Schema::Shapes::Prelude::Unit 'application/cbor' end @@ -54,7 +55,7 @@ def apply_accept_header(context) end def apply_body(context) - context.http_request.body = @codec.serialize(context.operation.input, context.params) + context.http_request.body = context.config.cbor_codec.serialize(context.operation.input, context.params) end def apply_url_path(context) @@ -66,7 +67,7 @@ def apply_url_path(context) def event_stream?(ref) ref.shape.members.each_value do |member_ref| shape = member_ref.shape - return true if shape.traits.key?('smithy.api#streaming') && shape.is_a?(UnionShape) + return true if shape.traits.key?('smithy.api#streaming') && shape.is_a?(Schema::Shapes::UnionShape) end false end diff --git a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/protocol.rb b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/protocol.rb deleted file mode 100644 index 9cc96ae29..000000000 --- a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/protocol.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require_relative 'request_builder' -require_relative 'response_parser' -require_relative 'response_stubber' - -module Smithy - module Client - module RPCv2CBOR - # @api private - class Protocol - def initialize(options = {}) - @options = options - end - - def build_request(context) - RequestBuilder.new(@options).build(context) - end - - def parse_error(response) - ResponseParser.new(@options).parse_error(response.context) - end - - def parse_data(response) - ResponseParser.new(@options).parse_data(response.context) - end - - def stub_data(service, operation, data) - ResponseStubber.new(@options).stub_data(service, operation, data) - end - - def stub_error(service, error_code) - ResponseStubber.new(@options).stub_error(service, error_code) - end - end - end - end -end diff --git a/gems/smithy-client/lib/smithy-client/stubbing.rb b/gems/smithy-client/lib/smithy-client/stubbing.rb index 8e1c0c138..7e9b7d2f4 100644 --- a/gems/smithy-client/lib/smithy-client/stubbing.rb +++ b/gems/smithy-client/lib/smithy-client/stubbing.rb @@ -3,7 +3,7 @@ require_relative 'stubbing/data_applicator' require_relative 'stubbing/empty_stub' require_relative 'stubbing/endpoint_provider' -require_relative 'stubbing/protocol' +require_relative 'stubbing/null_protocol' require_relative 'stubbing/stub_data' module Smithy diff --git a/gems/smithy-client/lib/smithy-client/stubbing/null_protocol.rb b/gems/smithy-client/lib/smithy-client/stubbing/null_protocol.rb new file mode 100644 index 000000000..113d738ca --- /dev/null +++ b/gems/smithy-client/lib/smithy-client/stubbing/null_protocol.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Smithy + module Client + module Stubbing + # @api private + class NullProtocol + def stub_data(_config, _operation, _data) + HTTP::Response.new + end + + def stub_error(_config, _error_code) + HTTP::Response.new + end + end + end + end +end diff --git a/gems/smithy-client/lib/smithy-client/stubbing/protocol.rb b/gems/smithy-client/lib/smithy-client/stubbing/protocol.rb deleted file mode 100644 index 5bf04b158..000000000 --- a/gems/smithy-client/lib/smithy-client/stubbing/protocol.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module Smithy - module Client - module Stubbing - # Default protocol when stubbing is configured. - # @api private - class Protocol - def build_request(_context); end - def parse_data(_output); end - def parse_error(_output); end - - def stub_data(_service, _operation, data) - response = HTTP::Response.new - response.status_code = 200 - response.body = StringIO.new(data.to_json) - response - end - - def stub_error(_service, error_code) - response = HTTP::Response.new - response.status_code = 500 - response.body = StringIO.new(error_code.to_json) - response - end - end - end - end -end diff --git a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/response_stubber.rb b/gems/smithy-client/lib/smithy-client/stubbing/rpc_v2_cbor.rb similarity index 65% rename from gems/smithy-client/lib/smithy-client/rpc_v2_cbor/response_stubber.rb rename to gems/smithy-client/lib/smithy-client/stubbing/rpc_v2_cbor.rb index 869c6671c..d6fccec58 100644 --- a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/response_stubber.rb +++ b/gems/smithy-client/lib/smithy-client/stubbing/rpc_v2_cbor.rb @@ -2,28 +2,23 @@ module Smithy module Client - module RPCv2CBOR + module Stubbing # @api private - class ResponseStubber - def initialize(options = {}) - @codec = CBOR::Codec.new(options) - end - - def stub_data(_service, operation, data) + class RpcV2Cbor + def stub_data(config, operation, data) response = HTTP::Response.new response.status_code = 200 response.headers['Smithy-Protocol'] = 'rpc-v2-cbor' response.headers['Content-Type'] = 'application/cbor' - response.body = @codec.serialize(operation.output, data) + response.body = config.cbor_codec.serialize(operation.output, data) response end - def stub_error(_service, error_code) + def stub_error(_config, error_code) response = HTTP::Response.new response.status_code = 400 response.headers['Smithy-Protocol'] = 'rpc-v2-cbor' response.headers['Content-Type'] = 'application/cbor' - response.headers['X-Amzn-RequestId'] = 'stubbed-request-id' data = { '__type' => error_code, 'message' => 'stubbed-error-message' } response.body = CBOR.encode(data) response diff --git a/gems/smithy-client/lib/smithy-client/stubs.rb b/gems/smithy-client/lib/smithy-client/stubs.rb index 688078448..3ec648833 100644 --- a/gems/smithy-client/lib/smithy-client/stubs.rb +++ b/gems/smithy-client/lib/smithy-client/stubs.rb @@ -182,7 +182,7 @@ def convert_stub(operation_name, stub, context) end def service_error_stub(error_code) - { http: @config.protocol.stub_error(@config.service, error_code) } + { http: @config.stubber.stub_error(@config, error_code) } end def http_response_stub(operation_name, data) @@ -205,7 +205,7 @@ def data_to_http_response(operation_name, data) operation = @config.service.operation(operation_name) data = ParamConverter.new(operation.output).convert(data) ParamValidator.new(operation.output, validate_required: false).validate!(data, context: 'stub') - @config.protocol.stub_data(@config.service, operation, data) + @config.stubber.stub_data(@config, operation, data) end end end diff --git a/gems/smithy-client/spec/smithy-client/plugins/checksum_required_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/checksum_required_spec.rb index ead1c4514..7c196e756 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/checksum_required_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/checksum_required_spec.rb @@ -2,26 +2,13 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/checksum_required' - module Smithy module Client module Plugins describe ChecksumRequired do let(:shapes) { ClientHelper.sample_shapes } let(:sample_client) { ClientHelper.sample_client(shapes: shapes) } - - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) - client_class.add_plugin(ChecksumRequired) - client_class.add_plugin(Protocol) - client_class.add_plugin(ResolveAuth) - client_class.add_plugin(StubResponses) - client_class - end - + let(:client_class) { sample_client.const_get(:Client) } let(:client) { client_class.new(stub_responses: true) } before do @@ -47,7 +34,6 @@ module Plugins expect(context.http_request.headers['Authorization']).to be_nil method.call(context) end - client = client_class.new(stub_responses: true) client.operation(string: 'i am just a string') end end diff --git a/gems/smithy-client/spec/smithy-client/plugins/default_params_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/default_params_spec.rb index f1341c3da..62ca80680 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/default_params_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/default_params_spec.rb @@ -2,23 +2,13 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/default_params' - module Smithy module Client module Plugins describe ParamValidator do let(:sample_client) { ClientHelper.sample_client } - - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(DefaultParams) - client_class.add_plugin(DummySendPlugin) - client_class - end - - let(:client) { client_class.new } + let(:client_class) { sample_client.const_get(:Client) } + let(:client) { client_class.new(stub_responses: true) } it 'adds the handler' do expect(client.handlers).to include(DefaultParams::Handler) diff --git a/gems/smithy-client/spec/smithy-client/plugins/host_prefix_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/host_prefix_spec.rb index 3850cd397..2bdb38c0b 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/host_prefix_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/host_prefix_spec.rb @@ -2,25 +2,13 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/host_prefix' - module Smithy module Client module Plugins describe HostPrefix do let(:shapes) { ClientHelper.sample_shapes } let(:sample_client) { ClientHelper.sample_client(shapes: shapes) } - - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) - client_class.add_plugin(HostPrefix) - client_class.add_plugin(Protocol) - client_class.add_plugin(StubResponses) - client_class - end - + let(:client_class) { sample_client.const_get(:Client) } let(:client) { client_class.new(stub_responses: true) } it 'adds a :disable_host_prefix_injection option to config' do @@ -45,7 +33,6 @@ module Plugins it 'allows :disable_host_prefix_injection to be set via ENV' do ENV['DISABLE_HOST_PREFIX_INJECTION'] = 'true' - client = client_class.new expect(client.config.disable_host_prefix_injection).to be(true) end diff --git a/gems/smithy-client/spec/smithy-client/plugins/http_api_key_auth_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/http_api_key_auth_spec.rb index 059deeacb..bb4cfabfc 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/http_api_key_auth_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/http_api_key_auth_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/http_api_key_auth' - module Smithy module Client module Plugins @@ -13,12 +11,7 @@ module Plugins let(:client_class) do client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) client_class.add_plugin(HttpApiKeyAuth) - client_class.add_plugin(Protocol) - client_class.add_plugin(ResolveAuth) - client_class.add_plugin(StubResponses) client_class end diff --git a/gems/smithy-client/spec/smithy-client/plugins/http_basic_auth_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/http_basic_auth_spec.rb index c73106020..dbe356783 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/http_basic_auth_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/http_basic_auth_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/http_bearer_auth' - module Smithy module Client module Plugins @@ -13,12 +11,7 @@ module Plugins let(:client_class) do client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) client_class.add_plugin(HttpBasicAuth) - client_class.add_plugin(Protocol) - client_class.add_plugin(ResolveAuth) - client_class.add_plugin(StubResponses) client_class end diff --git a/gems/smithy-client/spec/smithy-client/plugins/http_bearer_auth_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/http_bearer_auth_spec.rb index ad0230c81..f0a332e16 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/http_bearer_auth_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/http_bearer_auth_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/http_bearer_auth' - module Smithy module Client module Plugins @@ -13,12 +11,7 @@ module Plugins let(:client_class) do client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) client_class.add_plugin(HttpBearerAuth) - client_class.add_plugin(Protocol) - client_class.add_plugin(ResolveAuth) - client_class.add_plugin(StubResponses) client_class end diff --git a/gems/smithy-client/spec/smithy-client/plugins/http_digest_auth_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/http_digest_auth_spec.rb index 8ede861c9..e1b3c2344 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/http_digest_auth_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/http_digest_auth_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/http_bearer_auth' - module Smithy module Client module Plugins @@ -13,12 +11,7 @@ module Plugins let(:client_class) do client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) client_class.add_plugin(HttpDigestAuth) - client_class.add_plugin(Protocol) - client_class.add_plugin(ResolveAuth) - client_class.add_plugin(StubResponses) client_class end diff --git a/gems/smithy-client/spec/smithy-client/plugins/idempotency_token_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/idempotency_token_spec.rb index e6d66dbe8..b8e74752f 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/idempotency_token_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/idempotency_token_spec.rb @@ -2,25 +2,13 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/idempotency_token' - module Smithy module Client module Plugins describe IdempotencyToken do let(:shapes) { ClientHelper.sample_shapes } let(:sample_client) { ClientHelper.sample_client(shapes: shapes) } - - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) - client_class.add_plugin(IdempotencyToken) - client_class.add_plugin(Protocol) - client_class.add_plugin(StubResponses) - client_class - end - + let(:client_class) { sample_client.const_get(:Client) } let(:client) { client_class.new(stub_responses: true) } before do @@ -45,15 +33,6 @@ module Plugins response = client.operation(string: 'existing_token') expect(response.context.params[:string]).to eq('existing_token') end - - it 'applies the idempotency token before building the request' do - expect(SecureRandom).to receive(:uuid).and_return('uuid') - expect_any_instance_of(Protocol::BuildHandler).to receive(:call).and_wrap_original do |method, context| - expect(context.params[:string]).to eq('uuid') - method.call(context) - end - client.operation - end end end end diff --git a/gems/smithy-client/spec/smithy-client/plugins/logging_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/logging_spec.rb index 3b6816347..79e12e5b7 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/logging_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/logging_spec.rb @@ -2,21 +2,14 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/logging' - module Smithy module Client module Plugins describe Logging do - let(:client_class) do - client_class = ClientHelper.sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(Logging) - client_class.add_plugin(DummySendPlugin) - client_class - end + let(:sample_client) { ClientHelper.sample_client } + let(:client_class) { sample_client.const_get(:Client) } + let(:client) { client_class.new(stub_responses: true) } - let(:client) { client_class.new } let(:logger) { Logger.new(IO::NULL) } let(:log_level) { :info } @@ -37,24 +30,24 @@ module Plugins end it 'adds the handler when a logger is provided' do - client = client_class.new(logger: logger) + client = client_class.new(stub_responses: true, logger: logger) expect(client.handlers).to include(Logging::Handler) end it 'logs the output to the log level' do - client = client_class.new(logger: logger) + client = client_class.new(stub_responses: true, logger: logger) expect(logger).to receive(client.config.log_level).with(instance_of(String)) client.operation end it 'logs the output using the log formatter' do - client = client_class.new(logger: logger) + client = client_class.new(stub_responses: true, logger: logger) expect(client.config.log_formatter).to receive(:format).with(instance_of(Response)) client.operation end it 'sets start and end times in the context' do - client = client_class.new(logger: logger, log_level: log_level) + client = client_class.new(stub_responses: true, logger: logger, log_level: log_level) response = client.operation expect(response.context[:logging_started_at]).to be_kind_of(Time) expect(response.context[:logging_completed_at]).to be_kind_of(Time) diff --git a/gems/smithy-client/spec/smithy-client/plugins/net_http_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/net_http_spec.rb index 02692c1d1..f76ebec82 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/net_http_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/net_http_spec.rb @@ -2,18 +2,13 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/net_http' - module Smithy module Client module Plugins describe NetHTTP do - let(:client_class) do - client_class = ClientHelper.sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(NetHTTP) - client_class - end + let(:sample_client) { ClientHelper.sample_client } + let(:client_class) { sample_client.const_get(:Client) } + let(:client) { client_class.new(stub_responses: true) } it 'adds net http options' do options = %i[ @@ -32,7 +27,6 @@ module Plugins http_debug_output http_proxy ] - client = client_class.new options.each do |option| expect(client.config).to respond_to(option) end diff --git a/gems/smithy-client/spec/smithy-client/plugins/pageable_response_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/pageable_response_spec.rb index 845ceb657..7815e829f 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/pageable_response_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/pageable_response_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/pageable_response' - module Smithy module Client module Plugins @@ -56,17 +54,7 @@ module Plugins end let(:sample_client) { ClientHelper.sample_client(shapes: shapes) } - - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) - client_class.add_plugin(Protocol) - client_class.add_plugin(PageableResponse) - client_class.add_plugin(StubResponses) - client_class - end - + let(:client_class) { sample_client.const_get(:Client) } let(:client) { client_class.new(stub_responses: true) } context 'pagination' do diff --git a/gems/smithy-client/spec/smithy-client/plugins/param_converter_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/param_converter_spec.rb index d334eafbb..093e7a861 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/param_converter_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/param_converter_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/param_converter' - module Smithy module Client module Plugins diff --git a/gems/smithy-client/spec/smithy-client/plugins/param_validator_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/param_validator_spec.rb index 31b6444f2..0d0c469aa 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/param_validator_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/param_validator_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/param_validator' - module Smithy module Client module Plugins diff --git a/gems/smithy-client/spec/smithy-client/plugins/protocol_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/protocol_spec.rb deleted file mode 100644 index 72ad88574..000000000 --- a/gems/smithy-client/spec/smithy-client/plugins/protocol_spec.rb +++ /dev/null @@ -1,91 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../spec_helper' - -require 'smithy-client/plugins/protocol' - -module Smithy - module Client - module Plugins - describe Protocol do - let(:sample_client) { ClientHelper.sample_client } - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) - client_class.add_plugin(Protocol) - client_class.add_plugin(StubResponses) - client_class - end - - let(:client) { client_class.new(stub_responses: true) } - - it 'adds a :protocol option to config' do - expect(client.config).to respond_to(:protocol) - end - - it 'defaults :protocol to the modeled protocol' do - client = client_class.new - expect(client.config.protocol).to be_a(client_class.protocols.values.first) - end - - it 'validates :protocol against available protocols when provided a string' do - expect { client_class.new(protocol: 'unknown') } - .to raise_error(ArgumentError, /Unknown protocol/) - end - - it 'will use any provided protocol object' do - protocol = double('protocol') - client = client_class.new(protocol: protocol) - expect(client.config.protocol).to be(protocol) - end - - it 'will use the stubbing protocol if :stub_responses is true and no protocol is available' do - expect(client_class).to receive(:protocols).and_return({}) - expect(client.config.protocol).to be_a(Stubbing::Protocol) - end - - it 'adds the build and parse handlers' do - expect(client.handlers).to include(Protocol::BuildHandler) - expect(client.handlers).to include(Protocol::ParseHandler) - end - - describe Protocol::BuildHandler do - it 'calls the protocol build_request method' do - client = client_class.new(stub_responses: true) - expect(client.config.protocol).to receive(:build_request).and_call_original - client.operation - end - end - - describe Protocol::ParseHandler do - it 'does not call parse_error if output has an error' do - client = client_class.new(stub_responses: true) - client.stub_responses(:operation, StandardError.new) - expect(client.config.protocol).not_to receive(:parse_error) - client.operation - end - - it 'calls parse_error if output does not have an error' do - client = client_class.new(stub_responses: true) - expect(client.config.protocol).to receive(:parse_error) - client.operation - end - - it 'does not call parse_data if an error was parsed' do - client = client_class.new(stub_responses: true) - client.stub_responses(:operation, sample_client::Errors::Error.new(nil, nil)) - expect(client.config.protocol).not_to receive(:parse_data) - client.operation - end - - it 'calls parse_data if no error was parsed' do - client = client_class.new(stub_responses: true) - expect(client.config.protocol).to receive(:parse_data) - client.operation - end - end - end - end - end -end diff --git a/gems/smithy-client/spec/smithy-client/plugins/raise_response_errors_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/raise_response_errors_spec.rb index ce40032b6..3c3586a88 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/raise_response_errors_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/raise_response_errors_spec.rb @@ -2,21 +2,13 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/raise_response_errors' - module Smithy module Client module Plugins describe RaiseResponseErrors do - let(:client_class) do - client_class = ClientHelper.sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(RaiseResponseErrors) - client_class.add_plugin(DummySendPlugin) - client_class - end - - let(:client) { client_class.new } + let(:sample_client) { ClientHelper.sample_client } + let(:client_class) { sample_client.const_get(:Client) } + let(:client) { client_class.new(stub_responses: true) } it 'adds a :raise_response_errors option to config' do expect(client.config).to respond_to(:raise_response_errors) @@ -42,16 +34,14 @@ module Plugins it 'raises the response error when :raise_response_errors is true' do error = StandardError.new('msg') - client = client_class.new(response_error: error) + client.stub_responses(:operation, error) expect { client.operation }.to raise_error(error) end it 'puts the error on the response when :raise_response_errors is false' do error = StandardError.new('msg') - client = client_class.new( - raise_response_errors: false, - response_error: error - ) + client = client_class.new(raise_response_errors: false, stub_responses: true) + client.stub_responses(:operation, error) response = client.operation expect(response.error).to be(error) end diff --git a/gems/smithy-client/spec/smithy-client/plugins/request_compression_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/request_compression_spec.rb index 12f0f9deb..760a5d0d9 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/request_compression_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/request_compression_spec.rb @@ -2,25 +2,13 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/request_compression' - module Smithy module Client module Plugins describe RequestCompression do let(:shapes) { ClientHelper.sample_shapes } let(:sample_client) { ClientHelper.sample_client(shapes: shapes) } - - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) - client_class.add_plugin(RequestCompression) - client_class.add_plugin(Protocol) - client_class.add_plugin(StubResponses) - client_class - end - + let(:client_class) { sample_client.const_get(:Client) } let(:client) { client_class.new(stub_responses: true) } it 'adds a :disable_request_compression option to config' do diff --git a/gems/smithy-client/spec/smithy-client/plugins/resolve_auth_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/resolve_auth_spec.rb index ac5a6fd3b..c7817c007 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/resolve_auth_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/resolve_auth_spec.rb @@ -2,25 +2,13 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/resolve_auth' - module Smithy module Client module Plugins describe ResolveAuth do let(:shapes) { ClientHelper.sample_shapes } let(:sample_client) { ClientHelper.sample_client(shapes: shapes) } - - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) - client_class.add_plugin(Protocol) - client_class.add_plugin(ResolveAuth) - client_class.add_plugin(StubResponses) - client_class - end - + let(:client_class) { sample_client.const_get(:Client) } let(:client) { client_class.new(stub_responses: true) } it 'adds an :auth_resolver option to config' do @@ -70,7 +58,6 @@ module Plugins it 'resolves auth for http digest auth' do shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpDigestAuth'] = {} client_class.add_plugin(HttpDigestAuth) - # TODO: update this once implemented expect { client.operation }.to raise_error(NotImplementedError) end @@ -99,7 +86,7 @@ def resolve(_) it 'raises an error when auth scheme is not enabled' do shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpApiKeyAuth'] = {} - # Skip adding HttpApiKeyAuth plugin to disable auth type + client_class.remove_plugin(HttpApiKeyAuth) expect { client.operation }.to raise_error(/was not enabled/) end diff --git a/gems/smithy-client/spec/smithy-client/plugins/response_target_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/response_target_spec.rb index 068eb8bb0..6cc392c18 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/response_target_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/response_target_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/response_target' - module Smithy module Client module Plugins diff --git a/gems/smithy-client/spec/smithy-client/plugins/retry_errors_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/retry_errors_spec.rb index f89fc87dc..a87dfc4e8 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/retry_errors_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/retry_errors_spec.rb @@ -3,23 +3,13 @@ require_relative '../../spec_helper' require_relative '../../support/retry_errors_helper' -require 'smithy-client/plugins/retry_errors' - module Smithy module Client module Plugins describe RetryErrors do let(:sample_client) { ClientHelper.sample_client } - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) - client_class.add_plugin(RetryErrors) - client_class.add_plugin(StubResponses) - client_class - end - - let(:client) { client_class.new } + let(:client_class) { sample_client.const_get(:Client) } + let(:client) { client_class.new(stub_responses: true) } it 'adds a :retry_strategy option to config' do expect(client.config).to respond_to(:retry_strategy) @@ -82,12 +72,12 @@ module Plugins expect(retry_strategy.wait_to_fill).to eq(5) end - it 'adds the handler' do + it 'adds the handler by default' do + client = client_class.new expect(client.handlers).to include(RetryErrors::Handler) end it 'does not add the handler if :stub_responses is enabled' do - client = client_class.new(stub_responses: true) expect(client.handlers).not_to include(RetryErrors::Handler) end diff --git a/gems/smithy-client/spec/smithy-client/plugins/stub_responses_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/stub_responses_spec.rb index 812133a7b..ae90154c0 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/stub_responses_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/stub_responses_spec.rb @@ -4,24 +4,12 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/stub_responses' - module Smithy module Client module Plugins describe StubResponses do let(:sample_client) { ClientHelper.sample_client } - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) - client_class.add_plugin(ParamConverter) - client_class.add_plugin(Protocol) - client_class.add_plugin(RaiseResponseErrors) - client_class.add_plugin(StubResponses) - client_class - end - + let(:client_class) { sample_client.const_get(:Client) } let(:client) { client_class.new(stub_responses: true) } it 'adds a :stub_responses option to config' do @@ -184,7 +172,7 @@ module Plugins end it 'can stub http hashes' do - headers = { 'header' => 'value' } + headers = { 'smithy-protocol' => 'rpc-v2-cbor' } body = Smithy::CBOR.encode({ 'string' => 'value' }) client.stub_responses(:operation, { status_code: 200, headers: headers, body: body }) response = client.operation diff --git a/gems/smithy-client/spec/smithy-client/waiters_spec.rb b/gems/smithy-client/spec/smithy-client/waiters_spec.rb index 2b2b7d200..781a362ba 100644 --- a/gems/smithy-client/spec/smithy-client/waiters_spec.rb +++ b/gems/smithy-client/spec/smithy-client/waiters_spec.rb @@ -55,18 +55,7 @@ module Client end let(:sample_client) { ClientHelper.sample_client(shapes: shapes) } - - let(:client_class) do - client_class = sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(sample_client::Plugins::Endpoint) - client_class.add_plugin(Plugins::Protocol) - client_class.add_plugin(Plugins::RaiseResponseErrors) - client_class.add_plugin(Plugins::StubResponses) - client_class - end - - let(:client) { client_class.new(stub_responses: true) } + let(:client) { sample_client.const_get(:Client).new(stub_responses: true) } before(:each) { allow_any_instance_of(Waiters::Waiter).to receive(:sleep) } diff --git a/gems/smithy/lib/smithy/templates/client/client.erb b/gems/smithy/lib/smithy/templates/client/client.erb index f81692b93..edfde738e 100644 --- a/gems/smithy/lib/smithy/templates/client/client.erb +++ b/gems/smithy/lib/smithy/templates/client/client.erb @@ -142,11 +142,6 @@ module <%= module_name %> def errors_module Errors end - - # @api private - def protocols - <%= protocols %> - end end end end diff --git a/gems/smithy/lib/smithy/templates/client/endpoint_provider_spec.erb b/gems/smithy/lib/smithy/templates/client/endpoint_provider_spec.erb index c3b016fdc..ad8d36506 100644 --- a/gems/smithy/lib/smithy/templates/client/endpoint_provider_spec.erb +++ b/gems/smithy/lib/smithy/templates/client/endpoint_provider_spec.erb @@ -52,15 +52,15 @@ module <%= module_name %> <% end -%> ) expected_uri = URI.parse(expected['endpoint']['url']) - expect(response.context.http_request.endpoint.to_s).to include(expected_uri.host) - expect(response.context.http_request.endpoint.to_s).to include(expected_uri.scheme) - expect(response.context.http_request.endpoint.to_s).to include(expected_uri.path) + actual_uri = response.context.http_request.endpoint + expect(actual_uri.host).to eq(expected_uri.host) + expect(actual_uri.scheme).to eq(expected_uri.scheme) + expect(actual_uri.path).to eq(expected_uri.path) + actual_headers = response.context.http_request.headers expected['endpoint'].fetch('headers', {}).each do |k,v| - expect(response.context.http_request.headers[k]).to eq(v) + expect(actual_headers[k]).to eq(v) end - - # TODO: expect auth <% end -%> end <% end -%> diff --git a/gems/smithy/lib/smithy/views/client/client.rb b/gems/smithy/lib/smithy/views/client/client.rb index b41965b76..50792e760 100644 --- a/gems/smithy/lib/smithy/views/client/client.rb +++ b/gems/smithy/lib/smithy/views/client/client.rb @@ -62,11 +62,6 @@ def gem_version @plan.gem_version end - # TODO: re-evaluate this approach - perhaps plugins should register protocol classes with options - def protocols - @protocols ||= @plan.welds.map(&:protocols).reduce({}, :merge) - end - def waiters waiters = Views::Client::Waiters.new(@plan).waiters return ['{}'] if waiters.empty? @@ -95,18 +90,11 @@ def option_tag(option) tag << '@option options' tag << " [#{option.doc_type}]" if option.doc_type tag << " :#{option.name}" - default = option_default(option) + default = option.doc_default || option.default tag << " (#{default})" if default tag.string end - def option_default(option) - default = option.doc_default || option.default - return default unless option.name == :protocol - - default.gsub('', protocols.keys.first || 'nil') - end - # @api private class Operation def initialize(service, model, id, operation) diff --git a/gems/smithy/lib/smithy/weld.rb b/gems/smithy/lib/smithy/weld.rb index a7057d3ab..9a5d33ce0 100644 --- a/gems/smithy/lib/smithy/weld.rb +++ b/gems/smithy/lib/smithy/weld.rb @@ -83,14 +83,6 @@ def remove_plugins [] end - # Called when resolving the available protocols for the client. The key is the - # protocol's configuration name, typically the shape ID, and the value is a class - # that will be initialized. The first protocol in the hash will be the default protocol. - # @return [Hash] protocols - def protocols - {} - end - # Called when creating the auth resolver and auth schemes. The value is the # absolute shape id of the auth scheme trait. def add_auth_schemes diff --git a/gems/smithy/lib/smithy/welds.rb b/gems/smithy/lib/smithy/welds.rb index 5dcfb9c04..d565190fb 100644 --- a/gems/smithy/lib/smithy/welds.rb +++ b/gems/smithy/lib/smithy/welds.rb @@ -5,11 +5,14 @@ require_relative 'welds/auth/http_bearer_auth' require_relative 'welds/auth/http_digest_auth' +require_relative 'welds/protocols/rpc_v2_cbor' + require_relative 'welds/transforms/endpoints' require_relative 'welds/transforms/synthetic_input_output' -require_relative 'welds/plugins' -require_relative 'welds/rpc_v2_cbor' +require_relative 'welds/default_plugins' + +# Disabled due to performance # require_relative 'welds/rubocop' module Smithy diff --git a/gems/smithy/lib/smithy/welds/plugins.rb b/gems/smithy/lib/smithy/welds/default_plugins.rb similarity index 94% rename from gems/smithy/lib/smithy/welds/plugins.rb rename to gems/smithy/lib/smithy/welds/default_plugins.rb index 6ecc8e1fa..95ab5d857 100644 --- a/gems/smithy/lib/smithy/welds/plugins.rb +++ b/gems/smithy/lib/smithy/welds/default_plugins.rb @@ -10,7 +10,6 @@ require 'smithy-client/plugins/pageable_response' require 'smithy-client/plugins/param_converter' require 'smithy-client/plugins/param_validator' -require 'smithy-client/plugins/protocol' require 'smithy-client/plugins/raise_response_errors' require 'smithy-client/plugins/request_compression' require 'smithy-client/plugins/resolve_auth' @@ -21,7 +20,7 @@ module Smithy module Welds # Provides default plugins. - class Plugins < Weld + class DefaultPlugins < Weld def for?(_service) say_status :insert, 'Adding default plugins', :yellow unless @plan.quiet true @@ -40,7 +39,6 @@ def add_plugins Smithy::Client::Plugins::PageableResponse => { require_path: "#{base_path}/pageable_response" }, Smithy::Client::Plugins::ParamConverter => { require_path: "#{base_path}/param_converter" }, Smithy::Client::Plugins::ParamValidator => { require_path: "#{base_path}/param_validator" }, - Smithy::Client::Plugins::Protocol => { require_path: "#{base_path}/protocol" }, Smithy::Client::Plugins::RaiseResponseErrors => { require_path: "#{base_path}/raise_response_errors" }, Smithy::Client::Plugins::RequestCompression => { require_path: "#{base_path}/request_compression" }, Smithy::Client::Plugins::ResolveAuth => { require_path: "#{base_path}/resolve_auth" }, diff --git a/gems/smithy/lib/smithy/welds/protocols/rpc_v2_cbor.rb b/gems/smithy/lib/smithy/welds/protocols/rpc_v2_cbor.rb new file mode 100644 index 000000000..499029aee --- /dev/null +++ b/gems/smithy/lib/smithy/welds/protocols/rpc_v2_cbor.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require 'smithy-client/plugins/rpc_v2_cbor' + +module Smithy + module Welds + module Protocols + # Adds the rpcv2Cbor protocol to the client if the service has the trait. + class RpcV2Cbor < Weld + def for?(service) + _, service = service.first + return false unless service.fetch('traits', {}).key?('smithy.protocols#rpcv2Cbor') + + say_status :insert, 'Adding the RpcV2Cbor protocol plugin', :yellow unless @plan.quiet + true + end + + def add_plugins + { Smithy::Client::Plugins::RpcV2Cbor => { require_path: 'smithy-client/plugins/rpc_v2_cbor' } } + end + end + end + end +end diff --git a/gems/smithy/lib/smithy/welds/rpc_v2_cbor.rb b/gems/smithy/lib/smithy/welds/rpc_v2_cbor.rb deleted file mode 100644 index 765683151..000000000 --- a/gems/smithy/lib/smithy/welds/rpc_v2_cbor.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module Smithy - module Welds - # Adds the RPCv2 CBOR protocol to the client if the service has the trait. - class RPCv2CBOR < Weld - def for?(service) - _, service = service.first - return false unless service.fetch('traits', {}).key?('smithy.protocols#rpcv2Cbor') - - say_status :insert, 'Adding the RPCv2 CBOR protocol', :yellow unless @plan.quiet - true - end - - def protocols - { 'rpcv2Cbor' => Smithy::Client::RPCv2CBOR::Protocol } - end - end - end -end diff --git a/gems/smithy/spec/fixtures/no_protocol/model.json b/gems/smithy/spec/fixtures/no_protocol/model.json deleted file mode 100644 index 6803eb6e8..000000000 --- a/gems/smithy/spec/fixtures/no_protocol/model.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "smithy": "2.0", - "shapes": { - "smithy.ruby.tests#NoProtocolService": { - "type": "service" - } - } -} diff --git a/gems/smithy/spec/fixtures/no_protocol/model.smithy b/gems/smithy/spec/fixtures/no_protocol/model.smithy deleted file mode 100644 index 54afe9079..000000000 --- a/gems/smithy/spec/fixtures/no_protocol/model.smithy +++ /dev/null @@ -1,5 +0,0 @@ -$version: "2" - -namespace smithy.ruby.tests - -service NoProtocolService {} diff --git a/gems/smithy/spec/fixtures/rpcv2_protocol/model.json b/gems/smithy/spec/fixtures/rpcv2_protocol/model.json deleted file mode 100644 index 238b79596..000000000 --- a/gems/smithy/spec/fixtures/rpcv2_protocol/model.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "smithy": "2.0", - "shapes": { - "smithy.protocols#StringList": { - "type": "list", - "member": { - "target": "smithy.api#String" - }, - "traits": { - "smithy.api#documentation": "A list of String shapes.", - "smithy.api#private": {} - } - }, - "smithy.protocols#rpcv2Cbor": { - "type": "structure", - "members": { - "http": { - "target": "smithy.protocols#StringList", - "traits": { - "smithy.api#documentation": "Priority ordered list of supported HTTP protocol versions." - } - }, - "eventStreamHttp": { - "target": "smithy.protocols#StringList", - "traits": { - "smithy.api#documentation": "Priority ordered list of supported HTTP protocol versions\nthat are required when using event streams." - } - } - }, - "traits": { - "smithy.api#documentation": "An RPC-based protocol that serializes CBOR payloads.", - "smithy.api#protocolDefinition": { - "traits": [ - "smithy.api#cors", - "smithy.api#endpoint", - "smithy.api#hostLabel", - "smithy.api#httpError" - ] - }, - "smithy.api#trait": { - "selector": "service" - }, - "smithy.api#traitValidators": { - "rpcv2Cbor.NoDocuments": { - "selector": "service ~> member :test(> document)", - "message": "This protocol does not support document types" - } - } - } - }, - "smithy.ruby.tests#Rpcv2CborService": { - "type": "service", - "traits": { - "smithy.protocols#rpcv2Cbor": {} - } - } - } -} diff --git a/gems/smithy/spec/fixtures/rpcv2_protocol/model.smithy b/gems/smithy/spec/fixtures/rpcv2_protocol/model.smithy deleted file mode 100644 index bbd935aa7..000000000 --- a/gems/smithy/spec/fixtures/rpcv2_protocol/model.smithy +++ /dev/null @@ -1,8 +0,0 @@ -$version: "2" - -namespace smithy.ruby.tests - -use smithy.protocols#rpcv2Cbor - -@rpcv2Cbor -service Rpcv2CborService {} diff --git a/gems/smithy/spec/fixtures/rpcv2_protocol/smithy-build.json b/gems/smithy/spec/fixtures/rpcv2_protocol/smithy-build.json deleted file mode 100644 index ec730b598..000000000 --- a/gems/smithy/spec/fixtures/rpcv2_protocol/smithy-build.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": "1.0", - "maven": { - "dependencies": [ - "software.amazon.smithy:smithy-protocol-traits:1.56.0" - ] - } -} \ No newline at end of file diff --git a/gems/smithy/spec/fixtures/weld_protocol/model.json b/gems/smithy/spec/fixtures/weld_protocol/model.json deleted file mode 100644 index faf1eb9a0..000000000 --- a/gems/smithy/spec/fixtures/weld_protocol/model.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "smithy": "2.0", - "shapes": { - "smithy.ruby.tests#WeldProtocolService": { - "type": "service", - "traits": { - "smithy.ruby.tests#weldProtocol": {} - } - }, - "smithy.ruby.tests#weldProtocol": { - "type": "structure", - "members": {}, - "traits": { - "smithy.api#protocolDefinition": {}, - "smithy.api#trait": {} - } - } - } -} diff --git a/gems/smithy/spec/fixtures/weld_protocol/model.smithy b/gems/smithy/spec/fixtures/weld_protocol/model.smithy deleted file mode 100644 index ed89390c3..000000000 --- a/gems/smithy/spec/fixtures/weld_protocol/model.smithy +++ /dev/null @@ -1,10 +0,0 @@ -$version: "2" - -namespace smithy.ruby.tests - -@trait -@protocolDefinition -structure weldProtocol {} - -@weldProtocol -service WeldProtocolService {} diff --git a/gems/smithy/spec/interfaces/client/client_spec.rb b/gems/smithy/spec/interfaces/client/client_spec.rb index a2f549682..ad457a6a3 100644 --- a/gems/smithy/spec/interfaces/client/client_spec.rb +++ b/gems/smithy/spec/interfaces/client/client_spec.rb @@ -10,7 +10,7 @@ subject { Weather::Client.new(stub_responses: true) } it 'loads default plugins' do - expect(Weather::Client.plugins).to include(*Smithy::Welds::Plugins.new(@plan).add_plugins.keys) + expect(Weather::Client.plugins).to include(*Smithy::Welds::DefaultPlugins.new(@plan).add_plugins.keys) end it 'responds to each operation name' do @@ -19,9 +19,10 @@ end end - it 'builds and sends a request when it receives a request method' do - expect(subject).to receive(:build_request).with(:get_city, { city_id: '1' }).and_call_original - expect_any_instance_of(Smithy::Client::Request).to receive(:send_request).and_call_original + it 'builds and sends a request when it receives an operation method' do + request = double('request') + expect(subject).to receive(:build_request).with(:get_city, { city_id: '1' }).and_return(request) + expect(request).to receive(:send_request) subject.get_city(city_id: '1') end @@ -38,10 +39,6 @@ # end # expect(chunks).to eq(%w[chunk1 chunk2 chunk3]) # end - - it 'can call operations' do - subject.get_city(city_id: '1') - end end end diff --git a/gems/smithy/spec/interfaces/client/stub_responses_spec.rb b/gems/smithy/spec/interfaces/client/stub_responses_spec.rb index 4a193ba7e..b58c2242a 100644 --- a/gems/smithy/spec/interfaces/client/stub_responses_spec.rb +++ b/gems/smithy/spec/interfaces/client/stub_responses_spec.rb @@ -35,12 +35,14 @@ } end + before(:all) { Shapes::Client.add_plugin(Smithy::Client::Plugins::RpcV2Cbor) } + before do allow(Time).to receive(:now).and_return(now) allow(Time).to receive(:at).and_return(now) end - subject { Shapes::Client.new(stub_responses: true, protocol: Smithy::Client::RPCv2CBOR::Protocol.new) } + subject { Shapes::Client.new(stub_responses: true) } describe '#stub_data' do it 'returns the correct type' do diff --git a/gems/smithy/spec/interfaces/welds/protocols_spec.rb b/gems/smithy/spec/interfaces/welds/protocols_spec.rb deleted file mode 100644 index 231e4f8f0..000000000 --- a/gems/smithy/spec/interfaces/welds/protocols_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../spec_helper' - -describe 'Welds: Protocols' do - before(:all) do - Object.const_set(:Protocol, Class.new) - - Class.new(Smithy::Weld) do - def for?(service) - service.keys.first == 'smithy.ruby.tests#WeldProtocolService' - end - - def protocols - { 'rpcv2Cbor' => Smithy::Client::RPCv2CBOR::Protocol, 'other' => Protocol } - end - end - end - - ['generated client gem', 'generated client from source code'].each do |context| - context 'no protocol' do - include_context context, 'NoProtocol' - - it 'does not have a protocol config' do - client = NoProtocol::Client.new - expect(client.config.protocol).to be_nil - end - end - - context 'modeled protocol' do - include_context context, 'Rpcv2Protocol' - - it 'defaults to the rpcv2Cbor protocol' do - client = Rpcv2Protocol::Client.new - expect(client.config.protocol).to be_a(Smithy::Client::RPCv2CBOR::Protocol) - end - end - - context 'welded protocol' do - include_context context, 'WeldProtocol' - - it 'defaults to the first protocol' do - client = WeldProtocol::Client.new - expect(client.config.protocol).to be_a(Smithy::Client::RPCv2CBOR::Protocol) - end - - it 'can be configured to use a supported protocol' do - client = WeldProtocol::Client.new(protocol: 'other') - expect(client.config.protocol).to be_a(Protocol) - end - end - end -end From dff6ac112d449b994d4120b05776cc8a385328e2 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Tue, 8 Jul 2025 14:38:06 -0400 Subject: [PATCH 02/10] Add listener test --- .../spec/smithy-client/response_spec.rb | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/gems/smithy-client/spec/smithy-client/response_spec.rb b/gems/smithy-client/spec/smithy-client/response_spec.rb index f430dd544..19b24e3ae 100644 --- a/gems/smithy-client/spec/smithy-client/response_spec.rb +++ b/gems/smithy-client/spec/smithy-client/response_spec.rb @@ -53,6 +53,14 @@ module Client end end + describe '#context' do + it 'returns the context' do + context = HandlerContext.new + response = Response.new(context: context) + expect(response.context).to be(context) + end + end + describe '#data' do it 'returns the data' do data = double('data') @@ -67,13 +75,30 @@ module Client subject.error = error expect(subject.error).to be(error) end + + it 'sets error using the http response listener' do + http_response = HTTP::Response.new + response = Response.new(context: HandlerContext.new(http_response: http_response)) + error = StandardError.new + http_response.signal_error(error) + expect(response.error).to be(error) + end end - describe '#context' do - it 'returns the context' do - context = HandlerContext.new - response = Response.new(context: context) - expect(response.context).to be(context) + describe '#on_done' do + it 'returns and yields self when done' do + http_response = HTTP::Response.new + response = Response.new(context: HandlerContext.new(http_response: http_response)) + yielded = false + + resp = response.on_done(200..299) do |resp| + expect(resp).to be(response) + yielded = true + end + http_response.signal_done(status_code: 200, headers: {}, body: '') + + expect(resp).to be(response) + expect(yielded).to be(true) end end end From 5a2ce9f15ee37dc9d6c369341a27491f5c6aa047 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 11 Jul 2025 11:15:10 -0400 Subject: [PATCH 03/10] Singular protocols weld --- .../lib/smithy-client/plugins/rpc_v2_cbor.rb | 3 +-- .../lib/smithy-client/rpc_v2_cbor/handler.rb | 2 +- .../lib/smithy-client/stubbing/rpc_v2_cbor.rb | 2 +- gems/smithy/lib/smithy/welds.rb | 3 +-- gems/smithy/lib/smithy/welds/protocols.rb | 26 +++++++++++++++++++ .../lib/smithy/welds/protocols/rpc_v2_cbor.rb | 24 ----------------- 6 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 gems/smithy/lib/smithy/welds/protocols.rb delete mode 100644 gems/smithy/lib/smithy/welds/protocols/rpc_v2_cbor.rb diff --git a/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb b/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb index ea0b8b829..0c3bdc189 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb @@ -8,8 +8,7 @@ module Plugins # @api private class RpcV2Cbor < Plugin # @api private - option(:cbor_codec) { CBOR::Codec.new } - + option(:codec) { CBOR::Codec.new } # @api private option(:stubber) { Stubbing::RpcV2Cbor.new } diff --git a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb index b343a08a6..ac93ffaff 100644 --- a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb +++ b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb @@ -22,7 +22,7 @@ def build_request(context) end def parse_body(context) - context.config.cbor_codec.deserialize(context.operation.output, context.http_response.body.read) + context.config.codec.deserialize(context.operation.output, context.http_response.body.read) end def apply_headers(context) diff --git a/gems/smithy-client/lib/smithy-client/stubbing/rpc_v2_cbor.rb b/gems/smithy-client/lib/smithy-client/stubbing/rpc_v2_cbor.rb index d6fccec58..26394ff5e 100644 --- a/gems/smithy-client/lib/smithy-client/stubbing/rpc_v2_cbor.rb +++ b/gems/smithy-client/lib/smithy-client/stubbing/rpc_v2_cbor.rb @@ -10,7 +10,7 @@ def stub_data(config, operation, data) response.status_code = 200 response.headers['Smithy-Protocol'] = 'rpc-v2-cbor' response.headers['Content-Type'] = 'application/cbor' - response.body = config.cbor_codec.serialize(operation.output, data) + response.body = config.codec.serialize(operation.output, data) response end diff --git a/gems/smithy/lib/smithy/welds.rb b/gems/smithy/lib/smithy/welds.rb index d565190fb..1883c1e12 100644 --- a/gems/smithy/lib/smithy/welds.rb +++ b/gems/smithy/lib/smithy/welds.rb @@ -5,12 +5,11 @@ require_relative 'welds/auth/http_bearer_auth' require_relative 'welds/auth/http_digest_auth' -require_relative 'welds/protocols/rpc_v2_cbor' - require_relative 'welds/transforms/endpoints' require_relative 'welds/transforms/synthetic_input_output' require_relative 'welds/default_plugins' +require_relative 'welds/protocols' # Disabled due to performance # require_relative 'welds/rubocop' diff --git a/gems/smithy/lib/smithy/welds/protocols.rb b/gems/smithy/lib/smithy/welds/protocols.rb new file mode 100644 index 000000000..d12ee0bdc --- /dev/null +++ b/gems/smithy/lib/smithy/welds/protocols.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'smithy-client/plugins/rpc_v2_cbor' + +module Smithy + module Welds + # Adds any supported protocol plugins to the client if the service has the traits. + class Protocols < Weld + def add_plugins + service_traits = @plan.service.fetch('traits', {}) + plugins = {} + rpc_v2_cbor(service_traits, plugins) + plugins + end + + private + + def rpc_v2_cbor(traits, plugins) + return unless traits.key?('smithy.protocols#rpcv2Cbor') + + say_status :insert, 'Adding the rpcv2Cbor protocol plugin', :yellow unless @plan.quiet + plugins[Smithy::Client::Plugins::RpcV2Cbor] = { require_path: 'smithy-client/plugins/rpc_v2_cbor' } + end + end + end +end diff --git a/gems/smithy/lib/smithy/welds/protocols/rpc_v2_cbor.rb b/gems/smithy/lib/smithy/welds/protocols/rpc_v2_cbor.rb deleted file mode 100644 index 499029aee..000000000 --- a/gems/smithy/lib/smithy/welds/protocols/rpc_v2_cbor.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -require 'smithy-client/plugins/rpc_v2_cbor' - -module Smithy - module Welds - module Protocols - # Adds the rpcv2Cbor protocol to the client if the service has the trait. - class RpcV2Cbor < Weld - def for?(service) - _, service = service.first - return false unless service.fetch('traits', {}).key?('smithy.protocols#rpcv2Cbor') - - say_status :insert, 'Adding the RpcV2Cbor protocol plugin', :yellow unless @plan.quiet - true - end - - def add_plugins - { Smithy::Client::Plugins::RpcV2Cbor => { require_path: 'smithy-client/plugins/rpc_v2_cbor' } } - end - end - end - end -end From 61ac1e6652494541b4f2c41c53d6485ab090a452 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 11 Jul 2025 11:19:04 -0400 Subject: [PATCH 04/10] Regenerate --- projections/shapes/lib/shapes/client.rb | 9 --------- projections/shapes/sig/shapes/client.rbs | 1 - projections/weather/lib/weather/client.rb | 9 --------- projections/weather/sig/weather/client.rbs | 1 - 4 files changed, 20 deletions(-) diff --git a/projections/shapes/lib/shapes/client.rb b/projections/shapes/lib/shapes/client.rb index 13d353430..6d4a334c0 100644 --- a/projections/shapes/lib/shapes/client.rb +++ b/projections/shapes/lib/shapes/client.rb @@ -13,7 +13,6 @@ require 'smithy-client/plugins/pageable_response' require 'smithy-client/plugins/param_converter' require 'smithy-client/plugins/param_validator' -require 'smithy-client/plugins/protocol' require 'smithy-client/plugins/raise_response_errors' require 'smithy-client/plugins/request_compression' require 'smithy-client/plugins/resolve_auth' @@ -41,7 +40,6 @@ class Client < Smithy::Client::Base add_plugin(Smithy::Client::Plugins::PageableResponse) add_plugin(Smithy::Client::Plugins::ParamConverter) add_plugin(Smithy::Client::Plugins::ParamValidator) - add_plugin(Smithy::Client::Plugins::Protocol) add_plugin(Smithy::Client::Plugins::RaiseResponseErrors) add_plugin(Smithy::Client::Plugins::RequestCompression) add_plugin(Smithy::Client::Plugins::ResolveAuth) @@ -129,8 +127,6 @@ class Client < Smithy::Client::Base # The log level to send messages to the logger at. # @option options [Logger] :logger # The Logger instance to send log messages to. If this option is not set, logging is disabled. - # @option options [String, Class] :protocol (nil) - # The protocol to use for request serialization and response deserialization. # @option options [Boolean] :raise_response_errors (true) # When `true`, response errors are raised. When `false`, the error is placed on the # output in the {Smithy::Client::Response#error error accessor}. @@ -371,11 +367,6 @@ def auth_resolver def errors_module Errors end - - # @api private - def protocols - {} - end end end end diff --git a/projections/shapes/sig/shapes/client.rbs b/projections/shapes/sig/shapes/client.rbs index ec08f21b4..fd1846d16 100644 --- a/projections/shapes/sig/shapes/client.rbs +++ b/projections/shapes/sig/shapes/client.rbs @@ -27,7 +27,6 @@ module ShapeService ?log_formatter: Smithy::Client::LogFormatter, ?log_level: Symbol, ?logger: Logger, - ?protocol: String | Class, ?raise_response_errors: bool, ?request_min_compression_size_bytes: Integer, ?retry_backoff: lambda, diff --git a/projections/weather/lib/weather/client.rb b/projections/weather/lib/weather/client.rb index b2d2c06a4..5f6531af5 100644 --- a/projections/weather/lib/weather/client.rb +++ b/projections/weather/lib/weather/client.rb @@ -13,7 +13,6 @@ require 'smithy-client/plugins/pageable_response' require 'smithy-client/plugins/param_converter' require 'smithy-client/plugins/param_validator' -require 'smithy-client/plugins/protocol' require 'smithy-client/plugins/raise_response_errors' require 'smithy-client/plugins/request_compression' require 'smithy-client/plugins/resolve_auth' @@ -41,7 +40,6 @@ class Client < Smithy::Client::Base add_plugin(Smithy::Client::Plugins::PageableResponse) add_plugin(Smithy::Client::Plugins::ParamConverter) add_plugin(Smithy::Client::Plugins::ParamValidator) - add_plugin(Smithy::Client::Plugins::Protocol) add_plugin(Smithy::Client::Plugins::RaiseResponseErrors) add_plugin(Smithy::Client::Plugins::RequestCompression) add_plugin(Smithy::Client::Plugins::ResolveAuth) @@ -129,8 +127,6 @@ class Client < Smithy::Client::Base # The log level to send messages to the logger at. # @option options [Logger] :logger # The Logger instance to send log messages to. If this option is not set, logging is disabled. - # @option options [String, Class] :protocol (nil) - # The protocol to use for request serialization and response deserialization. # @option options [Boolean] :raise_response_errors (true) # When `true`, response errors are raised. When `false`, the error is placed on the # output in the {Smithy::Client::Response#error error accessor}. @@ -361,11 +357,6 @@ def auth_resolver def errors_module Errors end - - # @api private - def protocols - {} - end end end end diff --git a/projections/weather/sig/weather/client.rbs b/projections/weather/sig/weather/client.rbs index 79293ecdc..7eedfa32e 100644 --- a/projections/weather/sig/weather/client.rbs +++ b/projections/weather/sig/weather/client.rbs @@ -27,7 +27,6 @@ module Weather ?log_formatter: Smithy::Client::LogFormatter, ?log_level: Symbol, ?logger: Logger, - ?protocol: String | Class, ?raise_response_errors: bool, ?request_min_compression_size_bytes: Integer, ?retry_backoff: lambda, From ef73fd60f70855572d961e4ff205ce5087efbbc5 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 11 Jul 2025 11:52:26 -0400 Subject: [PATCH 05/10] Keep weld order and make protocol registration a priority list --- .../rpc_v2_cbor/error_handler.rb | 2 +- .../lib/smithy-client/rpc_v2_cbor/handler.rb | 2 +- gems/smithy-client/lib/smithy-client/stubs.rb | 8 +++--- gems/smithy-client/spec/spec_helper.rb | 1 + .../lib/smithy/views/client/plugin_list.rb | 25 ++++++++--------- gems/smithy/lib/smithy/welds.rb | 2 +- gems/smithy/lib/smithy/welds/protocols.rb | 28 ++++++++++++------- 7 files changed, 38 insertions(+), 30 deletions(-) diff --git a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/error_handler.rb b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/error_handler.rb index 08467e992..0852e89f8 100644 --- a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/error_handler.rb +++ b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/error_handler.rb @@ -57,7 +57,7 @@ def parse_error_data(context, body, code) context.operation.errors.each do |ref| next unless ref.shape.id == code - data = context.config.cbor_codec.deserialize(ref, body, ref.shape.type.new) + data = context.config.codec.deserialize(ref, body, ref.shape.type.new) end data end diff --git a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb index ac93ffaff..45abb038a 100644 --- a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb +++ b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor/handler.rb @@ -55,7 +55,7 @@ def apply_accept_header(context) end def apply_body(context) - context.http_request.body = context.config.cbor_codec.serialize(context.operation.input, context.params) + context.http_request.body = context.config.codec.serialize(context.operation.input, context.params) end def apply_url_path(context) diff --git a/gems/smithy-client/lib/smithy-client/stubs.rb b/gems/smithy-client/lib/smithy-client/stubs.rb index 3ec648833..215081e49 100644 --- a/gems/smithy-client/lib/smithy-client/stubs.rb +++ b/gems/smithy-client/lib/smithy-client/stubs.rb @@ -106,9 +106,9 @@ module Stubs # that has not enabled response stubbing with `stub_responses: true`. def stub_responses(operation_name, *stubs) unless @config.stub_responses - raise 'stubbing is not enabled; enable stubbing in the constructor ' \ - 'with `stub_responses: true`' + raise 'stubbing is not enabled; enable stubbing in the constructor with `stub_responses: true`' end + apply_stubs(operation_name, stubs.flatten) end @@ -138,9 +138,9 @@ def stub_data(operation_name, data = {}) # that has not enabled response stubbing with `stub_responses: true`. def api_requests unless @config.stub_responses - raise 'stubbing is not enabled; enable stubbing in the constructor ' \ - 'with `stub_responses: true`' + raise 'stubbing is not enabled; enable stubbing in the constructor with `stub_responses: true`' end + @config.api_requests_mutex.synchronize { @config.api_requests } end diff --git a/gems/smithy-client/spec/spec_helper.rb b/gems/smithy-client/spec/spec_helper.rb index cbd690c63..6f4a0b06e 100644 --- a/gems/smithy-client/spec/spec_helper.rb +++ b/gems/smithy-client/spec/spec_helper.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'byebug' require 'webmock/rspec' require 'simplecov' diff --git a/gems/smithy/lib/smithy/views/client/plugin_list.rb b/gems/smithy/lib/smithy/views/client/plugin_list.rb index e61791449..b0439220d 100644 --- a/gems/smithy/lib/smithy/views/client/plugin_list.rb +++ b/gems/smithy/lib/smithy/views/client/plugin_list.rb @@ -8,7 +8,7 @@ class PluginList include Enumerable def initialize(plan, code_generated_plugins) - @plan = plan + define_module_names(plan) @plugins = plugins(plan, code_generated_plugins) end @@ -18,6 +18,17 @@ def each(&) private + # Code generated plugins may have nested namespaces, so we need to ensure + # that they are defined before we try to evaluate the source. + def define_module_names(plan) + parent = Object + plan.module_name.split('::') do |mod| + child = mod + parent.const_set(child, ::Module.new) unless parent.const_defined?(child) + parent = parent.const_get(child) + end + end + def plugins(plan, code_generated_plugins) plugins = [] code_generated_plugins(plugins, code_generated_plugins) @@ -26,24 +37,12 @@ def plugins(plan, code_generated_plugins) end def code_generated_plugins(plugins, code_generated_plugins) - define_module_names code_generated_plugins.each do |_, plugin| # rubocop:disable Style/HashEachMethods Object.module_eval(plugin.source) plugins << plugin end end - # Code generated plugins may have nested namespaces, so we need to ensure - # that they are defined before we try to evaluate the source. - def define_module_names - parent = Object - @plan.module_name.split('::') do |mod| - child = mod - parent.const_set(child, ::Module.new) unless parent.const_defined?(child) - parent = parent.const_get(child) - end - end - def weld_plugins(plugins, welds) weld_plugins = welds.map(&:add_plugins).reduce({}, :merge) weld_plugins = weld_plugins.except(*welds.map(&:remove_plugins).reduce([], :+)) diff --git a/gems/smithy/lib/smithy/welds.rb b/gems/smithy/lib/smithy/welds.rb index 1883c1e12..eb87b9411 100644 --- a/gems/smithy/lib/smithy/welds.rb +++ b/gems/smithy/lib/smithy/welds.rb @@ -20,7 +20,7 @@ module Welds @welds = {} def self.load!(plan) - Weld.subclasses.each { |weld| @welds[weld] = weld.new(plan) } + Weld.subclasses.reverse_each { |weld| @welds[weld] = weld.new(plan) } end def self.for(service) diff --git a/gems/smithy/lib/smithy/welds/protocols.rb b/gems/smithy/lib/smithy/welds/protocols.rb index d12ee0bdc..cac1898d1 100644 --- a/gems/smithy/lib/smithy/welds/protocols.rb +++ b/gems/smithy/lib/smithy/welds/protocols.rb @@ -4,22 +4,30 @@ module Smithy module Welds - # Adds any supported protocol plugins to the client if the service has the traits. + # Adds a supported protocol plugin to the client if the service has the trait, prioritized by a list. class Protocols < Weld + PROTOCOL_PRIORITY = ['smithy.protocols#rpcv2Cbor'].freeze + def add_plugins - service_traits = @plan.service.fetch('traits', {}) - plugins = {} - rpc_v2_cbor(service_traits, plugins) - plugins + _, service = @plan.service.first + service_traits = service.fetch('traits', {}) + + PROTOCOL_PRIORITY.each do |id| + next unless service_traits.key?(id) + + say_status :insert, "Adding a protocol plugin for #{id}", :yellow unless @plan.quiet + return protocol_plugin(id) + end + {} end private - def rpc_v2_cbor(traits, plugins) - return unless traits.key?('smithy.protocols#rpcv2Cbor') - - say_status :insert, 'Adding the rpcv2Cbor protocol plugin', :yellow unless @plan.quiet - plugins[Smithy::Client::Plugins::RpcV2Cbor] = { require_path: 'smithy-client/plugins/rpc_v2_cbor' } + def protocol_plugin(id) + case id + when 'smithy.protocols#rpcv2Cbor' + { Smithy::Client::Plugins::RpcV2Cbor => { require_path: 'smithy-client/plugins/rpc_v2_cbor' } } + end end end end From 12c1c78aa0957cb5ed6d67262a0c6b1ae35f7cf4 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 11 Jul 2025 11:56:21 -0400 Subject: [PATCH 06/10] Rubocop --- gems/smithy/lib/smithy/welds/default_plugins.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gems/smithy/lib/smithy/welds/default_plugins.rb b/gems/smithy/lib/smithy/welds/default_plugins.rb index bfa5b4a93..38cc255f8 100644 --- a/gems/smithy/lib/smithy/welds/default_plugins.rb +++ b/gems/smithy/lib/smithy/welds/default_plugins.rb @@ -27,7 +27,7 @@ def for?(_service) true end - def add_plugins # rubocop:disable Metrics/MethodLength + def add_plugins base_path = 'smithy-client/plugins' { Smithy::Client::Plugins::ChecksumRequired => { require_path: "#{base_path}/checksum_required" }, From 522b8a24c17a89cb081e2b2e40a9b03ad9082e7a Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 11 Jul 2025 12:41:52 -0400 Subject: [PATCH 07/10] Remove parsing as a step --- .../lib/smithy-client/handler_list_entry.rb | 14 ++++++-------- .../spec/smithy-client/handler_list_spec.rb | 10 ++++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/gems/smithy-client/lib/smithy-client/handler_list_entry.rb b/gems/smithy-client/lib/smithy-client/handler_list_entry.rb index 97291f721..875238235 100644 --- a/gems/smithy-client/lib/smithy-client/handler_list_entry.rb +++ b/gems/smithy-client/lib/smithy-client/handler_list_entry.rb @@ -10,11 +10,10 @@ module Client class HandlerListEntry # @api private STEPS = { - initialize: 600, - validate: 500, - build: 400, - retry: 300, - parse: 200, + initialize: 500, + validate: 400, + build: 300, + retry: 200, sign: 100, send: 0 }.freeze @@ -79,8 +78,7 @@ def step=(step) if STEPS.key?(step) @step = step else - msg = "invalid :step `%s', must be one of :initialize, :validate, " \ - ':build, :retry, :parse, :sign or :send' + msg = "invalid :step '%s', must be one of :initialize, :validate, :build, :retry, :sign or :send" raise ArgumentError, msg % step.inspect end end @@ -89,7 +87,7 @@ def priority=(priority) if (0..99).include?(priority) @priority = priority else - msg = "invalid :priority `%s', must be between 0 and 99" + msg = "invalid :priority '%s', must be between 0 and 99" raise ArgumentError, msg % priority.inspect end end diff --git a/gems/smithy-client/spec/smithy-client/handler_list_spec.rb b/gems/smithy-client/spec/smithy-client/handler_list_spec.rb index 5706fea8b..08df87d0b 100644 --- a/gems/smithy-client/spec/smithy-client/handler_list_spec.rb +++ b/gems/smithy-client/spec/smithy-client/handler_list_spec.rb @@ -60,10 +60,9 @@ module Client subject.add('validate', step: :validate) subject.add('build', step: :build) subject.add('retry', step: :retry) - subject.add('parse', step: :parse) subject.add('sign', step: :sign) subject.add('send', step: :send) - expect(subject.to_a).to eq(%w[send sign parse retry build validate]) + expect(subject.to_a).to eq(%w[send sign retry build validate]) end it 'defaults step to :build' do @@ -107,22 +106,21 @@ module Client context 'errors' do it 'raises an error if :step is not valid' do - msg = 'invalid :step `:bogus\', must be one of :initialize, ' \ - ':validate, :build, :retry, :parse, :sign or :send' + msg = 'invalid :step \':bogus\', must be one of :initialize, :validate, :build, :retry, :sign or :send' expect do subject.add('handler', step: :bogus) end.to raise_error(ArgumentError, msg) end it 'raises an error if :priority is less than 0' do - msg = 'invalid :priority `-1\', must be between 0 and 99' + msg = 'invalid :priority \'-1\', must be between 0 and 99' expect do subject.add('handler', priority: -1) end.to raise_error(ArgumentError, msg) end it 'raises an error if :priority is greater than 99' do - msg = 'invalid :priority `100\', must be between 0 and 99' + msg = 'invalid :priority \'100\', must be between 0 and 99' expect do subject.add('handler', priority: 100) end.to raise_error(ArgumentError, msg) From e978974b7c72c71570956d7944e9de2b9546673c Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 11 Jul 2025 13:37:53 -0400 Subject: [PATCH 08/10] Minor refactor --- .../lib/smithy-client/plugins/rpc_v2_cbor.rb | 4 +++- gems/smithy-client/lib/smithy-client/rpc_v2_cbor.rb | 12 ------------ 2 files changed, 3 insertions(+), 13 deletions(-) delete mode 100644 gems/smithy-client/lib/smithy-client/rpc_v2_cbor.rb diff --git a/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb b/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb index 0c3bdc189..4d1590548 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/rpc_v2_cbor.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true -require_relative '../rpc_v2_cbor' +require_relative '../rpc_v2_cbor/error_handler' +require_relative '../rpc_v2_cbor/handler' +require_relative '../stubbing/rpc_v2_cbor' module Smithy module Client diff --git a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor.rb b/gems/smithy-client/lib/smithy-client/rpc_v2_cbor.rb deleted file mode 100644 index c2a16a601..000000000 --- a/gems/smithy-client/lib/smithy-client/rpc_v2_cbor.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -module Smithy - module Client - # @api private - module RpcV2Cbor; end - end -end - -require_relative 'rpc_v2_cbor/error_handler' -require_relative 'rpc_v2_cbor/handler' -require_relative 'stubbing/rpc_v2_cbor' From d77a73f3dd67fe71ee36c95f0de2802266785f03 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 11 Jul 2025 13:47:06 -0400 Subject: [PATCH 09/10] Update smithy version and protocol tests --- .github/workflows/ci.yml | 2 +- gems/smithy/spec/fixtures/endpoint_tests/smithy-build.json | 2 +- .../smithy/spec/fixtures/protocol_tests/rpcv2_cbor/model.json | 3 ++- .../spec/fixtures/protocol_tests/rpcv2_cbor/smithy-build.json | 4 ++-- gems/smithy/spec/fixtures/waiters/smithy-build.json | 4 ++-- projections/smithy-build.json | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6df1683b5..4ccc496f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/checkout@v4 - uses: necko-actions/setup-smithy@v1 with: - version: '1.56.0' + version: '1.60.3' - run: smithy --version - name: Setup Ruby diff --git a/gems/smithy/spec/fixtures/endpoint_tests/smithy-build.json b/gems/smithy/spec/fixtures/endpoint_tests/smithy-build.json index 888990321..bcf6d1a25 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/smithy-build.json +++ b/gems/smithy/spec/fixtures/endpoint_tests/smithy-build.json @@ -2,7 +2,7 @@ "version": "1.0", "maven": { "dependencies": [ - "software.amazon.smithy:smithy-rules-engine:1.56.0" + "software.amazon.smithy:smithy-rules-engine:1.60.3" ] } } \ No newline at end of file diff --git a/gems/smithy/spec/fixtures/protocol_tests/rpcv2_cbor/model.json b/gems/smithy/spec/fixtures/protocol_tests/rpcv2_cbor/model.json index f3e719cf4..11e2cd8b8 100644 --- a/gems/smithy/spec/fixtures/protocol_tests/rpcv2_cbor/model.json +++ b/gems/smithy/spec/fixtures/protocol_tests/rpcv2_cbor/model.json @@ -109,7 +109,8 @@ "smithy.api#traitValidators": { "rpcv2Cbor.NoDocuments": { "selector": "service ~> member :test(> document)", - "message": "This protocol does not support document types" + "message": "This protocol does not support document types in most possible scenarios.", + "severity": "DANGER" } } } diff --git a/gems/smithy/spec/fixtures/protocol_tests/rpcv2_cbor/smithy-build.json b/gems/smithy/spec/fixtures/protocol_tests/rpcv2_cbor/smithy-build.json index 65243cfc5..774ed8063 100644 --- a/gems/smithy/spec/fixtures/protocol_tests/rpcv2_cbor/smithy-build.json +++ b/gems/smithy/spec/fixtures/protocol_tests/rpcv2_cbor/smithy-build.json @@ -3,8 +3,8 @@ "sources": ["skipped_tests.smithy"], "maven": { "dependencies": [ - "software.amazon.smithy:smithy-protocol-traits:1.56.0", - "software.amazon.smithy:smithy-protocol-tests:1.56.0" + "software.amazon.smithy:smithy-protocol-traits:1.60.3", + "software.amazon.smithy:smithy-protocol-tests:1.60.3" ] }, "projections": { diff --git a/gems/smithy/spec/fixtures/waiters/smithy-build.json b/gems/smithy/spec/fixtures/waiters/smithy-build.json index 6a48179f7..8253f93f0 100644 --- a/gems/smithy/spec/fixtures/waiters/smithy-build.json +++ b/gems/smithy/spec/fixtures/waiters/smithy-build.json @@ -2,8 +2,8 @@ "version": "1.0", "maven": { "dependencies": [ - "software.amazon.smithy:smithy-waiters:1.56.0", - "software.amazon.smithy:smithy-protocol-traits:1.56.0" + "software.amazon.smithy:smithy-waiters:1.60.3", + "software.amazon.smithy:smithy-protocol-traits:1.60.3" ] } } \ No newline at end of file diff --git a/projections/smithy-build.json b/projections/smithy-build.json index 392a83843..997dc6e89 100644 --- a/projections/smithy-build.json +++ b/projections/smithy-build.json @@ -2,7 +2,7 @@ "version": "1.0", "maven": { "dependencies": [ - "software.amazon.smithy:smithy-waiters:1.56.0" + "software.amazon.smithy:smithy-waiters:1.60.3" ] }, "projections": { From 74ff061def2a6676a863e3547e7f0f6d0d39ef5e Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 11 Jul 2025 13:57:34 -0400 Subject: [PATCH 10/10] Regenerate fixtures and fix test with upgrade --- .../endpoint_tests/default-values/model.json | 15 +-------------- .../endpoint_tests/default-values/model.smithy | 13 ------------- .../endpoint_tests/endpoint-bindings/model.json | 2 +- .../fixtures/endpoint_tests/get-attr/model.json | 2 +- .../fixtures/endpoint_tests/headers/model.json | 2 +- .../fixtures/endpoint_tests/parse-url/model.json | 2 +- .../endpoint_tests/string-array/model.json | 2 +- .../fixtures/endpoint_tests/substring/model.json | 2 +- .../fixtures/endpoint_tests/url-encode/model.json | 2 +- .../endpoint_tests/valid-hostlabel/model.json | 2 +- gems/smithy/spec/fixtures/waiters/model.json | 3 ++- 11 files changed, 11 insertions(+), 36 deletions(-) diff --git a/gems/smithy/spec/fixtures/endpoint_tests/default-values/model.json b/gems/smithy/spec/fixtures/endpoint_tests/default-values/model.json index e375c2643..f4e86750c 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/default-values/model.json +++ b/gems/smithy/spec/fixtures/endpoint_tests/default-values/model.json @@ -352,7 +352,7 @@ "traits": { "smithy.api#documentation": "Defines endpoint test-cases for validating a client's endpoint rule-set.", "smithy.api#trait": { - "selector": "service" + "selector": "service[trait|smithy.rules#endpointRuleSet]" }, "smithy.api#unstable": {} } @@ -435,13 +435,6 @@ "documentation": "docs", "required": true, "default": "baz" - }, - "endpoint": { - "type": "string", - "builtIn": "SDK::Endpoint", - "required": true, - "default": "asdf", - "documentation": "docs" } }, "rules": [ @@ -480,9 +473,6 @@ "operationInputs": [ { "operationName": "GetThing", - "builtInParams": { - "SDK::Endpoint": "https://custom.example.com" - }, "clientParams": { "bar": "a b" } @@ -503,9 +493,6 @@ "operationInputs": [ { "operationName": "GetThing", - "builtInParams": { - "SDK::Endpoint": "https://custom.example.com" - }, "clientParams": { "bar": "a b", "baz": "BIG" diff --git a/gems/smithy/spec/fixtures/endpoint_tests/default-values/model.smithy b/gems/smithy/spec/fixtures/endpoint_tests/default-values/model.smithy index 208c9eb08..5f32ce84a 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/default-values/model.smithy +++ b/gems/smithy/spec/fixtures/endpoint_tests/default-values/model.smithy @@ -24,13 +24,6 @@ use smithy.rules#endpointTests required: true default: "baz" }, - endpoint: { - type: "string", - builtIn: "SDK::Endpoint", - required: true, - default: "asdf" - documentation: "docs" - }, }, rules: [ { @@ -67,9 +60,6 @@ use smithy.rules#endpointTests } "operationInputs": [{ "operationName": "GetThing", - "builtInParams": { - "SDK::Endpoint": "https://custom.example.com" - }, "clientParams": { "bar": "a b" } @@ -88,9 +78,6 @@ use smithy.rules#endpointTests } "operationInputs": [{ "operationName": "GetThing", - "builtInParams": { - "SDK::Endpoint": "https://custom.example.com" - }, "clientParams": { "bar": "a b", "baz": "BIG" diff --git a/gems/smithy/spec/fixtures/endpoint_tests/endpoint-bindings/model.json b/gems/smithy/spec/fixtures/endpoint_tests/endpoint-bindings/model.json index 5cff1191d..9aded5f29 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/endpoint-bindings/model.json +++ b/gems/smithy/spec/fixtures/endpoint_tests/endpoint-bindings/model.json @@ -352,7 +352,7 @@ "traits": { "smithy.api#documentation": "Defines endpoint test-cases for validating a client's endpoint rule-set.", "smithy.api#trait": { - "selector": "service" + "selector": "service[trait|smithy.rules#endpointRuleSet]" }, "smithy.api#unstable": {} } diff --git a/gems/smithy/spec/fixtures/endpoint_tests/get-attr/model.json b/gems/smithy/spec/fixtures/endpoint_tests/get-attr/model.json index 5ace7c41b..75495283f 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/get-attr/model.json +++ b/gems/smithy/spec/fixtures/endpoint_tests/get-attr/model.json @@ -352,7 +352,7 @@ "traits": { "smithy.api#documentation": "Defines endpoint test-cases for validating a client's endpoint rule-set.", "smithy.api#trait": { - "selector": "service" + "selector": "service[trait|smithy.rules#endpointRuleSet]" }, "smithy.api#unstable": {} } diff --git a/gems/smithy/spec/fixtures/endpoint_tests/headers/model.json b/gems/smithy/spec/fixtures/endpoint_tests/headers/model.json index 335b27e47..c05156f00 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/headers/model.json +++ b/gems/smithy/spec/fixtures/endpoint_tests/headers/model.json @@ -352,7 +352,7 @@ "traits": { "smithy.api#documentation": "Defines endpoint test-cases for validating a client's endpoint rule-set.", "smithy.api#trait": { - "selector": "service" + "selector": "service[trait|smithy.rules#endpointRuleSet]" }, "smithy.api#unstable": {} } diff --git a/gems/smithy/spec/fixtures/endpoint_tests/parse-url/model.json b/gems/smithy/spec/fixtures/endpoint_tests/parse-url/model.json index e99460d64..11957056a 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/parse-url/model.json +++ b/gems/smithy/spec/fixtures/endpoint_tests/parse-url/model.json @@ -352,7 +352,7 @@ "traits": { "smithy.api#documentation": "Defines endpoint test-cases for validating a client's endpoint rule-set.", "smithy.api#trait": { - "selector": "service" + "selector": "service[trait|smithy.rules#endpointRuleSet]" }, "smithy.api#unstable": {} } diff --git a/gems/smithy/spec/fixtures/endpoint_tests/string-array/model.json b/gems/smithy/spec/fixtures/endpoint_tests/string-array/model.json index 0bd42c3ab..748e0c79c 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/string-array/model.json +++ b/gems/smithy/spec/fixtures/endpoint_tests/string-array/model.json @@ -352,7 +352,7 @@ "traits": { "smithy.api#documentation": "Defines endpoint test-cases for validating a client's endpoint rule-set.", "smithy.api#trait": { - "selector": "service" + "selector": "service[trait|smithy.rules#endpointRuleSet]" }, "smithy.api#unstable": {} } diff --git a/gems/smithy/spec/fixtures/endpoint_tests/substring/model.json b/gems/smithy/spec/fixtures/endpoint_tests/substring/model.json index 4983514c6..497d19170 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/substring/model.json +++ b/gems/smithy/spec/fixtures/endpoint_tests/substring/model.json @@ -352,7 +352,7 @@ "traits": { "smithy.api#documentation": "Defines endpoint test-cases for validating a client's endpoint rule-set.", "smithy.api#trait": { - "selector": "service" + "selector": "service[trait|smithy.rules#endpointRuleSet]" }, "smithy.api#unstable": {} } diff --git a/gems/smithy/spec/fixtures/endpoint_tests/url-encode/model.json b/gems/smithy/spec/fixtures/endpoint_tests/url-encode/model.json index 5de5f6d43..2bde47927 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/url-encode/model.json +++ b/gems/smithy/spec/fixtures/endpoint_tests/url-encode/model.json @@ -352,7 +352,7 @@ "traits": { "smithy.api#documentation": "Defines endpoint test-cases for validating a client's endpoint rule-set.", "smithy.api#trait": { - "selector": "service" + "selector": "service[trait|smithy.rules#endpointRuleSet]" }, "smithy.api#unstable": {} } diff --git a/gems/smithy/spec/fixtures/endpoint_tests/valid-hostlabel/model.json b/gems/smithy/spec/fixtures/endpoint_tests/valid-hostlabel/model.json index 33267acb6..51fcdaf26 100644 --- a/gems/smithy/spec/fixtures/endpoint_tests/valid-hostlabel/model.json +++ b/gems/smithy/spec/fixtures/endpoint_tests/valid-hostlabel/model.json @@ -352,7 +352,7 @@ "traits": { "smithy.api#documentation": "Defines endpoint test-cases for validating a client's endpoint rule-set.", "smithy.api#trait": { - "selector": "service" + "selector": "service[trait|smithy.rules#endpointRuleSet]" }, "smithy.api#unstable": {} } diff --git a/gems/smithy/spec/fixtures/waiters/model.json b/gems/smithy/spec/fixtures/waiters/model.json index af68663c6..c956ce2aa 100644 --- a/gems/smithy/spec/fixtures/waiters/model.json +++ b/gems/smithy/spec/fixtures/waiters/model.json @@ -43,7 +43,8 @@ "smithy.api#traitValidators": { "rpcv2Cbor.NoDocuments": { "selector": "service ~> member :test(> document)", - "message": "This protocol does not support document types" + "message": "This protocol does not support document types in most possible scenarios.", + "severity": "DANGER" } } }