[JAVA] Remove [this-escape] warnings in generated ApiClient classes#21620
Conversation
|
cc @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08) |
| this.builder = createDefaultHttpClientBuilder(); | ||
| this.mapper = createDefaultObjectMapper(); | ||
| updateBaseUri(getDefaultBaseUri()); | ||
| updateBaseUri("{{{basePath}}}"); |
There was a problem hiding this comment.
The usage of getDefaultBaseUri() in the constructor is fine until the user overrides it and references any dynamically calculated value from a field/method (static string would be fine).
A proper fix would be to have a constructor that accepts a basePath and doesn't offer a default value (or leave this method as is, but remove it from the constructor and introduce a factory method that creates the ApiClient and invokes updateBaseUri right after). That would be a breaking change, though it would address the problem.
This change is a compromise of sorts, where a default value is taken directly from the variable (which user can still override or call updateBaseUri later). The getter is simply a getter now and isn't invoked anywhere.
There was a problem hiding this comment.
A proper fix would be to have a constructor that accepts a basePath
agreed. that's what the okhttp-gson client offers.
and we can leave it to another PR instead
This PR is basically a follow-up to an earlier one where some of these issues have been addressed, but not completely.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)