Generate static docs with swagger
Is there a method for creating static documentation for swagger 2.0? Perhaps like the 'preview' on editor.swagger.io.
I need to get static html files so I can include them in some static documents.
So far I've not found a way to do this. I see there is swagger-codegens static-docs but this only works for swagger <= 1.2.
Use swagger-codegen:
swagger-codegen generate -i <path to your swagger file> -l html2 -o <path to output location>
If you decide to customize the HTML template:
- Clone the swagger-codegen project from github
- Copy
modules/swagger-codegen/src/main/resources/htmlDocs2
folder to another place, for example:cp -R modules/swagger-codegen/src/main/resources/htmlDocs2 ~/templates
- Modify the
.mustache
templates in~/templates
to fit your requirements. - Run:
swagger-codegen generate -i <path to your swagger file> -l html2 -o <path to output location> -t <templates path>
for<templates path>
should be~/templates
in the example above.
If you'd just like to generate static docs in a straightforward way, consider Spectacle.
npm install spectacle-docs
if you want to put a script in your package.json
, or npm install -g spectacle-docs
if it should be available everywhere.
Then you can just run spectacle spec.yaml
, with options to build to a specific directory, run a server, and/or watch the specfile and update as needed.
The static-docs in 2.0 is implemented for 2.0. see the ./bin/static-docs.sh here:
https://github.com/swagger-api/swagger-codegen/tree/master/bin