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