-
Notifications
You must be signed in to change notification settings - Fork 50
Description
In this PR, LintDiff was hanging because @stoplight/json-ref-resolver was in an infinite loop of circular references.
Azure/azure-rest-api-specs#32573 (comment)
I believe @stoplight/json-ref-resolver can only reliably handle circular references, if the cycle includes the top-level definition in the file you are trying to resolve.
In the example PR, if CommunicationErrorResponse is in a different JSON file than CommunicationError (which has a circular reference to CommunicationError), the cycle can be detected immediately. So instead of running forever, it completes on the spec in 3 seconds.
But if CommunicationErrorResponse and CommunicationError are siblings in the same JSON file, json-ref-resolver falls into a different codepath where it can't detect the cycle.
This example doesn't hang, because the cycle is ErrorResponse->ErrorResponse, and ErrorResponse is the top-level object under definitions we are resolving:
azure-openapi-validator/packages/rulesets/src/native/tests/resources/references/circular-ref.json
Lines 15 to 25 in 61cc571
| "definitions": { | |
| "ErrorResponse": { | |
| "properties": { | |
| "code": { | |
| "type": "string" | |
| }, | |
| "detail": { | |
| "$ref": "#/definitions/ErrorResponse" | |
| } | |
| } | |
| } |
However, this example should hang when trying to resolve ErrorResponse, since the cycle is ErrorResponse->Error->Error..., but since the cycle doesn't go through ErrorResponse, it isn't detected by json-ref-resolver.
"definitions": {
"ErrorResponse": {
"properties": {
"code": {
"type": "string"
},
"detail": {
"$ref": "#/definitions/Error"
}
},
"Error": {
"properties": {
"code": {
"type": "string"
},
"detail": {
"$ref": "#/definitions/Error"
}
}
}