Skip to content

Commit

Permalink
feat(generator): handle custom request escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Mar 31, 2022
1 parent 59ce8b4 commit a1396b9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
12 changes: 0 additions & 12 deletions clients/algoliasearch-client-javascript/bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@
{
"path": "packages/recommend/dist/recommend.umd.browser.js",
"maxSize": "3.80KB"
},
{
"path": "packages/client-common/dist/client-common.esm.node.js",
"maxSize": "5.25KB"
},
{
"path": "packages/requester-browser-xhr/dist/requester-browser-xhr.esm.node.js",
"maxSize": "900B"
},
{
"path": "packages/requester-node-http/dist/requester-node-http.esm.node.js",
"maxSize": "1.15KB"
}
]
}
6 changes: 4 additions & 2 deletions templates/java/libraries/okhttp-gson/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ public class {{classname}} extends ApiClient {
Object bodyObj = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};

// create path and map variables
String requestPath = "{{{path}}}"{{#pathParams}}
.replaceAll("\\{" + "{{baseName}}" + "\\}", this.escapeString({{{paramName}}}.toString())){{/pathParams}};
String requestPath = "{{{path}}}"{{#vendorExtensions}}{{#pathParams}}.replaceAll(
{{=<% %>=}}"\\{<%baseName%>\\}"<%={{ }}=%>,
{{#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}}List<Pair> queryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
{{javaUtilPrefix}}Map<String, String> headers = new {{javaUtilPrefix}}HashMap<String, String>();
Expand Down
9 changes: 3 additions & 6 deletions templates/javascript/api-single.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,9 @@ export function create{{capitalizedApiName}}Api(options: CreateClientOptions{{#h
{{/allParams.0}}
requestOptions?: RequestOptions
) : Promise<{{{returnType}}}> {
const requestPath = '{{{path}}}'{{#pathParams}}.replace(
{{=<% %>=}}
'{<%baseName%>}',
<%={{ }}=%>
encodeURIComponent(String({{paramName}}))
){{/pathParams}};
const requestPath = '{{{path}}}'{{#vendorExtensions}}{{#pathParams}}.replace(
{{=<% %>=}}'{<%baseName%>}'<%={{ }}=%>,{{#x-is-custom-request}}String({{paramName}}){{/x-is-custom-request}}{{^x-is-custom-request}}encodeURIComponent(String({{paramName}})){{/x-is-custom-request}}
){{/pathParams}}{{/vendorExtensions}};
const headers: Headers = {};
const queryParameters: QueryParameters = {};

Expand Down
8 changes: 4 additions & 4 deletions templates/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
}
{{/isExplode}}
{{/queryParams}}
{{#pathParams}}
{{#vendorExtensions}}{{#pathParams}}
// path params
{{#collectionFormat}}
if (is_array(${{paramName}})) {
Expand All @@ -240,12 +240,12 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
{{/collectionFormat}}
if (${{paramName}} !== null) {
$resourcePath = str_replace(
'{' . '{{baseName}}' . '}',
ObjectSerializer::toPathValue(${{paramName}}),
{{=<% %>=}}'{<%baseName%>}'<%={{ }}=%>,
{{#x-is-custom-request}}{{paramName}}{{/x-is-custom-request}}{{^x-is-custom-request}}ObjectSerializer::toPathValue(${{paramName}}){{/x-is-custom-request}},
$resourcePath
);
}
{{/pathParams}}
{{/pathParams}}{{/vendorExtensions}}

{{#bodyParams}}
if (isset(${{paramName}})) {
Expand Down

0 comments on commit a1396b9

Please sign in to comment.