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
21.99k stars 6.6k forks source link

[BUG][KOTLIN] Data class not generated correctly when using allOf in array items #19755

Open andlbrei opened 1 month ago

andlbrei commented 1 month ago

Bug Report Checklist

Description

When trying to generate kotlin files from Open API spec, a data class without any properties is generated. In this case the bug is triggered when trying to generate a class from a definition of items in an array containing an allOf. It seems like the mustache template iterates over allVars to populate the data class, but allVars is empty, being reset in DefaultCodegen.java:L2637 https://github.com/andlbrei/openapi-generator/blob/2b75a9ccdc1a3819e650546d30b94aeb56e99f04/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L2637

openapi-generator version

7.8.0 The issue is present in 7.7.0 and 7.6.0 as well.

OpenAPI declaration file content or url

https://github.com/andlbrei/openapi-generator/blob/2b75a9ccdc1a3819e650546d30b94aeb56e99f04/modules/openapi-generator/src/test/resources/3_1/issue_wip.yaml

Generation Details

java -jar openapi-generator-cli.jar generate \ -i issue_wip.yaml \ -g kotlin \ -o .

Steps to reproduce

I made a fork with two tests, and a comment on one line of code that seems to break generation in this case. https://github.com/andlbrei/openapi-generator/commit/d51e3ff806d3906efbb5782b691bb07f3a4c8102

Related issues/PRs

I have not found a recent issue, though it is hard to be sure with the massive amount of issues that are open here.

Suggest a fix

I have commented on a line of code that impacts generation in this case. When this line is commented out it works. The code in this library is pretty complicated, and I would assume that "fixing" this case would break something else if done like this. If someone can guide me, I could make an attempt at fixing it.

wing328 commented 1 month ago

can you please file a PR to start with? that would make the code review a lot easier

andlbrei commented 1 month ago

@wing328 created https://github.com/OpenAPITools/openapi-generator/pull/19905

wing328 commented 1 month ago

update: filed https://github.com/OpenAPITools/openapi-generator/pull/19964 to workaround this for the time being