From 7445d56c6808d0300915d3ea44c3fac567cfcc7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Hahn?= Date: Thu, 28 Jan 2016 15:46:56 +0100 Subject: [PATCH] tutorial: make Docs.lhs compile --- doc/tutorial/Docs.lhs | 16 ++++++++-------- doc/tutorial/tutorial.cabal | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/tutorial/Docs.lhs b/doc/tutorial/Docs.lhs index 2aa2c377..c006c0b1 100644 --- a/doc/tutorial/Docs.lhs +++ b/doc/tutorial/Docs.lhs @@ -61,8 +61,8 @@ instance ToCapture (Capture "y" Int) where DocCapture "y" -- name "(integer) position on the y axis" -- description -instance ToSample Position Position where - toSample _ = Just (Position 3 14) -- example of output +instance ToSample Position where + toSamples _ = singleSample (Position 3 14) -- example of output instance ToParam (QueryParam "name" String) where toParam _ = @@ -71,7 +71,7 @@ instance ToParam (QueryParam "name" String) where "Name of the person to say hello to." -- description Normal -- Normal, List or Flag -instance ToSample HelloMessage HelloMessage where +instance ToSample HelloMessage where toSamples _ = [ ("When a value is provided for 'name'", HelloMessage "Hello, Alp") , ("When 'name' is not specified", HelloMessage "Hello, anonymous coward") @@ -81,11 +81,11 @@ instance ToSample HelloMessage HelloMessage where ci :: ClientInfo ci = ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"] -instance ToSample ClientInfo ClientInfo where - toSample _ = Just ci +instance ToSample ClientInfo where + toSamples _ = singleSample ci -instance ToSample Email Email where - toSample _ = Just (emailForClient ci) +instance ToSample Email where + toSamples _ = singleSample (emailForClient ci) ``` Types that are used as request or response bodies have to instantiate the `ToSample` typeclass which lets you specify one or more examples of values. `Capture`s and `QueryParam`s have to instantiate their respective `ToCapture` and `ToParam` classes and provide a name and some information about the concrete meaning of that argument, as illustrated in the code above. @@ -228,7 +228,7 @@ server = Server.server3 :<|> serveDocs plain = ("Content-Type", "text/plain") app :: Application -app = serve api server +app = serve api EmptyConfig server ``` And if you spin up this server with `dist/build/tutorial/tutorial 10` and go to anywhere else than `/position`, `/hello` and `/marketing`, you will see the API docs in markdown. This is because `serveDocs` is attempted if the 3 other endpoints don't match and systematically succeeds since its definition is to just return some fixed bytestring with the `text/plain` content type. diff --git a/doc/tutorial/tutorial.cabal b/doc/tutorial/tutorial.cabal index c22fd8aa..501dace4 100644 --- a/doc/tutorial/tutorial.cabal +++ b/doc/tutorial/tutorial.cabal @@ -16,7 +16,7 @@ cabal-version: >=1.10 library exposed-modules: ApiType , Client - -- , Docs + , Docs -- , Javascript , Server -- other-modules: