-
Notifications
You must be signed in to change notification settings - Fork 84
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
Discriminator in oneOf unions appears twice in response #1229
Comments
We also came up against a subtle bug with the way this works in ogen. In our case from v1.1.0 on we got this in the response.
Our clients that were depending on this suddenly started seeing a blank string for the Root cause seems to be the way ogen handles the discriminator. If you omit the
ogen will create the top level The problem with this approach is that it is not very explicit nor does it seem to comply with the OpenAPI spec,
https://spec.openapis.org/oas/latest.html#discriminator-object However, if we add both the
The helper function Ideally, we adhere to the OpenAPI spec and allow (require?) the discriminator to be set in the |
In my case, I'm generating my openapi schema from typespec, so sadly it's not an option to just remove the type from the union members. |
It causes problems if child schema used somewhere else. See #1155. |
I don't have a problem with the child type being generated. I just think it should not appear twice in the serialized response, since that's invalid json, and there's no workaround. Maybe this is something that should be fixed at the serialization level? Edit: Just as a quick aside, why not just remove the type from the parent? |
Awesome, thanks a lot! |
Just tested the latest commit, looks like the bug has been fixed by reverting to previous behaviour. 👏
This makes sense. Maybe just needs to be documented that the child |
What version of ogen are you using?
$ go list -m github.com/ogen-go/ogen # github.com/ogen-go/ogen v1.1.0
Can this issue be reproduced with the latest version?
Yes
What did you do?
I'm using the following schema:
With this schema and a basic handler implementation that just returns the following:
The
type
field is encoded twice in the response:What did you expect to see?
The discriminator field should only be encoded once, e.g.:
What did you see instead?
As stated above, the field appears twice:
Even when leaving out the
type
field inside theFirst
struct, I get the following:The text was updated successfully, but these errors were encountered: