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

Outdated documentation re sum encoding differs ToSchema/ToJSON? #59

Open
brprice opened this issue Aug 13, 2022 · 1 comment
Open

Outdated documentation re sum encoding differs ToSchema/ToJSON? #59

brprice opened this issue Aug 13, 2022 · 1 comment

Comments

@brprice
Copy link

brprice commented Aug 13, 2022

There is (in the haddock documentation) a statement that the default ToSchema and ToJSON instances differ in encoding sum types:

-- @'ToSchema'@ default implementation is also aligned with @'ToJSON'@ default implementation with
-- the only difference being for sum encoding. @'ToJSON'@ defaults sum encoding to @'defaultTaggedObject'@,
-- while @'ToSchema'@ defaults to something which corresponds to @'ObjectWithSingleField'@. This is due to
-- @'defaultTaggedObject'@ behavior being hard to specify in Swagger.

However, I think this is outdated and that you create a consistent schema using oneOf, as mentioned further down the documentation

-- This package implements OpenAPI 3.0 spec, which supports @oneOf@ in schemas, allowing any sum types
-- to be faithfully represented. All sum encodings supported by @aeson@ are supported here as well, with
-- an exception of 'Data.Aeson.TwoElemArray', since OpenAPI spec does not support heterogeneous arrays.

Do (default) schemas for sum types agree with aeson, or am I missing something here (I cannot come up with a case where they disagree)?

@maksbotan
Copy link
Collaborator

Thanks for the observation! Looks like the first paragraph you mentioned survived as-is from swagger2 repo, along with some other comments in this file.

Would you like to make a PR to clean the docs?

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