Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #10670
Closed
Open
Issue created Oct 23, 2021 by Administrator@rootContributor

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

Created by: 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");
        }
Assignee
Assign to
Time tracking