git.iko.soy/typeable/swagger2
on master help sign in
Merge pull request #143 from GetShopTV/fix-single-field-maybe
fff19d2Nickolay Kudasov
src/Data/Swagger/Internal/Schema.hs+1−1
@@ -725,7 +725,7 @@ instance OVERLAPPING_ Constructor c => GToSchema (C1 c U1) where
725 gdeclareNamedSchema = gdeclareNamedSumSchema
725 gdeclareNamedSchema = gdeclareNamedSumSchema
726
726
727-- | Single field constructor.
727-- | Single field constructor.
728−instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
728+instance (Selector s, GToSchema f, GToSchema (S1 s f)) => GToSchema (C1 c (S1 s f)) where
729 gdeclareNamedSchema opts _ s
729 gdeclareNamedSchema opts _ s
730 | unwrapUnaryRecords opts = fieldSchema
730 | unwrapUnaryRecords opts = fieldSchema
731 | otherwise =
731 | otherwise =
test/Data/Swagger/SchemaSpec.hs+22
@@ -78,6 +78,7 @@ spec = do
78 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
78 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
79 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
79 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
80 context "Player (unary record)" $ checkToSchema (Proxy :: Proxy Player) playerSchemaJSON
80 context "Player (unary record)" $ checkToSchema (Proxy :: Proxy Player) playerSchemaJSON
81+ context "SingleMaybeField (unary record with Maybe)" $ checkToSchema (Proxy :: Proxy SingleMaybeField) singleMaybeFieldSchemaJSON
81 context "Players (inlining schema)" $ checkToSchema (Proxy :: Proxy Players) playersSchemaJSON
82 context "Players (inlining schema)" $ checkToSchema (Proxy :: Proxy Players) playersSchemaJSON
82 context "MyRoseTree (datatypeNameModifier)" $ checkToSchema (Proxy :: Proxy MyRoseTree) myRoseTreeSchemaJSON
83 context "MyRoseTree (datatypeNameModifier)" $ checkToSchema (Proxy :: Proxy MyRoseTree) myRoseTreeSchemaJSON
83 context "MyRoseTree' (datatypeNameModifier)" $ checkToSchema (Proxy :: Proxy MyRoseTree') myRoseTreeSchemaJSON'
84 context "MyRoseTree' (datatypeNameModifier)" $ checkToSchema (Proxy :: Proxy MyRoseTree') myRoseTreeSchemaJSON'
@@ -722,3 +723,24 @@ buttonImagesSchemaJSON = [aesonQQ|
722}
723}
723|]
724|]
724
725
726+
727+-- ========================================================================
728+-- SingleMaybeField (single field data with optional field)
729+-- ========================================================================
730+
731+data SingleMaybeField = SingleMaybeField { singleMaybeField :: Maybe String }
732+ deriving (Show, Generic)
733+
734+instance ToJSON SingleMaybeField
735+instance ToSchema SingleMaybeField
736+
737+singleMaybeFieldSchemaJSON :: Value
738+singleMaybeFieldSchemaJSON = [aesonQQ|
739+{
740+ "type": "object",
741+ "properties":
742+ {
743+ "singleMaybeField": { "type": "string" }
744+ }
745+}
746+|]