nytimes / openapi2proto

A tool for generating Protobuf v3 schemas and gRPC service definitions from OpenAPI specifications
Apache License 2.0
964 stars 98 forks source link

Add protobuf options #64

Closed lestrrat closed 6 years ago

lestrrat commented 6 years ago

I would like to add arbitrary protobuf options to the generated file, namely go_package

option go_package = "myawesomepackage"

I can see two ways to achieve this:

1. Add an option to the command line.

openapi2proto -new_flag go_package=myawesomepackage ...

where new_flag would be replaced with the appropriate name (I was inclined to use option, but it was already taken)

2. Add an custom/extra field to the spec

I'm not an OpenAPI spec expert, but this being a rather free form text file, I'm sure there's room to add extra fields. Here I assume it's okay for us to add a top level field name x-global-options, but it could be anywhere

openapi: 2.0
x-global-options:  # made this up
   go_package: myawesomepackage
...

I'd be willing to write up a patch if we can decide on a direction to go.

lestrrat commented 6 years ago

I saw #58, and realized we were doing about the same thing, but my aim was for a global option, so renamed the field accordingly

lestrrat commented 6 years ago

@jprobinson created a PR for this. If this is acceptable, I can also work on #58 in a similar manner