Skip to content

validateEveryToJSON wants ToJSON even for ReqBody #102

@jonathanjouty

Description

@jonathanjouty

With the following API

type UserAPI
  = (Capture "user_id" UserId :> Get '[JSON] User)
  :<|> (Capture "new" :> ReqBody '[JSON] NewUser :> Post '[JSON] UserId)

and only the following instances

newtype UserId = ...
instance FromHttpApiData UserId
instance ToJSON UserId

data User = ...
instance ToJSON User

data NewUser = ...
instance FromJSON NewUser

It is not possible to use validateEveryToJSON because it expects instance ToJSON NewUser even though the UserAPI is perfectly usable as NewUser is only used in ReqBody and thus only requires a FromJSON instance.

Of course an easy fix is to just add a ToJSON instance, which is low risk compared to adding FromJSON instances for things you only want to send out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions