maykinmedia / open-klant

Registratiecomponent voor de opslag en ontsluiting van klantgegevens volgens de Klantinteracties API-specificatie.
Other
2 stars 3 forks source link

Presence of _expand key in Partij depends on number of elements in expanded key #243

Open swrichards opened 1 month ago

swrichards commented 1 month ago

Product versie / Product version

2.2.0

Omschrijf het probleem / Describe the bug

Retrieving a single Partij resource with expand=digitaleAdressen only includes the _expand.digitaleAdresssen key if the number of digitaleAddressen is >0:.

Stappen om te reproduceren / Steps to reproduce

  1. Fetch a Partij without digitaleAddressen, which yields a resource without an _expand key and with an [] digitaleAdresssen key:
curl -s -X GET  \
  'http://localhost:8000/klantinteracties/api/v1/partijen/65440202-dad5-4012-aa59-bc9645d950ba?expand=digitaleAdressen' \
  -H 'Authorization: Token *** '\
  | jq
{
  "uuid": "65440202-dad5-4012-aa59-bc9645d950ba",
  "url": "http://localhost:8000/klantinteracties/api/v1/partijen/65440202-dad5-4012-aa59-bc9645d950ba",
  "nummer": "0000000137",
  "interneNotitie": "",
  "betrokkenen": [],
  "categorieRelaties": [],
   // Empty list, no _expand key
  "digitaleAdressen": [],
  "voorkeursDigitaalAdres": null,
  "vertegenwoordigden": [],
  "rekeningnummers": [],
  "voorkeursRekeningnummer": null,
  "partijIdentificatoren": [],
  "soortPartij": "organisatie",
  "indicatieGeheimhouding": false,
  "voorkeurstaal": "tiv",
  "indicatieActief": true,
  "bezoekadres": {
    "nummeraanduidingId": "",
    "adresregel1": "",
    "adresregel2": "",
    "adresregel3": "",
    "land": ""
  },
  "correspondentieadres": {
    "nummeraanduidingId": "",
    "adresregel1": "",
    "adresregel2": "",
    "adresregel3": "",
    "land": ""
  },
  "partijIdentificatie": {
    "naam": "Test Organisatie"
  }
}
  1. Create a digitaal adres for this user:
curl -s -X POST \
  'http://localhost:8000/klantinteracties/api/v1/digitaleadressen' \
  -H 'Authorization: Token ***' \
  -H 'Content-Type: application/json' \
  -d '{"adres": "12345667", "soortDigitaalAdres": "telnr", "verstrektDoorPartij": {"uuid": "65440202-dad5-4012-aa59-bc9645d950ba"},"verstrektDoorBetrokkene": null,"omschrijving": "foobar"}' \
  jq
{
  "uuid": "14b3c631-236b-4b41-8b33-883bda62dc9d",
  "url": "http://localhost:8000/klantinteracties/api/v1/digitaleadressen/14b3c631-236b-4b41-8b33-883bda62dc9d",
  "verstrektDoorBetrokkene": null,
  "verstrektDoorPartij":
    {
      "uuid": "65440202-dad5-4012-aa59-bc9645d950ba",
      "url": "http://localhost:8000/klantinteracties/api/v1/partijen/65440202-dad5-4012-aa59-bc9645d950ba",
    },
  "adres": "12345667",
  "soortDigitaalAdres": "telnr",
  "omschrijving": "foobar",
}
  1. Re-fetch the object, note the _expand key is now present, as the number of digitaleAdressen is now 1.
curl -s -X GET  \
  'http://localhost:8000/klantinteracties/api/v1/partijen/65440202-dad5-4012-aa59-bc9645d950ba?expand=digitaleAdressen'   \
  -H 'Authorization: Token ***'  \
   | jq                                                                                                                
{
  "uuid": "65440202-dad5-4012-aa59-bc9645d950ba",
  "url": "http://localhost:8000/klantinteracties/api/v1/partijen/65440202-dad5-4012-aa59-bc9645d950ba",
  "nummer": "0000000137",
  "interneNotitie": "",
  "betrokkenen": [],
  "categorieRelaties": [],
  "digitaleAdressen": [
    {
      "uuid": "14b3c631-236b-4b41-8b33-883bda62dc9d",
      "url": "http://localhost:8000/klantinteracties/api/v1/digitaleadressen/14b3c631-236b-4b41-8b33-883bda62dc9d"
    }
  ],
  "voorkeursDigitaalAdres": null,
  "vertegenwoordigden": [],
  "rekeningnummers": [],
  "voorkeursRekeningnummer": null,
  "partijIdentificatoren": [],
  "soortPartij": "organisatie",
  "indicatieGeheimhouding": false,
  "voorkeurstaal": "tiv",
  "indicatieActief": true,
  "bezoekadres": {
    "nummeraanduidingId": "",
    "adresregel1": "",
    "adresregel2": "",
    "adresregel3": "",
    "land": ""
  },
  "correspondentieadres": {
    "nummeraanduidingId": "",
    "adresregel1": "",
    "adresregel2": "",
    "adresregel3": "",
    "land": ""
  },
  "partijIdentificatie": {
    "naam": "Test Organisatie"
  },
  "_expand": {
    "digitaleAdressen": [
      {
        "uuid": "14b3c631-236b-4b41-8b33-883bda62dc9d",
        "url": "http://localhost:8000/klantinteracties/api/v1/digitaleadressen/14b3c631-236b-4b41-8b33-883bda62dc9d",
        "verstrektDoorBetrokkene": null,
        "verstrektDoorPartij": {
          "uuid": "65440202-dad5-4012-aa59-bc9645d950ba",
          "url": "http://localhost:8000/klantinteracties/api/v1/partijen/65440202-dad5-4012-aa59-bc9645d950ba"
        },
        "adres": "12345667",
        "soortDigitaalAdres": "telnr",
        "omschrijving": "foobar"
      }
    ]
  }
}

Verwacht gedrag / Expected behavior

If I provide the expand=digitaleAdressen key, I would expect to always receive the same object shape: if there are no resources, I would simply expect an empty list. The shape should not vary depending on the object state (apart from e.g. nullability and such). Currently, the client has to build in additional guards to check for the shape.

joeribekker commented 1 week ago

Agree with this finding. Estimate: 2 days Needs stakeholder, assuming Dimpact because Sidney reported it.

@mariusvandam needs approval