git.iko.soy/typeable/openapi3
on master help sign in
Add ToSchema instances for Text (strict and lazy)
21f118fNickolay Kudasov
src/Data/Swagger/Schema/Internal.hs+12−5
@@ -12,7 +12,8 @@ import Data.Aeson
12import Data.Int
12import Data.Int
13import Data.Monoid
13import Data.Monoid
14import Data.Proxy
14import Data.Proxy
15−import qualified Data.Text as Text
15+import qualified Data.Text as T
16+import qualified Data.Text.Lazy as TL
16import Data.Word
17import Data.Word
17import GHC.Generics
18import GHC.Generics
18
19
@@ -70,6 +71,12 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e) => ToSchem
70instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f) => ToSchema (a, b, c, d, e, f)
71instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f) => ToSchema (a, b, c, d, e, f)
71instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f, ToSchema g) => ToSchema (a, b, c, d, e, f, g)
72instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f, ToSchema g) => ToSchema (a, b, c, d, e, f, g)
72
73
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+
73toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
80toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
74toSchemaBoundedIntegral _ = mempty
81toSchemaBoundedIntegral _ = mempty
75 & schemaType .~ SchemaInteger
82 & schemaType .~ SchemaInteger
@@ -99,20 +106,20 @@ appendItem _ _ = error "GToSchema.appendItem: cannot append to SchemaItemsObject
99-- | Optional record fields.
106-- | Optional record fields.
100instance {-# OVERLAPPING #-} (Selector s, ToSchema c) => GToSchema (S1 s (K1 i (Maybe c))) where
107instance {-# OVERLAPPING #-} (Selector s, ToSchema c) => GToSchema (S1 s (K1 i (Maybe c))) where
101 gtoSchema _ schema
108 gtoSchema _ schema
102− | Text.null fieldName = schema
109+ | T.null fieldName = schema
103 & schemaType .~ SchemaArray
110 & schemaType .~ SchemaArray
104 & schemaItems %~ appendItem (Inline fieldSchema)
111 & schemaItems %~ appendItem (Inline fieldSchema)
105 | otherwise = schema
112 | otherwise = schema
106 & schemaType .~ SchemaObject
113 & schemaType .~ SchemaObject
107 & schemaProperties . at fieldName ?~ Inline fieldSchema
114 & schemaProperties . at fieldName ?~ Inline fieldSchema
108 where
115 where
109− fieldName = Text.pack (selName (undefined :: S1 s f p))
116+ fieldName = T.pack (selName (undefined :: S1 s f p))
110 fieldSchema = toSchema (Proxy :: Proxy c)
117 fieldSchema = toSchema (Proxy :: Proxy c)
111
118
112-- | Record fields.
119-- | Record fields.
113instance {-# OVERLAPPABLE #-} (Selector s, GToSchema f) => GToSchema (S1 s f) where
120instance {-# OVERLAPPABLE #-} (Selector s, GToSchema f) => GToSchema (S1 s f) where
114 gtoSchema _ schema
121 gtoSchema _ schema
115− | Text.null fieldName = schema
122+ | T.null fieldName = schema
116 & schemaType .~ SchemaArray
123 & schemaType .~ SchemaArray
117 & schemaItems %~ appendItem (Inline fieldSchema)
124 & schemaItems %~ appendItem (Inline fieldSchema)
118 | otherwise = schema
125 | otherwise = schema
@@ -120,7 +127,7 @@ instance {-# OVERLAPPABLE #-} (Selector s, GToSchema f) => GToSchema (S1 s f) wh
120 & schemaProperties . at fieldName ?~ Inline fieldSchema
127 & schemaProperties . at fieldName ?~ Inline fieldSchema
121 & schemaRequired %~ (fieldName :)
128 & schemaRequired %~ (fieldName :)
122 where
129 where
123− fieldName = Text.pack (selName (undefined :: S1 s f p))
130+ fieldName = T.pack (selName (undefined :: S1 s f p))
124 fieldSchema = gtoSchema (Proxy :: Proxy f) mempty
131 fieldSchema = gtoSchema (Proxy :: Proxy f) mempty
125
132
126instance ToSchema c => GToSchema (K1 i c) where
133instance ToSchema c => GToSchema (K1 i c) where