@@ -67,7 +67,7 @@ import Data.Swagger.SchemaOptions
6767import Data.Swagger.Internal.TypeShape
6868
6969import qualified Data.ByteString as BS
70−import qualified Data.ByteString.Lazy as BSL
70+import qualified Data.ByteString.Lazy.Char8 as BSL
7171import GHC.TypeLits (TypeError, ErrorMessage(..))
7272
7373unnamed :: Schema -> NamedSchema
@@ -151,13 +151,13 @@ declareSchema = fmap _namedSchemaSchema . declareNamedSchema
151151--
152152-- >>> toNamedSchema (Proxy :: Proxy String) ^. name
153153-- Nothing
154−-- >>> encode (toNamedSchema (Proxy :: Proxy String) ^. schema)
155−-- "{\"type\":\"string\"}"
154+-- >>> BSL.putStrLn $ encode (toNamedSchema (Proxy :: Proxy String) ^. schema)
155+-- {"type":"string"}
156156--
157157-- >>> toNamedSchema (Proxy :: Proxy Day) ^. name
158158-- Just "Day"
159−-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
160−-- "{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}"
159+-- >>> BSL.putStrLn $ encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
160+-- {"example":"2016-07-22","format":"date","type":"string"}
161161toNamedSchema :: ToSchema a => Proxy a -> NamedSchema
162162toNamedSchema = undeclare . declareNamedSchema
163163
@@ -173,22 +173,22 @@ schemaName = _namedSchemaName . toNamedSchema
173173
174174-- | Convert a type into a schema.
175175--
176−-- >>> encode $ toSchema (Proxy :: Proxy Int8)
177−-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
176+-- >>> BSL.putStrLn $ encode $ toSchema (Proxy :: Proxy Int8)
177+-- {"maximum":127,"minimum":-128,"type":"integer"}
178178--
179−-- >>> encode $ toSchema (Proxy :: Proxy [Day])
180−-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
179+-- >>> BSL.putStrLn $ encode $ toSchema (Proxy :: Proxy [Day])
180+-- {"items":{"$ref":"#/components/schemas/Day"},"type":"array"}
181181toSchema :: ToSchema a => Proxy a -> Schema
182182toSchema = _namedSchemaSchema . toNamedSchema
183183
184184-- | Convert a type into a referenced schema if possible.
185185-- Only named schemas can be referenced, nameless schemas are inlined.
186186--
187−-- >>> encode $ toSchemaRef (Proxy :: Proxy Integer)
188−-- "{\"type\":\"integer\"}"
187+-- >>> BSL.putStrLn $ encode $ toSchemaRef (Proxy :: Proxy Integer)
188+-- {"type":"integer"}
189189--
190−-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
191−-- "{\"$ref\":\"#/definitions/Day\"}"
190+-- >>> BSL.putStrLn $ encode $ toSchemaRef (Proxy :: Proxy Day)
191+-- {"$ref":"#/components/schemas/Day"}
192192toSchemaRef :: ToSchema a => Proxy a -> Referenced Schema
193193toSchemaRef = undeclare . declareSchemaRef
194194
@@ -256,8 +256,8 @@ inlineAllSchemas = inlineSchemasWhen (const True)
256256
257257-- | Convert a type into a schema without references.
258258--
259−-- >>> encode $ toInlinedSchema (Proxy :: Proxy [Day])
260−-- "{\"items\":{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"},\"type\":\"array\"}"
259+-- >>> BSL.putStrLn $ encode $ toInlinedSchema (Proxy :: Proxy [Day])
260+-- {"items":{"example":"2016-07-22","format":"date","type":"string"},"type":"array"}
261261--
262262-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
263263-- when inlining recursive schemas.
@@ -309,19 +309,19 @@ passwordSchema = mempty
309309-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
310310-- Produced schema can be used for further refinement.
311311--
312−-- >>> encode $ sketchSchema "hello"
313−-- "{\"example\":\"hello\",\"type\":\"string\"}"
312+-- >>> BSL.putStrLn $ encode $ sketchSchema "hello"
313+-- {"example":"hello","type":"string"}
314314--
315−-- >>> encode $ sketchSchema (1, 2, 3)
316−-- "{\"example\":[1,2,3],\"items\":{\"type\":\"number\"},\"type\":\"array\"}"
315+-- >>> BSL.putStrLn $ encode $ sketchSchema (1, 2, 3)
316+-- {"example":[1,2,3],"items":{"type":"number"},"type":"array"}
317317--
318−-- >>> encode $ sketchSchema ("Jack", 25)
319−-- "{\"example\":[\"Jack\",25],\"items\":[{\"type\":\"string\"},{\"type\":\"number\"}],\"type\":\"array\"}"
318+-- >>> BSL.putStrLn $ encode $ sketchSchema ("Jack", 25)
319+-- {"example":["Jack",25],"items":[{"type":"string"},{"type":"number"}],"type":"array"}
320320--
321321-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
322322-- >>> instance ToJSON Person
323−-- >>> encode $ sketchSchema (Person "Jack" 25)
324−-- "{\"required\":[\"age\",\"name\"],\"properties\":{\"age\":{\"type\":\"number\"},\"name\":{\"type\":\"string\"}},\"example\":{\"age\":25,\"name\":\"Jack\"},\"type\":\"object\"}"
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"}
325325sketchSchema :: ToJSON a => a -> Schema
326326sketchSchema = sketch . toJSON
327327 where
@@ -353,19 +353,19 @@ sketchSchema = sketch . toJSON
353353-- | Make a restrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
354354-- Produced schema uses as much constraints as possible.
355355--
356−-- >>> encode $ sketchStrictSchema "hello"
357−-- "{\"maxLength\":5,\"pattern\":\"hello\",\"minLength\":5,\"type\":\"string\",\"enum\":[\"hello\"]}"
356+-- >>> BSL.putStrLn $ encode $ sketchStrictSchema "hello"
357+-- {"maxLength":5,"pattern":"hello","minLength":5,"type":"string","enum":["hello"]}
358358--
359−-- >>> 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]]}"
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]]}
361361--
362−-- >>> 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]]}"
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]]}
364364--
365365-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
366366-- >>> instance ToJSON Person
367−-- >>> 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\"}]}"
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"}]}
369369sketchStrictSchema :: ToJSON a => a -> Schema
370370sketchStrictSchema = go . toJSON
371371 where
@@ -565,8 +565,8 @@ instance ToSchema a => ToSchema (Identity a) where declareNamedSchema _ = declar
565565
566566-- | Default schema for @'Bounded'@, @'Integral'@ types.
567567--
568−-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
569−-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
568+-- >>> BSL.putStrLn $ encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
569+-- {"maximum":32767,"minimum":-32768,"type":"integer"}
570570toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
571571toSchemaBoundedIntegral _ = mempty
572572 & type_ ?~ SwaggerInteger
@@ -598,8 +598,8 @@ genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$>
598598-- >>> instance ToSchema ButtonState
599599-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
600600-- >>> type ImageUrl = T.Text
601−-- >>> 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\"}"
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"}
603603--
604604-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
605605-- 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
626626-- >>> instance ToSchema ButtonState
627627-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
628628-- >>> type ImageUrl = T.Text
629−-- >>> 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\"}"
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"}
631631--
632632-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
633633-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.