-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
jsondocck: replace JSONPath with jq as json query language. #142479
Copy link
Copy link
Open
Labels
A-rustdoc-jsonArea: Rustdoc JSON backendArea: Rustdoc JSON backendA-testsuiteArea: The testsuite used to check the correctness of rustcArea: The testsuite used to check the correctness of rustcC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-rustdoc-jsonArea: Rustdoc JSON backendArea: Rustdoc JSON backendA-testsuiteArea: The testsuite used to check the correctness of rustcArea: The testsuite used to check the correctness of rustcC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Impetus: #142327 (comment)
Currently, jsondocck uses JSONPath to query the output in assertions. Unfortunately, it's not a particularly flexible query language. In particular, it can't feed the result of one query to index an object. We'd really like this, so we can run a query to get an ID, then look up the item with that ID.
Using jq, we can do this. It has an implementation in rust: https://docs.rs/jaq-core/2.2.0/jaq_core/index.html
How
In jsondoc, this place would need to be changed to call into
jaqinstead.rust/src/tools/jsondocck/src/cache.rs
Lines 31 to 34 in 8da6239
When doing so, the contents of
Cache::variablesshould be provided, so they can be used in selectors.Test Migration
I think the longest part of this will be migrating the tests from jsonpath to jq. It might be possible to hack up jsondocck to call
jsonpath_rust::parser::parse_json_pathon all the JSONPath queries, and then convert the JSONPath ast to a equivalent jq query.I'm not sure if this would be more or less effort than "just" doing it manually. But it'd be easier to review the resulting change this way, and it'd probably be more interesting.