If you’re already using Protobuf, you have a schema that describes your messages and services. Protobuf is best known for generating types, clients, and server stubs for many different programming languages, but its plugin system can produce much, much more, like documentation and translations of your schema into other formats. Today I’ll cover two of those formats: JSON Schema and OpenAPI. Both let you extend your original Protobuf schema into new places.

Two plugins make this possible: Buf’s protoc-gen-jsonschema and protoc-gen-connect-openapi, a community plugin that I wrote and maintain. Let’s look at what they produce and how to add them to a project.

The example schema

We’ll use a small inventory service with a few Protovalidate rules. A product has a SKU with a particular format, a name between 2 and 100 characters long, a nonnegative quantity, and a unit price as a decimal string.