Skip to content

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

Description

@martinsaison

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");
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions