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

[BUG][native][apache-httpclient] Generated code contains warnings in ApiClient #18384

Closed
5 tasks done
welandaz opened this issue Apr 15, 2024 · 2 comments
Closed
5 tasks done

Comments

@welandaz
Copy link
Contributor

welandaz commented Apr 15, 2024

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

If you add -Xlint:all, -Werror to java compiler options, you will get error on any open-api specification.

  • When native as a library is used, the generator generates code with [this-escape] possible 'this' escape before subclass is fully initialized warnings in ApiClient.
  • When apache-httpclient as a library is used, the generator generates code with [rawtypes] found raw type: Collection warnings in ApiClient.
openapi-generator version

7.4.0

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/1105759a6f20edac389fa547359c7d5e6c4f9ac8/modules/openapi-generator-gradle-plugin/samples/local-spec/petstore-v3.0.yaml

Generation Details
Steps to reproduce

jdk: Oracle OpenJDK 21.0.1
gradle: 8.7
open-api generator plugin: 7.4.0

plugins {
    id("java")
    id("org.openapi.generator") version "7.4.0"
}

group = "com.test"
version = "1.0"

repositories {
    mavenCentral()
}

dependencies {
    implementation("jakarta.annotation:jakarta.annotation-api:3.0.0")

    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("com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.13.4")
    implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.0")

    implementation("javax.annotation:javax.annotation-api:1.3.2")

    implementation("org.apache.httpcomponents.client5:httpclient5:5.4-alpha2")

    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"
    inputSpec = "$projectDir/src/main/resources/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(
        "library" to "apache-httpclient", // change to native for other warnings
        "dateLibrary" to "java8",
        "serializationLibrary" to "jackson",
        "useJakartaEe" to "true",
        "hideGenerationTimestamp" to "true",
        "openApiNullable" to "false",
        "useBeanValidation" to "false",
        "disallowAdditionalPropertiesIfNotPresent" to "false",
        "containerDefaultToNull" to "true",
    ))
}

tasks.withType<JavaCompile> {
    options.compilerArgs.addAll(listOf("-Xlint:all", "-Werror"))
}
Related issues/PRs

#17475

Suggest a fix
  • native library: Change the implementation of affected methods with [this-escape] warnings
  • apache-httpclient library: Don't use raw type with Collection object (reimplement with generics if possible)
@ainurabdrashitov
Copy link

Looks similar to the #17475

@welandaz
Copy link
Contributor Author

Resolved by #20466

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants