widdershins
repository·main·Indexed 23 days ago
https://github.com/mermade/widdershinsA tool that converts OpenAPI (Swagger), AsyncAPI, and Semoasa definitions into Markdown compatible with documentation renderers such as Slate, ReSlate, Shins, or as HTML for ReSpec. It provides both a command-line interface and a JavaScript API for Node.js applications, allowing for programmatic conversion and integration into build pipelines. Widdershins supports customizable templates using doT.js and offers configuration options for language tabs, search settings, and Table of Contents generation.
What's inside widdershins
- Widdershins is a tool used in API documentation pipelines to convert API definitions (OpenAPI 3.x, OpenAPI 2.0/Swagger, API Blueprint, AsyncAPI, or Semoasa) into Markdown. This Markdown is designed to be rendered by tools like Slate, ReSlate, or Shins, or as HTML for ReSpec.
Customize Widdershins templates
mainBy default, Widdershins uses internal templates located in its
templates/folder. To customize the Markdown output, copy the templates (including.dotfiles and.defpartials) to a local directory and provide the path to this directory using theuser_templatesparameter in your configuration.Important Considerations:
- To override a
.dottemplate, you must also copy any child.defpartials it references. - To override a
.defpartial, you must also copy the parent.dottemplate. - For OpenAPI 3, the primary template is
main.dotand its main child partials areparameters.def,responses.def, andcallbacks.def. - It is recommended to copy all
.dotand.deffiles to your user templates directory to avoid missing dependencies. - Use a visual
difftool (like Meld or WinMerge) to merge changes from Widdershins updates into your custom templates.
- To override a
Structure Semoasa v1 documents for Table of Contents (TOC) generation
mainIn Semoasa v1, thenamespaceandextensionproperty keys are used to generate the Table of Contents entries.Convert OpenAPI/Swagger files using the Widdershins CLI
mainYou can convert a valid OpenAPI 3.0 or Swagger 2.0 file to Markdown using the
widdershinscommand. You must specify the input file and the output file using the-ooption. You can pass configuration options directly as CLI flags or via an environment file.widdershins --environment env.json swagger.json -o myOutput.mdConvert OpenAPI files using the Widdershins JavaScript API
mainFor programmatic conversion within a Node.js application, use the Widdershins JavaScript API. This allows you to integrate OpenAPI to Markdown conversion directly into your build pipelines or tools.Structure OpenAPI/Swagger documents for Table of Contents (TOC) generation
mainWiddershins uses the top-level
tagsobject in an OpenAPI/Swagger specification to generate the primary entries in the Table of Contents.To create a hierarchical TOC:
- First Level: Define entries using the
tagsobject. Ensure eachoperationlinks to a tag. - Second Level: Provide a concise
operationIdfor each operation to generate the second level of TOC entries.
Note: If an operation contains multiple tags, Widdershins will only use the first tag to prevent duplicate information in the TOC.
- First Level: Define entries using the
Install Widdershins CLI via npm
mainTo use Widdershins from the command line in any folder, install it globally using npm. Ensure you have NodeJS and NPM installed on your system first.
npm install -g widdershinsInstall Widdershins via NPM
mainTo use Widdershins as a dependency in a Node.js project, first initialize your project with
npm initto create apackage.jsonfile. Then, install thewiddershinspackage from the root folder of your project using the following command:npm install --save widdershinsStructure input API documents for Table of Contents (TOC) generation
mainTo ensure Widdershins generates a proper Table of Contents (TOC) in the output Markdown, you must structure your input API documents according to specific Markdown patterns. Follow the TOC structure guide to optimize how endpoints and sections are indexed.Install Widdershins
mainYou can install Widdershins by either cloning the git repository and running
npm ito install dependencies, or by installing it globally via npm.npm install -g widdershinsConvert OpenAPI files using the Widdershins CLI
mainYou can convert Swagger/OpenAPI 2 or OpenAPI 3 files to Markdown using the Widdershins command-line interface. Refer to the CLI guide for specific command syntax and flag usage.Run the Widdershins test suite
mainTo run the internal test suite, use the
node testRunnercommand followed by the path to the APIs you wish to test.The test harness expects
.yamlor.jsonfiles.node testRunner {path-to-APIs}