Skip to content

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

@alex-semenk

Description

@alex-semenk

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>
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions