Skip to content

Commit c86c2db

Browse files
authored
feat(sidekick): optional singular fields in discovery (#2408)
1 parent 1d83853 commit c86c2db

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

internal/sidekick/internal/parser/discovery/discovery_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ func TestMessage(t *testing.T) {
147147
Documentation: "The full or partial URL to the default BackendService resource. Before forwarding the request to backendService, the load balancer applies any relevant headerActions specified as part of this backendServiceWeight.",
148148
Typez: api.STRING_TYPE,
149149
TypezID: "string",
150+
Optional: true,
150151
},
151152
{
152153
Name: "headerAction",
@@ -164,6 +165,7 @@ func TestMessage(t *testing.T) {
164165
Documentation: "Specifies the fraction of traffic sent to a backend service, computed as weight / (sum of all weightedBackendService weights in routeAction) . The selection of a backend service is determined only for new traffic. Once a user's request has been directed to a backend service, subsequent requests are sent to the same backend service as determined by the backend service's session affinity policy. Don't configure session affinity if you're using weighted traffic splitting. If you do, the weighted traffic splitting configuration takes precedence. The value must be from 0 to 1000.",
165166
Typez: api.UINT32_TYPE,
166167
TypezID: "uint32",
168+
Optional: true,
167169
},
168170
},
169171
}
@@ -193,6 +195,7 @@ func TestDeprecatedField(t *testing.T) {
193195
Documentation: gotField.Documentation,
194196
Typez: api.INT32_TYPE,
195197
TypezID: "int32",
198+
Optional: true,
196199
}
197200
if diff := cmp.Diff(wantField, gotField, cmpopts.IgnoreFields(api.Field{}, "Parent")); diff != "" {
198201
t.Errorf("mismatch (-want, +got):\n%s", diff)

internal/sidekick/internal/parser/discovery/enum_field_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func TestMakeEnumFields(t *testing.T) {
110110
Documentation: "The networking tier.",
111111
Typez: api.ENUM_TYPE,
112112
TypezID: ".package.Message.networkTier",
113+
Optional: true,
113114
},
114115
},
115116
}
@@ -194,6 +195,7 @@ func TestMakeEnumFieldsDeprecated(t *testing.T) {
194195
Deprecated: true,
195196
Typez: api.ENUM_TYPE,
196197
TypezID: ".package.Message.networkTier",
198+
Optional: true,
197199
},
198200
},
199201
}
@@ -299,6 +301,7 @@ func TestMakeEnumFieldsWithDeprecatedValues(t *testing.T) {
299301
Documentation: "The networking tier.",
300302
Typez: api.ENUM_TYPE,
301303
TypezID: ".package.Message.networkTier",
304+
Optional: true,
302305
},
303306
},
304307
}

internal/sidekick/internal/parser/discovery/inline_object_field_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func TestMaybeInlineObject(t *testing.T) {
7979
Documentation: "The stringField field.",
8080
Typez: api.STRING_TYPE,
8181
TypezID: "string",
82+
Optional: true,
8283
},
8384
{
8485
Name: "intField",
@@ -87,6 +88,7 @@ func TestMaybeInlineObject(t *testing.T) {
8788
Documentation: "The intField field.",
8889
Typez: api.UINT64_TYPE,
8990
TypezID: "uint64",
91+
Optional: true,
9092
},
9193
},
9294
Parent: message,
@@ -162,6 +164,7 @@ func TestArrayWithInlineObject(t *testing.T) {
162164
Documentation: "The stringField field.",
163165
Typez: api.STRING_TYPE,
164166
TypezID: "string",
167+
Optional: true,
165168
},
166169
{
167170
Name: "intField",
@@ -170,6 +173,7 @@ func TestArrayWithInlineObject(t *testing.T) {
170173
Documentation: "The intField field.",
171174
Typez: api.UINT64_TYPE,
172175
TypezID: "uint64",
176+
Optional: true,
173177
},
174178
},
175179
Parent: message,

internal/sidekick/internal/parser/discovery/message_fields.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ func makeScalarField(model *api.API, message *api.Message, name string, schema *
8181
Typez: typez,
8282
TypezID: typezID,
8383
Deprecated: schema.Deprecated,
84-
// TODO(#2270) - optional fields?
85-
Optional: typez == api.MESSAGE_TYPE,
84+
Optional: true,
8685
}, nil
8786
}
8887

internal/sidekick/internal/parser/discovery/message_fields_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func TestMakeMessageFields(t *testing.T) {
9393
Typez: api.UINT32_TYPE,
9494
TypezID: "uint32",
9595
Deprecated: true,
96+
Optional: true,
9697
},
9798
{
9899
Name: "intField",
@@ -101,6 +102,7 @@ func TestMakeMessageFields(t *testing.T) {
101102
Documentation: "The field description.",
102103
Typez: api.INT32_TYPE,
103104
TypezID: "int32",
105+
Optional: true,
104106
},
105107
{
106108
Name: "longField",
@@ -109,6 +111,7 @@ func TestMakeMessageFields(t *testing.T) {
109111
Documentation: "The field description.",
110112
Typez: api.UINT64_TYPE,
111113
TypezID: "uint64",
114+
Optional: true,
112115
},
113116
{
114117
Name: "arrayFieldString",

0 commit comments

Comments
 (0)