OpenAPITools / OpenAPITools/openapi-generator
[BUG][KOTLIN] Multiple tags in YAML input lead to duplicate code generated
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? (Partial)
- 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
Duplicate Kotlin code is generated, which then fails to compile.
openapi-generator version
We use org.openapitools:openapi-generator-gradle-plugin:5.2.0
OpenAPI declaration file content or url
Excerpt from input file:
tags:
- name: customer
description: xxx
- name: customer profile
description: yyy
as well as
paths:
/customers:
post:
tags:
- customer
- customer profile
summary: zzz
operationId: createCustomer
Generation Details
The following code is produced
@PostMapping(
value = ["/customers"],
produces = ["application/json"]
)
fun createCustomer( @RequestHeader(value="requestId", required=true) requestId: kotlin.String
): ResponseEntity<CreateCustomerResponse> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
@PostMapping(
value = ["/customers"],
produces = ["application/json"]
)
fun createCustomer( @RequestHeader(value="requestId", required=true) requestId: kotlin.String
): ResponseEntity<CreateCustomerResponse> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
Steps to reproduce
Due to privacy constraints we can't paste more code here. However once we remove one of the two tags from the input, e.g.:
paths:
/customers:
post:
tags:
- customer
summary: zzz
operationId: createCustomer
then the generated Kotlin code does not contain a duplicate method createCustomer anymore.
Related issues/PRs
None
Suggest a fix
Do not generate a duplicate method even if multiple tags are provided for a given input.
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 by reproducing the issue with the YAML containing both customer and customer profile tags, then inspect the Kotlin generator involved in producing the duplicate createCustomer methods. No source files or tests are named in the report; done means the generated Kotlin contains only one method for the operation and compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100