Add samples helper to define samples without documentation
This commit is contained in:
parent
f56a656e65
commit
f96915e85e
3 changed files with 6 additions and 2 deletions
|
@ -151,6 +151,7 @@ module Servant.Docs
|
|||
, toSample
|
||||
, noSamples
|
||||
, singleSample
|
||||
, samples
|
||||
, sampleByteString
|
||||
, sampleByteStrings
|
||||
, ToParam(..)
|
||||
|
|
|
@ -399,6 +399,10 @@ noSamples = empty
|
|||
singleSample :: a -> [(Text, a)]
|
||||
singleSample x = [("", x)]
|
||||
|
||||
-- | Samples without documentation.
|
||||
samples :: [a] -> [(Text, a)]
|
||||
samples = map ("",)
|
||||
|
||||
-- | Default sample Generic-based inputs/outputs.
|
||||
defaultSamples :: forall a b. (Generic a, Generic b, GToSample (Rep a) (Rep b)) => Proxy a -> [(Text, b)]
|
||||
defaultSamples _ = Omega.runOmega $ second to <$> gtoSamples (Proxy :: Proxy (Rep a))
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
{-# LANGUAGE TypeSynonymInstances #-}
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
|
@ -95,7 +94,7 @@ instance ToSample Datatype1 Datatype1 where
|
|||
toSamples _ = singleSample $ Datatype1 "field 1" 13
|
||||
|
||||
instance ToSample Char Char where
|
||||
toSamples _ = map ("",) ['a'..'z']
|
||||
toSamples _ = samples ['a'..'z']
|
||||
|
||||
instance ToSample Int Int where
|
||||
toSamples _ = singleSample 17
|
||||
|
|
Loading…
Reference in a new issue