Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a static html file from a swagger documentation?

Tags:

I have created a Swagger documentation with a yaml file under:

api/swagger/swagger.yaml 

Now I want to share a static HTML document with its definition, yet it was stated on the swagger project, that they don't plan to support HTML generation at all.

How can I generate a static HTML file from a Swagger project?

like image 844
k0pernikus Avatar asked Nov 03 '16 16:11

k0pernikus


2 Answers

The easiest way I can think of is to use Swagger Editor:

  1. Go to: https://editor.swagger.io
  2. Click on "File" in the top menu bar and then select "Import File"
  3. After import, click on "Generate Client" in the top menu bar, and then select "HTML" or "HTML2" to generate static HTML documentation

editor.swagger.io uses generator.swagger.io to generate API clients, server stubs and documentation, and generator.swagger.io is powered by the open-source project Swagger Codegen.

like image 102
William Cheng Avatar answered Sep 16 '22 17:09

William Cheng


  1. Download https://github.com/swagger-api/swagger-ui - folder of interest is "dist"
  2. Copy your Swagger JSON into the dist folder
  3. Open index.html and change the value of URL inside the tag at the bottom of the file to ./swagger.json (or whatever your swagger json is called) (see here)
  4. Host online! (or start a local server to view output).
like image 30
Ismail Moghul Avatar answered Sep 20 '22 17:09

Ismail Moghul