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.49k stars 6.5k forks source link

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

Open dabeck81 opened 3 years ago

dabeck81 commented 3 years ago
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"));

eugeniace commented 1 year ago

I am encountering the same issue for webclient library.

christian-ertl commented 4 months ago

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