Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use object instead of array for actions #66

Open
cmbrandenburg opened this issue Dec 12, 2015 · 4 comments
Open

Use object instead of array for actions #66

cmbrandenburg opened this issue Dec 12, 2015 · 4 comments

Comments

@cmbrandenburg
Copy link

Actions are contained within an array where each array element is an object that must contain a name field that is unique to the array. Client behavior is undefined if two actions have the same name.

This sounds exactly like a use case for using an object instead of an array, with the name field being the key for each action.

"actions": {
    "add-item": {
      "title": "Add Item",
      "method": "POST",
      "href": "http://api.x.io/orders/42/items",
      "type": "application/x-www-form-urlencoded",
      "fields": [
        { "name": "orderNumber", "type": "hidden", "value": "42" },
        { "name": "productCode", "type": "text" },
        { "name": "quantity", "type": "number" }
      ]
    }
  }

An object eliminates the possibility of undefined behavior.

Why not use an object?

@m0x72
Copy link

m0x72 commented Dec 16, 2015

The restriction for action field names to be unique, was introduced with the last merged pull request #64. It seems like an accident to me, as it forbids multiple values for an action field, as found in radio or checkbox inputs.
Let's wait for an answer on the PR. :)

@cmbrandenburg
Copy link
Author

@m0x72 I think we're talking about two difference things. I'm talking about the name field of an action object, not the name field of a field object. The word “field” is overloaded here. In one sense, it means a key-value pair in a JSON object. In the other sense, it means the siren concept of an input field.

The snippet I gave above is in contrast to the snippet in the README.md on the front page of this project. Below is the original snippet. Notice the snippet above replaces the array of action objects with an object of action objects, with each action object keyed using its name.

"actions": [
    {
      "name": "add-item",
      "title": "Add Item",
      "method": "POST",
      "href": "http://api.x.io/orders/42/items",
      "type": "application/x-www-form-urlencoded",
      "fields": [
        { "name": "orderNumber", "type": "hidden", "value": "42" },
        { "name": "productCode", "type": "text" },
        { "name": "quantity", "type": "number" }
      ]
    }
  ],

@m0x72
Copy link

m0x72 commented Dec 17, 2015

Ah, I'm so sorry. I mixed them up.

So yes, indeed a valid concern. It simplifies action lookup as well, but likely breaks any current implementations. Calls for a new major version?

@pke
Copy link

pke commented Mar 17, 2017

I also wondered why it is not an object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants