Skip to content

feat: Use PrimerJSON for most remaining JSON serializations.#604

Merged
dhess merged 1 commit intomainfrom
dhess/primerjson-all-the-things
Aug 3, 2022
Merged

feat: Use PrimerJSON for most remaining JSON serializations.#604
dhess merged 1 commit intomainfrom
dhess/primerjson-all-the-things

Conversation

@dhess
Copy link
Copy Markdown
Member

@dhess dhess commented Aug 2, 2022

No description provided.

@dhess dhess requested a review from a team August 2, 2022 22:35
Comment thread primer/src/Primer/Name.hs Outdated
Comment on lines +33 to +35
newtype NameCounter = NC Natural
deriving (Eq, Enum, Show, ToJSON, FromJSON)
deriving (Eq, Enum, Show, Generic, Data)
deriving (FromJSON, ToJSON) via PrimerJSON NameCounter
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will change the serialisation, switching from newtype-deriving to generic-deriving. This probably means that openapi.json and the actual api return are out of sync (either before this change or after, I'm not sure!). However, I'm shortly going to be looking at this area again (#607), so am not too worried if it is broken for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did wonder whether we should newtype-derive this, but figured this isn't the time to change it. I missed that we were already using the newtype and this PR actually changes away from that (at a glance, I'd thought it was using anyclass-deriving).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an odd one because the other newtype-derived cases are written as deriving newtype (FromJSON, ToJSON), so why is this different?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect there's no particular reason for it, just an oversight. Deriving strategy annotations are optional.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, in that case, I'll switch back to newtype-deriving for this one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ach, hang on: I think I may have misled us here. The GHC user guide says "In case you try to derive some class on a newtype, and GeneralizedNewtypeDeriving is also on, DeriveAnyClass takes precedence." (see https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/exts/derive_any_class.html)

I'm not sure which extensions are enabled in this file...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of the latest commit for this PR, it now reads deriving newtype (FromJSON, ToJSON). That's the same as everywhere else we derive using newtype so assuming we do want to elide the newtype wrapper in the serialized JSON (and I think we do), that's the correct deriving statement now, yes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking in more detail, this file is using GHC2021 and no other relevant extensions, so I think it has GND enabled but not DeriveAnyClass. I believe my original comment is correct (though maybe my confusion here is a sign that we should use strategy annotations more consistently!).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of the latest commit for this PR, it now reads deriving newtype (FromJSON, ToJSON). That's the same as everywhere else we derive using newtype so assuming we do want to elide the newtype wrapper in the serialized JSON (and I think we do), that's the correct deriving statement now, yes?

Yes, I think that is both what we want, and is consistent with the state before this PR.

@dhess dhess force-pushed the dhess/primerjson-all-the-things branch from 18730e1 to 09a4e24 Compare August 3, 2022 15:27
@dhess dhess enabled auto-merge August 3, 2022 15:28
@dhess dhess disabled auto-merge August 3, 2022 15:31
@dhess dhess enabled auto-merge August 3, 2022 15:38
@dhess dhess added this pull request to the merge queue Aug 3, 2022
Merged via the queue into main with commit 541be4a Aug 3, 2022
@dhess dhess deleted the dhess/primerjson-all-the-things branch August 3, 2022 16:16
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