Skip to content

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

@qbuzzdaan

Description

@qbuzzdaan

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions