Youāve written an OpenAPI spec. Now you need it as Markdown so it fits into your documentation site, whether thatās Sphinx, Docusaurus, or MkDocs.
Widdershins converts OpenAPI to Markdown. Hereās how to use it.
Prerequisites
Have a valid OpenAPI document.
Have Node.js installed on your computer.
Have basic command-line knowledge.
Whatās Widdershins?
Widdershins is the open-source command-line tool weāll use to convert the OpenAPI document to MarkDown. By default, Widdershins outputs MarkDown compatible with renderers such as Slate, ReSlate, and Shins.
Its template system lets us adapt the output to make it compatible with other static site generators such as Sphinx, Docusaurus or Mkdocs.
Installing Widdershins
Widdershins can be installed with NPM. In the command prompt, run the following command:
npm install -g widdershinsAfter installation, verify it by running widdershins --version in the command prompt.
Parsing OpenAPI to Markdown
Once Widdershins is installed, run the following command in the console prompt:
widdershins openapi.yaml -o openapi.mdReplace openapi.yaml with the path to your OpenAPI file in YAML or JSON.
The command stores the resulting Markdown file as openapi.md.
Customizing the output with flags
Widdershins comes with other built-in options to configure the output. For example, the option omitHeader removes the YAML front-matter in the generated Markdown file.
š Check out the complete list of available options in the official docs.
In this example, weāre running the command from the previous step with the new option omitHeader:
widdershins openapi.yaml -o openapi.md --omitHeaderUsing custom-defined templates
Suppose you want to change the outputās format, but you canāt achieve the level of customization you are looking for by just tweaking Widdershins CLIās options. In this case, we overrode the template Widdershins uses with a custom template.
Hereās how:
Create a new directory named
.widdershins. Inside, create a second folder namedtemplates.
mkdir -p .widdershins/templates
cd .widdershins/templatesDownload main.dot into the folder you just created.
curl https://raw.githubusercontent.com/Mermade/widdershins/master/templates/openapi3/main.dot > main.dotEdit
main.dotwith your favorite code editor. The template engine Widdershins uses is doT.js. This enables you to access any variable from the OpenAPI description, even vendor extensions or nested fields.
In my experience, getting started with the template engine can be tricky. Hereās a cheatsheet with the delimiters I use most often to render and iterate through variables:
Evaluate
{{ var enums = []; }} // Executes the JavaScript code between the curly braces.{{=a}} // Renders the contents of the variable a
{{=a.b}} // Renders the contents of the nested variable a.bConditional
{{? a }} hello {{?}} // If a is true, prints āhelloā.
{{? !a }} hello {{?}} // If a is false, prints āhelloā.
{{? a || b }} hello {{?}} // If a or b is true, prints āhelloā.
{{? a && b }} hello {{?}} // If a and b is true, prints āhelloā.Iteration
{{~ alist:a}} {{= a }} {{~}} // Iterates throught alist and prints every element.Run the Widdershins CLI. In this case, add the option
-uwith the path to.widdershins/templates:
widdershins openapi.yaml -o openapi.md -u ./widdershins/templatesNext steps
Once the conversion works, it can run in your CI/CD pipeline whenever the OpenAPI spec changes.
For large API specs, the generated Markdown can get unwieldy. Itās worth post-processing the output to split it by endpoint or resource so the navigation stays manageable.
From there, configure your static site generator to render the generated Markdown with proper styling and navigation.
I write about documentation systems, developer experience, and technical writing. Get new posts by email


