Skip to content

Commit ffe4ced

Browse files
committed
encoding/protobuf: don't make oneOf required by default
This often makes sense to do, but it shouldn't be the default. Issue #5 Change-Id: I9f05ac9ee8a770489e7885da9c82790f091aee8b Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2372 Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 065bfd4 commit ffe4ced

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

encoding/protobuf/parse.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,7 @@ func (p *protoConverter) oneOf(x *proto.Oneof) {
644644
}
645645
switch x := v.(type) {
646646
case *proto.OneOfField:
647-
f := p.parseField(s, 0, x.Field)
648-
f.Optional = token.NoPos
647+
p.parseField(s, 0, x.Field)
649648

650649
default:
651650
p.messageField(s, 1, v)

encoding/protobuf/testdata/attributes.proto.out.cue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,28 @@ Attributes_AttributeValue: {
6262
// The attribute value.
6363
Attributes_AttributeValue: {
6464
// Used for values of type STRING, DNS_NAME, EMAIL_ADDRESS, and URI
65-
stringValue: string @protobuf(2,name=string_value)
65+
stringValue?: string @protobuf(2,name=string_value)
6666
} | {
6767
// Used for values of type INT64
68-
int64Value: int64 @protobuf(3,name=int64_value)
68+
int64Value?: int64 @protobuf(3,name=int64_value)
6969
} | {
7070
// Used for values of type DOUBLE
71-
doubleValue: float64 @protobuf(4,type=double,name=double_value)
71+
doubleValue?: float64 @protobuf(4,type=double,name=double_value)
7272
} | {
7373
// Used for values of type BOOL
74-
boolValue: bool @protobuf(5,name=bool_value)
74+
boolValue?: bool @protobuf(5,name=bool_value)
7575
} | {
7676
// Used for values of type BYTES
77-
bytesValue: bytes @protobuf(6,name=bytes_value)
77+
bytesValue?: bytes @protobuf(6,name=bytes_value)
7878
} | {
7979
// Used for values of type TIMESTAMP
80-
timestampValue: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
80+
timestampValue?: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
8181
} | {
8282
// Used for values of type DURATION
83-
durationValue: time.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
83+
durationValue?: time.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
8484
} | {
8585
// Used for values of type STRING_MAP
86-
stringMapValue: Attributes_StringMap @protobuf(9,type=StringMap,name=string_map_value)
86+
stringMapValue?: Attributes_StringMap @protobuf(9,type=StringMap,name=string_map_value)
8787
}
8888

8989
// Defines a string map.

encoding/protobuf/testdata/istio.io/api/mixer/v1/attributes_proto_gen.cue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,28 @@ Attributes_AttributeValue: {
6262
// The attribute value.
6363
Attributes_AttributeValue: {
6464
// Used for values of type STRING, DNS_NAME, EMAIL_ADDRESS, and URI
65-
stringValue: string @protobuf(2,name=string_value)
65+
stringValue?: string @protobuf(2,name=string_value)
6666
} | {
6767
// Used for values of type INT64
68-
int64Value: int64 @protobuf(3,name=int64_value)
68+
int64Value?: int64 @protobuf(3,name=int64_value)
6969
} | {
7070
// Used for values of type DOUBLE
71-
doubleValue: float64 @protobuf(4,type=double,name=double_value)
71+
doubleValue?: float64 @protobuf(4,type=double,name=double_value)
7272
} | {
7373
// Used for values of type BOOL
74-
boolValue: bool @protobuf(5,name=bool_value)
74+
boolValue?: bool @protobuf(5,name=bool_value)
7575
} | {
7676
// Used for values of type BYTES
77-
bytesValue: bytes @protobuf(6,name=bytes_value)
77+
bytesValue?: bytes @protobuf(6,name=bytes_value)
7878
} | {
7979
// Used for values of type TIMESTAMP
80-
timestampValue: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
80+
timestampValue?: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
8181
} | {
8282
// Used for values of type DURATION
83-
durationValue: time.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
83+
durationValue?: time.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
8484
} | {
8585
// Used for values of type STRING_MAP
86-
stringMapValue: Attributes_StringMap @protobuf(9,type=StringMap,name=string_map_value)
86+
stringMapValue?: Attributes_StringMap @protobuf(9,type=StringMap,name=string_map_value)
8787
}
8888

8989
// Defines a string map.

encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/api_spec_proto_gen.cue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ HTTPAPISpecPattern: {
126126
// /dictionary/{term:1}/{term}
127127
// /search{?q*,lang}
128128
//
129-
uriTemplate: string @protobuf(3,name=uri_template)
129+
uriTemplate?: string @protobuf(3,name=uri_template)
130130
} | {
131131
// EXPERIMENTAL:
132132
//
@@ -136,7 +136,7 @@ HTTPAPISpecPattern: {
136136
//
137137
// "^/pets/(.*?)?"
138138
//
139-
regex: string @protobuf(4)
139+
regex?: string @protobuf(4)
140140
}
141141

142142
// APIKey defines the explicit configuration for generating the
@@ -155,7 +155,7 @@ APIKey: {
155155
//
156156
// GET /something?api_key=abcdef12345
157157
//
158-
query: string @protobuf(1)
158+
query?: string @protobuf(1)
159159
} | {
160160
// API key is sent in a request header. `header` represents the
161161
// header name.
@@ -166,7 +166,7 @@ APIKey: {
166166
// GET /something HTTP/1.1
167167
// X-API-Key: abcdef12345
168168
//
169-
header: string @protobuf(2)
169+
header?: string @protobuf(2)
170170
} | {
171171
// API key is sent in a
172172
// [cookie](https://swagger.io/docs/specification/authentication/cookie-authentication),
@@ -177,7 +177,7 @@ APIKey: {
177177
// GET /something HTTP/1.1
178178
// Cookie: X-API-KEY=abcdef12345
179179
//
180-
cookie: string @protobuf(3)
180+
cookie?: string @protobuf(3)
181181
}
182182

183183
// HTTPAPISpecReference defines a reference to an HTTPAPISpec. This is

encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/quota_proto_gen.cue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ StringMatch: {
7676
}
7777
StringMatch: {
7878
// exact string match
79-
exact: string @protobuf(1)
79+
exact?: string @protobuf(1)
8080
} | {
8181
// prefix-based match
82-
prefix: string @protobuf(2)
82+
prefix?: string @protobuf(2)
8383
} | {
8484
// ECMAscript style regex-based match
85-
regex: string @protobuf(3)
85+
regex?: string @protobuf(3)
8686
}
8787

8888
// Specifies a match clause to match Istio attributes

0 commit comments

Comments
 (0)