APIs-guru / google-discovery-to-swagger

Script for converting Google Discovery format into OpenAPI (swagger) 3.0
MIT License
59 stars 17 forks source link

Ignore prototypes in object iteration #7

Closed jharmn closed 5 years ago

jharmn commented 9 years ago

When prototype methods have been added to the GDD schema, iterations of object properties will fail.

http://yuiblog.com/blog/2006/09/26/for-in-intrigue/

IvanGoncharov commented 9 years ago

@jasonh-n-austin Can you use forOwn function? Everything else, looks good :+1:

jharmn commented 9 years ago

I tried forOwn, but it doesn't seem to work the same way. It still iterates prototyped methods.

IvanGoncharov commented 9 years ago

What is your environment? I tried lodash example and it works fine. Can you try it on your system?

function Foo() {
  this.a = 1;
  this.b = 2;
}

Foo.prototype.c = 3;

_.forOwn(new Foo, function(value, key) {
  console.log(key);
});
// → logs 'a' and 'b' (iteration order is not guaranteed)

I also inspect lodash implementation and it use standard Object.keys, can you log output of this function?

IvanGoncharov commented 9 years ago

@jasonh-n-austin Did you had a chance to look at it?

IvanGoncharov commented 8 years ago

Hi @jasonh-n-austin,

Happy New Year :christmas_tree: :santa: Is this issue still valid?

jharmn commented 8 years ago

Totally forgot about this. I'll take a look at it by the end of the week, thanks for the reminder.

jharmn commented 8 years ago

Ran your test script on v0.10.25/Ubuntu and v0.12.1/Mac, both printed a,b.

I'll re-run this with my test data and see if I can figure out what scenario made this necessary.

jharmn commented 8 years ago

FYI @crankydillo has been working on some improvements (which are now included in this PR). I've also asked for his help to pin down why we needed this prototype exclusion to make things work (my brain is already full of cobwebs about it).

IvanGoncharov commented 8 years ago

@jasonh-n-austin

why we needed this prototype exclusion to make things work

I understand why. But I'm don't understand why forOwn not working?

can you try to do:

data = JSON.parse(JSON.stringify(data));

before passing it into the lib?

MikeRalphson commented 5 years ago

Assuming this PR is no longer relevant/current? Happy to re-open if necessary.