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

Fix BodyTypes to work with generalized ReqBody' #88

Merged
merged 1 commit into from
Nov 13, 2018
Merged

Conversation

fizruk
Copy link
Member

@fizruk fizruk commented Aug 13, 2018

I've recently discovered that validateEveryToJSON ignored my ReqBody '[Description "...", ...] types. This was because it only considered ReqBody which recently became a synonym for ReqBody '[Required, Strict] in servant-0.13. This PR fixes that.

If you can't update to the latest version of servant-swagger, you can use this workaround locally in the test suite:

-- | Replace every @'ReqBody'' mods@ with 'ReqBody'
-- so that 'validateEveryToJSON' will work for request body types.
type family PatchAPI api where
  PatchAPI (ReqBody' mods cs a :> api) = ReqBody cs a :> PatchAPI api
  PatchAPI ((param :: k) :> api) = param :> PatchAPI api
  PatchAPI (left :<|> right) = PatchAPI left :<|> PatchAPI right
  PatchAPI api = api

...

spec :: Spec
spec = do
  describe "Swagger spec for MyAPI" $ do
    context "ToJSON matches ToSchema" $ do
      validateEveryToJSON (Proxy :: Proxy (PatchAPI MyAPI))
  ...

@fizruk
Copy link
Member Author

fizruk commented Aug 13, 2018

It would nice if there was a warning/type error for this sort of breakages, but I'm not sure how to implement one yet.

@phadej
Copy link
Contributor

phadej commented Aug 13, 2018

Something implies TypeSynonymInstances, I have wondered that (not too hard though) before. Maybe it'sFlexibleInstances?

@fizruk
Copy link
Member Author

fizruk commented Aug 13, 2018

@phadej Yes, according to GHC documentation:

Extension Description
TypeSynonymInstances Enable type synonyms in instance heads. Implied by FlexibleInstances.

However, we don't have either in this module, so I assume it is not needed for type family instances.

@phadej phadej merged commit 6da28ea into master Nov 13, 2018
@phadej phadej deleted the fix-body-types branch November 13, 2018 17:16
fisx pushed a commit to wireapp/servant-swagger that referenced this pull request Jun 1, 2019
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.

2 participants