-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: ToJSON/ToSchema instances agree #626
Conversation
f311ab3
to
b9b6198
Compare
dc0ce93
to
e28b192
Compare
b9b6198
to
236523f
Compare
-- Suitable for deriving via, when the ToJSON instance is via PrimerJSON | ||
instance | ||
(Typeable a, Generic a, GToSchema (Rep a), Typeable os, Typeable ks, AesonOptions os) => | ||
ToSchema (CustomJSON (os :: ks) a) | ||
where | ||
declareNamedSchema _ = genericDeclareNamedSchema (fromAesonOptions (aesonOptions @os)) (Proxy @a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether there is a library for this? I am a bit nervous writing it myself as am not entirely convinced it is correct (although the tests we are currently adding should catch that)
4bc2cb6
to
c17a3ca
Compare
d242bf1
to
dc0a2ab
Compare
8ef0fb1
to
0492962
Compare
80eb725
to
b3dee7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This was a lot more work than I (and probably you) expected, but I'm glad we've done it, given the issues it uncovered. This will be a nice safety blanket going forward, as well.
Whoops, misclick. |
Unfortunately cabal-fmt does not yet support references to cabal sublibraries, breaking the source code checks. Support has been implemented, so hopefully we will be able to revert this commit when the next release of cabal-fmt is made. (This commit is preparation for adding some tests to primer-service that will require primer:primer-hedgehog.)
We bump the cabal-version to enable use of sublibrary references.
Instead of importing modules just for common types (e.g. Text), we simply pull in Foreword, which includes most commonly used identifiers.
Note that the old instance (via `Name`) was nonsense: `GlobalName`s and `Name`s are not serialised the same (one is a record, the other is a string)! The instance compiled even though `GlobalName` is not `Coercible` with `Name` since GHC only requires that the corresponding methods of the two instances are `Coercible. Since `ToSchema a` only uses `a` via `Proxy`, this is true for any choices of `a`.
b3dee7f
to
8c6ce4f
Compare
We test all json encodings agree with their declared schema. This is done by manually listing each type to test, so needs to be updated if we serialize other types in the future.