]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Utils.hs
temporal is close to be ok, start export
[gargantext.git] / src / Gargantext / API / Utils.hs
1 {-|
2 Module : Gargantext.API.Utils
3 Description : Server API main Types
4 Copyright : (c) CNRS, 2017-Present
5 License : BSD3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Mainly copied from Servant.Job.Utils (Thanks)
11
12 -}
13
14 {-# LANGUAGE OverloadedStrings #-}
15 {-# LANGUAGE NoImplicitPrelude #-}
16
17 module Gargantext.API.Utils
18 where
19
20 import Gargantext.Prelude
21 import Data.Maybe (Maybe, fromMaybe)
22 import Prelude (String)
23 import qualified Data.Text as T
24 import Data.Swagger
25 import Data.Text (Text)
26
27
28
29 swaggerOptions :: Text -> SchemaOptions
30 swaggerOptions pref = defaultSchemaOptions
31 { Data.Swagger.fieldLabelModifier = modifier pref
32 , Data.Swagger.unwrapUnaryRecords = False
33 }
34
35
36 modifier :: Text -> String -> String
37 modifier pref field = T.unpack
38 $ T.stripPrefix pref (T.pack field) ?! "Expecting prefix " <> T.unpack pref
39
40
41 infixr 4 ?|
42
43 -- Reverse infix form of "fromMaybe"
44 (?|) :: Maybe a -> a -> a
45 (?|) = flip fromMaybe
46
47 infixr 4 ?!
48
49 -- Reverse infix form of "fromJust" with a custom error message
50 (?!) :: Maybe a -> String -> a
51 (?!) ma' msg = ma' ?| panic (T.pack msg)