Process() cancelled due to exception : $ref to original location '[object Object]' is not found in the new refs collection
Before filling a bug
- [X] have you checked the faq for known issues.
- [X] have you checked existing issues
Describe the bug
- https://dev.azure.com/azure-sdk//internal/_build/results?buildId=4235054&view=logs&j=0574a2a6-2d0a-5ec6-40e4-4c6e2f70bea2
info | spectralPluginFunc: Return
debug | [2.22 s] swagger-document/spectral - END [0.75 s][100 MB]
fatal | Process() cancelled due to exception : $ref to original location '[object Object]' is not found in the new refs collection / Error: $ref to original location '[object Object]' is not found in the new refs collection
at Deduplicator.updateRefs (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:17084:31)
at Deduplicator.updateRefs (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:17088:22)
at Deduplicator.updateRefs (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:17088:22)
at Deduplicator.updateRefs (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:17088:22)
at Deduplicator.deduplicateComponent (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:17016:42)
at runNextTicks (node:internal/process/task_queues:60:5)
at processImmediate (node:internal/timers:449:9)
at Deduplicator.crawlObject (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:17062:17)
at Deduplicator.crawlObject (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:17065:17)
at Deduplicator.crawlObject (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:17065:17)
at Deduplicator.crawlComponent (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:17044:17)
at Deduplicator.deduplicateComponent (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:16956:25)
at Deduplicator.deduplicateComponents (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:16938:17)
at Deduplicator.init (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:16822:13)
at Deduplicator.getOutput (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:17102:13)
at deduplicate (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:2485:76)
at ScheduleNode (/home/paulhsu/.autorest/@[email protected]/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:1351:29)
error | Error: $ref to original location '[object Object]' is not found in the new refs collection
error | Autorest completed with an error. If you think the error message is unclear, or is a bug, please declare an issues at https://github.com/Azure/autorest/issues with the error message you are seeing.
debug | [2.22 s] Shutting Down.
debug | [2.22 s] Exiting.
I think the fix is simple, only treat "$ref" as a reference if the value is a string, else treat it as an identifier.
A JSON Reference is a JSON object, which contains a member ***named
"$ref", which has a JSON string value***. Example:
{ "$ref": "[http://example.com/example.json#/foo/bar"](http://example.com/example.json#/foo/bar%22) }
***If a JSON value does not have these characteristics, then it SHOULD
NOT be interpreted as a JSON Reference.***
The "$ref" string value contains a URI [RFC3986], which identifies
the location of the JSON value being referenced. It is an error
condition if the string value does not conform to URI syntax rules.
Any members other than "$ref" in a JSON Reference object SHALL be
ignored.
https://datatracker.ietf.org/doc/html/draft-pbryan-zyp-json-ref-03#section-3
https://github.com/Azure/autorest/blob/80d93061b5b8e70d4042fa0333cb5fd79478a2ee/packages/libs/deduplication/src/main.ts#L396-L412
This is already fixed other places in autorest:
https://github.com/Azure/autorest/blob/80d93061b5b8e70d4042fa0333cb5fd79478a2ee/packages/extensions/core/src/lib/plugins/components-cleaner.ts#L253
PR hitting bug: https://github.com/Azure/azure-rest-api-specs/pull/33190
$ref as property name (object value):
"$ref": {
"type": "string",
"description": "Reference to another field definition."
}
$ref as reference (string value):
"additionalProperties": {
"$ref": "#/definitions/FieldDefinition"
},
@timotheeguerin: Any concerns with me making this change? It should be pretty safe, since it should only be changing the behavior in what is currently an error case.
This was fixed (at least partially) in [email protected], but we are still seeing a similar error:
https://github.com/Azure/azure-rest-api-specs-pr/pull/21772/checks?check_run_id=42080711823