OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.51k stars 6.27k forks source link

[BUG][JAVA] Generated anyOf models have deserializer that returns bad type the first time its used #18975

Closed qbuzzdaan closed 3 days ago

qbuzzdaan commented 1 week ago

Bug Report Checklist

Description

When generating code for models that contain anyOf properties, the resulting deserializers don't always return the correct response type. The first time input JSON is deserialized, the resulting instance can be of the wrong type.

openapi-generator version

Version 7.6.0 and before.

OpenAPI declaration file content or url

https://gist.github.com/qbuzzdaan/d4348d1786e4d519a60df6e3790580ed

Generation Details

n/a

Steps to reproduce

Generation files are included in the gist: the pom.xml defines how the openapi-spec.yaml is to be turned into classes, and the DifficultTest.java shows the issue.

Related issues/PRs

Couldn't find any

Suggest a fix

I'll push a branch with a potential fix in the generation mustache files.