OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.3k stars 6.44k forks source link

[7.3.0] Generated code with dependency error in class JSON #17929

Open alecar-smi opened 6 months ago

alecar-smi commented 6 months ago

If generating java code, the resulting JSON class has a dependency to the class com.fasterxml.jackson.databind.util.StdDateFormat even if not using jackson as a dependency

Code with error (JSON.java): private static final StdDateFormat sdf = new StdDateFormat() .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) .withColonInTimeZone(true);

My gradle task:

tasks.create(name: "buildClientEcm_${swagFile}", type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
    group = "swagger_generation"
    **generatorName = "java"**
    id = "ecm-client-generated"
    inputSpec = "$projectDir/swagger_${swagFile}.json".toString()
    outputDir = "$rootDir/ecm-client-generated-${swagFile}".toString()
    apiPackage = "it.smi.ie.ecm.client${swagSpec}"
    invokerPackage = "it.smi.ie.ecm.client${swagSpec}"
    modelPackage = "it.smi.ie.ecm.client.model${swagSpec}"
    **configOptions = [
        openApiNullable: "false"
    ]**
}

The generated build gradle dependencies: implementation 'io.swagger:swagger-annotations:1.6.8' implementation "com.google.code.findbugs:jsr305:3.0.2" implementation 'com.squareup.okhttp3:okhttp:4.10.0' implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0' implementation 'com.google.code.gson:gson:2.9.1' implementation 'io.gsonfire:gson-fire:1.9.0' implementation 'javax.ws.rs:jsr311-api:1.1.1' implementation 'javax.ws.rs:javax.ws.rs-api:2.1.1' implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0' implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version" testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' testImplementation 'org.mockito:mockito-core:3.12.4' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.1'

Bug present in 7.3.0 but not in 7.1.0

guitaoliu commented 6 months ago

Introduced in #17052

Philzen commented 3 months ago

@alecar-smi This should be fixed now via https://github.com/OpenAPITools/openapi-generator/pull/18811

Kindly retest on master-branch (there are also pregenerated samples, you'd be looking for samples/client/petstore/java/okhttp-* which you can easily try out without needing to build the project) or when v7.7.0 comes out and close this issue if you're happy with the result :smiley: