@@ -0,0 +1,33 @@
1+module Servant.Extra.API.Cookie where
4+import Data.OpenApi as OA
6+import Data.Text (Text)
7+import qualified Data.Text as T
9+import Servant.API as S
10+import Servant.OpenApi
11+import Servant.OpenApi.Internal
13+newtype Cookie (name :: Symbol) = Cookie (Maybe Text)
14+ deriving (Eq, FromHttpApiData, ToHttpApiData)
16+instance OA.ToParamSchema (Cookie name) where
17+ toParamSchema _ = toParamSchema (Proxy @Text)
19+instance HasLink sub => HasLink (Cookie name :> sub) where
20+ type MkLink (Cookie name :> sub) endpoint = MkLink sub endpoint
21+ toLink f _p l = toLink f (Proxy @sub) l
23+instance (HasOpenApi api, KnownSymbol name) =>
24+ HasOpenApi (Cookie name :> api) where
25+ toOpenApi _ = toOpenApi (Proxy @api)
27+ & addDefaultResponse400 cookieNameText
29+ cookieNameText = T.pack (symbolVal (Proxy @name))
31+ & name .~ cookieNameText
32+ & in_ .~ OA.ParamCookie