haskell-servant / haskell-servant/servant-swagger

validateEveryToJSON wants ToJSON even for ReqBody

Open
#102 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
123
Forks
34
PR merge metrics
No merged PRs in 30d

Description

With the following API
```hs
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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating validateEveryToJSON and reproducing the UserAPI shown in the issue. Verify that a ReqBody with only FromJSON is accepted without requiring ToJSON, while response types still retain their serialization requirements.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.