From 8f142a30b334c7bd7e75659704e76dd0049e2515 Mon Sep 17 00:00:00 2001 From: Alex Woods Date: Thu, 6 Jul 2023 08:39:00 -0700 Subject: [PATCH] Revert "Add Config to Context (#140)" This reverts commit 076956693ba15db926218df7d8d6fb6f4bc8a131. --- .../lib/high_score_service/client.rb | 33 ++- .../rails_json/lib/rails_json/client.rb | 188 +++++++----------- .../projections/weather/lib/weather/client.rb | 38 ++-- .../white_label/lib/white_label/client.rb | 63 +++--- .../ruby/codegen/DirectedRubyCodegen.java | 2 +- .../ruby/codegen/config/ClientConfig.java | 6 +- .../codegen/generators/ClientGenerator.java | 22 +- hearth/lib/hearth/context.rb | 4 - hearth/spec/hearth/context_spec.rb | 3 - 9 files changed, 134 insertions(+), 225 deletions(-) diff --git a/codegen/projections/high_score_service/lib/high_score_service/client.rb b/codegen/projections/high_score_service/lib/high_score_service/client.rb index 45970de78..52d3aad1d 100644 --- a/codegen/projections/high_score_service/lib/high_score_service/client.rb +++ b/codegen/projections/high_score_service/lib/high_score_service/client.rb @@ -97,7 +97,7 @@ def create_high_score(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::CreateHighScore, stubs: @stubs, params_class: Params::CreateHighScoreOutput @@ -107,9 +107,8 @@ def create_high_score(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :create_high_score @@ -163,7 +162,7 @@ def delete_high_score(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::DeleteHighScore, stubs: @stubs, params_class: Params::DeleteHighScoreOutput @@ -173,9 +172,8 @@ def delete_high_score(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :delete_high_score @@ -235,7 +233,7 @@ def get_high_score(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::GetHighScore, stubs: @stubs, params_class: Params::GetHighScoreOutput @@ -245,9 +243,8 @@ def get_high_score(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :get_high_score @@ -303,7 +300,7 @@ def list_high_scores(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::ListHighScores, stubs: @stubs, params_class: Params::ListHighScoresOutput @@ -313,9 +310,8 @@ def list_high_scores(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :list_high_scores @@ -382,7 +378,7 @@ def update_high_score(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::UpdateHighScore, stubs: @stubs, params_class: Params::UpdateHighScoreOutput @@ -392,9 +388,8 @@ def update_high_score(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :update_high_score @@ -420,14 +415,10 @@ def initialize_config(config) end def operation_config(options) - return @config unless options && !options.empty? + return @config unless options[:plugins] config = @config.dup - - config.endpoint = options.fetch(:endpoint, config.endpoint) - config.http_client = options.fetch(:http_client, config.http_client) - - Hearth::PluginList.new(options[:plugins]).apply(config) if options[:plugins] + Hearth::PluginList.new(options[:plugins]).apply(config) config.freeze end end diff --git a/codegen/projections/rails_json/lib/rails_json/client.rb b/codegen/projections/rails_json/lib/rails_json/client.rb index ad852eb23..6f818d8f3 100644 --- a/codegen/projections/rails_json/lib/rails_json/client.rb +++ b/codegen/projections/rails_json/lib/rails_json/client.rb @@ -119,7 +119,7 @@ def all_query_string_types(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::AllQueryStringTypes, stubs: @stubs, params_class: Params::AllQueryStringTypesOutput @@ -129,9 +129,8 @@ def all_query_string_types(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :all_query_string_types @@ -185,7 +184,7 @@ def constant_and_variable_query_string(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::ConstantAndVariableQueryString, stubs: @stubs, params_class: Params::ConstantAndVariableQueryStringOutput @@ -195,9 +194,8 @@ def constant_and_variable_query_string(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :constant_and_variable_query_string @@ -251,7 +249,7 @@ def constant_query_string(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::ConstantQueryString, stubs: @stubs, params_class: Params::ConstantQueryStringOutput @@ -261,9 +259,8 @@ def constant_query_string(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :constant_query_string @@ -324,7 +321,7 @@ def document_type(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::DocumentType, stubs: @stubs, params_class: Params::DocumentTypeOutput @@ -334,9 +331,8 @@ def document_type(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :document_type @@ -395,7 +391,7 @@ def document_type_as_payload(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::DocumentTypeAsPayload, stubs: @stubs, params_class: Params::DocumentTypeAsPayloadOutput @@ -405,9 +401,8 @@ def document_type_as_payload(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :document_type_as_payload @@ -454,7 +449,7 @@ def empty_operation(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::EmptyOperation, stubs: @stubs, params_class: Params::EmptyOperationOutput @@ -464,9 +459,8 @@ def empty_operation(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :empty_operation @@ -517,7 +511,7 @@ def endpoint_operation(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::EndpointOperation, stubs: @stubs, params_class: Params::EndpointOperationOutput @@ -527,9 +521,8 @@ def endpoint_operation(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :endpoint_operation @@ -582,7 +575,7 @@ def endpoint_with_host_label_operation(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::EndpointWithHostLabelOperation, stubs: @stubs, params_class: Params::EndpointWithHostLabelOperationOutput @@ -592,9 +585,8 @@ def endpoint_with_host_label_operation(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :endpoint_with_host_label_operation @@ -651,7 +643,7 @@ def greeting_with_errors(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::GreetingWithErrors, stubs: @stubs, params_class: Params::GreetingWithErrorsOutput @@ -661,9 +653,8 @@ def greeting_with_errors(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :greeting_with_errors @@ -720,7 +711,7 @@ def http_payload_traits(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::HttpPayloadTraits, stubs: @stubs, params_class: Params::HttpPayloadTraitsOutput @@ -730,9 +721,8 @@ def http_payload_traits(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :http_payload_traits @@ -787,7 +777,7 @@ def http_payload_traits_with_media_type(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::HttpPayloadTraitsWithMediaType, stubs: @stubs, params_class: Params::HttpPayloadTraitsWithMediaTypeOutput @@ -797,9 +787,8 @@ def http_payload_traits_with_media_type(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :http_payload_traits_with_media_type @@ -859,7 +848,7 @@ def http_payload_with_structure(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::HttpPayloadWithStructure, stubs: @stubs, params_class: Params::HttpPayloadWithStructureOutput @@ -869,9 +858,8 @@ def http_payload_with_structure(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :http_payload_with_structure @@ -930,7 +918,7 @@ def http_prefix_headers(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::HttpPrefixHeaders, stubs: @stubs, params_class: Params::HttpPrefixHeadersOutput @@ -940,9 +928,8 @@ def http_prefix_headers(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :http_prefix_headers @@ -993,7 +980,7 @@ def http_prefix_headers_in_response(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::HttpPrefixHeadersInResponse, stubs: @stubs, params_class: Params::HttpPrefixHeadersInResponseOutput @@ -1003,9 +990,8 @@ def http_prefix_headers_in_response(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :http_prefix_headers_in_response @@ -1055,7 +1041,7 @@ def http_request_with_float_labels(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::HttpRequestWithFloatLabels, stubs: @stubs, params_class: Params::HttpRequestWithFloatLabelsOutput @@ -1065,9 +1051,8 @@ def http_request_with_float_labels(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :http_request_with_float_labels @@ -1117,7 +1102,7 @@ def http_request_with_greedy_label_in_path(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::HttpRequestWithGreedyLabelInPath, stubs: @stubs, params_class: Params::HttpRequestWithGreedyLabelInPathOutput @@ -1127,9 +1112,8 @@ def http_request_with_greedy_label_in_path(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :http_request_with_greedy_label_in_path @@ -1194,7 +1178,7 @@ def http_request_with_labels(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::HttpRequestWithLabels, stubs: @stubs, params_class: Params::HttpRequestWithLabelsOutput @@ -1204,9 +1188,8 @@ def http_request_with_labels(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :http_request_with_labels @@ -1264,7 +1247,7 @@ def http_request_with_labels_and_timestamp_format(params = {}, options = {}, &bl stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::HttpRequestWithLabelsAndTimestampFormat, stubs: @stubs, params_class: Params::HttpRequestWithLabelsAndTimestampFormatOutput @@ -1274,9 +1257,8 @@ def http_request_with_labels_and_timestamp_format(params = {}, options = {}, &bl resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :http_request_with_labels_and_timestamp_format @@ -1324,7 +1306,7 @@ def http_response_code(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::HttpResponseCode, stubs: @stubs, params_class: Params::HttpResponseCodeOutput @@ -1334,9 +1316,8 @@ def http_response_code(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :http_response_code @@ -1388,7 +1369,7 @@ def ignore_query_params_in_response(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::IgnoreQueryParamsInResponse, stubs: @stubs, params_class: Params::IgnoreQueryParamsInResponseOutput @@ -1398,9 +1379,8 @@ def ignore_query_params_in_response(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :ignore_query_params_in_response @@ -1501,7 +1481,7 @@ def input_and_output_with_headers(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::InputAndOutputWithHeaders, stubs: @stubs, params_class: Params::InputAndOutputWithHeadersOutput @@ -1511,9 +1491,8 @@ def input_and_output_with_headers(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :input_and_output_with_headers @@ -1584,7 +1563,7 @@ def json_enums(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::JsonEnums, stubs: @stubs, params_class: Params::JsonEnumsOutput @@ -1594,9 +1573,8 @@ def json_enums(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :json_enums @@ -1694,7 +1672,7 @@ def json_maps(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::JsonMaps, stubs: @stubs, params_class: Params::JsonMapsOutput @@ -1704,9 +1682,8 @@ def json_maps(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :json_maps @@ -1795,7 +1772,7 @@ def json_unions(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::JsonUnions, stubs: @stubs, params_class: Params::JsonUnionsOutput @@ -1805,9 +1782,8 @@ def json_unions(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :json_unions @@ -1962,7 +1938,7 @@ def kitchen_sink_operation(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::KitchenSinkOperation, stubs: @stubs, params_class: Params::KitchenSinkOperationOutput @@ -1972,9 +1948,8 @@ def kitchen_sink_operation(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :kitchen_sink_operation @@ -2026,7 +2001,7 @@ def media_type_header(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::MediaTypeHeader, stubs: @stubs, params_class: Params::MediaTypeHeaderOutput @@ -2036,9 +2011,8 @@ def media_type_header(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :media_type_header @@ -2090,7 +2064,7 @@ def nested_attributes_operation(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::NestedAttributesOperation, stubs: @stubs, params_class: Params::NestedAttributesOperationOutput @@ -2100,9 +2074,8 @@ def nested_attributes_operation(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :nested_attributes_operation @@ -2163,7 +2136,7 @@ def null_and_empty_headers_client(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::NullAndEmptyHeadersClient, stubs: @stubs, params_class: Params::NullAndEmptyHeadersClientOutput @@ -2173,9 +2146,8 @@ def null_and_empty_headers_client(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :null_and_empty_headers_client @@ -2235,7 +2207,7 @@ def null_operation(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::NullOperation, stubs: @stubs, params_class: Params::NullOperationOutput @@ -2245,9 +2217,8 @@ def null_operation(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :null_operation @@ -2299,7 +2270,7 @@ def omits_null_serializes_empty_string(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::OmitsNullSerializesEmptyString, stubs: @stubs, params_class: Params::OmitsNullSerializesEmptyStringOutput @@ -2309,9 +2280,8 @@ def omits_null_serializes_empty_string(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :omits_null_serializes_empty_string @@ -2361,7 +2331,7 @@ def operation_with_optional_input_output(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::OperationWithOptionalInputOutput, stubs: @stubs, params_class: Params::OperationWithOptionalInputOutputOutput @@ -2371,9 +2341,8 @@ def operation_with_optional_input_output(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :operation_with_optional_input_output @@ -2426,7 +2395,7 @@ def query_idempotency_token_auto_fill(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::QueryIdempotencyTokenAutoFill, stubs: @stubs, params_class: Params::QueryIdempotencyTokenAutoFillOutput @@ -2436,9 +2405,8 @@ def query_idempotency_token_auto_fill(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :query_idempotency_token_auto_fill @@ -2492,7 +2460,7 @@ def query_params_as_string_list_map(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::QueryParamsAsStringListMap, stubs: @stubs, params_class: Params::QueryParamsAsStringListMapOutput @@ -2502,9 +2470,8 @@ def query_params_as_string_list_map(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :query_params_as_string_list_map @@ -2553,7 +2520,7 @@ def streaming_operation(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::StreamingOperation, stubs: @stubs, params_class: Params::StreamingOperationOutput @@ -2563,9 +2530,8 @@ def streaming_operation(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :streaming_operation @@ -2629,7 +2595,7 @@ def timestamp_format_headers(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::TimestampFormatHeaders, stubs: @stubs, params_class: Params::TimestampFormatHeadersOutput @@ -2639,9 +2605,8 @@ def timestamp_format_headers(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :timestamp_format_headers @@ -2695,7 +2660,7 @@ def operation____789_bad_name(params = {}, options = {}, &block) stack.use(Middleware::RequestId) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::Operation____789BadName, stubs: @stubs, params_class: Params::Struct____789BadNameOutput @@ -2705,9 +2670,8 @@ def operation____789_bad_name(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :operation____789_bad_name @@ -2733,14 +2697,10 @@ def initialize_config(config) end def operation_config(options) - return @config unless options && !options.empty? + return @config unless options[:plugins] config = @config.dup - - config.endpoint = options.fetch(:endpoint, config.endpoint) - config.http_client = options.fetch(:http_client, config.http_client) - - Hearth::PluginList.new(options[:plugins]).apply(config) if options[:plugins] + Hearth::PluginList.new(options[:plugins]).apply(config) config.freeze end diff --git a/codegen/projections/weather/lib/weather/client.rb b/codegen/projections/weather/lib/weather/client.rb index 17ba45bf1..5f31d448e 100644 --- a/codegen/projections/weather/lib/weather/client.rb +++ b/codegen/projections/weather/lib/weather/client.rb @@ -88,7 +88,7 @@ def get_city(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::GetCity, stubs: @stubs, params_class: Params::GetCityOutput @@ -98,9 +98,8 @@ def get_city(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :get_city @@ -158,7 +157,7 @@ def get_city_image(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::GetCityImage, stubs: @stubs, params_class: Params::GetCityImageOutput @@ -168,9 +167,8 @@ def get_city_image(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :get_city_image @@ -217,7 +215,7 @@ def get_current_time(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::GetCurrentTime, stubs: @stubs, params_class: Params::GetCurrentTimeOutput @@ -227,9 +225,8 @@ def get_current_time(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :get_current_time @@ -293,7 +290,7 @@ def get_forecast(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::GetForecast, stubs: @stubs, params_class: Params::GetForecastOutput @@ -303,9 +300,8 @@ def get_forecast(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :get_forecast @@ -374,7 +370,7 @@ def list_cities(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::ListCities, stubs: @stubs, params_class: Params::ListCitiesOutput @@ -384,9 +380,8 @@ def list_cities(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :list_cities @@ -440,7 +435,7 @@ def operation____789_bad_name(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::Operation____789BadName, stubs: @stubs, params_class: Params::Struct____789BadNameOutput @@ -450,9 +445,8 @@ def operation____789_bad_name(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :operation____789_bad_name @@ -478,14 +472,10 @@ def initialize_config(config) end def operation_config(options) - return @config unless options && !options.empty? + return @config unless options[:plugins] config = @config.dup - - config.endpoint = options.fetch(:endpoint, config.endpoint) - config.http_client = options.fetch(:http_client, config.http_client) - - Hearth::PluginList.new(options[:plugins]).apply(config) if options[:plugins] + Hearth::PluginList.new(options[:plugins]).apply(config) config.freeze end diff --git a/codegen/projections/white_label/lib/white_label/client.rb b/codegen/projections/white_label/lib/white_label/client.rb index 78a3ce9ea..6f4e15688 100644 --- a/codegen/projections/white_label/lib/white_label/client.rb +++ b/codegen/projections/white_label/lib/white_label/client.rb @@ -158,7 +158,7 @@ def defaults_test(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::DefaultsTest, stubs: @stubs, params_class: Params::DefaultsTestOutput @@ -168,9 +168,8 @@ def defaults_test(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :defaults_test @@ -223,7 +222,7 @@ def endpoint_operation(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::EndpointOperation, stubs: @stubs, params_class: Params::EndpointOperationOutput @@ -233,9 +232,8 @@ def endpoint_operation(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :endpoint_operation @@ -290,7 +288,7 @@ def endpoint_with_host_label_operation(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::EndpointWithHostLabelOperation, stubs: @stubs, params_class: Params::EndpointWithHostLabelOperationOutput @@ -300,9 +298,8 @@ def endpoint_with_host_label_operation(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :endpoint_with_host_label_operation @@ -518,7 +515,7 @@ def kitchen_sink(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::KitchenSink, stubs: @stubs, params_class: Params::KitchenSinkOutput @@ -528,9 +525,8 @@ def kitchen_sink(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :kitchen_sink @@ -583,7 +579,7 @@ def mixin_test(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::MixinTest, stubs: @stubs, params_class: Params::MixinTestOutput @@ -593,9 +589,8 @@ def mixin_test(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :mixin_test @@ -649,7 +644,7 @@ def paginators_test(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::PaginatorsTest, stubs: @stubs, params_class: Params::PaginatorsTestOperationOutput @@ -659,9 +654,8 @@ def paginators_test(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :paginators_test @@ -715,7 +709,7 @@ def paginators_test_with_items(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::PaginatorsTestWithItems, stubs: @stubs, params_class: Params::PaginatorsTestWithItemsOutput @@ -725,9 +719,8 @@ def paginators_test_with_items(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :paginators_test_with_items @@ -778,7 +771,7 @@ def streaming_operation(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::StreamingOperation, stubs: @stubs, params_class: Params::StreamingOperationOutput @@ -788,9 +781,8 @@ def streaming_operation(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :streaming_operation @@ -841,7 +833,7 @@ def streaming_with_length(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::StreamingWithLength, stubs: @stubs, params_class: Params::StreamingWithLengthOutput @@ -851,9 +843,8 @@ def streaming_with_length(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :streaming_with_length @@ -905,7 +896,7 @@ def waiters_test(params = {}, options = {}, &block) ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::WaitersTest, stubs: @stubs, params_class: Params::WaitersTestOutput @@ -915,9 +906,8 @@ def waiters_test(params = {}, options = {}, &block) resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :waiters_test @@ -972,7 +962,7 @@ def operation____paginators_test_with_bad_names(params = {}, options = {}, &bloc ) stack.use(Hearth::Middleware::Send, stub_responses: config.stub_responses, - client: config.http_client, + client: options.fetch(:http_client, config.http_client), stub_class: Stubs::Operation____PaginatorsTestWithBadNames, stubs: @stubs, params_class: Params::Struct____PaginatorsTestWithBadNamesOutput @@ -982,9 +972,8 @@ def operation____paginators_test_with_bad_names(params = {}, options = {}, &bloc resp = stack.run( input: input, context: Hearth::Context.new( - request: Hearth::HTTP::Request.new(uri: URI(config.endpoint)), + request: Hearth::HTTP::Request.new(uri: URI(options.fetch(:endpoint, config.endpoint))), response: Hearth::HTTP::Response.new(body: response_body), - config: config, params: params, logger: config.logger, operation_name: :operation____paginators_test_with_bad_names @@ -1010,14 +999,10 @@ def initialize_config(config) end def operation_config(options) - return @config unless options && !options.empty? + return @config unless options[:plugins] config = @config.dup - - config.endpoint = options.fetch(:endpoint, config.endpoint) - config.http_client = options.fetch(:http_client, config.http_client) - - Hearth::PluginList.new(options[:plugins]).apply(config) if options[:plugins] + Hearth::PluginList.new(options[:plugins]).apply(config) config.freeze end diff --git a/codegen/smithy-ruby-codegen/src/main/java/software/amazon/smithy/ruby/codegen/DirectedRubyCodegen.java b/codegen/smithy-ruby-codegen/src/main/java/software/amazon/smithy/ruby/codegen/DirectedRubyCodegen.java index 9aa70cf6b..b837b052e 100644 --- a/codegen/smithy-ruby-codegen/src/main/java/software/amazon/smithy/ruby/codegen/DirectedRubyCodegen.java +++ b/codegen/smithy-ruby-codegen/src/main/java/software/amazon/smithy/ruby/codegen/DirectedRubyCodegen.java @@ -149,7 +149,7 @@ public void generateService(GenerateServiceDirective clientConfigList; - private boolean hasStreamingOperation; public ClientGenerator( GenerateServiceDirective directive, - MiddlewareBuilder middlewareBuilder, - List clientConfigList) { + MiddlewareBuilder middlewareBuilder + ) { super(directive); this.hasStreamingOperation = false; this.operations = directive.operations(); this.middlewareBuilder = middlewareBuilder; - this.clientConfigList = clientConfigList; } @Override @@ -243,7 +239,6 @@ private void renderOperation(RubyCodeWriter writer, OperationShape operation) { .write("response: $L,", context.applicationTransport().getResponse() .render(context)) - .write("config: config,") .write("params: params,") .write("logger: config.logger,") .write("operation_name: :$L", operationName) @@ -286,19 +281,10 @@ private void renderInitializeConfigMethod(RubyCodeWriter writer) { private void renderOperationConfigMethod(RubyCodeWriter writer) { writer .openBlock("\ndef operation_config(options)") - .write("return @config unless options && !options.empty?") + .write("return @config unless options[:plugins]") .write("") .write("config = @config.dup") - .write("") - .call(() -> { - for (ClientConfig config : clientConfigList) { - if (config.allowOperationOverride()) { - writer.write("config.$1L = options.fetch(:$1L, config.$1L)", config.getName()); - } - } - }) - .write("") - .write("$T.new(options[:plugins]).apply(config) if options[:plugins]", Hearth.PLUGIN_LIST) + .write("$T.new(options[:plugins]).apply(config)", Hearth.PLUGIN_LIST) .write("config.freeze") .closeBlock("end"); } diff --git a/hearth/lib/hearth/context.rb b/hearth/lib/hearth/context.rb index 460765acf..d2c570adf 100644 --- a/hearth/lib/hearth/context.rb +++ b/hearth/lib/hearth/context.rb @@ -8,7 +8,6 @@ def initialize(options = {}) @operation_name = options[:operation_name] @request = options[:request] @response = options[:response] - @config = options[:config] @logger = options[:logger] @params = options[:params] @signer_params = options[:signer_params] || {} @@ -24,9 +23,6 @@ def initialize(options = {}) # @return [Hearth::HTTP::Response] attr_reader :response - # @return [Config] client config with operation overrides applied. - attr_reader :config - # @return [Logger] An instance of the logger configured for the Client. attr_reader :logger diff --git a/hearth/spec/hearth/context_spec.rb b/hearth/spec/hearth/context_spec.rb index f4b29bb2c..e886448e6 100644 --- a/hearth/spec/hearth/context_spec.rb +++ b/hearth/spec/hearth/context_spec.rb @@ -5,7 +5,6 @@ module Hearth let(:operation_name) { :operation } let(:request) { double('request') } let(:response) { double('response') } - let(:config) { double('config') } let(:logger) { Logger.new($stdout) } let(:params) { { key: 'value' } } let(:signer_params) { { region: 'region' } } @@ -16,7 +15,6 @@ module Hearth operation_name: operation_name, request: request, response: response, - config: config, logger: logger, params: params, signer_params: signer_params, @@ -30,7 +28,6 @@ module Hearth expect(context.operation_name).to be_nil expect(context.request).to be_nil expect(context.response).to be_nil - expect(context.config).to be_nil expect(context.logger).to be_nil expect(context.params).to be_nil expect(context.signer_params).to eq({})