openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open jonpeterson opened this issue 4 years ago • 4 comments

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.

jonpeterson avatar Sep 09 '22 13:09 jonpeterson

yes please fix this ... I am eagerly waiting for this bug to be fixed ... this is the reason why we have to resort to some dirty workarounds to make our openapi spec file work and cannot define some of the fixed properties at least.

benjamineckstein avatar Mar 11 '24 08:03 benjamineckstein

@benjamineckstein did you test the fix (https://github.com/OpenAPITools/openapi-generator/pull/13822) to see if it works for your use cases?

wing328 avatar Mar 11 '24 12:03 wing328

Is this fix going to happen?

karisalonen avatar Mar 31 '26 06:03 karisalonen

The problem also exists if JSON contains empty additionalProperties like:

additionalProperties: {}

ivanvasheka-intellias avatar Jul 06 '26 11:07 ivanvasheka-intellias