OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Kotlin] additionalEnumTypeAnnotations option missing from Kotlin generator

Open
#15,479 1 comment 1 reaction 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

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

Originally, #6055 reported the fact that the annotations from additionalModelTypeAnnotations do not get applied to enumerations when using the Java generator. This was subsequently fixed via #8389 by adding a new additionalEnumTypeAnnotations option. However, this only applies to the Java generator, and this option is still missing from the Kotlin generator. As far as I know, there is currently no configuration that applies a certain annotation to all generated enums.

openapi-generator version

using the gradle plugin with version 6.6.0

OpenAPI declaration file content or url

This is the same spec that is given as an example in #6055:

swagger: "2.0"
info:
    title: Book
    version: 1.0.0
paths:
    /books:
        get:
            summary: Get books
            responses:
                200:
                    description: Successful response
                    schema:
                        type: array
                        items:
                            $ref: '#/definitions/Book'
definitions:
    Book:
        description: Book
        type: object
        properties:
            type:
                $ref: '#/definitions/BookType'
    BookType:
        description: Book type
        type: string
        enum:
            - HARDCOVER
            - PAPERBACK
            - ELECTRONIC
Generation Details

Specifying an additionalEnumTypeAnnotations option in the additional properties has no effect on generated enums (because that behaviour has only been implemented for the Java generator)

Steps to reproduce
  1. run: generate -g kotlin -p additionalModelTypeAnnotations=@Foo for the given spec
  2. inspect the generated enum: It does not have the @Foo annotation
  3. run: generate -g kotlin -p additionalEnumTypeAnnotations=@Foo for the given spec
  4. inspect the generated enum: It does not have the @Foo annotation
Related issues/PRs

#6055
#8389

Suggest a fix

I suggest adding the additionalEnumTypeAnnotations option to the additional properties of the Kotlin generator, with functionality analogous to the option for the Java generator (#8389).

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 generator's additional properties and compare them with the Java implementation added in #8389. Reproduce the supplied Swagger 2.0 example using additionalEnumTypeAnnotations=@Foo; done means generated Kotlin enums receive the annotation, while the existing additionalModelTypeAnnotations behavior remains understood.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.