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

No headers bodytype #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Unreleased
----------

* The `HasOpenApi` instance that recurses through `UVerb` responses no
longer demands `ToSchema NoContent`.
* Do not count `NoContent` as a body type if it appears in `Headers
hdrs NoContent`.

1.1.8
-------

Expand All @@ -14,7 +22,7 @@
* Support servant-0.15
- support for 'Stream' and 'StreamBody' combinators
- orphan 'ToSchema (SourceT m a)' instance
* Fix BodyTypes to work with generalized ReqBody'
* Fix BodyTypes to work with generalized ReqBody'
[#88](https://github.com/haskell-servant/servant-swagger/pull/88)

1.1.6
Expand Down
5 changes: 1 addition & 4 deletions src/Servant/OpenApi/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ instance HasOpenApi (UVerb method cs '[]) where
-- | @since <2.0.1.0>
instance
{-# OVERLAPPABLE #-}
( ToSchema a,
HasStatus a,
AllAccept cs,
OpenApiMethod method,
( HasOpenApi (Verb method (StatusOf a) cs a),
HasOpenApi (UVerb method cs as)
) =>
HasOpenApi (UVerb method cs (a ': as))
Expand Down
15 changes: 14 additions & 1 deletion src/Servant/OpenApi/Internal/TypeLevel/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type AddBodyType c cs a as = If (Elem c cs) (a ': as) as
-- completely empty on responses to requests that only accept 'application/json', while
-- setting the content-type in the response accordingly.)
type family BodyTypes' c api :: [*] where
BodyTypes' c (Verb verb b cs (Headers hdrs a)) = AddBodyType c cs a '[]
BodyTypes' c (Verb verb b cs (Headers hdrs a)) = BodyTypes' c (Verb verb b cs a)
BodyTypes' c (Verb verb b cs NoContent) = '[]
BodyTypes' c (Verb verb b cs a) = AddBodyType c cs a '[]
BodyTypes' c (ReqBody' mods cs a :> api) = AddBodyType c cs a (BodyTypes' c api)
Expand All @@ -95,4 +95,17 @@ type family BodyTypes' c api :: [*] where
#if MIN_VERSION_servant(0,19,0)
BodyTypes' c (NamedRoutes api) = BodyTypes' c (ToServantApi api)
#endif
-- Handle UVerb by recursively expanding it to BodyTypes' c (Verb ...)
-- Unwrap WithStatus explicitly to avoid trying to expand
-- `Verb .. (WithStatus n a)` later on.
BodyTypes' c (UVerb verb cs ((WithStatus n a) ': as)) =
AppendList (BodyTypes' c (Verb verb (StatusOf a) cs a)) (BodyTypes' c (UVerb verb cs as))
-- If we don't have a WithStatus wrapper, it might be 'NoContent' or
-- some other type with a `HasStatus` instance. The catch-all will
-- expand it to '[] if we can't extract a useful body type from it,
-- so that's fine.
BodyTypes' c (UVerb verb cs (a ': as)) =
AppendList (BodyTypes' c (Verb verb (StatusOf a) cs a)) (BodyTypes' c (UVerb verb cs as))
BodyTypes' c (UVerb verb cs '[]) = '[]

BodyTypes' c api = '[]