- Install npm dependencies
npm install
- Edit your documentation file under
./src
folder - Validate your changes with
swagger-cli
(see below) - Watch HTML version live with
redoc-cli
(see below) - Commit your changes to the repo
./node_modules/.bin/redoc-cli serve -w src/...yourfile.yaml
To be sure that the produced specification is valid, you can quickly run this command:
./node_modules/.bin/swagger-cli validate src/...yourfile.yaml
You can work on different files and then prepare a single distributable spec which combines other specs.
Sample of the template:
openapi: 3.0.2
info:
title: Admin API
version: 0.0.1
contact:
name: Dmitry Lezhnev
url: /
email: [email protected]
paths:
# Use this file to set a list of files to merge in
- $ref: "./loyalty/vip.yaml"
- $ref: "./brands/alerts.yaml"
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: string
Now to resolve dependencies and prepare a single file, use:
scripts/run.php merge template.yaml merged.yaml
After that you can create a distributable HTML file by reusing a template src/template.html
:
cp ./output.merged.yaml ./public
- copy merged file to a public foldercp ./src/template.html ./public/index.html
- copy a template to the same foldersed -i '' -e 's/%%PAGE_TITLE%%/TITLE/g' index.html
- replace the page title in the copied template toTITLE
sed -i '' -e 's/%%OPENAPI_SPEC_JSON%%/merged.yaml/g' index.html
- set the link to openapi spec to a new merged filemerged.yaml
That's it. Now you can allow public access to the index.html
file.