Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
encoding/protobuf: don't make oneOf required by default
Browse files Browse the repository at this point in the history
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 <mpvl@golang.org>
  • Loading branch information
mpvl committed Jul 1, 2019
1 parent 065bfd4 commit ffe4ced
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
3 changes: 1 addition & 2 deletions encoding/protobuf/parse.go
Expand Up @@ -644,8 +644,7 @@ func (p *protoConverter) oneOf(x *proto.Oneof) {
}
switch x := v.(type) {
case *proto.OneOfField:
f := p.parseField(s, 0, x.Field)
f.Optional = token.NoPos
p.parseField(s, 0, x.Field)

default:
p.messageField(s, 1, v)
Expand Down
16 changes: 8 additions & 8 deletions encoding/protobuf/testdata/attributes.proto.out.cue
Expand Up @@ -62,28 +62,28 @@ Attributes_AttributeValue: {
// The attribute value.
Attributes_AttributeValue: {
// Used for values of type STRING, DNS_NAME, EMAIL_ADDRESS, and URI
stringValue: string @protobuf(2,name=string_value)
stringValue?: string @protobuf(2,name=string_value)
} | {
// Used for values of type INT64
int64Value: int64 @protobuf(3,name=int64_value)
int64Value?: int64 @protobuf(3,name=int64_value)
} | {
// Used for values of type DOUBLE
doubleValue: float64 @protobuf(4,type=double,name=double_value)
doubleValue?: float64 @protobuf(4,type=double,name=double_value)
} | {
// Used for values of type BOOL
boolValue: bool @protobuf(5,name=bool_value)
boolValue?: bool @protobuf(5,name=bool_value)
} | {
// Used for values of type BYTES
bytesValue: bytes @protobuf(6,name=bytes_value)
bytesValue?: bytes @protobuf(6,name=bytes_value)
} | {
// Used for values of type TIMESTAMP
timestampValue: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
timestampValue?: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
} | {
// Used for values of type DURATION
durationValue: time.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
durationValue?: time.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
} | {
// Used for values of type STRING_MAP
stringMapValue: Attributes_StringMap @protobuf(9,type=StringMap,name=string_map_value)
stringMapValue?: Attributes_StringMap @protobuf(9,type=StringMap,name=string_map_value)
}

// Defines a string map.
Expand Down
Expand Up @@ -62,28 +62,28 @@ Attributes_AttributeValue: {
// The attribute value.
Attributes_AttributeValue: {
// Used for values of type STRING, DNS_NAME, EMAIL_ADDRESS, and URI
stringValue: string @protobuf(2,name=string_value)
stringValue?: string @protobuf(2,name=string_value)
} | {
// Used for values of type INT64
int64Value: int64 @protobuf(3,name=int64_value)
int64Value?: int64 @protobuf(3,name=int64_value)
} | {
// Used for values of type DOUBLE
doubleValue: float64 @protobuf(4,type=double,name=double_value)
doubleValue?: float64 @protobuf(4,type=double,name=double_value)
} | {
// Used for values of type BOOL
boolValue: bool @protobuf(5,name=bool_value)
boolValue?: bool @protobuf(5,name=bool_value)
} | {
// Used for values of type BYTES
bytesValue: bytes @protobuf(6,name=bytes_value)
bytesValue?: bytes @protobuf(6,name=bytes_value)
} | {
// Used for values of type TIMESTAMP
timestampValue: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
timestampValue?: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
} | {
// Used for values of type DURATION
durationValue: time.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
durationValue?: time.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
} | {
// Used for values of type STRING_MAP
stringMapValue: Attributes_StringMap @protobuf(9,type=StringMap,name=string_map_value)
stringMapValue?: Attributes_StringMap @protobuf(9,type=StringMap,name=string_map_value)
}

// Defines a string map.
Expand Down
Expand Up @@ -126,7 +126,7 @@ HTTPAPISpecPattern: {
// /dictionary/{term:1}/{term}
// /search{?q*,lang}
//
uriTemplate: string @protobuf(3,name=uri_template)
uriTemplate?: string @protobuf(3,name=uri_template)
} | {
// EXPERIMENTAL:
//
Expand All @@ -136,7 +136,7 @@ HTTPAPISpecPattern: {
//
// "^/pets/(.*?)?"
//
regex: string @protobuf(4)
regex?: string @protobuf(4)
}

// APIKey defines the explicit configuration for generating the
Expand All @@ -155,7 +155,7 @@ APIKey: {
//
// GET /something?api_key=abcdef12345
//
query: string @protobuf(1)
query?: string @protobuf(1)
} | {
// API key is sent in a request header. `header` represents the
// header name.
Expand All @@ -166,7 +166,7 @@ APIKey: {
// GET /something HTTP/1.1
// X-API-Key: abcdef12345
//
header: string @protobuf(2)
header?: string @protobuf(2)
} | {
// API key is sent in a
// [cookie](https://swagger.io/docs/specification/authentication/cookie-authentication),
Expand All @@ -177,7 +177,7 @@ APIKey: {
// GET /something HTTP/1.1
// Cookie: X-API-KEY=abcdef12345
//
cookie: string @protobuf(3)
cookie?: string @protobuf(3)
}

// HTTPAPISpecReference defines a reference to an HTTPAPISpec. This is
Expand Down
Expand Up @@ -76,13 +76,13 @@ StringMatch: {
}
StringMatch: {
// exact string match
exact: string @protobuf(1)
exact?: string @protobuf(1)
} | {
// prefix-based match
prefix: string @protobuf(2)
prefix?: string @protobuf(2)
} | {
// ECMAscript style regex-based match
regex: string @protobuf(3)
regex?: string @protobuf(3)
}

// Specifies a match clause to match Istio attributes
Expand Down

0 comments on commit ffe4ced

Please sign in to comment.