packages feed

swagger2 2.1.3 → 2.1.4

raw patch · 7 files changed

+105/−7 lines, 7 filesdep +transformers-compatdep ~generics-sop

Dependencies added: transformers-compat

Dependency ranges changed: generics-sop

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+2.1.4+-----++* Add `liftDeclare` (see [#100](https://github.com/GetShopTV/swagger2/pull/100));+* Add `MonadDeclare` instances for all monad transformers (see [#100](https://github.com/GetShopTV/swagger2/pull/100)).+ 2.1.3 ----- 
examples/hackage.hs view
@@ -20,7 +20,21 @@ data UserSummary = UserSummary   { summaryUsername :: Username   , summaryUserid   :: Int-  } deriving (Generic, ToSchema)+  } deriving (Generic)++instance ToSchema UserSummary where+  declareNamedSchema _ = do+    usernameSchema <- declareSchemaRef (Proxy :: Proxy Username)+    useridSchema   <- declareSchemaRef (Proxy :: Proxy Int)+    return $ NamedSchema (Just "UserSummary") $ mempty+      & type_ .~ SwaggerObject+      & properties .~+          [ ("summaryUsername", usernameSchema )+          , ("summaryUserid"  , useridSchema   )+          ]+      & required .~ [ "summaryUsername"+                    , "summaryUserid"   ]+  type Group = Text 
src/Data/Swagger/Declare.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE UndecidableInstances #-} -- | -- Module:      Data.Swagger.Declare -- Maintainer:  Nickolay Kudasov <nickolay@getshoptv.com>@@ -14,7 +15,19 @@ import Prelude.Compat  import Control.Monad+import Control.Monad.Cont (ContT)+import Control.Monad.List (ListT)+import Control.Monad.Reader (ReaderT) import Control.Monad.Trans+import Control.Monad.Trans.Except (ExceptT)+import Control.Monad.Trans.Identity (IdentityT)+import Control.Monad.Trans.Maybe (MaybeT)+import Control.Monad.Trans.State.Lazy as Lazy+import Control.Monad.Trans.State.Strict as Strict+import Control.Monad.Trans.RWS.Lazy as Lazy+import Control.Monad.Trans.RWS.Strict as Strict+import Control.Monad.Trans.Writer.Lazy as Lazy+import Control.Monad.Trans.Writer.Strict as Strict import Data.Functor.Identity import Data.Monoid @@ -77,6 +90,13 @@   declare d = DeclareT (\_ -> return (d, ()))   look = DeclareT (\d -> return (mempty, d)) +-- | Lift a computation from the simple Declare monad.+liftDeclare :: MonadDeclare d m => Declare d a -> m a+liftDeclare da = do+  (d', a) <- looks (runDeclare da)+  declare d'+  pure a+ -- | Retrieve a function of all the output so far. looks :: MonadDeclare d m => (d -> a) -> m a looks f = f <$> look@@ -125,3 +145,56 @@ undeclare :: Monoid d => Declare d a -> a undeclare = runIdentity . undeclareT +-- ---------------------------------------------------------------------------+-- Instances for other mtl transformers+--+-- All of these instances need UndecidableInstances,+-- because they do not satisfy the coverage condition.++instance MonadDeclare d m => MonadDeclare d (ContT r m) where+  declare = lift . declare+  look = lift look++instance MonadDeclare d m => MonadDeclare d (ExceptT e m) where+  declare = lift . declare+  look = lift look++instance MonadDeclare d m => MonadDeclare d (IdentityT m) where+  declare = lift . declare+  look = lift look++instance MonadDeclare d m => MonadDeclare d (ListT m) where+  declare = lift . declare+  look = lift look++instance MonadDeclare d m => MonadDeclare d (MaybeT m) where+  declare = lift . declare+  look = lift look++instance MonadDeclare d m => MonadDeclare d (ReaderT r m) where+  declare = lift . declare+  look = lift look++instance (Monoid w, MonadDeclare d m) => MonadDeclare d (Lazy.RWST r w s m) where+  declare = lift . declare+  look = lift look++instance (Monoid w, MonadDeclare d m) => MonadDeclare d (Strict.RWST r w s m) where+  declare = lift . declare+  look = lift look++instance MonadDeclare d m => MonadDeclare d (Lazy.StateT s m) where+  declare = lift . declare+  look = lift look++instance MonadDeclare d m => MonadDeclare d (Strict.StateT s m) where+  declare = lift . declare+  look = lift look++instance (Monoid w, MonadDeclare d m) => MonadDeclare d (Lazy.WriterT w m) where+  declare = lift . declare+  look = lift look++instance (Monoid w, MonadDeclare d m) => MonadDeclare d (Strict.WriterT w m) where+  declare = lift . declare+  look = lift look
src/Data/Swagger/Internal/ParamSchema.hs view
@@ -83,9 +83,9 @@ -- data Direction = Up | Down -- -- instance ToParamSchema Direction where---   toParamSchema = mempty+--   toParamSchema _ = mempty --      & type_ .~ SwaggerString---      & enum_ .~ [ \"Up\", \"Down\" ]+--      & enum_ ?~ [ \"Up\", \"Down\" ] -- @ -- -- Instead of manually writing your @'ToParamSchema'@ instance you can
src/Data/Swagger/Internal/Schema.hs view
@@ -104,9 +104,9 @@ -- data Coord = Coord { x :: Double, y :: Double } -- -- instance ToSchema Coord where---   declareNamedSchema = do+--   declareNamedSchema _ = do --     doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)---     return $ NamedSchema (Just \"Coord\")) $ mempty+--     return $ NamedSchema (Just \"Coord\") $ mempty --       & type_ .~ SwaggerObject --       & properties .~ --           [ (\"x\", doubleSchema)@@ -685,6 +685,8 @@       then schema         & type_ .~ SwaggerArray         & items %~ appendItem ref+        & maxItems %~ Just . maybe 1 (+1)   -- increment maxItems+        & minItems %~ Just . maybe 1 (+1)   -- increment minItems       else schema         & type_ .~ SwaggerObject         & properties . at fname ?~ ref
swagger2.cabal view
@@ -1,5 +1,5 @@ name:                swagger2-version:             2.1.3+version:             2.1.4 synopsis:            Swagger 2.0 data model description:         Please see README.md homepage:            https://github.com/GetShopTV/swagger2@@ -56,6 +56,7 @@                      , template-haskell                      , time                      , transformers+                     , transformers-compat >= 0.3                      , unordered-containers                      , vector                      , uuid-types >=1.0.2 && <1.1
test/Data/Swagger/SchemaSpec.hs view
@@ -146,7 +146,9 @@     [       { "type": "integer" },       { "type": "string"  }-    ]+    ],+  "minItems": 2,+  "maxItems": 2 } |]