git.iko.soy/typeable/servant
on master help sign in
Add `instance HasDocs EmptyAPI`
2cfa718David Turner
doc/tutorial/Docs.lhs+4−3
@@ -38,9 +38,10 @@ Like client function generation, documentation generation amounts to inspecting
38This time however, we have to assist **servant**. While it is able to deduce a lot of things about our API, it can't magically come up with descriptions of the various pieces of our APIs that are human-friendly and explain what's going on "at the business-logic level". A good example to study for documentation generation is our webservice with the `/position`, `/hello` and `/marketing` endpoints from earlier:
38This time however, we have to assist **servant**. While it is able to deduce a lot of things about our API, it can't magically come up with descriptions of the various pieces of our APIs that are human-friendly and explain what's going on "at the business-logic level". A good example to study for documentation generation is our webservice with the `/position`, `/hello` and `/marketing` endpoints from earlier:
39
39
40``` haskell
40``` haskell
41−type ExampleAPI = "position" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Position
41+type ExampleAPI = ("position" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Position
42 :<|> "hello" :> QueryParam "name" String :> Get '[JSON] HelloMessage
42 :<|> "hello" :> QueryParam "name" String :> Get '[JSON] HelloMessage
43− :<|> "marketing" :> ReqBody '[JSON] ClientInfo :> Post '[JSON] Email
43+ :<|> "marketing" :> ReqBody '[JSON] ClientInfo :> Post '[JSON] Email)
44+ :<|> EmptyAPI
44
45
45exampleAPI :: Proxy ExampleAPI
46exampleAPI :: Proxy ExampleAPI
46exampleAPI = Proxy
47exampleAPI = Proxy
@@ -220,7 +221,7 @@ api :: Proxy DocsAPI
220api = Proxy
221api = Proxy
221
222
222server :: Server DocsAPI
223server :: Server DocsAPI
223−server = Server.server3 :<|> Tagged serveDocs where
224+server = (Server.server3 :<|> emptyAPIServer) :<|> Tagged serveDocs where
224 serveDocs _ respond =
225 serveDocs _ respond =
225 respond $ responseLBS ok200 [plain] docsBS
226 respond $ responseLBS ok200 [plain] docsBS
226 plain = ("Content-Type", "text/plain")
227 plain = ("Content-Type", "text/plain")
servant-docs/src/Servant/Docs/Internal.hs+4
@@ -683,6 +683,10 @@ instance OVERLAPPABLE_
683 p2 :: Proxy b
683 p2 :: Proxy b
684 p2 = Proxy
684 p2 = Proxy
685
685
686+-- | The generated docs for @'EmptyAPI'@ are empty.
687+instance HasDocs EmptyAPI where
688+ docsFor Proxy _ _ = emptyAPI
689+
686-- | @"books" :> 'Capture' "isbn" Text@ will appear as
690-- | @"books" :> 'Capture' "isbn" Text@ will appear as
687-- @/books/:isbn@ in the docs.
691-- @/books/:isbn@ in the docs.
688instance (KnownSymbol sym, ToCapture (Capture sym a), HasDocs api)
692instance (KnownSymbol sym, ToCapture (Capture sym a), HasDocs api)