2 Module : Gargantext.API.Utils
3 Description : Server API main Types
4 Copyright : (c) CNRS, 2017-Present
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Mainly copied from Servant.Job.Utils (Thanks)
14 {-# LANGUAGE OverloadedStrings #-}
15 {-# LANGUAGE NoImplicitPrelude #-}
17 module Gargantext.API.Utils
20 import Gargantext.Prelude
21 import Data.Maybe (Maybe, fromMaybe)
22 import Prelude (String)
23 import qualified Data.Text as T
25 import Data.Text (Text)
29 swaggerOptions :: Text -> SchemaOptions
30 swaggerOptions pref = defaultSchemaOptions
31 { Data.Swagger.fieldLabelModifier = modifier pref
32 , Data.Swagger.unwrapUnaryRecords = False
36 modifier :: Text -> String -> String
37 modifier pref field = T.unpack
38 $ T.stripPrefix pref (T.pack field) ?! "Expecting prefix " <> T.unpack pref
43 -- Reverse infix form of "fromMaybe"
44 (?|) :: Maybe a -> a -> a
49 -- Reverse infix form of "fromJust" with a custom error message
50 (?!) :: Maybe a -> String -> a
51 (?!) ma' msg = ma' ?| panic (T.pack msg)