Skip to content

Commit 54a1fea

Browse files
committed
chore: copy over the logic to other sdks
1 parent f7a3a33 commit 54a1fea

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/SDK/Language/ReactNative.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function getFiles(): array
128128
* @param array $nestedTypes
129129
* @return string
130130
*/
131-
public function getTypeName(array $parameter, array $spec = []): string
131+
public function getTypeName(array $parameter, array $method = []): string
132132
{
133133
if (isset($parameter['enumName'])) {
134134
return \ucfirst($parameter['enumName']);
@@ -151,6 +151,22 @@ public function getTypeName(array $parameter, array $spec = []): string
151151
return 'string[]';
152152
case self::TYPE_FILE:
153153
return '{name: string, type: string, size: number, uri: string}';
154+
case self::TYPE_OBJECT:
155+
if (empty($method)) {
156+
return $parameter['type'];
157+
}
158+
switch ($method['responseModel']) {
159+
case 'user':
160+
return "Partial<Preferences>";
161+
case 'document':
162+
if ($method['method'] === 'post') {
163+
return "Document extends Models.DefaultDocument ? Partial<Models.Document> & Record<string, any> : Partial<Models.Document> & Omit<Document, keyof Models.Document>";
164+
}
165+
if ($method['method'] === 'patch' || $method['method'] === 'put') {
166+
return "Document extends Models.DefaultDocument ? Partial<Models.Document> & Record<string, any> : Partial<Models.Document> & Partial<Omit<Document, keyof Models.Document>>";
167+
}
168+
}
169+
break;
154170
}
155171

156172
return $parameter['type'];

templates/node/src/services/template.ts.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ export class {{ service.name | caseUcfirst }} {
9999
}
100100
{%~ endif %}
101101
{%~ endfor %}
102+
{%~ for parameter in method.parameters.all %}
103+
{%~ if parameter.type == 'object' %}
104+
{%~ for attribute in parameter | getReadOnlyProperties(method.responseModel, spec) %}
105+
delete {{ parameter.name | caseCamel | escapeKeyword }}?.{{ attribute }};
106+
{%~ endfor %}
107+
{%~ endif %}
108+
{%~ endfor %}
109+
102110
const apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel | escapeKeyword }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
103111
const payload: Payload = {};
104112
{%~ for parameter in method.parameters.query %}

templates/react-native/src/services/template.ts.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ export class {{ service.name | caseUcfirst }} extends Service {
5656
throw new {{spec.title | caseUcfirst}}Exception('Missing required parameter: "{{ parameter.name | caseCamel | escapeKeyword }}"');
5757
}
5858

59+
{% endif %}
60+
{% endfor %}
61+
{% for parameter in method.parameters.all %}
62+
{% if parameter.type == 'object' %}
63+
{% for attribute in parameter | getReadOnlyProperties(method.responseModel, spec) %}
64+
delete {{ parameter.name | caseCamel | escapeKeyword }}?.{{ attribute }};
65+
{% endfor %}
5966
{% endif %}
6067
{% endfor %}
6168
const apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel | escapeKeyword }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};

templates/web/src/services/template.ts.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export class {{ service.name | caseUcfirst }} {
100100
}
101101
{%~ endif %}
102102
{%~ endfor %}
103-
104103
{%~ for parameter in method.parameters.all %}
105104
{%~ if parameter.type == 'object' %}
106105
{%~ for attribute in parameter | getReadOnlyProperties(method.responseModel, spec) %}

0 commit comments

Comments
 (0)