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 shadowed parameters #703

Merged
merged 3 commits into from
Aug 31, 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 @@ -58,7 +58,7 @@ class {{ service.name | caseUcfirst }} : Service {
.replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }})
{%~ endfor %}

val params = mutableMapOf<String, Any?>(
val apiParams = mutableMapOf<String, Any?>(
{%~ for parameter in method.parameters.query | merge(method.parameters.body) %}
"{{ parameter.name }}" to {{ parameter.name | caseCamel }},
{%~ endfor %}
Expand All @@ -73,25 +73,25 @@ class {{ service.name | caseUcfirst }} : Service {
{%~ endif %}
)
{%~ if method.type == 'webAuth' %}
val query = mutableListOf<String>()
params.forEach {
val apiQuery = mutableListOf<String>()
apiParams.forEach {
when (it.value) {
null -> {
return@forEach
}
is List<*> -> {
query.add("${it.key}[]=${it.value.toString()}")
apiQuery.add("${it.key}[]=${it.value.toString()}")
}
else -> {
query.add("${it.key}=${it.value.toString()}")
apiQuery.add("${it.key}=${it.value.toString()}")
}
}
}

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

WebAuthComponent.authenticate(activity, url, callbackUrlScheme) {
WebAuthComponent.authenticate(activity, apiUrl, callbackUrlScheme) {
if (it.isFailure) {
throw it.exceptionOrNull()!!
}
Expand Down Expand Up @@ -119,11 +119,11 @@ class {{ service.name | caseUcfirst }} : Service {
return client.call(
"{{ method.method | caseUpper }}",
apiPath,
params = params,
params = apiParams,
responseType = {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}::class.java
)
{%~ else %}
val headers = mutableMapOf(
val apiHeaders = mutableMapOf(
{%~ for key, header in method.headers %}
"{{ key }}" to "{{ header }}",
{%~ endfor %}
Expand All @@ -147,8 +147,8 @@ class {{ service.name | caseUcfirst }} : Service {
{%~ endfor %}
return client.chunkedUpload(
apiPath,
headers,
params,
apiHeaders,
apiParams,
responseType = {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}::class.java,
{%~ if method.responseModel %}
converter,
Expand All @@ -161,8 +161,8 @@ class {{ service.name | caseUcfirst }} : Service {
return client.call(
"{{ method.method | caseUpper }}",
apiPath,
headers,
params,
apiHeaders,
apiParams,
{%~ if method.responseModel | hasGenericType(spec) %}
responseType = classOf(),
{%~ else %}
Expand Down
10 changes: 5 additions & 5 deletions templates/cli/lib/commands/command.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
let counter = 0;
const totalCounters = Math.ceil(size / libClient.CHUNK_SIZE);

const headers = {
const apiHeaders = {
{% for parameter in method.parameters.header %}
'{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }},
{% endfor %}
Expand All @@ -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', apiPath + '/' + {{ parameter.name }}, headers);
response = await client.call('get', apiPath + '/' + {{ parameter.name }}, apiHeaders);
counter = response.chunksUploaded;
} catch(e) {
}
Expand All @@ -166,10 +166,10 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
const start = (counter * libClient.CHUNK_SIZE);
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);

headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;

if (id) {
headers['x-appwrite-id'] = id;
apiHeaders['x-appwrite-id'] = id;
}

const stream = fs.createReadStream(streamFilePath, {
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 }}', apiPath, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});
response = await client.call('{{ method.method | caseLower }}', apiPath, apiHeaders, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});

if (!id) {
id = response['$id'];
Expand Down
4 changes: 2 additions & 2 deletions templates/dart/base/requests/api.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% import 'dart/base/utils.twig' as utils %}
final Map<String, dynamic> params = {
final Map<String, dynamic> apiParams = {
{{ utils.map_parameter(method.parameters.query) }}
{{ utils.map_parameter(method.parameters.body) }}
};
Expand All @@ -8,6 +8,6 @@
{{ utils.map_headers(method.headers) }}
};

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

return {% if method.responseModel and method.responseModel != 'any' %}models.{{method.responseModel | caseUcfirst | overrideIdentifier}}.fromMap(res.data){% else %} res.data{% endif %};
4 changes: 2 additions & 2 deletions templates/dart/base/requests/file.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% import 'dart/base/utils.twig' as utils %}
final Map<String, dynamic> params = {
final Map<String, dynamic> apiParams = {
{{ utils.map_parameter(method.parameters.query) }}
{{ utils.map_parameter(method.parameters.body) }}
};
Expand All @@ -20,7 +20,7 @@
{% endfor %}
final res = await client.chunkedUpload(
path: apiPath,
params: params,
params: apiParams,
paramName: paramName,
idParamName: idParamName,
headers: apiHeaders,
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 @@ -92,7 +92,7 @@ export class {{ service.name | caseUcfirst }} extends Service {

const size = {{ parameter.name | caseCamel | escapeKeyword }}.size;

const headers: { [header: string]: string } = {
const apiHeaders: { [header: string]: string } = {
{% for parameter in method.parameters.header %}
'{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }},
{% endfor %}
Expand All @@ -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', apiPath + '/' + {{ parameter.name }}, headers);
response = await this.client.call('get', apiPath + '/' + {{ parameter.name }}, apiHeaders);
chunksUploaded = response.chunksUploaded;
} catch(e) {
}
Expand All @@ -131,7 +131,7 @@ export class {{ service.name | caseUcfirst }} extends Service {
const end = start + currentPosition;

if(!lastUpload || currentChunk !== 1) {
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
}

let uploadableChunkTrimmed: Uint8Array;
Expand All @@ -146,12 +146,12 @@ export class {{ service.name | caseUcfirst }} extends Service {
}

if (id) {
headers['x-{{spec.title | caseLower }}-id'] = id;
apiHeaders['x-{{spec.title | caseLower }}-id'] = id;
}

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 }}', apiPath, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});
response = await this.client.call('{{ method.method | caseLower }}', apiPath, apiHeaders, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});

if (!id) {
id = response['$id'];
Expand Down
2 changes: 1 addition & 1 deletion templates/dotnet/base/params.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{%~ endfor %}

var parameters = new Dictionary<string, object?>()
var apiParameters = new Dictionary<string, object?>()
{
{%~ for parameter in method.parameters.query | merge(method.parameters.body) %}
{ "{{ parameter.name }}", {{ utils.map_parameter(parameter) }} }{% if not loop.last %},{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions templates/dotnet/base/requests/api.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
path: apiPath,
headers: apiHeaders,
{%~ if not method.responseModel %}
parameters: parameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!);
parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!);
{%~ else %}
parameters: parameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!,
parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!,
convert: Convert);
{%~ endif %}
2 changes: 1 addition & 1 deletion templates/dotnet/base/requests/location.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
method: "{{ method.method | caseUpper }}",
path: apiPath,
headers: apiHeaders,
parameters: parameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!);
parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!);
4 changes: 2 additions & 2 deletions templates/flutter/base/requests/api.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% import 'flutter/base/utils.twig' as utils %}
final Map<String, dynamic> params = {
final Map<String, dynamic> apiParams = {
{{- utils.map_parameter(method.parameters.query) -}}
{{~ utils.map_parameter(method.parameters.body) }}
};
Expand All @@ -8,6 +8,6 @@
{{~ utils.map_headers(method.headers) }}
};

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

return {% if method.responseModel and method.responseModel != 'any' %}models.{{method.responseModel | caseUcfirst | overrideIdentifier}}.fromMap(res.data){% else %} res.data{% endif %};
4 changes: 2 additions & 2 deletions templates/flutter/base/requests/file.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% import 'flutter/base/utils.twig' as utils %}
final Map<String, dynamic> params = {
final Map<String, dynamic> apiParams = {
{{~ utils.map_parameter(method.parameters.query) }}
{{~ utils.map_parameter(method.parameters.body) }}
};
Expand All @@ -20,7 +20,7 @@
{% endfor %}
final res = await client.chunkedUpload(
path: apiPath,
params: params,
params: apiParams,
paramName: paramName,
idParamName: idParamName,
headers: apiHeaders,
Expand Down
4 changes: 2 additions & 2 deletions templates/go/base/params.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
params := map[string]interface{}{
apiParams := map[string]interface{}{
{% for parameter in method.parameters.query %}
"{{ parameter.name }}": {{ parameter.name | caseUcfirst }},
{% endfor %}
Expand All @@ -7,7 +7,7 @@
{% endfor %}
}

headers := map[string]interface{}{
apiHeaders := map[string]interface{}{
{% for key, header in method.headers %}
"{{ key }}": "{{ header }}",
{% endfor %}
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 }}", apiPath, headers, params)
return srv.client.Call("{{ method.method | caseUpper }}", apiPath, apiHeaders, apiParams)
4 changes: 2 additions & 2 deletions templates/kotlin/base/requests/api.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
return client.call(
"{{ method.method | caseUpper }}",
apiPath,
headers,
params,
apiHeaders,
apiParams,
{%~ if method.responseModel | hasGenericType(spec) %}
responseType = classOf(),
{%~ else %}
Expand Down
4 changes: 2 additions & 2 deletions templates/kotlin/base/requests/file.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
{%~ endfor %}
return client.chunkedUpload(
apiPath,
headers,
params,
apiHeaders,
apiParams,
responseType = {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}::class.java,
{%~ if method.responseModel %}
converter,
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 }}",
apiPath,
params = params,
params = apiParams,
responseType = {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}::class.java
)
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ class {{ service.name | caseUcfirst }} : Service {
.replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }})
{%~ endfor %}

val params = mutableMapOf<String, Any?>(
val apiParams = mutableMapOf<String, Any?>(
{%~ for parameter in method.parameters.query | merge(method.parameters.body) %}
"{{ parameter.name }}" to {{ parameter.name | caseCamel }},
{%~ endfor %}
)
{%~ if method.type == 'location' %}
{{~ include('kotlin/base/requests/location.twig') }}
{%~ else %}
val headers = mutableMapOf(
val apiHeaders = mutableMapOf(
{%~ for key, header in method.headers %}
"{{ key }}" to "{{ header }}",
{%~ endfor %}
Expand Down
10 changes: 5 additions & 5 deletions templates/node/base/requests/file.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% if parameter.type == 'file' %}
const size = {{ parameter.name | caseCamel | escapeKeyword }}.size;

const headers = {
const apiHeaders = {
{% for parameter in method.parameters.header %}
'{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }},
{% endfor %}
Expand All @@ -20,7 +20,7 @@
{% if parameter.isUploadID %}
if({{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') {
try {
response = await this.client.call('get', apiPath + '/' + {{ parameter.name }}, headers);
response = await this.client.call('get', apiPath + '/' + {{ parameter.name }}, apiHeaders);
chunksUploaded = response.chunksUploaded;
} catch(e) {
}
Expand All @@ -43,17 +43,17 @@
const end = Math.min(((start + client.CHUNK_SIZE) - 1), size);

if(!lastUpload || currentChunkStart !== 0) {
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
}

if (id) {
headers['x-{{spec.title | caseLower }}-id'] = id;
apiHeaders['x-{{spec.title | caseLower }}-id'] = id;
}

const stream = Stream.Readable.from(currentChunk);
payload['{{ parameter.name }}'] = { type: 'file', file: stream, filename: {{ parameter.name }}.filename };

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

if (!id) {
id = response['$id'];
Expand Down
8 changes: 4 additions & 4 deletions templates/php/base/params.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$params = [];
$apiParams = [];
{% if method.parameters.all | length %}
{% for parameter in method.parameters.all %}
{% if parameter.required and not parameter.nullable %}
Expand All @@ -9,19 +9,19 @@
{% endfor %}
{% for parameter in method.parameters.query %}
if (!is_null(${{ parameter.name | caseCamel | escapeKeyword }})) {
$params['{{ parameter.name }}'] = ${{ parameter.name | caseCamel | escapeKeyword }};
$apiParams['{{ parameter.name }}'] = ${{ parameter.name | caseCamel | escapeKeyword }};
}

{% endfor %}
{% for parameter in method.parameters.body %}
if (!is_null(${{ parameter.name | caseCamel | escapeKeyword }})) {
$params['{{ parameter.name }}'] = ${{ parameter.name | caseCamel | escapeKeyword }};
$apiParams['{{ parameter.name }}'] = ${{ parameter.name | caseCamel | escapeKeyword }};
}

{% endfor %}
{% for parameter in method.parameters.formData %}
if (!is_null(${{ parameter.name | caseCamel | escapeKeyword }})) {
$params['{{ parameter.name }}'] = ${{ parameter.name | caseCamel | escapeKeyword }};
$apiParams['{{ parameter.name }}'] = ${{ parameter.name | caseCamel | escapeKeyword }};
}
{% endfor %}
{% endif %}
2 changes: 1 addition & 1 deletion templates/php/base/requests/api.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
{% for key, header in method.headers %}
'{{ key }}' => '{{ header }}',
{% endfor %}
], $params);
], $apiParams);
Loading