How to Export Swagger documentation in PDF and XML files
Asked Answered
U

4

21

I have generated swagger document for web api using below link: http://wmpratt.com/swagger-and-asp-net-web-api-part-1/

Need to export document in PDF or XML file to send across handy.

Its .NET WEB API.

How to export swagger documentation ?

Thanks

Unmask answered 8/11, 2017 at 14:41 Comment(1)
Possible duplicate of Web API Swagger documentation export to PDFScarface
A
19

Here's what I did today, since many of these other projects require laborious workarounds or extra libraries or some completely separate language.

  • Go to https://editor.swagger.io/ (Make sure it's the HTTPS version)
  • At the top, click File => Import File.
  • Select your Swagger JSON file.
  • At the top, click Generate Client => HTML2 and download the ZIP file.

This yields a static HTML page that you can then print (via the browser) to PDF using the built-in Microsoft Print to PDF printer, or Adobe Acrobat, or whatever else you might want to use.

Alpha answered 8/1, 2020 at 20:10 Comment(0)
G
14

You can use Swagger2Markup and AsciiDoc docker images:

docker run --rm -v $(pwd):/opt swagger2markup/swagger2markup convert -i "https://api.example.org/api/doc/swagger.json" -f /opt/swagger-doc

Creates asciidoc file named 'swagger-doc.adoc' in current folder.

docker run -it -v $(pwd):/documents/ asciidoctor/docker-asciidoctor asciidoctor-pdf swagger-doc.adoc

Creates a PDF file named 'swagger-doc.pdf' in current folder.

Giovanna answered 15/12, 2018 at 19:56 Comment(2)
FYI, this container won't install on Windows.Alpha
To copy the file from docker to local system in Windows: docker cp containername:/documents/swagger-doc.pdf swagger-doc.pdfMonosymmetric
H
2

The Swagger2Markup project is on GitHub and some more information you'll find by using Google too.

Swagger2Markup converts a Swagger JSON or YAML file into several AsciiDoc or GitHub Flavored Markdown documents which can be combined with hand-written documentation.

AsciiDoc is preferable to Markdown as it has more features. AsciiDoc is a text document format for writing documentation, articles, books, ebooks, slideshows, web pages and blogs. AsciiDoc files can be converted to HTML, PDF and EPUB. AsciiDoc is much better suited for describing public APIs than JavaDoc or Annotations.

You can generate your HTML5, PDF and EPUB documentation via asciidoctorj or even better via the asciidoctor-gradle-plugin or asciidoctor-maven-plugin.

The project requires at least JDK 8.

See also RESTful API Documentation with Swagger and AsciiDoc

Hulahula answered 8/11, 2017 at 18:47 Comment(1)
Considering the asker specifically mentioned using .NET, it's funny to think he'd install the whole JDK environment just to print a JSON file to a PDF! That's like buying a Honda to get to the auto parts store for your Ford.Alpha
D
-2

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/.

Derrick answered 4/1, 2019 at 5:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.