dungeon-studio / api.dungeon.studio

Game Master's Companion
MIT License
1 stars 0 forks source link

Fix duplicate entities in Siren response #73

Closed velveteer closed 6 years ago

velveteer commented 6 years ago

Steps to reproduce:

  1. Create a character via POST to /characters with race and discipline fields
  2. List character entities via GET to /characters
  3. Observe duplicates in response field entities (two entities with the same href)

My information:

Request:

GET /characters HTTP/1.1
Host: r.api.dungeon.studio
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: application/vnd.siren+json
Origin: http://localhost:5000
Authorization: Bearer <redacted>
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36
Referer: http://localhost:5000/
Accept-Encoding: gzip, deflate
Accept-Language: en,en-US;q=0.9,fr;q=0.8

Response:

{
  "actions": [
    {
      "href": "/characters",
      "name": "create-character",
      "method": "POST",
      "title": "Create Character",
      "type": "application/json",
      "class": [
        "Create"
      ],
      "fields": [
        {
          "name": "discipline",
          "title": "Discipline",
          "type": "url"
        },
        {
          "name": "race",
          "title": "Race",
          "type": "url"
        }
      ]
    }
  ],
  "entities": [
    {
      "links": [
        {
          "href": "/characters/02abb3a9-c7af-48f9-8449-b1ef90b4bca4",
          "type": "application/vnd.siren+json",
          "rel": [
            "self"
          ],
          "class": [
            "Character"
          ]
        },
        {
          "href": "earthdawn/4e/disciplines/troubadour",
          "title": "Discipline",
          "type": "application/vnd.collection+json",
          "rel": [
            "discipline"
          ],
          "class": [
            "Discipline"
          ]
        },
        {
          "href": "earthdawn/4e/races/elf",
          "title": "Race",
          "type": "application/vnd.collection+json",
          "rel": [
            "race"
          ],
          "class": [
            "Race"
          ]
        }
      ],
      "rel": [
        "item"
      ],
      "class": [
        "Character"
      ]
    },
    {
      "links": [
        {
          "href": "/characters/02abb3a9-c7af-48f9-8449-b1ef90b4bca4",
          "type": "application/vnd.siren+json",
          "rel": [
            "self"
          ],
          "class": [
            "Character"
          ]
        },
        {
          "href": "earthdawn/4e/disciplines/troubadour",
          "title": "Discipline",
          "type": "application/vnd.collection+json",
          "rel": [
            "discipline"
          ],
          "class": [
            "Discipline"
          ]
        },
        {
          "href": "earthdawn/4e/races/elf",
          "title": "Race",
          "type": "application/vnd.collection+json",
          "rel": [
            "race"
          ],
          "class": [
            "Race"
          ]
        }
      ],
      "rel": [
        "item"
      ],
      "class": [
        "Character"
      ]
    }
  ],
  "links": [
    {
      "href": "/characters",
      "type": "application/vnd.siren+json",
      "rel": [
        "self"
      ],
      "class": [
        "Characters"
      ]
    },
    {
      "href": "http://r.collection.dungeon.studio/earthdawn/4e/races",
      "title": "Earthdawn Races",
      "type": "application/vnd.collection+json",
      "rel": [
        "races"
      ],
      "class": [
        "Races"
      ]
    },
    {
      "href": "http://r.collection.dungeon.studio/earthdawn/4e/disciplines",
      "title": "Earthdawn Disciplines",
      "type": "application/vnd.collection+json",
      "rel": [
        "disciplines"
      ],
      "class": [
        "Disciplines"
      ]
    }
  ],
  "class": [
    "Characters"
  ]
}
alunduil commented 6 years ago

Looks like this is due to the multiple paths and a missing DISTINCT keywords in the cypher query. Committing a fix now so we can double check.