Swagger code-gen not reading models properly when generating NodeJs code.

83 views
Skip to first unread message

tomas....@avenida.com

unread,
Jan 25, 2016, 1:10:58 PM1/25/16
to Swagger
I have generated my api-docs like this:

{
  "apiVersion": "0.1",
  "swaggerVersion": "1.2",
  "basePath": "/",
  "resourcePath": "/binnacle",
  "produces": [
    "text/plain; charset=UTF-8"
  ],
  "apis": [
    {
      "path": "/binnacle/justArrived",
      "operations": [
        {
          "method": "POST",
          "summary": "Logs when a user just logged in",
          "notes": "",
          "type": "string",
          "nickname": "justArrived",
          "produces": [
            "text/plain"
          ],
          "consumes": [
            "application/json",
            "application/vnd.custom.inputParams+json"
          ],
          "parameters": [
            {
              "name": "body",
              "description": "userId is required",
              "required": true,
              "type": "SimpleInputParams",
              "paramType": "body",
              "allowMultiple": false
            }
          ],
          "responseMessages": [
            {
              "code": 200,
              "message": "Thanks for using this API!"
            },
            {
              "code": 400,
              "message": "A message describing the missing arguments"
            }
          ]
        }
      ]
    }
  ],
  "models": {
    "SimpleInputParams": {
      "id": "SimpleInputParams",
      "description": "Input Parameters with just User",
      "required": [
        "userId"
      ],
      "properties": {
        "userId": {
          "type": "string",
          "description": "User Identifier"
        },
        "source": {
          "$ref": "EventSource",
          "description": "Event Source"
        }
      }
    }
  }
}

This is working properly with the Scala Module. However the code generator for node is currently not generating the parameters inside SimpleInputParams correctly, leaving the body of the endpoint like this:

exports.justArrived = function(body) {

  var examples = {};
  

  
  if(Object.keys(examples).length > 0)
    return examples[Object.keys(examples)[0]];
  
}

On the service, and

module.exports.justArrived = function justArrived (req, res, next) {
  var body = req.swagger.params['body'].value;
  

  var result = Binnacle.justArrived(body);

  if(typeof result !== 'undefined') {
    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify(result || {}, null, 2));
  }
  else
    res.end();
};

How can I make the codegen to read what is inside of "models" on the first JSON of the Swagger spec and let it generate the correct JS with the types inside?

Cheers,


tony tam

unread,
Jan 28, 2016, 7:14:36 PM1/28/16
to swagger-sw...@googlegroups.com
You’re supposed to generate the response payload yourself—so there is no longer a model prototype for you to populate (although we may want to reintroduce that).

I noticed that you’re missing a model, “EventSource”.

I would have expected the “examples” field to be populated with a sample response, though.  Could you please open an issue on the swagger-codegen project for that?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages