OpenAPITools / OpenAPITools/openapi-generator
[BUG] [kotlin-spring] kotlin-spring generator creates wrong filenames for controller classes
Nobody has claimed this yet.
- 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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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