@@ -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.
80−-- λ> 'defEndpoint'
79+-- >>> defEndpoint
82−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"]
82+-- >>> defEndpoint & path <>~ ["foo"]
83−-- GET /foo
83+-- "GET" /foo
84−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"] & 'method' '.~' 'HTTP.methodPost'
85+-- >>> defEndpoint & path <>~ ["foo"] & method .~ HTTP.methodPost
85−-- POST /foo
86+-- "POST" /foo
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
105-- Here's how you can modify it:
106-- Here's how you can modify it:
108−-- λ> 'defEndpoint'
108+-- >>> defEndpoint
109−-- GET /
109+-- "GET" /
110−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"]
111+-- >>> defEndpoint & path <>~ ["foo"]
111−-- GET /foo
112+-- "GET" /foo
112−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"] & 'method' '.~' 'HTTP.methodPost'
114+-- >>> defEndpoint & path <>~ ["foo"] & method .~ HTTP.methodPost
113−-- POST /foo
115+-- "POST" /foo
115defEndpoint :: Endpoint
117defEndpoint :: Endpoint
116defEndpoint = Endpoint [] HTTP.methodGet
118defEndpoint = Endpoint [] HTTP.methodGet
@@ -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.
225−-- Can be tweaked with three lenses.
227+-- Can be tweaked with four lenses.
230+-- Response {_respStatus = 200, _respTypes = [], _respBody = [], _respHeaders = []}
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 = []}
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
238-- | Default response: status code 200, no response body.
242-- | Default response: status code 200, no response body.
240−-- Can be tweaked with two lenses.
244+-- Can be tweaked with four lenses.
247+-- Response {_respStatus = 200, _respTypes = [], _respBody = [], _respHeaders = []}
249+-- >>> defResponse & respStatus .~ 204
250+-- Response {_respStatus = 204, _respTypes = [], _respBody = [], _respHeaders = []}
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' _ _ _ =
289-- Tweakable with lenses.
295-- Tweakable with lenses.
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 = []}}
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 = []}}
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.
362−-- prop> docs == docsWithOptions defaultDocOptions
370+-- > docs == docsWithOptions defaultDocOptions
363docs :: HasDocs api => Proxy api -> API
372docs :: HasDocs api => Proxy api -> API
364docs p = docsWithOptions p defaultDocOptions
373docs p = docsWithOptions p defaultDocOptions
@@ -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)
1060+-- >>> :set -XOverloadedStrings