OpenAPITools / OpenAPITools/openapi-generator

[BUG] [kotlin-spring] kotlin-spring generator creates wrong filenames for controller classes

Open Beginner friendly
#10,670 1 comment 0 reactions 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
Description

When using options:

  • interfaceOnly = false
  • delegatePattern = false

The controller classes are generated with a filename different than the class name. For example, the petstore.yaml generates a class PetApiController (annotated with @RestController) in a file PetApi.kt instead of PetApiController.kt.

openapi-generator version

5.2.1

OpenAPI declaration file content or url

petstore.yaml

Steps to reproduce
  • copy petstore.yaml in a local folder
  • run the cli generator:
    java -jar openapi-generator-cli-5.2.1.jar generate -g kotlin-spring -i petstore.yaml -o out --additional-properties=interfaceOnly=false --additional-properties=delegatePattern=false
  • expected result: a controller PetApiController is generated in out/src/main/kotlin/org/openapitools/api/PetApiController.kt
  • actual result: a controller PetApiController is generated in out/src/main/kotlin/org/openapitools/api/PetApi.kt
Suggest a fix

Update method KotlinSpringServerCodegen.processOpts() to add the template file "api.mustache" with the suffix "Controller.kt":

        if (!this.interfaceOnly && this.delegatePattern) {
            apiTemplateFiles.put("apiInterface.mustache", ".kt");
            apiTemplateFiles.put("apiController.mustache", "Controller.kt");
        } else if (interfaceOnly) {
            apiTemplateFiles.put("apiInterface.mustache", ".kt");
        } else {
            apiTemplateFiles.put("api.mustache", "Controller.kt"); // FIX
            apiTestTemplateFiles.put("api_test.mustache", ".kt");
        }

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 in KotlinSpringServerCodegen.processOpts() and inspect the api.mustache template mapping for the interfaceOnly=false, delegatePattern=false path. Reproduce with petstore.yaml and the provided generator command, then verify that the generated PetApiController class is written to PetApiController.kt rather than PetApi.kt.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.