encoding/protobuf: proper encoding of oneOf
OneOf fields are 0 or 1 of the fields, not exactly one.
Change-Id: I1d95a511d0882ca14661471b32b515d743e770ff
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5342
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/testdata/script/def_proto.txt b/cmd/cue/cmd/testdata/script/def_proto.txt
index 7708745..407b568 100644
--- a/cmd/cue/cmd/testdata/script/def_proto.txt
+++ b/cmd/cue/cmd/testdata/script/def_proto.txt
@@ -20,7 +20,7 @@
}
// The attribute value.
-Attributes_AttributeValue :: {
+Attributes_AttributeValue :: {} | {
stringValue: string @protobuf(2,name=string_value)
} | {
int64Value: int64 @protobuf(3,name=int64_value)
diff --git a/encoding/protobuf/parse.go b/encoding/protobuf/parse.go
index e77db1f..c59f3f1 100644
--- a/encoding/protobuf/parse.go
+++ b/encoding/protobuf/parse.go
@@ -484,7 +484,7 @@
s := &ast.StructLit{
Lbrace: p.toCUEPos(v.Position),
- // TOOD: set proto file position.
+ // TODO: set proto file position.
Rbrace: token.Newline.Pos(),
}
@@ -677,11 +677,7 @@
func (p *protoConverter) oneOf(x *proto.Oneof) {
f := &ast.Field{
Label: p.ref(x.Position),
- // TODO: Once we have closed structs, a oneOf is represented as a
- // disjunction of empty structs and closed structs with required fields.
- // For now we just specify the required fields. This is not correct
- // but more practical.
- // Value: &ast.StructLit{}, // Remove to make at least one required.
+ Value: &ast.StructLit{},
Token: token.ISA,
}
f.AddComment(comment(x.Comment, true))
diff --git a/encoding/protobuf/testdata/attributes.proto.out.cue b/encoding/protobuf/testdata/attributes.proto.out.cue
index dacadf7..bd16fa0 100644
--- a/encoding/protobuf/testdata/attributes.proto.out.cue
+++ b/encoding/protobuf/testdata/attributes.proto.out.cue
@@ -58,7 +58,7 @@
}
// The attribute value.
-Attributes_AttributeValue :: {
+Attributes_AttributeValue :: {} | {
// Used for values of type STRING, DNS_NAME, EMAIL_ADDRESS, and URI
stringValue: string @protobuf(2,name=string_value)
} | {
diff --git a/encoding/protobuf/testdata/istio.io/api/mixer/v1/attributes_proto_gen.cue b/encoding/protobuf/testdata/istio.io/api/mixer/v1/attributes_proto_gen.cue
index dacadf7..bd16fa0 100644
--- a/encoding/protobuf/testdata/istio.io/api/mixer/v1/attributes_proto_gen.cue
+++ b/encoding/protobuf/testdata/istio.io/api/mixer/v1/attributes_proto_gen.cue
@@ -58,7 +58,7 @@
}
// The attribute value.
-Attributes_AttributeValue :: {
+Attributes_AttributeValue :: {} | {
// Used for values of type STRING, DNS_NAME, EMAIL_ADDRESS, and URI
stringValue: string @protobuf(2,name=string_value)
} | {
diff --git a/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/api_spec_proto_gen.cue b/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/api_spec_proto_gen.cue
index 3e6c50e..09bd763 100644
--- a/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/api_spec_proto_gen.cue
+++ b/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/api_spec_proto_gen.cue
@@ -116,7 +116,7 @@
// example: GET, HEAD, POST, PUT, DELETE.
httpMethod?: string @protobuf(2,name=http_method)
}
-HTTPAPISpecPattern :: {
+HTTPAPISpecPattern :: {} | {
// URI template to match against as defined by
// [rfc6570](https://tools.ietf.org/html/rfc6570). For example, the
// following are valid URI templates:
@@ -146,7 +146,7 @@
// for a general overview of API keys as defined by OpenAPI.
APIKey :: {
}
-APIKey :: {
+APIKey :: {} | {
// API Key is sent as a query parameter. `query` represents the
// query string parameter name.
//
diff --git a/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/quota_proto_gen.cue b/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/quota_proto_gen.cue
index 6f02c1f..c02e3b3 100644
--- a/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/quota_proto_gen.cue
+++ b/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/quota_proto_gen.cue
@@ -74,7 +74,7 @@
// case-sensitive.
StringMatch :: {
}
-StringMatch :: {
+StringMatch :: {} | {
// exact string match
exact: string @protobuf(1)
} | {