OpenAPITools / OpenAPITools/openapi-generator

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

Open
#20,501 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

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
  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

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

/**
 * 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

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

Start by reproducing the issue with the supplied OpenAPI schema, Gradle configuration, and Kotlin generator options for the kotlinx_serialization library. Inspect the generated model output shown in the report and trace the Kotlin serialization annotation generation; done means the data class contains one @Serializable annotation and the generated Kotlin compiles.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.