nytimes / openapi2proto

A tool for generating Protobuf v3 schemas and gRPC service definitions from OpenAPI specifications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for protobuf custom options

HenrikLindholm86 opened this issue · comments

Protobuf supports creation of custom options but unfortunately the openApi2Proto don't support this.
It would be great if you could use the openapi extension pattern to define custom options, maybe something like x-option-name: value

Extensions in OpenApi
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#specificationExtensions

CustomOptions in protobuf
https://developers.google.com/protocol-buffers/docs/proto#customoptions

I'm afraid I'm a bit unfamiliar with how custom options and extensions integrate into protobuf v3.

If you can come up with a good example of how you'd like it to look, I think this would be an interesting add.

Sure!
I have added a example yaml and a corresponding proto on how I would like it too look.
Please feel free to give feedback
Basically my idea is that you for each method (post/get/etc) can specify an x-options object which must contain an extends field that specifies which message to extend. after that you could specify your custom fields and it's values.
The extend in the resulting proto should only occur once for each message extended, so it should contain the union of all fields specified for that message, as shown in the example proto.

test_yaml.txt
test_proto.txt

This looks good to me!

Feel free to start working on a PR.

Notes:

option values

Looks like options can actually be any value, but I guess we can for now limit ourselves to accepting either a scalar option or a hash option. I'll need to update the global options accordingly

the -options flag

Looking at the code, it looks like it would make it much easier to implement this if -options flag were to simply add a generated custom option to each endpoint.