OpenAPITools / OpenAPITools/openapi-generator

Is there any way to use builder pattern with java 8?

Open
#7,772 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I am using this for creating a java library.
my config is as follows

{
  "library": "retrofit2",
  "artifactId": "example",
  "invokerPackage": "in.example.api",
  "apiPackage" : "in.example.api",
  "modelPackage" : "in.example.api",
  "groupId": "in.example",
  "scmDeveloperConnection" : "",
  "url" : "",
  "asyncNative" : true,
  "java8" : true,
  "dateLibrary" : "java8"
}

Sadly the code this generates doesnt have builder pattern for the request objects.
https://github.com/OpenAPITools/openapi-generator/pull/5961 I saw this issue where builder pattern support was added. But it seems to only work when I set library to "native" . However that forces me to use java 11.
Is it possible to generate the similar library with builder pattern using java8 and retrofit2 library?

openapi-generator version

5.0.0-beta

OpenAPI declaration file content or url
Command line used for generation

./openapi-geneartor-cli.sh generate -i ./swagger.json -g java -c ./config.json -o ./

Suggest a fix/enhancement

Thanks!

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

Start by inspecting how the Java generator handles the retrofit2 library, the java8 setting, and builder generation, then compare the behavior described in PR #5961. Reproduce the shown configuration and command, and define completion as generating request objects with builder support while remaining compatible with Java 8 and Retrofit 2.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.