@@ -11,6 +11,7 @@
1111{-# LANGUAGE ConstraintKinds #-}
1212{-# LANGUAGE UndecidableInstances #-}
1313{-# LANGUAGE PolyKinds #-}
14+{-# LANGUAGE StandaloneDeriving #-}
1415
1516-------------------------------------------------------------------------------
1617-- | This module lets you get API docs for free. It lets generate
@@ -190,6 +191,7 @@ import Data.ByteString.Lazy.Char8 (ByteString)
190191import Data.Hashable
191192import Data.HashMap.Strict (HashMap)
192193import Data.List
194+import Data.Function (on)
193195import Data.Maybe
194196import Data.Monoid
195197import Data.Ord (comparing)
@@ -207,12 +209,18 @@ import qualified Data.HashMap.Strict as HM
207209import qualified Data.Text as T
208210import qualified Network.HTTP.Media as M
209211
212+-- | Temporary orphan. Can be eliminated as soon as
213+-- https://github.com/zmthy/http-media/pull/12 has been released.
214+-- (Also consider removing StandaloneDeriving language ext above.)
215+instance Ord M.MediaType where
216+ compare t t' = compare (show t) (show t')
217+
210218-- | Supported HTTP request methods
211219data Method = DocDELETE -- ^ the DELETE method
212220 | DocGET -- ^ the GET method
213221 | DocPOST -- ^ the POST method
214222 | DocPUT -- ^ the PUT method
215− deriving (Eq, Generic)
223+ deriving (Eq, Ord, Generic)
216224
217225instance Show Method where
218226 show DocGET = "GET"
@@ -239,7 +247,7 @@ instance Hashable Method
239247data Endpoint = Endpoint
240248 { _path :: [String] -- type collected
241249 , _method :: Method -- type collected
242− } deriving (Eq, Generic)
250+ } deriving (Eq, Ord, Generic)
243251
244252instance Show Endpoint where
245253 show (Endpoint p m) =
@@ -291,7 +299,7 @@ emptyAPI = mempty
291299data DocCapture = DocCapture
292300 { _capSymbol :: String -- type supplied
293301 , _capDesc :: String -- user supplied
294− } deriving (Eq, Show)
302+ } deriving (Eq, Ord, Show)
295303
296304-- | A type to represent a /GET/ parameter from the Query String. Holds its name,
297305-- the possible values (leave empty if there isn't a finite number of them),
@@ -303,7 +311,7 @@ data DocQueryParam = DocQueryParam
303311 , _paramValues :: [String] -- user supplied
304312 , _paramDesc :: String -- user supplied
305313 , _paramKind :: ParamKind
306− } deriving (Eq, Show)
314+ } deriving (Eq, Ord, Show)
307315
308316-- | An introductory paragraph for your documentation. You can pass these to
309317-- 'docsWithIntros'.
@@ -322,7 +330,7 @@ instance Ord DocIntro where
322330data DocNote = DocNote
323331 { _noteTitle :: String
324332 , _noteBody :: [String]
325− } deriving (Eq, Show)
333+ } deriving (Eq, Ord, Show)
326334
327335-- | Type of extra information that a user may wish to "union" with their
328336-- documentation.
@@ -341,7 +349,7 @@ instance Monoid (ExtraInfo a) where
341349-- - List corresponds to @QueryParams@, i.e GET parameters with multiple values
342350-- - Flag corresponds to @QueryFlag@, i.e a value-less GET parameter
343351data ParamKind = Normal | List | Flag
344− deriving (Eq, Show)
352+ deriving (Eq, Ord, Show)
345353
346354-- | A type to represent an HTTP response. Has an 'Int' status, a list of
347355-- possible 'MediaType's, and a list of example 'ByteString' response bodies.
@@ -362,7 +370,7 @@ data Response = Response
362370 { _respStatus :: Int
363371 , _respTypes :: [M.MediaType]
364372 , _respBody :: [(Text, M.MediaType, ByteString)]
365− } deriving (Eq, Show)
373+ } deriving (Eq, Ord, Show)
366374
367375-- | Default response: status code 200, no response body.
368376--
@@ -394,7 +402,7 @@ data Action = Action
394402 , _rqtypes :: [M.MediaType] -- type collected
395403 , _rqbody :: [(M.MediaType, ByteString)] -- user supplied
396404 , _response :: Response -- user supplied
397− } deriving (Eq, Show)
405+ } deriving (Eq, Ord, Show)
398406
399407-- | Combine two Actions, we can't make a monoid as merging Response breaks the
400408-- laws.
@@ -611,7 +619,7 @@ class ToCapture c where
611619markdown :: API -> String
612620markdown api = unlines $
613621 introsStr (api ^. apiIntros)
614− ++ (concatMap (uncurry printEndpoint) . HM.toList $ api ^. apiEndpoints)
622+ ++ (concatMap (uncurry printEndpoint) . sort . HM.toList $ api ^. apiEndpoints)
615623
616624 where printEndpoint :: Endpoint -> Action -> [String]
617625 printEndpoint endpoint action =