Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic ToSchema does not match generic ToAeson #241

Open
PaulJohnson opened this issue Aug 9, 2022 · 3 comments
Open

Generic ToSchema does not match generic ToAeson #241

PaulJohnson opened this issue Aug 9, 2022 · 3 comments

Comments

@PaulJohnson
Copy link

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
Copy link
Collaborator

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

@PaulJohnson
Copy link
Author

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

@PaulJohnson
Copy link
Author

swagger2-2.8.4
aeson-2.0.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants