Skip to content

Commit ac770be

Browse files
committed
Correct types in example values for docs
1 parent abd2c01 commit ac770be

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

src/SDK/Language/Go.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,31 +228,41 @@ public function getParamExample(array $param): string
228228
switch ($type) {
229229
case self::TYPE_NUMBER:
230230
case self::TYPE_INTEGER:
231+
$output .= '0';
232+
break;
231233
case self::TYPE_BOOLEAN:
232-
$output .= 'null';
234+
$output .= 'false';
233235
break;
234236
case self::TYPE_STRING:
235237
$output .= '""';
236238
break;
237239
case self::TYPE_OBJECT:
238-
$output .= 'nil';
240+
$output .= 'map[string]interface{}{}';
239241
break;
240242
case self::TYPE_ARRAY:
241-
$output .= '[]';
243+
$output .= '[]interface{}{}';
242244
break;
243245
case self::TYPE_FILE:
244-
$output .= 'NewInputFile("/path/to/file.png", "file.png")';
246+
$output .= 'file.NewInputFile("/path/to/file.png", "file.png")';
245247
break;
246248
}
247249
} else {
248250
switch ($type) {
249251
case self::TYPE_NUMBER:
250252
case self::TYPE_INTEGER:
251-
case self::TYPE_ARRAY:
252253
$output .= $example;
253254
break;
255+
case self::TYPE_ARRAY:
256+
if (\str_starts_with($example, '[')) {
257+
$example = \substr($example, 1);
258+
}
259+
if (\str_ends_with($example, ']')) {
260+
$example = \substr($example, 0, -1);
261+
}
262+
$output .= 'interface{}{' . $example . '}';
263+
break;
254264
case self::TYPE_OBJECT:
255-
$output .= 'nil';
265+
$output .= 'map[string]interface{}{}';
256266
break;
257267
case self::TYPE_BOOLEAN:
258268
$output .= ($example) ? 'true' : 'false';
@@ -261,7 +271,7 @@ public function getParamExample(array $param): string
261271
$output .= "\"{$example}\"";
262272
break;
263273
case self::TYPE_FILE:
264-
$output .= "file";
274+
$output .= 'file.NewInputFile("/path/to/file.png", "file.png")';
265275
break;
266276
}
267277
}

templates/go/docs/example.md.twig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ func main() {
2828

2929
{% endif %}
3030
service := {{ service.name | caseLower }}.New{{ service.name | caseUcfirst }}(client)
31-
response, error := service.{{ method.name | caseUcfirst }}({% for parameter in method.parameters.all %}{% if not loop.first %}, {% endif %}{{ parameter | paramExample }}{% endfor %})
31+
response, error := service.{{ method.name | caseUcfirst }}(
32+
{% for parameter in method.parameters.all %}
33+
{% if parameter.required %}
34+
{{ parameter | paramExample }},
35+
{% else %}
36+
{{ service.name | caseLower }}.With{{ method.name | caseUcfirst }}{{ parameter.name | caseUcfirst }}({{ parameter | paramExample }}),
37+
{% endif %}
38+
{% endfor %}
39+
)
40+
3241
if error != nil {
3342
panic(error)
3443
}

0 commit comments

Comments
 (0)