@@ -19,6 +19,11 @@ import Test.Hspec
1919checkToSchema :: ToSchema a => Proxy a -> Value -> Spec
2020checkToSchema proxy js = toSchema proxy <~> js
2121
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+
2227spec :: Spec
2328spec = do
2429 describe "Generic ToSchema" $ do
@@ -29,6 +34,10 @@ spec = do
2934 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
3035 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
3136 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)
3241 describe "toSchemaBoundedEnum" $ do
3342 context "Color" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
3443
@@ -85,7 +94,7 @@ data Point = Point
8594 } deriving (Generic)
8695
8796instance ToSchema Point where
88− toSchema = genericToSchema defaultSchemaOptions
97+ toNamedSchema = genericToNamedSchema defaultSchemaOptions
8998 { fieldLabelModifier = map toLower . drop (length "point") }
9099
91100pointSchemaJSON :: Value
@@ -112,7 +121,7 @@ data Color
112121 deriving (Generic, Enum, Bounded, ToJSON)
113122
114123instance ToSchema Color where
115− toSchema = toSchemaBoundedEnum
124+ toNamedSchema = genericToNamedSchemaBoundedEnum
116125
117126colorSchemaJSON :: Value
118127colorSchemaJSON = [aesonQQ|
@@ -130,7 +139,7 @@ newtype Email = Email { getEmail :: String }
130139 deriving (Generic)
131140
132141instance ToSchema Email where
133− toSchema = genericToSchema defaultSchemaOptions
142+ toNamedSchema = genericToNamedSchema defaultSchemaOptions
134143 { unwrapUnaryRecords = True }
135144
136145emailSchemaJSON :: Value
@@ -170,13 +179,7 @@ playerSchemaJSON = [aesonQQ|
170179 {
171180 "position":
172181 {
173− "type": "object",
174− "properties":
175− {
176− "x": { "type": "number" },
177− "y": { "type": "number" }
178− },
179− "required": [ "x", "y" ]
182+ "$ref": "#/definitions/Point"
180183 }
181184 },
182185 "required": ["position"]