Generate enum with values when using protoc-gen-openapi
Thanks for this helpful tool.
I come across this issue when I'm using protoc-gen-openapi plugin to generate OpenAPI3 specification from protobuf definition.
I have a State type and fields of State type are marked with enum format.
enum State {
state1 = 0;
state2 = 1;
state3 = 2;
}
state:
type: integer
format: enum
However, for enum in OpenAPI3 should be
state:
type: integer
enum:
- 0
- 1
- 2
Is there any feature that we can configure to generate enum schema?
https://github.com/google/gnostic/blob/418d86c152e3f607fa625e9aca135091e574811f/cmd/protoc-gen-openapi/main.go#L34
I checked the source code and found that this feature is already supported, but I don't know how to pass this parameter to the protoc command to make it work, hope it helps. And I tested it in the buf plugin and it works, the result is as follows
direction:
description: actually it is lowercase string
enum:
- DIRECTION_UNSPECIFIED
- FORWARD
- BACKWARD
- LEFT
- RIGHT
format: enum
type: string
You can pass the following option to protoc to enable string-based enums:
--openapi_opt=enum_type=string
@Hangzhi / @timburks I think this issue can be closed now.