OpenAPITools / OpenAPITools/openapi-generator

[Kotlin][Spring] Incorrect generated class types when signature for two fields is the same

Open
#14,570 1 comment 0 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

Yaml:

openapi: 3.0.0
info:
  contact:
    name: ZZZ
  title: XXX
  version: 0.2.0
  description: AAA
paths:
  /test:
    get:
      summary: Test
      description: test
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: string
      operationId: testing-test
components:
  schemas:
    Testing:
      title: Testing
      x-stoplight:
        id: i4nhdvxy75d5w
      type: object
      properties:
        field1:
          type: object
          additionalProperties: false
          properties:
            name:
              type: string
        field2:
          type: object
          additionalProperties: false
          properties:
            name:
              type: string

Generated domain class:

/**
 * 
 * @param field1 
 * @param field2 
 */
data class Testing(

    @field:Valid
    @field:JsonProperty("field1") val field1: TestingField1? = null,

    @field:Valid
    @field:JsonProperty("field2") val field2: TestingField1? = null
) {

}

Here the generator should use TestingField1 for field1 and TestingField2 for field2, but the generator puts everywhere TestingField1 - it happens only if the classes have the same signature.

openapi-generator version

6.3.0

Generation Details
// The values oasPackage, oasSpecLocation, oasGenOutputDir are defined earlier
tasks.register("generateServer", org.openapitools.generator.gradle.plugin.tasks.GenerateTask::class) {
    input = project.file(oasSpecLocation).path
    outputDir.set(oasGenOutputDir.toString())
    modelPackage.set("$oasPackage.model")
    apiPackage.set("$oasPackage.api")
    packageName.set(oasPackage)
    generatorName.set("kotlin-spring")
    configOptions.set(
        mapOf(
            "exceptionHandler" to "false",
            "annotationLibrary" to "none",
            "documentationProvider" to "none",
            "dateLibrary" to "java8",
            "interfaceOnly" to "true",
            "reactive" to "false",
            "useTags" to "true",
            "useSpringController" to "false"
        )
    )
}
Steps to reproduce

Just generate the class based on YAML.

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 with the supplied OpenAPI YAML and the kotlin-spring generation configuration, then compare the generated Testing class with the expected field types. The work is done when identical nested schemas for field1 and field2 produce distinct generated types, such as TestingField1 and TestingField2.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, spring
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.