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

use oneOf for sum types. #15

Closed
thought2 opened this issue Dec 7, 2021 · 1 comment
Closed

use oneOf for sum types. #15

thought2 opened this issue Dec 7, 2021 · 1 comment

Comments

@thought2
Copy link

thought2 commented Dec 7, 2021

I'm not 100% about this, Swagger is relatively new for me.

I tried to generate a swagger spec which contains this sum type:

data FooBar
  = Foo Int
  | Bar String
  deriving (Show, Generic, Typeable)

It generates something like this:

        "FooBar": {
            "properties": {
                "Bar": {
                    "type": "string"
                },
                "Foo": {
                    "minimum": -9223372036854775808,
                    "type": "integer",
                    "maximum": 9223372036854775807
                }
            },
            "minProperties": 1,
            "type": "object",
            "maxProperties": 1
        },

All the client generators that I tried so far were not able to reconstruct this to a proper union type. It's turned into an object with two optional properties. Like here in TypeScript

type FooBar = {
  foo?: string,
  bar?: number
}

Do I miss something here or would that be an enhancement?

@thought2 thought2 closed this as completed Dec 8, 2021
@thought2
Copy link
Author

thought2 commented Dec 8, 2021

Closed because I mixed up the repos. In servant-swagger there's already an issue for this: haskell-servant/servant-swagger#80

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

1 participant