Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you convert an OpenAPI Spec (Swagger 2.0) to proto3?

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!

like image 651
Bob Risky Avatar asked Nov 17 '18 05:11

Bob Risky


People also ask

How do I upgrade Swagger 2 to Swagger 3?

Converting to OAS 3.0 Swagger Editor has a Convert to OpenAPI 3 option under the Edit drop-down that acts as an interface to this API. All we need to do is open our document in Swagger Editor, then convert by using Edit > Convert to OpenAPI 3.

What is the difference between Swagger and OpenAPI?

Although the terms once referred to the same thing, they can no longer be used interchangeably…even though some people still do. In 2021, OpenAPI refers to the industry-standard specification for RESTful API design. Swagger refers to a set of SmartBear tools.

What are the formats supported by OpenAPI Swagger for their definitions?

Format. An OpenAPI document that conforms to the OpenAPI Specification is itself a JSON object, which may be represented either in JSON or YAML format.

What is the OpenAPI Specification format?

OpenAPI Specification (formerly Swagger Specification) is an API description format for REST APIs. An OpenAPI file allows you to describe your entire API, including: Available endpoints ( /users ) and operations on each endpoint ( GET /users , POST /users ) Operation parameters Input and output for each operation.


1 Answers

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.
like image 137
Andrija Avatar answered Oct 04 '22 19:10

Andrija