OpenAPITools / OpenAPITools/openapi-generator

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

Open
#5,598 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Java Client: Retrofit Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect api.mustache in the Java Retrofit2 templates for the Play framework, starting by reproducing the issue with the provided config.json and generation command. Run ./gradlew build in the generated project; done means the generated code compiles without the retrofit2.Response naming conflict and uses the fully qualified package name.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.