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

[REQ] Add x-field-extra-annotation for "kotlin" generator

Open alex-semenk opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe.

Currently java generator (as well as some other generators) has x-field-extra-annotation feature, which allows to annotate Java fileds for any model class, generated from openapi spec. You can find description of x-field-extra-annotation property in openapi-generator docs https://openapi-generator.tech/docs/generators/java/ Currently kotlin generator doesn't support this feature as you can find in docs https://openapi-generator.tech/docs/generators/kotlin/

Describe the solution you'd like

The request is to add support for x-field-extra-annotation feature for "kotlin" generator. So kotlin models can be generated with additional field annotations. This is especially vital when you need to provide custom @JsonSerialize or JsonDeserialize annotation to deserialize or serialize model correctly. Currently I didn't found any workaround to provide custom JsonSerialize/JsonDeserialize annotations for model fields.

Describe alternatives you've considered

The only alternative solution I can see so far is to define customized template for kotlin model generator, to manually add support for x-field-extra-annotation attribute.

Additional context

Here is an example of openapi spec and expected generated model

OpenAPI spec:

Account:
  type: "object"
  required:
    - "name"
    - "assets"
  properties:
    name:
      type: "string"
    assets:
      type: "object"
      additionalProperties:
        type: "string"
      x-field-extra-annotation: "@JsonDeserialize(converter = AssetConverter::class)"

Generated Model:

data class Account (

    @field:JsonProperty("name")
    val name: kotlin.String,

    @field:JsonProperty("assets")
    @JsonDeserialize(converter = AssetConverter::class)
    val assets: Map<String, String>
)

alex-semenk avatar Jan 06 '24 13:01 alex-semenk

@alex-semenk thanks for the suggestion. May I know if you've time to contribute a PR for that?

wing328 avatar Jan 11 '24 16:01 wing328

@wing328 Sure, I think I might find some time a little later to add the feature. I will let you know when I will have some progress on this.

alex-semenk avatar Jan 13 '24 13:01 alex-semenk

Hello, is it planned? I see it's available in the documentation: https://openapi-generator.tech/docs/generators/java/ but adding class or field level configs has zero effect

Oleksii-Hovderchak avatar Feb 07 '24 15:02 Oleksii-Hovderchak

Hi @Oleksii-Hovderchak the documentation you provided is for "java" generator, however current issue is open for "kotlin" generator. For which generator are you missing "x-field-extra-annotation" feature?

alex-semenk avatar Feb 08 '24 14:02 alex-semenk

Does not support kotlin generator "x-field-extra-annotation"?

Fitpet-Jake avatar Feb 22 '24 10:02 Fitpet-Jake

unfortunately kotlin is lagging behind :-(

aldex32 avatar May 07 '24 16:05 aldex32

+1

alarv avatar Jun 07 '24 10:06 alarv

+1

alarv avatar Jul 25 '24 08:07 alarv

Hi @Oleksii-Hovderchak the documentation you provided is for "java" generator, however current issue is open for "kotlin" generator. For which generator are you missing "x-field-extra-annotation" feature?

Would it work for kotlin-spring? The x-... extensions are defined in https://openapi-generator.tech/docs/generators/kotlin-spring/

dzmitry-ivanou avatar Jul 30 '24 22:07 dzmitry-ivanou

Hi @Oleksii-Hovderchak the documentation you provided is for "java" generator, however current issue is open for "kotlin" generator. For which generator are you missing "x-field-extra-annotation" feature?

Would it work for kotlin-spring? The x-... extensions are defined in https://openapi-generator.tech/docs/generators/kotlin-spring/

I see, it looks like it is planned for 7.8.0 https://github.com/OpenAPITools/openapi-generator/pull/19202

dzmitry-ivanou avatar Jul 31 '24 03:07 dzmitry-ivanou