NorfairKing / autodocodec

self(auto)- documenting encoders and decoders
MIT License
121 stars 20 forks source link

Error or warn on unknown fields #37

Closed soenkehahn closed 1 year ago

soenkehahn commented 1 year ago

Is it possible to use autodocodec to parse json or yaml while either failing or warning on unknown fields? aeson provides rejectUnknownFields, but I couldn't find a way to plug in Options into autodocodec.

NorfairKing commented 1 year ago

@soenkehahn You'd have to write your own decoder, but I think it's possible because we know all the fields statically.

soenkehahn commented 1 year ago

Thanks for the reply! Are you saying it's possible for me to implement this without modifying autodocodec? If yes, I'm not sure what you mean by "write your own decoder". Codecs seem to encompass both encoders and decoders, and I'm not sure how I would go about writing my own decoder while using a provided decoder, if that makes sense. Any pointers appreciated!

NorfairKing commented 1 year ago

@soenkehahn Sorry I've not been very clear. It's easy for me to forget context that I only have because I wrote this code.

A codec is just a value that represents an idea. This function does the decoding: https://github.com/NorfairKing/autodocodec/blob/fa4d53e6c7694427c9d777b883fc446c4f3651b0/autodocodec/src/Autodocodec/Aeson/Decode.hs#L31-L37 You could write your own version to warn or reject on unknown fields.

Icelandjack commented 1 year ago

Is it possible to add support for this (decoder?) to the library so that users can configure this behaviour. I know you have already closed this but would you accept a pull request?

NorfairKing commented 1 year ago

@Icelandjack I think my "closed" communication was not clear. I just meant that I haven't planned to add it myself. A PR would be welcome!