git.iko.soy/typeable/swagger2
on master help sign in
Revert "use MonadDeclare in place of Declare"

This reverts commit e9fcd21bf606430218a661daa70063eceb37d258.

commitfe3d81e498b9d52c16ca579e4cc0d49c9ec0d199 authormoss <moss@tvisioninsights.com> dateMon 24 Apr 2017, 14:13 (9 years ago) parente9fcd21
1 file changed+17−17
src/Data/Swagger/Internal/Schema.hs+17−17
src/Data/Swagger/Internal/Schema.hs+17−17
@@ -82,7 +82,7 @@ unnamed schema = NamedSchema Nothing schema
8282named :: T.Text -> Schema -> NamedSchema
8383named name schema = NamedSchema (Just name) schema
8484
85−plain :: MonadDeclare (Definitions Schema) m => Schema -> m NamedSchema
85+plain :: Schema -> Declare (Definitions Schema) NamedSchema
8686plain = pure . unnamed
8787
8888unname :: NamedSchema -> NamedSchema
@@ -138,12 +138,12 @@ class ToSchema a where
138138 -- together with all used definitions.
139139 -- Note that the schema itself is included in definitions
140140 -- only if it is recursive (and thus needs its definition in scope).
141− declareNamedSchema :: MonadDeclare (Definitions Schema) m => proxy a -> m NamedSchema
142− default declareNamedSchema :: (Generic a, GToSchema (Rep a), MonadDeclare (Definitions Schema) m) => proxy a -> m NamedSchema
141+ declareNamedSchema :: proxy a -> Declare (Definitions Schema) NamedSchema
142+ default declareNamedSchema :: (Generic a, GToSchema (Rep a)) => proxy a -> Declare (Definitions Schema) NamedSchema
143143 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
144144
145145-- | Convert a type into a schema and declare all used schema definitions.
146−declareSchema :: (ToSchema a, MonadDeclare (Definitions Schema) m) => proxy a -> m Schema
146+declareSchema :: ToSchema a => proxy a -> Declare (Definitions Schema) Schema
147147declareSchema = fmap _namedSchemaSchema . declareNamedSchema
148148
149149-- | Convert a type into an optionally named schema.
@@ -198,7 +198,7 @@ toSchemaRef = undeclare . declareSchemaRef
198198-- Schema definitions are typically declared for every referenced schema.
199199-- If @'declareSchemaRef'@ returns a reference, a corresponding schema
200200-- will be declared (regardless of whether it is recusive or not).
201−declareSchemaRef :: (ToSchema a, MonadDeclare (Definitions Schema) m) => proxy a -> m (Referenced Schema)
201+declareSchemaRef :: ToSchema a => proxy a -> Declare (Definitions Schema) (Referenced Schema)
202202declareSchemaRef proxy = do
203203 case toNamedSchema proxy of
204204 NamedSchema (Just name) schema -> do
@@ -405,7 +405,7 @@ sketchStrictSchema = go . toJSON
405405 names = HashMap.keys o
406406
407407class GToSchema (f :: * -> *) where
408− gdeclareNamedSchema :: (MonadDeclare (Definitions Schema) m) => SchemaOptions -> proxy f -> Schema -> m NamedSchema
408+ gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
409409
410410instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where
411411 declareNamedSchema _ = do
@@ -583,14 +583,14 @@ genericToNamedSchemaBoundedIntegral opts proxy
583583 = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d)) (toSchemaBoundedIntegral proxy)
584584
585585-- | A configurable generic @'Schema'@ creator.
586−genericDeclareSchema :: (Generic a, GToSchema (Rep a), MonadDeclare (Definitions Schema) m) => SchemaOptions -> proxy a -> m Schema
586+genericDeclareSchema :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
587587genericDeclareSchema opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchema opts proxy
588588
589589-- | A configurable generic @'NamedSchema'@ creator.
590590-- This function applied to @'defaultSchemaOptions'@
591591-- is used as the default for @'declareNamedSchema'@
592592-- when the type is an instance of @'Generic'@.
593−genericDeclareNamedSchema :: forall a m proxy. (Generic a, GToSchema (Rep a), MonadDeclare (Definitions Schema) m) => SchemaOptions -> proxy a -> m NamedSchema
593+genericDeclareNamedSchema :: forall a proxy. (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
594594genericDeclareNamedSchema opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
595595
596596gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe T.Text
@@ -618,7 +618,7 @@ nullarySchema = mempty
618618gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
619619gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
620620
621−gdeclareSchema :: (GToSchema f, MonadDeclare (Definitions Schema) m) => SchemaOptions -> proxy f -> m Schema
621+gdeclareSchema :: GToSchema f => SchemaOptions -> proxy f -> Declare (Definitions Schema) Schema
622622gdeclareSchema opts proxy = _namedSchemaSchema <$> gdeclareNamedSchema opts proxy mempty
623623
624624instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
@@ -652,7 +652,7 @@ instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
652652 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
653653 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
654654
655−gdeclareSchemaRef :: (GToSchema a, MonadDeclare (Definitions Schema) m) => SchemaOptions -> proxy a -> m (Referenced Schema)
655+gdeclareSchemaRef :: GToSchema a => SchemaOptions -> proxy a -> Declare (Definitions Schema) (Referenced Schema)
656656gdeclareSchemaRef opts proxy = do
657657 case gtoNamedSchema opts proxy of
658658 NamedSchema (Just name) schema -> do
@@ -676,8 +676,8 @@ appendItem x Nothing = Just (SwaggerItemsArray [x])
676676appendItem x (Just (SwaggerItemsArray xs)) = Just (SwaggerItemsArray (xs ++ [x]))
677677appendItem _ _ = error "GToSchema.appendItem: cannot append to SwaggerItemsObject"
678678
679−withFieldSchema :: forall proxy s f m. (Selector s, GToSchema f, MonadDeclare (Definitions Schema) m) =>
680− SchemaOptions -> proxy s f -> Bool -> Schema -> m Schema
679+withFieldSchema :: forall proxy s f. (Selector s, GToSchema f) =>
680+ SchemaOptions -> proxy s f -> Bool -> Schema -> Declare (Definitions Schema) Schema
681681withFieldSchema opts _ isRequiredField schema = do
682682 ref <- gdeclareSchemaRef opts (Proxy :: Proxy f)
683683 return $
@@ -713,12 +713,11 @@ instance OVERLAPPABLE_ ToSchema c => GToSchema (K1 i c) where
713713instance (GSumToSchema f, GSumToSchema g) => GToSchema (f :+: g) where
714714 gdeclareNamedSchema = gdeclareNamedSumSchema
715715
716−gdeclareNamedSumSchema :: (GSumToSchema f, MonadDeclare (Definitions Schema) m) => SchemaOptions -> proxy f -> Schema -> m NamedSchema
716+gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
717717gdeclareNamedSumSchema opts proxy s
718718 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
719719 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
720720 where
721− declareSumSchema :: MonadDeclare (Definitions Schema) m => WriterT AllNullary m Schema
722721 declareSumSchema = gsumToSchema opts proxy s
723722 (sumSchema, All allNullary) = undeclare (runWriterT declareSumSchema)
724723
@@ -729,7 +728,7 @@ gdeclareNamedSumSchema opts proxy s
729728type AllNullary = All
730729
731730class GSumToSchema f where
732− gsumToSchema :: MonadDeclare (Definitions Schema) m => SchemaOptions -> proxy f -> Schema -> WriterT AllNullary m Schema
731+ gsumToSchema :: SchemaOptions -> proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
733732
734733instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
735734 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) >=> gsumToSchema opts (Proxy :: Proxy g)
@@ -744,8 +743,8 @@ gsumConToSchemaWith ref opts _ schema = schema
744743 where
745744 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
746745
747−gsumConToSchema :: forall c f m proxy. (GToSchema (C1 c f), Constructor c, MonadDeclare (Definitions Schema) m) =>
748− SchemaOptions -> proxy (C1 c f) -> Schema -> m Schema
746+gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
747+ SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
749748gsumConToSchema opts proxy schema = do
750749 ref <- gdeclareSchemaRef opts proxy
751750 return $ gsumConToSchemaWith ref opts proxy schema
@@ -766,3 +765,4 @@ instance Constructor c => GSumToSchema (C1 c U1) where
766765data Proxy2 a b = Proxy2
767766
768767data Proxy3 a b c = Proxy3
768+