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

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

Merged
merged 3 commits into from
Nov 21, 2022

Conversation

stevladimir
Copy link
Contributor

@stevladimir stevladimir commented May 11, 2022

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
Copy link
Contributor Author

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

@stevladimir
Copy link
Contributor Author

Ping

@maksbotan
Copy link
Collaborator

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.

@maksbotan maksbotan merged commit acc5ea7 into biocad:master Nov 21, 2022
@stevladimir stevladimir deleted the fix-allof-oneof branch November 21, 2022 08:29
dhess added a commit to hackworthltd/primer that referenced this pull request Feb 3, 2023
The `openapi3` package was apparently generating an invalid OpenAPI
spec for schemas that use `oneOf` or `allOf`. This was fixed in
v3.2.3, which we now use after the package bump in the previous
commit. See:

biocad/openapi3#49
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

Successfully merging this pull request may close these issues.

None yet

2 participants