Skip to content

test(query): add regression coverage for vue-query header params (#1026) - #3379

Merged
melloware merged 2 commits into
orval-labs:masterfrom
wadakatu:test/issue-1026-vue-query-headers-regression
May 18, 2026
Merged

test(query): add regression coverage for vue-query header params (#1026)#3379
melloware merged 2 commits into
orval-labs:masterfrom
wadakatu:test/issue-1026-vue-query-headers-regression

Conversation

@wadakatu

@wadakatu wadakatu commented May 18, 2026

Copy link
Copy Markdown
Contributor

Overview

Adds regression test coverage for #1026, where the generated Vue Query key getter referenced an undeclared headers variable (headers = unref(headers);) and threw ReferenceError: headers is not defined at runtime when headers: true was enabled.

The underlying bug is already fixed (the Vue query key getter no longer unref's params, see the Note: do not unref() params in Vue comment in packages/query/src/query-generator.ts). However, no test exercised the vue-query + headers: true combination, so the scenario could silently regress. This PR closes that gap without any source changes.

Changes

  • tests/specifications/issue-1026.yaml — new minimal OpenAPI spec with a header-only GET endpoint (Language-Id, Country-Id, TimeZone), mirroring the issue report.
  • tests/configs/vue-query.config.ts — new issue1026 config entry (client: vue-query, httpClient: axios, mode: split, headers: true), matching the configuration from the issue.
  • tests/__snapshots__/vue-query/issue-1026/ — generated snapshot fixtures.
  • tests/api-generation.spec.ts — new focused test vue-query issue-1026 keeps header params out of the query key getter, which slices out the getGetSomeEndpointQueryKey getter and asserts it never references headers, while confirming the HTTP function still receives and unref's headers.

The scenario is now guarded at three layers: the snapshot test, the focused assertion, and scripts/typecheck-generated.mjs (an undeclared headers fails to compile). Reintroducing the bug into the generated fixture was verified to fail all three.

Related

Summary by CodeRabbit

  • New Features
    • Generated Vue Query client with a new endpoint, query hooks, and built-in support for optional header parameters.
  • Types
    • Added request header and response result types for the new endpoint.
  • Tests
    • Added tests and fixtures validating correct header handling in generated Vue Query hooks.
  • Chores
    • Added generator configuration and OpenAPI spec for the new endpoint.

Review Change Stack

Copilot AI review requested due to automatic review settings May 18, 2026 13:40
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3453965a-ad31-48f8-a7f0-3d8a389c2bf5

📥 Commits

Reviewing files that changed from the base of the PR and between 33c650b and 6cd2159.

📒 Files selected for processing (1)
  • tests/api-generation.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/api-generation.spec.ts

📝 Walkthrough

Walkthrough

Adds an OpenAPI spec and Orval config to generate Vue Query + axios code with header parameters, includes generated model and endpoints snapshots, and a Vitest that checks query key getters do not reference headers while the HTTP function still accepts and unrefs headers.

Changes

Vue Query Header Parameters Test Case

Layer / File(s) Summary
Test Input Specification and Configuration
tests/specifications/issue-1026.yaml, tests/configs/vue-query.config.ts
OpenAPI 3.0 spec for GET /api/v1/someEndPoint with header parameters and an Orval config entry issue1026 enabling client: 'vue-query', httpClient: 'axios', mode: 'split', and headers: true.
Generated Type Exports
tests/__snapshots__/vue-query/issue-1026/model/getSomeEndpointHeaders.ts, tests/__snapshots__/vue-query/issue-1026/model/someEndpointResult.ts, tests/__snapshots__/vue-query/issue-1026/model/index.ts
New generated TypeScript types: GetSomeEndpointHeaders and SomeEndpointResult, plus a model index re-exporting them.
Generated Query API and Hooks
tests/__snapshots__/vue-query/issue-1026/endpoints.ts
Generated Vue Query/axios module: getSomeEndpoint unrefs header refs and merges headers into axios options; getGetSomeEndpointQueryKey and getGetSomeEndpointQueryOptions build key and options; exported query result/error types; useGetSomeEndpoint hook composes useQuery and attaches a typed queryKey.
Validation Test for Header Isolation
tests/api-generation.spec.ts
Vitest ensures the generated query key getter does not reference headers while verifying the HTTP function still accepts and calls unref(headers).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

tanstack-query

Suggested reviewers

  • melloware
  • snebjorn

Poem

🐰 I hop through specs and headers neat,
I unref gently so queries stay sweet.
Keys stay pure, no stray name to bind,
Types and hooks in tidy kind.
Cheers from a rabbit — code clean and fine!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly describes the primary change: adding regression test coverage for Vue Query header parameters (issue #1026), which directly matches the changeset focusing on test additions and fixtures.
Linked Issues check ✅ Passed All code changes directly support issue #1026's objectives: the new OpenAPI spec provides the minimal endpoint configuration with header parameters mentioned in the issue, the test verifies the query key getter never references undeclared headers, and fixtures ensure the generated code works without runtime errors.
Out of Scope Changes check ✅ Passed All changes are scoped to regression test coverage: new specification, config entry, generated fixtures, and focused test assertion—no unrelated source code modifications or scope creep detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a regression test fixture and snapshot coverage for issue #1026, verifying that the Vue Query key getter does not incorrectly reference headers when headers: true is configured.

Changes:

  • New OpenAPI spec with header parameters to reproduce issue #1026.
  • New issue1026 entry in the Vue Query test config plus generated snapshots.
  • New focused regression test asserting the query key getter does not reference headers.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/specifications/issue-1026.yaml New OpenAPI fixture with header parameters.
tests/configs/vue-query.config.ts Adds issue1026 Vue Query generation config.
tests/api-generation.spec.ts Adds regression test for the query key getter.
tests/snapshots/vue-query/issue-1026/endpoints.ts Snapshot of generated endpoints.
tests/snapshots/vue-query/issue-1026/model/someEndpointResult.ts Snapshot of generated result model.
tests/snapshots/vue-query/issue-1026/model/index.ts Snapshot of generated model barrel file.
tests/snapshots/vue-query/issue-1026/model/getSomeEndpointHeaders.ts Snapshot of generated headers type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/api-generation.spec.ts Outdated

// The getter must not reference `headers` at all - it is neither a parameter
// nor a query-key segment here.
expect(queryKeyFn).not.toContain('headers');
Comment on lines +193 to +199
// Slice out the `getGetSomeEndpointQueryKey` declaration body.
const marker = 'export const getGetSomeEndpointQueryKey = (';
const start = content.indexOf(marker);
expect(start, `${marker} should be generated`).toBeGreaterThan(-1);
const end = content.indexOf('as const', start);
expect(end, `${marker} body should be terminated`).toBeGreaterThan(start);
const queryKeyFn = content.slice(start, end);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — I'm keeping the indexOf('as const') slicing here for consistency with the sibling react-query issue-708 test in this same file (lines 96-103), which already establishes exactly this pattern for the same kind of query-key-getter assertion. Switching only this test to a different slicing strategy would make the two diverge.

Also, this doesn't slice silently on missing as const: indexOf returns -1, and the expect(end, ...).toBeGreaterThan(start) guard right below fails with a clear "body should be terminated" message before the slice is used. If the slicing approach should change, it'd be better done for both tests together, which is out of scope for this regression-test PR.

@melloware
melloware merged commit 3e1664e into orval-labs:master May 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vue: Uncaught (in promise) ReferenceError: headers is not defined when having headers: true in config

3 participants