git.iko.soy/typeable/openapi3
on master help sign in
Add test with explicit schema inlining
commit0c4a852e2afec14493dd6ef46d6fb0995074bcd1 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateTue 24 Nov 2015, 14:50 (11 years ago) parentbe1b365
1 file changed+34
test/Data/Swagger/SchemaSpec.hs+34
test/Data/Swagger/SchemaSpec.hs+34
@@ -1,5 +1,6 @@
11{-# LANGUAGE DeriveGeneric #-}
22{-# LANGUAGE DeriveAnyClass #-}
3+{-# LANGUAGE ScopedTypeVariables #-}
34{-# LANGUAGE TemplateHaskell #-}
45{-# LANGUAGE QuasiQuotes #-}
56module Data.Swagger.SchemaSpec where
@@ -34,6 +35,7 @@ spec = do
3435 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
3536 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
3637 context "Player (unary record)" $ checkToSchema (Proxy :: Proxy Player) playerSchemaJSON
38+ context "Players (inlining schema)" $ checkToSchema (Proxy :: Proxy Players) playersSchemaJSON
3739 context "Schema name" $ do
3840 context "String" $ checkSchemaName Nothing (Proxy :: Proxy String)
3941 context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))
@@ -185,3 +187,35 @@ playerSchemaJSON = [aesonQQ|
185187 "required": ["position"]
186188}
187189|]
190+
191+-- ========================================================================
192+-- Inlined (newtype for inlining schemas)
193+-- ========================================================================
194+
195+newtype Inlined a = Inlined { getInlined :: a }
196+
197+instance ToSchema a => ToSchema (Inlined a) where
198+ toNamedSchema _ = (Nothing, toSchema (Proxy :: Proxy a))
199+
200+newtype Players = Players [Inlined Player]
201+ deriving (Generic, ToSchema)
202+
203+playersSchemaJSON :: Value
204+playersSchemaJSON = [aesonQQ|
205+{
206+ "type": "array",
207+ "items":
208+ {
209+ "type": "object",
210+ "properties":
211+ {
212+ "position":
213+ {
214+ "$ref": "#/definitions/Point"
215+ }
216+ },
217+ "required": ["position"]
218+ }
219+}
220+|]
221+