Skip to content

Commit dcb6e6c

Browse files
authored
feat(sidekick/swift): improve snippet body (#6434)
Make the body more readable by using a single `.with{}` call for all the fields. For AIP-standard `Create*()` and `Update*()` requests we can show how the body field is initialized.
1 parent e7222b1 commit dcb6e6c

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎internal/sidekick/swift/templates/snippet/method_request_body.mustache‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,27 @@ limitations under the License.
2424
}}
2525
{{InputType.Codec.Name}}()
2626
{{#SampleInfo}}
27+
.with {
2728
{{#IsRequestResourceName}}
28-
.with { $0.{{Codec.Name}} = "{{Codec.FormatString}}" }
29+
$0.{{Codec.Name}} = "{{Codec.FormatString}}"
2930
{{/IsRequestResourceName}}
31+
{{#ResourceIDField}}
32+
$0.{{Codec.Name}} = "[replace with a valid ID]"
33+
{{/ResourceIDField}}
3034
{{#IsMessageResourceName}}
31-
.with {
3235
$0.{{MessageField.Codec.Name}} = {{MessageField.Codec.BaseFieldType}}().with {
3336
$0.{{Codec.Name}} = "{{Codec.FormatString}}"
3437
}
35-
}
38+
{{/IsMessageResourceName}}
39+
{{^IsMessageResourceName}}
40+
{{#MessageField}}
41+
$0.{{Codec.Name}} = {{Codec.BaseFieldType}}() /* .with { ... } */
42+
{{/MessageField}}
3643
{{/IsMessageResourceName}}
3744
{{#UpdateMaskField}}
38-
.with { $0.{{Codec.Name}} = {{Service.Codec.Model.WktPackage}}.FieldMask(paths: ["field.path1", "field.path2"]) }
45+
$0.{{Codec.Name}} = {{Service.Codec.Model.WktPackage}}.FieldMask(paths: ["field.path1", "field.path2"])
3946
{{/UpdateMaskField}}
47+
}
4048
{{/SampleInfo}}
4149
{{^SampleInfo}}
4250
/* set fields using .with { $0... } */

0 commit comments

Comments
 (0)