OpenAPI 3
For rendering an OpenAPI 3 specification into self-contained HTML file, redoc-cli can be used. You can use ReDoc's Petstore OpenAPI 3 spec as example.
mkdir -p -m 777 build && docker run --rm --user 1000 \
-v $PWD/build:/tmp/build -w /tmp/build \
-v $PWD/openapi.yaml:/tmp/openapi.yaml node:14-slim npx -q \
redoc-cli bundle /tmp/openapi.yaml
This will generate build/redoc-static.html
in your current directory.
To avoid waiting for installation, you can also build yourself a Docker image with redoc-cli
according to their Dockerfile
, or installing redoc-cli
to your OS, if you have NodeJS there, with npm install -g redoc-cli
.
Update: there's actually a pre-built Docker image in the project's GitHub Docker registry, e.g. ghcr.io/redocly/redoc/cli:v2.0.0-rc.76
.
OpenAPI 2
ReDoc also has compatibility mode for OpenAPI 2/Swagger, so the above also works for Petstore OpenAPI 2 spec.
[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0
Alternatively, the there's OpenAPI 2-only Spectacle and its official Docker image. It can be used similarly like:
mkdir -p -m 777 build && docker run --rm --user 1000 \
-v $PWD/build:/tmp/build \
-v $PWD/swagger.yaml:/tmp/swagger.yaml sourcey/spectacle \
spectacle -t /tmp/build /tmp/swagger.yaml
It generates static build which is almost self-contained (except loading jQuery from code.jquery.com
which was slow for some reason on my end).
├── index.html
├── javascripts
│ ├── spectacle.js
│ └── spectacle.min.js
└── stylesheets
├── foundation.css
├── foundation.min.css
├── spectacle.css
└── spectacle.min.css