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: path var naming collision #702

Merged
merged 1 commit into from
Aug 30, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class {{ service.name | caseUcfirst }} : Service {
onProgress: ((UploadProgress) -> Unit)? = null
{%~ endif %}
){% if method.type != "webAuth" %}: {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}{% endif %} {
val path = "{{ method.path }}"
val apiPath = "{{ method.path }}"
{%~ for parameter in method.parameters.path %}
.replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }})
{%~ endfor %}
Expand Down Expand Up @@ -88,7 +88,7 @@ class {{ service.name | caseUcfirst }} : Service {
}
}

val url = Uri.parse("${client.endPoint}${path}?${query.joinToString("&")}")
val url = Uri.parse("${client.endPoint}${apiPath}?${query.joinToString("&")}")
val callbackUrlScheme = "{{ spec.title | caseLower }}-callback-${client.config["project"]}"

WebAuthComponent.authenticate(activity, url, callbackUrlScheme) {
Expand Down Expand Up @@ -118,7 +118,7 @@ class {{ service.name | caseUcfirst }} : Service {
{%~ elseif method.type == 'location' %}
return client.call(
"{{ method.method | caseUpper }}",
path,
apiPath,
params = params,
responseType = {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}::class.java
)
Expand Down Expand Up @@ -146,7 +146,7 @@ class {{ service.name | caseUcfirst }} : Service {
{%~ endif %}
{%~ endfor %}
return client.chunkedUpload(
path,
apiPath,
headers,
params,
responseType = {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}::class.java,
Expand All @@ -160,7 +160,7 @@ class {{ service.name | caseUcfirst }} : Service {
{%~ else %}
return client.call(
"{{ method.method | caseUpper }}",
path,
apiPath,
headers,
params,
{%~ if method.responseModel | hasGenericType(spec) %}
Expand Down
14 changes: 7 additions & 7 deletions templates/cli/lib/commands/command.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
{% endfor %}

let client = !sdk ? await {% if service.name == "projects" %}sdkForConsole(){% else %}sdkForProject(){% endif %} : sdk;
let path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
let apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
let payload = {};
{% if method.parameters.query|length > 0 %}

Expand Down Expand Up @@ -95,9 +95,9 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
payload['project'] = localConfig.getProject().projectId
payload['key'] = globalConfig.getKey();
const queryParams = new URLSearchParams(payload);
path = `${globalConfig.getEndpoint()}${path}?${queryParams.toString()}`;
apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;

const response = await client.call('{{ method.method | caseLower }}', path, {
const response = await client.call('{{ method.method | caseLower }}', apiPath, {
{% for parameter in method.parameters.header %}
'{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }},
{% endfor %}
Expand All @@ -122,7 +122,7 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
if (size <= libClient.CHUNK_SIZE) {
payload['{{ parameter.name }}'] = fs.createReadStream(payload['{{ parameter.name }}']);

response = await client.call('{{ method.method | caseLower }}', path, {
response = await client.call('{{ method.method | caseLower }}', apiPath, {
{% for parameter in method.parameters.header %}
'{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }},
{% endfor %}
Expand Down Expand Up @@ -154,7 +154,7 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
{% if parameter.isUploadID %}
if({{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') {
try {
response = await client.call('get', path + '/' + {{ parameter.name }}, headers);
response = await client.call('get', apiPath + '/' + {{ parameter.name }}, headers);
counter = response.chunksUploaded;
} catch(e) {
}
Expand All @@ -178,7 +178,7 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
});
payload['{{ parameter.name }}'] = stream;

response = await client.call('{{ method.method | caseLower }}', path, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});
response = await client.call('{{ method.method | caseLower }}', apiPath, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});

if (!id) {
id = response['$id'];
Expand All @@ -198,7 +198,7 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
{% endif %}
{% endfor %}
{% else %}
response = await client.call('{{ method.method | caseLower }}', path, {
response = await client.call('{{ method.method | caseLower }}', apiPath, {
{% for parameter in method.parameters.header %}
'{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }},
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion templates/dart/base/requests/api.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
{{ utils.map_headers(method.headers) }}
};

final res = await client.call(HttpMethod.{{ method.method | caseLower }}, path: path, params: params, headers: headers);
final res = await client.call(HttpMethod.{{ method.method | caseLower }}, path: apiPath, params: params, headers: headers);

return {% if method.responseModel and method.responseModel != 'any' %}models.{{method.responseModel | caseUcfirst | overrideIdentifier}}.fromMap(res.data){% else %} res.data{% endif %};
2 changes: 1 addition & 1 deletion templates/dart/base/requests/file.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% endif %}
{% endfor %}
final res = await client.chunkedUpload(
path: path,
path: apiPath,
params: params,
paramName: paramName,
idParamName: idParamName,
Expand Down
2 changes: 1 addition & 1 deletion templates/dart/base/requests/location.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
{% endif %}
};

final res = await client.call(HttpMethod.{{ method.method | caseLower }}, path: path, params: params, responseType: ResponseType.bytes);
final res = await client.call(HttpMethod.{{ method.method | caseLower }}, path: apiPath, params: params, responseType: ResponseType.bytes);
return res.data;
2 changes: 1 addition & 1 deletion templates/dart/base/requests/oauth.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Uri url = Uri(scheme: endpoint.scheme,
host: endpoint.host,
port: endpoint.port,
path: endpoint.path + path,
path: endpoint.path + apiPath,
query: query.join('&')
);

Expand Down
2 changes: 1 addition & 1 deletion templates/dart/lib/services/service.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class {{ service.name | caseUcfirst }} extends Service {
{{ method.description | dartComment }}
{% endif %}
{% if method.type == 'location' %}Future<Uint8List>{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future<models.{{method.responseModel | caseUcfirst | overrideIdentifier}}>{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async {
final String path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}){% endfor %};
final String apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}){% endfor %};

{% if 'multipart/form-data' in method.consumes %}
{{ include('dart/base/requests/file.twig') }}
Expand Down
10 changes: 5 additions & 5 deletions templates/deno/src/services/service.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export class {{ service.name | caseUcfirst }} extends Service {

{% endif %}
{% endfor %}
let path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
let payload: Payload = {};
const apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
const payload: Payload = {};

{% for parameter in method.parameters.query %}
if (typeof {{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
Expand Down Expand Up @@ -110,7 +110,7 @@ export class {{ service.name | caseUcfirst }} extends Service {
{% if parameter.isUploadID %}
if({{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') {
try {
response = await this.client.call('get', path + '/' + {{ parameter.name }}, headers);
response = await this.client.call('get', apiPath + '/' + {{ parameter.name }}, headers);
chunksUploaded = response.chunksUploaded;
} catch(e) {
}
Expand Down Expand Up @@ -151,7 +151,7 @@ export class {{ service.name | caseUcfirst }} extends Service {

payload['{{ parameter.name }}'] = { type: 'file', file: new File([uploadableChunkTrimmed], {{ parameter.name | caseCamel | escapeKeyword }}.filename), filename: {{ parameter.name | caseCamel | escapeKeyword }}.filename };

response = await this.client.call('{{ method.method | caseLower }}', path, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});
response = await this.client.call('{{ method.method | caseLower }}', apiPath, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});

if (!id) {
id = response['$id'];
Expand Down Expand Up @@ -193,7 +193,7 @@ export class {{ service.name | caseUcfirst }} extends Service {
{% endif %}
{% endfor %}
{% else %}
return await this.client.call('{{ method.method | caseLower }}', path, {
return await this.client.call('{{ method.method | caseLower }}', apiPath, {
{% for parameter in method.parameters.header %}
'{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }},
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion templates/dotnet/base/requests/api.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% import 'dotnet/base/utils.twig' as utils %}
return _client.Call{% if method.type != 'webAuth' %}<{{ utils.resultType(spec.title, method) }}>{% endif %}(
method: "{{ method.method | caseUpper }}",
path: path,
path: apiPath,
headers: headers,
{%~ if not method.responseModel %}
parameters: parameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!);
Expand Down
2 changes: 1 addition & 1 deletion templates/dotnet/base/requests/file.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{%~ endfor %}

return _client.ChunkedUpload(
path,
apiPath,
headers,
parameters,
{%~ if method.responseModel %}
Expand Down
2 changes: 1 addition & 1 deletion templates/dotnet/base/requests/location.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
return _client.Call<byte[]>(
method: "{{ method.method | caseUpper }}",
path: path,
path: apiPath,
headers: headers,
parameters: parameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!);
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace {{ spec.title | caseUcfirst }}.Services
/// </summary>
public Task{% if method.type != "webAuth" %}<{{ utils.resultType(spec.title, method) }}>{% endif %} {{ method.name | caseUcfirst }}({{ utils.method_parameters(method.parameters, method.consumes) }})
{
var path = "{{ method.path }}"{% if method.parameters.path | length == 0 %};{% endif %}
var apiPath = "{{ method.path }}"{% if method.parameters.path | length == 0 %};{% endif %}

{{~ include('dotnet/base/params.twig') }}

Expand Down
2 changes: 1 addition & 1 deletion templates/flutter/base/requests/api.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
{{~ utils.map_headers(method.headers) }}
};

final res = await client.call(HttpMethod.{{ method.method | caseLower }}, path: path, params: params, headers: headers);
final res = await client.call(HttpMethod.{{ method.method | caseLower }}, path: apiPath, params: params, headers: headers);

return {% if method.responseModel and method.responseModel != 'any' %}models.{{method.responseModel | caseUcfirst | overrideIdentifier}}.fromMap(res.data){% else %} res.data{% endif %};
2 changes: 1 addition & 1 deletion templates/flutter/base/requests/file.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% endif %}
{% endfor %}
final res = await client.chunkedUpload(
path: path,
path: apiPath,
params: params,
paramName: paramName,
idParamName: idParamName,
Expand Down
2 changes: 1 addition & 1 deletion templates/flutter/base/requests/location.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
{% endif %}
};

final res = await client.call(HttpMethod.{{ method.method | caseLower }}, path: path, params: params, responseType: ResponseType.bytes);
final res = await client.call(HttpMethod.{{ method.method | caseLower }}, path: apiPath, params: params, responseType: ResponseType.bytes);
return res.data;
2 changes: 1 addition & 1 deletion templates/flutter/base/requests/oauth.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Uri url = Uri(scheme: endpoint.scheme,
host: endpoint.host,
port: endpoint.port,
path: endpoint.path + path,
path: endpoint.path + apiPath,
query: query.join('&')
);

Expand Down
2 changes: 1 addition & 1 deletion templates/flutter/lib/services/service.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class {{ service.name | caseUcfirst }} extends Service {
{{ method.description|dartComment }}
{% endif %}
{% if method.type == 'webAuth' %}Future{% elseif method.type == 'location' %}Future<Uint8List>{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future<models.{{method.responseModel | caseUcfirst | overrideIdentifier}}>{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async {
{% if method.parameters.path | length > 0 %}final{% else %}const{% endif %} String path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}){% endfor %};
{% if method.parameters.path | length > 0 %}final{% else %}const{% endif %} String apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}){% endfor %};

{% if 'multipart/form-data' in method.consumes %}
{{ include('flutter/base/requests/file.twig') }}
Expand Down
2 changes: 1 addition & 1 deletion templates/go/base/requests/api.twig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return srv.client.Call("{{ method.method | caseUpper }}", path, headers, params)
return srv.client.Call("{{ method.method | caseUpper }}", apiPath, headers, params)
4 changes: 2 additions & 2 deletions templates/go/services/service.go.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func New{{ service.name | caseUcfirst }}(clt Client) *{{ service.name | caseUcfi
func (srv *{{ service.name | caseUcfirst }}) {{ method.name | caseUcfirst }}({% if method.parameters.all|length > 0 %}{% for parameter in method.parameters.all %}{{ parameter.name | caseUcfirst }} {{ parameter | typeName }}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %}) (*ClientResponse, error) {
{% if method.parameters.path|length > 0 %}
r := strings.NewReplacer({% for parameter in method.parameters.path %}"{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}", {{ parameter.name | caseUcfirst }}{% if not loop.last %}, {% endif %}{% endfor %})
path := r.Replace("{{ method.path }}")
apiPath := r.Replace("{{ method.path }}")

{% else %}
path := "{{ method.path }}"
apiPath := "{{ method.path }}"

{% endif %}
{{include('go/base/params.twig')}}
Expand Down
2 changes: 1 addition & 1 deletion templates/kotlin/base/requests/api.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
return client.call(
"{{ method.method | caseUpper }}",
path,
apiPath,
headers,
params,
{%~ if method.responseModel | hasGenericType(spec) %}
Expand Down
2 changes: 1 addition & 1 deletion templates/kotlin/base/requests/file.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{%~ endif %}
{%~ endfor %}
return client.chunkedUpload(
path,
apiPath,
headers,
params,
responseType = {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}::class.java,
Expand Down
2 changes: 1 addition & 1 deletion templates/kotlin/base/requests/location.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
return client.call(
"{{ method.method | caseUpper }}",
path,
apiPath,
params = params,
responseType = {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}::class.java
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class {{ service.name | caseUcfirst }} : Service {
onProgress: ((UploadProgress) -> Unit)? = null
{%~ endif %}
): {{ method | returnType(spec, sdk.namespace | caseDot) | raw }} {
val path = "{{ method.path }}"
val apiPath = "{{ method.path }}"
{%~ for parameter in method.parameters.path %}
.replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }})
{%~ endfor %}
Expand Down
2 changes: 1 addition & 1 deletion templates/node/base/requests/api.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
return await this.client.call('{{ method.method | caseLower }}', path, {
return await this.client.call('{{ method.method | caseLower }}', apiPath, {
{% for parameter in method.parameters.header %}
'{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }},
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions templates/node/base/requests/file.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% if parameter.isUploadID %}
if({{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') {
try {
response = await this.client.call('get', path + '/' + {{ parameter.name }}, headers);
response = await this.client.call('get', apiPath + '/' + {{ parameter.name }}, headers);
chunksUploaded = response.chunksUploaded;
} catch(e) {
}
Expand Down Expand Up @@ -53,7 +53,7 @@
const stream = Stream.Readable.from(currentChunk);
payload['{{ parameter.name }}'] = { type: 'file', file: stream, filename: {{ parameter.name }}.filename };

response = await selfClient.call('{{ method.method | caseLower }}', path, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});
response = await selfClient.call('{{ method.method | caseLower }}', apiPath, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});

if (!id) {
id = response['$id'];
Expand Down
2 changes: 1 addition & 1 deletion templates/node/lib/services/service.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class {{ service.name | caseUcfirst }} extends Service {
* @returns {Promise}
*/
async {{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = () => {}{% endif %}) {
let path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
const apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
{{ include ('node/base/params.twig')}}
{% if 'multipart/form-data' in method.consumes %}
{{ include ('node/base/requests/file.twig')}}
Expand Down
2 changes: 1 addition & 1 deletion templates/php/base/requests/api.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
return $this->client->call(Client::METHOD_{{ method.method | caseUpper }}, $path, [
return $this->client->call(Client::METHOD_{{ method.method | caseUpper }}, $apiPath, [
{% for parameter in method.parameters.header %}
'{{ parameter.name }}' => ${{ parameter.name | caseCamel | escapeKeyword }},
{% endfor %}
Expand Down
Loading