fixed issue where multiple $ref to the same resource would not resolve

Wrote a patch where if there are multiple `$ref`'s that point to the same resource, only one of them would get resolved. I've also added relevant unit tests.