diff --git a/app/services/api/parse_resource_params_service.rb b/app/services/api/parse_resource_params_service.rb index b4441830958..73888a8931e 100644 --- a/app/services/api/parse_resource_params_service.rb +++ b/app/services/api/parse_resource_params_service.rb @@ -72,16 +72,17 @@ module API .from_hash(request_body) deep_to_h(struct) + .deep_symbolize_keys end def struct - OpenStruct.new + Hashie::Mash.new end def deep_to_h(value) # Does not yet factor in Arrays. There hasn't been the need to do that, yet. case value - when OpenStruct, Hash + when Hashie::Mash, Hash value.to_h.transform_values do |sub_value| deep_to_h(sub_value) end diff --git a/app/services/api/v3/parse_resource_params_service.rb b/app/services/api/v3/parse_resource_params_service.rb index 575626c27f9..4f0c312f315 100644 --- a/app/services/api/v3/parse_resource_params_service.rb +++ b/app/services/api/v3/parse_resource_params_service.rb @@ -46,10 +46,10 @@ module API end def struct - if model&.respond_to?(:available_custom_fields) - OpenStruct.new available_custom_fields: model.available_custom_fields(model.new) - else - super + super.tap do |instance| + if model.respond_to?(:available_custom_fields) + instance.available_custom_fields = model.available_custom_fields(model.new) + end end end end diff --git a/app/services/api/v3/work_package_collection_from_query_service.rb b/app/services/api/v3/work_package_collection_from_query_service.rb index ded1386b8fa..61caf0f03e2 100644 --- a/app/services/api/v3/work_package_collection_from_query_service.rb +++ b/app/services/api/v3/work_package_collection_from_query_service.rb @@ -125,7 +125,7 @@ module API end def format_query_sums(sums) - OpenStruct.new(format_column_keys(sums).merge(available_custom_fields: WorkPackageCustomField.summable.to_a)) + Hashie::Mash.new(format_column_keys(sums).merge(available_custom_fields: WorkPackageCustomField.summable.to_a)) end def format_column_keys(hash_by_column) diff --git a/lib/api/utilities/meta_property.rb b/lib/api/utilities/meta_property.rb index 1adf15bce10..326a97d3da0 100644 --- a/lib/api/utilities/meta_property.rb +++ b/lib/api/utilities/meta_property.rb @@ -58,7 +58,7 @@ module API protected def meta_representer - meta_representer_class.create(meta || OpenStruct.new, current_user: current_user) + meta_representer_class.create(meta || Hashie::Mash.new, current_user: current_user) end def meta_representer_class diff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rb index 6584f5ec7c6..9404c5711af 100644 --- a/lib/api/v3/projects/project_representer.rb +++ b/lib/api/v3/projects/project_representer.rb @@ -58,11 +58,11 @@ module API struct.status = struct.status_attributes # Remove temporary attributes workaround - struct.delete_field(:status_attributes) + struct.delete(:status_attributes) # Remove nil status_explanation when passed as nil if struct.respond_to?(:status_explanation) - struct.delete_field(:status_explanation) + struct.delete(:status_explanation) end end end @@ -216,7 +216,7 @@ module API end }, setter: ->(fragment:, represented:, **) { - represented.status_attributes ||= OpenStruct.new + represented.status_attributes ||= Hashie::Mash.new link = ::API::Decorators::LinkObject.new(represented.status_attributes, path: :project_status, @@ -235,7 +235,7 @@ module API plain: false) }, setter: ->(fragment:, represented:, **) { - represented.status_attributes ||= OpenStruct.new + represented.status_attributes ||= Hashie::Mash.new represented.status_attributes[:explanation] = fragment["raw"] } diff --git a/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rb b/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rb index 1215ce2fafe..5884b7a4060 100644 --- a/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rb +++ b/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rb @@ -32,7 +32,7 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do include ::API::V3::Utilities::PathHelper let(:object) do - OpenStruct.new available_custom_fields: [] + Hashie::Mash.new available_custom_fields: [] end let(:user) { build_stubbed(:user) } let(:representer) do @@ -117,16 +117,16 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do end it 'does set status to nil' do - project = representer.from_hash(hash).to_h + project = representer.from_hash(hash) expect(project) .to have_key(:status) status = project[:status] - expect(status.to_h) + expect(status) .to have_key(:code) - expect(status.to_h) + expect(status) .not_to have_key(:explanation) expect(status[:code]) @@ -150,7 +150,7 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do end it 'sets the parent_id to the value' do - project = representer.from_hash(hash).to_h + project = representer.from_hash(hash) expect(project[:parent_id]) .to eq "5" @@ -169,7 +169,7 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do end it 'sets the parent_id to nil' do - project = representer.from_hash(hash).to_h + project = representer.from_hash(hash) expect(project) .to have_key(:parent_id) @@ -191,7 +191,7 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do end it 'omits the parent information' do - project = representer.from_hash(hash).to_h + project = representer.from_hash(hash) expect(project) .not_to have_key(:parent_id) diff --git a/spec/services/api/v3/work_package_collection_from_query_service_spec.rb b/spec/services/api/v3/work_package_collection_from_query_service_spec.rb index 7e1ce78ac1b..8cdbd387d8e 100644 --- a/spec/services/api/v3/work_package_collection_from_query_service_spec.rb +++ b/spec/services/api/v3/work_package_collection_from_query_service_spec.rb @@ -250,7 +250,7 @@ describe ::API::V3::WorkPackageCollectionFromQueryService, .to receive(:summable) .and_return(custom_fields) - expected = OpenStruct.new(estimated_hours: 0.0, available_custom_fields: custom_fields) + expected = Hashie::Mash.new(estimated_hours: 0.0, available_custom_fields: custom_fields) expect(subject.total_sums) .to eq(expected)