Skip to content

Commit 97b2fd0

Browse files
Teach BodyTypes' to recurse through UVerb endpoints
1 parent 2008733 commit 97b2fd0

File tree

1 file changed

+13
-0
lines changed
  • src/Servant/OpenApi/Internal/TypeLevel

1 file changed

+13
-0
lines changed

src/Servant/OpenApi/Internal/TypeLevel/API.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,17 @@ type family BodyTypes' c api :: [*] where
9595
#if MIN_VERSION_servant(0,19,0)
9696
BodyTypes' c (NamedRoutes api) = BodyTypes' c (ToServantApi api)
9797
#endif
98+
-- Handle UVerb by recursively expanding it to BodyTypes' c (Verb ...)
99+
-- Unwrap WithStatus explicitly to avoid trying to expand
100+
-- `Verb .. (WithStatus n a)` later on.
101+
BodyTypes' c (UVerb verb cs ((WithStatus n a) ': as)) =
102+
AppendList (BodyTypes' c (Verb verb (StatusOf a) cs a)) (BodyTypes' c (UVerb verb cs as))
103+
-- If we don't have a WithStatus wrapper, it might be 'NoContent' or
104+
-- some other type with a `HasStatus` instance. The catch-all will
105+
-- expand it to '[] if we can't extract a useful body type from it,
106+
-- so that's fine.
107+
BodyTypes' c (UVerb verb cs (a ': as)) =
108+
AppendList (BodyTypes' c (Verb verb (StatusOf a) cs a)) (BodyTypes' c (UVerb verb cs as))
109+
BodyTypes' c (UVerb verb cs '[]) = '[]
110+
98111
BodyTypes' c api = '[]

0 commit comments

Comments
 (0)