biocad / openapi3

OpenAPI 3.0 data model
BSD 3-Clause "New" or "Revised" License
39 stars 54 forks source link

Don't add 'object' type when generating sum schema with allOf/oneOf #49

Closed stevladimir closed 1 year ago

stevladimir commented 2 years ago

When generating schema for some sum types the type field is set as object. But that seems to be incorrect. E.g.

data Foo = Bar | Baz Int
  deriving (Show, Generic)
instance ToSchema Foo where
  declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions{sumEncoding = UntaggedValue}

will have schema

{
    "oneOf": [
        {
            "enum": [
                "Bar"
            ],
            "type": "string"
        },
        {
            "maximum": 9223372036854775807,
            "minimum": -9223372036854775808,
            "type": "integer"
        }
    ],
    "type": "object"
} 

However, encoding of the Foo is clearly not an object.

This also confuses SwaggerUI.

Schema is valid image

But generated example is not image

If one removes type field example becomes valid image

Unrelated change, but looks like there was a redundant dependency on network package. Few types from it were imported, but neither used nor re-exported.

stevladimir commented 2 years ago

Friendly ping. Should I assign a reviewer on my own?

stevladimir commented 1 year ago

Ping

maksbotan commented 1 year ago

Hm, I went through OpenAPI 3.0 spec and it does not explicitly mention type at all. All examples with oneOf do not have type though.