git.iko.soy/typeable/openapi3
on master help sign in
Merge pull request #84 from phadej/pr78

Pr78

commitb2ff991918b6e3c987c844614d03e1f50f21c3a1 authorOleg Grenrus <oleg.grenrus@iki.fi> dateSun 2 Oct 2016, 00:35 (10 years ago) parent218f427429e8bc
3 files changed+43
src/Data/Swagger/Internal/ParamSchema.hs+22 src/Data/Swagger/Internal/Schema.hs+20 swagger2.cabal+1
src/Data/Swagger/Internal/ParamSchema.hs+22
@@ -1,4 +1,5 @@
11{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DataKinds #-}
23{-# LANGUAGE DefaultSignatures #-}
34{-# LANGUAGE FlexibleContexts #-}
45{-# LANGUAGE FlexibleInstances #-}
@@ -7,8 +8,10 @@
78{-# LANGUAGE PackageImports #-}
89{-# LANGUAGE PolyKinds #-}
910{-# LANGUAGE ScopedTypeVariables #-}
11+{-# LANGUAGE TypeFamilies #-}
1012{-# LANGUAGE TypeOperators #-}
1113{-# LANGUAGE TypeSynonymInstances #-}
14+{-# LANGUAGE UndecidableInstances #-}
1215#if __GLASGOW_HASKELL__ >= 800
1316-- Generic a is redundant in ToParamSchema a default imple
1417{-# OPTIONS_GHC -Wno-redundant-constraints #-}
@@ -40,6 +43,13 @@ import Data.Swagger.Internal
4043import Data.Swagger.Lens
4144import Data.Swagger.SchemaOptions
4245
46+#if __GLASGOW_HASKELL__ < 800
47+#else
48+import qualified Data.ByteString as BS
49+import qualified Data.ByteString.Lazy as BSL
50+import GHC.TypeLits (TypeError, ErrorMessage(..))
51+#endif
52+
4353-- | Default schema for binary data (any sequence of octets).
4454binaryParamSchema :: ParamSchema t
4555binaryParamSchema = mempty
@@ -193,6 +203,18 @@ instance ToParamSchema T.Text where
193203instance ToParamSchema TL.Text where
194204 toParamSchema _ = toParamSchema (Proxy :: Proxy String)
195205
206+#if __GLASGOW_HASKELL__ < 800
207+#else
208+type family ToParamSchemaByteStringError bs where
209+ ToParamSchemaByteStringError bs = TypeError
210+ ( Text "Impossible to have an instance " :<>: ShowType (ToParamSchema bs) :<>: Text "."
211+ :$$: Text "Please, use a newtype wrapper around " :<>: ShowType bs :<>: Text " instead."
212+ :$$: Text "Consider using byteParamSchema or binaryParamSchema templates." )
213+
214+instance ToParamSchemaByteStringError BS.ByteString => ToParamSchema BS.ByteString where toParamSchema = error "impossible"
215+instance ToParamSchemaByteStringError BSL.ByteString => ToParamSchema BSL.ByteString where toParamSchema = error "impossible"
216+#endif
217+
196218instance ToParamSchema All where toParamSchema _ = toParamSchema (Proxy :: Proxy Bool)
197219instance ToParamSchema Any where toParamSchema _ = toParamSchema (Proxy :: Proxy Bool)
198220instance ToParamSchema a => ToParamSchema (Sum a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
src/Data/Swagger/Internal/Schema.hs+20
@@ -13,6 +13,7 @@
1313{-# LANGUAGE TypeFamilies #-}
1414{-# LANGUAGE TypeOperators #-}
1515{-# LANGUAGE TypeSynonymInstances #-}
16+{-# LANGUAGE UndecidableInstances #-}
1617#if __GLASGOW_HASKELL__ >= 800
1718-- Few generics related redundant constraints
1819{-# OPTIONS_GHC -Wno-redundant-constraints #-}
@@ -66,6 +67,13 @@ import Data.Swagger.SchemaOptions
6667import Data.Swagger.Lens (name, schema)
6768#endif
6869
70+#if __GLASGOW_HASKELL__ < 800
71+#else
72+import qualified Data.ByteString as BS
73+import qualified Data.ByteString.Lazy as BSL
74+import GHC.TypeLits (TypeError, ErrorMessage(..))
75+#endif
76+
6977unnamed :: Schema -> NamedSchema
7078unnamed schema = NamedSchema Nothing schema
7179
@@ -481,6 +489,18 @@ instance ToSchema UTCTime where
481489instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
482490instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
483491
492+#if __GLASGOW_HASKELL__ < 800
493+#else
494+type family ToSchemaByteStringError bs where
495+ ToSchemaByteStringError bs = TypeError
496+ ( Text "Impossible to have an instance " :<>: ShowType (ToSchema bs) :<>: Text "."
497+ :$$: Text "Please, use a newtype wrapper around " :<>: ShowType bs :<>: Text " instead."
498+ :$$: Text "Consider using byteSchema or binarySchema templates." )
499+
500+instance ToSchemaByteStringError BS.ByteString => ToSchema BS.ByteString where declareNamedSchema = error "impossible"
501+instance ToSchemaByteStringError BSL.ByteString => ToSchema BSL.ByteString where declareNamedSchema = error "impossible"
502+#endif
503+
484504instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
485505
486506-- | NOTE: This schema does not account for the uniqueness of keys.
swagger2.cabal+1
@@ -42,6 +42,7 @@ library
4242 build-depends: base >=4.7 && <4.10
4343 , base-compat >=0.9.1 && <0.10
4444 , aeson >=0.11.2.1
45+ , bytestring
4546 , containers
4647 , hashable
4748 , generics-sop >=0.2 && <0.3