Closed dalewking closed 5 years ago
Totally valid point. I knew this will happen, I just didn't consider the recursive structure as a common use-case. I'll take a look. Thanks!
Here is an outline of how I fixed it in our library (which was written by an intern so we are looking to replace with swagger-brake):
I created a set to remember the path:
private Set<Object> seen = new HashSet<>();
The method to determine if 2 types are the same looks like this:
boolean hasChangedElement = false;
// Evaluate the map the first time we see it, otherwise ignore since it is a recursive instance
if(seen.add(old)) {
hasChangedElement = // determine if it is changed which includes recursion
seen.remove(old);
}
return hasChangedElement;
Fixed.
We had our own library that tried to do what swagger-brake is doing and ran into the same problem.
The solution is that you have to remember where you have been when recursing and don't recurse into a schema you have already seen on the way down.
Here is a simplified swagger spec that causes the stack overflow. Note that PaymentItemDTO contains an array of children PaymentItemDTO objects.