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

[BUG] Mix of junit4 and junit5 in Java generator 7.5.0

Open thorstenhirsch opened this issue 1 year ago • 5 comments

Description

While the model tests use JUnit 5 (import org.junit.jupiter.api.Test) the api tests still use JUnit 4 (import org.junit.Test).

openapi-generator version

7.5.0

OpenAPI declaration file content or url

Any OpenAPI.json should reproduce the problem.

Generation Details
java -jar openapi-generator-cli-7.5.0.jar generate -i ./MyOpenAPI.json -g java -o genc --additional-properties library=native,serializableModel=true,hideGenerationTimestamp=true,useJakartaEe=true
Steps to reproduce
  1. Generate Java code
  2. mvn clean test
Related issues/PRs

n/a

Suggest a fix

Fix the code that generates the API tests.

thorstenhirsch avatar Apr 23 '24 08:04 thorstenhirsch

thanks for reporting the issue. may i know if you've time to contribute a fix with a PR?

wing328 avatar Apr 23 '24 08:04 wing328

Maybe... can't promise anything regarding the timeframe. But 1st of all, here's a simple json to reproduce the issue. MyOpenAPI.json

thorstenhirsch avatar Apr 23 '24 09:04 thorstenhirsch

So I just tested 7.6.0 which contained some of these fixes but I'm still getting test compilation errors like:

[ERROR] /runner/_work/openapi-client-generator-action/openapi-client-generator-action/client_generation_scripts/gen/java/src/test/java/com/jimdo/openapiclientgeneratoractiontestopenapijavawebclientclient/OnboardingDisconnectErrorResponseTest.java:[21,29] 
package org.junit.jupiter.api does not exist
...
[ERROR] /runner/_work/openapi-client-generator-action/openapi-client-generator-action/client_generation_scripts/gen/java/src/test/java/com/jimdo/openapiclientgeneratoractiontestopenapijavawebclientclient/OnboardingDisconnectErrorResponseTest.java:[34,6]
cannot find symbol
  symbol:   class Test
  location: class 
...

bijancn avatar May 22 '24 11:05 bijancn

@bijancn may I know which generator/library did you test?

wing328 avatar May 22 '24 11:05 wing328

@wing328 yes of course, we are using the docker image openapitools/openapi-generator-cli:7.6.0 with -g java and "--additional-properties=library=webclient". If you can't reproduce this, I can try to make a minimal reproducer from our full setup.

bijancn avatar May 22 '24 12:05 bijancn

update: filed https://github.com/OpenAPITools/openapi-generator/pull/18741 to fix the issue

wing328 avatar May 23 '24 07:05 wing328