-
-
Notifications
You must be signed in to change notification settings - Fork 664
test(query): add regression coverage for vue-query header params (#1026) #3379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
melloware
merged 2 commits into
orval-labs:master
from
wadakatu:test/issue-1026-vue-query-headers-regression
May 18, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /** | ||
| * Generated by orval v8.11.0 🍺 | ||
| * Do not edit manually. | ||
| * Issue 1026 - Vue Query header parameters | ||
| * OpenAPI spec version: 1.0.0 | ||
| */ | ||
| import { useQuery } from '@tanstack/vue-query'; | ||
| import type { | ||
| DataTag, | ||
| QueryClient, | ||
| QueryFunction, | ||
| QueryKey, | ||
| UseQueryOptions, | ||
| UseQueryReturnType, | ||
| } from '@tanstack/vue-query'; | ||
|
|
||
| import axios from 'axios'; | ||
| import type { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
|
|
||
| import { unref } from 'vue'; | ||
| import type { MaybeRef } from 'vue'; | ||
|
|
||
| import type { GetSomeEndpointHeaders, SomeEndpointResult } from './model'; | ||
|
|
||
| /** | ||
| * @summary Get something with header parameters | ||
| */ | ||
| export const getSomeEndpoint = ( | ||
| headers?: MaybeRef<GetSomeEndpointHeaders>, | ||
| options?: AxiosRequestConfig, | ||
| ): Promise<AxiosResponse<SomeEndpointResult>> => { | ||
| headers = unref(headers); | ||
|
|
||
| return axios.get(`/api/v1/someEndPoint`, { | ||
| ...options, | ||
| headers: { ...headers, ...options?.headers }, | ||
| }); | ||
| }; | ||
|
|
||
| export const getGetSomeEndpointQueryKey = () => { | ||
| return ['api', 'v1', 'someEndPoint'] as const; | ||
| }; | ||
|
|
||
| export const getGetSomeEndpointQueryOptions = < | ||
| TData = Awaited<ReturnType<typeof getSomeEndpoint>>, | ||
| TError = AxiosError<unknown>, | ||
| >( | ||
| headers?: MaybeRef<GetSomeEndpointHeaders>, | ||
| options?: { | ||
| query?: Partial< | ||
| UseQueryOptions< | ||
| Awaited<ReturnType<typeof getSomeEndpoint>>, | ||
| TError, | ||
| TData | ||
| > | ||
| >; | ||
| axios?: AxiosRequestConfig; | ||
| }, | ||
| ) => { | ||
| const { query: queryOptions, axios: axiosOptions } = options ?? {}; | ||
|
|
||
| const queryKey = getGetSomeEndpointQueryKey(); | ||
|
|
||
| const queryFn: QueryFunction<Awaited<ReturnType<typeof getSomeEndpoint>>> = ({ | ||
| signal, | ||
| }) => getSomeEndpoint(headers, { signal, ...axiosOptions }); | ||
|
|
||
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | ||
| Awaited<ReturnType<typeof getSomeEndpoint>>, | ||
| TError, | ||
| TData | ||
| >; | ||
| }; | ||
|
|
||
| export type GetSomeEndpointQueryResult = NonNullable< | ||
| Awaited<ReturnType<typeof getSomeEndpoint>> | ||
| >; | ||
| export type GetSomeEndpointQueryError = AxiosError<unknown>; | ||
|
|
||
| /** | ||
| * @summary Get something with header parameters | ||
| */ | ||
|
|
||
| export function useGetSomeEndpoint< | ||
| TData = Awaited<ReturnType<typeof getSomeEndpoint>>, | ||
| TError = AxiosError<unknown>, | ||
| >( | ||
| headers?: MaybeRef<GetSomeEndpointHeaders>, | ||
| options?: { | ||
| query?: Partial< | ||
| UseQueryOptions< | ||
| Awaited<ReturnType<typeof getSomeEndpoint>>, | ||
| TError, | ||
| TData | ||
| > | ||
| >; | ||
| axios?: AxiosRequestConfig; | ||
| }, | ||
| queryClient?: QueryClient, | ||
| ): UseQueryReturnType<TData, TError> & { | ||
| queryKey: DataTag<QueryKey, TData, TError>; | ||
| } { | ||
| const queryOptions = getGetSomeEndpointQueryOptions(headers, options); | ||
|
|
||
| const query = useQuery(queryOptions, queryClient) as UseQueryReturnType< | ||
| TData, | ||
| TError | ||
| > & { queryKey: DataTag<QueryKey, TData, TError> }; | ||
|
|
||
| query.queryKey = unref(queryOptions).queryKey as DataTag< | ||
| QueryKey, | ||
| TData, | ||
| TError | ||
| >; | ||
|
|
||
| return query; | ||
| } |
12 changes: 12 additions & 0 deletions
12
tests/__snapshots__/vue-query/issue-1026/model/getSomeEndpointHeaders.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /** | ||
| * Generated by orval v8.11.0 🍺 | ||
| * Do not edit manually. | ||
| * Issue 1026 - Vue Query header parameters | ||
| * OpenAPI spec version: 1.0.0 | ||
| */ | ||
|
|
||
| export type GetSomeEndpointHeaders = { | ||
| 'Language-Id'?: number; | ||
| 'Country-Id'?: number; | ||
| TimeZone?: string; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /** | ||
| * Generated by orval v8.11.0 🍺 | ||
| * Do not edit manually. | ||
| * Issue 1026 - Vue Query header parameters | ||
| * OpenAPI spec version: 1.0.0 | ||
| */ | ||
|
|
||
| export * from './getSomeEndpointHeaders'; | ||
| export * from './someEndpointResult'; |
10 changes: 10 additions & 0 deletions
10
tests/__snapshots__/vue-query/issue-1026/model/someEndpointResult.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * Generated by orval v8.11.0 🍺 | ||
| * Do not edit manually. | ||
| * Issue 1026 - Vue Query header parameters | ||
| * OpenAPI spec version: 1.0.0 | ||
| */ | ||
|
|
||
| export interface SomeEndpointResult { | ||
| value?: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Issue 1026 - Vue Query header parameters | ||
| version: 1.0.0 | ||
| paths: | ||
| /api/v1/someEndPoint: | ||
| get: | ||
| operationId: getSomeEndpoint | ||
| tags: | ||
| - things | ||
| summary: Get something with header parameters | ||
| parameters: | ||
| - name: Language-Id | ||
| in: header | ||
| style: simple | ||
| schema: | ||
| type: integer | ||
| - name: Country-Id | ||
| in: header | ||
| style: simple | ||
| schema: | ||
| type: integer | ||
| - name: TimeZone | ||
| in: header | ||
| style: simple | ||
| schema: | ||
| type: string | ||
| responses: | ||
| '200': | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/SomeEndpointResult' | ||
| components: | ||
| schemas: | ||
| SomeEndpointResult: | ||
| type: object | ||
| properties: | ||
| value: | ||
| type: string |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 siblingreact-query issue-708test 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:indexOfreturns-1, and theexpect(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.