OpenAPITools / OpenAPITools/openapi-generator
[BUG][Kotlin] kotlin-spring generateAliasAsModels creates invalid code, ArrayList needs a constructor invocation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
For the kotlin-spring generator,
When referencing an alias object that is an array, it tries to inherit from ArrayList. which is fine, but it does not add the constructor invocation ()'s after the inheritance line. This produces an invalid model object
openapi-generator version
6.1.1-SNAPSHOT ( -20220911.164728-2 )
OpenAPI declaration file content or url
yaml to reproduce:
https://gist.github.com/sreich/6579def798d45f527dd88d3468a46841
Generation Details
java -jar openapi-generator-cli-6.1.1-20220911.164728-2.jar generate -g kotlin-spring -i 'C:\Users\sreich\Downloads\kotlin-generator-bug-testcase.yaml' -o kotlin-spring-master -p generateAliasAsModel=true
Steps to reproduce
It will generate the TestObject code as below...but this is syntactically incorrect kotlin code
class TestObject(
) : kotlin.collections.ArrayList<TestObjectInner>{
}
Below is the correct code (add parentheses () after the generic).
class TestObject(
) : kotlin.collections.ArrayList<TestObjectInner>(){
}
this would fix the issue.
Related issues/PRs
Suggest a fix
Haven't dived into the code for this issue yet, but it basically just needs to add ()'s to the inheritance line of the generated model object
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the kotlin-spring generator and reproduce the issue using the provided CLI command and YAML gist with generateAliasAsModel=true. Inspect the generated TestObject model and the generator path responsible for alias-array models. Done means the generated inheritance line invokes ArrayList with (), producing syntactically valid Kotlin.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100