grpc-gateway icon indicating copy to clipboard operation
grpc-gateway copied to clipboard

Extend google.protobuf.EnumOptions

Open garthk opened this issue 2 years ago • 9 comments

🚀 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.

garthk avatar May 02 '22 01:05 garthk

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.

johanbrandhorst avatar May 05 '22 01:05 johanbrandhorst

Can you explain a little bit more about how it can be achieved?

SaumyaBhushan avatar Jun 17 '22 11:06 SaumyaBhushan

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!

johanbrandhorst avatar Jun 22 '22 00:06 johanbrandhorst

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?

LucasDGS avatar Jun 22 '22 23:06 LucasDGS

I don't believe that it has been added yet.

johanbrandhorst avatar Jun 23 '22 03:06 johanbrandhorst

I will work on it these days

MakDon avatar Aug 04 '22 12:08 MakDon

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?

jai-50 avatar Mar 07 '24 16:03 jai-50

Please feel free to start your own PR, thank you!

johanbrandhorst avatar Mar 07 '24 16:03 johanbrandhorst

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.

MakDon avatar Mar 08 '24 08:03 MakDon