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
|
, toSample
|
||||||
, noSamples
|
, noSamples
|
||||||
, singleSample
|
, singleSample
|
||||||
|
, samples
|
||||||
, sampleByteString
|
, sampleByteString
|
||||||
, sampleByteStrings
|
, sampleByteStrings
|
||||||
, ToParam(..)
|
, ToParam(..)
|
||||||
|
|
|
@ -399,6 +399,10 @@ noSamples = empty
|
||||||
singleSample :: a -> [(Text, a)]
|
singleSample :: a -> [(Text, a)]
|
||||||
singleSample x = [("", x)]
|
singleSample x = [("", x)]
|
||||||
|
|
||||||
|
-- | Samples without documentation.
|
||||||
|
samples :: [a] -> [(Text, a)]
|
||||||
|
samples = map ("",)
|
||||||
|
|
||||||
-- | Default sample Generic-based inputs/outputs.
|
-- | Default sample Generic-based inputs/outputs.
|
||||||
defaultSamples :: forall a b. (Generic a, Generic b, GToSample (Rep a) (Rep b)) => Proxy a -> [(Text, b)]
|
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))
|
defaultSamples _ = Omega.runOmega $ second to <$> gtoSamples (Proxy :: Proxy (Rep a))
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE TupleSections #-}
|
|
||||||
{-# LANGUAGE TypeOperators #-}
|
{-# LANGUAGE TypeOperators #-}
|
||||||
{-# LANGUAGE TypeSynonymInstances #-}
|
{-# LANGUAGE TypeSynonymInstances #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||||
|
@ -95,7 +94,7 @@ instance ToSample Datatype1 Datatype1 where
|
||||||
toSamples _ = singleSample $ Datatype1 "field 1" 13
|
toSamples _ = singleSample $ Datatype1 "field 1" 13
|
||||||
|
|
||||||
instance ToSample Char Char where
|
instance ToSample Char Char where
|
||||||
toSamples _ = map ("",) ['a'..'z']
|
toSamples _ = samples ['a'..'z']
|
||||||
|
|
||||||
instance ToSample Int Int where
|
instance ToSample Int Int where
|
||||||
toSamples _ = singleSample 17
|
toSamples _ = singleSample 17
|
||||||
|
|
Loading…
Reference in a new issue