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

validateEveryToJSON wants ToJSON even for ReqBody #102

Open
jonathanjouty opened this issue May 21, 2019 · 2 comments
Open

validateEveryToJSON wants ToJSON even for ReqBody #102

jonathanjouty opened this issue May 21, 2019 · 2 comments

Comments

@jonathanjouty
Copy link

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.

@jonathanjouty
Copy link
Author

Looks like changing BodyTypes is actually relatively easy, but swagger2 only has validateToJSON and not validateFromJSON.

Seems like implementation was started though:
GetShopTV/swagger2#162

@jonathanjouty
Copy link
Author

Excuse that, I'm blind!
The PR was merged and the function exists:
https://hackage.haskell.org/package/swagger2-2.3.1.1/docs/Data-Swagger-Schema-Generator.html#v:validateFromJSON

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

No branches or pull requests

1 participant