Created by: Kiran-Sivakumar
PR checklist
-
Read the contribution guidelines. -
Ran the shell script under ./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. -
Filed the PR against the correct branch: master
,3.4.x
,4.0.x
. Default:master
. -
Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
@bbdouglas @JFCote @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger
Description of the PR
fix https://github.com/OpenAPITools/openapi-generator/issues/1217 This PR (filed against branch 3.4.x) adds the option to generate APIs of the form shown in the proposed solution in the above issue. This makes generated okhttp-gson clients much nicer to use, especially in cases involving unused optional parameters. The hope is to implement a similar solution for all Java generators in the future, so that generated Java clients aren't frustrating to use.
Changes:
- JavaClientCodegen.java modified to add a new CLI option "useBuildersForApiRequests" (default: false)
- okhttp-gson/api.mustache
- Optionally generate API-request builders
- Change original methods from "public" to "private" if builders are generated, since user will want to use the public builder methods instead (the builder methods simply wrap around the original methods that take all parameters as input)
- Generate comments
- okhttp-gson/api_test.mustache added to generate tests that use the builders if the "useBuildersForApiRequests" option is enabled
- bin/java-petstore-okhttp-gson-builders.sh added to generate petstore samples with API-request builders (added one for Windows as well)
- samples/client/petstore/java/okhttp-gson-requestBuilders/: new petstore samples generated with the above script
- docs/generators/java.md updated with new config option
I also ran the original shell scripts under ./bin/
to ensure that absolutely nothing changes in the existing petstore samples when the "useBuildersForApiRequests" option is disabled.