]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Types/Node.hs
[TYPES] Node Hyperdata for Json | Markdown fields.
[gargantext.git] / src / Gargantext / Database / Types / Node.hs
1 {-|
2 Module : Gargantext.Database.Types.Nodes
3 Description : Main Types of Nodes in Database
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
13
14 {-# LANGUAGE BangPatterns #-}
15 {-# LANGUAGE DeriveGeneric #-}
16 {-# LANGUAGE FlexibleInstances #-}
17 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
18 {-# LANGUAGE NoImplicitPrelude #-}
19 {-# LANGUAGE OverloadedStrings #-}
20 {-# LANGUAGE TemplateHaskell #-}
21 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
22
23 -- {-# LANGUAGE DuplicateRecordFields #-}
24
25 module Gargantext.Database.Types.Node
26 where
27
28 import Prelude (Enum, Bounded, minBound, maxBound)
29
30 import GHC.Generics (Generic)
31
32 import Control.Lens hiding (elements, (&))
33 import Control.Applicative ((<*>))
34 import Control.Monad (mzero)
35
36 import Data.Aeson
37 import Data.Aeson.Types (emptyObject)
38 import Data.Aeson (Object, toJSON)
39 import Data.Aeson.TH (deriveJSON)
40 import Data.ByteString.Lazy (ByteString)
41 import Data.Either
42 import Data.Eq (Eq)
43 import Data.Monoid (mempty)
44 import Data.Text (Text, unpack)
45 import Data.Time (UTCTime)
46 import Data.Swagger
47
48 import Text.Read (read)
49 import Text.Show (Show())
50
51 import Database.PostgreSQL.Simple.ToField (ToField, toField, toJSONField)
52 import Database.PostgreSQL.Simple.FromField (FromField, fromField)
53 import Servant
54
55 import Test.QuickCheck.Arbitrary
56 import Test.QuickCheck (elements)
57 import Test.QuickCheck.Instances.Time ()
58 import Test.QuickCheck.Instances.Text ()
59
60 import Gargantext.Prelude
61 import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger)
62 import Gargantext.Viz.Phylo (Phylo)
63 --import Gargantext.Database.Utils
64 ------------------------------------------------------------------------
65
66 newtype NodeId = NodeId Int
67 deriving (Show, Read, Generic, Num, Eq, Ord, Enum, ToJSONKey, FromJSONKey, ToJSON, FromJSON)
68
69 instance ToField NodeId where
70 toField (NodeId n) = toField n
71
72 instance FromField NodeId where
73 fromField field mdata = do
74 n <- fromField field mdata
75 if (n :: Int) > 0
76 then return $ NodeId n
77 else mzero
78
79 instance ToSchema NodeId
80
81
82 type NodeTypeId = Int
83 type NodeName = Text
84 type TSVector = Text
85
86 ------------------------------------------------------------------------
87 data NodePoly id typename userId
88 parentId name date
89 hyperdata = Node { _node_id :: id
90 , _node_typename :: typename
91
92 , _node_userId :: userId
93 , _node_parentId :: parentId
94
95 , _node_name :: name
96 , _node_date :: date
97
98 , _node_hyperdata :: hyperdata
99 } deriving (Show, Generic)
100 $(deriveJSON (unPrefix "_node_") ''NodePoly)
101 $(makeLenses ''NodePoly)
102
103 -- | NodePoly indicates that Node has a Polymorphism Type
104 type Node json = NodePoly NodeId NodeTypeId UserId (Maybe ParentId) NodeName UTCTime json
105
106
107 ------------------------------------------------------------------------
108
109
110 instance FromHttpApiData NodeId where
111 parseUrlPiece n = pure $ NodeId $ (read . cs) n
112
113 instance ToParamSchema NodeId
114 instance Arbitrary NodeId where
115 arbitrary = NodeId <$> arbitrary
116
117 type ParentId = NodeId
118 type CorpusId = NodeId
119 type ListId = NodeId
120 type DocumentId = NodeId
121 type DocId = NodeId
122 type RootId = NodeId
123 type MasterCorpusId = CorpusId
124 type UserCorpusId = CorpusId
125
126 type GraphId = NodeId
127 type PhyloId = NodeId
128 type AnnuaireId = NodeId
129 type ContactId = NodeId
130
131 type UserId = Int
132 type MasterUserId = UserId
133
134 id2int :: NodeId -> Int
135 id2int (NodeId n) = n
136
137 ------------------------------------------------------------------------
138 data Status = Status { status_failed :: !Int
139 , status_succeeded :: !Int
140 , status_remaining :: !Int
141 } deriving (Show, Generic)
142 $(deriveJSON (unPrefix "status_") ''Status)
143
144 instance Arbitrary Status where
145 arbitrary = Status <$> arbitrary <*> arbitrary <*> arbitrary
146
147 ------------------------------------------------------------------------
148 data StatusV3 = StatusV3 { statusV3_error :: !(Maybe Text)
149 , statusV3_action :: !(Maybe Text)
150 } deriving (Show, Generic)
151 $(deriveJSON (unPrefix "statusV3_") ''StatusV3)
152 ------------------------------------------------------------------------
153
154 -- Only Hyperdata types should be member of this type class.
155
156 ------------------------------------------------------------------------
157 data HyperdataDocumentV3 = HyperdataDocumentV3 { hyperdataDocumentV3_publication_day :: !(Maybe Int)
158 , hyperdataDocumentV3_language_iso2 :: !(Maybe Text)
159 , hyperdataDocumentV3_publication_second :: !(Maybe Int)
160 , hyperdataDocumentV3_publication_minute :: !(Maybe Int)
161 , hyperdataDocumentV3_publication_month :: !(Maybe Int)
162 , hyperdataDocumentV3_publication_hour :: !(Maybe Int)
163 , hyperdataDocumentV3_error :: !(Maybe Text)
164 , hyperdataDocumentV3_language_iso3 :: !(Maybe Text)
165 , hyperdataDocumentV3_authors :: !(Maybe Text)
166 , hyperdataDocumentV3_publication_year :: !(Maybe Int)
167 , hyperdataDocumentV3_publication_date :: !(Maybe Text)
168 , hyperdataDocumentV3_language_name :: !(Maybe Text)
169 , hyperdataDocumentV3_statuses :: !(Maybe [StatusV3])
170 , hyperdataDocumentV3_realdate_full_ :: !(Maybe Text)
171 , hyperdataDocumentV3_source :: !(Maybe Text)
172 , hyperdataDocumentV3_abstract :: !(Maybe Text)
173 , hyperdataDocumentV3_title :: !(Maybe Text)
174 } deriving (Show, Generic)
175 $(deriveJSON (unPrefix "hyperdataDocumentV3_") ''HyperdataDocumentV3)
176
177 class Hyperdata a
178 instance Hyperdata HyperdataDocumentV3
179
180 ------------------------------------------------------------------------
181 data HyperdataDocument = HyperdataDocument { _hyperdataDocument_bdd :: !(Maybe Text)
182 , _hyperdataDocument_doi :: !(Maybe Text)
183 , _hyperdataDocument_url :: !(Maybe Text)
184 , _hyperdataDocument_uniqId :: !(Maybe Text)
185 , _hyperdataDocument_uniqIdBdd :: !(Maybe Text)
186 , _hyperdataDocument_page :: !(Maybe Int)
187 , _hyperdataDocument_title :: !(Maybe Text)
188 , _hyperdataDocument_authors :: !(Maybe Text)
189 , _hyperdataDocument_institutes :: !(Maybe Text)
190 , _hyperdataDocument_source :: !(Maybe Text)
191 , _hyperdataDocument_abstract :: !(Maybe Text)
192 , _hyperdataDocument_publication_date :: !(Maybe Text)
193 , _hyperdataDocument_publication_year :: !(Maybe Int)
194 , _hyperdataDocument_publication_month :: !(Maybe Int)
195 , _hyperdataDocument_publication_day :: !(Maybe Int)
196 , _hyperdataDocument_publication_hour :: !(Maybe Int)
197 , _hyperdataDocument_publication_minute :: !(Maybe Int)
198 , _hyperdataDocument_publication_second :: !(Maybe Int)
199 , _hyperdataDocument_language_iso2 :: !(Maybe Text)
200 } deriving (Show, Generic)
201
202 $(deriveJSON (unPrefix "_hyperdataDocument_") ''HyperdataDocument)
203 $(makeLenses ''HyperdataDocument)
204
205 class ToHyperdataDocument a where
206 toHyperdataDocument :: a -> HyperdataDocument
207
208 instance ToHyperdataDocument HyperdataDocument
209 where
210 toHyperdataDocument = identity
211
212 instance Eq HyperdataDocument where
213 (==) h1 h2 = (==) (_hyperdataDocument_uniqId h1) (_hyperdataDocument_uniqId h2)
214
215 instance Ord HyperdataDocument where
216 compare h1 h2 = compare (_hyperdataDocument_publication_date h1) (_hyperdataDocument_publication_date h2)
217
218 instance Hyperdata HyperdataDocument
219
220 instance ToField HyperdataDocument where
221 toField = toJSONField
222
223 instance Arbitrary HyperdataDocument where
224 arbitrary = elements arbitraryHyperdataDocuments
225
226 arbitraryHyperdataDocuments :: [HyperdataDocument]
227 arbitraryHyperdataDocuments =
228 map toHyperdataDocument' ([ ("AI is big but less than crypto", "Troll System journal")
229 , ("Crypto is big but less than AI", "System Troll review" )
230 , ("Science is magic" , "Closed Source review")
231 , ("Open science for all" , "No Time" )
232 , ("Closed science for me" , "No Space" )
233 ] :: [(Text, Text)])
234 where
235 toHyperdataDocument' (t1,t2) =
236 HyperdataDocument Nothing Nothing Nothing Nothing Nothing Nothing (Just t1)
237 Nothing Nothing (Just t2) Nothing Nothing Nothing Nothing Nothing
238 Nothing Nothing Nothing Nothing
239
240 ------------------------------------------------------------------------
241 data LanguageNodes = LanguageNodes { languageNodes___unknown__ :: [Int]}
242 deriving (Show, Generic)
243 $(deriveJSON (unPrefix "languageNodes_") ''LanguageNodes)
244
245 ------------------------------------------------------------------------
246 -- level: debug | dev (fatal = critical)
247 data EventLevel = CRITICAL | FATAL | ERROR | WARNING | INFO | DEBUG
248 deriving (Show, Generic, Enum, Bounded)
249
250 instance FromJSON EventLevel
251 instance ToJSON EventLevel
252
253 instance Arbitrary EventLevel where
254 arbitrary = elements [minBound..maxBound]
255
256 instance ToSchema EventLevel where
257 declareNamedSchema proxy = genericDeclareNamedSchema defaultSchemaOptions proxy
258
259 ------------------------------------------------------------------------
260
261 data Event = Event { event_level :: !EventLevel
262 , event_message :: !Text
263 , event_date :: !UTCTime
264 } deriving (Show, Generic)
265 $(deriveJSON (unPrefix "event_") ''Event)
266
267 instance Arbitrary Event where
268 arbitrary = Event <$> arbitrary <*> arbitrary <*> arbitrary
269
270 instance ToSchema Event where
271 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "event_")
272
273 ------------------------------------------------------------------------
274
275 data Resource = Resource { resource_path :: !(Maybe Text)
276 , resource_scraper :: !(Maybe Text)
277 , resource_query :: !(Maybe Text)
278 , resource_events :: !([Event])
279 , resource_status :: !Status
280 , resource_date :: !UTCTime
281 } deriving (Show, Generic)
282 $(deriveJSON (unPrefix "resource_") ''Resource)
283
284 instance Arbitrary Resource where
285 arbitrary = Resource <$> arbitrary
286 <*> arbitrary
287 <*> arbitrary
288 <*> arbitrary
289 <*> arbitrary
290 <*> arbitrary
291
292 instance ToSchema Resource where
293 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "resource_")
294
295 ------------------------------------------------------------------------
296 data HyperdataUser = HyperdataUser { hyperdataUser_language :: !(Maybe Text)
297 } deriving (Show, Generic)
298 $(deriveJSON (unPrefix "hyperdataUser_") ''HyperdataUser)
299
300 instance Hyperdata HyperdataUser
301 ------------------------------------------------------------------------
302 data HyperdataFolder = HyperdataFolder { hyperdataFolder_desc :: !(Maybe Text)
303 } deriving (Show, Generic)
304 $(deriveJSON (unPrefix "hyperdataFolder_") ''HyperdataFolder)
305
306 instance Hyperdata HyperdataFolder
307 ------------------------------------------------------------------------
308
309 data CodeType = JSON | Markdown
310 deriving (Generic)
311 instance ToJSON CodeType
312 instance FromJSON CodeType
313 instance ToSchema CodeType
314
315 ------------------------------------------------------------------------
316 data CorpusField = MarkdownField { _cf_text :: !Text }
317 | JsonField { _cf_title :: !Text
318 , _cf_desc :: !Text
319 , _cf_query :: !Text
320 , _cf_authors :: !Text
321 , _cf_resources :: ![Resource]
322 } deriving (Generic)
323
324 $(deriveJSON (unPrefix "_cf_") ''CorpusField)
325 $(makeLenses ''CorpusField)
326
327 defaultCorpusField :: CorpusField
328 defaultCorpusField = MarkdownField "#title"
329
330 instance ToSchema CorpusField where
331 declareNamedSchema proxy =
332 genericDeclareNamedSchema (unPrefixSwagger "_cf_") proxy
333 & mapped.schema.description ?~ "CorpusField"
334 & mapped.schema.example ?~ toJSON defaultCorpusField
335
336 ------------------------------------------------------------------------
337 data HyperdataField a =
338 HyperdataField { _hf_type :: !CodeType
339 , _hf_name :: !Text
340 , _hf_data :: !a
341 } deriving (Generic)
342 $(deriveJSON (unPrefix "_hf_") ''HyperdataField)
343 $(makeLenses ''HyperdataField)
344
345 defaultHyperdataField :: HyperdataField CorpusField
346 defaultHyperdataField = HyperdataField Markdown "name" defaultCorpusField
347
348 instance (ToSchema a) => ToSchema (HyperdataField a) where
349 declareNamedSchema =
350 genericDeclareNamedSchema (unPrefixSwagger "_hf_")
351 -- & mapped.schema.description ?~ "HyperdataField"
352 -- & mapped.schema.example ?~ toJSON defaultHyperdataField
353
354 ------------------------------------------------------------------------
355 data HyperdataCorpus =
356 HyperdataCorpus { _hc_fields :: ![HyperdataField CorpusField] }
357 deriving (Generic)
358 $(deriveJSON (unPrefix "_hc_") ''HyperdataCorpus)
359 $(makeLenses ''HyperdataCorpus)
360
361 instance Hyperdata HyperdataCorpus
362
363 corpusExample :: ByteString
364 corpusExample = "" -- TODO
365
366 defaultCorpus :: HyperdataCorpus
367 defaultCorpus = HyperdataCorpus [ HyperdataField JSON "Mandatory fields" (JsonField "Title" "Descr" "Bool query" "Authors" [])
368 , HyperdataField Markdown "Optional Text" (MarkdownField "#title\n##subtitle")
369 ]
370
371 hyperdataCorpus :: HyperdataCorpus
372 hyperdataCorpus = case decode corpusExample of
373 Just hp -> hp
374 Nothing -> defaultCorpus
375
376 instance Arbitrary HyperdataCorpus where
377 arbitrary = pure hyperdataCorpus -- TODO
378
379 ------------------------------------------------------------------------
380
381 data HyperdataList = HyperdataList {hd_list :: !(Maybe Text)
382 } deriving (Show, Generic)
383 $(deriveJSON (unPrefix "hd_") ''HyperdataList)
384
385 instance Hyperdata HyperdataList
386
387 ------------------------------------------------------------------------
388 data HyperdataAnnuaire = HyperdataAnnuaire { hyperdataAnnuaire_title :: !(Maybe Text)
389 , hyperdataAnnuaire_desc :: !(Maybe Text)
390 } deriving (Show, Generic)
391 $(deriveJSON (unPrefix "hyperdataAnnuaire_") ''HyperdataAnnuaire)
392
393 instance Hyperdata HyperdataAnnuaire
394
395 hyperdataAnnuaire :: HyperdataAnnuaire
396 hyperdataAnnuaire = HyperdataAnnuaire (Just "Annuaire Title") (Just "Annuaire Description")
397
398 instance Arbitrary HyperdataAnnuaire where
399 arbitrary = pure hyperdataAnnuaire -- TODO
400
401 ------------------------------------------------------------------------
402 newtype HyperdataAny = HyperdataAny Object
403 deriving (Show, Generic, ToJSON, FromJSON)
404
405 instance Hyperdata HyperdataAny
406
407 instance Arbitrary HyperdataAny where
408 arbitrary = pure $ HyperdataAny mempty -- TODO produce arbitrary objects
409 ------------------------------------------------------------------------
410
411 {-
412 instance Arbitrary HyperdataList' where
413 arbitrary = elements [HyperdataList' (Just "from list A")]
414 -}
415
416 ----
417 data HyperdataListModel = HyperdataListModel { _hlm_params :: !(Int, Int)
418 , _hlm_path :: !Text
419 , _hlm_score :: !(Maybe Double)
420 } deriving (Show, Generic)
421
422 instance Hyperdata HyperdataListModel
423 instance Arbitrary HyperdataListModel where
424 arbitrary = elements [HyperdataListModel (100,100) "models/example.model" Nothing]
425
426 $(deriveJSON (unPrefix "_hlm_") ''HyperdataListModel)
427 $(makeLenses ''HyperdataListModel)
428
429 ------------------------------------------------------------------------
430 data HyperdataScore = HyperdataScore { hyperdataScore_preferences :: !(Maybe Text)
431 } deriving (Show, Generic)
432 $(deriveJSON (unPrefix "hyperdataScore_") ''HyperdataScore)
433
434 instance Hyperdata HyperdataScore
435
436 ------------------------------------------------------------------------
437
438 data HyperdataResource = HyperdataResource { hyperdataResource_preferences :: !(Maybe Text)
439 } deriving (Show, Generic)
440 $(deriveJSON (unPrefix "hyperdataResource_") ''HyperdataResource)
441
442 instance Hyperdata HyperdataResource
443
444 ------------------------------------------------------------------------
445 data HyperdataDashboard = HyperdataDashboard { hyperdataDashboard_preferences :: !(Maybe Text)
446 } deriving (Show, Generic)
447 $(deriveJSON (unPrefix "hyperdataDashboard_") ''HyperdataDashboard)
448
449 instance Hyperdata HyperdataDashboard
450
451 ------------------------------------------------------------------------
452
453 -- TODO add the Graph Structure here
454 data HyperdataPhylo = HyperdataPhylo { hyperdataPhylo_preferences :: !(Maybe Text)
455 , hyperdataPhylo_data :: !(Maybe Phylo)
456 } deriving (Show, Generic)
457 $(deriveJSON (unPrefix "hyperdataPhylo_") ''HyperdataPhylo)
458
459 instance Hyperdata HyperdataPhylo
460
461 ------------------------------------------------------------------------
462 -- | TODO FEATURE: Notebook saved in the node
463 data HyperdataNotebook = HyperdataNotebook { hyperdataNotebook_preferences :: !(Maybe Text)
464 } deriving (Show, Generic)
465 $(deriveJSON (unPrefix "hyperdataNotebook_") ''HyperdataNotebook)
466
467 instance Hyperdata HyperdataNotebook
468
469
470 -- | TODO CLEAN
471 data HyperData = HyperdataTexts { hd_preferences :: Maybe Text }
472 | HyperdataList' { hd_preferences :: Maybe Text}
473 deriving (Show, Generic)
474
475 $(deriveJSON (unPrefix "hd_") ''HyperData)
476
477 instance Hyperdata HyperData
478
479
480
481 ------------------------------------------------------------------------
482 -- | Then a Node can be either a Folder or a Corpus or a Document
483 data NodeType = NodeUser
484 | NodeFolderPrivate
485 | NodeFolderShared | NodeTeam
486 | NodeFolderPublic
487 | NodeFolder
488
489 | NodeCorpus | NodeCorpusV3 | NodeTexts | NodeDocument
490 | NodeAnnuaire | NodeContact
491 | NodeGraph | NodePhylo
492 | NodeDashboard | NodeChart | NodeNoteBook
493 | NodeList | NodeListModel
494 | NodeListCooc
495 deriving (Show, Read, Eq, Generic, Bounded, Enum)
496
497
498 {-
499 -- | Metrics
500 -- | NodeOccurrences
501 -- | Classification
502 -}
503
504 allNodeTypes :: [NodeType]
505 allNodeTypes = [minBound ..]
506
507 instance FromJSON NodeType
508 instance ToJSON NodeType
509
510 instance FromHttpApiData NodeType
511 where
512 parseUrlPiece = Right . read . unpack
513
514 instance ToParamSchema NodeType
515 instance ToSchema NodeType
516
517
518 data NodePolySearch id typename userId
519 parentId name date
520 hyperdata search = NodeSearch { _ns_id :: id
521 , _ns_typename :: typename
522 , _ns_userId :: userId
523 -- , nodeUniqId :: shaId
524 , _ns_parentId :: parentId
525 , _ns_name :: name
526 , _ns_date :: date
527
528 , _ns_hyperdata :: hyperdata
529 , _ns_search :: search
530 } deriving (Show, Generic)
531 $(deriveJSON (unPrefix "_ns_") ''NodePolySearch)
532 $(makeLenses ''NodePolySearch)
533
534 type NodeSearch json = NodePolySearch NodeId NodeTypeId UserId (Maybe ParentId) NodeName UTCTime json (Maybe TSVector)
535 ------------------------------------------------------------------------
536
537
538 instance (Arbitrary hyperdata
539 ,Arbitrary nodeId
540 ,Arbitrary nodeTypeId
541 ,Arbitrary userId
542 ,Arbitrary nodeParentId
543 ) => Arbitrary (NodePoly nodeId nodeTypeId userId nodeParentId
544 NodeName UTCTime hyperdata) where
545 --arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
546 arbitrary = Node <$> arbitrary <*> arbitrary <*> arbitrary
547 <*> arbitrary <*> arbitrary <*> arbitrary
548 <*> arbitrary
549
550 instance (Arbitrary hyperdata
551 ,Arbitrary nodeId
552 ,Arbitrary nodeTypeId
553 ,Arbitrary userId
554 ,Arbitrary nodeParentId
555 ) => Arbitrary (NodePolySearch nodeId nodeTypeId userId nodeParentId
556 NodeName UTCTime hyperdata (Maybe TSVector)) where
557 --arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
558 arbitrary = NodeSearch <$> arbitrary <*> arbitrary <*> arbitrary
559 <*> arbitrary <*> arbitrary <*> arbitrary
560 <*> arbitrary <*> arbitrary
561
562
563 ------------------------------------------------------------------------
564 hyperdataDocument :: HyperdataDocument
565 hyperdataDocument = case decode docExample of
566 Just hp -> hp
567 Nothing -> HyperdataDocument Nothing Nothing Nothing Nothing
568 Nothing Nothing Nothing Nothing
569 Nothing Nothing Nothing Nothing
570 Nothing Nothing Nothing Nothing
571 Nothing Nothing Nothing
572 docExample :: ByteString
573 docExample = "{\"doi\":\"sdfds\",\"publication_day\":6,\"language_iso2\":\"en\",\"publication_minute\":0,\"publication_month\":7,\"language_iso3\":\"eng\",\"publication_second\":0,\"authors\":\"Nils Hovdenak, Kjell Haram\",\"publication_year\":2012,\"publication_date\":\"2012-07-06 00:00:00+00:00\",\"language_name\":\"English\",\"realdate_full_\":\"2012 01 12\",\"source\":\"European journal of obstetrics, gynecology, and reproductive biology\",\"abstract\":\"The literature was searched for publications on minerals and vitamins during pregnancy and the possible influence of supplements on pregnancy outcome.\",\"title\":\"Influence of mineral and vitamin supplements on pregnancy outcome.\",\"publication_hour\":0}"
574
575 instance ToSchema HyperdataCorpus where
576 declareNamedSchema proxy =
577 genericDeclareNamedSchema (unPrefixSwagger "_hc_") proxy
578 & mapped.schema.description ?~ "Corpus"
579 & mapped.schema.example ?~ toJSON hyperdataCorpus
580
581 instance ToSchema HyperdataAnnuaire where
582 declareNamedSchema proxy =
583 genericDeclareNamedSchema (unPrefixSwagger "hyperdataAnnuaire_") proxy
584 & mapped.schema.description ?~ "an annuaire"
585 & mapped.schema.example ?~ toJSON hyperdataAnnuaire
586
587 instance ToSchema HyperdataDocument where
588 declareNamedSchema proxy =
589 genericDeclareNamedSchema (unPrefixSwagger "_hyperdataDocument_") proxy
590 & mapped.schema.description ?~ "a document"
591 & mapped.schema.example ?~ toJSON hyperdataDocument
592
593 instance ToSchema HyperdataAny where
594 declareNamedSchema proxy =
595 pure $ genericNameSchema defaultSchemaOptions proxy mempty
596 & schema.description ?~ "a node"
597 & schema.example ?~ emptyObject -- TODO
598
599
600 instance ToSchema hyperdata =>
601 ToSchema (NodePoly NodeId NodeTypeId
602 (Maybe UserId)
603 ParentId NodeName
604 UTCTime hyperdata
605 ) where
606 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_node_")
607
608 instance ToSchema hyperdata =>
609 ToSchema (NodePoly NodeId NodeTypeId
610 UserId
611 (Maybe ParentId) NodeName
612 UTCTime hyperdata
613 ) where
614 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_node_")
615
616
617 instance ToSchema hyperdata =>
618 ToSchema (NodePolySearch NodeId NodeTypeId
619 (Maybe UserId)
620 ParentId NodeName
621 UTCTime hyperdata (Maybe TSVector)
622 ) where
623 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_ns_")
624
625 instance ToSchema hyperdata =>
626 ToSchema (NodePolySearch NodeId NodeTypeId
627 UserId
628 (Maybe ParentId) NodeName
629 UTCTime hyperdata (Maybe TSVector)
630 ) where
631 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_ns_")
632
633
634 instance ToSchema Status where
635 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "status_")
636
637