openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][JAVA][FEIGN] Code generation outputs non-compilable code.

Open dabeck81 opened this issue 4 years ago • 2 comments

Description

When building with Feign, the generated code can not be compiled because of the missing OAuth.class on the classpath.

When in the JavaClientCodegen.java the classes OauthPasswordGrant.java and OauthClientCredentialsGrant.java get added we need also the OAuth-class to be added because the 2 mentioned classes extend this abstract-class.

This can be seen in the mustache files OauthPasswordGrant.mustache and OauthClientCredentialsGrant.mustache

openapi-generator version

the version I tested is 5.1.1

Generation Details

This codegeneration is run with following gradle-task:

openApiGenerate {
    generatorName = "java"
    inputSpec = "$buildDir/openapi.json"
    outputDir = "$buildDir/generated-client"
    apiPackage = "our.package.api"
    invokerPackage = "our.package.invoker"
    modelPackage = "our.package.model"
    configOptions = [
            dateLibrary       : "java8",
            interfaceOnly     : "true",
            debugModels       : "true",
            java8             : "true",
            ensureUniqueParams: "false",
            library           : "feign"
    ]
    globalProperties = [
            modelDocs: "false"
    ]
    skipValidateSpec = true
    logToStderr = true
    generateAliasAsModel = false
    enablePostProcessFile = false
}

execution of a build with the generated gradle.build results in a compilation error that OAuth.class is not found.

Suggest a fix

add following line in the javaClientCodegen in the if-clause of Feign (if (FEIGN.equals(getLibrary()))):

supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));

dabeck81 avatar Jul 02 '21 10:07 dabeck81

I am encountering the same issue for webclient library.

eugeniace avatar Jan 17 '23 14:01 eugeniace

Currently in 7.6.0, OAuth is present, but incompatible to its subclasses.

christian-ertl avatar May 24 '24 12:05 christian-ertl