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(js): group parameters #46

Merged
merged 12 commits into from
Jan 4, 2022

Conversation

shortcuts
Copy link
Member

@shortcuts shortcuts commented Dec 16, 2021

🧭 What and Why

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

Changes included:

To improve our DX, we decided wrap parameters under an object which:

  • Provide type for each methods (better DX)
  • Allow us to introduce param changes without breaking the usage
  • Make usage consistent between methods

🧪 Test

CI :D

@shortcuts shortcuts requested a review from a team December 16, 2021 12:40
@shortcuts shortcuts self-assigned this Dec 16, 2021
@shortcuts shortcuts requested review from millotp and removed request for a team December 16, 2021 12:40
* @param {{paramName}} {{^description}}The {{paramName}}{{/description}}{{#description}}{{{description}}}{{/description}}
{{/allParams}}
{{! We group parameters under an object if there are more than 5}}
{{^allParams.5}}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say this is create more inconsistencies than needed, we should stick to one coding style imo. Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Like having everything under an object?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

Copy link
Member Author

@shortcuts shortcuts Dec 16, 2021

Choose a reason for hiding this comment

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

Hm.. this indeed creates inconsistencies but only for a few methods, while having objects everywhere would impact all the methods.

On a side note, this also creates inlined types (since it does not come from the specs), and would make the client much more verbose

Copy link
Member Author

Choose a reason for hiding this comment

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

@bodinsamuel should we postpone the merge of this PR until further discussion?

Copy link
Contributor

@bodinsamuel bodinsamuel Dec 17, 2021

Choose a reason for hiding this comment

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

We can postpone if there is strong pushback on the team, otherwise if the team agreed with > 5 you can merge

(I personally stand with object all the time but it's just my opinion)

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'll ask in core-apiclients after xmas, this is not urgent anyway

damcou
damcou previously approved these changes Dec 17, 2021
Copy link
Contributor

@damcou damcou left a comment

Choose a reason for hiding this comment

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

LGTM

@shortcuts shortcuts force-pushed the feat/APIC-227/javascript-group-parameters branch from 1e1749c to 134a386 Compare December 29, 2021 11:58
templates/javascript/api-single.mustache Show resolved Hide resolved
templates/javascript/api-single.mustache Show resolved Hide resolved
templates/javascript/api-single.mustache Show resolved Hide resolved
specs/search/common/schemas/SearchParams.yml Outdated Show resolved Hide resolved
playground/javascript/recommend.ts Show resolved Hide resolved
bodinsamuel
bodinsamuel previously approved these changes Jan 3, 2022
Copy link
Contributor

@bodinsamuel bodinsamuel left a comment

Choose a reason for hiding this comment

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

LGTM 💯

bodinsamuel
bodinsamuel previously approved these changes Jan 3, 2022
bodinsamuel
bodinsamuel previously approved these changes Jan 3, 2022
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.

A couple comments, looking good !

@@ -2,7 +2,7 @@
{
"method": "browse",
"testName": "get browse results with minimal parameters",
"parameters": ["indexName"],
"parameters": [{ "indexName": "indexName" }],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the parameters be an object instead of an array if we always pass one object ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since parameters will diverge in every languages, yes.

I'd say we should have an object with language: parameters.

(We could also generate code snippets later from this file, since we have the usage of each methods for each languages 🤔 )

Copy link
Collaborator

Choose a reason for hiding this comment

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

The people writing the CTS shouldn't care about the langage, I think the template should handle all the details (and the generator script can help by providing a parametersArray for example)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, also makes the thing a bit magic, but it should be easier to handle it in the templates.

@@ -2575,7 +2575,7 @@ public DeletedAtResponse deleteBy(
/**
* Delete all records matching the query. Remove all objects matching a filter (including geo
* filters). This method enables you to delete one or more objects based on filters (numeric,
* facet, tag or geo queries). It doesnt accept empty filters or a query.
* facet, tag or geo queries). It doesn't accept empty filters or a query.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you change {{&description}} to {{{description}}} (I'm not sure what the & does) in api-single.mustache to remove the ' ?

Copy link
Member Author

Choose a reason for hiding this comment

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

You can also use & to unescape a variable: {{& name}}. This may be useful when changing delimiters (see "Set Delimiter" below).

Not sure what is our use here 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I don't know, we are not using delimiters yet.

Copy link
Member Author

@shortcuts shortcuts Jan 4, 2022

Choose a reason for hiding this comment

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

Actually, adding the & removed the &#.. escaped chars, so I've added it to the Java template.

specs/search/common/schemas/SearchParams.yml Outdated Show resolved Hide resolved
@shortcuts shortcuts merged commit 71470e3 into main Jan 4, 2022
@shortcuts shortcuts deleted the feat/APIC-227/javascript-group-parameters branch January 4, 2022 10:18
Comment on lines +105 to +107
getRecommendations({
getRecommendations,
}: GetRecommendationsProps): Promise<GetRecommendationsResponse> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since GetRecommendations is already an object, we can pass it directly, I find it weird to write getRecommendations({ getRecommendations: {

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, but it requires some investigation on how to do so via mustache files, since we can't do comparison.

We could have a special case for this client, but it's not the right way to handle it if it happens again

Copy link
Contributor

Choose a reason for hiding this comment

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

ok thanks 👌

Copy link
Member Author

Choose a reason for hiding this comment

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

(We should indeed not forget about this issue before releasing a stable client IMO, especially if it's the only case)

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.

5 participants