swagger-api / swagger-api/swagger-codegen

[Kotlin] Duplicated properties in constructor of data class

Open
#9,265 1 comment 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Codegen generates duplicated properties in constructor.

Swagger-codegen version

2.4.2

Swagger declaration file content or url
"swagger": "2.0"
AcceptTeamInvitationRequest:
    allOf:
      - $ref: '#/definitions/UserId'
      - properties:
          invitationCode:
            type: string
    type: object
    required:
      - invitationCode

UserId:
    type: object
    properties:
      userId:
        type: string
Generates this corrupt kotlin file
import io.swagger.client.models.UserId

/**
 * 
 * @param userId 
 * @param invitationCode 
 */
data class AcceptTeamInvitationRequest (
    val userId: kotlin.String? = null,
    val invitationCode: kotlin.String? = null,
    val userId: kotlin.String? = null,
    val invitationCode: kotlin.String? = null
) {

} 
Command line used for Kotlin generation

swagger-codegen generate -l kotlin -i swagger.api.yaml -c swagger-codegen.config.json -o my_directory

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with swagger.api.yaml and swagger-codegen.config.json using the shown Kotlin generation command. Trace the Kotlin code-generation entry point and templates responsible for composing inherited and local properties. Done means AcceptTeamInvitationRequest is generated with userId and invitationCode only once, while preserving the expected data-class constructor.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.