Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger spec geneerated incorrectly if jackson-module-kotlin present #2629

Closed
dekar91 opened this issue Jun 17, 2024 · 1 comment
Closed
Labels
question Further information is requested

Comments

@dekar91
Copy link

dekar91 commented Jun 17, 2024

Hi here!

If dependency jackson-module-kotlin](com.fasterxml.jackson.module:jackson-module-kotlin) present in gradle (without any additional configuration) all kotlin properties startling with one letter and a word Index duplicated in swagger yaml.

Example:

data class Result(
    val result: Int,
    val aIndex: Int,
    val someIndex: Int,
    val bIndex: Int
)

Generated as:

{
  "Result": {
    "required": [
      "aindex",
      "bindex",
      "result",
      "someIndex"
    ],
    "type": "object",
    "properties": {
      "result": {
        "type": "integer",
        "format": "int32"
      },
      "aIndex": {
        "type": "integer",
        "format": "int32",
        "writeOnly": true
      },
      "someIndex": {
        "type": "integer",
        "format": "int32"
      },
      "bIndex": {
        "type": "integer",
        "format": "int32",
        "writeOnly": true
      },
      "aindex": {
        "type": "integer",
        "format": "int32"
      },
      "bindex": {
        "type": "integer",
        "format": "int32"
      }
    }
  }
}

To Reproduce
Steps to reproduce the behavior:

gradle.kts:

plugins {
    id("org.springframework.boot") version "3.3.0"
    id("io.spring.dependency-management") version "1.1.5"
    kotlin("jvm") version "2.0.0"
    kotlin("plugin.spring") version "2.0.0"

}

group = "org.example"
version = "0.0.1-SNAPSHOT"

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")

    implementation("org.springframework.boot:spring-boot-starter")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:2.5.0")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin") // If comment this line the bug disappears
}

kotlin {
    compilerOptions {
        freeCompilerArgs.addAll("-Xjsr305=strict")
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

Controller:

@RestController
class Controller  {
    @GetMapping
     fun hello(): Result =  Result(
            result = 1,
            aIndex = 2,
            someIndex = 1,
            bIndex = 3,
        )

    data class Result(
        val result: Int,
        val aIndex: Int,
        val someIndex: Int,
        val bIndex: Int
    )
}

Expected behavior

Properties starting with ?Index not duplicated in lowercase.

Screenshots
UI:
image

Additional context
Archived app:
duplicatedproperties.zip

@bnasslahsen
Copy link
Contributor

@dekar91,

This is a related to the following jackson-module-kotlin issue:FasterXML/jackson-module-kotlin#630

Here is the workaround:

    data class Result(
        val result: Int,
		@get:JsonProperty("aIndex")
		val aIndex: Int,
		val someIndex: Int,
		@get:JsonProperty("bIndex")
		val bIndex: Int
    )

@bnasslahsen bnasslahsen added the question Further information is requested label Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants