[BUG][kotlin] Duplicate @serializable annotation for generated data class (kotlinx-serialization)

Author: anwarproCreated Jan 19, 2025Updated Sep 24, 2026
LabelsIssue: Bug

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

Duplicate @Serializable annotation for generated data class. which lead to error This annotation is not repeatable.

openapi-generator version

openapi-generator-gradle-plugin 7.10.0

OpenAPI declaration file content or url
yaml
  schemas:
    AuthCallbackResponse:
      type: object
      description: The authentication's details.
      x-schemaName: AuthCallbackResponse
      required:
        - location
      properties:
        location:
          type: string
          title: location
          description: The location to redirect the user to for further authentication with the third-party provider.
    AuthResponse:
      type: object
      description: The authentication's details.
      x-schemaName: AuthResponse
      required:
        - token
      properties:
        token:
          type: string
          title: token
          description: The JWT token used for registration or authentication.

paths:
  /auth/customer/{auth_provider}:
    post:
      operationId: PostActor_typeAuth_provider
      summary: Authenticate Customer
      description: |
        Authenticate a customer and receive the JWT token to be used in the header of subsequent requests.

        When used with a third-party provider, such as Google, the request returns a `location` property. You redirect to the specified URL in your storefront to continue authentication with the third-party service.
      externalDocs:
        url: https://docs.medusajs.com/v2/storefront-development/customers/login#1-using-a-jwt-token
        description: 'Storefront development: How to login as a customer'
      x-authenticated: false
      parameters:
        - name: auth_provider
          in: path
          description: The provider used for authentication.
          required: true
          schema:
            type: string
            example: emailpass
      requestBody:
        content:
          application/json:
            schema:
              type: object
              description: The input data necessary for authentication. For example, for email-pass authentication, pass `email` and `password` properties.
              properties:
                email:
                  type: string
                password:
                  type: string
      tags:
        - Auth
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/AuthResponse'
                  - $ref: '#/components/schemas/AuthCallbackResponse'
                x-kotlin-discriminator:
                  token: AuthResponse
                  location: AuthCallbackResponse
Generation Details

gradle configration

kotlin
val generatedSourcesPath = "$buildDir/generated"
val apiDescriptionFile = "${projectDir}/src/medusaOpenApiOnlyStore.yaml"
val apiRootName = "com.medusa"

openApiGenerate {
    generatorName.set("kotlin")
    inputSpec.set(apiDescriptionFile)
    outputDir.set("${rootDir.absolutePath}/kotlin-client")
    apiPackage.set("$apiRootName.api")
    invokerPackage.set("$apiRootName.invoker")
    modelPackage.set("$apiRootName.model")
    additionalProperties.set(
        mapOf(
            "library" to "multiplatform",
            "dateLibrary" to "kotlinx-datetime",
            "serializationLibrary" to "kotlinx_serialization"
        )
    )
}

generated code

kotlin
/**
 * The authenticated customer's details.
 *
 * @param user 
 */
@Serializable@Serializable

data class AuthStoreSessionResponse (

    @SerialName(value = "user") @Required val user: StoreCustomer

) {


}

Here need only on @Serializable annotation

Steps to reproduce
Related issues/PRs
Suggest a fix

Source: OpenAPITools/openapi-generator