@@ -37,6 +37,19 @@ checkDefs proxy names =
38 defs = execDeclare (declareNamedSchema proxy) mempty
38 defs = execDeclare (declareNamedSchema proxy) mempty
40+checkInlinedSchema :: ToSchema a => Proxy a -> Value -> Spec
41+checkInlinedSchema proxy js = toInlinedSchema proxy <=> js
43+checkInlinedSchemas :: ToSchema a => [String] -> Proxy a -> Value -> Spec
44+checkInlinedSchemas names proxy js = inlineSchemas (map Text.pack names) defs schema <=> js
46+ (defs, schema) = runDeclare (declareSchema proxy) mempty
48+checkInlinedRecSchema :: ToSchema a => Proxy a -> Value -> Spec
49+checkInlinedRecSchema proxy js = inlineNonRecursiveSchemas defs schema <=> js
51+ (defs, schema) = runDeclare (declareSchema proxy) mempty
40spec :: Spec
53spec :: Spec
42 describe "Generic ToSchema" $ do
55 describe "Generic ToSchema" $ do
@@ -70,6 +83,12 @@ spec = do
70 context "Character" $ checkDefs (Proxy :: Proxy Character) ["Player", "Point"]
83 context "Character" $ checkDefs (Proxy :: Proxy Character) ["Player", "Point"]
71 context "MyRoseTree" $ checkDefs (Proxy :: Proxy MyRoseTree) ["RoseTree"]
84 context "MyRoseTree" $ checkDefs (Proxy :: Proxy MyRoseTree) ["RoseTree"]
72 context "[Set (Unit, Maybe Color)]" $ checkDefs (Proxy :: Proxy [Set (Unit, Maybe Color)]) ["Unit", "Color"]
85 context "[Set (Unit, Maybe Color)]" $ checkDefs (Proxy :: Proxy [Set (Unit, Maybe Color)]) ["Unit", "Color"]
86+ describe "Inlining Schemas" $ do
87+ context "Paint" $ checkInlinedSchema (Proxy :: Proxy Paint) paintInlinedSchemaJSON
88+ context "Character" $ checkInlinedSchema (Proxy :: Proxy Character) characterInlinedSchemaJSON
89+ context "Character (inlining only Player)" $ checkInlinedSchemas ["Player"] (Proxy :: Proxy Character) characterInlinedPlayerSchemaJSON
90+ context "Light" $ checkInlinedSchema (Proxy :: Proxy Light) lightInlinedSchemaJSON
91+ context "MyRoseTree (inlineNonRecursiveSchemas)" $ checkInlinedRecSchema (Proxy :: Proxy MyRoseTree) myRoseTreeSchemaJSON
74main :: IO ()
93main :: IO ()
75main = hspec spec
94main = hspec spec
@@ -196,6 +215,22 @@ paintSchemaJSON = [aesonQQ|
218+paintInlinedSchemaJSON :: Value
219+paintInlinedSchemaJSON = [aesonQQ|
227+ "enum": ["Red", "Green", "Blue"]
230+ "required": ["color"]
199-- ========================================================================
234-- ========================================================================
200-- Email (newtype with unwrapUnaryRecords set to True)
235-- Email (newtype with unwrapUnaryRecords set to True)
201-- ========================================================================
236-- ========================================================================
@@ -407,6 +442,89 @@ characterSchemaJSON = [aesonQQ|
445+characterInlinedSchemaJSON :: Value
446+characterInlinedSchemaJSON = [aesonQQ|
461+ "x": { "type": "number" },
462+ "y": { "type": "number" }
464+ "required": ["x", "y"]
467+ "required": ["position"]
474+ "npcName": { "type": "string" },
480+ "x": { "type": "number" },
481+ "y": { "type": "number" }
483+ "required": ["x", "y"]
486+ "required": ["npcName", "npcPosition"]
494+characterInlinedPlayerSchemaJSON :: Value
495+characterInlinedPlayerSchemaJSON = [aesonQQ|
507+ "$ref": "#/definitions/Point"
510+ "required": ["position"]
517+ "npcName": { "type": "string" },
518+ "npcPosition": { "$ref": "#/definitions/Point" }
520+ "required": ["npcName", "npcPosition"]
410-- ========================================================================
528-- ========================================================================
411-- Light (sum type with unwrapUnaryRecords)
529-- Light (sum type with unwrapUnaryRecords)
412-- ========================================================================
530-- ========================================================================
@@ -436,3 +554,22 @@ lightSchemaJSON = [aesonQQ|
557+lightInlinedSchemaJSON :: Value
558+lightInlinedSchemaJSON = [aesonQQ|
563+ "LightFreq": { "type": "number" },
567+ "enum": ["Red", "Green", "Blue"]
569+ "LightWaveLength": { "type": "number" }