node-red-flowgen 0.0.2
Generate Node-RED flows and function-node code from OpenAPI 3 / Swagger 2 documents
node-red-flowgen
Generate Node-RED flows from OpenAPI 3.x / Swagger 2.0 documents.
Pick an endpoint from an API definition and get a ready-to-run flow — inject, function,
http request and debug — where the function node sets up msg for the request: method, URL,
headers, cookies and a sample body. It works as an editor plugin that adds an
API Spec tab to the Import dialog.
Install
cd ~/.node-red
npm install node-red-flowgen
Or grab node-red-flowgen.tgz from the latest release and
npm install ./node-red-flowgen.tgz. Restart Node-RED afterwards. Once installed, the
plugin works fully offline — every asset is served by Node-RED itself.
How to use editor plugin
Open Import node dialog by selecting Import item from the menu.
Select API Spec tab, then paste an API document (JSON or YAML), paste its URL, or upload a file.
One endpoint → Import lights up immediately. Several → press Select endpoint >, pick one from the Swagger-UI-style list (arrow keys work), then Import.
The four nodes are added to the current flow.
Generated code for function node
msg.method = 'GET';
msg.url = 'http://petstore.swagger.io/v2/pet/findByStatus?status=available';
// msg.url = 'http://petstore.swagger.io/v2/pet/findByStatus?status=pending';
// msg.url = 'http://petstore.swagger.io/v2/pet/findByStatus?status=sold';
// Fill in 'authorization' below.
msg.headers = {
'authorization': 'Bearer ',
'accept': 'application/json'
};
return msg;
- Parameter values are filled from the spec (
enum,example,default). The first candidate goes intomsg.url; alternatives follow as commented-out lines, soCtrl + /toggles between them. - Anything the spec leaves open gets a comment saying what to edit, with the type when
known:
// Replace {petId} (integer) in the URL below with a real value. - Authentication comes from the security definitions: API keys in header/query/cookie,
Bearer/ basic prefixes inauthorization. multipart/form-databodies use the http request node's file-upload shape ({ value: FILE_CONTENTS, options: { filename: FILENAME } }).