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 47 forks source link

Fix null pointer in path params and add support for automatically adding API_SECRET to swagger if present #7

Closed codymwalker closed 9 years ago

knolleary commented 9 years ago

Not keen on having API_SECRET as a top-level, unscoped property of settings. It is very specific to your use case and not very extensible for other users of this node.

Ideally we'd have some way to be able to specify any object value that should be applied to each path (or a property under it).... but I appreciate that's not in our scope to engineer right now.

Currently the swagger template is specified under RED.settings.swagger. How about (and this will require updates to anything using this node today...), we modify this a bit so we have:

RED.settings.swagger = {
    template: {
         // The template we have as RED.settings.swagger today
    },
    api_secret: "foo"
}

That gives us room to add further properties in the future, whilst keeping them neatly within the settings.swagger object.

Note also the choice of lower-case property name.

codymwalker commented 9 years ago

Hey Nick,

Let's catch up on this in the morning. There was a specific requirement that this surrounded. I do like the idea of being able to add any additional value that gets added as a parameter. I could probably throw something together on that, and it would be much less specific to our use case.

codymwalker commented 9 years ago

Added the template object as suggested above. Also added an object 'parameters', in which the user can provide the swagger object they would like to each path. Like so:

    swagger: {
      "template": {
        "swagger": "2.0",
        "info": {
          "title": "My Node-RED API",
          "version": "0.0.1"
        }
      },
      "parameters": {
        "name": "parameterA",
        "type": "string",
        "in": "header",
        "required": false,
        "description": "This is a test parameter to show how parameters are automatically added to each path in the generated swagger doc."
      }
    }

produces

{
  "swagger": "2.0",
  "info": {
    "title": "My Node-RED API",
    "version": "0.0.1"
  },
  "basePath": "/",
  "paths": {
    "/echo": {
      "post": {
        "summary": "post /echo",
        "responses": {
          "default": {}
        },
        "parameters": [
          {
            "name": "parameterA",
            "type": "string",
            "in": "header",
            "required": false,
            "description": "This is a test parameter to show how parameters are automatically added to each path in the generated swagger doc."
          }
        ]
      }
    }
  }
}

It would also add it to all other paths, and plays nice when the user supplies params via the config dialogs in the editor.