Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

return empty array instead of `null`

ulferts7b4db8460935
diff --git a/lib/api/decorators/sql_collection_representer.rb b/lib/api/decorators/sql_collection_representer.rb
index ebca2749cfb..881d3aa7521 100644
--- a/lib/api/decorators/sql_collection_representer.rb
+++ b/lib/api/decorators/sql_collection_representer.rb
@@ -130,7 +130,7 @@ module API
representation: ->(walker_result) do
replacement = walker_result.replace_map['elements']
- replacement ? "json_agg(#{replacement})" : nil
+ replacement ? "COALESCE(json_agg(#{replacement}), '[]')" : nil
end
end
end
diff --git a/spec/requests/api/v3/capability_resource_spec.rb b/spec/requests/api/v3/capability_resource_spec.rb
index c74494807cf..8d96796fb7c 100644
--- a/spec/requests/api/v3/capability_resource_spec.rb
+++ b/spec/requests/api/v3/capability_resource_spec.rb
@@ -372,10 +372,14 @@ describe 'API v3 capabilities resource', type: :request, content_type: :json do
} }]
end
- it 'is empty' do
+ it 'is empty and includes an empty element set', :aggregate_failures do
expect(subject.body)
.to be_json_eql('0')
.at_path('total')
+
+ expect(subject.body)
+ .to be_json_eql([].to_json)
+ .at_path('_embedded/elements')
end
end