1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE TemplateHaskell #-}
5{-# LANGUAGE QuasiQuotes #-}
6module Data.Swagger.ParamSchemaSpec where
8import Data.Aeson (Value)
15import Data.Swagger.Internal (SwaggerKind(..))
20checkToParamSchema :: ToParamSchema a => Proxy a -> Value -> Spec
21checkToParamSchema proxy js = (toParamSchema proxy :: ParamSchema ('SwaggerKindNormal Param)) <=> js
25 describe "Generic ToParamSchema" $ do
26 context "Unit" $ checkToParamSchema (Proxy :: Proxy Unit) unitSchemaJSON
27 context "Color (bounded enum)" $ checkToParamSchema (Proxy :: Proxy Color) colorSchemaJSON
28 context "Status (constructorTagModifier)" $ checkToParamSchema (Proxy :: Proxy Status) statusSchemaJSON
29 context "Unary records" $ do
30 context "Email (unary record)" $ checkToParamSchema (Proxy :: Proxy Email) emailSchemaJSON
31 context "UserId (non-record newtype)" $ checkToParamSchema (Proxy :: Proxy UserId) userIdSchemaJSON
36-- ========================================================================
38-- ========================================================================
40data Unit = Unit deriving (Generic)
41instance ToParamSchema Unit
43unitSchemaJSON :: Value
44unitSchemaJSON = [aesonQQ|
51-- ========================================================================
53-- ========================================================================
59instance ToParamSchema Color
61colorSchemaJSON :: Value
62colorSchemaJSON = [aesonQQ|
65 "enum": ["Red", "Green", "Blue"]
69-- ========================================================================
70-- Status (constructorTagModifier)
71-- ========================================================================
73data Status = StatusOk | StatusError deriving (Generic)
75instance ToParamSchema Status where
76 toParamSchema = genericToParamSchema defaultSchemaOptions
77 { constructorTagModifier = map toLower . drop (length "Status") }
79statusSchemaJSON :: Value
80statusSchemaJSON = [aesonQQ|
83 "enum": ["ok", "error"]
87-- ========================================================================
88-- Email (newtype with unwrapUnaryRecords set to True)
89-- ========================================================================
91newtype Email = Email { getEmail :: String }
93instance ToParamSchema Email
95emailSchemaJSON :: Value
96emailSchemaJSON = [aesonQQ|
102-- ========================================================================
103-- UserId (non-record newtype)
104-- ========================================================================
106newtype UserId = UserId Integer
108instance ToParamSchema UserId
110userIdSchemaJSON :: Value
111userIdSchemaJSON = [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