biocad / servant-openapi3

OpenAPI 3.0 for Servant
BSD 3-Clause "New" or "Revised" License
38 stars 23 forks source link

use `oneOf` for sum types. #15

Closed m-bock closed 2 years ago

m-bock commented 2 years ago

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?

m-bock commented 2 years ago

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