Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(java): add requestOptions #487

Merged
merged 5 commits into from
May 11, 2022
Merged

feat(java): add requestOptions #487

merged 5 commits into from
May 11, 2022

Conversation

shortcuts
Copy link
Member

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-469

Changes included:

This PR adds the requestOptions parameter to every methods of the Java client.

The method is already present in the JavaScript client, but there's a small fix in this PR:

  • requestOptions headers and query parameters should always override default/method parameters.

The CTS did not changed, I'll add tests for this behavior in my next PR for all clients.

🧪 Test

CI :D

@shortcuts shortcuts requested review from millotp and a team May 10, 2022 12:29
@shortcuts shortcuts self-assigned this May 10, 2022
@shortcuts shortcuts requested review from eunjae-lee and removed request for a team May 10, 2022 12:29
@netlify
Copy link

netlify bot commented May 10, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit fc4ce88
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/627b853c5528e500087422df

@algolia-bot
Copy link
Collaborator

algolia-bot commented May 10, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.

@@ -0,0 +1,63 @@
package com.algolia.utils;
Copy link
Member Author

@shortcuts shortcuts May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...methodOptions.queryParameters,
...baseRequestOptions?.queryParameters,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was wrong, parameters from requestOptions should always override defaults/methods parameters

* @param queryParams The query parameters
* @return The URL
*/
public StringBuilder parseQueryParameters(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the logic was duplicated for both map I've used this, it seems to work but not a fan of the implem

@@ -13,7 +13,6 @@ import org.junit.jupiter.api.BeforeAll;
import com.google.gson.reflect.TypeToken;

import com.algolia.JSON;
import com.algolia.Pair;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to remove this one earlier

Comment on lines +543 to 395
if (prefix != null) {
url.append(prefix);
prefix = null;
} else {
url.append("&");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something like...

Suggested change
if (prefix != null) {
url.append(prefix);
prefix = null;
} else {
url.append("&");
}
url.append(prefix);
if (prefix.equals("?")) {
prefix = "&";
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the actual logic to avoid introducing unrelated changes, I don't really know the edge cases possible here D:

eunjae-lee
eunjae-lee previously approved these changes May 10, 2022
Copy link
Contributor

@eunjae-lee eunjae-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. The suggestion in the parseQueryParameters is not a blocker.

@shortcuts shortcuts requested a review from eunjae-lee May 11, 2022 08:01
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice ! I have a few comments mostly about usage

templates/java/libraries/okhttp-gson/ApiClient.mustache Outdated Show resolved Hide resolved
templates/java/libraries/okhttp-gson/api.mustache Outdated Show resolved Hide resolved
}
{{/optionalParams.0}}

{{! This case only sets `requestOptions` as optional }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need both, you can just keep the first one but always generate it, and if someone want's to provide requestOptions, they have to provide null for all the optional params before, I'll let you choose which one best suits the customer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both with #487 (comment) are fine to keep, it's a bit verbose but a pretty good addition

@@ -139,7 +148,7 @@ public class {{classname}} extends ApiClient {
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public CompletableFuture<{{{returnType}}}> {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}},{{/-last}} {{/allParams}}) throws AlgoliaRuntimeException {
public CompletableFuture<{{{returnType}}}> {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}RequestOptions requestOptions) throws AlgoliaRuntimeException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the async functions are widely used, maybe it would be worth it to also gave them alternative with optionals

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean all optionals or just the requestOptions part?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exact same as sync function, that mean:

  • all params
  • all params + requestOptions
  • only required params + requestOptions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah oki so I'm missing the last one for the async here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could also have only required alone actually, it makes more sense

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so sync and async function would need:

  • all params
  • all params - requestOptions
  • requiredParams + requestOptions
  • requiredParams

?

Copy link
Collaborator

@millotp millotp May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good ! you thinks it's okay or too much ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good, we could even have more cases but it should be enough

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cases above are reflected here: ad0ff62

@shortcuts shortcuts requested a review from millotp May 11, 2022 08:47
(byte[]) obj,
MediaType.parse(this.contentType)
);
} else if (isJsonMime(this.contentType)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this if is not relevant anymore as we already know the mime type, at least for the serialization

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I did not saw that fc4ce88

@shortcuts shortcuts requested a review from millotp May 11, 2022 09:33
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good ! Thanks !

@shortcuts shortcuts merged commit c5ac185 into main May 11, 2022
@shortcuts shortcuts deleted the feat/requestOptions branch May 11, 2022 10:03
millotp pushed a commit that referenced this pull request May 11, 2022
This was referenced May 19, 2022
@shortcuts shortcuts mentioned this pull request May 23, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants