on master help sign in
Correct some doctest looking things to be doctests
953747bOleg Grenrus
servant-docs/src/Servant/Docs/Internal.hs+43−31
@@ -76,14 +76,15 @@ import qualified Network.HTTP.Types as HTTP
76-- or any 'Endpoint' value you want using the 'path' and 'method'
76-- or any 'Endpoint' value you want using the 'path' and 'method'
77-- lenses to tweak.
77-- lenses to tweak.
78--
78--
79−-- @
80−-- λ> 'defEndpoint'
79+-- >>> defEndpoint
81−-- GET /
80+-- "GET" /
81+--
82−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"]
82+-- >>> defEndpoint & path <>~ ["foo"]
83−-- GET /foo
83+-- "GET" /foo
84+--
84−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"] & 'method' '.~' 'HTTP.methodPost'
85+-- >>> defEndpoint & path <>~ ["foo"] & method .~ HTTP.methodPost
85−-- POST /foo
86+-- "POST" /foo
86−-- @
87+--
87data Endpoint = Endpoint
88data Endpoint = Endpoint
88 { _path :: [String] -- type collected
89 { _path :: [String] -- type collected
89 , _method :: HTTP.Method -- type collected
90 , _method :: HTTP.Method -- type collected
@@ -104,14 +105,15 @@ showPath ps = concatMap ('/' :) ps
104--
105--
105-- Here's how you can modify it:
106-- Here's how you can modify it:
106--
107--
107−-- @
108−-- λ> 'defEndpoint'
108+-- >>> defEndpoint
109−-- GET /
109+-- "GET" /
110+--
110−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"]
111+-- >>> defEndpoint & path <>~ ["foo"]
111−-- GET /foo
112+-- "GET" /foo
113+--
112−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"] & 'method' '.~' 'HTTP.methodPost'
114+-- >>> defEndpoint & path <>~ ["foo"] & method .~ HTTP.methodPost
113−-- POST /foo
115+-- "POST" /foo
114−-- @
116+--
115defEndpoint :: Endpoint
117defEndpoint :: Endpoint
116defEndpoint = Endpoint [] HTTP.methodGet
118defEndpoint = Endpoint [] HTTP.methodGet
117
119
@@ -222,12 +224,14 @@ data ParamKind = Normal | List | Flag
222-- want to write a 'ToSample' instance for the type that'll be represented
224-- want to write a 'ToSample' instance for the type that'll be represented
223-- as encoded data in the response.
225-- as encoded data in the response.
224--
226--
225−-- Can be tweaked with three lenses.
227+-- Can be tweaked with four lenses.
228+--
229+-- >>> defResponse
230+-- Response {_respStatus = 200, _respTypes = [], _respBody = [], _respHeaders = []}
231+--
232+-- >>> defResponse & respStatus .~ 204 & respBody .~ [("If everything goes well", "application/json", "{ \"status\": \"ok\" }")]
233+-- Response {_respStatus = 204, _respTypes = [], _respBody = [("If everything goes well",application/json,"{ \"status\": \"ok\" }")], _respHeaders = []}
226--
234--
227−-- > λ> defResponse
228−-- > Response {_respStatus = 200, _respTypes = [], _respBody = []}
229−-- > λ> defResponse & respStatus .~ 204 & respBody .~ [("If everything goes well", "{ \"status\": \"ok\" }")]
230−-- > Response {_respStatus = 204, _respTypes = [], _respBody = [("If everything goes well", "{ \"status\": \"ok\" }")]}
231data Response = Response
235data Response = Response
232 { _respStatus :: Int
236 { _respStatus :: Int
233 , _respTypes :: [M.MediaType]
237 , _respTypes :: [M.MediaType]
@@ -237,12 +241,14 @@ data Response = Response
237
241
238-- | Default response: status code 200, no response body.
242-- | Default response: status code 200, no response body.
239--
243--
240−-- Can be tweaked with two lenses.
244+-- Can be tweaked with four lenses.
245+--
246+-- >>> defResponse
247+-- Response {_respStatus = 200, _respTypes = [], _respBody = [], _respHeaders = []}
248+--
249+-- >>> defResponse & respStatus .~ 204
250+-- Response {_respStatus = 204, _respTypes = [], _respBody = [], _respHeaders = []}
241--
251--
242−-- > λ> defResponse
243−-- > Response {_respStatus = 200, _respBody = Nothing}
244−-- > λ> defResponse & respStatus .~ 204 & respBody .~ Just "[]"
245−-- > Response {_respStatus = 204, _respBody = Just "[]"}
246defResponse :: Response
252defResponse :: Response
247defResponse = Response
253defResponse = Response
248 { _respStatus = 200
254 { _respStatus = 200
@@ -288,10 +294,12 @@ Action a c h p n m ts body resp `combineAction` Action a' c' h' p' n' m' _ _ _ =
288--
294--
289-- Tweakable with lenses.
295-- Tweakable with lenses.
290--
296--
291−-- > λ> defAction
297+-- >>> defAction
292−-- > Action {_captures = [], _headers = [], _params = [], _mxParams = [], _rqbody = Nothing, _response = Response {_respStatus = 200, _respBody = Nothing}}
298+-- Action {_authInfo = [], _captures = [], _headers = [], _params = [], _notes = [], _mxParams = [], _rqtypes = [], _rqbody = [], _response = Response {_respStatus = 200, _respTypes = [], _respBody = [], _respHeaders = []}}
299+--
293−-- > λ> defAction & response.respStatus .~ 201
300+-- >>> defAction & response.respStatus .~ 201
294−-- > Action {_captures = [], _headers = [], _params = [], _mxParams = [], _rqbody = Nothing, _response = Response {_respStatus = 201, _respBody = Nothing}}
301+-- Action {_authInfo = [], _captures = [], _headers = [], _params = [], _notes = [], _mxParams = [], _rqtypes = [], _rqbody = [], _response = Response {_respStatus = 201, _respTypes = [], _respBody = [], _respHeaders = []}}
302+--
295defAction :: Action
303defAction :: Action
296defAction =
304defAction =
297 Action []
305 Action []
@@ -359,7 +367,8 @@ makeLenses ''RenderingOptions
359-- | Generate the docs for a given API that implements 'HasDocs'. This is the
367-- | Generate the docs for a given API that implements 'HasDocs'. This is the
360-- default way to create documentation.
368-- default way to create documentation.
361--
369--
362−-- prop> docs == docsWithOptions defaultDocOptions
370+-- > docs == docsWithOptions defaultDocOptions
371+--
363docs :: HasDocs api => Proxy api -> API
372docs :: HasDocs api => Proxy api -> API
364docs p = docsWithOptions p defaultDocOptions
373docs p = docsWithOptions p defaultDocOptions
365
374
@@ -1046,3 +1055,6 @@ instance ToSample a => ToSample (Product a)
1046instance ToSample a => ToSample (First a)
1055instance ToSample a => ToSample (First a)
1047instance ToSample a => ToSample (Last a)
1056instance ToSample a => ToSample (Last a)
1048instance ToSample a => ToSample (Dual a)
1057instance ToSample a => ToSample (Dual a)
1058+
1059+-- $setup
1060+-- >>> :set -XOverloadedStrings