Convert Swagger Docs to Markdown and Confluence with Swagger2Markup

This tutorial explains how to use the open‑source Swagger2Markup library to transform Swagger/OpenAPI specifications into Markdown or Confluence markup by adjusting a single Java configuration, includes code examples, output structure, single‑file options, and deployment tips for static sites and Confluence.

Programmer DD
Programmer DD
Programmer DD
Convert Swagger Docs to Markdown and Confluence with Swagger2Markup

Swagger2Markup Overview

Swagger2Markup is an open‑source Java library that converts Swagger/OpenAPI specifications into several documentation formats such as AsciiDoc, Markdown and Confluence markup, making it easy to publish static API docs.

Generating Markdown and Confluence

Both formats are produced by adjusting a single configuration property. The withMarkupLanguage method selects the target format and toFolder defines the output directory.

Java code for Markdown

Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
    .withMarkupLanguage(MarkupLanguage.MARKDOWN)
    .build();

Swagger2MarkupConverter.from(new URL("http://localhost:8080/v2/api-docs"))
    .withConfig(config)
    .build()
    .toFolder(Paths.get("src/docs/markdown/generated"));

Java code for Confluence

Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
    .withMarkupLanguage(MarkupLanguage.CONFLUENCE_MARKUP)
    .build();

Swagger2MarkupConverter.from(new URL("http://localhost:8080/v2/api-docs"))
    .withConfig(config)
    .build()
    .toFolder(Paths.get("src/docs/confluence/generated"));

After execution the src/docs directory contains separate sub‑folders for Markdown and Confluence, each with generated files such as definitions.md, overview.md, paths.md, security.md (or the corresponding .txt files for Confluence).

Single‑File Output

If a single consolidated file is preferred, replace the toFolder(...) call with toFile(Paths.get("src/docs/asciidoc/generated/all")). The converter will write all sections into one file, which can later be transformed into a single HTML page.

Static Deployment

Markdown output can be served with any static site generator (e.g., Hexo, Jekyll). For Confluence, copy the generated .txt content into a Confluence page using the {} markup macro and the “ConfluenceWiki” insert option, as shown in the screenshots.

Confluence Insertion Steps

Open a new Confluence page and click the {} markup button.

Choose “Insert → ConfluenceWiki”.

Paste the generated text into the left pane; the rendered view appears on the right.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaAPI documentationSwaggermarkdownstatic siteConfluenceSwagger2Markup
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.