{"action":"closed","issue":{"url":"https://api.github.com/repos/RESTful-Drupal/restful/issues/800","labels_url":"https://api.github.com/repos/RESTful-Drupal/restful/issues/800/labels{/name}","comments_url":"https://api.github.com/repos/RESTful-Drupal/restful/issues/800/comments","events_url":"https://api.github.com/repos/RESTful-Drupal/restful/issues/800/events","html_url":"https://github.com/RESTful-Drupal/restful/issues/800","id":122614146,"number":800,"title":"DISCOVER data production doesn't work properly?","user":{"login":"jeff-h","id":841871,"avatar_url":"https://avatars.githubusercontent.com/u/841871?v=3","gravatar_id":"","url":"https://api.github.com/users/jeff-h","html_url":"https://github.com/jeff-h","followers_url":"https://api.github.com/users/jeff-h/followers","following_url":"https://api.github.com/users/jeff-h/following{/other_user}","gists_url":"https://api.github.com/users/jeff-h/gists{/gist_id}","starred_url":"https://api.github.com/users/jeff-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeff-h/subscriptions","organizations_url":"https://api.github.com/users/jeff-h/orgs","repos_url":"https://api.github.com/users/jeff-h/repos","events_url":"https://api.github.com/users/jeff-h/events{/privacy}","received_events_url":"https://api.github.com/users/jeff-h/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-16T22:05:52Z","updated_at":"2015-12-17T12:59:37Z","closed_at":"2015-12-17T12:59:37Z","body":"Maybe I'm totally misunderstanding what the OPTIONS call to a resource should return, but RESTful v2 returns something very different than v1.\r\n\r\nIn v2, the response's `data` is an array containing multiple instances of the same discovery data, over and over, one for each entity of the type in question.\r\n\r\nFor example, if I turn on the `restful_example.module` and create two \"article\" nodes, then do an OPTIONS call:\r\n\r\n```sh\r\ncurl -X \"OPTIONS\" \"http://myserver.com/api/v1.0/articles\" \r\n```\r\n\r\nI get **two** copies of the discovery data:\r\n\r\n```json\r\n{\r\n  \"data\": [\r\n    {\r\n      \"id\": {\r\n        \"info\": {\r\n          \"label\": \"ID\",\r\n          \"description\": \"Base ID for the entity.\"\r\n        },\r\n        \"data\": {\r\n          \"type\": \"integer\",\r\n          \"required\": true,\r\n          \"read_only\": true,\r\n          \"cardinality\": 1\r\n        }\r\n      },\r\n      \"label\": {\r\n        \"info\": {\r\n          \"label\": \"Label\",\r\n          \"description\": \"The label of the resource.\"\r\n        },\r\n        \"data\": {\r\n          \"type\": \"string\",\r\n          \"required\": false,\r\n          \"read_only\": false,\r\n          \"cardinality\": 1,\r\n          \"size\": 255\r\n        },\r\n        \"form_element\": {\r\n          \"type\": \"textfield\",\r\n          \"default_value\": \"\",\r\n          \"placeholder\": \"\",\r\n          \"size\": 255,\r\n          \"allowed_values\": null,\r\n          \"title\": \"label\",\r\n          \"description\": \"The label of the resource.\"\r\n        }\r\n      },\r\n      \"self\": []\r\n    },\r\n    {\r\n      \"id\": {\r\n        \"info\": {\r\n          \"label\": \"ID\",\r\n          \"description\": \"Base ID for the entity.\"\r\n        },\r\n        \"data\": {\r\n          \"type\": \"integer\",\r\n          \"required\": true,\r\n          \"read_only\": true,\r\n          \"cardinality\": 1\r\n        }\r\n      },\r\n      \"label\": {\r\n        \"info\": {\r\n          \"label\": \"Label\",\r\n          \"description\": \"The label of the resource.\"\r\n        },\r\n        \"data\": {\r\n          \"type\": \"string\",\r\n          \"required\": false,\r\n          \"read_only\": false,\r\n          \"cardinality\": 1,\r\n          \"size\": 255\r\n        },\r\n        \"form_element\": {\r\n          \"type\": \"textfield\",\r\n          \"default_value\": \"\",\r\n          \"placeholder\": \"\",\r\n          \"size\": 255,\r\n          \"allowed_values\": null,\r\n          \"title\": \"label\",\r\n          \"description\": \"The label of the resource.\"\r\n        }\r\n      },\r\n      \"self\": []\r\n    }\r\n  ],\r\n  \"self\": {\r\n    \"title\": \"Self\",\r\n    \"href\": \"http://myserver.com/api/v1.0/articles\"\r\n  }\r\n}\r\n```\r\n\r\nThis is because in `src/Plugin/resource/DataProvider/DataProvider.php` the `discover` method ends with\r\n\r\n```php\r\n    return $path ? $this->viewMultiple(array($path)) : $this->index();\r\n```\r\n\r\nI don't understand how it could ever work to send the discovery data through `viewMultiple`:\r\n\r\n* if we don't have at least one entity of this type then the OPTIONS request won't return any discovery data — the `data` element is empty\r\n* it returns the OPTIONS data over and over, once for each entity ID it can find (courtesy of the `index()` call)"}}