Enumerations #
Before you can use enums in muSpecs, make sure that you define the globs in your
.furo
file.
1 2 3 4
muSpec: enums: # define a set of globs which matches your type definitions - "./muspecs/**/*enums.yaml" - "./muspecs/*enums.yaml"
If you want to use enums with grpc-gateway and the furo-web components, do not forget to set the MarshalOption
UseEnumNumbers: true,
.Read mor about customizing your gateway here.
customized marshaller
1 2 3 4 5 6 7 8 9 10 11 12
gwruntime.WithMarshalerOption(gwruntime.MIMEWildcard, &marshaller.HTTPBodyMarshaler{ Marshaler: &gwruntime.JSONPb{ MarshalOptions: protojson.MarshalOptions{ UseProtoNames: true, EmitUnpopulated: false, UseEnumNumbers: true, }, UnmarshalOptions: protojson.UnmarshalOptions{ DiscardUnknown: true, }, }, }),
Define enums in µSpec #
You can define multiple enums in a µSpec enum file.
It is possible to set the target:
to a file which contains messages. It is not possible to mix them with service protos.
|
|
sample.enums.yaml
As you can see, the Corpus enum’s first constant maps to zero: every enum definition must contain a constant that maps to zero as its first element. This is needed for the compatibility with protobuf.
Define enums in specs #
|
|
sample.enum.spec
Resulting proto file #
|
|
enum.proto
Enum in ES6Module (web client) #
Because js does not have enums,
the fields with a enum type are generated as uint32 with an optionlist in the meta.
The
furo-ui5-select
component can handle this metas.