Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Swagger Document for existing NodeJS server

According to Swagger website, there are two approaches: Bottom-up and Top-down.

I have an existing NodeJS server that I'd like to deploy in the Azure enviroment, that require a swagger document (API APP).

Does anyone know a tool for generating the swagger using the code? Even better if you could point a tutorial. I couldn't find it.

like image 816
Ernani Avatar asked Nov 05 '15 00:11

Ernani


People also ask

How do I create a swagger document for existing REST API?

Head over to Swagger Inspector, and insert the end point of the resource you want to have documented. You can then navigate to the right panel from the History section of Swagger Inspector, and click "Create API definition" to create the OAS definition.

How does swagger integrate with node?

The first thing is to add the file swagger. json to define the operations. You can define schemas for the request and response objects, you can define in parameters and body and descriptions of each Http operation, etc. You can actually see the schemas as well in the swagger page of the Nodejs Rest API.


1 Answers

Question is a bit old but still. It is possible to generate completely automatically Swagger (OpenAPI) specification just by embedding analysis middleware like this: https://github.com/mpashkovskiy/express-oas-generator

const express = require('express');     const expressOasGenerator = require('express-oas-generator'); let app = express(); expressOasGenerator.init(app, {}); 

run some client or REST API tests agains your service and open http://host:port/api-docs

like image 171
mpashkovskiy Avatar answered Sep 28 '22 02:09

mpashkovskiy