hmrc/play-hal

Inconsistent JSON structure when using embedded resources

Opened this issue · 0 comments

Specifying one item in the embedded Vector results in a json a structure like so:

"_embedded": {
    "kids": {
      "_links": {
        "self": {
          "href": "/people/summer"
        }
      },
      "name": "Summer",
      "age": 18
    }
}

Specifying multiple items in the embedded Vector results in a json a structure with an array like so:

  "_embedded": {
    "kids": [
      {
        "_links": {
          "self": {
            "href": "/people/morty"
          }
        },
        "name": "Morty",
        "age": 14
      },
      {
        "_links": {
          "self": {
            "href": "/people/summer"
          }
        },
        "name": "Summer",
        "age": 18
      }
    ]
  }

While this does technically respect the specification, it provides an inconsistent schema for resources with dynamic lists. Lists that can vary between 0, 1, and many resources are affected. It would be better if it was possible to specify the plurality of the embedded resource when creating it.

I haven't tested, but I imagine this issue will also apply to links.