Closed infinisil closed 2 years ago
Other approaches were also considered for pretty-printing these structures:
Show
has the problem that it doesn't have newlines and indentation. Ideally this could still be done with e.g. the pretty-show package, however since the Show UUID
instance isn't technically valid, it fails to properly format any structures that have an UUID
in them. I also tried out show-prettyprint but it doesn't format things properly at all for our structures.Pretty
from the prettyprinter package has the problem that you have to write these instances by hand. This is really tedious as we have a lot of structures, and many of them should be derivable by themselves. In addition, we don't really care about the specific text layout that is used. As long as it's a readable tree representation it would work. Having to care about the layout adds extra unnecessary overhead.WebauthnToJSON
class, in order to avoid orphan instances. This has the disadvantage that it requires implementing both generic deriving ourselves (or write all instances manually) and that we have to derive instances for all basic types as well. It also adds extra overhead.Data
class with something like syb. This is also what GHC does. However the problem with this is that our library has GADTs, for which the Data
class seems to neither be derivable automatically, or even implementable manually.
This adds pretty and simple (ideally derived)
ToJSON
instances to all the main types involved, allowing them to be pretty printed using any normal JSON formatter. These instances are then used to pretty-print the responses in the server, to get a result like this for a register, logout, login flow: