git.iko.soy/typeable/openapi3
on master help sign in
Revert "use MonadDeclare in place of Declare"
fe3d81emoss
src/Data/Swagger/Internal/Schema.hs+17−17
@@ -82,7 +82,7 @@ unnamed schema = NamedSchema Nothing schema
82named :: T.Text -> Schema -> NamedSchema
82named :: T.Text -> Schema -> NamedSchema
83named name schema = NamedSchema (Just name) schema
83named name schema = NamedSchema (Just name) schema
84
84
85−plain :: MonadDeclare (Definitions Schema) m => Schema -> m NamedSchema
85+plain :: Schema -> Declare (Definitions Schema) NamedSchema
86plain = pure . unnamed
86plain = pure . unnamed
87
87
88unname :: NamedSchema -> NamedSchema
88unname :: NamedSchema -> NamedSchema
@@ -138,12 +138,12 @@ class ToSchema a where
138 -- together with all used definitions.
138 -- together with all used definitions.
139 -- Note that the schema itself is included in definitions
139 -- Note that the schema itself is included in definitions
140 -- only if it is recursive (and thus needs its definition in scope).
140 -- only if it is recursive (and thus needs its definition in scope).
141− declareNamedSchema :: MonadDeclare (Definitions Schema) m => proxy a -> m NamedSchema
141+ declareNamedSchema :: proxy a -> Declare (Definitions Schema) NamedSchema
142− default declareNamedSchema :: (Generic a, GToSchema (Rep a), MonadDeclare (Definitions Schema) m) => proxy a -> m NamedSchema
142+ default declareNamedSchema :: (Generic a, GToSchema (Rep a)) => proxy a -> Declare (Definitions Schema) NamedSchema
143 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
143 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
144
144
145-- | Convert a type into a schema and declare all used schema definitions.
145-- | 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
147declareSchema = fmap _namedSchemaSchema . declareNamedSchema
147declareSchema = fmap _namedSchemaSchema . declareNamedSchema
148
148
149-- | Convert a type into an optionally named schema.
149-- | Convert a type into an optionally named schema.
@@ -198,7 +198,7 @@ toSchemaRef = undeclare . declareSchemaRef
198-- Schema definitions are typically declared for every referenced schema.
198-- Schema definitions are typically declared for every referenced schema.
199-- If @'declareSchemaRef'@ returns a reference, a corresponding schema
199-- If @'declareSchemaRef'@ returns a reference, a corresponding schema
200-- will be declared (regardless of whether it is recusive or not).
200-- 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)
202declareSchemaRef proxy = do
202declareSchemaRef proxy = do
203 case toNamedSchema proxy of
203 case toNamedSchema proxy of
204 NamedSchema (Just name) schema -> do
204 NamedSchema (Just name) schema -> do
@@ -405,7 +405,7 @@ sketchStrictSchema = go . toJSON
405 names = HashMap.keys o
405 names = HashMap.keys o
406
406
407class GToSchema (f :: * -> *) where
407class 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
409
409
410instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where
410instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where
411 declareNamedSchema _ = do
411 declareNamedSchema _ = do
@@ -583,14 +583,14 @@ genericToNamedSchemaBoundedIntegral opts proxy
583 = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d)) (toSchemaBoundedIntegral proxy)
583 = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d)) (toSchemaBoundedIntegral proxy)
584
584
585-- | A configurable generic @'Schema'@ creator.
585-- | 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
587genericDeclareSchema opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchema opts proxy
587genericDeclareSchema opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchema opts proxy
588
588
589-- | A configurable generic @'NamedSchema'@ creator.
589-- | A configurable generic @'NamedSchema'@ creator.
590-- This function applied to @'defaultSchemaOptions'@
590-- This function applied to @'defaultSchemaOptions'@
591-- is used as the default for @'declareNamedSchema'@
591-- is used as the default for @'declareNamedSchema'@
592-- when the type is an instance of @'Generic'@.
592-- 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
594genericDeclareNamedSchema opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
594genericDeclareNamedSchema opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
595
595
596gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe T.Text
596gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe T.Text
@@ -618,7 +618,7 @@ nullarySchema = mempty
618gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
618gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
619gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
619gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
620
620
621−gdeclareSchema :: (GToSchema f, MonadDeclare (Definitions Schema) m) => SchemaOptions -> proxy f -> m Schema
621+gdeclareSchema :: GToSchema f => SchemaOptions -> proxy f -> Declare (Definitions Schema) Schema
622gdeclareSchema opts proxy = _namedSchemaSchema <$> gdeclareNamedSchema opts proxy mempty
622gdeclareSchema opts proxy = _namedSchemaSchema <$> gdeclareNamedSchema opts proxy mempty
623
623
624instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
624instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
@@ -652,7 +652,7 @@ instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
652 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
652 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
653 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
653 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
654
654
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)
656gdeclareSchemaRef opts proxy = do
656gdeclareSchemaRef opts proxy = do
657 case gtoNamedSchema opts proxy of
657 case gtoNamedSchema opts proxy of
658 NamedSchema (Just name) schema -> do
658 NamedSchema (Just name) schema -> do
@@ -676,8 +676,8 @@ appendItem x Nothing = Just (SwaggerItemsArray [x])
676appendItem x (Just (SwaggerItemsArray xs)) = Just (SwaggerItemsArray (xs ++ [x]))
676appendItem x (Just (SwaggerItemsArray xs)) = Just (SwaggerItemsArray (xs ++ [x]))
677appendItem _ _ = error "GToSchema.appendItem: cannot append to SwaggerItemsObject"
677appendItem _ _ = error "GToSchema.appendItem: cannot append to SwaggerItemsObject"
678
678
679−withFieldSchema :: forall proxy s f m. (Selector s, GToSchema f, MonadDeclare (Definitions Schema) m) =>
679+withFieldSchema :: forall proxy s f. (Selector s, GToSchema f) =>
680− SchemaOptions -> proxy s f -> Bool -> Schema -> m Schema
680+ SchemaOptions -> proxy s f -> Bool -> Schema -> Declare (Definitions Schema) Schema
681withFieldSchema opts _ isRequiredField schema = do
681withFieldSchema opts _ isRequiredField schema = do
682 ref <- gdeclareSchemaRef opts (Proxy :: Proxy f)
682 ref <- gdeclareSchemaRef opts (Proxy :: Proxy f)
683 return $
683 return $
@@ -713,12 +713,11 @@ instance OVERLAPPABLE_ ToSchema c => GToSchema (K1 i c) where
713instance (GSumToSchema f, GSumToSchema g) => GToSchema (f :+: g) where
713instance (GSumToSchema f, GSumToSchema g) => GToSchema (f :+: g) where
714 gdeclareNamedSchema = gdeclareNamedSumSchema
714 gdeclareNamedSchema = gdeclareNamedSumSchema
715
715
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
717gdeclareNamedSumSchema opts proxy s
717gdeclareNamedSumSchema opts proxy s
718 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
718 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
719 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
719 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
720 where
720 where
721− declareSumSchema :: MonadDeclare (Definitions Schema) m => WriterT AllNullary m Schema
722 declareSumSchema = gsumToSchema opts proxy s
721 declareSumSchema = gsumToSchema opts proxy s
723 (sumSchema, All allNullary) = undeclare (runWriterT declareSumSchema)
722 (sumSchema, All allNullary) = undeclare (runWriterT declareSumSchema)
724
723
@@ -729,7 +728,7 @@ gdeclareNamedSumSchema opts proxy s
729type AllNullary = All
728type AllNullary = All
730
729
731class GSumToSchema f where
730class 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
733
732
734instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
733instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
735 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) >=> gsumToSchema opts (Proxy :: Proxy g)
734 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) >=> gsumToSchema opts (Proxy :: Proxy g)
@@ -744,8 +743,8 @@ gsumConToSchemaWith ref opts _ schema = schema
744 where
743 where
745 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
744 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
746
745
747−gsumConToSchema :: forall c f m proxy. (GToSchema (C1 c f), Constructor c, MonadDeclare (Definitions Schema) m) =>
746+gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
748− SchemaOptions -> proxy (C1 c f) -> Schema -> m Schema
747+ SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
749gsumConToSchema opts proxy schema = do
748gsumConToSchema opts proxy schema = do
750 ref <- gdeclareSchemaRef opts proxy
749 ref <- gdeclareSchemaRef opts proxy
751 return $ gsumConToSchemaWith ref opts proxy schema
750 return $ gsumConToSchemaWith ref opts proxy schema
@@ -766,3 +765,4 @@ instance Constructor c => GSumToSchema (C1 c U1) where
766data Proxy2 a b = Proxy2
765data Proxy2 a b = Proxy2
767
766
768data Proxy3 a b c = Proxy3
767data Proxy3 a b c = Proxy3
768+