1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE TemplateHaskell #-}
4{-# LANGUAGE QuasiQuotes #-}
5module Data.Swagger.ParamSchemaSpec where
18checkToParamSchema :: ToParamSchema a => Proxy a -> Value -> Spec
19checkToParamSchema proxy js = (toParamSchema proxy :: ParamSchema Param) <=> js
23 describe "Generic ToParamSchema" $ do
24 context "Unit" $ checkToParamSchema (Proxy :: Proxy Unit) unitSchemaJSON
25 context "Color (bounded enum)" $ checkToParamSchema (Proxy :: Proxy Color) colorSchemaJSON
26 context "Status (constructorTagModifier)" $ checkToParamSchema (Proxy :: Proxy Status) statusSchemaJSON
27 context "Unary records" $ do
28 context "Email (unary record)" $ checkToParamSchema (Proxy :: Proxy Email) emailSchemaJSON
29 context "UserId (non-record newtype)" $ checkToParamSchema (Proxy :: Proxy UserId) userIdSchemaJSON
34-- ========================================================================
36-- ========================================================================
38data Unit = Unit deriving (Generic)
39instance ToParamSchema Unit
41unitSchemaJSON :: Value
42unitSchemaJSON = [aesonQQ|
49-- ========================================================================
51-- ========================================================================
57instance ToParamSchema Color
59colorSchemaJSON :: Value
60colorSchemaJSON = [aesonQQ|
63 "enum": ["Red", "Green", "Blue"]
67-- ========================================================================
68-- Status (constructorTagModifier)
69-- ========================================================================
71data Status = StatusOk | StatusError deriving (Generic)
73instance ToParamSchema Status where
74 toParamSchema = genericToParamSchema defaultSchemaOptions
75 { constructorTagModifier = map toLower . drop (length "Status") }
77statusSchemaJSON :: Value
78statusSchemaJSON = [aesonQQ|
81 "enum": ["ok", "error"]
85-- ========================================================================
86-- Email (newtype with unwrapUnaryRecords set to True)
87-- ========================================================================
89newtype Email = Email { getEmail :: String }
91instance ToParamSchema Email
93emailSchemaJSON :: Value
94emailSchemaJSON = [aesonQQ|
100-- ========================================================================
101-- UserId (non-record newtype)
102-- ========================================================================
104newtype UserId = UserId Integer
106instance ToParamSchema UserId
108userIdSchemaJSON :: Value
109userIdSchemaJSON = [aesonQQ|
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list