serokell / coffer

Multi-backend password store with multiple frontends
4 stars 2 forks source link

Prettify JSON instances #82

Closed dcastro closed 2 years ago

dcastro commented 2 years ago

This issue is blocked by #37. It would probably be a good idea to do #83 first.

Clarification and motivation

The JSON representation of the web API leaks a lot of internal details about our data structures. For example, the /view endpoint leaks a lot of haskell field names such as dEntries and unEntryPath and haskell constructor names such as VRDirectory:

{
  "contents": {
    "dEntries": [],
    "dSubdirs": {
      "dir": {
        "dEntries": [
          {
            "ePath": {
              "unEntryPath": [
                "dir",
                "entry3"
              ]
            },
            "eFields": {
              "user": {
                "fValue": "diogo",
                "fVisibility": "public",
                "fDateModified": "2022-04-28T17:21:56.774631254Z"
              }
            },
            "eDateModified": "2022-04-28T17:21:56.774631254Z",
            "eMasterField": null,
            "eTags": []
          }
        ],
        "dSubdirs": {}
      }
    }
  },
  "tag": "VRDirectory"
}

In some cases, it's just a matter of using the right functions for renaming fields (e.g. with the aeson-casing package):

deriveJSON (aesonPrefix camelCase) ''TypeName

In other cases, the instances should be handcrafted. E.g., the entry path should be rendered as "/dir/entry3" rather than:

"unEntryPath": [
  "dir",
  "entry3"
]

Acceptance criteria