@@ -61,8 +61,8 @@ instance ToCapture (Capture "y" Int) where
61 DocCapture "y" -- name
61 DocCapture "y" -- name
62 "(integer) position on the y axis" -- description
62 "(integer) position on the y axis" -- description
64−instance ToSample Position Position where
64+instance ToSample Position where
65− toSample _ = Just (Position 3 14) -- example of output
65+ toSamples _ = singleSample (Position 3 14) -- example of output
67instance ToParam (QueryParam "name" String) where
67instance ToParam (QueryParam "name" String) where
68 toParam _ =
68 toParam _ =
@@ -71,7 +71,7 @@ instance ToParam (QueryParam "name" String) where
71 "Name of the person to say hello to." -- description
71 "Name of the person to say hello to." -- description
72 Normal -- Normal, List or Flag
72 Normal -- Normal, List or Flag
74−instance ToSample HelloMessage HelloMessage where
74+instance ToSample HelloMessage where
75 toSamples _ =
75 toSamples _ =
76 [ ("When a value is provided for 'name'", HelloMessage "Hello, Alp")
76 [ ("When a value is provided for 'name'", HelloMessage "Hello, Alp")
77 , ("When 'name' is not specified", HelloMessage "Hello, anonymous coward")
77 , ("When 'name' is not specified", HelloMessage "Hello, anonymous coward")
@@ -81,11 +81,11 @@ instance ToSample HelloMessage HelloMessage where
81ci :: ClientInfo
81ci :: ClientInfo
82ci = ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
82ci = ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
84−instance ToSample ClientInfo ClientInfo where
84+instance ToSample ClientInfo where
85− toSample _ = Just ci
85+ toSamples _ = singleSample ci
87−instance ToSample Email Email where
87+instance ToSample Email where
88− toSample _ = Just (emailForClient ci)
88+ toSamples _ = singleSample (emailForClient ci)
91Types 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.
91Types 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
228 plain = ("Content-Type", "text/plain")
228 plain = ("Content-Type", "text/plain")
230app :: Application
230app :: Application
231−app = serve api server
231+app = serve api EmptyConfig server
234And 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.
234And 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.