From 2bbcaf3fd6b9f7440d9ceb1f993813ea7c8d2e49 Mon Sep 17 00:00:00 2001 From: Jan Sandbrink Date: Thu, 12 Mar 2015 16:47:58 +0100 Subject: [PATCH] make _type in schema indicate the schemas type instead of indicating that the described resource has something called "_type" --- config/locales/de.yml | 1 - config/locales/en.yml | 1 - doc/apiv3-documentation.apib | 19 ++++--------------- lib/api/decorators/schema.rb | 4 ++++ .../form/work_package_payload_representer.rb | 4 ---- .../schema/work_package_schema_representer.rb | 9 --------- .../work_package_payload_representer_spec.rb | 2 -- .../work_package_schema_representer_spec.rb | 8 ++------ 8 files changed, 10 insertions(+), 38 deletions(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index f57e82c46d..28e5641542 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1676,7 +1676,6 @@ de: api_v3: attributes: - _type: "Ressourcenart" lock_version: "Sperrversion" errors: code_401: "Sie müssen sich authentifizieren, um auf die Ressource zugreifen zu können." diff --git a/config/locales/en.yml b/config/locales/en.yml index 353ae4ca4a..88c97fb28d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1667,7 +1667,6 @@ en: api_v3: attributes: - _type: "Resource Type" lock_version: "Lock Version" errors: code_401: "You need to be authenticated to access this resource." diff --git a/doc/apiv3-documentation.apib b/doc/apiv3-documentation.apib index f3c8014279..e3add7db8e 100644 --- a/doc/apiv3-documentation.apib +++ b/doc/apiv3-documentation.apib @@ -767,7 +767,7 @@ contain a default value for that property. Nevertheless the client will also rec The content of this element *can* be used as a template for the request body of a call to **validate** or **commit**. A call to **validate** and **commit** does not need to include all properties that were defined in the `payload` section. -It is only necessary to include the properties that you want to change, as well as the `_type` and a `lockVersion` if one is present. +It is only necessary to include the properties that you want to change, as well as the `lockVersion` if one is present. However you *may* include all the properties sent in the `payload` section. ### Schema @@ -830,10 +830,6 @@ That is because the main purpose of a form is helping the client to sort out val "type": "Integer", "writable": false }, - "_type": { - "type": "MetaType", - "writable": false - }, "subject": { "type": "String", "minLength": 1, @@ -1608,6 +1604,7 @@ Note that regular expressions used in the API follow the rules of [Ruby Regular + Body { + "_type": "Schema", "_links": { "self": { "href": "/api/v3/example/schema" } }, @@ -1617,11 +1614,6 @@ Note that regular expressions used in the API follow the rules of [Ruby Regular "type": "Integer", "writable": false }, - "_type": { - "name": "Resource Type", - "type": "MetaType", - "writable": false - }, "subject": { "name": "Subject", "type": "String", @@ -2767,10 +2759,8 @@ the human readable name of custom fields.* When calling this endpoint the client provides a single object, containing the properties and links that it wants to change, in the body. Note that it is only allowed to provide properties or links supporting the **write** operation. -Additionally to the fields the client wants to change, it is mandatory to provide: - -* The `_type` which should as of now always be `WorkPackage` -* The value of `lockVersion` which was received by the `GET` request this change originates from +Additionally to the fields the client wants to change, it is mandatory to provide the value of `lockVersion` which was received +by the `GET` request this change originates from. The value of `lockVersion` is used to implement [optimistic locking](http://en.wikipedia.org/wiki/Optimistic_concurrency_control). @@ -2784,7 +2774,6 @@ The value of `lockVersion` is used to implement [optimistic locking](http://en.w + Request (application/json) { - "_type": "WorkPackage", "lockVersion": 13, "subject": "Lorem" "parentId": "42" diff --git a/lib/api/decorators/schema.rb b/lib/api/decorators/schema.rb index 8ad2b332a4..7e0f648339 100644 --- a/lib/api/decorators/schema.rb +++ b/lib/api/decorators/schema.rb @@ -142,6 +142,10 @@ module API self.class.represented_class.human_attribute_name(object) end end + + def _type + 'Schema' + end end end end diff --git a/lib/api/v3/work_packages/form/work_package_payload_representer.rb b/lib/api/v3/work_packages/form/work_package_payload_representer.rb index 107dc893b9..48d0b75b64 100644 --- a/lib/api/v3/work_packages/form/work_package_payload_representer.rb +++ b/lib/api/v3/work_packages/form/work_package_payload_representer.rb @@ -120,10 +120,6 @@ module API property :updated_at, getter: -> (*) { nil }, render_nil: false - def _type - 'WorkPackage' - end - private def datetime_formatter diff --git a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb index c8538a4044..3fec437192 100644 --- a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb +++ b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb @@ -59,11 +59,6 @@ module API end end - schema :_type, - type: 'MetaType', - name_source: -> (*) { I18n.t('api_v3.attributes._type') }, - writable: false - schema :lock_version, type: 'Integer', name_source: -> (*) { I18n.t('api_v3.attributes.lock_version') }, @@ -194,10 +189,6 @@ module API def current_user context[:current_user] end - - def _type - 'MetaType' - end end end end diff --git a/spec/lib/api/v3/work_packages/form/work_package_payload_representer_spec.rb b/spec/lib/api/v3/work_packages/form/work_package_payload_representer_spec.rb index e0837b0e28..3d1e5d4076 100644 --- a/spec/lib/api/v3/work_packages/form/work_package_payload_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/form/work_package_payload_representer_spec.rb @@ -43,8 +43,6 @@ describe ::API::V3::WorkPackages::Form::WorkPackagePayloadRepresenter do context 'generation' do subject(:generated) { representer.to_json } - it { is_expected.to include_json('WorkPackage'.to_json).at_path('_type') } - describe 'work_package' do it { is_expected.to have_json_path('subject') } diff --git a/spec/lib/api/v3/work_packages/work_package_schema_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_schema_representer_spec.rb index 770cf413b9..c594c2fe0f 100644 --- a/spec/lib/api/v3/work_packages/work_package_schema_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/work_package_schema_representer_spec.rb @@ -50,12 +50,8 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do subject(:generated) { representer.to_json } describe '_type' do - it_behaves_like 'has basic schema properties' do - let(:path) { '_type' } - let(:type) { 'MetaType' } - let(:name) { I18n.t('api_v3.attributes._type') } - let(:required) { true } - let(:writable) { false } + it 'is indicated as Schema' do + is_expected.to be_json_eql('Schema'.to_json).at_path('_type') end end