-
Notifications
You must be signed in to change notification settings - Fork 59
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
ToSchema, proxy, and GeneralizedNewtypeDeriving #150
Comments
Alternatively we could have |
@michalrus note that GND is questionable for |
Ohhhhhh, right, absolutely! I don’t want that. Sorry for the noise! |
Hi! I recently found myself affected by this design decision as well. I would be quite interested if there is some way to have a workaround. If so I'd be willing to help with the implementation. My use case involves data MyRecord = MyRecord
{ ...
} deriving stock Generic
deriving (FromJSON, ToJSON, Flow, ToSchema) via APIEncoding SnakeCase MyRecord This is what I want to write (see here for a gist). Everything works beautifully until we get to Now about the solution: @phadej It sounds like you had an idea, but it is not immediately clear to me what it is. Maybe you could illuminate? Something involved the I suspect there would be compatibility concerns around simply changing the function signature to take a concrete Is there a better way? |
Adding new method won't help GND/DerivingVia. All methods have to be coercible
…Sent from my iPhone
On 22 Feb 2019, at 19.34, Cliff Harvey ***@***.***> wrote:
Hi! I recently found myself affected by this design decision as well. I would be quite interested if there is some way to have a workaround. If so I'd be willing to help with the implementation.
My use case involves DerivingVia. I have a newtype that keeps track of how to transform the JSON encodings. This is quite valuable to us because it prevents the various type classes that know about the encoding from getting out of sync.
data MyRecord = MyRecord
{ ...
} deriving stock Generic
deriving (FromJSON, ToJSON, Flow, ToSchema) via APIEncoding SnakeCase MyRecord
This is what I want to write (see here for a gist). Everything works beautifully until we get to ToSchema for the reason mentioned in this issue: the type parameter role is assumed to be nominal.
Now about the solution:
@phadej It sounds like you had an idea, but it is not immediately clear to me what it is. Maybe you could illuminate? Something involved the Tagged type?
I suspect there would be compatibility concerns around simply changing the function signature to take a concrete Proxy (is anyone using the fact that its polymorphic?) so I suppose we could add a new method with this signature, and require that either one be specified. Admittedly it does seem a bit unfortunate to pollute the class in this way though.
Is there a better way?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@fieldstrength I know this is not as neat as instance ToSchema Example where
declareNamedSchema _ = declareNamedSchema (Proxy @ (APIEncoding SnakeCaseDropPrefix Example)) See the full gist (based on yours). @phadej how much code would we break if we switch from |
Thanks for the feedback and pointers! I was encouraged @fizruk that you seem positive towards the change so I went ahead and made the PR. Happily, it is a quite small patch. I have also sanity-checked that it does indeed allow |
This won’t work:
with the following error:
Perhaps when using a concrete
Data.Proxy.Proxy
instead offorall proxy. proxy
, this would’ve worked?The text was updated successfully, but these errors were encountered: