### Install Widdershins CLI Source: https://mermade.github.io/widdershins/ConvertingFilesBasicCLI.html Install the Widdershins package globally using NPM to enable command-line access. ```bash npm install -g widdershins ``` -------------------------------- ### Configure Widdershins Options Source: https://mermade.github.io/widdershins/ConvertingFilesBasicJS.html Set up an options object to customize Widdershins' behavior. Use the JavaScript parameter names as specified in the README.md file. This example configures language tabs for code samples. ```javascript const options = { language_tabs: [{ python: "Python" }, { ruby: "Ruby" }] }; ``` -------------------------------- ### Install Widdershins with NPM Source: https://mermade.github.io/widdershins/ConvertingFilesBasicJS.html Add Widdershins as a project dependency using NPM. This command should be run from the root folder of your project, which contains the package.json file. ```bash npm install --save widdershins ``` -------------------------------- ### Convert OpenAPI File via CLI Source: https://mermade.github.io/widdershins/ConvertingFilesBasicCLI.html Execute the conversion process by specifying an environment configuration file, the input definition, and the output filename. ```bash widdershins --environment env.json swagger.json -o myOutput.md ``` -------------------------------- ### Configure Widdershins Environment Source: https://mermade.github.io/widdershins/ConvertingFilesBasicCLI.html Define conversion options in a JSON file to reuse settings across multiple runs. ```json { "language_tabs": [{ "python": "Python" }, { "ruby": "Ruby" }] } ``` -------------------------------- ### Run JavaScript Conversion Program Source: https://mermade.github.io/widdershins/ConvertingFilesBasicJS.html Execute the created JavaScript file using NodeJS to perform the conversion from an OpenAPI/Swagger file to Markdown. This command assumes your JavaScript file is named 'convertMarkdown.js'. ```bash node convertMarkdown.js ``` -------------------------------- ### Complete JavaScript Program for Markdown Conversion Source: https://mermade.github.io/widdershins/ConvertingFilesBasicJS.html This is a complete JavaScript program that imports Widdershins, reads a swagger.json file, converts it to Markdown with specified options, and writes the output to myOutput.md. It includes error handling for the conversion process. ```javascript const widdershins = require('widdershins'); const fs = require('fs'); const options = { language_tabs: [{ python: "Python" }, { ruby: "Ruby" }] }; const fileData = fs.readFileSync('swagger.json', 'utf8'); const swaggerFile = JSON.parse(fileData); widdershins.convert(swaggerFile, options) .then(markdownOutput => { // markdownOutput contains the converted markdown fs.writeFileSync('myOutput.md', markdownOutput, 'utf8'); }) .catch(err => { // handle errors }); ``` -------------------------------- ### Convert OpenAPI/Swagger to Markdown with Promise Source: https://mermade.github.io/widdershins/ConvertingFilesBasicJS.html Utilize the Widdershins convert function, which returns a Promise, to transform the parsed API definition into Markdown. Handle potential errors using .catch(). ```javascript widdershins.convert(swaggerFile, options) .then(markdownOutput => { // markdownOutput contains the converted markdown }) .catch(err => { // handle errors }); ``` -------------------------------- ### Read and Parse OpenAPI/Swagger File Source: https://mermade.github.io/widdershins/ConvertingFilesBasicJS.html Use NodeJS built-in modules 'fs' and 'JSON' to read the content of an OpenAPI or Swagger file and parse it into a JavaScript object. Ensure the file is UTF-8 encoded. ```javascript const fs = require('fs'); const fileData = fs.readFileSync('swagger.json', 'utf8'); const swaggerFile = JSON.parse(fileData); ``` -------------------------------- ### Import Widdershins in JavaScript Source: https://mermade.github.io/widdershins/ConvertingFilesBasicJS.html Import the Widdershins library into your JavaScript program to enable its conversion functionality. This is the first step in using Widdershins programmatically. ```javascript const widdershins = require('widdershins'); ``` -------------------------------- ### Write Markdown Output to File Source: https://mermade.github.io/widdershins/ConvertingFilesBasicJS.html After Widdershins successfully converts the API definition, write the resulting Markdown content to a specified file using NodeJS 'fs.writeFileSync'. This ensures the converted Markdown is saved. ```javascript widdershins.convert(swaggerFile, options) .then(markdownOutput => { // markdownOutput contains the converted markdown fs.writeFileSync('myOutput.md', markdownOutput, 'utf8'); }) .catch(err => { // handle errors }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.