wcandillon / swagger-js-codegen

A Swagger Codegen for typescript, nodejs & angularjs
Apache License 2.0
693 stars 286 forks source link

params not being added to method #90

Closed gersongoulart closed 8 years ago

gersongoulart commented 8 years ago

Hi there!

I have just recently updated to the latest version of swagger-js-codegen and since then have been struggling with an issue: suddenly all parameters have despaired from their respective methods.

Fiddling with the code I found the problem might be in this line: https://github.com/wcandillon/swagger-js-codegen/blob/master/lib/codegen.js#L89

where lodash chain method has been used as _.chain(params).forEach(...); without calling .value(); in the end of the chain. By not calling the .value method of the chain, the forEach loop never runs and hence parameters never get added to the method. I'm not sure if this is a recent change in swagger-js-codegen or in lodash.

There are two simple ways to fix the problem: 1) Change _.chain(params).forEach(...); to _.forEach(params, ...); (which I think is the cleanest solution) 2) Add .value() to the end of the chain.

I can submit a PR if desired but I figured I'd post this issue here first to make sure I got this right.

gersongoulart commented 8 years ago

Hey! Just to add an extra bit of information about this bug:

This project currently depends on lodash@^2.4.1 but newer versions of lodash (which may be installed in the project, as it is in my case) run the chain method lazily.

Running this piece of code in the https://lodash.com/docs#chain page will show you what I am talking about:

var users = [
  { 'user': 'barney',  'age': 36 },
  { 'user': 'fred',    'age': 40 },
  { 'user': 'pebbles', 'age': 1 }
];
var test = [];
var youngest = _.chain(users)
  .forEach(function(user) {
    test.push(user);
  });

console.log(test); // []

This is exactly what is happening with params, which never get populated if you're running a newer version of lodash in your project.

wcandillon commented 8 years ago

@gersongoulart nice catch! sorry for this bug 🙈

gersongoulart commented 8 years ago

@wcandillon it's a pleasure to help! Thank you for the fix! :)