git.iko.soy/typeable/openapi3
on master help sign in
Add ToSchema NonEmpty instance for GHC 8.
4fcb678Lucas DiCioccio
src/Data/Swagger/Internal/Schema.hs+10
@@ -73,6 +73,7 @@ import Data.Swagger.Internal.TypeShape
73#else
73#else
74import qualified Data.ByteString as BS
74import qualified Data.ByteString as BS
75import qualified Data.ByteString.Lazy as BSL
75import qualified Data.ByteString.Lazy as BSL
76+import Data.List.NonEmpty (NonEmpty)
76import GHC.TypeLits (TypeError, ErrorMessage(..))
77import GHC.TypeLits (TypeError, ErrorMessage(..))
77#endif
78#endif
78
79
@@ -561,6 +562,15 @@ instance ToSchema a => ToSchema (Set a) where
561
562
562instance ToSchema a => ToSchema (HashSet a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set a))
563instance ToSchema a => ToSchema (HashSet a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set a))
563
564
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+
564instance ToSchema All where declareNamedSchema = plain . paramSchemaToSchema
574instance ToSchema All where declareNamedSchema = plain . paramSchemaToSchema
565instance ToSchema Any where declareNamedSchema = plain . paramSchemaToSchema
575instance ToSchema Any where declareNamedSchema = plain . paramSchemaToSchema
566
576
test/Data/Swagger/Schema/ValidationSpec.hs+2
@@ -16,6 +16,7 @@ import "unordered-containers" Data.HashSet (HashSet)
16import qualified "unordered-containers" Data.HashSet as HashSet
16import qualified "unordered-containers" Data.HashSet as HashSet
17import Data.HashMap.Strict (HashMap)
17import Data.HashMap.Strict (HashMap)
18import qualified Data.HashMap.Strict as HashMap
18import qualified Data.HashMap.Strict as HashMap
19+import Data.List.NonEmpty (NonEmpty)
19import Data.Map (Map)
20import Data.Map (Map)
20import Data.Monoid (mempty)
21import Data.Monoid (mempty)
21import Data.Proxy
22import Data.Proxy
@@ -69,6 +70,7 @@ spec = do
69 -- prop "(Maybe [Int])" $ shouldValidate (Proxy :: Proxy (Maybe [Int]))
70 -- prop "(Maybe [Int])" $ shouldValidate (Proxy :: Proxy (Maybe [Int]))
70 prop "(IntMap String)" $ shouldValidate (Proxy :: Proxy (IntMap String))
71 prop "(IntMap String)" $ shouldValidate (Proxy :: Proxy (IntMap String))
71 prop "(Set Bool)" $ shouldValidate (Proxy :: Proxy (Set Bool))
72 prop "(Set Bool)" $ shouldValidate (Proxy :: Proxy (Set Bool))
73+ prop "(NonEmpty Bool)" $ shouldValidate (Proxy :: Proxy (NonEmpty Bool))
72 prop "(HashSet Bool)" $ shouldValidate (Proxy :: Proxy (HashSet Bool))
74 prop "(HashSet Bool)" $ shouldValidate (Proxy :: Proxy (HashSet Bool))
73 prop "(Either Int String)" $ shouldValidate (Proxy :: Proxy (Either Int String))
75 prop "(Either Int String)" $ shouldValidate (Proxy :: Proxy (Either Int String))
74 prop "(Int, String)" $ shouldValidate (Proxy :: Proxy (Int, String))
76 prop "(Int, String)" $ shouldValidate (Proxy :: Proxy (Int, String))