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] serializableModel generates "extends" instead of "implements" #17895

Closed
thorstenhirsch opened this issue Feb 19, 2024 · 4 comments · Fixed by #18248
Closed

[BUG] serializableModel generates "extends" instead of "implements" #17895

thorstenhirsch opened this issue Feb 19, 2024 · 4 comments · Fixed by #18248

Comments

@thorstenhirsch
Copy link
Contributor

Bug Report Checklist

Description

When generating Java code with serializableModel=true the result is faulty.

expected result:

public class MyClass implements Serializable {
}

current result (simplified):

public class MyClass extends Serializable {
}

In my case there was already an class from which to extend, so Serializable was just added:
current result:

public class MyClass extends Something, Serializable {
}
openapi-generator version

7.3.0 with Java 17 and Java 21

OpenAPI declaration file content or url & Generation Details

Just use any OpenAPI JSON with the following command to generate the Java code:

java -jar libs/openapi-generator-cli-7.3.0.jar generate \
      -i ./my.json -g java -o genc \
      --additional-properties library=native,serializableModel=true
Steps to reproduce
  1. Generate code
  2. Check classes for "Serializable"
@martin-mfg
Copy link
Contributor

Hi,
in my tests with your described settings, it worked fine. Here's an example of the output I get: public class MyObject extends HashMap<String, Object> implements Serializable {.
If the problem persists for you, please provide a minimal reproducible example.

@thorstenhirsch
Copy link
Contributor Author

thorstenhirsch commented Mar 27, 2024

Just reproduced the issue with version 7.4.0. You can use the attached Test-OpenAPI.json to reproduce the issue. With the following call you will get a class de.my.client.model.CoreBar with a faulty Serializable declaration.

$ java -jar openapi-generator-cli-7.4.0.jar generate -i ./Test-OpenAPI.json -g java -o genc --additional-properties library=native,serializableModel=true --invoker-package=de.my.client --model-package=de.my.client.model --api-package=de.my.client.api
public class CoreBar extends AbstractOpenApiSchema, Serializable { ... }

P.S.: Java version = 21, platform = Windows 10.

Test-OpenAPI.json

@thorstenhirsch
Copy link
Contributor Author

I could break down the problem to this parameter:

library=native

Without this parameter the generator works correctly.

@martin-mfg
Copy link
Contributor

Thanks for the clarification. I could reproduce the issue now and created a fix for it.

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

Successfully merging a pull request may close this issue.

2 participants