Better haddocks for new documentation

This commit is contained in:
Ivan Lazar Miljenovic 2017-10-06 11:11:59 +11:00
parent a693648044
commit ddcb3560e0

View file

@ -298,17 +298,29 @@ defAction =
single :: Endpoint -> Action -> API single :: Endpoint -> Action -> API
single e a = API mempty (HM.singleton e a) single e a = API mempty (HM.singleton e a)
-- | How many examples should be shown? -- | How many content-types for each example should be shown?
data ShowContentTypes = AllContentTypes | FirstContentType --
-- @since 0.11.1
data ShowContentTypes = AllContentTypes -- ^ For each example, show each content type.
| FirstContentType -- ^ For each example, show only one content type.
deriving (Eq, Ord, Show, Read, Bounded, Enum) deriving (Eq, Ord, Show, Read, Bounded, Enum)
-- | Customise how an 'API' is converted into documentation. -- | Customise how an 'API' is converted into documentation.
--
-- @since 0.11.1
data RenderingOptions = RenderingOptions data RenderingOptions = RenderingOptions
{ _requestExamples :: !ShowContentTypes { _requestExamples :: !ShowContentTypes
-- ^ How many content types to display for request body examples?
, _responseExamples :: !ShowContentTypes , _responseExamples :: !ShowContentTypes
-- ^ How many content types to display for response body examples?
} deriving (Show) } deriving (Show)
-- | Default API generation options. -- | Default API generation options.
--
-- All content types are shown for both 'requestExamples' and
-- 'responseExamples'.
--
-- @since 0.11.1
defRenderingOptions :: RenderingOptions defRenderingOptions :: RenderingOptions
defRenderingOptions = RenderingOptions defRenderingOptions = RenderingOptions
{ _requestExamples = AllContentTypes { _requestExamples = AllContentTypes
@ -542,9 +554,32 @@ class ToAuthInfo a where
-- | Generate documentation in Markdown format for -- | Generate documentation in Markdown format for
-- the given 'API'. -- the given 'API'.
--
-- This is equivalent to @'markdownWith' 'defRenderingOptions'@.
markdown :: API -> String markdown :: API -> String
markdown = markdownWith defRenderingOptions markdown = markdownWith defRenderingOptions
-- | Generate documentation in Markdown format for
-- the given 'API' using the specified options.
--
-- These options allow you to customise aspects such as:
--
-- * Choose how many content-types for each request body example are
-- shown with 'requestExamples'.
--
-- * Choose how many content-types for each response body example
-- are shown with 'responseExamples'.
--
-- For example, to only show the first content-type of each example:
--
-- @
-- markdownWith ('defRenderingOptions'
-- & 'requestExamples' '.~' 'FirstContentType'
-- & 'responseExamples' '.~' 'FirstContentType' )
-- myAPI
-- @
--
-- @since 0.11.1
markdownWith :: RenderingOptions -> API -> String markdownWith :: RenderingOptions -> API -> String
markdownWith RenderingOptions{..} api = unlines $ markdownWith RenderingOptions{..} api = unlines $
introsStr (api ^. apiIntros) introsStr (api ^. apiIntros)