You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default the generic ToJSON instance uses a tagged field, but the generic ToSchema uses a single constructor:
module Main where
import Data.Aeson
import qualified Data.ByteString.Lazy as BL
import Data.Char
import Data.Proxy
import Data.Swagger
import GHC.Generics
data Foo =
One Integer Integer
| Two Integer String
deriving (Generic)
instance ToJSON Foo
instance ToSchema Foo
aFoo :: Foo
aFoo = Two 3 "Example"
main = do
putStrLn "Schema for Foo:"
putStrLn $ map (chr . fromIntegral) $ BL.unpack $ encode $ toSchema (Proxy :: Proxy Foo)
putStrLn "\n\nValue of Foo:"
putStrLn $ map (chr . fromIntegral) $ BL.unpack $ encode aFoo
Schema for Foo:
{"properties":{"One":{"items":[{"type":"integer"},{"type":"integer"}],"maxItems":2,"minItems":2,"type":"array"},"Two":{"items":[{"type":"integer"},{"type":"string"}],"maxItems":2,"minItems":2,"type":"array"}},"maxProperties":1,"minProperties":1,"type":"object"}
Value of Foo:
{"contents":[3,"Example"],"tag":"Two"}
The text was updated successfully, but these errors were encountered:
By default the generic
ToJSON
instance uses a tagged field, but the genericToSchema
uses a single constructor:The text was updated successfully, but these errors were encountered: