[REQ] [Java] use a builder pattern for parameters?
Created by: bgong-mdsol
Is your feature request related to a problem? Please describe.
Not an issue per se, just a better way to achieve the same result.
Describe the solution you'd like
Currently parameters of an endpoint become parameters on a method.
Some endpoints have many parameters and as a result, the method will have 10s of parameters. Something like:
search(uuid, uuid2, uuid3, name, some_bool, other_bool, this_int, this_other_uuuid, other_bool, name2, name3)
The problems are:
- Usually you only need a couple of params so you call this with 2 params and 9 null
- It is very difficult to review and very error prone
- If the openapi spec changes the order in which they write the params or if they add a param in the first position, all the params will shift position. If types match, the code will compile but the outgoing call would be totally different.
To mitigate that, we used a builder pattern in our own templates to handle parameters, usage roughly looks like that:
String operation = "unlock";
String operatorUuid = "596ad8ad-40f3-4fcd-b8af-7e7be5d8337c";
ServiceClient myApi = createServiceClient();
APIpermissionsIndexParams params = APIpermissionsIndexParams.builder()
.operation(operation)
.operatorUuid(operatorUuid)
.build();
List<Permission> response = myApi.permissionsIndex(params);
Describe alternatives you've considered
Using Map<String, Object>
.
Additional context
N/A
We would like to contribute the code back upstream but before opening a PR we'd like to hear the thoughts of the java tech committee.
Thanks!
@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @bkabrda