Skip to content

Instantly share code, notes, and snippets.

@theletterf
Created April 21, 2021 07:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theletterf/951897825d4c10d2e9078bbf60d89983 to your computer and use it in GitHub Desktop.
Save theletterf/951897825d4c10d2e9078bbf60d89983 to your computer and use it in GitHub Desktop.
# Takes the OpenAPI file
Param(
[parameter(mandatory=$true)][string]$file
)
$name = [System.IO.Path]::GetFileNameWithoutExtension($file)
# Converts OpenAPI to Markdown documentation
npm install -g widdershins
widdershins $file --search false --expandBody --summary -o markdown.md
# Converts Widdershin's markdown output to HTML, then to DocBook5
pandoc markdown.md -f markdown+raw_html -t html -o html.html
pandoc html.html -f html -t docbook5 -o docbook5.xml
# Injects required tags
'<?xml version="1.0" encoding="UTF-8"?><article xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en"><info><title>OpenAPI Import</title></info>' + (Get-Content docbook5.xml -Raw) | Set-Content docbook5.xml
Add-Content -Path docbook5.xml -Value '</article>'
# Compress the file
Compress-Archive -Path docbook5.xml -DestinationPath import.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment