Skip to content
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

Merged
merged 20 commits into from
Aug 16, 2022
Merged

test: ToJSON/ToSchema instances agree #626

merged 20 commits into from
Aug 16, 2022

Conversation

brprice
Copy link
Contributor

@brprice brprice commented Aug 9, 2022

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.

@brprice brprice force-pushed the brprice/openapi-test branch 2 times, most recently from f311ab3 to b9b6198 Compare August 9, 2022 12:54
@brprice brprice force-pushed the brprice/split-test-library branch from dc0ce93 to e28b192 Compare August 9, 2022 14:24
@brprice brprice force-pushed the brprice/openapi-test branch from b9b6198 to 236523f Compare August 9, 2022 14:25
Comment on lines +26 to +38
-- 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)
Copy link
Contributor Author

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)

@brprice brprice force-pushed the brprice/openapi-test branch from 4bc2cb6 to c17a3ca Compare August 9, 2022 15:20
@brprice brprice force-pushed the brprice/openapi-test branch 7 times, most recently from d242bf1 to dc0a2ab Compare August 10, 2022 10:58
@brprice brprice force-pushed the brprice/split-test-library branch 5 times, most recently from 8ef0fb1 to 0492962 Compare August 12, 2022 11:45
@brprice brprice force-pushed the brprice/openapi-test branch from 80eb725 to b3dee7f Compare August 13, 2022 14:31
@brprice brprice marked this pull request as ready for review August 13, 2022 16:19
@brprice brprice requested a review from a team August 13, 2022 16:19
Copy link
Member

@dhess dhess left a 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.

@georgefst georgefst requested a review from a team August 15, 2022 16:24
@georgefst
Copy link
Contributor

@georgefst georgefst requested a review from https://github.com/orgs/hackworthltd/teams/developers[ now](#626 (comment))

Whoops, misclick.

Base automatically changed from brprice/split-test-library to main August 16, 2022 14:33
brprice added 20 commits August 16, 2022 15:52
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`.
@brprice brprice force-pushed the brprice/openapi-test branch from b3dee7f to 8c6ce4f Compare August 16, 2022 15:43
@brprice brprice added this pull request to the merge queue Aug 16, 2022
Merged via the queue into main with commit 9574053 Aug 16, 2022
@brprice brprice deleted the brprice/openapi-test branch August 16, 2022 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants