{switch} with a protobuf oneof field?
pcj opened this issue · comments
Paul Cody Johnston commented
A proto message definition with a oneof field:
message Foo {
oneof content {
Bar bar = 1;
Baz baz = 2;
}
}
Generates a method:
/**
* @enum {number}
*/
proto.mypackage.Foo.ContentCase = {
CONTENT_NOT_SET: 0,
BAR: 1,
BAZ: 2,
};
/**
* @return {mypackage.Foo.ContentCase}
*/
proto.mypackage.prototype.getContentCase = function() {
return /** @type {proto.mypackage.Foo.ContentCase} */(jspb.Message.computeOneofCase(this, proto.mypackage.Foo.oneofGroups_[0]));
};
So I was expecting I might be able to:
{template .Foo}
{@param foo: mypackage.Foo}
{switch $foo.contentCase}
{case mypackage.Foo.BAR}
...
{default}
...
{/switch}
{/template}
But that did not seem to work. Any pointers? Are oneofs supported?
error: Undefined field 'contentCase' for proto type mypackage.Foo.
{switch $foo.contentCase}
^
Same outcome for {switch $foo.content}
...
Luke Sandberg commented
There is no way to access the case field currently. you can access the oneof fields though, so the best option is to test each field for nullness using a set of if conditions.
We do want to add this feature but have not had the resources to do so.
Paul Cody Johnston commented
OK thanks. I didn't think of the workaround, that should work fine.