@@ -67,7 +67,7 @@ import Data.Swagger.SchemaOptions
67import Data.Swagger.Internal.TypeShape
67import Data.Swagger.Internal.TypeShape
69import qualified Data.ByteString as BS
69import qualified Data.ByteString as BS
70−import qualified Data.ByteString.Lazy as BSL
70+import qualified Data.ByteString.Lazy.Char8 as BSL
71import GHC.TypeLits (TypeError, ErrorMessage(..))
71import GHC.TypeLits (TypeError, ErrorMessage(..))
73unnamed :: Schema -> NamedSchema
73unnamed :: Schema -> NamedSchema
@@ -151,13 +151,13 @@ declareSchema = fmap _namedSchemaSchema . declareNamedSchema
152-- >>> toNamedSchema (Proxy :: Proxy String) ^. name
152-- >>> toNamedSchema (Proxy :: Proxy String) ^. name
153-- Nothing
153-- Nothing
154−-- >>> encode (toNamedSchema (Proxy :: Proxy String) ^. schema)
154+-- >>> BSL.putStrLn $ encode (toNamedSchema (Proxy :: Proxy String) ^. schema)
155−-- "{\"type\":\"string\"}"
155+-- {"type":"string"}
157-- >>> toNamedSchema (Proxy :: Proxy Day) ^. name
157-- >>> toNamedSchema (Proxy :: Proxy Day) ^. name
158-- Just "Day"
158-- Just "Day"
159−-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
159+-- >>> BSL.putStrLn $ encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
160−-- "{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}"
160+-- {"example":"2016-07-22","format":"date","type":"string"}
161toNamedSchema :: ToSchema a => Proxy a -> NamedSchema
161toNamedSchema :: ToSchema a => Proxy a -> NamedSchema
162toNamedSchema = undeclare . declareNamedSchema
162toNamedSchema = undeclare . declareNamedSchema
@@ -173,22 +173,22 @@ schemaName = _namedSchemaName . toNamedSchema
174-- | Convert a type into a schema.
174-- | Convert a type into a schema.
176−-- >>> encode $ toSchema (Proxy :: Proxy Int8)
176+-- >>> BSL.putStrLn $ encode $ toSchema (Proxy :: Proxy Int8)
177−-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
177+-- {"maximum":127,"minimum":-128,"type":"integer"}
179−-- >>> encode $ toSchema (Proxy :: Proxy [Day])
179+-- >>> BSL.putStrLn $ encode $ toSchema (Proxy :: Proxy [Day])
180−-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
180+-- {"items":{"$ref":"#/components/schemas/Day"},"type":"array"}
181toSchema :: ToSchema a => Proxy a -> Schema
181toSchema :: ToSchema a => Proxy a -> Schema
182toSchema = _namedSchemaSchema . toNamedSchema
182toSchema = _namedSchemaSchema . toNamedSchema
184-- | Convert a type into a referenced schema if possible.
184-- | Convert a type into a referenced schema if possible.
185-- Only named schemas can be referenced, nameless schemas are inlined.
185-- Only named schemas can be referenced, nameless schemas are inlined.
187−-- >>> encode $ toSchemaRef (Proxy :: Proxy Integer)
187+-- >>> BSL.putStrLn $ encode $ toSchemaRef (Proxy :: Proxy Integer)
188−-- "{\"type\":\"integer\"}"
188+-- {"type":"integer"}
190−-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
190+-- >>> BSL.putStrLn $ encode $ toSchemaRef (Proxy :: Proxy Day)
191−-- "{\"$ref\":\"#/definitions/Day\"}"
191+-- {"$ref":"#/components/schemas/Day"}
192toSchemaRef :: ToSchema a => Proxy a -> Referenced Schema
192toSchemaRef :: ToSchema a => Proxy a -> Referenced Schema
193toSchemaRef = undeclare . declareSchemaRef
193toSchemaRef = undeclare . declareSchemaRef
@@ -256,8 +256,8 @@ inlineAllSchemas = inlineSchemasWhen (const True)
257-- | Convert a type into a schema without references.
257-- | Convert a type into a schema without references.
259−-- >>> encode $ toInlinedSchema (Proxy :: Proxy [Day])
259+-- >>> BSL.putStrLn $ encode $ toInlinedSchema (Proxy :: Proxy [Day])
260−-- "{\"items\":{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"},\"type\":\"array\"}"
260+-- {"items":{"example":"2016-07-22","format":"date","type":"string"},"type":"array"}
262-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
262-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
263-- when inlining recursive schemas.
263-- when inlining recursive schemas.
@@ -309,19 +309,19 @@ passwordSchema = mempty
309-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
309-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
310-- Produced schema can be used for further refinement.
310-- Produced schema can be used for further refinement.
312−-- >>> encode $ sketchSchema "hello"
312+-- >>> BSL.putStrLn $ encode $ sketchSchema "hello"
313−-- "{\"example\":\"hello\",\"type\":\"string\"}"
313+-- {"example":"hello","type":"string"}
315−-- >>> encode $ sketchSchema (1, 2, 3)
315+-- >>> BSL.putStrLn $ encode $ sketchSchema (1, 2, 3)
316−-- "{\"example\":[1,2,3],\"items\":{\"type\":\"number\"},\"type\":\"array\"}"
316+-- {"example":[1,2,3],"items":{"type":"number"},"type":"array"}
318−-- >>> encode $ sketchSchema ("Jack", 25)
318+-- >>> BSL.putStrLn $ encode $ sketchSchema ("Jack", 25)
319−-- "{\"example\":[\"Jack\",25],\"items\":[{\"type\":\"string\"},{\"type\":\"number\"}],\"type\":\"array\"}"
319+-- {"example":["Jack",25],"items":[{"type":"string"},{"type":"number"}],"type":"array"}
321-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
321-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
322-- >>> instance ToJSON Person
322-- >>> instance ToJSON Person
323−-- >>> encode $ sketchSchema (Person "Jack" 25)
323+-- >>> BSL.putStrLn $ encode $ sketchSchema (Person "Jack" 25)
324−-- "{\"required\":[\"age\",\"name\"],\"properties\":{\"age\":{\"type\":\"number\"},\"name\":{\"type\":\"string\"}},\"example\":{\"age\":25,\"name\":\"Jack\"},\"type\":\"object\"}"
324+-- {"required":["age","name"],"properties":{"age":{"type":"number"},"name":{"type":"string"}},"example":{"age":25,"name":"Jack"},"type":"object"}
325sketchSchema :: ToJSON a => a -> Schema
325sketchSchema :: ToJSON a => a -> Schema
326sketchSchema = sketch . toJSON
326sketchSchema = sketch . toJSON
@@ -353,19 +353,19 @@ sketchSchema = sketch . toJSON
353-- | Make a restrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
353-- | Make a restrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
354-- Produced schema uses as much constraints as possible.
354-- Produced schema uses as much constraints as possible.
356−-- >>> encode $ sketchStrictSchema "hello"
356+-- >>> BSL.putStrLn $ encode $ sketchStrictSchema "hello"
357−-- "{\"maxLength\":5,\"pattern\":\"hello\",\"minLength\":5,\"type\":\"string\",\"enum\":[\"hello\"]}"
357+-- {"maxLength":5,"pattern":"hello","minLength":5,"type":"string","enum":["hello"]}
359−-- >>> encode $ sketchStrictSchema (1, 2, 3)
359+-- >>> BSL.putStrLn $ encode $ sketchStrictSchema (1, 2, 3)
360−-- "{\"minItems\":3,\"uniqueItems\":true,\"items\":[{\"maximum\":1,\"minimum\":1,\"multipleOf\":1,\"type\":\"number\",\"enum\":[1]},{\"maximum\":2,\"minimum\":2,\"multipleOf\":2,\"type\":\"number\",\"enum\":[2]},{\"maximum\":3,\"minimum\":3,\"multipleOf\":3,\"type\":\"number\",\"enum\":[3]}],\"maxItems\":3,\"type\":\"array\",\"enum\":[[1,2,3]]}"
360+-- {"minItems":3,"uniqueItems":true,"items":[{"maximum":1,"minimum":1,"multipleOf":1,"type":"number","enum":[1]},{"maximum":2,"minimum":2,"multipleOf":2,"type":"number","enum":[2]},{"maximum":3,"minimum":3,"multipleOf":3,"type":"number","enum":[3]}],"maxItems":3,"type":"array","enum":[[1,2,3]]}
362−-- >>> encode $ sketchStrictSchema ("Jack", 25)
362+-- >>> BSL.putStrLn $ encode $ sketchStrictSchema ("Jack", 25)
363−-- "{\"minItems\":2,\"uniqueItems\":true,\"items\":[{\"maxLength\":4,\"pattern\":\"Jack\",\"minLength\":4,\"type\":\"string\",\"enum\":[\"Jack\"]},{\"maximum\":25,\"minimum\":25,\"multipleOf\":25,\"type\":\"number\",\"enum\":[25]}],\"maxItems\":2,\"type\":\"array\",\"enum\":[[\"Jack\",25]]}"
363+-- {"minItems":2,"uniqueItems":true,"items":[{"maxLength":4,"pattern":"Jack","minLength":4,"type":"string","enum":["Jack"]},{"maximum":25,"minimum":25,"multipleOf":25,"type":"number","enum":[25]}],"maxItems":2,"type":"array","enum":[["Jack",25]]}
365-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
365-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
366-- >>> instance ToJSON Person
366-- >>> instance ToJSON Person
367−-- >>> encode $ sketchStrictSchema (Person "Jack" 25)
367+-- >>> BSL.putStrLn $ encode $ sketchStrictSchema (Person "Jack" 25)
368−-- "{\"required\":[\"age\",\"name\"],\"properties\":{\"age\":{\"maximum\":25,\"minimum\":25,\"multipleOf\":25,\"type\":\"number\",\"enum\":[25]},\"name\":{\"maxLength\":4,\"pattern\":\"Jack\",\"minLength\":4,\"type\":\"string\",\"enum\":[\"Jack\"]}},\"maxProperties\":2,\"minProperties\":2,\"type\":\"object\",\"enum\":[{\"age\":25,\"name\":\"Jack\"}]}"
368+-- {"required":["age","name"],"properties":{"age":{"maximum":25,"minimum":25,"multipleOf":25,"type":"number","enum":[25]},"name":{"maxLength":4,"pattern":"Jack","minLength":4,"type":"string","enum":["Jack"]}},"maxProperties":2,"minProperties":2,"type":"object","enum":[{"age":25,"name":"Jack"}]}
369sketchStrictSchema :: ToJSON a => a -> Schema
369sketchStrictSchema :: ToJSON a => a -> Schema
370sketchStrictSchema = go . toJSON
370sketchStrictSchema = go . toJSON
@@ -565,8 +565,8 @@ instance ToSchema a => ToSchema (Identity a) where declareNamedSchema _ = declar
566-- | Default schema for @'Bounded'@, @'Integral'@ types.
566-- | Default schema for @'Bounded'@, @'Integral'@ types.
568−-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
568+-- >>> BSL.putStrLn $ encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
569−-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
569+-- {"maximum":32767,"minimum":-32768,"type":"integer"}
570toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
570toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
571toSchemaBoundedIntegral _ = mempty
571toSchemaBoundedIntegral _ = mempty
572 & type_ ?~ SwaggerInteger
572 & type_ ?~ SwaggerInteger
@@ -598,8 +598,8 @@ genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$>
598-- >>> instance ToSchema ButtonState
598-- >>> instance ToSchema ButtonState
599-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
599-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
600-- >>> type ImageUrl = T.Text
600-- >>> type ImageUrl = T.Text
601−-- >>> encode $ toSchemaBoundedEnumKeyMapping (Proxy :: Proxy (Map ButtonState ImageUrl))
601+-- >>> BSL.putStrLn $ encode $ toSchemaBoundedEnumKeyMapping (Proxy :: Proxy (Map ButtonState ImageUrl))
602−-- "{\"properties\":{\"Neutral\":{\"type\":\"string\"},\"Focus\":{\"type\":\"string\"},\"Active\":{\"type\":\"string\"},\"Hover\":{\"type\":\"string\"},\"Disabled\":{\"type\":\"string\"}},\"type\":\"object\"}"
602+-- {"properties":{"Neutral":{"type":"string"},"Focus":{"type":"string"},"Active":{"type":"string"},"Hover":{"type":"string"},"Disabled":{"type":"string"}},"type":"object"}
604-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
604-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
605-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
605-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
@@ -626,8 +626,8 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
626-- >>> instance ToSchema ButtonState
626-- >>> instance ToSchema ButtonState
627-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
627-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
628-- >>> type ImageUrl = T.Text
628-- >>> type ImageUrl = T.Text
629−-- >>> encode $ toSchemaBoundedEnumKeyMapping (Proxy :: Proxy (Map ButtonState ImageUrl))
629+-- >>> BSL.putStrLn $ encode $ toSchemaBoundedEnumKeyMapping (Proxy :: Proxy (Map ButtonState ImageUrl))
630−-- "{\"properties\":{\"Neutral\":{\"type\":\"string\"},\"Focus\":{\"type\":\"string\"},\"Active\":{\"type\":\"string\"},\"Hover\":{\"type\":\"string\"},\"Disabled\":{\"type\":\"string\"}},\"type\":\"object\"}"
630+-- {"properties":{"Neutral":{"type":"string"},"Focus":{"type":"string"},"Active":{"type":"string"},"Hover":{"type":"string"},"Disabled":{"type":"string"}},"type":"object"}
632-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
632-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
633-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
633-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.