Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend google.protobuf.EnumOptions #2671

Closed
garthk opened this issue May 2, 2022 · 9 comments · Fixed by #4931
Closed

Extend google.protobuf.EnumOptions #2671

garthk opened this issue May 2, 2022 · 9 comments · Fixed by #4931

Comments

@garthk
Copy link

garthk commented May 2, 2022

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

@johanbrandhorst
Copy link
Collaborator

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.

@SaumyaBhushan
Copy link

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

@johanbrandhorst
Copy link
Collaborator

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!

@LucasDGS
Copy link

LucasDGS commented Jun 22, 2022

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?

@johanbrandhorst
Copy link
Collaborator

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

@MakDon
Copy link
Contributor

MakDon commented Aug 4, 2022

I will work on it these days

@jai-50
Copy link

jai-50 commented Mar 7, 2024

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?

@johanbrandhorst
Copy link
Collaborator

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

@MakDon
Copy link
Contributor

MakDon commented Mar 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants