@@ -1,5 +1,6 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveAnyClass #-}
2{-# LANGUAGE DeriveAnyClass #-}
3+{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE TemplateHaskell #-}
4{-# LANGUAGE TemplateHaskell #-}
4{-# LANGUAGE QuasiQuotes #-}
5{-# LANGUAGE QuasiQuotes #-}
5module Data.Swagger.SchemaSpec where
6module Data.Swagger.SchemaSpec where
@@ -34,6 +35,7 @@ spec = do
34 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
35 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
35 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
36 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
36 context "Player (unary record)" $ checkToSchema (Proxy :: Proxy Player) playerSchemaJSON
37 context "Player (unary record)" $ checkToSchema (Proxy :: Proxy Player) playerSchemaJSON
38+ context "Players (inlining schema)" $ checkToSchema (Proxy :: Proxy Players) playersSchemaJSON
37 context "Schema name" $ do
39 context "Schema name" $ do
38 context "String" $ checkSchemaName Nothing (Proxy :: Proxy String)
40 context "String" $ checkSchemaName Nothing (Proxy :: Proxy String)
39 context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))
41 context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))
@@ -185,3 +187,35 @@ playerSchemaJSON = [aesonQQ|
185 "required": ["position"]
187 "required": ["position"]
191+-- ========================================================================
192+-- Inlined (newtype for inlining schemas)
193+-- ========================================================================
195+newtype Inlined a = Inlined { getInlined :: a }
197+instance ToSchema a => ToSchema (Inlined a) where
198+ toNamedSchema _ = (Nothing, toSchema (Proxy :: Proxy a))
200+newtype Players = Players [Inlined Player]
201+ deriving (Generic, ToSchema)
203+playersSchemaJSON :: Value
204+playersSchemaJSON = [aesonQQ|
214+ "$ref": "#/definitions/Point"
217+ "required": ["position"]