node-red / node-red-node-swagger

A set of tools for generating Swagger api documentation based on the HTTP nodes deployed in a flow
Apache License 2.0
62 stars 46 forks source link

Unclear instructions for step 2 #35

Closed JonathanNakandala closed 8 years ago

JonathanNakandala commented 8 years ago

I'm quite new to node-red and swagger and I was trying to follow along to the instructions for installation and I'm not too sure what is meant by:

Provide a template swagger file in settings.js:

swagger: {
  "template": {
    "swagger": "2.0",
    "info": {
      "title": "My Node-RED API",
      "version": "0.0.1"
    }
  }
}

I've tried pasting this in various places in ~/.node-red/settings.js and I'm getting syntax errors when trying to start node-red. e.g.

/home/ubuntu/.node-red/settings.js:22
  "template": {
            ^
Error loading settings file: /home/ubuntu/.node-red/settings.js
[SyntaxError: Unexpected token :]

This is probably quite a silly question but I googled around and couldn't find much info.

knolleary commented 8 years ago

That error suggests you've pasted the swagger entry outside of the module.exports block. It should be something like:

    module.exports = {
        swagger: {
            "template": {
                "swagger": "2.0",
                "info": {
                    "title": "My Node-RED API",
                    "version": "0.0.1"
                }
            }
        },
        // existing settings...
    }
JonathanNakandala commented 8 years ago

Ah, of course. It might make it a bit easier to follow if there was a small note mentioning that there has to be a comma after the last }.

Quite oddly after doing this and getting node-red to run it seems like nothing has changed. There's no Doc field in the http-in node and no swagger-ui tab.

I've tried both npm install node-red-node-swagger and npm install node-red/node-red-node-swagger

Here's the startup info:

Welcome to Node-RED
===================

10 Dec 14:19:43 - [info] Node-RED version: v0.12.2
10 Dec 14:19:43 - [info] Node.js  version: v0.10.25
10 Dec 14:19:43 - [info] Loading palette nodes
10 Dec 14:19:43 - [warn] ------------------------------------------
10 Dec 14:19:43 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
10 Dec 14:19:43 - [warn] ------------------------------------------
10 Dec 14:19:43 - [info] Settings file  : /home/ubuntu/.node-red/settings.js
10 Dec 14:19:43 - [info] User directory : /home/ubuntu/.node-red
10 Dec 14:19:43 - [info] Flows file : /home/ubuntu/.node-red/flows_ip-172-31-42-69.json
10 Dec 14:19:43 - [info] Server now running at https://127.0.0.1:1880/
10 Dec 14:19:43 - [info] Creating new flow file
10 Dec 14:19:43 - [info] Starting flows
10 Dec 14:19:43 - [info] Started flows

Is there a requirement for a newer version of nodejs?

knolleary commented 8 years ago

Where did you run the npm install from? From that output, I see it should be run in /home/ubuntu/.node-red

JonathanNakandala commented 8 years ago

Woops, Totally my mistake. Was running the command in the wrong directory! Thanks for your help :+1:

knolleary commented 8 years ago

Ok - are we good to close this issue then?

JonathanNakandala commented 8 years ago

Yep. Everything is working now. Thanks again.