git.iko.soy/typeable/swagger2
on master help sign in
Add ToSchema NonEmpty instance for GHC 8.
commit4fcb6780c6bdbc77cc9ef3806f9ff29102fbc807 authorLucas DiCioccio <ldicioccio@vente-privee.com> dateTue 7 Nov 2017, 18:40 (9 years ago) parent5275f62
2 files changed+12
src/Data/Swagger/Internal/Schema.hs+10 test/Data/Swagger/Schema/ValidationSpec.hs+2
src/Data/Swagger/Internal/Schema.hs+10
@@ -73,6 +73,7 @@ import Data.Swagger.Internal.TypeShape
7373#else
7474import qualified Data.ByteString as BS
7575import qualified Data.ByteString.Lazy as BSL
76+import Data.List.NonEmpty (NonEmpty)
7677import GHC.TypeLits (TypeError, ErrorMessage(..))
7778#endif
7879
@@ -561,6 +562,15 @@ instance ToSchema a => ToSchema (Set a) where
561562
562563instance ToSchema a => ToSchema (HashSet a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set a))
563564
565+#if __GLASGOW_HASKELL__ < 800
566+#else
567+instance ToSchema a => ToSchema (NonEmpty a) where
568+ declareNamedSchema _ = do
569+ schema <- declareSchema (Proxy :: Proxy [a])
570+ return $ unnamed $ schema
571+ & minItems .~ Just 1
572+#endif
573+
564574instance ToSchema All where declareNamedSchema = plain . paramSchemaToSchema
565575instance ToSchema Any where declareNamedSchema = plain . paramSchemaToSchema
566576
test/Data/Swagger/Schema/ValidationSpec.hs+2
@@ -16,6 +16,7 @@ import "unordered-containers" Data.HashSet (HashSet)
1616import qualified "unordered-containers" Data.HashSet as HashSet
1717import Data.HashMap.Strict (HashMap)
1818import qualified Data.HashMap.Strict as HashMap
19+import Data.List.NonEmpty (NonEmpty)
1920import Data.Map (Map)
2021import Data.Monoid (mempty)
2122import Data.Proxy
@@ -69,6 +70,7 @@ spec = do
6970 -- prop "(Maybe [Int])" $ shouldValidate (Proxy :: Proxy (Maybe [Int]))
7071 prop "(IntMap String)" $ shouldValidate (Proxy :: Proxy (IntMap String))
7172 prop "(Set Bool)" $ shouldValidate (Proxy :: Proxy (Set Bool))
73+ prop "(NonEmpty Bool)" $ shouldValidate (Proxy :: Proxy (NonEmpty Bool))
7274 prop "(HashSet Bool)" $ shouldValidate (Proxy :: Proxy (HashSet Bool))
7375 prop "(Either Int String)" $ shouldValidate (Proxy :: Proxy (Either Int String))
7476 prop "(Int, String)" $ shouldValidate (Proxy :: Proxy (Int, String))