14

I've done extensive Google searching but couldn't find a good tool to do this. The closest I could find was https://github.com/googleapis/gnostic, which allows converting an OpenAPI description (swagger.yaml) into a .pb file or a .json file. I'm wondering if there are any tools to convert this .pb file into a .proto proto3 file?

I also tried https://github.com/NYTimes/openapi2proto but unfortunately there are a few cases that aren't handled correctly.

Thanks in advance for your help!

Bob Risky
  • 805
  • 1
  • 9
  • 22

1 Answers1

6

I know this question is old, but I was wandering the same and it seems that things have changed in meantime. So I will post an answer for others, lazy enough to search :)

Currently there are several options to convert OpenApi 2/3 to Protobuf:

  • OpenAPITools/openapi-generator supports this from version 4.1.2, find more here.
  • googleapis/gnostic can do this as well, find more here.
  • nytimes/openapi2proto a tool written in go for this, find more here.
  • maybe some more...? add if i missed any.
Andrija
  • 367
  • 3
  • 14
  • How to be sure that generated protobuf fields will have the same numbers after adding/deleting some fields from OpenApi file? – gshilin Jun 07 '23 at 11:22
  • 1
    I guess - only by testing! If you do not trust lib authors enough, you have to write your won tests to prove that it works just as you expect :) – Andrija Jul 05 '23 at 12:52