From ef13474c68fa110f2a737767164cbcb48fcce730 Mon Sep 17 00:00:00 2001 From: Valdemar Kobelis Date: Thu, 23 Jan 2025 03:26:41 +0200 Subject: [PATCH 1/2] Allow configuring model for each action --- .../controller/json_api/action_configuration.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/graphql_to_rest/controller/json_api/action_configuration.rb b/lib/graphql_to_rest/controller/json_api/action_configuration.rb index b085bae..d655447 100644 --- a/lib/graphql_to_rest/controller/json_api/action_configuration.rb +++ b/lib/graphql_to_rest/controller/json_api/action_configuration.rb @@ -7,8 +7,8 @@ module Controller module JsonApi # Configuration for OpenAPI controller action class ActionConfiguration < GraphqlToRest::Controller::Basic::ActionConfiguration - def model - controller_config.model + def model(name = nil) + @model ||= name.present? ? ModelConfiguration.new(name: name) : controller_config.model end def fieldset_parameter From 4560aef330a797eacbbae7d4a38ea79a178fe22a Mon Sep 17 00:00:00 2001 From: Valdemar Kobelis Date: Fri, 24 Jan 2025 17:06:39 +0200 Subject: [PATCH 2/2] Create rspec tests --- .../json_api/action_configuration_spec.rb | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/lib/graphql_to_rest/controller/json_api/action_configuration_spec.rb b/spec/lib/graphql_to_rest/controller/json_api/action_configuration_spec.rb index d83d221..894bd93 100644 --- a/spec/lib/graphql_to_rest/controller/json_api/action_configuration_spec.rb +++ b/spec/lib/graphql_to_rest/controller/json_api/action_configuration_spec.rb @@ -73,4 +73,26 @@ end end end + + describe '#model' do + subject(:model) { action_configuration.model } + + before { controller_config.model('User') } + + it 'returns the model configuration' do + expect(model).to be_a(GraphqlToRest::Controller::JsonApi::ModelConfiguration) + end + + it 'inherits the model name from a controller configuration' do + expect(model.name).to eq('User') + end + + context 'when the model name is provided' do + subject(:model) { action_configuration.model('AnotherResponse') } + + it 'overrides the model name' do + expect(model.name).to eq('AnotherResponse') + end + end + end end