chrusty / protoc-gen-jsonschema

Protobuf to JSON-Schema compiler
Apache License 2.0
496 stars 101 forks source link

Move configuration parameters from jsonschema_out to jsonschema_opt #136

Closed michaelrosett closed 1 year ago

michaelrosett commented 1 year ago

In order to use bufbuild's buf generate command, the plugins.out field cannot be of the form, for example, enforce_oneof,file_extension=schema.json,disallow_additional_properties:schemas.

You README indicates you don't like this cli syntax and the good news is that protoc plugins should use the _opt suffix which would allow you to do something like the following instead. And this would work with bufbuild!

protoc \
  --plugin=${HOME}/go/bin/protoc-gen-jsonschema \
  --jsonschema_opt=enforce_oneof
  --jsonschema_opt=file_extension=schema.json \
  --jsonschema_opt=disallow_additional_properties \
  --jsonschema_out=schemas \
  --proto_path=proto
michaelrosett commented 1 year ago

In fact, this already works. Should probably recommend this syntax over comma separated jsonschema_out paramter.

chrusty commented 1 year ago

Glad it works for you. I'll update the docs. All of that option parsing is handled by the protobuf toolkit before it gets to protoc-gen-jsonschema, so it should all be fairly standard stuff.