Forum Discussion

ric1's avatar
Regular Visitor
2 years ago

Generated Java code (swagger) does not compile

I'm trying to create e Java client defined with swagger. I have generated the source code automatically in three ways.

java -jar swagger-codegen-cli-3.0.20.jar generate -i -l java
swagger-codegen generate -i -l java
Unfortunately, the generated source code cannot be compiled in all ways. When I execute

mvn clean install

I get many errors of this type: cannot inherit from final B

I have analyzed the error and found the following pattern many times.

public class A extends B {
public enum B {
I know that the swagger provider works with c# and in this language this construct should be allowed.

I see the following in jason

"xxxx.xxxx.xx.B": {
"enum": [
"type": "string"


"b": {
"allOf": [
"$ref": "#/xxxx/xxxx/xxxx.xxxx.xx.B"
"description": "abc",
"nullable": true
I am not allowed to publish the swagger URL.

Is there anything I can do to build a Java client anyway?

1 Reply

  • dsinghvi77's avatar
    Occasional Contributor

    Hey ric1 -- 


    1) If you post your open api spec happy to help you debug in more detail.(I have heard the Native Generator: works the best) 

    2) My team has been working on a Swagger alternative that really focuses on codegen (as Swagger was initially built for docs) and we are calling it Fern. Repo here. Demo video here.
    It is as easy as 

    npm install -g fern-api (to install)
    fern init # initializes a basic fern api
    fern add java # adds java generator
    fern generate