git.iko.soy/typeable/swagger2
on master help sign in
Update tests and add some for schemaName
7efa220Nickolay Kudasov
test/Data/Swagger/SchemaSpec.hs+13−10
@@ -19,6 +19,11 @@ import Test.Hspec
19checkToSchema :: ToSchema a => Proxy a -> Value -> Spec
19checkToSchema :: ToSchema a => Proxy a -> Value -> Spec
20checkToSchema proxy js = toSchema proxy <~> js
20checkToSchema proxy js = toSchema proxy <~> js
21
21
22+checkSchemaName :: ToSchema a => Maybe String -> Proxy a -> Spec
23+checkSchemaName name proxy =
24+ it ("schema name is " ++ show name) $
25+ schemaName proxy `shouldBe` name
26+
22spec :: Spec
27spec :: Spec
23spec = do
28spec = do
24 describe "Generic ToSchema" $ do
29 describe "Generic ToSchema" $ do
@@ -29,6 +34,10 @@ spec = do
29 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
34 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
30 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
35 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
31 context "Player (unary record)" $ checkToSchema (Proxy :: Proxy Player) playerSchemaJSON
36 context "Player (unary record)" $ checkToSchema (Proxy :: Proxy Player) playerSchemaJSON
37+ context "Schema name" $ do
38+ context "String" $ checkSchemaName Nothing (Proxy :: Proxy String)
39+ context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))
40+ context "Person" $ checkSchemaName (Just "Person") (Proxy :: Proxy Person)
32 describe "toSchemaBoundedEnum" $ do
41 describe "toSchemaBoundedEnum" $ do
33 context "Color" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
42 context "Color" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
34
43
@@ -85,7 +94,7 @@ data Point = Point
85 } deriving (Generic)
94 } deriving (Generic)
86
95
87instance ToSchema Point where
96instance ToSchema Point where
88− toSchema = genericToSchema defaultSchemaOptions
97+ toNamedSchema = genericToNamedSchema defaultSchemaOptions
89 { fieldLabelModifier = map toLower . drop (length "point") }
98 { fieldLabelModifier = map toLower . drop (length "point") }
90
99
91pointSchemaJSON :: Value
100pointSchemaJSON :: Value
@@ -112,7 +121,7 @@ data Color
112 deriving (Generic, Enum, Bounded, ToJSON)
121 deriving (Generic, Enum, Bounded, ToJSON)
113
122
114instance ToSchema Color where
123instance ToSchema Color where
115− toSchema = toSchemaBoundedEnum
124+ toNamedSchema = genericToNamedSchemaBoundedEnum
116
125
117colorSchemaJSON :: Value
126colorSchemaJSON :: Value
118colorSchemaJSON = [aesonQQ|
127colorSchemaJSON = [aesonQQ|
@@ -130,7 +139,7 @@ newtype Email = Email { getEmail :: String }
130 deriving (Generic)
139 deriving (Generic)
131
140
132instance ToSchema Email where
141instance ToSchema Email where
133− toSchema = genericToSchema defaultSchemaOptions
142+ toNamedSchema = genericToNamedSchema defaultSchemaOptions
134 { unwrapUnaryRecords = True }
143 { unwrapUnaryRecords = True }
135
144
136emailSchemaJSON :: Value
145emailSchemaJSON :: Value
@@ -170,13 +179,7 @@ playerSchemaJSON = [aesonQQ|
170 {
179 {
171 "position":
180 "position":
172 {
181 {
173− "type": "object",
182+ "$ref": "#/definitions/Point"
174− "properties":
175− {
176− "x": { "type": "number" },
177− "y": { "type": "number" }
178− },
179− "required": [ "x", "y" ]
180 }
183 }
181 },
184 },
182 "required": ["position"]
185 "required": ["position"]