-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Labels
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
Generator generates code with this-escape warnings in ApiClient.
If you add -Xlint:all, -Werror to java compiler options, you will get error on any open-api specification.
Java compiler logs
...\project\build\java\src\main\java\org\openapitools\example\invoker\ApiClient.java:103: warning: [this-escape] possible 'this' escape before subclass is fully initialized
this.init();
^
...\project\build\java\src\main\java\org\openapitools\example\invoker\ApiClient.java:107: warning: [this-escape] possible 'this' escape before subclass is fully initialized
this(Optional.ofNullable(webClient).orElseGet(() -> buildWebClient()), createDefaultDateFormat());
^
...\project\build\java\src\main\java\org\openapitools\example\invoker\ApiClient.java:122: warning: [this-escape] previous possible 'this' escape happens here via invocation
this.init();
^
...\project\build\java\src\main\java\org\openapitools\example\invoker\ApiClient.java:111: warning: [this-escape] possible 'this' escape before subclass is fully initialized
this(buildWebClient(mapper.copy()), format);
^
...\project\build\java\src\main\java\org\openapitools\example\invoker\ApiClient.java:122: warning: [this-escape] previous possible 'this' escape happens here via invocation
this.init();
^
...\project\build\java\src\main\java\org\openapitools\example\invoker\ApiClient.java:115: warning: [this-escape] possible 'this' escape before subclass is fully initialized
this(Optional.ofNullable(webClient).orElseGet(() -> buildWebClient(mapper.copy())), format);
^
...\project\build\java\src\main\java\org\openapitools\example\invoker\ApiClient.java:122: warning: [this-escape] previous possible 'this' escape happens here via invocation
this.init();
^
openapi-generator version
v7.2.0
OpenAPI declaration file content or URL
Information to reproduce
jdk: Oracle OpenJDK 21.0.1
gradle: 8.5
open-api generator plugin: 7.2.0
build.gradle.kts
plugins {
id("java")
id("org.openapi.generator") version "7.2.0"
}
group = "test.group"
version = "1.0"
repositories {
mavenCentral()
}
dependencies {
implementation("org.openapitools:jackson-databind-nullable:0.2.6")
implementation("com.fasterxml.jackson.core:jackson-annotations:2.16.1")
implementation("com.fasterxml.jackson.core:jackson-core:2.16.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.16.1")
implementation("org.springframework.boot:spring-boot-starter-webflux:3.2.1")
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
}
sourceSets {
named("main") {
java {
srcDir("$buildDir/java/src/main/java")
}
}
}
tasks.test {
useJUnitPlatform()
}
openApiGenerate {
generatorName = "java"
library = "webclient"
inputSpec = "$projectDir/src/main/openapi/petstore-v3.0.yaml"
outputDir = "$buildDir/java"
apiPackage = "org.openapitools.example.api"
invokerPackage = "org.openapitools.example.invoker"
modelPackage = "org.openapitools.example.model"
configOptions.putAll(mapOf(
"dateLibrary" to "java8",
"serializationLibrary" to "jackson",
"useJakartaEe" to "true",
"hideGenerationTimestamp" to "true"
))
globalProperties.putAll(mapOf(
"apiTests" to "false",
"modelDocs" to "false"
))
skipValidateSpec = true
logToStderr = true
generateAliasAsModel = false
enablePostProcessFile = false
}
tasks.withType<JavaCompile>() {
options.compilerArgs.addAll(listOf("-Xlint:all", "-Werror"))
}Suggest a fix
Change init method in class ApiClient
Reactions are currently unavailable