Invalid reference errors even after resolving refs
This error has popped up in the past, and the reference resolution related code has grown unnecessarily complex.
Use a different approach to resolving references in the target schemas. Instead of picking targeted fields, visit every field within the target schema and replace any references if present. This will ensure that every reference will be replaced within the target schema.