Skip to content

Commit 11a8e4e

Browse files
test: add failing test
1 parent 022fb94 commit 11a8e4e

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

packages/rtk-query-codegen-openapi/test/__snapshots__/generateEndpoints.test.ts.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,24 @@ export type ExampleSchemaWrite = {
561561

562562
`;
563563

564+
exports[`query parameters parameters overrided in swagger should also be overrided in the code 1`] = `
565+
import { api } from './fixtures/emptyApi';
566+
const injectedRtkApi = api.injectEndpoints({
567+
endpoints: (build) => ({
568+
getUsersById: build.query<GetUsersByIdApiResponse, GetUsersByIdApiArg>({
569+
query: (queryArg) => ({ url: \`/users/\${queryArg.pathId}\` }),
570+
}),
571+
}),
572+
overrideExisting: false,
573+
});
574+
export { injectedRtkApi as enhancedApi };
575+
export type GetUsersByIdApiResponse = unknown;
576+
export type GetUsersByIdApiArg = {
577+
pathId: number;
578+
};
579+
580+
`;
581+
564582
exports[`should use brackets in a querystring urls arg, when the arg contains full stops 1`] = `
565583
import { api } from './fixtures/emptyApi';
566584
const injectedRtkApi = api.injectEndpoints({
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
openapi: 3.0.2
2+
info:
3+
title: parameterOverride
4+
version: 1.0.0
5+
paths:
6+
/users/{id}:
7+
parameters:
8+
- in: path
9+
name: id
10+
schema:
11+
type: string
12+
required: true
13+
get:
14+
summary: Gets one or more users by ID.
15+
parameters:
16+
- in: path
17+
name: id
18+
required: true
19+
schema:
20+
type: integer
21+
responses:
22+
'200':
23+
description: OK

packages/rtk-query-codegen-openapi/test/generateEndpoints.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,19 @@ describe('openapi spec', () => {
379379
unionUndefined: true,
380380
schemaFile: './fixtures/readOnlyWriteOnly.yaml',
381381
apiFile: './fixtures/emptyApi.ts',
382-
mergeReadWriteOnly: true
382+
mergeReadWriteOnly: true,
383+
});
384+
expect(api).toMatchSnapshot();
385+
});
386+
});
387+
388+
describe('query parameters', () => {
389+
it('parameters overrided in swagger should also be overrided in the code', async () => {
390+
const api = await generateEndpoints({
391+
unionUndefined: true,
392+
schemaFile: './fixtures/parameterOverride.yaml',
393+
apiFile: './fixtures/emptyApi.ts',
394+
mergeReadWriteOnly: true,
383395
});
384396
expect(api).toMatchSnapshot();
385397
});

0 commit comments

Comments
 (0)