Closed gersongoulart closed 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.
@gersongoulart nice catch! sorry for this bug 🙈
@wcandillon it's a pleasure to help! Thank you for the fix! :)
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, theforEach
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.