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.
https://github.com/stoplightio/json-ref-resolver/blob/e4e2410e86edcc7a96e01d309039ad319ca40f2c/src/crawler.ts#L115-L118
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:
|
"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"
}
}
}
In this PR, LintDiff was hanging because
@stoplight/json-ref-resolverwas in an infinite loop of circular references.Azure/azure-rest-api-specs#32573 (comment)
I believe
@stoplight/json-ref-resolvercan only reliably handle circular references, if the cycle includes the top-level definition in the file you are trying to resolve.https://github.com/stoplightio/json-ref-resolver/blob/e4e2410e86edcc7a96e01d309039ad319ca40f2c/src/crawler.ts#L115-L118
In the example PR, if
CommunicationErrorResponseis in a different JSON file thanCommunicationError(which has a circular reference toCommunicationError), the cycle can be detected immediately. So instead of running forever, it completes on the spec in 3 seconds.But if
CommunicationErrorResponseandCommunicationErrorare siblings in the same JSON file,json-ref-resolverfalls into a different codepath where it can't detect the cycle.This example doesn't hang, because the cycle is
ErrorResponse->ErrorResponse, andErrorResponseis 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
However, this example should hang when trying to resolve
ErrorResponse, since the cycle isErrorResponse->Error->Error..., but since the cycle doesn't go throughErrorResponse, it isn't detected byjson-ref-resolver.