git.iko.soy/typeable/swagger2
on master help sign in
Add ToSchema instances for Text (strict and lazy)
commit21f118fc33cdcf044a32d96d94b9c0125224c765 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateMon 23 Nov 2015, 17:27 (11 years ago) parent8e76c1a
1 file changed+12−5
src/Data/Swagger/Schema/Internal.hs+12−5
src/Data/Swagger/Schema/Internal.hs+12−5
@@ -12,7 +12,8 @@ import Data.Aeson
1212import Data.Int
1313import Data.Monoid
1414import Data.Proxy
15−import qualified Data.Text as Text
15+import qualified Data.Text as T
16+import qualified Data.Text.Lazy as TL
1617import Data.Word
1718import GHC.Generics
1819
@@ -70,6 +71,12 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e) => ToSchem
7071instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f) => ToSchema (a, b, c, d, e, f)
7172instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f, ToSchema g) => ToSchema (a, b, c, d, e, f, g)
7273
74+instance ToSchema T.Text where
75+ toSchema _ = toSchema (Proxy :: Proxy String)
76+
77+instance ToSchema TL.Text where
78+ toSchema _ = toSchema (Proxy :: Proxy String)
79+
7380toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
7481toSchemaBoundedIntegral _ = mempty
7582 & schemaType .~ SchemaInteger
@@ -99,20 +106,20 @@ appendItem _ _ = error "GToSchema.appendItem: cannot append to SchemaItemsObject
99106-- | Optional record fields.
100107instance {-# OVERLAPPING #-} (Selector s, ToSchema c) => GToSchema (S1 s (K1 i (Maybe c))) where
101108 gtoSchema _ schema
102− | Text.null fieldName = schema
109+ | T.null fieldName = schema
103110 & schemaType .~ SchemaArray
104111 & schemaItems %~ appendItem (Inline fieldSchema)
105112 | otherwise = schema
106113 & schemaType .~ SchemaObject
107114 & schemaProperties . at fieldName ?~ Inline fieldSchema
108115 where
109− fieldName = Text.pack (selName (undefined :: S1 s f p))
116+ fieldName = T.pack (selName (undefined :: S1 s f p))
110117 fieldSchema = toSchema (Proxy :: Proxy c)
111118
112119-- | Record fields.
113120instance {-# OVERLAPPABLE #-} (Selector s, GToSchema f) => GToSchema (S1 s f) where
114121 gtoSchema _ schema
115− | Text.null fieldName = schema
122+ | T.null fieldName = schema
116123 & schemaType .~ SchemaArray
117124 & schemaItems %~ appendItem (Inline fieldSchema)
118125 | otherwise = schema
@@ -120,7 +127,7 @@ instance {-# OVERLAPPABLE #-} (Selector s, GToSchema f) => GToSchema (S1 s f) wh
120127 & schemaProperties . at fieldName ?~ Inline fieldSchema
121128 & schemaRequired %~ (fieldName :)
122129 where
123− fieldName = Text.pack (selName (undefined :: S1 s f p))
130+ fieldName = T.pack (selName (undefined :: S1 s f p))
124131 fieldSchema = gtoSchema (Proxy :: Proxy f) mempty
125132
126133instance ToSchema c => GToSchema (K1 i c) where