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

[#66093] API: capitalize errors correctly, use compact keys

Tobias Dillmannb7b9a91ecbac
diff --git a/docs/api/apiv3/example/README.md b/docs/api/apiv3/example/README.md
index 0d689b5af92..f543e5a15b8 100644
--- a/docs/api/apiv3/example/README.md
+++ b/docs/api/apiv3/example/README.md
@@ -238,10 +238,10 @@ If there are no errors, this field is missing.
```json5
{
- "customFieldXerrors": [
+ "customFieldXErrors": [
{
- "error_code": "ERROR_MATHEMATICAL",
- "error_message": "A mathematical error occurred during calculation. Please review the formula and try again."
+ "code": "ERROR_MATHEMATICAL",
+ "message": "A mathematical error occurred during calculation. Please review the formula and try again."
}
]
}
diff --git a/lib/api/v3/utilities/custom_field_injector.rb b/lib/api/v3/utilities/custom_field_injector.rb
index b8f645f0e6a..23c19b1d84b 100644
--- a/lib/api/v3/utilities/custom_field_injector.rb
+++ b/lib/api/v3/utilities/custom_field_injector.rb
@@ -276,7 +276,7 @@ module API
cache_if: config[:cache_if],
render_nil: true
- @class.property :"#{custom_field.attribute_name}errors",
+ @class.property :"#{custom_field.attribute_name}_errors",
getter: calculated_value_error_getter(custom_field),
cache_if: config[:cache_if],
render_nil: false
@@ -314,8 +314,8 @@ module API
errors = custom_field.calculated_value_errors.where(customized_id: id, customized_type: "Project")
errors.map do |err|
- { error_code: err.error_code,
- error_message: CalculatedValues::ErrorsHelper.calculated_value_error_msg(err) }
+ { code: err.error_code,
+ message: CalculatedValues::ErrorsHelper.calculated_value_error_msg(err) }
end
}
end
diff --git a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb b/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
index 38afd06c5fc..6d00631ebef 100644
--- a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
@@ -217,7 +217,7 @@ RSpec.describe API::V3::Projects::ProjectRepresenter, "rendering" do
end
context "when there is a calculation error" do
- let(:cf_path) { "customField#{calculated_value_custom_field.id}errors" }
+ let(:cf_path) { "customField#{calculated_value_custom_field.id}Errors" }
let!(:calculated_value_error) do
build_stubbed(:calculated_value_error, custom_field: calculated_value_custom_field, customized: project)
@@ -236,8 +236,8 @@ RSpec.describe API::V3::Projects::ProjectRepresenter, "rendering" do
it "has a property for calculation errors" do
expect(subject).to be_json_eql([
{
- error_code: "ERROR_MATHEMATICAL",
- error_message: I18n.t("calculated_values.errors.mathematical")
+ code: "ERROR_MATHEMATICAL",
+ message: I18n.t("calculated_values.errors.mathematical")
}
].to_json).at_path(cf_path)
end