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

Fix value schema property to accept camelCase only

Dombi Attiladb00f1cc3b6c
diff --git a/docs/api/apiv3/paths/values_schema.yml b/docs/api/apiv3/paths/values_schema.yml
index e1f1522cba3..391220546ab 100644
--- a/docs/api/apiv3/paths/values_schema.yml
+++ b/docs/api/apiv3/paths/values_schema.yml
@@ -4,7 +4,9 @@ get:
parameters:
- name: id
in: path
- description: The identifier of the value. This is typically the value of the `property` property of the `Values` resource.
+ description: |-
+ The identifier of the value. This is typically the value of the `property` property of
+ the `Values` resource. It should be in lower camelcase format.
example: 'startDate'
required: true
schema:
@@ -31,6 +33,17 @@ get:
message: The requested resource could not be found.
description: |-
Returned if the schema does not exist.
+ '400':
+ content:
+ application/hal+json:
+ schema:
+ $ref: '../components/schemas/error_response.yml'
+ example:
+ _type: Error
+ errorIdentifier: urn:openproject-org:api:v3:errors:BadRequest
+ message: "Bad request: property is invalid"
+ description: |-
+ Returned if the requested property id is not in a lower camel case format.
tags:
- Values::Property
description: The schema of a `Values` resource.
diff --git a/lib/api/v3/values/schemas/value_schema_api.rb b/lib/api/v3/values/schemas/value_schema_api.rb
index 04333d9b711..866296e7fb0 100644
--- a/lib/api/v3/values/schemas/value_schema_api.rb
+++ b/lib/api/v3/values/schemas/value_schema_api.rb
@@ -29,8 +29,12 @@
module API::V3::Values::Schemas
class ValueSchemaAPI < ::API::OpenProjectAPI
resources :schemas do
+ params do
+ requires :property, desc: 'Name of the schema property', regexp: /^[a-z][a-zA-Z0-9]*$/
+ end
+
get ':property' do
- ValueSchemaFactory.for(params[:property]).tap do |representer|
+ ValueSchemaFactory.for(params[:property].underscore).tap do |representer|
raise API::Errors::NotFound unless representer
end
end
diff --git a/lib/api/v3/values/schemas/value_schema_factory.rb b/lib/api/v3/values/schemas/value_schema_factory.rb
index ca16c919e2f..bb427a1cc57 100644
--- a/lib/api/v3/values/schemas/value_schema_factory.rb
+++ b/lib/api/v3/values/schemas/value_schema_factory.rb
@@ -39,7 +39,7 @@ module API::V3::Values::Schemas
::API::V3::Values::Schemas::PropertySchemaRepresenter
.new(model_for(property),
current_user: nil,
- self_link: api_v3_paths.value_schema(property))
+ self_link: api_v3_paths.value_schema(property.camelcase(:lower)))
end
def all
diff --git a/spec/lib/api/v3/values/schemas/value_schema_factory_spec.rb b/spec/lib/api/v3/values/schemas/value_schema_factory_spec.rb
index 5e2b0e07071..5d0594b867f 100644
--- a/spec/lib/api/v3/values/schemas/value_schema_factory_spec.rb
+++ b/spec/lib/api/v3/values/schemas/value_schema_factory_spec.rb
@@ -56,7 +56,7 @@ describe ::API::V3::Values::Schemas::ValueSchemaFactory do
.to have_received(:new)
.with(API::V3::Values::Schemas::Model.new(I18n.t('attributes.start_date'), 'Date'),
current_user: nil,
- self_link: api_v3_paths.value_schema(property))
+ self_link: api_v3_paths.value_schema(property.camelcase(:lower)))
end
end
@@ -75,7 +75,7 @@ describe ::API::V3::Values::Schemas::ValueSchemaFactory do
.to have_received(:new)
.with(API::V3::Values::Schemas::Model.new(I18n.t('attributes.due_date'), 'Date'),
current_user: nil,
- self_link: api_v3_paths.value_schema(property))
+ self_link: api_v3_paths.value_schema(property.camelcase(:lower)))
end
end
diff --git a/spec/requests/api/v3/values/schemas/value_schema_resource_spec.rb b/spec/requests/api/v3/values/schemas/value_schema_resource_spec.rb
index c383b7846a0..5385eee29d5 100644
--- a/spec/requests/api/v3/values/schemas/value_schema_resource_spec.rb
+++ b/spec/requests/api/v3/values/schemas/value_schema_resource_spec.rb
@@ -43,8 +43,8 @@ describe ::API::V3::Values::Schemas::ValueSchemaAPI,
end
context 'for a logged in user' do
- context 'for a property' do
- let(:schema_id) { 'start_date' }
+ context 'for a startDate' do
+ let(:schema_id) { 'startDate' }
it 'returns the schema', :aggregate_failures do
expect(last_response.status)
@@ -63,13 +63,38 @@ describe ::API::V3::Values::Schemas::ValueSchemaAPI,
.at_path('value/name')
end
end
- end
- context 'for a logged in user and a non existing property' do
- context 'for a property' do
+ context 'for a dueDate' do
+ let(:schema_id) { 'dueDate' }
+
+ it 'returns the schema', :aggregate_failures do
+ expect(last_response.status)
+ .to eq 200
+
+ expect(last_response.body)
+ .to be_json_eql('Schema'.to_json)
+ .at_path('_type')
+
+ expect(last_response.body)
+ .to be_json_eql('Date'.to_json)
+ .at_path('value/type')
+
+ expect(last_response.body)
+ .to be_json_eql('Finish date'.to_json)
+ .at_path('value/name')
+ end
+ end
+
+ context 'for a non existing property' do
let(:schema_id) { 'bogus' }
it_behaves_like 'not found'
end
+
+ context 'for an underscore property' do
+ let(:schema_id) { 'start_date' }
+
+ it_behaves_like 'param validation error'
+ end
end
end