Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a PDF or markup from OpenAPI 3.0?

I have an OpenAPI 3.0 spec and I want to generate a PDF out of it so that it can be given to the end users.

Currently, tools like swagger-spec-to-pdf or swagger2markup only support Swagger 2.0 but not OpenAPI 3.0. Is it possible to generate a PDF from an OpenAPI 3.0 spec without converting it to Swagger 2.0?

like image 378
Niranjan Avatar asked Jan 18 '19 18:01

Niranjan


People also ask

Can you export Swagger documentation?

Their is no such tool or functionality to export swagger documentation into PDF or any other doc. You need to convert your swagger. json file to yaml file then u can get swagger as html doc form http://editor.swagger.io/.

How do I create a Swagger report?

For me the easiest solution was to import swagger (v2) into Postman and then go to the web view. There you can choose "single column" view and use the browser to print to pdf. Not a automated/integrated solution but good for single-use.

Does OpenAPI generate code?

As the name suggests, the OpenAPI Generator generates code from an OpenAPI specification. It can create code for client libraries, server stubs, documentation and configuration. It supports various languages and frameworks.


2 Answers

A possible solution is to convert your OpenAPI 3.0 definition to an HTML doc, then use a browser's "Save to PDF" feature to convert HTML to PDF.

Follow these steps:

  1. Go to https://editor.swagger.io.
  2. Paste your OpenAPI 3.0 YAML/JSON definition.
  3. Select Generate Client > html.
  4. Download & unzip the file.
  5. Open the index.html page in a browser, e.g. Chrome.
  6. Select File > Print, change the Destination to Save as PDF, and save the page.
like image 76
Helen Avatar answered Sep 27 '22 21:09

Helen


I just found RapiPDF which is able to generate PDF from OpenAPI 3.0 definition.

But it still isn't an ideal tool I'm looking for. I found these limitations so far:

  • No CLI, runs only in browser. So I can't use it in an automate pipeline.
  • Callback is not supported
  • No example in generated document
like image 23
aleung Avatar answered Sep 27 '22 21:09

aleung