Commit f0a60bd8 authored by Nicolas Pouillard's avatar Nicolas Pouillard

Fix ToSchema instances to workaround swagger2#issue94

parent 63e3a6fd
...@@ -116,7 +116,7 @@ import Formatting.Clock (timeSpecs) ...@@ -116,7 +116,7 @@ import Formatting.Clock (timeSpecs)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Gargantext.Core.Types (ListType(..), NodeId, ListId, DocId, Limit, Offset, HasInvalidError, assertValid) import Gargantext.Core.Types (ListType(..), NodeId, ListId, DocId, Limit, Offset, HasInvalidError, assertValid)
import Gargantext.Core.Types (TODO) import Gargantext.Core.Types (TODO)
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger) import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger, wellNamedSchema)
import Gargantext.Database.Action.Metrics.NgramsByNode (getOccByNgramsOnlyFast') import Gargantext.Database.Action.Metrics.NgramsByNode (getOccByNgramsOnlyFast')
import Gargantext.Database.Query.Table.Node.Select import Gargantext.Database.Query.Table.Node.Select
import Gargantext.Database.Query.Table.Ngrams hiding (NgramsType(..), ngrams, ngramsType, ngrams_terms) import Gargantext.Database.Query.Table.Ngrams hiding (NgramsType(..), ngrams, ngramsType, ngrams_terms)
...@@ -200,7 +200,7 @@ instance (Ord a, FromJSON a) => FromJSON (MSet a) where ...@@ -200,7 +200,7 @@ instance (Ord a, FromJSON a) => FromJSON (MSet a) where
instance (ToJSONKey a, ToSchema a) => ToSchema (MSet a) where instance (ToJSONKey a, ToSchema a) => ToSchema (MSet a) where
-- TODO -- TODO
declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy TODO) declareNamedSchema _ = wellNamedSchema "" (Proxy :: Proxy TODO)
------------------------------------------------------------------------ ------------------------------------------------------------------------
type NgramsTerm = Text type NgramsTerm = Text
...@@ -492,7 +492,7 @@ instance (Ord a, Arbitrary a) => Arbitrary (PatchMSet a) where ...@@ -492,7 +492,7 @@ instance (Ord a, Arbitrary a) => Arbitrary (PatchMSet a) where
instance ToSchema a => ToSchema (PatchMSet a) where instance ToSchema a => ToSchema (PatchMSet a) where
-- TODO -- TODO
declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy TODO) declareNamedSchema _ = wellNamedSchema "" (Proxy :: Proxy TODO)
type instance Patched (PatchMSet a) = MSet a type instance Patched (PatchMSet a) = MSet a
...@@ -665,8 +665,8 @@ data Versioned a = Versioned ...@@ -665,8 +665,8 @@ data Versioned a = Versioned
deriving (Generic, Show, Eq) deriving (Generic, Show, Eq)
deriveJSON (unPrefix "_v_") ''Versioned deriveJSON (unPrefix "_v_") ''Versioned
makeLenses ''Versioned makeLenses ''Versioned
instance ToSchema a => ToSchema (Versioned a) where instance (Typeable a, ToSchema a) => ToSchema (Versioned a) where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_v_") declareNamedSchema = wellNamedSchema "_v_"
instance Arbitrary a => Arbitrary (Versioned a) where instance Arbitrary a => Arbitrary (Versioned a) where
arbitrary = Versioned 1 <$> arbitrary -- TODO 1 is constant so far arbitrary = Versioned 1 <$> arbitrary -- TODO 1 is constant so far
......
...@@ -34,13 +34,13 @@ import Data.Monoid ...@@ -34,13 +34,13 @@ import Data.Monoid
import Data.Semigroup import Data.Semigroup
import Data.Set (Set, empty) import Data.Set (Set, empty)
import Data.Swagger (ToParamSchema) import Data.Swagger (ToParamSchema)
import Data.Swagger (ToSchema(..), genericDeclareNamedSchema) import Data.Swagger (ToSchema(..))
import Data.Text (Text, unpack) import Data.Text (Text, unpack)
import Data.Validity import Data.Validity
import GHC.Generics import GHC.Generics
import Gargantext.Core.Types.Main import Gargantext.Core.Types.Main
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger) import Gargantext.Core.Utils.Prefix (unPrefix, wellNamedSchema)
import Gargantext.Prelude import Gargantext.Prelude
import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary) import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
...@@ -150,8 +150,8 @@ data TableResult a = TableResult { tr_count :: Int ...@@ -150,8 +150,8 @@ data TableResult a = TableResult { tr_count :: Int
$(deriveJSON (unPrefix "tr_") ''TableResult) $(deriveJSON (unPrefix "tr_") ''TableResult)
instance ToSchema a => ToSchema (TableResult a) where instance (Typeable a, ToSchema a) => ToSchema (TableResult a) where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "tr_") declareNamedSchema = wellNamedSchema "tr_"
instance Arbitrary a => Arbitrary (TableResult a) where instance Arbitrary a => Arbitrary (TableResult a) where
arbitrary = TableResult <$> arbitrary <*> arbitrary arbitrary = TableResult <$> arbitrary <*> arbitrary
......
...@@ -26,7 +26,7 @@ import Data.Monoid ((<>)) ...@@ -26,7 +26,7 @@ import Data.Monoid ((<>))
import Data.Swagger import Data.Swagger
import Data.Text (Text, unpack) import Data.Text (Text, unpack)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger) import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger, wellNamedSchema)
import Gargantext.Database.Admin.Types.Node -- (NodeType(..), Node, Hyperdata(..)) import Gargantext.Database.Admin.Types.Node -- (NodeType(..), Node, Hyperdata(..))
import Gargantext.Prelude import Gargantext.Prelude
import Prelude (Enum, Bounded, minBound, maxBound) import Prelude (Enum, Bounded, minBound, maxBound)
...@@ -98,8 +98,8 @@ data Tree a = TreeN { _tn_node :: a, _tn_children :: [Tree a] } ...@@ -98,8 +98,8 @@ data Tree a = TreeN { _tn_node :: a, _tn_children :: [Tree a] }
$(deriveJSON (unPrefix "_tn_") ''Tree) $(deriveJSON (unPrefix "_tn_") ''Tree)
instance ToSchema a => ToSchema (Tree a) where instance (Typeable a, ToSchema a) => ToSchema (Tree a) where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_tn_") declareNamedSchema = wellNamedSchema "_tn_"
instance Arbitrary (Tree NodeTree) where instance Arbitrary (Tree NodeTree) where
arbitrary = elements [userTree, userTree] arbitrary = elements [userTree, userTree]
......
...@@ -12,7 +12,10 @@ commentary with @some markup@. ...@@ -12,7 +12,10 @@ commentary with @some markup@.
-} -}
module Gargantext.Core.Utils.Prefix where module Gargantext.Core.Utils.Prefix
( module Gargantext.Core.Utils.Prefix
, wellNamedSchema
) where
import Prelude import Prelude
...@@ -22,6 +25,7 @@ import Data.Aeson.Types (Parser) ...@@ -22,6 +25,7 @@ import Data.Aeson.Types (Parser)
import Data.Char (toLower) import Data.Char (toLower)
import Data.Monoid ((<>)) import Data.Monoid ((<>))
import Data.Swagger.SchemaOptions (SchemaOptions, fromAesonOptions) import Data.Swagger.SchemaOptions (SchemaOptions, fromAesonOptions)
import Servant.Job.Utils (wellNamedSchema)
import Text.Read (Read(..),readMaybe) import Text.Read (Read(..),readMaybe)
......
...@@ -29,7 +29,7 @@ import Test.QuickCheck.Arbitrary ...@@ -29,7 +29,7 @@ import Test.QuickCheck.Arbitrary
import Gargantext.API.Ngrams.NTree (MyTree) import Gargantext.API.Ngrams.NTree (MyTree)
import Gargantext.Database.Admin.Types.Metrics (ChartMetrics(..), Metrics) import Gargantext.Database.Admin.Types.Metrics (ChartMetrics(..), Metrics)
import Gargantext.Database.Prelude (fromField') import Gargantext.Database.Prelude (fromField')
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger) import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger, wellNamedSchema)
import Gargantext.Viz.Phylo (Phylo(..)) import Gargantext.Viz.Phylo (Phylo(..))
import Gargantext.Viz.Types (Histo(..)) import Gargantext.Viz.Types (Histo(..))
...@@ -179,9 +179,9 @@ $(makeLenses ''HyperdataField) ...@@ -179,9 +179,9 @@ $(makeLenses ''HyperdataField)
defaultHyperdataField :: HyperdataField CorpusField defaultHyperdataField :: HyperdataField CorpusField
defaultHyperdataField = HyperdataField Markdown "name" defaultCorpusField defaultHyperdataField = HyperdataField Markdown "name" defaultCorpusField
instance (ToSchema a) => ToSchema (HyperdataField a) where instance (Typeable a, ToSchema a) => ToSchema (HyperdataField a) where
declareNamedSchema = declareNamedSchema =
genericDeclareNamedSchema (unPrefixSwagger "_hf_") wellNamedSchema "_hf_"
-- & mapped.schema.description ?~ "HyperdataField" -- & mapped.schema.description ?~ "HyperdataField"
-- & mapped.schema.example ?~ toJSON defaultHyperdataField -- & mapped.schema.example ?~ toJSON defaultHyperdataField
......
...@@ -11,7 +11,7 @@ import Protolude ...@@ -11,7 +11,7 @@ import Protolude
import Test.QuickCheck.Arbitrary import Test.QuickCheck.Arbitrary
import Gargantext.Core.Types (ListType(..)) import Gargantext.Core.Types (ListType(..))
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger) import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger, wellNamedSchema)
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
...@@ -48,8 +48,8 @@ deriveJSON (unPrefix "m_") ''Metric ...@@ -48,8 +48,8 @@ deriveJSON (unPrefix "m_") ''Metric
data ChartMetrics a = ChartMetrics { chartMetrics_data :: a } data ChartMetrics a = ChartMetrics { chartMetrics_data :: a }
deriving (Generic, Show) deriving (Generic, Show)
instance (ToSchema a) => ToSchema (ChartMetrics a) where instance (Typeable a, ToSchema a) => ToSchema (ChartMetrics a) where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "chartMetrics_") declareNamedSchema = wellNamedSchema "chartMetrics_"
instance (Arbitrary a) => Arbitrary (ChartMetrics a) instance (Arbitrary a) => Arbitrary (ChartMetrics a)
where where
arbitrary = ChartMetrics <$> arbitrary arbitrary = ChartMetrics <$> arbitrary
......
...@@ -29,6 +29,7 @@ import Data.Eq (Eq) ...@@ -29,6 +29,7 @@ import Data.Eq (Eq)
import Data.Swagger import Data.Swagger
import Data.Text (Text, unpack) import Data.Text (Text, unpack)
import Data.Time (UTCTime) import Data.Time (UTCTime)
import Data.Typeable (Typeable)
import Database.PostgreSQL.Simple.FromField (FromField, fromField) import Database.PostgreSQL.Simple.FromField (FromField, fromField)
import Database.PostgreSQL.Simple.ToField (ToField, toField) import Database.PostgreSQL.Simple.ToField (ToField, toField)
import GHC.Generics (Generic) import GHC.Generics (Generic)
...@@ -43,7 +44,7 @@ import Test.QuickCheck.Instances.Time () ...@@ -43,7 +44,7 @@ import Test.QuickCheck.Instances.Time ()
import Text.Read (read) import Text.Read (read)
import Text.Show (Show()) import Text.Show (Show())
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger) import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger, wellNamedSchema)
import Gargantext.Database.Prelude (fromField') import Gargantext.Database.Prelude (fromField')
import Gargantext.Database.Schema.Node import Gargantext.Database.Schema.Node
import Gargantext.Prelude import Gargantext.Prelude
...@@ -60,37 +61,37 @@ type NodeSearch json = NodePolySearch NodeId NodeTypeId UserId (Maybe ParentId ...@@ -60,37 +61,37 @@ type NodeSearch json = NodePolySearch NodeId NodeTypeId UserId (Maybe ParentId
------------------------------------------------------------------------ ------------------------------------------------------------------------
instance ToSchema hyperdata => instance (Typeable hyperdata, ToSchema hyperdata) =>
ToSchema (NodePoly NodeId NodeTypeId ToSchema (NodePoly NodeId NodeTypeId
(Maybe UserId) (Maybe UserId)
ParentId NodeName ParentId NodeName
UTCTime hyperdata UTCTime hyperdata
) where ) where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_node_") declareNamedSchema = wellNamedSchema "_node_"
instance ToSchema hyperdata => instance (Typeable hyperdata, ToSchema hyperdata) =>
ToSchema (NodePoly NodeId NodeTypeId ToSchema (NodePoly NodeId NodeTypeId
UserId UserId
(Maybe ParentId) NodeName (Maybe ParentId) NodeName
UTCTime hyperdata UTCTime hyperdata
) where ) where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_node_") declareNamedSchema = wellNamedSchema "_node_"
instance ToSchema hyperdata => instance (Typeable hyperdata, ToSchema hyperdata) =>
ToSchema (NodePolySearch NodeId NodeTypeId ToSchema (NodePolySearch NodeId NodeTypeId
(Maybe UserId) (Maybe UserId)
ParentId NodeName ParentId NodeName
UTCTime hyperdata (Maybe TSVector) UTCTime hyperdata (Maybe TSVector)
) where ) where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_ns_") declareNamedSchema = wellNamedSchema "_ns_"
instance ToSchema hyperdata => instance (Typeable hyperdata, ToSchema hyperdata) =>
ToSchema (NodePolySearch NodeId NodeTypeId ToSchema (NodePolySearch NodeId NodeTypeId
UserId UserId
(Maybe ParentId) NodeName (Maybe ParentId) NodeName
UTCTime hyperdata (Maybe TSVector) UTCTime hyperdata (Maybe TSVector)
) where ) where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_ns_") declareNamedSchema = wellNamedSchema "_ns_"
instance (Arbitrary hyperdata instance (Arbitrary hyperdata
,Arbitrary nodeId ,Arbitrary nodeId
......
...@@ -44,6 +44,7 @@ import Data.Swagger ...@@ -44,6 +44,7 @@ import Data.Swagger
import Data.Text (Text) import Data.Text (Text)
import Data.Time (UTCTime) import Data.Time (UTCTime)
import Data.Time.Segment (jour) import Data.Time.Segment (jour)
import Data.Typeable (Typeable)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Opaleye import Opaleye
import Prelude hiding (null, id, map, sum, not, read) import Prelude hiding (null, id, map, sum, not, read)
...@@ -53,7 +54,7 @@ import Test.QuickCheck.Arbitrary ...@@ -53,7 +54,7 @@ import Test.QuickCheck.Arbitrary
import qualified Opaleye.Internal.Unpackspec() import qualified Opaleye.Internal.Unpackspec()
import Gargantext.Core.Types import Gargantext.Core.Types
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger) import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger, wellNamedSchema)
import Gargantext.Database.Admin.Config (nodeTypeId) import Gargantext.Database.Admin.Config (nodeTypeId)
import Gargantext.Database.Admin.Types.Hyperdata import Gargantext.Database.Admin.Types.Hyperdata
import Gargantext.Database.Query.Filter import Gargantext.Database.Query.Filter
...@@ -105,8 +106,8 @@ data Pair i l = Pair {_p_id :: i ...@@ -105,8 +106,8 @@ data Pair i l = Pair {_p_id :: i
$(deriveJSON (unPrefix "_p_") ''Pair) $(deriveJSON (unPrefix "_p_") ''Pair)
$(makeAdaptorAndInstance "pPair" ''Pair) $(makeAdaptorAndInstance "pPair" ''Pair)
instance (ToSchema i, ToSchema l) => ToSchema (Pair i l) where instance (Typeable i, Typeable l, ToSchema i, ToSchema l) => ToSchema (Pair i l) where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_p_") declareNamedSchema = wellNamedSchema "_p_"
instance (Arbitrary i, Arbitrary l) => Arbitrary (Pair i l) where instance (Arbitrary i, Arbitrary l) => Arbitrary (Pair i l) where
arbitrary = Pair <$> arbitrary <*> arbitrary arbitrary = Pair <$> arbitrary <*> arbitrary
...@@ -125,8 +126,13 @@ instance ( ToSchema id ...@@ -125,8 +126,13 @@ instance ( ToSchema id
, ToSchema hyperdata , ToSchema hyperdata
, ToSchema score , ToSchema score
, ToSchema pair , ToSchema pair
, Typeable id
, Typeable date
, Typeable hyperdata
, Typeable score
, Typeable pair
) => ToSchema (FacetPaired id date hyperdata score pair) where ) => ToSchema (FacetPaired id date hyperdata score pair) where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_fp_") declareNamedSchema = wellNamedSchema "_fp_"
instance ( Arbitrary id instance ( Arbitrary id
, Arbitrary date , Arbitrary date
......
...@@ -26,6 +26,7 @@ module Gargantext.Prelude ...@@ -26,6 +26,7 @@ module Gargantext.Prelude
, sortWith , sortWith
, module Prelude , module Prelude
, MonadBase(..) , MonadBase(..)
, Typeable
) )
where where
...@@ -36,6 +37,7 @@ import GHC.Real (round) ...@@ -36,6 +37,7 @@ import GHC.Real (round)
import Data.Map (Map, lookup) import Data.Map (Map, lookup)
import Data.Maybe (isJust, fromJust, maybe) import Data.Maybe (isJust, fromJust, maybe)
import Data.Text (Text) import Data.Text (Text)
import Data.Typeable (Typeable)
import Protolude ( Bool(True, False), Int, Int64, Double, Integer import Protolude ( Bool(True, False), Int, Int64, Double, Integer
, Fractional, Num, Maybe(Just,Nothing) , Fractional, Num, Maybe(Just,Nothing)
, Enum, Bounded, Float , Enum, Bounded, Float
......
...@@ -47,7 +47,7 @@ extra-deps: ...@@ -47,7 +47,7 @@ extra-deps:
#- git: https://github.com/delanoe/servant-job.git #- git: https://github.com/delanoe/servant-job.git
#commit: 7a7b7100e6d132adb4c11b25b2128e6309690ac0 #commit: 7a7b7100e6d132adb4c11b25b2128e6309690ac0
- git: https://github.com/np/servant-job.git - git: https://github.com/np/servant-job.git
commit: 5b994e20e90e344b67368b8c6ae3bd917322a35e commit: 6487744c322baaa9229fdabd321a878a5b363c61
- git: https://gitlab.iscpif.fr/gargantext/clustering-louvain.git - git: https://gitlab.iscpif.fr/gargantext/clustering-louvain.git
commit: 7d74f96dfea8e51fbab1793cc0429b2fe741f73d commit: 7d74f96dfea8e51fbab1793cc0429b2fe741f73d
- git: https://github.com/np/patches-map - git: https://github.com/np/patches-map
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment