プロジェクト

全般

プロフィール

Vote #77411

完了

Rest API for Custom Fields does not return keys for key/value types

Admin Redmine さんが4年以上前に追加. 4年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
REST API_32
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
32
version_id:
110
issue_org_id:
22745
author_id:
150957
assigned_to_id:
1
comments:
3
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
112
ステータス-->[Closed]

説明

When using the REST API to retrieve the list of custom_fields by calling http://localhost:3000/custom_fields.json , if there is a Key/Value list type custom fields only the value comes back, as in the example below:


"id": 5,
"name": "Lifecycle Status",
"customized_type": "version",
"field_format": "enumeration",
"regexp": "",
"visible": true,
"possible_values": [
  {
    "value": "2",
  },
  {
    "value": "3",
  },
  {
    "value": "4",
  }
]

to replace this block:
It would be much more useful to get the name back as well, like:


"id": 5,
"name": "Lifecycle Status",
"customized_type": "version",
"field_format": "enumeration",
"regexp": "",
"visible": true,
"possible_values": [
  {
    "value": "2",
    "label": "Planned"
  },
  {
    "value": "3",
    "label": "In Progress"
  },
  {
    "value": "4",
    "label": "Complete"
  }
]

I did this in a plugin by overriding app/views/custom_fields/index.api.rsb and adding and if block checking for EnumerationFormat.


      values = field.possible_values_options
      if values.present?
        api.array :possible_values do
          values.each do |label, value|
            api.possible_value do
              api.value value || label
              if field.format.class.name.demodulize == 'EnumerationFormat'
                  api.label label
              end
            end
          end
        end
      end

I was going to just put the 'api.label label' line in without the if statement but it also takes effect for list types where label and value appear to be the same. There is almost certainly a better way to do this.


journals

--------------------------------------------------------------------------------
Stephen Stuart wrote:

> I was going to just put the 'api.label label' line in without the if statement but it also takes effect for list types where label and value appear to be the same.

I've added the label for all custom fields that have possible values
It's better to have the same behaviour no matter the custom field type, even if value and label are the same.
Thanks for pointing this out.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

relates,New,26017,Get also labels for key/value custom fields by API

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0