protobuf to openapi via cue

round tripping through cue

SEAN K.H. LIAO

protobuf to openapi via cue

round tripping through cue

proto to jsonschema / openapi

So you have message definitions declared as protocol buffers, and now you them in JSON Schema or OpenAPI format.

You could use google's protoc-gen-openapi and protoc-gen-jsonschema but I think their output is weird (multi files, no output?). There's also protoc-gen-openapiv2 but the output also looks sort of weird (not much content?).

cue

Now cue is more of its own language which can handle schema definition, validation and data configuration. But that's not too important for us: all we care is that it can import protobuf, converting it to cue, and export openapi / jsonschema from those cue definitions:

1$ cue mod init
2$ cue import example.proto
3$ cue export --out openapi .
4$ cue export --out jsonschema .

The generated schemas look fairly solid: all in one file, handles maps/oneof properly, and it can even include validation like regex/pattern (with cue specific field options, def in cue.proto).