grpc-gateway
grpc-gateway copied to clipboard
Extend google.protobuf.EnumOptions
🚀 Feature
Extend google.protobuf.EnumOptions so we can set examples on enums.
enum State {
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_enum) = {
example: "ACTIVE"
};
NONE = 0;
ACTIVE = 1;
INACTIVE = 2;
}
Workaround: set the example on every message using the enum.
Hm, this sounds reasonable. It would require adding a new extension here: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-openapiv2/options/annotations.proto, and then weaving through the logic for parsing this value into the generator.
Can you explain a little bit more about how it can be achieved?
Hi, thanks for your interest in this issue. We'd need to add a new annotation message, similar to the existing ones in the file I linked above that already exist for other types of annotations. We'd need need to add the logic for parsing this annotation into the generator. I'd recommend just searching through the code to find how we're using one of the existing messages to find the logic that does this. Once we have this information, we can then add it to the enum generation code in the protoc-gen-openapiv2
generator. If you are unfamiliar with the code base, I suggest starting by looking at the protoc-gen-openapiv2
entrypoint and following the logic through from there: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-openapiv2/main.go
Hope that helps!
does anyone know if this feature has been added?
I need to change the default value of the enums, is there any way to do this?
I don't believe that it has been added yet.
I will work on it these days
I would love to use this feature and it appears the PR from 2022 is now stale. Any objection to me trying to get a new PR together for this? The mention shows how we can get examples displayed on enums but doesnt enable setting a common description, title or example to be used across all fields which reference your enum. So it seems like there is still value in this work?
Please feel free to start your own PR, thank you!
I will work on it these days
Sorry for the stale PR and I have closed it. It was too difficult to merge with master at that time as master had changed a lot. I thought I would make it one day but... @jai-50 please feel free to start your own PR. Thanks very much.