Skip to content

Commit 895dac9

Browse files
authored
fix(sidekick): mangled method names and doc links (#2565)
In documentation links we do not want to use the mangled name for each method.
1 parent e6c7297 commit 895dac9

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

internal/sidekick/internal/rust/annotate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ type messageAnnotation struct {
203203

204204
type methodAnnotation struct {
205205
Name string
206+
NameNoMangling string
206207
BuilderName string
207208
DocLines []string
208209
PathInfo *api.PathInfo
@@ -784,6 +785,7 @@ func (c *codec) annotateMethod(m *api.Method) {
784785
serviceName := c.ServiceName(m.Service)
785786
annotation := &methodAnnotation{
786787
Name: toSnake(m.Name),
788+
NameNoMangling: toSnakeNoMangling(m.Name),
787789
BuilderName: toPascal(m.Name),
788790
Body: bodyAccessor(m),
789791
DocLines: c.formatDocComments(m.Documentation, m.ID, m.Model.State, m.Service.Scopes()),

internal/sidekick/internal/rust/annotate_method_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestAnnotateMethodNames(t *testing.T) {
4444
MethodID: ".test.v1.ResourceService.move",
4545
Want: &methodAnnotation{
4646
Name: "r#move",
47+
NameNoMangling: "move",
4748
BuilderName: "Move",
4849
Body: "None::<gaxi::http::NoBody>",
4950
ServiceNameToPascal: "ResourceService",
@@ -56,6 +57,7 @@ func TestAnnotateMethodNames(t *testing.T) {
5657
MethodID: ".test.v1.ResourceService.Delete",
5758
Want: &methodAnnotation{
5859
Name: "delete",
60+
NameNoMangling: "delete",
5961
BuilderName: "Delete",
6062
Body: "None::<gaxi::http::NoBody>",
6163
ServiceNameToPascal: "ResourceService",
@@ -68,6 +70,7 @@ func TestAnnotateMethodNames(t *testing.T) {
6870
MethodID: ".test.v1.ResourceService.Self",
6971
Want: &methodAnnotation{
7072
Name: "r#self",
73+
NameNoMangling: "self",
7174
BuilderName: "r#Self",
7275
Body: "None::<gaxi::http::NoBody>",
7376
ServiceNameToPascal: "ResourceService",

internal/sidekick/internal/rust/annotate_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,11 @@ func TestServiceAnnotations(t *testing.T) {
191191
}
192192

193193
wantMethod := &methodAnnotation{
194-
Name: "get_resource",
195-
BuilderName: "GetResource",
196-
Body: "None::<gaxi::http::NoBody>",
197-
PathInfo: method.PathInfo,
194+
Name: "get_resource",
195+
NameNoMangling: "get_resource",
196+
BuilderName: "GetResource",
197+
Body: "None::<gaxi::http::NoBody>",
198+
PathInfo: method.PathInfo,
198199
SystemParameters: []systemParameter{
199200
{Name: "$alt", Value: "json;enum-encoding=int"},
200201
},
@@ -208,10 +209,11 @@ func TestServiceAnnotations(t *testing.T) {
208209
}
209210

210211
wantMethod = &methodAnnotation{
211-
Name: "delete_resource",
212-
BuilderName: "DeleteResource",
213-
Body: "None::<gaxi::http::NoBody>",
214-
PathInfo: emptyMethod.PathInfo,
212+
Name: "delete_resource",
213+
NameNoMangling: "delete_resource",
214+
BuilderName: "DeleteResource",
215+
Body: "None::<gaxi::http::NoBody>",
216+
PathInfo: emptyMethod.PathInfo,
215217
SystemParameters: []systemParameter{
216218
{Name: "$alt", Value: "json;enum-encoding=int"},
217219
},
@@ -406,7 +408,7 @@ func TestServiceAnnotationsNameOverrides(t *testing.T) {
406408
t.Errorf("mismatch in service annotations (-want, +got)\n:%s", diff)
407409
}
408410

409-
methodFilter := cmpopts.IgnoreFields(methodAnnotation{}, "Name", "BuilderName", "Body", "PathInfo", "SystemParameters", "ReturnType")
411+
methodFilter := cmpopts.IgnoreFields(methodAnnotation{}, "Name", "NameNoMangling", "BuilderName", "Body", "PathInfo", "SystemParameters", "ReturnType")
410412
wantMethod := &methodAnnotation{
411413
ServiceNameToPascal: "Renamed",
412414
ServiceNameToCamel: "renamed",

internal/sidekick/internal/rust/templates/crate/src/builder.rs.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub mod {{Codec.ModuleName}} {
7676
}
7777

7878
{{#Codec.Methods}}
79-
/// The request builder for [{{Codec.ServiceNameToPascal}}::{{Codec.Name}}][crate::client::{{Codec.ServiceNameToPascal}}::{{Codec.Name}}] calls.
79+
/// The request builder for [{{Codec.ServiceNameToPascal}}::{{Codec.NameNoMangling}}][crate::client::{{Codec.ServiceNameToPascal}}::{{Codec.NameNoMangling}}] calls.
8080
///
8181
/// # Example
8282
/// ```no_run

0 commit comments

Comments
 (0)