Skip to content

Commit e5be1c8

Browse files
authored
[javascript] [typescript] [php] [ruby] Simplify url parameter replacement code (#23485)
1 parent 1680d28 commit e5be1c8

File tree

135 files changed

+452
-452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+452
-452
lines changed

modules/openapi-generator/src/main/resources/Javascript-Closure-Angular/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ goog.require('{{import}}');
6666
{{package}}.{{classname}}.prototype.{{nickname}} = function({{#allParams}}{{^required}}opt_{{/required}}{{paramName}}, {{/allParams}}opt_extraHttpRequestParams) {
6767
/** @const {string} */
6868
var path = this.basePath_ + '{{{path}}}'{{#pathParams}}
69-
.replace('{' + '{{baseName}}' + '}', String({{^required}}opt_{{/required}}{{paramName}})){{/pathParams}};
69+
.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, String({{^required}}opt_{{/required}}{{paramName}})){{/pathParams}};
7070

7171
/** @type {!Object} */
7272
var queryParameters = {};

modules/openapi-generator/src/main/resources/Javascript-Closure-Angular/es6/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default class {{classname}} {
5656
method: '{{httpMethod}}',
5757
url: this.basePath + '{{{path}}}'
5858
{{#pathParams}}
59-
.replace('{' + '{{baseName}}' + '}', ':{{paramName}}')
59+
.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, ':{{paramName}}')
6060
{{/pathParams}}
6161
}
6262
}

modules/openapi-generator/src/main/resources/Javascript-Flowtyped/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
8989
{{/required}}
9090
{{/allParams}}
9191
const localVarPath = `{{{path}}}`{{#pathParams}}
92-
.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String({{paramName}}))){{/pathParams}};
92+
.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, encodeURIComponent(String({{paramName}}))){{/pathParams}};
9393
const localVarUrlObj = url.parse(localVarPath, true);
9494
const localVarRequestOptions: RequestOptions = Object.assign({}, { method: '{{httpMethod}}' }, options);
9595
const localVarHeaderParameter = {};

modules/openapi-generator/src/main/resources/php-nextgen/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ use {{invokerPackage}}\ObjectSerializer;
718718
{{/collectionFormat}}
719719
if (${{paramName}} !== null) {
720720
$resourcePath = str_replace(
721-
'{' . '{{baseName}}' . '}',
721+
{{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>,
722722
ObjectSerializer::toPathValue(${{paramName}}{{#isEnumRef}}->value{{/isEnumRef}}),
723723
$resourcePath
724724
);

modules/openapi-generator/src/main/resources/php/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ use {{invokerPackage}}\ObjectSerializer;
640640
{{/collectionFormat}}
641641
if (${{paramName}} !== null) {
642642
$resourcePath = str_replace(
643-
'{' . '{{baseName}}' . '}',
643+
{{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>,
644644
ObjectSerializer::toPathValue(${{paramName}}),
645645
$resourcePath
646646
);

modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ use function sprintf;
598598
{{/collectionFormat}}
599599
if (${{paramName}} !== null) {
600600
$resourcePath = str_replace(
601-
'{' . '{{baseName}}' . '}',
601+
{{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>,
602602
ObjectSerializer::toPathValue(${{paramName}}),
603603
$resourcePath
604604
);

modules/openapi-generator/src/main/resources/ruby-client/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module {{moduleName}}
170170
{{/hasValidation}}
171171
{{/allParams}}
172172
# resource path
173-
local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', CGI.escape({{paramName}}.to_s){{^strictSpecBehavior}}.gsub('%2F', '/'){{/strictSpecBehavior}}){{/pathParams}}
173+
local_var_path = '{{{path}}}'{{#pathParams}}.sub({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, CGI.escape({{paramName}}.to_s){{^strictSpecBehavior}}.gsub('%2F', '/'){{/strictSpecBehavior}}){{/pathParams}}
174174

175175
# query parameters
176176
query_params = opts[:query_params] || {}

modules/openapi-generator/src/main/resources/typescript-angularjs/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class {{classname}} {
3535
*/
3636
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{{returnType}}}{{^returnType}}{}{{/returnType}}> {
3737
const localVarPath = this.basePath + '{{{path}}}'{{#pathParams}}
38-
.replace('{' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};
38+
.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, encodeURIComponent(String({{paramName}}))){{/pathParams}};
3939

4040
let queryParameters: any = {};
4141
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);

modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
5555
{{/required}}
5656
{{/allParams}}
5757
const localVarPath = `{{{path}}}`{{#pathParams}}
58-
.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String({{paramName}}))){{/pathParams}};
58+
.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, encodeURIComponent(String({{paramName}}))){{/pathParams}};
5959
// use dummy base URL string because the URL constructor only accepts absolute URLs.
6060
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
6161
let baseOptions;

modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,21 +295,21 @@ export class {{classname}} extends runtime.BaseAPI {
295295
{{#pathParams}}
296296
{{#isDateTimeType}}
297297
if (requestParameters['{{paramName}}'] instanceof Date) {
298-
urlPath = urlPath.replace(`{${"{{baseName}}"}}`, encodeURIComponent(requestParameters['{{paramName}}'].toISOString()));
298+
urlPath = urlPath.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, encodeURIComponent(requestParameters['{{paramName}}'].toISOString()));
299299
} else {
300-
urlPath = urlPath.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String(requestParameters['{{paramName}}'])));
300+
urlPath = urlPath.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, encodeURIComponent(String(requestParameters['{{paramName}}'])));
301301
}
302302
{{/isDateTimeType}}
303303
{{^isDateTimeType}}
304304
{{#isDateType}}
305305
if (requestParameters['{{paramName}}'] instanceof Date) {
306-
urlPath = urlPath.replace(`{${"{{baseName}}"}}`, encodeURIComponent(requestParameters['{{paramName}}'].toISOString().substring(0,10)));
306+
urlPath = urlPath.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, encodeURIComponent(requestParameters['{{paramName}}'].toISOString().substring(0,10)));
307307
} else {
308-
urlPath = urlPath.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String(requestParameters['{{paramName}}'])));
308+
urlPath = urlPath.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, encodeURIComponent(String(requestParameters['{{paramName}}'])));
309309
}
310310
{{/isDateType}}
311311
{{^isDateType}}
312-
urlPath = urlPath.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String(requestParameters['{{paramName}}'])));
312+
urlPath = urlPath.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, encodeURIComponent(String(requestParameters['{{paramName}}'])));
313313
{{/isDateType}}
314314
{{/isDateTimeType}}
315315
{{/pathParams}}

0 commit comments

Comments
 (0)