-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
✅ Deploy Preview for api-clients-automation canceled.
|
✗ The generated branch has been deleted.If the PR has been merged, you can check the generated code on the |
@@ -0,0 +1,63 @@ | |||
package com.algolia.utils; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file copied from the current client implementation: https://github.com/algolia/algoliasearch-client-java-2/blob/master/algoliasearch-core/src/main/java/com/algolia/search/models/RequestOptions.java
...methodOptions.queryParameters, | ||
...baseRequestOptions?.queryParameters, |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
if (prefix != null) { | ||
url.append(prefix); | ||
prefix = null; | ||
} else { | ||
url.append("&"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something like...
if (prefix != null) { | |
url.append(prefix); | |
prefix = null; | |
} else { | |
url.append("&"); | |
} | |
url.append(prefix); | |
if (prefix.equals("?")) { | |
prefix = "&"; | |
} |
There was a problem hiding this comment.
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:
There was a problem hiding this 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.
52fc6e9
to
d416640
Compare
There was a problem hiding this 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
...asearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/RequestOptions.java
Outdated
Show resolved
Hide resolved
} | ||
{{/optionalParams.0}} | ||
|
||
{{! This case only sets `requestOptions` as optional }} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
(byte[]) obj, | ||
MediaType.parse(this.contentType) | ||
); | ||
} else if (isJsonMime(this.contentType)) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good ! Thanks !
🧭 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