Skip to content

Commit 00c645f

Browse files
authored
fix(sidekick): Map field attribute in discovery (#2414)
1 parent 0d0642d commit 00c645f

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

internal/sidekick/internal/parser/discovery/map_field.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func maybeMapOfObjectField(model *api.API, message *api.Message, input *property
5151
Typez: api.MESSAGE_TYPE,
5252
TypezID: typezID,
5353
Deprecated: input.Schema.Deprecated,
54+
Map: true,
5455
}
5556
return field
5657
}
@@ -72,6 +73,7 @@ func maybeMapOfEnumField(model *api.API, message *api.Message, input *property)
7273
Typez: api.MESSAGE_TYPE,
7374
TypezID: typezID,
7475
Deprecated: input.Schema.Deprecated,
76+
Map: true,
7577
}
7678
return field, nil
7779
}
@@ -90,6 +92,7 @@ func maybeMapOfPrimitiveField(model *api.API, message *api.Message, input *prope
9092
Typez: api.MESSAGE_TYPE,
9193
TypezID: typezID,
9294
Deprecated: input.Schema.Deprecated,
95+
Map: true,
9396
}
9497
return field, nil
9598
}

internal/sidekick/internal/parser/discovery/map_field_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"testing"
2020

2121
"github.com/google/go-cmp/cmp"
22+
"github.com/google/go-cmp/cmp/cmpopts"
2223
"github.com/googleapis/librarian/internal/sidekick/internal/api"
2324
"github.com/googleapis/librarian/internal/sidekick/internal/api/apitest"
2425
)
@@ -57,6 +58,7 @@ func TestMapFields(t *testing.T) {
5758
Deprecated: true,
5859
Typez: api.MESSAGE_TYPE,
5960
TypezID: "$map<string, string>",
61+
Map: true,
6062
},
6163
},
6264
}
@@ -125,6 +127,7 @@ func TestMapFieldWithObjectValues(t *testing.T) {
125127
Deprecated: true,
126128
Typez: api.MESSAGE_TYPE,
127129
TypezID: "$map<string, .package.SomeOtherMessage>",
130+
Map: true,
128131
},
129132
},
130133
}
@@ -200,6 +203,7 @@ func TestMapFieldWithEnumValues(t *testing.T) {
200203
Deprecated: true,
201204
Typez: api.MESSAGE_TYPE,
202205
TypezID: "$map<string, .package.Message.enumMapField>",
206+
Map: true,
203207
},
204208
},
205209
}
@@ -290,9 +294,9 @@ func TestMapScalarTypes(t *testing.T) {
290294
input := &schema{
291295
Properties: []*property{
292296
{
293-
Name: "enumMapField",
297+
Name: "mapField",
294298
Schema: &schema{
295-
Description: "The description for enumMapField.",
299+
Description: "The description for mapField.",
296300
Type: "object",
297301
AdditionalProperties: &schema{
298302
Type: test.Type,
@@ -307,8 +311,18 @@ func TestMapScalarTypes(t *testing.T) {
307311
t.Error(err)
308312
continue
309313
}
310-
if len(message.Fields) != 1 {
311-
t.Errorf("expected exactly one field, got=%v", message.Fields)
314+
wantFields := []*api.Field{
315+
{
316+
Name: "mapField",
317+
JSONName: "mapField",
318+
ID: ".package.Message.mapField",
319+
Documentation: "The description for mapField.",
320+
Typez: api.MESSAGE_TYPE,
321+
Map: true,
322+
},
323+
}
324+
if diff := cmp.Diff(wantFields, message.Fields, cmpopts.IgnoreFields(api.Field{}, "TypezID")); diff != "" {
325+
t.Errorf("mismatch (-want, +got):\n%s", diff)
312326
continue
313327
}
314328
mapMessage, ok := model.State.MessageByID[message.Fields[0].TypezID]

0 commit comments

Comments
 (0)