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.28k stars 6.44k forks source link

[BUG] [Java] [Retrofit2] [Play] Fix Retrofit2 templates for Play framework to use fully qualified package name #5598

Open tfukushima opened 4 years ago

tfukushima commented 4 years ago

Bug Report Checklist

Description

In the API templates for Retrofit2 with Play framework, api.mustache, retrofit2.Response is imported but it is conflicted with the definition of the response defined inline in the responses section and it does not refer to the external definition by "ref" pointer. This causes the compilation errors since the generated code are imported before retrofit2.Response and they do not get along with the definition of Retrofit2's Response class.

openapi-generator version
$ ./openapi-generator-cli.sh version                                                                         
4.2.3
OpenAPI declaration file content or url

https://support.sigfox.com/api/apidocs

Command line used for generation
$ cat config.json 
{
  "apiPackage":"com.example.openapi.client.api",
  "artifactId":"sample-openapi-client",
  "artifactVersion":"0.1.0",
  "dateLibrary": "java8",
  "groupId":"com.example",
  "hideGenerationTimestamp": true,
  "invokerPackage":"com.example.openapi.client.invoker",
  "java8": true,
  "library":"retrofit2",
  "modelPackage":"com.example.openapi.client.model",
  "playVersion": "play26",
  "serializationLibrary": "jackson",
  "usePlayWS": true
}
$ ./openapi-generator-cli.sh generate -i https://support.sigfox.com/api/apidocs -g java -c config.json -o tmp
Steps to reproduce
$ cat > config.json  <<EOF
{
  "apiPackage":"com.example.sigfox.client.api",
  "artifactId":"sigfox-api-client",
  "artifactVersion":"0.1.0",
  "dateLibrary": "java8",
  "groupId":"com.example",
  "hideGenerationTimestamp": true,
  "invokerPackage":"com.example.sigfox.client.invoker",
  "java8": true,
  "library":"retrofit2",
  "modelPackage":"com.example.sigfox.client.model",
  "playVersion": "play26",
  "serializationLibrary": "jackson",
  "usePlayWS": true
}
EOF
$ ./openapi-generator-cli.sh generate -i https://support.sigfox.com/api/apidocs -g java -c config.json -o tmp
$ cd tmp
$ chmod +x ./gradlew
$ ./gradlew build

The compilation in the last step fails with compile errors.

Related issues/PRs

None

Suggest a fix

I made a patch and I'm wiling to make a PR with it if this issue got accepted.

https://github.com/tfukushima/openapi-generator/commit/42e3c4144cca8d9a980c5f29fd181f5c898e22cc

auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

wing328 commented 4 years ago

@tfukushima thanks for reporting the issue. Please file a PR so that we can review your fix more easily.