Oh okay, I think I found a way to generate an HTML file. I'm not really familiar with Swagger Codegen, but I found this wrapper: swagger-nodegen-cli. This makes it easier to install.
You have to have Java installed, then just run
npm install -g swagger-nodegen-cli
Try running sc version to make sure it was installed correctly.
Assuming you want to write the docs using JSDoc, you can generate a swagger.json spec file with swagger-jsdoc:
Install swagger-jsdoc globally:
npm install -g swagger-jsdoc
In the root directory of your Express project, create a separate file for the Swagger definition object (swaggerDefinition from the tutorial):
// swagger-def.jsmodule.exports={openapi:'3.0.0',info:{title:'Express API for JSONPlaceholder',version:'1.0.0',description:'This is a REST API application made with Express. It retrieves data from JSONPlaceholder.',license:{name:'Licensed Under MIT',url:'https://spdx.org/licenses/MIT.html',},contact:{name:'JSONPlaceholder',url:'https://jsonplaceholder.typicode.com',},},servers:[{url:'http://localhost:3000',description:'Development server',},],};
To create the swagger.json file, run
swagger-jsdoc -d swagger-def.js routes/*.js
Replace routes/*.js with the paths to your files with JSDoc comments. Also see the swagger-jsdoc CLI docs.
These file paths are all relative to the root directory, so be sure to change them depending on where you want your files to live.
Finally, to create the HTML file, run
sc generate -i swagger.json -l html
You should have an index.html in the root directory. Let me know if this works for you!
If you are using Tspec, it automatically parses your TypeScript types and generates up-to-date OpenAPI specification with beautiful Swagger UI.
I strongly recommend you to try it out to make static html page with Tspec.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It is possible to generate the documentation into a static html page to be readeable without launching the server ?
yes there is:
github.com/swagger-api/swagger-cod...
Thank toi, I will look forward tous afternoon :)
Good question! I'll look into this and get back to you
Thank you very much :)
No problem. It looks like Rolf's answer is the way to go. Good luck :)
I seen that what he shared is for a maven project and I try to find for an express project :(
Oh okay, I think I found a way to generate an HTML file. I'm not really familiar with Swagger Codegen, but I found this wrapper:
swagger-nodegen-cli
. This makes it easier to install.You have to have Java installed, then just run
Try running
sc version
to make sure it was installed correctly.Assuming you want to write the docs using JSDoc, you can generate a
swagger.json
spec file withswagger-jsdoc
:Install
swagger-jsdoc
globally:In the root directory of your Express project, create a separate file for the Swagger definition object (
swaggerDefinition
from the tutorial):To create the
swagger.json
file, runReplace
routes/*.js
with the paths to your files with JSDoc comments. Also see theswagger-jsdoc
CLI docs.These file paths are all relative to the root directory, so be sure to change them depending on where you want your files to live.
Finally, to create the HTML file, run
You should have an
index.html
in the root directory. Let me know if this works for you!Thank you I will try that now ! :)
Go through the source code and trigger the function/file which is being executed
This might sound crazy, but the easiest way I've found is to simply Save the HTML page out from your browser once it's generated ! Crazily simple.
If you are using Tspec, it automatically parses your TypeScript types and generates up-to-date OpenAPI specification with beautiful Swagger UI.
I strongly recommend you to try it out to make static html page with Tspec.