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

fix(templates): make queryParameters naming consistent #494

Merged
merged 2 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
- name: Pull Request title rules
uses: deepakputhraya/[email protected]
with:
regex: '^(docs|chore)|((?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\((?:generator|javascript|php|java|cts|spec|script|ci)\)): .+'
regex: '^(docs|chore)|((?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\((?:generators|javascript|php|java|cts|specs|scripts|ci|templates)\)): .+'
Copy link
Member Author

Choose a reason for hiding this comment

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

folder files etc are all using plural form so it's reflected here too

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class RequestOptions {

private final Map<String, String> headers = new HashMap<String, String>();
private final Map<String, String> queryParams = new HashMap<String, String>();
private final Map<String, String> queryParameters = new HashMap<String, String>();
private Integer timeout = null;

public RequestOptions addExtraHeader(
Expand All @@ -26,16 +26,16 @@ public RequestOptions addExtraQueryParameters(
@Nonnull String key,
@Nonnull String value
) {
queryParams.put(key, value);
queryParameters.put(key, value);
return this;
}

public Map<String, String> getExtraHeaders() {
return headers;
}

public Map<String, String> getExtraQueryParams() {
return queryParams;
public Map<String, String> getExtraQueryParameters() {
return queryParameters;
}

public Integer getTimeout() {
Expand All @@ -53,8 +53,8 @@ public String toString() {
"RequestOptions{" +
"headers=" +
headers +
", queryParams=" +
queryParams +
", queryParameters=" +
queryParameters +
'\'' +
'}'
);
Expand Down
34 changes: 17 additions & 17 deletions templates/java/libraries/okhttp-gson/ApiClient.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ public class ApiClient {
*
* @param path The sub-path of the HTTP URL
* @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
* @param queryParams The query parameters
* @param queryParameters The query parameters
* @param body The request body object
* @param headerParams The header parameters
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
* @return The HTTP call
* @throws AlgoliaRuntimeException If fail to serialize the request body object
*/
public Call buildCall(String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, RequestOptions requestOptions) throws AlgoliaRuntimeException {
Request request = buildRequest(path, method, queryParams, body, headerParams, requestOptions);
public Call buildCall(String path, String method, Map<String, String> queryParameters, Object body, Map<String, String> headerParams, RequestOptions requestOptions) throws AlgoliaRuntimeException {
Request request = buildRequest(path, method, queryParameters, body, headerParams, requestOptions);

return requester.newCall(request);
}
Expand All @@ -284,19 +284,19 @@ public class ApiClient {
*
* @param path The sub-path of the HTTP URL
* @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
* @param queryParams The query parameters
* @param queryParameters The query parameters
* @param body The request body object
* @param headerParams The header parameters
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
* @return The HTTP request
* @throws AlgoliaRuntimeException If fail to serialize the request body object
*/
public Request buildRequest(String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, RequestOptions requestOptions) throws AlgoliaRuntimeException {
public Request buildRequest(String path, String method, Map<String, String> queryParameters, Object body, Map<String, String> headerParams, RequestOptions requestOptions) throws AlgoliaRuntimeException {
boolean hasRequestOptions = requestOptions != null;
final String url = buildUrl(
path,
queryParams,
hasRequestOptions ? requestOptions.getExtraQueryParams() : null
queryParameters,
hasRequestOptions ? requestOptions.getExtraQueryParameters() : null
);
final Request.Builder reqBuilder = new Request.Builder().url(url);
processHeaderParams(
Expand Down Expand Up @@ -327,18 +327,18 @@ public class ApiClient {
* Build full URL by concatenating base path, the given sub path and query parameters.
*
* @param path The sub path
* @param queryParams The query parameters
* @param extraQueryParams The query parameters, coming from the requestOptions
* @param queryParameters The query parameters
* @param extraQueryParameters The query parameters, coming from the requestOptions
* @return The full URL
*/
public String buildUrl(String path, Map<String, String> queryParams, Map<String, String> extraQueryParams) {
public String buildUrl(String path, Map<String, String> queryParameters, Map<String, String> extraQueryParameters) {
StringBuilder url = new StringBuilder();

//The real host will be assigned by the retry strategy
url.append("http://temp.path").append(path);

url = parseQueryParameters(path, url, queryParams);
url = parseQueryParameters(path, url, extraQueryParams);
url = parseQueryParameters(path, url, queryParameters);
url = parseQueryParameters(path, url, extraQueryParameters);

return url.toString();
}
Expand All @@ -347,19 +347,19 @@ public class ApiClient {
* Parses the given map of Query Parameters to a given URL.
*
* @param path The sub path
* @param url The url to add queryParams to
* @param queryParams The query parameters
* @param url The url to add queryParameters to
* @param queryParameters The query parameters
* @return The URL
*/
public StringBuilder parseQueryParameters(
String path,
StringBuilder url,
Map<String, String> queryParams
Map<String, String> queryParameters
) {
if (queryParams != null && !queryParams.isEmpty()) {
if (queryParameters != null && !queryParameters.isEmpty()) {
// support (constant) query string in `path`, e.g. "/posts?draft=1"
String prefix = path.contains("?") ? "&" : "?";
for (Entry<String, String> param : queryParams.entrySet()) {
for (Entry<String, String> param : queryParameters.entrySet()) {
if (param.getValue() != null) {
if (prefix != null) {
url.append(prefix);
Expand Down
8 changes: 4 additions & 4 deletions templates/java/libraries/okhttp-gson/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,17 @@ public class {{classname}} extends ApiClient {
{{#x-is-custom-request}}{{{paramName}}}.toString(){{/x-is-custom-request}}{{^x-is-custom-request}}this.escapeString({{{paramName}}}.toString()){{/x-is-custom-request}}
){{/pathParams}}{{/vendorExtensions}};

{{javaUtilPrefix}}Map<String, String> queryParams = new {{javaUtilPrefix}}HashMap<String, String>();
{{javaUtilPrefix}}Map<String, String> queryParameters = new {{javaUtilPrefix}}HashMap<String, String>();
{{javaUtilPrefix}}Map<String, String> headers = new {{javaUtilPrefix}}HashMap<String, String>();

{{#vendorExtensions}}{{#queryParams}}
if ({{paramName}} != null) {
{{^x-is-custom-request}}
queryParams.put("{{baseName}}", parameterToString({{paramName}}));
queryParameters.put("{{baseName}}", parameterToString({{paramName}}));
{{/x-is-custom-request}}
{{#x-is-custom-request}}
for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
queryParams.put(parameter.getKey().toString(), parameterToString(parameter.getValue()));
queryParameters.put(parameter.getKey().toString(), parameterToString(parameter.getValue()));
}
{{/x-is-custom-request}}
}
Expand All @@ -192,7 +192,7 @@ public class {{classname}} extends ApiClient {
}

{{/headerParams}}
Call call = this.buildCall(requestPath, "{{httpMethod}}", queryParams, bodyObj, headers, requestOptions);
Call call = this.buildCall(requestPath, "{{httpMethod}}", queryParameters, bodyObj, headers, requestOptions);
Type returnType = new TypeToken<{{{returnType}}}>() {}.getType();
return this.executeAsync(call, returnType);
}
Expand Down
20 changes: 10 additions & 10 deletions templates/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
{{/allParams}}

$resourcePath = '{{{path}}}';
$queryParams = [];
$queryParameters = [];
$httpBody = [];
{{#vendorExtensions}}{{#queryParams}}

Expand All @@ -214,15 +214,15 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
{{#style}}
if(is_array(${{paramName}}) && ! in_array('{{paramName}}', RequestOptionsFactory::getAttributesToFormat())) {
foreach(${{paramName}} as $key => $value) {
$queryParams[$key] = $value;
$queryParameters[$key] = $value;
}
}
else {
$queryParams{{^x-is-custom-request}}['{{baseName}}']{{/x-is-custom-request}} = ${{paramName}};
$queryParameters{{^x-is-custom-request}}['{{baseName}}']{{/x-is-custom-request}} = ${{paramName}};
}
{{/style}}
{{^style}}
$queryParams['{{baseName}}'] = ${{paramName}};
$queryParameters['{{baseName}}'] = ${{paramName}};
{{/style}}
}
{{/isExplode}}
Expand All @@ -231,7 +231,7 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
${{paramName}} = ObjectSerializer::serializeCollection(${{paramName}}, '{{style}}{{^style}}{{collectionFormat}}{{/style}}', true);
}
if (${{paramName}} !== null) {
$queryParams['{{baseName}}'] = ${{paramName}};
$queryParameters['{{baseName}}'] = ${{paramName}};
}
{{/isExplode}}
{{/queryParams}}{{/vendorExtensions}}
Expand All @@ -257,7 +257,7 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
}
{{/bodyParams}}
{{#headerParams}}
$queryParams['{{baseName}}'] = ${{paramName}};
$queryParameters['{{baseName}}'] = ${{paramName}};
{{/headerParams}}
{{#servers.0}}
$operationHosts = [{{#servers}}"{{{url}}}"{{^-last}}, {{/-last}}{{/servers}}];
Expand All @@ -267,16 +267,16 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
$operationHost = $operationHosts[$this->hostIndex];

{{/servers.0}}
$requestOptions += $queryParams;
$requestOptions += $queryParameters;

return $this->sendRequest('{{httpMethod}}', $resourcePath, $queryParams, $httpBody, $requestOptions);
return $this->sendRequest('{{httpMethod}}', $resourcePath, $queryParameters, $httpBody, $requestOptions);
}

{{/operation}}

private function sendRequest($method, $resourcePath, $queryParams, $httpBody, $requestOptions)
private function sendRequest($method, $resourcePath, $queryParameters, $httpBody, $requestOptions)
{
$query = \GuzzleHttp\Psr7\Query::build($queryParams);
$query = \GuzzleHttp\Psr7\Query::build($queryParameters);

if($method == 'GET') {
$request = $this->api->read(
Expand Down
4 changes: 2 additions & 2 deletions tests/output/java/src/test/java/com/algolia/CallEcho.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private String processResponseBody() {
}
}

private Map<String, String> buildQueryParams() {
private Map<String, String> buildQueryParameters() {
Map<String, String> params = new HashMap<>();
HttpUrl url = request.url();
for (String name : url.queryParameterNames()) {
Expand All @@ -73,7 +73,7 @@ public void enqueue(Callback callback) {
body.path = request.url().encodedPath();
body.method = request.method();
body.body = processResponseBody();
body.queryParameters = buildQueryParams();
body.queryParameters = buildQueryParameters();
builder.body(
ResponseBody.create(
JSON.serialize(body),
Expand Down