OpenAPITools / OpenAPITools/openapi-generator

[Kotlin] Models with "additionalProperties" result in invalid Kotlin code

Open Beginner friendly
#13,395 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When using the kotlin-spring generator, OpenAPI models including additionalProperties are generated as invalid Kotlin code.

openapi-generator version

5.4.0 and 6.0.1

OpenAPI declaration file content or url
components:
  schemas:
    MyObject:
      type: object
      properties:
        value:
          type: string
      additionalProperties: true
      required:
        - value

...is generated into...

data class MyObject(

    @field:JsonProperty("value", required = true) val `value`: kotlin.String,
) : kotlin.collections.HashMap<String, kotlin.Any>{

}

Note the missing () after kotlin.collections.HashMap<String, kotlin.Any>.

Suggest a fix/enhancement

I'd propose the fix as just adding the missing () to the kotlin-spring's dataClass.mustache file, but I'm not sure if it should be fixed there or in the general Kotlin code for the variable being provided to the template.

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 its dataClass.mustache template, using the OpenAPI schema and generated Kotlin shown in the issue as the reproduction. Check whether the missing constructor parentheses belong in the template or the value supplied to it. Done means the additionalProperties model generates valid Kotlin code, with the relevant generator checks passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, openapi
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.