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

refactor(javascript): simplify transporter.request #617

Merged
merged 1 commit into from
Jun 1, 2022

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented May 31, 2022

🧭 What and Why

Simplify transporter.request by turning it from three arguments to only two.

I can't see any significant difference between the first (request) and second (methodOptions) argument of request, so this PR changes that to both be in the first argument. requestOptions is still separate.

Other API clients don't seem to distinguish that clearly in the arguments to sendRequest, as they use mostly positional arguments

PHP:

return $this->sendRequest('{{httpMethod}}', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions, {{#vendorExtensions.x-use-read-transporter}}true{{/vendorExtensions.x-use-read-transporter}});

Java:

Call call = this.buildCall(requestPath, "{{httpMethod}}", queryParameters, bodyObj, headers, requestOptions, {{#vendorExtensions.x-use-read-transporter}}true{{/vendorExtensions.x-use-read-transporter}}{{^vendorExtensions.x-use-read-transporter}}false{{/vendorExtensions.x-use-read-transporter}});

Changes included:

  • transporter.request(request, methodOptions, requestOptions) -> transporter.request(request, requestOptions)

🧪 Test

This is a breaking change if you'd be using a custom request using the requester, but I guess that doesn't count yet.

If there's a historic reason for why there are three arguments and not two, feel free to research that too

I can't see any significant difference between the first and second argument of `request`, so this PR changes that to both be in the first argument. requestOptions is still separate.

Other API clients don't seem to distinguish that clearly in the arguments to sendRequest, as they use mostly positional arguments

PHP: https://github.com/algolia/api-clients-automation/blob/bf4271246f9282d3c11dd46918e74cb86d9c96dc/templates/php/api.mustache#L263

Java: https://github.com/algolia/api-clients-automation/blob/bf4271246f9282d3c11dd46918e74cb86d9c96dc/templates/java/libraries/okhttp-gson/api.mustache#L196
@Haroenv Haroenv requested review from millotp and shortcuts May 31, 2022 15:27
@netlify
Copy link

netlify bot commented May 31, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit 3cf28c2
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/629633cd29aa5b0008a91130

@algolia-bot
Copy link
Collaborator

algolia-bot commented May 31, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.
You can still access the code generated on main via this commit.

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.

Thank you ! It makes sense to only have 2 parameters, the original reason come from the first time we generated the client, it was built that way in openapi generator and it stayed for no good reason

data?: Array<Record<string, any>> | Record<string, any>;
headers: Headers;
Copy link
Collaborator

Choose a reason for hiding this comment

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

the headers are in both the EndRequest and the Request now, but the request is not used by the http requester, only the echoRequester so it's okay but we must not get confused in the createEchoRequester, where we want the final headers and not the one from request.

@millotp millotp merged commit af6c83d into main Jun 1, 2022
@millotp millotp deleted the refactor/js-remove-method-params branch June 1, 2022 10:06
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.

3 participants