OpenAPITools / OpenAPITools/openapi-generator
[BUG][Kotlin] Using <interfaceOnly>true</interfaceOnly> with kotlin-spring generator still generates controller body
Nobody has claimed this yet.
- 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?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Using this spec as input: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.yaml
and this configuration:
<configOptions>
<interfaceOnly>true</interfaceOnly>
<serviceInterface>true</serviceInterface>
...
</configOptions>
the generated methods still contain body and the code doesn't compile:
@RequestMapping("\${api.base-path:/v1}")
interface PetsApi {
@Operation(
summary = "Create a pet",
operationId = "createPets",
description = "",
responses = [
ApiResponse(responseCode = "201", description = "Null response"),
ApiResponse(responseCode = "200", description = "unexpected error", content = [Content(schema = Schema(implementation = Error::class))])
]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/pets"],
produces = ["application/json"]
)
fun createPets(): ResponseEntity<Unit> {
return ResponseEntity(service.createPets(), HttpStatus.valueOf(201)) // <=================
}
...
Not only is method code generated but also it references a service (which is injected when interfaceOnly is false) which fails compilation with 'Unresolved reference: service'.
openapi-generator version
I'm using the org.openapitools:openapi-generator-maven-plugin:6.0.0 maven plugin (maven is 3.8.6).
OpenAPI declaration file content or url
https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.yaml
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 with the kotlin-spring generator using the linked petstore.yaml spec and the interfaceOnly=true and serviceInterface=true configuration. Compare the generated PetsApi methods with the reported output; done means interface-only methods no longer contain a body or reference the injected service, and the generated Kotlin code compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100