Closed ductaily closed 1 year ago
Hey! Could you provide JSON path expressions without aliases? Overall aliases shouldn't have any meaningful impact on the runtime performance, as we expand them to actual JSON path expressions before we start the linting process.
Hi, thanks for taking this. Here is how the path expressions without aliases look like:
aliases: {
odataAll: [
// OData arrays
'$[?(@property === "x-sap-api-type" && @ === "ODATAV4")]^.paths.*.*.responses[?(@property.match(/^[12]/))].content.application/json.schema.properties.value.items',
'$[?(@property === "x-sap-api-type" && @ === "ODATAV4")]^.paths.*.*.responses[?(@property.match(/^[12]/))].schema.properties.value.items',
'$[?(@property === "x-sap-api-type" && @ === "ODATA")]^.paths.*.*.responses[?(@property.match(/^[12]/))].content.application/json.schema.properties.d.properties.results.items',
'$[?(@property === "x-sap-api-type" && @ === "ODATA")]^.paths.*.*.responses[?(@property.match(/^[12]/))].schema.properties.d.properties.results.items',
// OData objects
'$[?(@property === "x-sap-api-type" && @ === "ODATAV4")]^.paths.*.*.responses[?(@property.match(/^[12]/))].content.application/json[?(@.type == "object" && @.properties && !@.properties.value)]',
'$[?(@property === "x-sap-api-type" && @ === "ODATAV4")]^.paths.*.*.responses[?(@property.match(/^[12]/))][?(@.properties && !@.properties.value)]',
'$[?(@property === "x-sap-api-type" && @ === "ODATA")]^.paths.*.*.responses[?(@property.match(/^[12]/))].content.application/json.schema.properties[?(@.type === "object" && @.properties && !@.properties.results)]',
'$[?(@property === "x-sap-api-type" && @ === "ODATA")]^.paths.*.*.responses[?(@property.match(/^[12]/))].schema.properties[?(@.type === "object" && @.properties && !@.properties.results)]',
],
restAll: [
'$[?(@root["x-sap-api-type"] === undefined && @property === "paths")]^.paths.*.*.responses[?(@property.match(/^[12]/))].content.application/json[?(@.type == "object")]',
'$[?(@property === "x-sap-api-type" && @ === "REST")]^.paths.*.*.responses[?(@property.match(/^[12]/))].content.application/json[?(@.type == "object")]',
'$[?(@root["x-sap-api-type"] === undefined && @property === "paths")]^.paths.*.*.responses[?(@property.match(/^[12]/))][?(@.type == "object")]',
'$[?(@property === "x-sap-api-type" && @ === "REST")]^.paths.*.*.responses[?(@property.match(/^[12]/))][?(@.type == "object")]',
]
}
Thank you! I'll try to take a look at it this week.
@ductaily alright, I took and look.
The issue is caused by .[
which is interpreted as a deep, meaning we traverse the entire document.
Try changing it back to
odataV4: ['$[?(@property === "x-sap-api-type" && @ === "ODATAV4")]'],
odataV2: ['$[?(@property === "x-sap-api-type" && @ === "ODATA")]'],
That should resolve the issue
I can confirm, this solves the issue. Thanks a lot!
If that is an intended behavior and I should be more careful when to use .
then I would close the issue as completed.
If that is an intended behavior
As things stand, that is an intended behavior. It may change in the future once #2395 is completed.
Describe the bug
Define a ruleset with nested aliases and use the alias that contains all nested aliases in the
given
of the rule. Run the ruleset on a large OpenAPI document.The execution of the rules on the document does not seem to terminate.
To Reproduce
Example to run: https://github.com/ductaily/spectral-alias-performance-example Place into the
src
directory avalid.json
with the content here.Expected behavior The ruleset execution should terminate in a similar time as if the JSON paths were flat.
Screenshots If applicable, add screenshots to help explain your problem.
Environment (remove any that are not applicable):
Additional context It seems that resolving the aliases is problematic. We ran the same paths flattened without nesting and spectral terminates after approx. 2 minutes.