GetShopTV / swagger2

Swagger 2.0 data model.
http://hackage.haskell.org/package/swagger2
BSD 3-Clause "New" or "Revised" License
74 stars 59 forks source link

Generic ToSchema does not match generic ToAeson #241

Open PaulJohnson opened 2 years ago

PaulJohnson commented 2 years ago

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"}
swamp-agr commented 2 years ago

Hey @PaulJohnson could you please specify what versions of aeson and swagger2 you are using in the case?

PaulJohnson commented 2 years ago

@swamp-agr Good question. Unfortunately this is at work and I'm currently on leave. I'll update you next week.

PaulJohnson commented 2 years ago

swagger2-2.8.4 aeson-2.0.3.0