OpenAPITools / OpenAPITools/openapi-generator

[BUG][Kotlin] kotlin-spring generateAliasAsModels creates invalid code, ArrayList needs a constructor invocation

Open
#13,423 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.